@mnci/cli 4.40.5 → 4.40.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -4464,6 +4464,28 @@ function setGoModulePath(workspaceRoot, projectDir) {
4464
4464
  const rewritten = (0, import_node_fs18.readFileSync)(goModPath, "utf8").replace(/^module\s+\S+/m, () => `module ${prefix}/${projectDir}`);
4465
4465
  writeFileEnsured(goModPath, rewritten);
4466
4466
  }
4467
+ var GO_DIRECTIVE_CEILING = "1.24";
4468
+ function exceedsGoCeiling(version) {
4469
+ const [major, minor] = version.split(".").map(Number);
4470
+ const [ceilingMajor, ceilingMinor] = GO_DIRECTIVE_CEILING.split(".").map(Number);
4471
+ return major > ceilingMajor || major === ceilingMajor && minor > ceilingMinor;
4472
+ }
4473
+ function clampGoDirective(filePath) {
4474
+ if (!fileExists(filePath)) {
4475
+ return;
4476
+ }
4477
+ const before = (0, import_node_fs18.readFileSync)(filePath, "utf8");
4478
+ const directive = /^go\s+(\d+\.\d+(?:\.\d+)?)/m.exec(before);
4479
+ if (directive === null || !exceedsGoCeiling(directive[1])) {
4480
+ return;
4481
+ }
4482
+ const after = before.replace(/^go\s+\d+\.\d+(?:\.\d+)?/m, () => `go ${GO_DIRECTIVE_CEILING}`).replace(/^toolchain\s+\S+(?:\r?\n){1,2}/m, "");
4483
+ writeFileEnsured(filePath, after);
4484
+ }
4485
+ function pinGoDirective(workspaceRoot, projectDir) {
4486
+ clampGoDirective((0, import_node_path17.join)(workspaceRoot, projectDir, "go.mod"));
4487
+ clampGoDirective((0, import_node_path17.join)(workspaceRoot, "go.work"));
4488
+ }
4467
4489
  function writeGoAppExample(workspaceRoot, projectDir) {
4468
4490
  const goModPath = (0, import_node_path17.join)(workspaceRoot, projectDir, "go.mod");
4469
4491
  const modulePath = fileExists(goModPath) ? /^module\s+(\S+)/m.exec((0, import_node_fs18.readFileSync)(goModPath, "utf8"))?.[1] : void 0;
@@ -4654,6 +4676,7 @@ function addGoApp(workspaceRoot, name, options = {}) {
4654
4676
  workspaceRoot
4655
4677
  );
4656
4678
  setGoModulePath(workspaceRoot, `apps/${name}`);
4679
+ pinGoDirective(workspaceRoot, `apps/${name}`);
4657
4680
  if (options.web === void 0) {
4658
4681
  writeGoAppExample(workspaceRoot, `apps/${name}`);
4659
4682
  }
@@ -4696,6 +4719,7 @@ function addGoFunctionApp(workspaceRoot, name) {
4696
4719
  workspaceRoot
4697
4720
  );
4698
4721
  setGoModulePath(workspaceRoot, `apps/${name}`);
4722
+ pinGoDirective(workspaceRoot, `apps/${name}`);
4699
4723
  writeGoAppExample(workspaceRoot, `apps/${name}`);
4700
4724
  addProjectJsonTargets((0, import_node_path17.join)(workspaceRoot, "apps", name, "project.json"), {
4701
4725
  "build": goBuildTarget(name),
@@ -4721,6 +4745,7 @@ function addGoLib(workspaceRoot, name) {
4721
4745
  workspaceRoot
4722
4746
  );
4723
4747
  setGoModulePath(workspaceRoot, `packages/${name}`);
4748
+ pinGoDirective(workspaceRoot, `packages/${name}`);
4724
4749
  addProjectJsonTargets((0, import_node_path17.join)(workspaceRoot, "packages", name, "project.json"), {
4725
4750
  test: goTestTarget(),
4726
4751
  lint: goLintTarget()
@@ -4746,6 +4771,7 @@ function addGoInternalLib(workspaceRoot, name) {
4746
4771
  workspaceRoot
4747
4772
  );
4748
4773
  setGoModulePath(workspaceRoot, `libs/${name}`);
4774
+ pinGoDirective(workspaceRoot, `libs/${name}`);
4749
4775
  addProjectJsonTargets((0, import_node_path17.join)(workspaceRoot, "libs", name, "project.json"), {
4750
4776
  test: goTestTarget(),
4751
4777
  lint: goLintTarget()
@@ -5200,6 +5226,10 @@ function sourceMapCapableCompiler(indent) {
5200
5226
  ].join("\n");
5201
5227
  }
5202
5228
  var ROLLUP_ARG_ONE_BOUNDARY = [" },", " {", ""].join("\n");
5229
+ var ROLLUP_ARG_ONE_BOUNDARY_ONE_LINE = /^ {2}\},[ \t]*\{[ \t]*$/m;
5230
+ function withBoundaryOnTwoLines(config) {
5231
+ return config.replace(ROLLUP_ARG_ONE_BOUNDARY_ONE_LINE, () => ROLLUP_ARG_ONE_BOUNDARY.replace(/\n$/, ""));
5232
+ }
5203
5233
  var ROLLUP_ARG_ONE_WITH_SOURCE_MAPS = [
5204
5234
  " // Added by MoNecromanCI: without this rollup emits no .js.map at all, so",
5205
5235
  " // a breakpoint in a .ts file can never bind. Not published - see `files`.",
@@ -5212,12 +5242,13 @@ function hasRollupSourceMaps(config) {
5212
5242
  return /sourceMap\s*:\s*true\b/.test(config);
5213
5243
  }
5214
5244
  function canRepairRollupConfig(config) {
5215
- return config.includes(ROLLUP_ARG_ONE_BOUNDARY);
5245
+ return config.includes(ROLLUP_ARG_ONE_BOUNDARY) || ROLLUP_ARG_ONE_BOUNDARY_ONE_LINE.test(config);
5216
5246
  }
5217
- function withRollupSourceMaps(config) {
5218
- if (hasRollupSourceMaps(config) || !canRepairRollupConfig(config)) {
5219
- return config;
5247
+ function withRollupSourceMaps(original) {
5248
+ if (hasRollupSourceMaps(original) || !canRepairRollupConfig(original)) {
5249
+ return original;
5220
5250
  }
5251
+ const config = withBoundaryOnTwoLines(original);
5221
5252
  const withCompiler = config.replace(
5222
5253
  GENERATED_COMPILER_PATTERN,
5223
5254
  (_match, indent) => sourceMapCapableCompiler(indent)
@@ -5378,6 +5409,17 @@ function withUpgradedDeclarationSpecifierPlugin(config) {
5378
5409
  const [start, end] = span;
5379
5410
  return `${config.slice(0, start)}${DECLARATION_SPECIFIER_PLUGIN}${config.slice(end)}`;
5380
5411
  }
5412
+ var PLUGINS_ARRAY_OPEN = /^ {4}plugins\s*:\s*\[[ \t]*$/m;
5413
+ function canAddDeclarationSpecifierPlugin(config) {
5414
+ return !hasDeclarationSpecifierPlugin(config) && !config.includes(ROLLUP_CONFIG_PLACEHOLDER) && PLUGINS_ARRAY_OPEN.test(config);
5415
+ }
5416
+ function withDeclarationSpecifierPlugin(config) {
5417
+ if (!canAddDeclarationSpecifierPlugin(config)) {
5418
+ return config;
5419
+ }
5420
+ return config.replace(PLUGINS_ARRAY_OPEN, (opening) => `${opening}
5421
+ ${DECLARATION_SPECIFIER_PLUGIN},`);
5422
+ }
5381
5423
 
5382
5424
  // src/rollup-library/repair-rollup-config.use-case.ts
5383
5425
  function repairRollupSourceMaps(workspaceRoot) {
@@ -5419,11 +5461,33 @@ function repairDeclarationSpecifiers(projectRoot) {
5419
5461
  }
5420
5462
  const config = (0, import_node_fs22.readFileSync)(configPath, "utf8");
5421
5463
  if (!config.includes(ROLLUP_CONFIG_PLACEHOLDER)) {
5464
+ const repaired = withRollupSourceMaps(withDeclarationSpecifierPlugin(config));
5465
+ if (repaired !== config) {
5466
+ writeFileEnsured(configPath, repaired);
5467
+ } else if (!hasDeclarationSpecifierPlugin(config)) {
5468
+ logger.warn(`${configPath} has a shape mnci does not recognise, so its source maps and declaration repairs were not applied; \`mnci doctor\` names what to add by hand`);
5469
+ }
5422
5470
  return;
5423
5471
  }
5424
5472
  const withDtsFix = config.split(ROLLUP_CONFIG_PLACEHOLDER).join(ROLLUP_CONFIG_WITH_DTS_FIX);
5425
5473
  writeFileEnsured(configPath, withRollupSourceMaps(withDtsFix));
5426
5474
  }
5475
+ function addMissingDeclarationSpecifierPlugins(workspaceRoot) {
5476
+ const changed = [];
5477
+ const configs = (0, import_node_fs22.globSync)(["packages/*/rollup.config.cjs", "libs/*/rollup.config.cjs"], {
5478
+ cwd: workspaceRoot
5479
+ });
5480
+ for (const relativePath of configs) {
5481
+ const configPath = (0, import_node_path22.join)(workspaceRoot, relativePath);
5482
+ const before = (0, import_node_fs22.readFileSync)(configPath, "utf8");
5483
+ const after = withDeclarationSpecifierPlugin(before);
5484
+ if (after !== before) {
5485
+ writeFileEnsured(configPath, after);
5486
+ changed.push(relativePath.replaceAll("\\", "/"));
5487
+ }
5488
+ }
5489
+ return changed;
5490
+ }
5427
5491
 
5428
5492
  // src/rollup-library/rollup-config.repository.ts
5429
5493
  var import_node_fs23 = require("fs");
@@ -8186,7 +8250,7 @@ function checkRollupSourceMaps(workspaceRoot) {
8186
8250
  check: `source maps enabled in ${relativePath}`,
8187
8251
  ok: hasRollupSourceMaps(resolveRollupConfigText(configPath)),
8188
8252
  detail: "rollup emits no .js.map without it, so a breakpoint in a .ts file can never bind",
8189
- remedy: canRepairRollupConfig(config) ? "run `mnci upgrade`, which adds it to every rollup config" : "this config delegates via require() to a shared base mnci does not own \u2014 add `sourceMap: true` to withNx's first argument there by hand; `mnci upgrade` cannot repair a config in this shape"
8253
+ remedy: canRepairRollupConfig(config) ? "run `mnci upgrade`, which adds it to every rollup config" : "mnci does not recognise the shape of this config (it edits the boundary between withNx's two arguments, which is not here; a config that delegates via require() to a shared base is one such shape) \u2014 add `sourceMap: true` to withNx's first argument by hand; `mnci upgrade` cannot repair a config in this shape"
8190
8254
  }
8191
8255
  ];
8192
8256
  });
@@ -8207,15 +8271,11 @@ function checkDeclarationSpecifiers(workspaceRoot) {
8207
8271
  check: `${relativePath} normalises declaration specifiers`,
8208
8272
  ok: false,
8209
8273
  detail: "no mnci-normalise-declaration-specifiers plugin \u2014 the emitted .d.ts files keep the extensionless imports tsconfig.lib.json allows, which a nodenext consumer cannot resolve",
8210
- // Deliberately NOT `mnci upgrade`, which would send the user in a
8211
- // circle: `upgradeDeclarationSpecifierPlugins` only rewrites a
8212
- // plugin that is already there, and `repairDeclarationSpecifiers`
8213
- // is anchored on the generator's own placeholder comment, which a
8214
- // config in this state no longer has. Verified by running the
8215
- // command against exactly this shape — it no-ops. Naming a command
8216
- // that silently does nothing is the failure mode this file's own
8217
- // source-map check already goes out of its way to avoid.
8218
- remedy: "add the plugin to withNx's second argument by hand (copy it from a freshly `mnci add npm-lib`'d project) \u2014 `mnci upgrade` only updates a plugin that is already present, it cannot restore a missing one"
8274
+ // `mnci upgrade` adds the plugin only to a config whose second argument already has a
8275
+ // `plugins` array (what @nx/react:library writes). For any other shape it would no-op, and
8276
+ // naming a command that silently does nothing is the failure mode the source-map check
8277
+ // above goes out of its way to avoid, so the remedy depends on the shape.
8278
+ remedy: canAddDeclarationSpecifierPlugin((0, import_node_fs29.readFileSync)(configPath, "utf8")) ? "run `mnci upgrade`, which adds the plugin to the plugins array of withNx's second argument" : "add the plugin to withNx's second argument by hand (copy it from a freshly `mnci add npm-lib`'d project) \u2014 mnci does not recognise the shape of this config, so `mnci upgrade` cannot add it"
8219
8279
  }
8220
8280
  ];
8221
8281
  }
@@ -8919,6 +8979,13 @@ function runUpgrade(workspaceRoot, options) {
8919
8979
  logger.step("Registering the Go plugin in nx.json, so Nx can see which Go project imports which");
8920
8980
  logger.detail("updated nx.json");
8921
8981
  }
8982
+ const addedDtsPlugins = addMissingDeclarationSpecifierPlugins(workspaceRoot);
8983
+ if (addedDtsPlugins.length > 0) {
8984
+ logger.step("Adding the declaration-specifier plugin to rollup configs that lacked it");
8985
+ for (const path of addedDtsPlugins) {
8986
+ logger.detail(`updated ${path}`);
8987
+ }
8988
+ }
8922
8989
  const upgradedDtsPlugins = upgradeDeclarationSpecifierPlugins(workspaceRoot);
8923
8990
  if (upgradedDtsPlugins.length > 0) {
8924
8991
  logger.step("Upgrading declaration specifiers to resolve under nodenext");