dhoulb / multi-semantic-release

Proof of concept that wraps semantic-release to work with monorepos.
BSD Zero Clause License
203 stars 36 forks source link

Multi-semantic-release changes the "workspace:^" while versioning #85

Closed Code2Life closed 3 years ago

Code2Life commented 3 years ago

While using PNPM workspace in monorepo, dependencies could be:

"somePkg" : "workspace:^"

However, semantic release will change it to 1.0.x when writing version back to package.json.

Expect Behavior:

Remain original string: "workspace:^", otherwise, pnpm install will resuilt in wrong module structure.

antongolub commented 3 years ago

@Code2Life,

Thanks for the report. Here's how semrel npm plugin updates package version:

module.exports = async (npmrc, {tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) => {
  const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd;

  logger.log('Write version %s to package.json in %s', version, basePath);

  const versionResult = execa(
    'npm',
    ['version', version, '--userconfig', npmrc, '--no-git-tag-version', '--allow-same-version'],
    {
      cwd: basePath,
      env,
    }
  );

And here's the place, where msr can just override package.json.version value:

const prepare = async (pluginOptions, context) => {
    // Wait until the current pkg is ready to be tagged
    getLucky("_readyForTagging", pkg);
    await waitFor("_readyForTagging", pkg);

    updateManifestDeps(pkg);
    pkg._depsUpdated = true;

    const res = await plugins.prepare(context);
    pkg._prepared = true;

    debug("prepared: %s", pkg.name);

    return res;
};

But it may affect other plugins prepare result (like commit creation). I don't see a quick fix for the problem.

Code2Life commented 3 years ago

@antongolub Thank you ! Currently I removed "package.json" file from "@semantic-release/git" releaserc to avoid this issue, even it will cause inconsistency of "real" version.

antongolub commented 3 years ago