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.
- package/CHANGELOG.md +15 -0
- package/README.md +81 -11
- package/dist/bin.mjs +762 -12
- package/dist/bin.mjs.map +1 -1
- package/package.json +47 -14
- package/dist/bin.d.mts +0 -1
- package/dist/launcher-BrUi5a5_.mjs +0 -371
- package/dist/launcher-BrUi5a5_.mjs.map +0 -1
- package/dist/launcher.d.mts +0 -103
- package/dist/launcher.d.mts.map +0 -1
- package/dist/launcher.mjs +0 -1
package/dist/bin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.mjs","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * `strutvane` executable: runs the launcher for this process.\n *\n * @module\n */\nimport { readFileSync } from 'node:fs'\nimport { nodeLaunchSpawner, runLauncher } from './launcher.ts'\n\nfunction ownVersion(): string {\n try {\n const manifest: unknown = JSON.parse(\n readFileSync(new URL('../package.json', import.meta.url), 'utf8'),\n )\n const version = (manifest as { version?: unknown }).version\n return typeof version === 'string' ? version : '0.0.0'\n } catch {\n return '0.0.0'\n }\n}\n\nprocess.exitCode = await runLauncher(process.argv.slice(2), {\n cwd: process.cwd(),\n env: process.env,\n execPath: process.execPath,\n platform: process.platform,\n version: ownVersion(),\n stdout: (text) => process.stdout.write(text),\n stderr: (text) => process.stderr.write(text),\n spawn: nodeLaunchSpawner,\n})\n"],"mappings":";;;;;;;;;AASA,SAAS,aAAqB;CAC5B,IAAI;EAIF,MAAM,UAHoB,KAAK,MAC7B,aAAa,IAAI,IAAI,mBAAmB,YAAY,GAAG,GAAG,MAAM,CAE1C,CAAC,CAA2B;EACpD,OAAO,OAAO,YAAY,WAAW,UAAU;CACjD,QAAQ;EACN,OAAO;CACT;AACF;AAEA,QAAQ,WAAW,MAAM,YAAY,QAAQ,KAAK,MAAM,CAAC,GAAG;CAC1D,KAAK,QAAQ,IAAI;CACjB,KAAK,QAAQ;CACb,UAAU,QAAQ;CAClB,UAAU,QAAQ;CAClB,SAAS,WAAW;CACpB,SAAS,SAAS,QAAQ,OAAO,MAAM,IAAI;CAC3C,SAAS,SAAS,QAAQ,OAAO,MAAM,IAAI;CAC3C,OAAO;AACT,CAAC"}
|
|
1
|
+
{"version":3,"file":"bin.mjs","names":[],"sources":["../src/boundary.ts","../src/child.ts","../src/messages.ts","../src/manifest.ts","../src/project.ts","../src/target.ts","../src/version.ts","../src/main.ts","../src/bin.ts"],"sourcesContent":["/**\n * Which folders may ever be treated as a Strutvane project.\n *\n * Treating a folder as the project means running code from it (`strut.js`, or the framework in\n * its `node_modules`). So, walking up from the working directory, the search stops (with no\n * project) at a folder that:\n * - is a file-system or drive root,\n * - is the OS temp directory itself,\n * - is above the user's home directory,\n * because anyone able to write there (other users, an extracted archive) could otherwise plant a\n * project that applies to every folder below it. On POSIX the project folder must also belong to\n * the current user.\n *\n * These are the same rules as `@strutvane/framework`'s `console/project/boundary.ts`. This\n * package has no dependencies (it must work before anything is installed), so the rules are\n * mirrored here rather than imported. Keep the two in step.\n *\n * @module\n */\nimport { realpathSync, statSync } from 'node:fs'\nimport { homedir, tmpdir } from 'node:os'\nimport { dirname, isAbsolute, relative, resolve } from 'node:path'\n\n/** Facts the rules depend on (injectable, so tests can place \"home\" and \"temp\" anywhere). */\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 uid on POSIX; `undefined` where ownership is not checked (Windows). */\n readonly uid: number | undefined\n}\n\n/**\n * The boundary facts of this process.\n *\n * @example\n * isForbiddenProjectDir('/tmp', processBoundary()) // true\n */\nexport function processBoundary(): BoundaryFacts {\n return {\n home: homedir(),\n temp: tmpdir(),\n uid: typeof process.getuid === 'function' ? process.getuid() : undefined,\n }\n}\n\n/** Every spelling of a path worth comparing: as given, and with links resolved. */\nfunction spellings(path: string): string[] {\n const out = [resolve(path)]\n try {\n out.push(realpathSync.native(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 => (fold ? resolve(p).toLowerCase() : resolve(p))\n return norm(a) === norm(b)\n}\n\n/**\n * Whether `child` is `parent` itself or lies inside it. Both should already be real paths (links\n * resolved), or a link inside `parent` could point anywhere.\n *\n * Why not `startsWith`: `/srv/app-evil` starts with `/srv/app`. `path.relative` compares whole\n * segments, and on Windows it ignores case and reports another drive as an absolute path.\n *\n * @example\n * isInside('/srv/app', '/srv/app/strut.js') // true\n * isInside('/srv/app', '/srv/app-evil/strut.js') // false\n */\nexport function isInside(parent: string, child: string): boolean {\n const rel = relative(parent, child)\n if (rel === '') return true\n if (isAbsolute(rel)) return false\n const first = rel.split(/[\\\\/]/)[0]\n return first !== '..'\n}\n\n/** Whether `ancestor` is a strict ancestor of `path`. */\nfunction isStrictAncestor(ancestor: string, path: string): boolean {\n return !samePath(ancestor, path) && isInside(ancestor, path)\n}\n\n/**\n * A file-system or drive root, the temp directory itself, or a folder above home: never a\n * project, and the upward search stops there.\n *\n * @example\n * isForbiddenProjectDir('C:\\\\', facts) // true\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/**\n * POSIX only: whether `dir` belongs to the current user (always `true` without a uid, i.e. on\n * Windows). A missing folder is not owned by anyone: `false`.\n */\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 * Running the project's script as a child process, and passing its result back.\n *\n * - **No shell, ever.** The program is the running Node (`process.execPath`) and the arguments go\n * in an array, so `a&b`, `$(x)`, `; rm -rf ~` or `%PATH%` reach `strut.js` as plain text on\n * every platform. Arguments come after the script path, so `--import=x.mjs` or `--require x`\n * are the script's arguments, never Node options.\n * - **Exit codes** come back unchanged. When the child is killed by a signal, the caller re-raises\n * that signal on itself (see `bin.ts`), so a parent shell or CI sees what really happened;\n * where that is not possible (Windows) the exit code is the shell convention 128 + signal.\n * - **Signals** sent to this process are forwarded to the child, so `kill <pid>` or a supervisor\n * stopping the guard stops the command too, and the guard never exits before the child: see\n * {@link shouldForward} for which ones and why.\n *\n * @module\n */\nimport { spawn } from 'node:child_process'\nimport { constants } from 'node:os'\n\n/** Signals the guard listens for while a child runs. */\nexport const HANDLED_SIGNALS: readonly NodeJS.Signals[] = Object.freeze([\n 'SIGINT',\n 'SIGTERM',\n 'SIGHUP',\n 'SIGBREAK',\n])\n\n/**\n * Whether a signal received by the guard is passed on to the child.\n *\n * - **Windows: never.** A console Ctrl+C or Ctrl+Break already reaches every process attached to\n * the console, the child included, and \"sending\" a signal to a Windows process terminates it\n * outright, which would deny `strut.js` its own clean-up. The guard only keeps a listener so it\n * is not the one to die first.\n * - **Ctrl+C at a terminal (POSIX, `SIGINT` with stdin a TTY): not forwarded.** The terminal\n * sends it to the whole foreground process group, so the child already has it; a second copy\n * can turn \"stop gracefully\" into \"force quit\" in commands that count presses (a dev server).\n * - **Everything else is forwarded** (`SIGTERM`, `SIGHUP`, and `SIGINT` without a terminal, e.g.\n * from a supervisor or `kill -INT`), since only the guard received it.\n *\n * @example\n * shouldForward('SIGTERM', 'linux', true) // true\n * shouldForward('SIGINT', 'linux', true) // false\n */\nexport function shouldForward(\n signal: NodeJS.Signals,\n platform: NodeJS.Platform,\n stdinIsTTY: boolean,\n): boolean {\n if (platform === 'win32') return false\n if (signal === 'SIGINT' && stdinIsTTY) return false\n return true\n}\n\n/** The exit code that stands for death by `signal` (128 + its number; 1 when unknown). */\nexport function signalExitCode(signal: NodeJS.Signals): number {\n const number = constants.signals[signal]\n return typeof number === 'number' ? 128 + number : 1\n}\n\n/** How a child process ended. */\nexport type ChildOutcome =\n | { readonly kind: 'exit'; readonly code: number }\n | { readonly kind: 'signal'; readonly signal: NodeJS.Signals }\n | { readonly kind: 'error'; readonly message: string }\n\n/** Where signals come from (the real `process`, or a test's event emitter). */\nexport interface SignalSource {\n on(event: NodeJS.Signals, listener: (signal: NodeJS.Signals) => void): unknown\n off(event: NodeJS.Signals, listener: (signal: NodeJS.Signals) => void): unknown\n}\n\n/** What {@link runChild} needs to start the child. */\nexport interface ChildRequest {\n /** The Node executable (normally `process.execPath`). */\n readonly execPath: string\n /** The script to run (a real path, checked by `target.ts`). */\n readonly script: string\n /** The user's arguments, passed through exactly. */\n readonly args: readonly string[]\n /** The child's working directory (the project root). */\n readonly cwd: string\n /** The child's environment. */\n readonly env: NodeJS.ProcessEnv\n /** The platform, for {@link shouldForward}. */\n readonly platform: NodeJS.Platform\n /** Whether stdin is a terminal, for {@link shouldForward}. */\n readonly stdinIsTTY: boolean\n /** Where signals arrive (default: `process`). */\n readonly signals?: SignalSource\n /** The child's stdio (default `inherit`: the child talks to the user's terminal directly). */\n readonly stdio?: 'inherit' | 'pipe' | 'ignore'\n}\n\n/** Starts the child and resolves with how it ended. Injectable so tests can stand in. */\nexport type ChildRunner = (request: ChildRequest) => Promise<ChildOutcome>\n\n/**\n * Run `node <script> <args...>` with no shell, forward signals while it runs, and resolve with\n * how it ended. Never rejects: a child that cannot start resolves as `{ kind: 'error' }`.\n *\n * @example\n * await runChild({ execPath: process.execPath, script: '/srv/blog/strut.js', args: ['migrate'], ... })\n * // { kind: 'exit', code: 0 }\n */\nexport const runChild: ChildRunner = (request) =>\n new Promise((resolvePromise) => {\n const signals = request.signals ?? process\n let settled = false\n const child = spawn(request.execPath, [request.script, ...request.args], {\n cwd: request.cwd,\n env: request.env,\n stdio: request.stdio ?? 'inherit',\n shell: false,\n windowsHide: true,\n })\n const onSignal = (signal: NodeJS.Signals): void => {\n if (child.exitCode !== null || child.signalCode !== null) return\n if (shouldForward(signal, request.platform, request.stdinIsTTY)) child.kill(signal)\n }\n for (const signal of HANDLED_SIGNALS) signals.on(signal, onSignal)\n const finish = (outcome: ChildOutcome): void => {\n if (settled) return\n settled = true\n for (const signal of HANDLED_SIGNALS) signals.off(signal, onSignal)\n resolvePromise(outcome)\n }\n child.once('error', (error) => finish({ kind: 'error', message: error.message }))\n child.once('exit', (code, signal) => {\n if (signal !== null) finish({ kind: 'signal', signal })\n else finish({ kind: 'exit', code: code ?? 1 })\n })\n })\n","/**\n * Everything the guard says. One place, so the wording stays consistent and every value from\n * outside (paths, arguments, versions) is made safe to print first.\n *\n * Messages say what happened and how to fix it (ecosystem standard), in plain words.\n *\n * @module\n */\nimport type { UntrustedReason } from './project.ts'\nimport type { RefusalReason } from './target.ts'\n\n// biome-ignore lint/suspicious/noControlCharactersInRegex: matching control characters is the point\nconst CONTROL = /[\\u0000-\\u001f\\u007f-\\u009f]/g\n\n/**\n * Text from outside the guard (a path, an argument, a version from a file it does not control),\n * made safe for a terminal: control characters (ANSI escapes, line breaks) removed and the length\n * capped, so a crafted folder or argument can't rewrite the screen or fake a message.\n *\n * @example\n * printable('a\\u001b[2Jb') // 'a[2Jb'\n */\nexport function printable(text: string, max = 200): string {\n const clean = text.replace(CONTROL, '')\n return clean.length > max ? `${clean.slice(0, max - 1)}…` : clean\n}\n\n/**\n * The dist-tag to name in `npm create strutvane@<tag>`: `next` while this package is a\n * pre-release (before 1.0 the core train is published under `next`, decision #128), `latest`\n * otherwise. The same rule as create-strutvane's `releaseTag()`.\n *\n * @example\n * releaseTag('0.2.0-next.0') // 'next'\n * releaseTag('1.0.0') // 'latest'\n */\nexport function releaseTag(version: string): 'next' | 'latest' {\n return version.includes('-') ? 'next' : 'latest'\n}\n\n/** `npm create strutvane@<tag> <name>`, the one command that makes a project. */\nexport function createCommand(version: string, name = 'my-app'): string {\n return `npm create strutvane@${releaseTag(version)} ${name}`\n}\n\n/** A project name worth echoing back in a suggestion (otherwise the placeholder is shown). */\nconst SIMPLE_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/\n\n/** Commands people type to make a new project. */\nexport const CREATE_WORDS: ReadonlySet<string> = new Set(['new', 'create', 'init'])\n\n/** `strutvane <version>`. */\nexport function versionText(version: string): string {\n return `strutvane ${printable(version, 64)}`\n}\n\n/** What `npx strutvane` does, and how to make a project. Printed for `help` outside a project. */\nexport function helpText(version: string, start: string): string {\n return [\n `${versionText(version)}: run Strutvane project commands with npx.`,\n '',\n `No Strutvane project was found in ${printable(start)} or the folders above it.`,\n '',\n 'Create a new app:',\n ` ${createCommand(version)}`,\n '',\n 'Inside a project, `npx strutvane <command>` runs exactly what `node strut <command>` runs,',\n \"with the project's own @strutvane/framework (try `node strut list` there). A project is a\",\n 'folder whose package.json lists @strutvane/framework.',\n '',\n 'This command never installs or downloads anything.',\n ].join('\\n')\n}\n\n/** A project command was typed outside a project. */\nexport function noProjectText(version: string, command: string, start: string): string {\n const word = printable(command, 60)\n return [\n `strutvane: \"${word}\" needs a Strutvane project, and none was found in ${printable(start)}`,\n ' or the folders above it (a project is a folder whose package.json lists',\n ' @strutvane/framework; the search never goes above your home folder).',\n '',\n ` Create one with: ${createCommand(version)}`,\n ' Then run commands inside it: node strut list',\n ].join('\\n')\n}\n\n/** `new`, `create` or `init` was typed: point to the installer instead of running anything. */\nexport function createText(version: string, name: string | undefined): string {\n const shown = name !== undefined && SIMPLE_NAME.test(name) ? name : '<name>'\n return [\n 'strutvane: new projects are made by the installer, which asks how you want the app set up:',\n '',\n ` ${createCommand(version, shown)}`,\n ].join('\\n')\n}\n\n/** A candidate project folder was found but is not trusted. */\nexport function untrustedText(dir: string, reason: UntrustedReason): string {\n const where = printable(dir)\n if (reason === 'not-owned') {\n return [\n `strutvane: ${where} looks like a Strutvane project, but it belongs to another user.`,\n ' Refusing to run code from it. Run the command as the folder owner, or fix its ownership.',\n ].join('\\n')\n }\n return [\n `strutvane: ${where} has a strut.js, but its package.json does not list @strutvane/framework,`,\n ' so it is not a Strutvane project and its strut.js was not run.',\n ' If it is your project, add the framework (npm install @strutvane/framework) and try again;',\n ' otherwise run the command from your project folder.',\n ].join('\\n')\n}\n\n/** Why a trusted project still can't be run, and the fix. */\nexport function refusalText(reason: RefusalReason, path: string, realPath?: string): string {\n const where = printable(path)\n switch (reason) {\n case 'root-unreadable':\n return `strutvane: the project folder ${where} can no longer be read. Check it exists and try again.`\n case 'root-is-link':\n return [\n `strutvane: the project folder ${where} is a link${realPath === undefined ? '' : ` to ${printable(realPath)}`}.`,\n ' Refusing to run code through a link: open the real folder and run the command there.',\n ].join('\\n')\n case 'strut-not-file':\n return [\n `strutvane: ${where} is a link or not a regular file, so it was not run.`,\n ' Restore strut.js from git (or from a new project made with npm create strutvane).',\n ].join('\\n')\n case 'strut-outside-root':\n return `strutvane: ${where} really lives outside the project folder, so it was not run.`\n case 'framework-missing':\n return [\n `strutvane: the project's dependencies are not installed (${where} is missing).`,\n ' Run: npm install (or npm run setup in a project made by create-strutvane)',\n ].join('\\n')\n case 'framework-outside-root':\n return [\n `strutvane: ${where} points outside the project folder (a link or junction), so it was not run.`,\n ' Install the framework into the project instead: npm install',\n ].join('\\n')\n case 'framework-invalid':\n return [\n `strutvane: ${where} is not a usable @strutvane/framework (wrong name, or no safe \"strutvane\" program).`,\n ' Reinstall it: npm install',\n ].join('\\n')\n }\n}\n\n/** The guard was started again by the project it started (a `strut.js` calling `npx strutvane`). */\nexport function loopText(): string {\n return [\n 'strutvane: npx strutvane was started again from inside the command it ran, so it stopped',\n ' instead of looping. Call `node strut` (not `npx strutvane`) from strut.js and project scripts.',\n ].join('\\n')\n}\n\n/** Node is older than the minimum. */\nexport function nodeTooOldText(found: string, minimum: string): string {\n return [\n `strutvane: Node.js ${printable(found, 32)} is too old; Strutvane needs Node.js ${minimum} or newer.`,\n ' Install a current LTS from https://nodejs.org and try again.',\n ].join('\\n')\n}\n\n/** The child could not be started at all. */\nexport function startFailedText(script: string, message: string): string {\n return `strutvane: could not start ${printable(script)}: ${printable(message)}`\n}\n","/**\n * Reading `package.json` files the guard does not control.\n *\n * Every manifest read here is untrusted input (it may be in a folder someone else wrote), so the\n * reader is lenient (any problem means \"no manifest\") and bounded (a huge file is not read).\n * Nothing in a manifest is ever executed; it only decides what is trusted.\n *\n * @module\n */\nimport { readFileSync, statSync } from 'node:fs'\nimport { join } from 'node:path'\n\n/** The package that marks a Strutvane project, and whose `strutvane` program runs commands. */\nexport const FRAMEWORK_PACKAGE = '@strutvane/framework'\n\n/** Manifests larger than this are not read (1 MiB; real ones are a few KiB). */\nexport const MAX_MANIFEST_BYTES: number = 1024 * 1024\n\n/** A parsed JSON object. */\nexport type JsonObject = Readonly<Record<string, unknown>>\n\n/**\n * Read a JSON object file. Returns `undefined` when it is missing, not a regular file, larger than\n * {@link MAX_MANIFEST_BYTES}, not valid JSON, or not an object.\n *\n * @example\n * readJsonObject('/srv/app/package.json')?.['name'] // 'my-app'\n */\nexport function readJsonObject(path: string): JsonObject | undefined {\n try {\n const stats = statSync(path)\n if (!stats.isFile() || stats.size > MAX_MANIFEST_BYTES) return undefined\n const text = readFileSync(path, 'utf8')\n const parsed: unknown = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text)\n return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)\n ? (parsed as JsonObject)\n : undefined\n } catch {\n return undefined\n }\n}\n\n/** `<dir>/package.json`, read with {@link readJsonObject}. */\nexport function readManifest(dir: string): JsonObject | undefined {\n return readJsonObject(join(dir, 'package.json'))\n}\n\n/**\n * Whether a manifest lists `@strutvane/framework` in `dependencies` or `devDependencies` (as an\n * own property with a string range). That is what makes a folder a Strutvane project.\n *\n * Why only those two fields: an optional or peer dependency is not installed for the app itself,\n * and the framework's own project detection uses the same two.\n *\n * @example\n * declaresFramework({ dependencies: { '@strutvane/framework': '^0.2.0-next.0' } }) // true\n */\nexport function declaresFramework(manifest: JsonObject | 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 !Array.isArray(deps) &&\n Object.hasOwn(deps, FRAMEWORK_PACKAGE) &&\n typeof (deps as Record<string, unknown>)[FRAMEWORK_PACKAGE] === 'string'\n )\n })\n}\n","/**\n * Finding the Strutvane project for a working directory.\n *\n * From the working directory upwards, the **nearest** folder that holds a `strut.js` or whose\n * package.json lists `@strutvane/framework` is the candidate, and the search ends there (an\n * ancestor further up is never considered, so a project can't be hijacked from above). The\n * candidate is trusted only when:\n * - its package.json lists `@strutvane/framework` (a `strut.js` on its own is not enough: anyone\n * can drop a file called `strut.js` into a folder);\n * - it passes the boundary rules of `boundary.ts` (never a root, the temp directory or a folder\n * above home; owned by the current user on POSIX).\n *\n * Only files are read here; nothing is run.\n *\n * @module\n */\nimport { lstatSync } from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\nimport { type BoundaryFacts, isForbiddenProjectDir, isOwnedByCurrentUser } from './boundary.ts'\nimport { declaresFramework, readManifest } from './manifest.ts'\n\n/** The file that `node strut` runs, in the project root. */\nexport const STRUT_FILE = 'strut.js'\n\n/** Why a candidate folder was found but not trusted. */\nexport type UntrustedReason =\n /** It has a `strut.js` but its package.json does not list `@strutvane/framework`. */\n | 'strut-without-framework'\n /** POSIX: the folder belongs to another user. */\n | 'not-owned'\n\n/** The outcome of the search. */\nexport type ProjectSearch =\n /** A trusted project root (not yet checked for links; see `target.ts`). */\n | { readonly kind: 'project'; readonly root: string }\n /** A candidate was found and refused. */\n | { readonly kind: 'untrusted'; readonly dir: string; readonly reason: UntrustedReason }\n /** No candidate between `start` and the first boundary. */\n | { readonly kind: 'none'; readonly start: string }\n\n/** Whether `path` exists in any form (a file, a folder, a link, even a broken link). */\nfunction exists(path: string): boolean {\n try {\n lstatSync(path)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Find the project for `start` (see the module documentation for the rules).\n *\n * @example\n * findProject('/home/ana/blog/app/models', facts) // { kind: 'project', root: '/home/ana/blog' }\n */\nexport function findProject(start: string, facts: BoundaryFacts): ProjectSearch {\n const from = resolve(start)\n let dir = from\n for (;;) {\n if (isForbiddenProjectDir(dir, facts)) return { kind: 'none', start: from }\n const declares = declaresFramework(readManifest(dir))\n if (declares || exists(join(dir, STRUT_FILE))) {\n if (!declares) return { kind: 'untrusted', dir, reason: 'strut-without-framework' }\n if (!isOwnedByCurrentUser(dir, facts)) return { kind: 'untrusted', dir, reason: 'not-owned' }\n return { kind: 'project', root: dir }\n }\n const parent = dirname(dir)\n if (parent === dir) return { kind: 'none', start: from }\n dir = parent\n }\n}\n","/**\n * What to run for a trusted project root, and the checks that keep it inside that root.\n *\n * `node strut <args>` runs the project's `strut.js`. So the guard runs that same file, with the\n * same Node, when it is there. Without a `strut.js` (a project made by hand, or one whose\n * `strut.js` was deleted) it runs what `strut.js` would run for a framework command: the\n * `strutvane` program of the project's own installed `@strutvane/framework`. Never a second copy,\n * and never anything fetched.\n *\n * Every path is checked on its **real** location (links resolved), and must stay inside the\n * project root:\n * - the root itself must not be a link (a link can make an innocent-looking folder run code from\n * anywhere); the user is told the real folder to open instead;\n * - `strut.js` must be a regular file, not a link;\n * - `node_modules/@strutvane/framework` must really be inside the root (an `npm link` or a\n * planted junction pointing elsewhere is refused), must be named `@strutvane/framework`, and its\n * `bin` must be a plain relative `.js`/`.mjs`/`.cjs` path that stays inside the package.\n *\n * The file that runs is handed to Node by its real path, so what was checked is what runs.\n *\n * @module\n */\nimport { lstatSync, realpathSync, statSync } from 'node:fs'\nimport { join, posix, resolve, win32 } from 'node:path'\nimport { isInside } from './boundary.ts'\nimport { FRAMEWORK_PACKAGE, readJsonObject } from './manifest.ts'\nimport { STRUT_FILE } from './project.ts'\n\n/** The name of the framework's program in its package.json `bin`. */\nexport const FRAMEWORK_BIN = 'strutvane'\n\n/** Why a trusted project root still cannot be run. */\nexport type RefusalReason =\n /** The project root disappeared or cannot be read since it was found. */\n | 'root-unreadable'\n /** The project root is a symbolic link or junction. */\n | 'root-is-link'\n /** `strut.js` is a link, or not a regular file. */\n | 'strut-not-file'\n /** `strut.js`'s real location is outside the project root. */\n | 'strut-outside-root'\n /** No `strut.js`, and `@strutvane/framework` is not installed in the project. */\n | 'framework-missing'\n /** `node_modules/@strutvane/framework` really lives outside the project root. */\n | 'framework-outside-root'\n /** The installed package is not `@strutvane/framework`, or has no usable `strutvane` bin. */\n | 'framework-invalid'\n\n/** The outcome of resolving what to run. */\nexport type Target =\n | {\n readonly kind: 'run'\n /** The project root (as found; the child's working directory). */\n readonly root: string\n /** Real path of the script Node runs. */\n readonly script: string\n /** Which of the two kinds of script it is. */\n readonly via: 'strut.js' | 'framework'\n }\n | {\n readonly kind: 'refused'\n readonly reason: RefusalReason\n /** The path the refusal is about (printed in the message). */\n readonly path: string\n /** The real location, when it helps the user (for `root-is-link`). */\n readonly realPath?: string\n }\n\n/** Scripts the guard may hand to Node. */\nconst SCRIPT_EXTENSION = /\\.[cm]?js$/\n\n/**\n * Whether a package.json `bin` value is a plain relative path to a script: not empty, no NUL, not\n * absolute on any platform (`/x`, `C:\\x`, `\\\\server\\share\\x`), not drive-relative (`C:x`), no `..`\n * segment, and ending in `.js`, `.mjs` or `.cjs`.\n *\n * Why so strict: the value comes from a file inside `node_modules`, and becomes a path Node runs.\n *\n * @example\n * isSafeBinPath('dist/console/bin.mjs') // true\n * isSafeBinPath('..\\\\..\\\\evil.js') // false\n */\nexport function isSafeBinPath(bin: string): boolean {\n if (bin === '' || bin.length > 512 || bin.includes('\\0')) return false\n if (posix.isAbsolute(bin) || win32.isAbsolute(bin) || /^[A-Za-z]:/.test(bin)) return false\n if (bin.split(/[\\\\/]/).includes('..')) return false\n return SCRIPT_EXTENSION.test(bin)\n}\n\n/** The `strutvane` entry of a manifest's `bin` (a string `bin` counts as the package's only one). */\nexport function frameworkBin(manifest: Readonly<Record<string, unknown>>): string | undefined {\n const bin = manifest['bin']\n if (typeof bin === 'string') return bin\n if (typeof bin !== 'object' || bin === null || Array.isArray(bin)) return undefined\n if (!Object.hasOwn(bin, FRAMEWORK_BIN)) return undefined\n const entry = (bin as Record<string, unknown>)[FRAMEWORK_BIN]\n return typeof entry === 'string' ? entry : undefined\n}\n\n/** `lstat`, or `undefined` when the path does not exist (or cannot be read). */\nfunction lstatOrUndefined(path: string): ReturnType<typeof lstatSync> | undefined {\n try {\n return lstatSync(path)\n } catch {\n return undefined\n }\n}\n\n/** The real path, or `undefined` when it cannot be resolved (missing, broken link, no access). */\nfunction realOrUndefined(path: string): string | undefined {\n try {\n return realpathSync.native(path)\n } catch {\n return undefined\n }\n}\n\n/**\n * Decide what to run for the trusted project root `root` (see the module documentation).\n *\n * @example\n * resolveTarget('/srv/blog') // { kind: 'run', root: '/srv/blog', script: '/srv/blog/strut.js', via: 'strut.js' }\n */\nexport function resolveTarget(root: string): Target {\n const rootStats = lstatOrUndefined(root)\n const realRoot = realOrUndefined(root)\n if (rootStats === undefined || realRoot === undefined) {\n return { kind: 'refused', reason: 'root-unreadable', path: root }\n }\n if (rootStats.isSymbolicLink()) {\n return { kind: 'refused', reason: 'root-is-link', path: root, realPath: realRoot }\n }\n\n const strut = join(root, STRUT_FILE)\n const strutStats = lstatOrUndefined(strut)\n if (strutStats !== undefined) {\n if (strutStats.isSymbolicLink() || !strutStats.isFile()) {\n return { kind: 'refused', reason: 'strut-not-file', path: strut }\n }\n const real = realOrUndefined(strut)\n if (real === undefined || !isInside(realRoot, real)) {\n return { kind: 'refused', reason: 'strut-outside-root', path: strut }\n }\n return { kind: 'run', root, script: real, via: 'strut.js' }\n }\n\n return frameworkTarget(root, realRoot)\n}\n\n/** The framework's own `strutvane` program, for a project without `strut.js`. */\nfunction frameworkTarget(root: string, realRoot: string): Target {\n const dir = join(root, 'node_modules', ...FRAMEWORK_PACKAGE.split('/'))\n if (lstatOrUndefined(dir) === undefined) {\n return { kind: 'refused', reason: 'framework-missing', path: dir }\n }\n const realDir = realOrUndefined(dir)\n if (realDir === undefined || !isInside(realRoot, realDir)) {\n return { kind: 'refused', reason: 'framework-outside-root', path: dir }\n }\n const manifest = readJsonObject(join(realDir, 'package.json'))\n const bin = manifest === undefined ? undefined : frameworkBin(manifest)\n if (manifest?.['name'] !== FRAMEWORK_PACKAGE || bin === undefined || !isSafeBinPath(bin)) {\n return { kind: 'refused', reason: 'framework-invalid', path: dir }\n }\n const real = realOrUndefined(resolve(realDir, bin))\n if (real === undefined || !isInside(realDir, real) || !isRegularFile(real)) {\n return { kind: 'refused', reason: 'framework-invalid', path: dir }\n }\n return { kind: 'run', root, script: real, via: 'framework' }\n}\n\n/** Whether `path` is a regular file (following links). */\nfunction isRegularFile(path: string): boolean {\n try {\n return statSync(path).isFile()\n } catch {\n return false\n }\n}\n","/**\n * This package's own version, and the Node.js versions it supports.\n *\n * @module\n */\nimport { fileURLToPath } from 'node:url'\nimport { readJsonObject } from './manifest.ts'\n\n/** The oldest Node.js the guard (and the framework it starts) supports: package.json `engines`. */\nexport const MIN_NODE = '24.3.0'\n\n/**\n * This package's version, read from its own package.json (one folder up from both `src/` and\n * `dist/`), so it can never drift from what was published. `0.0.0` if it cannot be read.\n *\n * @example\n * ownVersion() // '0.2.0-next.0'\n */\nexport function ownVersion(manifestUrl: URL = new URL('../package.json', import.meta.url)): string {\n const version = readJsonObject(fileURLToPath(manifestUrl))?.['version']\n return typeof version === 'string' ? version : '0.0.0'\n}\n\n/**\n * Whether `version` (`process.versions.node`, e.g. `24.3.0`) is at least `minimum`. Anything that\n * is not `major.minor.patch` counts as too old (fail closed).\n *\n * @example\n * isNodeSupported('24.3.0', '24.3.0') // true\n * isNodeSupported('22.12.0', '24.3.0') // false\n */\nexport function isNodeSupported(version: string, minimum: string = MIN_NODE): boolean {\n const parse = (v: string): number[] | undefined => {\n const match = /^(\\d+)\\.(\\d+)\\.(\\d+)/.exec(v)\n return match === null ? undefined : [Number(match[1]), Number(match[2]), Number(match[3])]\n }\n const have = parse(version)\n const need = parse(minimum)\n if (have === undefined || need === undefined) return false\n for (let i = 0; i < 3; i++) {\n const a = have[i] ?? 0\n const b = need[i] ?? 0\n if (a !== b) return a > b\n }\n return true\n}\n","/**\n * `npx strutvane <args>`: the whole decision, with every process fact injected so it can be\n * tested without touching the real process.\n *\n * 1. Node older than {@link MIN_NODE}: say so, exit 1.\n * 2. Started again by the command it started (`STRUTVANE_NPX_DEPTH`): stop, exit 1, no loop.\n * 3. Find the project (`project.ts`) and what to run in it (`target.ts`).\n * - Found and trusted: run it with the user's arguments exactly as typed, and hand back its\n * exit code or signal. Every argument goes to the project, `--version` and `help` included,\n * because that is what `node strut` does.\n * - Found but untrusted or refused: say why and how to fix it, exit 1. Nothing runs.\n * - Not found: `help` / `--help` / no command prints help (exit 0), `--version` prints this\n * package's version (exit 0), `new` / `create` / `init` prints the installer command, and\n * anything else explains that it needs a project. Those last two exit 2: nothing was done.\n *\n * Nothing is ever installed or downloaded; outside a project the guard only prints.\n *\n * @module\n */\nimport { type BoundaryFacts, processBoundary } from './boundary.ts'\nimport { type ChildRunner, runChild, signalExitCode } from './child.ts'\nimport {\n CREATE_WORDS,\n createText,\n helpText,\n loopText,\n nodeTooOldText,\n noProjectText,\n refusalText,\n startFailedText,\n untrustedText,\n versionText,\n} from './messages.ts'\nimport { findProject } from './project.ts'\nimport { resolveTarget } from './target.ts'\nimport { isNodeSupported, MIN_NODE } from './version.ts'\n\n/** Exit codes of the guard itself (the project's own codes pass through unchanged). */\nexport const EXIT: Readonly<{ OK: 0; FAILURE: 1; USAGE: 2 }> = Object.freeze({\n OK: 0,\n /** Refused to run (untrusted folder, link, missing or invalid framework, loop, old Node). */\n FAILURE: 1,\n /** Outside a project: the command needs one (or is `new`), so nothing was done. */\n USAGE: 2,\n})\n\n/** Counts how deep `npx strutvane` is nested inside itself (guards against loops). */\nexport const DEPTH_ENV = 'STRUTVANE_NPX_DEPTH'\n\n/** How the guard should end. */\nexport type Outcome =\n | { readonly exitCode: number }\n /** The child died of `signal`: re-raise it (or exit with `exitCode` where that is impossible). */\n | { readonly signal: NodeJS.Signals; readonly exitCode: number }\n\n/** Process facts the guard needs (injectable for tests). */\nexport interface GuardEnvironment {\n readonly cwd: string\n readonly env: NodeJS.ProcessEnv\n readonly execPath: string\n readonly platform: NodeJS.Platform\n /** `process.versions.node`. */\n readonly nodeVersion: string\n /** This package's version. */\n readonly version: string\n readonly stdinIsTTY: boolean\n readonly stdout: (text: string) => void\n readonly stderr: (text: string) => void\n /** Project boundary facts. Default: this process's. */\n readonly boundary?: BoundaryFacts\n /** Starts the child. Default: {@link runChild}. */\n readonly run?: ChildRunner\n}\n\n/** Flags that ask for this package's version outside a project. */\nconst VERSION_FLAGS: ReadonlySet<string> = new Set(['--version', '-v', '-V'])\n/** Words and flags that ask for help outside a project. */\nconst HELP_WORDS: ReadonlySet<string> = new Set(['help', '--help', '-h'])\n\n/**\n * The child's environment: the user's, plus the nesting depth and, on Windows,\n * `NoDefaultCurrentDirectoryInExePath`, so a `.cmd` the project starts through cmd.exe can't pick\n * up a program planted in the working directory before PATH.\n */\nexport function childEnvironment(\n env: NodeJS.ProcessEnv,\n platform: NodeJS.Platform,\n depth: number,\n): NodeJS.ProcessEnv {\n return {\n ...env,\n ...(platform === 'win32' ? { NoDefaultCurrentDirectoryInExePath: '1' } : {}),\n [DEPTH_ENV]: String(depth + 1),\n }\n}\n\n/** The nesting depth from the environment (anything unexpected counts as 0). */\nexport function depthOf(env: NodeJS.ProcessEnv): number {\n const value = env[DEPTH_ENV]\n return value !== undefined && /^\\d{1,3}$/.test(value) ? Number(value) : 0\n}\n\n/**\n * Run the guard for `argv` (the arguments after `strutvane`). Never throws for expected\n * situations; returns how to end.\n *\n * @example\n * await main(['migrate'], environment) // { exitCode: 0 } after `node strut migrate` succeeded\n */\nexport async function main(argv: readonly string[], env: GuardEnvironment): Promise<Outcome> {\n if (!isNodeSupported(env.nodeVersion)) {\n env.stderr(nodeTooOldText(env.nodeVersion, MIN_NODE))\n return { exitCode: EXIT.FAILURE }\n }\n const depth = depthOf(env.env)\n if (depth >= 1) {\n env.stderr(loopText())\n return { exitCode: EXIT.FAILURE }\n }\n\n const search = findProject(env.cwd, env.boundary ?? processBoundary())\n if (search.kind === 'untrusted') {\n env.stderr(untrustedText(search.dir, search.reason))\n return { exitCode: EXIT.FAILURE }\n }\n if (search.kind === 'none') return outside(argv, search.start, env)\n\n const target = resolveTarget(search.root)\n if (target.kind === 'refused') {\n env.stderr(refusalText(target.reason, target.path, target.realPath))\n return { exitCode: EXIT.FAILURE }\n }\n\n const run = env.run ?? runChild\n const outcome = await run({\n execPath: env.execPath,\n script: target.script,\n args: argv,\n cwd: target.root,\n env: childEnvironment(env.env, env.platform, depth),\n platform: env.platform,\n stdinIsTTY: env.stdinIsTTY,\n })\n switch (outcome.kind) {\n case 'exit':\n return { exitCode: outcome.code }\n case 'signal':\n return { signal: outcome.signal, exitCode: signalExitCode(outcome.signal) }\n case 'error':\n env.stderr(startFailedText(target.script, outcome.message))\n return { exitCode: EXIT.FAILURE }\n }\n}\n\n/** Outside a project: only print (help, version, the installer command, or why not). */\nfunction outside(argv: readonly string[], start: string, env: GuardEnvironment): Outcome {\n const [first, second] = argv\n if (first === undefined || HELP_WORDS.has(first)) {\n env.stdout(helpText(env.version, start))\n return { exitCode: EXIT.OK }\n }\n if (VERSION_FLAGS.has(first)) {\n env.stdout(versionText(env.version))\n return { exitCode: EXIT.OK }\n }\n if (CREATE_WORDS.has(first)) {\n env.stderr(createText(env.version, second))\n return { exitCode: EXIT.USAGE }\n }\n env.stderr(noProjectText(env.version, first, start))\n return { exitCode: EXIT.USAGE }\n}\n","#!/usr/bin/env node\n/**\n * The `strutvane` executable (`npx strutvane <command>`). All decisions live in `main.ts`\n * (tested); this file only connects them to the real process: arguments, output, the exit code,\n * and re-raising a signal the child died of.\n *\n * It is the one file in this package allowed to print with `console` (package.json\n * `strutvane.allowConsole`).\n *\n * @module\n */\nimport { main } from './main.ts'\nimport { ownVersion } from './version.ts'\n\nconst outcome = await main(process.argv.slice(2), {\n cwd: process.cwd(),\n env: process.env,\n execPath: process.execPath,\n platform: process.platform,\n nodeVersion: process.versions.node,\n version: ownVersion(),\n stdinIsTTY: process.stdin.isTTY === true,\n // biome-ignore lint/suspicious/noConsole: the bin entry prints help and the version to stdout\n stdout: (text) => console.log(text),\n stderr: (text) => console.error(text),\n})\n\nprocess.exitCode = outcome.exitCode\n// The child was killed by a signal: die of the same signal, so the shell (or CI) that started us\n// sees exactly that. Windows has no such thing; there the exit code (128 + signal) stands.\nif ('signal' in outcome && process.platform !== 'win32') process.kill(process.pid, outcome.signal)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,kBAAiC;CAC/C,OAAO;EACL,MAAM,QAAQ;EACd,MAAM,OAAO;EACb,KAAK,OAAO,QAAQ,WAAW,aAAa,QAAQ,OAAO,IAAI,KAAA;CACjE;AACF;;AAGA,SAAS,UAAU,MAAwB;CACzC,MAAM,MAAM,CAAC,QAAQ,IAAI,CAAC;CAC1B,IAAI;EACF,IAAI,KAAK,aAAa,OAAO,IAAI,CAAC;CACpC,QAAQ,CAER;CACA,OAAO;AACT;;AAGA,SAAS,SAAS,GAAW,GAAoB;CAC/C,MAAM,OAAO,QAAQ,aAAa,WAAW,QAAQ,aAAa;CAClE,MAAM,QAAQ,MAAuB,OAAO,QAAQ,CAAC,CAAC,CAAC,YAAY,IAAI,QAAQ,CAAC;CAChF,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAC3B;;;;;;;;;;;;AAaA,SAAgB,SAAS,QAAgB,OAAwB;CAC/D,MAAM,MAAM,SAAS,QAAQ,KAAK;CAClC,IAAI,QAAQ,IAAI,OAAO;CACvB,IAAI,WAAW,GAAG,GAAG,OAAO;CAE5B,OADc,IAAI,MAAM,OAAO,CAAC,CAAC,OAChB;AACnB;;AAGA,SAAS,iBAAiB,UAAkB,MAAuB;CACjE,OAAO,CAAC,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GAAG;EAC3B,IAAI,OAAO,WAAW,IAAI,SAAS,MAAM,CAAC;EAC1C,OAAO,EAAE,UAAU,KAAK,MAAM;CAChC;CACA,IAAI,OAAO,cAAc,IAAI,SAAS,OAAO,KAAK,CAAC;CACnD,OAAO,EAAE,UAAU,KAAK,MAAM;AAChC;;;;;;;;;;;;AC7JA,MAAM,UAAU,MAAM,KAAK,QAAQ,KAAK,MAAM,CAAC,GAAG;CAChD,KAAK,QAAQ,IAAI;CACjB,KAAK,QAAQ;CACb,UAAU,QAAQ;CAClB,UAAU,QAAQ;CAClB,aAAa,QAAQ,SAAS;CAC9B,SAAS,WAAW;CACpB,YAAY,QAAQ,MAAM,UAAU;CAEpC,SAAS,SAAS,QAAQ,IAAI,IAAI;CAClC,SAAS,SAAS,QAAQ,MAAM,IAAI;AACtC,CAAC;AAED,QAAQ,WAAW,QAAQ;AAG3B,IAAI,YAAY,WAAW,QAAQ,aAAa,SAAS,QAAQ,KAAK,QAAQ,KAAK,QAAQ,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,47 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strutvane",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0-next.0",
|
|
4
|
+
"description": "npx strutvane: inside a Strutvane project it runs exactly what `node strut` runs, with the project's own @strutvane/framework; outside one it points you to `npm create strutvane`. A guard: never installs or downloads anything, zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strutvane",
|
|
7
7
|
"cli",
|
|
8
|
+
"npx",
|
|
8
9
|
"framework",
|
|
9
|
-
"typescript"
|
|
10
|
-
"launcher"
|
|
10
|
+
"typescript"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://github.com/vishwajit-vm/strutvane-
|
|
12
|
+
"homepage": "https://github.com/vishwajit-vm/strutvane-npx#readme",
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/vishwajit-vm/strutvane-
|
|
14
|
+
"url": "https://github.com/vishwajit-vm/strutvane-npx/issues"
|
|
15
15
|
},
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/vishwajit-vm/strutvane-
|
|
19
|
-
"directory": "packages/launcher"
|
|
18
|
+
"url": "git+https://github.com/vishwajit-vm/strutvane-npx.git"
|
|
20
19
|
},
|
|
21
20
|
"license": "MIT",
|
|
22
21
|
"author": "The Strutvane Authors",
|
|
23
22
|
"type": "module",
|
|
24
23
|
"sideEffects": false,
|
|
25
24
|
"bin": {
|
|
26
|
-
"strutvane": "
|
|
25
|
+
"strutvane": "dist/bin.mjs"
|
|
27
26
|
},
|
|
28
27
|
"exports": {
|
|
29
|
-
".": {
|
|
30
|
-
"types": "./dist/launcher.d.mts",
|
|
31
|
-
"default": "./dist/launcher.mjs"
|
|
32
|
-
},
|
|
33
28
|
"./package.json": "./package.json"
|
|
34
29
|
},
|
|
35
30
|
"files": [
|
|
36
31
|
"dist",
|
|
37
32
|
"README.md",
|
|
33
|
+
"CHANGELOG.md",
|
|
38
34
|
"LICENSE"
|
|
39
35
|
],
|
|
40
36
|
"engines": {
|
|
41
|
-
"node": ">=24"
|
|
37
|
+
"node": ">=24.3"
|
|
38
|
+
},
|
|
39
|
+
"devEngines": {
|
|
40
|
+
"packageManager": {
|
|
41
|
+
"name": "npm",
|
|
42
|
+
"version": ">=11.19.0",
|
|
43
|
+
"onFail": "error"
|
|
44
|
+
}
|
|
42
45
|
},
|
|
43
46
|
"publishConfig": {
|
|
44
47
|
"access": "public",
|
|
45
48
|
"provenance": true
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"lint": "biome check .",
|
|
52
|
+
"format": "biome check --write .",
|
|
53
|
+
"typecheck": "tsc --noEmit",
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"test:coverage": "vitest run --coverage",
|
|
56
|
+
"build": "tsdown",
|
|
57
|
+
"ci": "biome check . && tsc --noEmit && vitest run --coverage && tsdown",
|
|
58
|
+
"changeset": "changeset",
|
|
59
|
+
"version-packages": "changeset version",
|
|
60
|
+
"release": "changeset publish",
|
|
61
|
+
"test:perf": "vitest run --config vitest.perf.config.ts"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@biomejs/biome": "2.6.7",
|
|
65
|
+
"@changesets/cli": "3.0.3",
|
|
66
|
+
"@types/node": "24.19.2",
|
|
67
|
+
"@vitest/coverage-v8": "5.1.0",
|
|
68
|
+
"tsdown": "0.23.7",
|
|
69
|
+
"typescript": "6.0.3",
|
|
70
|
+
"vitest": "5.1.0"
|
|
71
|
+
},
|
|
72
|
+
"strutvane": {
|
|
73
|
+
"allowConsole": [
|
|
74
|
+
"src/bin.ts"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"allowScripts": {
|
|
78
|
+
"fsevents@2.3.3": false
|
|
46
79
|
}
|
|
47
80
|
}
|
package/dist/bin.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
3
|
-
import { homedir, tmpdir } from "node:os";
|
|
4
|
-
import { dirname, isAbsolute, join, relative, resolve, win32 } from "node:path";
|
|
5
|
-
// src/launcher.ts
|
|
6
|
-
/**
|
|
7
|
-
* The `strutvane` launcher (docs/09 §1.1).
|
|
8
|
-
*
|
|
9
|
-
* Installed globally or run through `npx strutvane`, it finds the project-local
|
|
10
|
-
* `@strutvane/cli` and hands project commands to it, so generators and runtime always match the
|
|
11
|
-
* versions pinned in the project's package.json. **Local wins over global for project commands.**
|
|
12
|
-
*
|
|
13
|
-
* **Which folder counts as a project.** Running a `node_modules` folder means running its code, so
|
|
14
|
-
* the search is deliberately narrow. From the working directory (or `--cwd`) upwards, a folder is
|
|
15
|
-
* used only when:
|
|
16
|
-
* - it is a project: its package.json declares `@strutvane/cli` (dependencies or devDependencies)
|
|
17
|
-
* or it contains `strutvane.config.ts`;
|
|
18
|
-
* - it is not a file-system or drive root, not the OS temp directory itself and not a folder above
|
|
19
|
-
* the user's home directory (the search stops at any of these);
|
|
20
|
-
* - on POSIX, it is owned by the current user.
|
|
21
|
-
* A folder with `strutvane.config.ts` also ends the search. See {@link findLocalCli}.
|
|
22
|
-
*
|
|
23
|
-
* **Never delegated:** `--version`, `help` (and no command at all), `new` and `create`. These are
|
|
24
|
-
* the commands people run outside projects, so the launcher always answers them itself.
|
|
25
|
-
*
|
|
26
|
-
* Without a local CLI only project-less commands run: `--version`, `help`, `new <name>` (via
|
|
27
|
-
* `create-strutvane`) and `doctor --global` (via `@strutvane/cli` matching this launcher).
|
|
28
|
-
*
|
|
29
|
-
* The launcher has zero dependencies and does no parsing beyond what delegation needs; it is
|
|
30
|
-
* deliberately tiny so it never has to change when the CLI does. The project boundary rules are
|
|
31
|
-
* mirrored in `@strutvane/cli`'s `project/boundary.ts` (the launcher cannot import it); keep the
|
|
32
|
-
* two in step.
|
|
33
|
-
*
|
|
34
|
-
* @module
|
|
35
|
-
*/
|
|
36
|
-
/** Environment variable carrying the delegation depth (guards against delegation loops). */
|
|
37
|
-
const DEPTH_ENV = "STRUTVANE_LAUNCHER_DEPTH";
|
|
38
|
-
/** Overrides the project starter command (a JSON array), e.g. for tests or mirrors. */
|
|
39
|
-
const CREATE_ENV = "STRUTVANE_CREATE_COMMAND";
|
|
40
|
-
/** Set to `1` to silence the version-mismatch notice. */
|
|
41
|
-
const NO_NOTICE_ENV = "STRUTVANE_NO_UPDATE_NOTICE";
|
|
42
|
-
/** The file that marks a Strutvane project root. */
|
|
43
|
-
const PROJECT_MARKER = "strutvane.config.ts";
|
|
44
|
-
/** The boundary facts of this process. */
|
|
45
|
-
function processBoundary() {
|
|
46
|
-
return {
|
|
47
|
-
home: homedir(),
|
|
48
|
-
temp: tmpdir(),
|
|
49
|
-
uid: typeof process.getuid === "function" ? process.getuid() : void 0
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function readJson(path) {
|
|
53
|
-
try {
|
|
54
|
-
const parsed = JSON.parse(readFileSync(path, "utf8").replace(/^/, ""));
|
|
55
|
-
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
|
|
56
|
-
} catch {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
61
|
-
/**
|
|
62
|
-
* Remove control characters (ANSI escapes, line breaks…) from text that came from a file the
|
|
63
|
-
* launcher does not control, before it is printed to a terminal.
|
|
64
|
-
*/
|
|
65
|
-
function printable(text) {
|
|
66
|
-
return text.replace(CONTROL, "");
|
|
67
|
-
}
|
|
68
|
-
/** Every spelling of a path worth comparing: as given and with symlinks resolved. */
|
|
69
|
-
function spellings(path) {
|
|
70
|
-
const out = [resolve(path)];
|
|
71
|
-
try {
|
|
72
|
-
out.push(realpathSync(path));
|
|
73
|
-
} catch {}
|
|
74
|
-
return out;
|
|
75
|
-
}
|
|
76
|
-
/** Path equality; case-insensitive on Windows and macOS, whose file systems usually are. */
|
|
77
|
-
function samePath(a, b) {
|
|
78
|
-
const fold = process.platform === "win32" || process.platform === "darwin";
|
|
79
|
-
const norm = (p) => {
|
|
80
|
-
const r = resolve(p);
|
|
81
|
-
return fold ? r.toLowerCase() : r;
|
|
82
|
-
};
|
|
83
|
-
return norm(a) === norm(b);
|
|
84
|
-
}
|
|
85
|
-
/** Whether `ancestor` is a strict ancestor of `path`. */
|
|
86
|
-
function isStrictAncestor(ancestor, path) {
|
|
87
|
-
const rel = relative(ancestor, path);
|
|
88
|
-
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Whether `dir` may never be treated as a project: a file-system or drive root, the OS temp
|
|
92
|
-
* directory itself, or a folder above the user's home directory. Anyone with write access to
|
|
93
|
-
* those (other users, downloads, extracted archives) could otherwise plant a `node_modules` that
|
|
94
|
-
* runs for every command typed below them.
|
|
95
|
-
*/
|
|
96
|
-
function isForbiddenProjectDir(dir, facts) {
|
|
97
|
-
for (const d of spellings(dir)) {
|
|
98
|
-
if (dirname(d) === d) return true;
|
|
99
|
-
for (const temp of spellings(facts.temp)) if (samePath(d, temp)) return true;
|
|
100
|
-
for (const home of spellings(facts.home)) if (isStrictAncestor(d, home)) return true;
|
|
101
|
-
}
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
/** POSIX only: whether `dir` is owned by the current user. Always `true` without a uid. */
|
|
105
|
-
function isOwnedByCurrentUser(dir, facts) {
|
|
106
|
-
if (facts.uid === void 0) return true;
|
|
107
|
-
try {
|
|
108
|
-
return statSync(dir).uid === facts.uid;
|
|
109
|
-
} catch {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/** Whether a package.json declares `@strutvane/cli` as a dependency or devDependency. */
|
|
114
|
-
function declaresCli(manifest) {
|
|
115
|
-
if (manifest === void 0) return false;
|
|
116
|
-
return ["dependencies", "devDependencies"].some((field) => {
|
|
117
|
-
const deps = manifest[field];
|
|
118
|
-
return typeof deps === "object" && deps !== null && Object.hasOwn(deps, "@strutvane/cli") && typeof deps["@strutvane/cli"] === "string";
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/** The executable declared by a CLI manifest, if it resolves inside the package. */
|
|
122
|
-
function binOf(packageDir, manifest) {
|
|
123
|
-
const bin = manifest["bin"];
|
|
124
|
-
const rel = typeof bin === "string" ? bin : typeof bin === "object" && bin !== null ? bin["strutvane-cli"] ?? Object.values(bin)[0] : void 0;
|
|
125
|
-
if (typeof rel !== "string") return void 0;
|
|
126
|
-
const path = resolve(packageDir, rel);
|
|
127
|
-
if (!existsSync(path)) return void 0;
|
|
128
|
-
const realDir = realpathSync(packageDir);
|
|
129
|
-
const inner = relative(realDir, realpathSync(path));
|
|
130
|
-
return inner.startsWith("..") || isAbsolute(inner) ? void 0 : path;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Find the project-local `@strutvane/cli`, searching upwards from `start` under the boundary
|
|
134
|
-
* rules in the module documentation. Returns `undefined` when there is none (or none that may be
|
|
135
|
-
* trusted).
|
|
136
|
-
*/
|
|
137
|
-
function findLocalCli(start, facts = processBoundary()) {
|
|
138
|
-
let dir = resolve(start);
|
|
139
|
-
for (;;) {
|
|
140
|
-
if (isForbiddenProjectDir(dir, facts)) return void 0;
|
|
141
|
-
const hasMarker = existsSync(join(dir, PROJECT_MARKER));
|
|
142
|
-
if ((hasMarker || declaresCli(readJson(join(dir, "package.json")))) && isOwnedByCurrentUser(dir, facts)) {
|
|
143
|
-
const packageDir = join(dir, "node_modules", "@strutvane", "cli");
|
|
144
|
-
const manifest = readJson(join(packageDir, "package.json"));
|
|
145
|
-
if (manifest !== void 0) {
|
|
146
|
-
const bin = binOf(packageDir, manifest);
|
|
147
|
-
if (bin !== void 0) return {
|
|
148
|
-
packageDir,
|
|
149
|
-
version: printable(typeof manifest["version"] === "string" ? manifest["version"] : "0.0.0").slice(0, 64),
|
|
150
|
-
bin
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (hasMarker) return void 0;
|
|
155
|
-
const parent = dirname(dir);
|
|
156
|
-
if (parent === dir) return void 0;
|
|
157
|
-
dir = parent;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/** The `--cwd` value from argv, if any (`--cwd x` or `--cwd=x`). */
|
|
161
|
-
function cwdFlag(argv) {
|
|
162
|
-
for (let i = 0; i < argv.length; i++) {
|
|
163
|
-
const token = argv[i] ?? "";
|
|
164
|
-
if (token === "--") return void 0;
|
|
165
|
-
if (token === "--cwd") return argv[i + 1];
|
|
166
|
-
if (token.startsWith("--cwd=")) return token.slice(6);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/** The leading command word of argv (skipping flags and the `--cwd` value), if any. */
|
|
170
|
-
function commandWord(argv) {
|
|
171
|
-
for (let i = 0; i < argv.length; i++) {
|
|
172
|
-
const token = argv[i] ?? "";
|
|
173
|
-
if (token === "--") return void 0;
|
|
174
|
-
if (token === "--cwd") {
|
|
175
|
-
i++;
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
if (!token.startsWith("-")) return token;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/** Commands the launcher always answers itself, even inside a project. */
|
|
182
|
-
const LAUNCHER_COMMANDS = /* @__PURE__ */ new Set([
|
|
183
|
-
"help",
|
|
184
|
-
"new",
|
|
185
|
-
"create"
|
|
186
|
-
]);
|
|
187
|
-
/**
|
|
188
|
-
* Whether argv is a command the launcher answers itself and never delegates: no command word
|
|
189
|
-
* (`strutvane`, `strutvane --version`, `strutvane --help`), `help`, `new` or `create`.
|
|
190
|
-
*/
|
|
191
|
-
function isLauncherCommand(argv) {
|
|
192
|
-
const word = commandWord(argv);
|
|
193
|
-
return word === void 0 || LAUNCHER_COMMANDS.has(word);
|
|
194
|
-
}
|
|
195
|
-
const SIGNAL_CODES = {
|
|
196
|
-
SIGINT: 130,
|
|
197
|
-
SIGTERM: 143,
|
|
198
|
-
SIGHUP: 129
|
|
199
|
-
};
|
|
200
|
-
/** The real spawner: inherits stdio and ignores Ctrl+C itself so the child decides. */
|
|
201
|
-
const nodeLaunchSpawner = (command, args, options) => new Promise((resolvePromise, reject) => {
|
|
202
|
-
const ignore = () => {};
|
|
203
|
-
process.on("SIGINT", ignore);
|
|
204
|
-
const child = spawn(command, [...args], {
|
|
205
|
-
stdio: "inherit",
|
|
206
|
-
env: options.env,
|
|
207
|
-
shell: options.shell
|
|
208
|
-
});
|
|
209
|
-
child.on("error", (error) => {
|
|
210
|
-
process.off("SIGINT", ignore);
|
|
211
|
-
reject(error);
|
|
212
|
-
});
|
|
213
|
-
child.on("exit", (code, signal) => {
|
|
214
|
-
process.off("SIGINT", ignore);
|
|
215
|
-
resolvePromise(code ?? (signal === null ? 1 : SIGNAL_CODES[signal] ?? 1));
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
/** Characters allowed in arguments that pass through a Windows shell (the npx.cmd fallback). */
|
|
219
|
-
const SHELL_SAFE = /^[A-Za-z0-9@._/:=+,-]+$/;
|
|
220
|
-
/** Characters allowed in an absolute shim path that is quoted for cmd.exe. */
|
|
221
|
-
const SHELL_SAFE_PATH = /^[^"%!^&|<>\r\n]+$/;
|
|
222
|
-
/**
|
|
223
|
-
* Environment for child processes. On Windows, `NoDefaultCurrentDirectoryInExePath` stops
|
|
224
|
-
* cmd.exe (and the `.cmd` shims it runs) from finding programs in the working directory before
|
|
225
|
-
* PATH, so a project folder can never shadow `node` or `npm`.
|
|
226
|
-
*/
|
|
227
|
-
function childEnv(env, platform, extra = {}) {
|
|
228
|
-
return {
|
|
229
|
-
...env,
|
|
230
|
-
...platform === "win32" ? { NoDefaultCurrentDirectoryInExePath: "1" } : {},
|
|
231
|
-
...extra
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* npm's `npx-cli.js` next to the running Node.js, so npx runs as `node npx-cli.js` with no shell
|
|
236
|
-
* and no PATH lookup. Windows installs keep npm in `<node dir>/node_modules/npm`; POSIX installs
|
|
237
|
-
* in `<prefix>/lib/node_modules/npm`.
|
|
238
|
-
*/
|
|
239
|
-
function findNpxCli(execPath, platform) {
|
|
240
|
-
const p = platform === "win32" ? win32 : {
|
|
241
|
-
join,
|
|
242
|
-
dirname
|
|
243
|
-
};
|
|
244
|
-
const dir = p.dirname(execPath);
|
|
245
|
-
return (platform === "win32" ? [p.join(dir, "node_modules", "npm", "bin", "npx-cli.js")] : [p.join(dir, "..", "lib", "node_modules", "npm", "bin", "npx-cli.js"), p.join(dir, "node_modules", "npm", "bin", "npx-cli.js")]).find((c) => existsSync(c));
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Windows only: the absolute path of `name` (e.g. `npx`) from PATH, trying each PATHEXT
|
|
249
|
-
* extension. The working directory, relative PATH entries and empty entries are skipped, which is
|
|
250
|
-
* exactly the lookup order cmd.exe would otherwise use to run a planted `npx.cmd` from the
|
|
251
|
-
* project folder.
|
|
252
|
-
*/
|
|
253
|
-
function resolveWindowsExecutable(name, env, cwd, exists = existsSync) {
|
|
254
|
-
const pathValue = env["PATH"] ?? env["Path"] ?? "";
|
|
255
|
-
const exts = (env["PATHEXT"] ?? ".COM;.EXE;.BAT;.CMD").split(";").filter((e) => e.startsWith("."));
|
|
256
|
-
const here = win32.resolve(cwd).toLowerCase();
|
|
257
|
-
for (const entry of pathValue.split(";")) {
|
|
258
|
-
const dir = entry.trim().replace(/^"(.*)"$/, "$1");
|
|
259
|
-
if (dir === "" || !win32.isAbsolute(dir) || win32.resolve(dir).toLowerCase() === here) continue;
|
|
260
|
-
for (const ext of exts) {
|
|
261
|
-
const candidate = win32.join(dir, `${name}${ext.toLowerCase()}`);
|
|
262
|
-
if (exists(candidate)) return candidate;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function help(version, local) {
|
|
267
|
-
const lines = [`strutvane ${version}: the Strutvane command line launcher`, ""];
|
|
268
|
-
if (local === void 0) lines.push("No project-local @strutvane/cli was found, so only these commands are available:");
|
|
269
|
-
else lines.push(`This project uses @strutvane/cli ${local.version}; it handles every project command`, "(e.g. strutvane make:model Invoice, strutvane migrate). To list them all, run:", " pnpm exec strutvane-cli help (or: npx strutvane-cli help)", "", "The launcher itself answers:");
|
|
270
|
-
lines.push(" strutvane new <name> [flags] Create a project (runs create-strutvane)", " strutvane doctor --global Check this machine (Node.js version, package managers)", " strutvane --version Print the launcher version", " strutvane help Show this help", "");
|
|
271
|
-
if (local === void 0) lines.push("Inside a project (a folder whose package.json lists @strutvane/cli, or with", "strutvane.config.ts), project commands are handled by the project's own @strutvane/cli,", "so they always match the versions in package.json.", "");
|
|
272
|
-
return lines.join("\n");
|
|
273
|
-
}
|
|
274
|
-
/** Parse `STRUTVANE_CREATE_COMMAND`: a non-empty JSON array of strings, else `undefined`. */
|
|
275
|
-
function parseCommandOverride(value) {
|
|
276
|
-
let parsed;
|
|
277
|
-
try {
|
|
278
|
-
parsed = JSON.parse(value);
|
|
279
|
-
} catch {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
if (!Array.isArray(parsed) || parsed.length === 0 || !parsed.every((p) => typeof p === "string" && p !== "")) return;
|
|
283
|
-
return parsed;
|
|
284
|
-
}
|
|
285
|
-
/** Run a project-less command through npx (or the override in `STRUTVANE_CREATE_COMMAND`). */
|
|
286
|
-
async function viaNpx(env, pkg, args) {
|
|
287
|
-
const childEnvironment = childEnv(env.env, env.platform);
|
|
288
|
-
const override = env.env[CREATE_ENV];
|
|
289
|
-
if (override !== void 0 && pkg.startsWith("create-strutvane")) {
|
|
290
|
-
const parsed = parseCommandOverride(override);
|
|
291
|
-
if (parsed === void 0) {
|
|
292
|
-
env.stderr(`strutvane: ${CREATE_ENV} must be a JSON array of strings.\n`);
|
|
293
|
-
return 2;
|
|
294
|
-
}
|
|
295
|
-
const [command = "", ...rest] = parsed;
|
|
296
|
-
return env.spawn(command, [...rest, ...args], {
|
|
297
|
-
env: childEnvironment,
|
|
298
|
-
shell: false
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
const npxArgs = [
|
|
302
|
-
"--yes",
|
|
303
|
-
pkg,
|
|
304
|
-
...args
|
|
305
|
-
];
|
|
306
|
-
const npxCli = findNpxCli(env.execPath, env.platform);
|
|
307
|
-
if (npxCli !== void 0) return env.spawn(env.execPath, [npxCli, ...npxArgs], {
|
|
308
|
-
env: childEnvironment,
|
|
309
|
-
shell: false
|
|
310
|
-
});
|
|
311
|
-
if (env.platform !== "win32") return env.spawn("npx", npxArgs, {
|
|
312
|
-
env: childEnvironment,
|
|
313
|
-
shell: false
|
|
314
|
-
});
|
|
315
|
-
const shim = resolveWindowsExecutable("npx", env.env, env.cwd);
|
|
316
|
-
if (shim === void 0 || !SHELL_SAFE_PATH.test(shim)) {
|
|
317
|
-
env.stderr("strutvane: could not find npx on PATH. Install Node.js with npm.\n");
|
|
318
|
-
return 2;
|
|
319
|
-
}
|
|
320
|
-
const unsafe = npxArgs.find((a) => !SHELL_SAFE.test(a));
|
|
321
|
-
if (unsafe !== void 0) {
|
|
322
|
-
env.stderr(`strutvane: refusing to pass "${printable(unsafe)}" to a shell. Use plain names and flags.\n`);
|
|
323
|
-
return 2;
|
|
324
|
-
}
|
|
325
|
-
return env.spawn(`"${shim}"`, npxArgs, {
|
|
326
|
-
env: childEnvironment,
|
|
327
|
-
shell: true
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
/** Run the launcher. Returns the exit code (the delegated CLI's, when delegating). */
|
|
331
|
-
async function runLauncher(argv, env) {
|
|
332
|
-
const depth = Number(env.env["STRUTVANE_LAUNCHER_DEPTH"] ?? "0");
|
|
333
|
-
const flag = cwdFlag(argv);
|
|
334
|
-
const start = flag === void 0 ? env.cwd : resolve(env.cwd, flag);
|
|
335
|
-
const boundary = env.boundary ?? processBoundary();
|
|
336
|
-
const local = depth >= 1 ? void 0 : findLocalCli(start, boundary);
|
|
337
|
-
if (local !== void 0 && !isLauncherCommand(argv)) {
|
|
338
|
-
const quiet = argv.includes("--json") || argv.includes("--quiet") || argv.includes("-q");
|
|
339
|
-
if (local.version !== env.version && !quiet && env.env["STRUTVANE_NO_UPDATE_NOTICE"] !== "1") env.stderr(`strutvane: using the project's @strutvane/cli ${local.version} (launcher ${env.version}).\n`);
|
|
340
|
-
return env.spawn(env.execPath, [local.bin, ...argv], {
|
|
341
|
-
env: childEnv(env.env, env.platform, { [DEPTH_ENV]: String(depth + 1) }),
|
|
342
|
-
shell: false
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
const word = commandWord(argv);
|
|
346
|
-
if (word === void 0 && (argv.includes("--version") || argv.includes("-V"))) {
|
|
347
|
-
env.stdout(`strutvane ${env.version}\n`);
|
|
348
|
-
if (local !== void 0) env.stdout(`project @strutvane/cli ${local.version}\n`);
|
|
349
|
-
return 0;
|
|
350
|
-
}
|
|
351
|
-
if (word === void 0 || word === "help") {
|
|
352
|
-
env.stdout(help(env.version, local));
|
|
353
|
-
return 0;
|
|
354
|
-
}
|
|
355
|
-
const [first, ...rest] = argv;
|
|
356
|
-
if (first === "new" || first === "create") return viaNpx(env, "create-strutvane@latest", rest);
|
|
357
|
-
if (first === "doctor" && rest.includes("--global")) return viaNpx(env, `@strutvane/cli@${env.version}`, argv);
|
|
358
|
-
env.stderr([
|
|
359
|
-
`strutvane: "${printable(word)}" needs a Strutvane project, but no project-local @strutvane/cli was found`,
|
|
360
|
-
` (searched from ${start} upwards; only folders whose package.json lists @strutvane/cli`,
|
|
361
|
-
" or that contain strutvane.config.ts count, and never a drive root, the temp folder or a",
|
|
362
|
-
" folder above your home directory).",
|
|
363
|
-
" Run it inside a project, or add the CLI to this one: pnpm add -D @strutvane/cli",
|
|
364
|
-
" Create a new project with: strutvane new <name>",
|
|
365
|
-
""
|
|
366
|
-
].join("\n"));
|
|
367
|
-
return 2;
|
|
368
|
-
}
|
|
369
|
-
export { resolveWindowsExecutable as _, childEnv as a, declaresCli as c, isForbiddenProjectDir as d, isLauncherCommand as f, processBoundary as g, printable as h, PROJECT_MARKER as i, findLocalCli as l, nodeLaunchSpawner as m, DEPTH_ENV as n, commandWord as o, isOwnedByCurrentUser as p, NO_NOTICE_ENV as r, cwdFlag as s, CREATE_ENV as t, findNpxCli as u, runLauncher as v };
|
|
370
|
-
|
|
371
|
-
//# sourceMappingURL=launcher-BrUi5a5_.mjs.map
|