@mnci/cli 4.1.2 → 4.1.4

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
@@ -206,9 +206,63 @@ var import_node_path = require("path");
206
206
  function readJson(path) {
207
207
  return JSON.parse((0, import_node_fs.readFileSync)(path, "utf8"));
208
208
  }
209
+ function stripJsonComments(text) {
210
+ let result = "";
211
+ let inString = false;
212
+ let inLineComment = false;
213
+ let inBlockComment = false;
214
+ for (let i = 0; i < text.length; i++) {
215
+ const char = text[i];
216
+ if (inLineComment) {
217
+ if (char === "\n") {
218
+ inLineComment = false;
219
+ result += char;
220
+ }
221
+ continue;
222
+ }
223
+ const next = text[i + 1];
224
+ if (inBlockComment) {
225
+ if (char === "*" && next === "/") {
226
+ inBlockComment = false;
227
+ i++;
228
+ }
229
+ continue;
230
+ }
231
+ if (inString) {
232
+ result += char;
233
+ if (char === "\\") {
234
+ result += next;
235
+ i++;
236
+ continue;
237
+ }
238
+ if (char === '"') {
239
+ inString = false;
240
+ }
241
+ continue;
242
+ }
243
+ if (char === '"') {
244
+ inString = true;
245
+ result += char;
246
+ continue;
247
+ }
248
+ if (char === "/" && next === "/") {
249
+ inLineComment = true;
250
+ i++;
251
+ continue;
252
+ }
253
+ if (char === "/" && next === "*") {
254
+ inBlockComment = true;
255
+ i++;
256
+ continue;
257
+ }
258
+ result += char;
259
+ }
260
+ return result;
261
+ }
209
262
  function readCodeWorkspace(path) {
210
263
  try {
211
- return JSON.parse((0, import_node_fs.readFileSync)(path, "utf8").replaceAll(/,(\s*[}\]])/g, "$1"));
264
+ const withoutComments = stripJsonComments((0, import_node_fs.readFileSync)(path, "utf8"));
265
+ return JSON.parse(withoutComments.replaceAll(/,(\s*[}\]])/g, "$1"));
212
266
  } catch {
213
267
  return void 0;
214
268
  }
