@orkestrel/scaffold 0.0.129 → 0.0.130

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.
@@ -4,7 +4,7 @@ let _orkestrel_template = require("@orkestrel/template");
4
4
  let _orkestrel_emitter = require("@orkestrel/emitter");
5
5
  var package_default = {
6
6
  name: "@orkestrel/scaffold",
7
- version: "0.0.129",
7
+ version: "0.0.130",
8
8
  description: "Scaffold workspaces with commands: new, audit, surface, repair, catalog, and overwrite.",
9
9
  keywords: [
10
10
  "audit",
@@ -2755,10 +2755,15 @@ export interface DistributionClassification {
2755
2755
  readonly targets: readonly string[]
2756
2756
  }
2757
2757
 
2758
+ /** Holds the file, leading arguments, and shell route an npm run spawns with. */
2759
+ export interface DistributionNpmCommand {
2760
+ readonly file: string
2761
+ readonly prefix: readonly string[]
2762
+ readonly shell: boolean
2763
+ }
2764
+
2758
2765
  /** Names the workspace whose packed artifact the proof consumes. */
2759
2766
  export const DISTRIBUTION_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
2760
- /** Names the npm executable on the running host. */
2761
- export const DISTRIBUTION_NPM = process.platform === 'win32' ? 'npm.cmd' : 'npm'
2762
2767
  // The compiler this workspace installs, run as a command rather than called in
2763
2768
  // process: the command and its plain-text diagnostics are the same across the
2764
2769
  // compiler majors this toolchain supports, and its in-process API is not. It is
@@ -2771,12 +2776,6 @@ export const DISTRIBUTION_TYPESCRIPT = createRequire(
2771
2776
  ).resolve('typescript/package.json')
2772
2777
  /** Names the compiler installed by the workspace under proof. */
2773
2778
  export const DISTRIBUTION_COMPILER = join(dirname(DISTRIBUTION_TYPESCRIPT), 'bin', 'tsc')
2774
- // Windows needs a shell to launch a \`.cmd\`: Node refuses one directly since the
2775
- // batch-argument hardening, and \`spawnSync\` returns \`EINVAL\` with a null status
2776
- // rather than an exit code a caller can read. Every following argument is a literal or
2777
- // a path this file built, so the shell has nothing to escape.
2778
- /** Selects the Windows command-shell route required by the npm shim. */
2779
- export const DISTRIBUTION_SHELL = process.platform === 'win32'
2780
2779
  // \`prepublishOnly\` runs this proof as \`npm run test:distribution -- --mode release\`,
2781
2780
  // and the root configuration's project factories carry that mode into this project.
2782
2781
  // Release is the publish gate, so evidence it cannot obtain fails there and skips
@@ -3103,6 +3102,50 @@ export function readDistributionOutput(result: SpawnSyncReturns<string>): string
3103
3102
  return \`\${result.stdout ?? ''}\${result.stderr ?? ''}\`.trim()
3104
3103
  }
3105
3104
 
3105
+ /**
3106
+ * Resolves the npm command for the running host.
3107
+ *
3108
+ * @remarks
3109
+ * npm's JavaScript entry beside the running Node binary spawns without a shell on every host. The
3110
+ * shim is the fallback where none sits there, and Windows needs a shell to launch its \`.cmd\`: Node
3111
+ * refuses one directly since the batch-argument hardening, and \`spawnSync\` returns \`EINVAL\` with a
3112
+ * null status rather than an exit code a caller can read. Every argument this file passes is a
3113
+ * literal or a path it built, so the shell has nothing to escape.
3114
+ *
3115
+ * @returns The file to spawn, the arguments that precede npm's own, and whether it needs a shell.
3116
+ */
3117
+ export function resolveDistributionNpm(): DistributionNpmCommand {
3118
+ const cli = join(dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js')
3119
+ if (existsSync(cli)) return { file: process.execPath, prefix: [cli], shell: false }
3120
+ const windows = process.platform === 'win32'
3121
+ return { file: windows ? 'npm.cmd' : 'npm', prefix: [], shell: windows }
3122
+ }
3123
+
3124
+ /**
3125
+ * Merges added variables over an inherited environment by case-folded name.
3126
+ *
3127
+ * @remarks
3128
+ * A Windows environment block folds names by case, and npm reads its \`npm_config_\` variables
3129
+ * case-insensitively on every host, so every inherited name an added name claims is dropped first:
3130
+ * an inherited \`NPM_CONFIG_CACHE\` would otherwise outrank an added \`npm_config_cache\`.
3131
+ *
3132
+ * @param inherited - The environment the child would inherit.
3133
+ * @param added - The variables the call sets.
3134
+ * @returns The merged environment.
3135
+ */
3136
+ export function mergeDistributionEnvironment(
3137
+ inherited: Readonly<Record<string, string | undefined>>,
3138
+ added: Readonly<Record<string, string>>,
3139
+ ): Readonly<Record<string, string | undefined>> {
3140
+ const claimed = new Set(Object.keys(added).map((name) => name.toLowerCase()))
3141
+ return {
3142
+ ...Object.fromEntries(
3143
+ Object.entries(inherited).filter(([name]) => !claimed.has(name.toLowerCase())),
3144
+ ),
3145
+ ...added,
3146
+ }
3147
+ }
3148
+
3106
3149
  /**
3107
3150
  * Runs npm with a cache inside the owned scratch directory.
3108
3151
  *
@@ -3116,11 +3159,12 @@ export function runDistributionNpm(
3116
3159
  cwd: string,
3117
3160
  scratch: string,
3118
3161
  ): SpawnSyncReturns<string> {
3119
- return spawnSync(DISTRIBUTION_NPM, [...args], {
3162
+ const npm = resolveDistributionNpm()
3163
+ return spawnSync(npm.file, [...npm.prefix, ...args], {
3120
3164
  cwd,
3121
3165
  encoding: 'utf8',
3122
- env: { ...process.env, npm_config_cache: join(scratch, 'cache') },
3123
- shell: DISTRIBUTION_SHELL,
3166
+ env: mergeDistributionEnvironment(process.env, { npm_config_cache: join(scratch, 'cache') }),
3167
+ shell: npm.shell,
3124
3168
  windowsHide: true,
3125
3169
  })
3126
3170
  }