strutvane 0.1.0-next.0 → 0.2.0-next.0

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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"launcher-BrUi5a5_.mjs","names":[],"sources":["../src/launcher.ts"],"sourcesContent":["/**\n * The `strutvane` launcher (docs/09 §1.1).\n *\n * Installed globally or run through `npx strutvane`, it finds the project-local\n * `@strutvane/cli` and hands project commands to it, so generators and runtime always match the\n * versions pinned in the project's package.json. **Local wins over global for project commands.**\n *\n * **Which folder counts as a project.** Running a `node_modules` folder means running its code, so\n * the search is deliberately narrow. From the working directory (or `--cwd`) upwards, a folder is\n * used only when:\n * - it is a project: its package.json declares `@strutvane/cli` (dependencies or devDependencies)\n * or it contains `strutvane.config.ts`;\n * - it is not a file-system or drive root, not the OS temp directory itself and not a folder above\n * the user's home directory (the search stops at any of these);\n * - on POSIX, it is owned by the current user.\n * A folder with `strutvane.config.ts` also ends the search. See {@link findLocalCli}.\n *\n * **Never delegated:** `--version`, `help` (and no command at all), `new` and `create`. These are\n * the commands people run outside projects, so the launcher always answers them itself.\n *\n * Without a local CLI only project-less commands run: `--version`, `help`, `new <name>` (via\n * `create-strutvane`) and `doctor --global` (via `@strutvane/cli` matching this launcher).\n *\n * The launcher has zero dependencies and does no parsing beyond what delegation needs; it is\n * deliberately tiny so it never has to change when the CLI does. The project boundary rules are\n * mirrored in `@strutvane/cli`'s `project/boundary.ts` (the launcher cannot import it); keep the\n * two in step.\n *\n * @module\n */\nimport { spawn } from 'node:child_process'\nimport { existsSync, readFileSync, realpathSync, statSync } from 'node:fs'\nimport { homedir, tmpdir } from 'node:os'\nimport { dirname, isAbsolute, join, relative, resolve, win32 } from 'node:path'\n\n/** Environment variable carrying the delegation depth (guards against delegation loops). */\nexport const DEPTH_ENV = 'STRUTVANE_LAUNCHER_DEPTH'\n/** Overrides the project starter command (a JSON array), e.g. for tests or mirrors. */\nexport const CREATE_ENV = 'STRUTVANE_CREATE_COMMAND'\n/** Set to `1` to silence the version-mismatch notice. */\nexport const NO_NOTICE_ENV = 'STRUTVANE_NO_UPDATE_NOTICE'\n\n/** The file that marks a Strutvane project root. */\nexport const PROJECT_MARKER = 'strutvane.config.ts'\n\n/** A project-local CLI the launcher can delegate to. */\nexport interface LocalCli {\n readonly packageDir: string\n /** The manifest's version, with control characters removed (safe to print). */\n readonly version: string\n /** Absolute path of the CLI's executable script. */\n readonly bin: string\n}\n\n/**\n * Facts the project boundary rules depend on. Injectable so tests can place \"home\" and \"temp\"\n * anywhere, and exercise the POSIX ownership rule on any OS.\n */\nexport interface BoundaryFacts {\n /** The user's home directory. */\n readonly home: string\n /** The OS temp directory. */\n readonly temp: string\n /** The current user's uid on POSIX; `undefined` where ownership is not checked (Windows). */\n readonly uid: number | undefined\n}\n\n/** The boundary facts of this process. */\nexport function processBoundary(): BoundaryFacts {\n return {\n home: homedir(),\n temp: tmpdir(),\n uid: typeof process.getuid === 'function' ? process.getuid() : undefined,\n }\n}\n\nfunction readJson(path: string): Record<string, unknown> | undefined {\n try {\n const parsed: unknown = JSON.parse(readFileSync(path, 'utf8').replace(/^/, ''))\n return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)\n ? (parsed as Record<string, unknown>)\n : undefined\n } catch {\n return undefined\n }\n}\n\n// biome-ignore lint/suspicious/noControlCharactersInRegex: matching control characters is the point\nconst CONTROL = /[\\u0000-\\u001f\\u007f-\\u009f]/g\n\n/**\n * Remove control characters (ANSI escapes, line breaks…) from text that came from a file the\n * launcher does not control, before it is printed to a terminal.\n */\nexport function printable(text: string): string {\n return text.replace(CONTROL, '')\n}\n\n/** Every spelling of a path worth comparing: as given and with symlinks resolved. */\nfunction spellings(path: string): string[] {\n const out = [resolve(path)]\n try {\n out.push(realpathSync(path))\n } catch {\n // a path that does not exist has only its given spelling\n }\n return out\n}\n\n/** Path equality; case-insensitive on Windows and macOS, whose file systems usually are. */\nfunction samePath(a: string, b: string): boolean {\n const fold = process.platform === 'win32' || process.platform === 'darwin'\n const norm = (p: string): string => {\n const r = resolve(p)\n return fold ? r.toLowerCase() : r\n }\n return norm(a) === norm(b)\n}\n\n/** Whether `ancestor` is a strict ancestor of `path`. */\nfunction isStrictAncestor(ancestor: string, path: string): boolean {\n const rel = relative(ancestor, path)\n return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)\n}\n\n/**\n * Whether `dir` may never be treated as a project: a file-system or drive root, the OS temp\n * directory itself, or a folder above the user's home directory. Anyone with write access to\n * those (other users, downloads, extracted archives) could otherwise plant a `node_modules` that\n * runs for every command typed below them.\n */\nexport function isForbiddenProjectDir(dir: string, facts: BoundaryFacts): boolean {\n for (const d of spellings(dir)) {\n if (dirname(d) === d) return true\n for (const temp of spellings(facts.temp)) if (samePath(d, temp)) return true\n for (const home of spellings(facts.home)) if (isStrictAncestor(d, home)) return true\n }\n return false\n}\n\n/** POSIX only: whether `dir` is owned by the current user. Always `true` without a uid. */\nexport function isOwnedByCurrentUser(dir: string, facts: BoundaryFacts): boolean {\n if (facts.uid === undefined) return true\n try {\n return statSync(dir).uid === facts.uid\n } catch {\n return false\n }\n}\n\n/** Whether a package.json declares `@strutvane/cli` as a dependency or devDependency. */\nexport function declaresCli(manifest: Readonly<Record<string, unknown>> | undefined): boolean {\n if (manifest === undefined) return false\n return ['dependencies', 'devDependencies'].some((field) => {\n const deps = manifest[field]\n return (\n typeof deps === 'object' &&\n deps !== null &&\n Object.hasOwn(deps, '@strutvane/cli') &&\n typeof (deps as Record<string, unknown>)['@strutvane/cli'] === 'string'\n )\n })\n}\n\n/** The executable declared by a CLI manifest, if it resolves inside the package. */\nfunction binOf(packageDir: string, manifest: Record<string, unknown>): string | undefined {\n const bin = manifest['bin']\n const rel =\n typeof bin === 'string'\n ? bin\n : typeof bin === 'object' && bin !== null\n ? ((bin as Record<string, unknown>)['strutvane-cli'] ?? Object.values(bin)[0])\n : undefined\n if (typeof rel !== 'string') return undefined\n const path = resolve(packageDir, rel)\n if (!existsSync(path)) return undefined\n const realDir = realpathSync(packageDir)\n const inner = relative(realDir, realpathSync(path))\n return inner.startsWith('..') || isAbsolute(inner) ? undefined : path\n}\n\n/**\n * Find the project-local `@strutvane/cli`, searching upwards from `start` under the boundary\n * rules in the module documentation. Returns `undefined` when there is none (or none that may be\n * trusted).\n */\nexport function findLocalCli(\n start: string,\n facts: BoundaryFacts = processBoundary(),\n): LocalCli | undefined {\n let dir = resolve(start)\n for (;;) {\n if (isForbiddenProjectDir(dir, facts)) return undefined\n const hasMarker = existsSync(join(dir, PROJECT_MARKER))\n const isProject = hasMarker || declaresCli(readJson(join(dir, 'package.json')))\n if (isProject && isOwnedByCurrentUser(dir, facts)) {\n const packageDir = join(dir, 'node_modules', '@strutvane', 'cli')\n const manifest = readJson(join(packageDir, 'package.json'))\n if (manifest !== undefined) {\n const bin = binOf(packageDir, manifest)\n if (bin !== undefined) {\n const raw = typeof manifest['version'] === 'string' ? manifest['version'] : '0.0.0'\n return { packageDir, version: printable(raw).slice(0, 64), bin }\n }\n }\n }\n if (hasMarker) return undefined // project root: stop\n const parent = dirname(dir)\n if (parent === dir) return undefined\n dir = parent\n }\n}\n\n/** The `--cwd` value from argv, if any (`--cwd x` or `--cwd=x`). */\nexport function cwdFlag(argv: readonly string[]): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const token = argv[i] ?? ''\n if (token === '--') return undefined\n if (token === '--cwd') return argv[i + 1]\n if (token.startsWith('--cwd=')) return token.slice('--cwd='.length)\n }\n return undefined\n}\n\n/** The leading command word of argv (skipping flags and the `--cwd` value), if any. */\nexport function commandWord(argv: readonly string[]): string | undefined {\n for (let i = 0; i < argv.length; i++) {\n const token = argv[i] ?? ''\n if (token === '--') return undefined\n if (token === '--cwd') {\n i++\n continue\n }\n if (!token.startsWith('-')) return token\n }\n return undefined\n}\n\n/** Commands the launcher always answers itself, even inside a project. */\nconst LAUNCHER_COMMANDS: ReadonlySet<string> = new Set(['help', 'new', 'create'])\n\n/**\n * Whether argv is a command the launcher answers itself and never delegates: no command word\n * (`strutvane`, `strutvane --version`, `strutvane --help`), `help`, `new` or `create`.\n */\nexport function isLauncherCommand(argv: readonly string[]): boolean {\n const word = commandWord(argv)\n return word === undefined || LAUNCHER_COMMANDS.has(word)\n}\n\n/** Runs a child process with inherited stdio and resolves with its exit code. */\nexport type LaunchSpawner = (\n command: string,\n args: readonly string[],\n options: { readonly env: NodeJS.ProcessEnv; readonly shell: boolean },\n) => Promise<number>\n\nconst SIGNAL_CODES: Readonly<Record<string, number>> = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 }\n\n/** The real spawner: inherits stdio and ignores Ctrl+C itself so the child decides. */\nexport const nodeLaunchSpawner: LaunchSpawner = (command, args, options) =>\n new Promise((resolvePromise, reject) => {\n const ignore = (): void => {}\n process.on('SIGINT', ignore)\n const child = spawn(command, [...args], {\n stdio: 'inherit',\n env: options.env,\n shell: options.shell,\n })\n child.on('error', (error) => {\n process.off('SIGINT', ignore)\n reject(error)\n })\n child.on('exit', (code, signal) => {\n process.off('SIGINT', ignore)\n resolvePromise(code ?? (signal === null ? 1 : (SIGNAL_CODES[signal] ?? 1)))\n })\n })\n\n/** Process facts the launcher needs (injectable for tests). */\nexport interface LauncherEnvironment {\n readonly cwd: string\n readonly env: NodeJS.ProcessEnv\n readonly execPath: string\n readonly platform: NodeJS.Platform\n readonly version: string\n readonly stdout: (text: string) => void\n readonly stderr: (text: string) => void\n readonly spawn: LaunchSpawner\n /** Project boundary facts. Default: this process's ({@link processBoundary}). */\n readonly boundary?: BoundaryFacts\n}\n\n/** Characters allowed in arguments that pass through a Windows shell (the npx.cmd fallback). */\nconst SHELL_SAFE = /^[A-Za-z0-9@._/:=+,-]+$/\n/** Characters allowed in an absolute shim path that is quoted for cmd.exe. */\nconst SHELL_SAFE_PATH = /^[^\"%!^&|<>\\r\\n]+$/\n\n/**\n * Environment for child processes. On Windows, `NoDefaultCurrentDirectoryInExePath` stops\n * cmd.exe (and the `.cmd` shims it runs) from finding programs in the working directory before\n * PATH, so a project folder can never shadow `node` or `npm`.\n */\nexport function childEnv(\n env: NodeJS.ProcessEnv,\n platform: NodeJS.Platform,\n extra: Readonly<Record<string, string>> = {},\n): NodeJS.ProcessEnv {\n return {\n ...env,\n ...(platform === 'win32' ? { NoDefaultCurrentDirectoryInExePath: '1' } : {}),\n ...extra,\n }\n}\n\n/**\n * npm's `npx-cli.js` next to the running Node.js, so npx runs as `node npx-cli.js` with no shell\n * and no PATH lookup. Windows installs keep npm in `<node dir>/node_modules/npm`; POSIX installs\n * in `<prefix>/lib/node_modules/npm`.\n */\nexport function findNpxCli(execPath: string, platform: NodeJS.Platform): string | undefined {\n const p = platform === 'win32' ? win32 : { join, dirname }\n const dir = p.dirname(execPath)\n const candidates =\n platform === 'win32'\n ? [p.join(dir, 'node_modules', 'npm', 'bin', 'npx-cli.js')]\n : [\n p.join(dir, '..', 'lib', 'node_modules', 'npm', 'bin', 'npx-cli.js'),\n p.join(dir, 'node_modules', 'npm', 'bin', 'npx-cli.js'),\n ]\n return candidates.find((c) => existsSync(c))\n}\n\n/**\n * Windows only: the absolute path of `name` (e.g. `npx`) from PATH, trying each PATHEXT\n * extension. The working directory, relative PATH entries and empty entries are skipped, which is\n * exactly the lookup order cmd.exe would otherwise use to run a planted `npx.cmd` from the\n * project folder.\n */\nexport function resolveWindowsExecutable(\n name: string,\n env: NodeJS.ProcessEnv,\n cwd: string,\n exists: (path: string) => boolean = existsSync,\n): string | undefined {\n const pathValue = env['PATH'] ?? env['Path'] ?? ''\n const exts = (env['PATHEXT'] ?? '.COM;.EXE;.BAT;.CMD').split(';').filter((e) => e.startsWith('.'))\n const here = win32.resolve(cwd).toLowerCase()\n for (const entry of pathValue.split(';')) {\n const dir = entry.trim().replace(/^\"(.*)\"$/, '$1')\n if (dir === '' || !win32.isAbsolute(dir) || win32.resolve(dir).toLowerCase() === here) continue\n for (const ext of exts) {\n const candidate = win32.join(dir, `${name}${ext.toLowerCase()}`)\n if (exists(candidate)) return candidate\n }\n }\n return undefined\n}\n\nfunction help(version: string, local: LocalCli | undefined): string {\n const lines = [`strutvane ${version}: the Strutvane command line launcher`, '']\n if (local === undefined) {\n lines.push('No project-local @strutvane/cli was found, so only these commands are available:')\n } else {\n lines.push(\n `This project uses @strutvane/cli ${local.version}; it handles every project command`,\n '(e.g. strutvane make:model Invoice, strutvane migrate). To list them all, run:',\n ' pnpm exec strutvane-cli help (or: npx strutvane-cli help)',\n '',\n 'The launcher itself answers:',\n )\n }\n lines.push(\n ' strutvane new <name> [flags] Create a project (runs create-strutvane)',\n ' strutvane doctor --global Check this machine (Node.js version, package managers)',\n ' strutvane --version Print the launcher version',\n ' strutvane help Show this help',\n '',\n )\n if (local === undefined) {\n lines.push(\n 'Inside a project (a folder whose package.json lists @strutvane/cli, or with',\n \"strutvane.config.ts), project commands are handled by the project's own @strutvane/cli,\",\n 'so they always match the versions in package.json.',\n '',\n )\n }\n return lines.join('\\n')\n}\n\n/** Parse `STRUTVANE_CREATE_COMMAND`: a non-empty JSON array of strings, else `undefined`. */\nfunction parseCommandOverride(value: string): string[] | undefined {\n let parsed: unknown\n try {\n parsed = JSON.parse(value)\n } catch {\n return undefined\n }\n if (\n !Array.isArray(parsed) ||\n parsed.length === 0 ||\n !parsed.every((p) => typeof p === 'string' && p !== '')\n ) {\n return undefined\n }\n return parsed as string[]\n}\n\n/** Run a project-less command through npx (or the override in `STRUTVANE_CREATE_COMMAND`). */\nasync function viaNpx(\n env: LauncherEnvironment,\n pkg: string,\n args: readonly string[],\n): Promise<number> {\n const childEnvironment = childEnv(env.env, env.platform)\n const override = env.env[CREATE_ENV]\n if (override !== undefined && pkg.startsWith('create-strutvane')) {\n const parsed = parseCommandOverride(override)\n if (parsed === undefined) {\n env.stderr(`strutvane: ${CREATE_ENV} must be a JSON array of strings.\\n`)\n return 2\n }\n const [command = '', ...rest] = parsed\n return env.spawn(command, [...rest, ...args], { env: childEnvironment, shell: false })\n }\n const npxArgs = ['--yes', pkg, ...args]\n // Preferred everywhere: `node npx-cli.js …` (no shell, no PATH lookup, any argument is safe).\n const npxCli = findNpxCli(env.execPath, env.platform)\n if (npxCli !== undefined) {\n return env.spawn(env.execPath, [npxCli, ...npxArgs], { env: childEnvironment, shell: false })\n }\n if (env.platform !== 'win32') {\n return env.spawn('npx', npxArgs, { env: childEnvironment, shell: false })\n }\n // Windows fallback: npx is a .cmd shim, which needs a shell. Resolve it from PATH (never the\n // working directory) and refuse arguments with shell meaning rather than escaping them.\n const shim = resolveWindowsExecutable('npx', env.env, env.cwd)\n if (shim === undefined || !SHELL_SAFE_PATH.test(shim)) {\n env.stderr('strutvane: could not find npx on PATH. Install Node.js with npm.\\n')\n return 2\n }\n const unsafe = npxArgs.find((a) => !SHELL_SAFE.test(a))\n if (unsafe !== undefined) {\n env.stderr(\n `strutvane: refusing to pass \"${printable(unsafe)}\" to a shell. Use plain names and flags.\\n`,\n )\n return 2\n }\n return env.spawn(`\"${shim}\"`, npxArgs, { env: childEnvironment, shell: true })\n}\n\n/** Run the launcher. Returns the exit code (the delegated CLI's, when delegating). */\nexport async function runLauncher(\n argv: readonly string[],\n env: LauncherEnvironment,\n): Promise<number> {\n const depth = Number(env.env[DEPTH_ENV] ?? '0')\n const flag = cwdFlag(argv)\n const start = flag === undefined ? env.cwd : resolve(env.cwd, flag)\n const boundary = env.boundary ?? processBoundary()\n const local = depth >= 1 ? undefined : findLocalCli(start, boundary)\n\n if (local !== undefined && !isLauncherCommand(argv)) {\n const quiet = argv.includes('--json') || argv.includes('--quiet') || argv.includes('-q')\n if (local.version !== env.version && !quiet && env.env[NO_NOTICE_ENV] !== '1') {\n env.stderr(\n `strutvane: using the project's @strutvane/cli ${local.version} (launcher ${env.version}).\\n`,\n )\n }\n return env.spawn(env.execPath, [local.bin, ...argv], {\n env: childEnv(env.env, env.platform, { [DEPTH_ENV]: String(depth + 1) }),\n shell: false,\n })\n }\n\n const word = commandWord(argv)\n if (word === undefined && (argv.includes('--version') || argv.includes('-V'))) {\n env.stdout(`strutvane ${env.version}\\n`)\n if (local !== undefined) env.stdout(`project @strutvane/cli ${local.version}\\n`)\n return 0\n }\n if (word === undefined || word === 'help') {\n env.stdout(help(env.version, local))\n return 0\n }\n const [first, ...rest] = argv\n if (first === 'new' || first === 'create') {\n return viaNpx(env, 'create-strutvane@latest', rest)\n }\n if (first === 'doctor' && rest.includes('--global')) {\n return viaNpx(env, `@strutvane/cli@${env.version}`, argv)\n }\n env.stderr(\n [\n `strutvane: \"${printable(word)}\" needs a Strutvane project, but no project-local @strutvane/cli was found`,\n ` (searched from ${start} upwards; only folders whose package.json lists @strutvane/cli`,\n ' or that contain strutvane.config.ts count, and never a drive root, the temp folder or a',\n ' folder above your home directory).',\n ' Run it inside a project, or add the CLI to this one: pnpm add -D @strutvane/cli',\n ' Create a new project with: strutvane new <name>',\n '',\n ].join('\\n'),\n )\n return 2\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,YAAY;;AAEzB,MAAa,aAAa;;AAE1B,MAAa,gBAAgB;;AAG7B,MAAa,iBAAiB;;AAyB9B,SAAgB,kBAAiC;CAC/C,OAAO;EACL,MAAM,QAAQ;EACd,MAAM,OAAO;EACb,KAAK,OAAO,QAAQ,WAAW,aAAa,QAAQ,OAAO,IAAI,KAAA;CACjE;AACF;AAEA,SAAS,SAAS,MAAmD;CACnE,IAAI;EACF,MAAM,SAAkB,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,EAAE,CAAC;EAC/E,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,CAAC,MAAM,QAAQ,MAAM,IACxE,SACD,KAAA;CACN,QAAQ;EACN;CACF;AACF;AAGA,MAAM,UAAU;;;;;AAMhB,SAAgB,UAAU,MAAsB;CAC9C,OAAO,KAAK,QAAQ,SAAS,EAAE;AACjC;;AAGA,SAAS,UAAU,MAAwB;CACzC,MAAM,MAAM,CAAC,QAAQ,IAAI,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,CAAC,EAAE,CAAC;GACvE,OAAO;EACT,CAAC;CACH;CAEA,MAAM,OAAO,YAAY,IAAI;CAC7B,IAAI,SAAS,KAAA,MAAc,KAAK,SAAS,WAAW,KAAK,KAAK,SAAS,IAAI,IAAI;EAC7E,IAAI,OAAO,aAAa,IAAI,QAAQ,GAAG;EACvC,IAAI,UAAU,KAAA,GAAW,IAAI,OAAO,0BAA0B,MAAM,QAAQ,GAAG;EAC/E,OAAO;CACT;CACA,IAAI,SAAS,KAAA,KAAa,SAAS,QAAQ;EACzC,IAAI,OAAO,KAAK,IAAI,SAAS,KAAK,CAAC;EACnC,OAAO;CACT;CACA,MAAM,CAAC,OAAO,GAAG,QAAQ;CACzB,IAAI,UAAU,SAAS,UAAU,UAC/B,OAAO,OAAO,KAAK,2BAA2B,IAAI;CAEpD,IAAI,UAAU,YAAY,KAAK,SAAS,UAAU,GAChD,OAAO,OAAO,KAAK,kBAAkB,IAAI,WAAW,IAAI;CAE1D,IAAI,OACF;EACE,eAAe,UAAU,IAAI,EAAE;EAC/B,oBAAoB,MAAM;EAC1B;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI,CACb;CACA,OAAO;AACT"}
@@ -1,103 +0,0 @@
1
- /** Environment variable carrying the delegation depth (guards against delegation loops). */
2
- export declare const DEPTH_ENV = "STRUTVANE_LAUNCHER_DEPTH";
3
- /** Overrides the project starter command (a JSON array), e.g. for tests or mirrors. */
4
- export declare const CREATE_ENV = "STRUTVANE_CREATE_COMMAND";
5
- /** Set to `1` to silence the version-mismatch notice. */
6
- export declare const NO_NOTICE_ENV = "STRUTVANE_NO_UPDATE_NOTICE";
7
- /** The file that marks a Strutvane project root. */
8
- export declare const PROJECT_MARKER = "strutvane.config.ts";
9
- /** A project-local CLI the launcher can delegate to. */
10
- export interface LocalCli {
11
- readonly packageDir: string;
12
- /** The manifest's version, with control characters removed (safe to print). */
13
- readonly version: string;
14
- /** Absolute path of the CLI's executable script. */
15
- readonly bin: string;
16
- }
17
- /**
18
- * Facts the project boundary rules depend on. Injectable so tests can place "home" and "temp"
19
- * anywhere, and exercise the POSIX ownership rule on any OS.
20
- */
21
- export interface BoundaryFacts {
22
- /** The user's home directory. */
23
- readonly home: string;
24
- /** The OS temp directory. */
25
- readonly temp: string;
26
- /** The current user's uid on POSIX; `undefined` where ownership is not checked (Windows). */
27
- readonly uid: number | undefined;
28
- }
29
- /** The boundary facts of this process. */
30
- export declare function processBoundary(): BoundaryFacts;
31
- /**
32
- * Remove control characters (ANSI escapes, line breaks…) from text that came from a file the
33
- * launcher does not control, before it is printed to a terminal.
34
- */
35
- export declare function printable(text: string): string;
36
- /**
37
- * Whether `dir` may never be treated as a project: a file-system or drive root, the OS temp
38
- * directory itself, or a folder above the user's home directory. Anyone with write access to
39
- * those (other users, downloads, extracted archives) could otherwise plant a `node_modules` that
40
- * runs for every command typed below them.
41
- */
42
- export declare function isForbiddenProjectDir(dir: string, facts: BoundaryFacts): boolean;
43
- /** POSIX only: whether `dir` is owned by the current user. Always `true` without a uid. */
44
- export declare function isOwnedByCurrentUser(dir: string, facts: BoundaryFacts): boolean;
45
- /** Whether a package.json declares `@strutvane/cli` as a dependency or devDependency. */
46
- export declare function declaresCli(manifest: Readonly<Record<string, unknown>> | undefined): boolean;
47
- /**
48
- * Find the project-local `@strutvane/cli`, searching upwards from `start` under the boundary
49
- * rules in the module documentation. Returns `undefined` when there is none (or none that may be
50
- * trusted).
51
- */
52
- export declare function findLocalCli(start: string, facts?: BoundaryFacts): LocalCli | undefined;
53
- /** The `--cwd` value from argv, if any (`--cwd x` or `--cwd=x`). */
54
- export declare function cwdFlag(argv: readonly string[]): string | undefined;
55
- /** The leading command word of argv (skipping flags and the `--cwd` value), if any. */
56
- export declare function commandWord(argv: readonly string[]): string | undefined;
57
- /**
58
- * Whether argv is a command the launcher answers itself and never delegates: no command word
59
- * (`strutvane`, `strutvane --version`, `strutvane --help`), `help`, `new` or `create`.
60
- */
61
- export declare function isLauncherCommand(argv: readonly string[]): boolean;
62
- /** Runs a child process with inherited stdio and resolves with its exit code. */
63
- export type LaunchSpawner = (command: string, args: readonly string[], options: {
64
- readonly env: NodeJS.ProcessEnv;
65
- readonly shell: boolean;
66
- }) => Promise<number>;
67
- /** The real spawner: inherits stdio and ignores Ctrl+C itself so the child decides. */
68
- export declare const nodeLaunchSpawner: LaunchSpawner;
69
- /** Process facts the launcher needs (injectable for tests). */
70
- export interface LauncherEnvironment {
71
- readonly cwd: string;
72
- readonly env: NodeJS.ProcessEnv;
73
- readonly execPath: string;
74
- readonly platform: NodeJS.Platform;
75
- readonly version: string;
76
- readonly stdout: (text: string) => void;
77
- readonly stderr: (text: string) => void;
78
- readonly spawn: LaunchSpawner;
79
- /** Project boundary facts. Default: this process's ({@link processBoundary}). */
80
- readonly boundary?: BoundaryFacts;
81
- }
82
- /**
83
- * Environment for child processes. On Windows, `NoDefaultCurrentDirectoryInExePath` stops
84
- * cmd.exe (and the `.cmd` shims it runs) from finding programs in the working directory before
85
- * PATH, so a project folder can never shadow `node` or `npm`.
86
- */
87
- export declare function childEnv(env: NodeJS.ProcessEnv, platform: NodeJS.Platform, extra?: Readonly<Record<string, string>>): NodeJS.ProcessEnv;
88
- /**
89
- * npm's `npx-cli.js` next to the running Node.js, so npx runs as `node npx-cli.js` with no shell
90
- * and no PATH lookup. Windows installs keep npm in `<node dir>/node_modules/npm`; POSIX installs
91
- * in `<prefix>/lib/node_modules/npm`.
92
- */
93
- export declare function findNpxCli(execPath: string, platform: NodeJS.Platform): string | undefined;
94
- /**
95
- * Windows only: the absolute path of `name` (e.g. `npx`) from PATH, trying each PATHEXT
96
- * extension. The working directory, relative PATH entries and empty entries are skipped, which is
97
- * exactly the lookup order cmd.exe would otherwise use to run a planted `npx.cmd` from the
98
- * project folder.
99
- */
100
- export declare function resolveWindowsExecutable(name: string, env: NodeJS.ProcessEnv, cwd: string, exists?: (path: string) => boolean): string | undefined;
101
- /** Run the launcher. Returns the exit code (the delegated CLI's, when delegating). */
102
- export declare function runLauncher(argv: readonly string[], env: LauncherEnvironment): Promise<number>;
103
- //# sourceMappingURL=launcher.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"launcher.d.mts","names":[],"sources":["../src/launcher.ts"],"mappings":";qBAoCa;;qBAEA;;qBAEA;;qBAGA;;iBAGI;WACN;;WAEA;;WAEA;;;;;;iBAOM;;WAEN;;WAEA;;WAEA;;;wBAIK,mBAAmB;;;;;wBA0BnB,UAAU;;;;;;;wBAqCV,sBAAsB,aAAa,OAAO;;wBAU1C,qBAAqB,aAAa,OAAO;;wBAUzC,YAAY,UAAU,SAAS;;;;;;wBAmC/B,aACd,eACA,QAAO,gBACN;;wBAyBa,QAAQ;;wBAWR,YAAY;;;;;wBAoBZ,kBAAkB;;YAMtB,iBACV,iBACA,yBACA;WAAoB,KAAK,OAAO;WAAqB;MAClD;;qBAKQ,mBAAmB;;iBAoBf;WACN;WACA,KAAK,OAAO;WACZ;WACA,UAAU,OAAO;WACjB;WACA,SAAS;WACT,SAAS;WACT,OAAO;;WAEP,WAAW;;;;;;;wBAaN,SACd,KAAK,OAAO,YACZ,UAAU,OAAO,UACjB,QAAO,SAAS,0BACf,OAAO;;;;;;wBAaM,WAAW,kBAAkB,UAAU,OAAO;;;;;;;wBAmB9C,yBACd,cACA,KAAK,OAAO,YACZ,aACA,UAAS;;wBA6GW,YACpB,yBACA,KAAK,sBACJ"}
package/dist/launcher.mjs DELETED
@@ -1 +0,0 @@
1
- export { t as CREATE_ENV, n as DEPTH_ENV, r as NO_NOTICE_ENV, i as PROJECT_MARKER, a as childEnv, o as commandWord, s as cwdFlag, c as declaresCli, l as findLocalCli, u as findNpxCli, d as isForbiddenProjectDir, f as isLauncherCommand, p as isOwnedByCurrentUser, m as nodeLaunchSpawner, h as printable, g as processBoundary, _ as resolveWindowsExecutable, v as runLauncher } from "./launcher-BrUi5a5_.mjs";