@@ -745,7 +799,7 @@ var FLUTTER_PUB_GET_GUARD = `node -e "const fs=require('node:fs');if(!fs.existsS
745
799
  var NPM_AUDIT_STEP = `node -e "const cp=require('node:child_process');const r=cp.spawnSync('npm',['audit','--json'],{encoding:'utf8',shell:process.platform==='win32',maxBuffer:33554432});let d;try{d=JSON.parse(r.stdout)}catch{console.log('npm audit produced no JSON (exit '+r.status+') - not blocking on a broken audit.');process.exit(0)}const all=Object.values(d.vulnerabilities||{});const BLOCK=['critical','high','moderate'];const act=all.filter(v=>v.fixAvailable&&BLOCK.includes(v.severity));const rest=all.filter(v=>!act.includes(v));for(const v of rest)console.log(' note ['+v.severity+'] '+v.name+(v.fixAvailable?' - fix available, below the blocking threshold':' - NO fix available upstream, nothing to do here'));if(act.length===0){console.log('npm audit - '+all.length+' advisory(ies), none actionable at moderate or above.');process.exit(0)}for(const v of act)console.log(' BLOCKING ['+v.severity+'] '+v.name+' - fix available'+(v.fixAvailable&&v.fixAvailable.isSemVerMajor?' (semver-major)':''));console.log('Each has a published fix. Add a targeted overrides entry in package.json rather than npm audit fix --force.');process.exit(1)"`;
746
800
  var VERIFY_TARGETS = "lint,typecheck,test,build";
747
801
  var AFFECTED_OR_ALL_GUARD = `node -e "const cp=require('node:child_process');const T='${VERIFY_TARGETS}';const all=()=>process.exit(cp.spawnSync('npx nx run-many -t '+T,{stdio:'inherit',shell:true}).status ?? 1);const ref=process.env.GITHUB_BASE_REF||process.env.SYSTEM_PULLREQUEST_TARGETBRANCH||'';if(!ref){console.log('Not a pull request - verifying EVERY project.');all()}const target=ref.replace('refs/heads/','');const mergeBase=r=>{const o=cp.spawnSync('git',['merge-base',r,'HEAD'],{encoding:'utf8'});return o.status===0?o.stdout.trim():''};let base=mergeBase('origin/'+target);if(!base){console.log('No origin/'+target+' ref - fetching it to resolve a merge-base.');cp.spawnSync('git',['fetch','--no-tags','origin',target],{stdio:'inherit'});base=mergeBase('FETCH_HEAD')}if(!base){console.log('Could not resolve a merge-base with '+target+' - verifying EVERY project.');all()}console.log('Pull request against '+target+' - verifying projects affected since '+base);process.exit(cp.spawnSync('npx nx affected -t '+T+' --base='+base,{stdio:'inherit',shell:true}).status ?? 1)"`;
748
- var PACK_APPS_GUARD = `node -e "const fs=require('node:fs');fs.mkdirSync('dist/drop',{recursive:true});if(fs.globSync('apps/*/project.json').length===0){console.log('No apps to pack - skipping.');process.exit(0)}process.exit(require('node:child_process').spawnSync('npx nx run-many -t package',{stdio:'inherit',shell:true}).status ?? 1)"`;
802
+ var PACK_APPS_GUARD = `node -e "const fs=require('node:fs');fs.mkdirSync('dist/drop',{recursive:true});const hasProjectJson=fs.globSync('apps/*/project.json').length>0;const hasInlineNx=fs.globSync('apps/*/package.json').some((f)=>{try{return Boolean(JSON.parse(fs.readFileSync(f,'utf8')).nx)}catch{return false}});if(!hasProjectJson&&!hasInlineNx){console.log('No apps to pack - skipping.');process.exit(0)}process.exit(require('node:child_process').spawnSync('npx nx run-many -t package',{stdio:'inherit',shell:true}).status ?? 1)"`;
749
803
  function releaseGuard(pythonPublishEnv) {
750
804
  return `node -e "const fs=require('node:fs'),cp=require('node:child_process');const hasNpm=fs.globSync('packages/*/package.json').length>0;const hasPython=fs.globSync('python-packages/*/pyproject.toml').length>0;if(!hasNpm&&!hasPython){console.log('Nothing to release - skipping.');process.exit(0)}const env={...process.env};${pythonPublishEnv}process.exit(cp.spawnSync('npx nx release --yes',{stdio:'inherit',shell:true,env}).status ?? 1)"`;
751
805
  }
@@ -1419,10 +1473,13 @@ var ROLLUP_ARG_ONE_WITH_SOURCE_MAPS = [
1419
1473
  ""
1420
1474
  ].join("\n");
1421
1475
  function hasRollupSourceMaps(config) {
1422
- return config.includes("sourceMap: true");
1476
+ return /sourceMap\s*:\s*true\b/.test(config);
1477
+ }
1478
+ function canRepairRollupConfig(config) {
1479
+ return config.includes(ROLLUP_ARG_ONE_BOUNDARY);
1423
1480
  }
1424
1481
  function withRollupSourceMaps(config) {
1425
- if (hasRollupSourceMaps(config) || !config.includes(ROLLUP_ARG_ONE_BOUNDARY)) {
1482
+ if (hasRollupSourceMaps(config) || !canRepairRollupConfig(config)) {
1426
1483
  return config;
1427
1484
  }
1428
1485
  const withCompiler = config.replace(GENERATED_COMPILER, () => SOURCE_MAP_CAPABLE_COMPILER);
@@ -1451,6 +1508,28 @@ function repairRollupSourceMaps(workspaceRoot) {
1451
1508
  }
1452
1509
  return changed;
1453
1510
  }
1511
+ function resolveRequireTarget(fromDir, specifier) {
1512
+ const base = (0, import_node_path3.join)(fromDir, specifier);
1513
+ return [base, `${base}.cjs`, `${base}.js`].find((candidate) => fileExists(candidate));
1514
+ }
1515
+ function resolveRollupConfigText(configPath, visited = /* @__PURE__ */ new Set()) {
1516
+ if (visited.has(configPath)) {
1517
+ return "";
1518
+ }
1519
+ visited.add(configPath);
1520
+ let text;
1521
+ try {
1522
+ text = (0, import_node_fs3.readFileSync)(configPath, "utf8");
1523
+ } catch {
1524
+ return "";
1525
+ }
1526
+ const specifiers = Array.from(
1527
+ text.matchAll(/require\((['"])(\.[^'"]*)\1\)/g),
1528
+ (match) => match[2]
1529
+ );
1530
+ const requiredText = specifiers.map((specifier) => resolveRequireTarget((0, import_node_path3.dirname)(configPath), specifier)).filter((target) => target !== void 0).map((target) => resolveRollupConfigText(target, visited));
1531
+ return [text, ...requiredText].join("\n");
1532
+ }
1454
1533
  var SOURCEMAP_PATH_TRANSFORM = [
1455
1534
  " // Added by MoNecromanCI. rollup hands sourcemapPathTransform an OS-NATIVE",
1456
1535
  " // path with one parent segment too many, so `sources` resolve to nothing",
@@ -3457,18 +3536,19 @@ function checkRollupSourceMaps(workspaceRoot) {
3457
3536
  cwd: workspaceRoot
3458
3537
  }).map((config) => toPosix2(config));
3459
3538
  return configs.flatMap((relativePath) => {
3539
+ const configPath = (0, import_node_path14.join)(workspaceRoot, relativePath);
3460
3540
  let config;
3461
3541
  try {
3462
- config = (0, import_node_fs8.readFileSync)((0, import_node_path14.join)(workspaceRoot, relativePath), "utf8");
3542
+ config = (0, import_node_fs8.readFileSync)(configPath, "utf8");
3463
3543
  } catch {
3464
3544
  return [];
3465
3545
  }
3466
3546
  return [
3467
3547
  {
3468
3548
  check: `source maps enabled in ${relativePath}`,
3469
- ok: hasRollupSourceMaps(config),
3549
+ ok: hasRollupSourceMaps(resolveRollupConfigText(configPath)),
3470
3550
  detail: "rollup emits no .js.map without it, so a breakpoint in a .ts file can never bind",
3471
- remedy: "run `mnci upgrade`, which adds it to every rollup config"
3551
+ 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"
3472
3552
  }
3473
3553
  ];
3474
3554
  });