create-blixis 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface CreateOptions {
|
|
|
14
14
|
install?: InstallRunner;
|
|
15
15
|
}
|
|
16
16
|
export declare function detectPackageManager(userAgent: string | undefined): PackageManager;
|
|
17
|
+
/** `"pnpm@11.25.0"` from an `npm_config_user_agent` like `pnpm/11.25.0 npm/? node/v24.0.0`, for the `packageManager` field. Bun isn't managed by corepack, so it gets none. */
|
|
18
|
+
export declare function packageManagerPin(userAgent: string | undefined): string | undefined;
|
|
17
19
|
/** The whole CLI as a function of argv + environment — no process.exit()/console.log(), so it is directly testable. */
|
|
18
20
|
export declare function runCreate(argv: readonly string[], options: CreateOptions): Promise<CreateResult>;
|
|
19
21
|
//#endregion
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";YAgBY;iBAEK;EACf;EACA;EACA;;;YAIU,iBAAiB,iBAAiB,yBAAyB,gBAAgB;iBAEtE;EACf;;EAEA;EACA,UAAU;;wBAGI,qBAAqB,gCAAgC;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";YAgBY;iBAEK;EACf;EACA;EACA;;;YAIU,iBAAiB,iBAAiB,yBAAyB,gBAAgB;iBAEtE;EACf;;EAEA;EACA,UAAU;;wBAGI,qBAAqB,gCAAgC;;wBAMrD,kBAAkB;;wBAqBZ,UAAU,yBAAyB,SAAS,gBAAgB,QAAQ"}
|
package/dist/index.js
CHANGED
|
@@ -5,13 +5,14 @@ import { basename, dirname, join, relative, resolve } from "node:path";
|
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
//#region src/template.ts
|
|
7
7
|
/** Every file of the generated app, keyed by path relative to the project root. */
|
|
8
|
-
function templateFiles(packageName) {
|
|
8
|
+
function templateFiles(packageName, packageManagerPin) {
|
|
9
9
|
return {
|
|
10
10
|
"package.json": `${JSON.stringify({
|
|
11
11
|
name: packageName,
|
|
12
12
|
version: "0.0.0",
|
|
13
13
|
private: true,
|
|
14
14
|
type: "module",
|
|
15
|
+
...packageManagerPin ? { packageManager: packageManagerPin } : {},
|
|
15
16
|
engines: { node: ">=24" },
|
|
16
17
|
scripts: {
|
|
17
18
|
dev: "tsc -p tsconfig.json && concurrently -k -n tsc,app \"tsc -p tsconfig.json --watch --preserveWatchOutput\" \"node --watch dist/main.js\"",
|
|
@@ -119,12 +120,12 @@ var ScaffoldError = class extends Error {
|
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
122
|
/** Writes the starter app into `cwd/<target>`. The directory may not exist yet, or must be empty. */
|
|
122
|
-
function scaffold(cwd, target) {
|
|
123
|
+
function scaffold(cwd, target, packageManagerPin) {
|
|
123
124
|
const directory = resolve(cwd, target);
|
|
124
125
|
const packageName = basename(directory);
|
|
125
126
|
if (!PACKAGE_NAME.test(packageName)) throw new ScaffoldError(`"${packageName}" is not a valid package name — use lowercase letters, digits, "-", "." or "_", starting with a letter or digit.`);
|
|
126
127
|
if (existsSync(directory) && readdirSync(directory).length > 0) throw new ScaffoldError(`${target} already exists and is not empty.`);
|
|
127
|
-
const files = Object.entries(templateFiles(packageName));
|
|
128
|
+
const files = Object.entries(templateFiles(packageName, packageManagerPin));
|
|
128
129
|
for (const [path, content] of files) {
|
|
129
130
|
const absolute = join(directory, path);
|
|
130
131
|
mkdirSync(dirname(absolute), { recursive: true });
|
|
@@ -149,6 +150,11 @@ function detectPackageManager(userAgent) {
|
|
|
149
150
|
const name = userAgent?.split("/")[0];
|
|
150
151
|
return name === "pnpm" || name === "yarn" || name === "bun" ? name : "npm";
|
|
151
152
|
}
|
|
153
|
+
/** `"pnpm@11.25.0"` from an `npm_config_user_agent` like `pnpm/11.25.0 npm/? node/v24.0.0`, for the `packageManager` field. Bun isn't managed by corepack, so it gets none. */
|
|
154
|
+
function packageManagerPin(userAgent) {
|
|
155
|
+
const match = /^(pnpm|npm|yarn)\/(\d+\.\d+\.\d+)/.exec(userAgent ?? "");
|
|
156
|
+
return match ? `${match[1]}@${match[2]}` : void 0;
|
|
157
|
+
}
|
|
152
158
|
function addArgs(pm, dev, packages) {
|
|
153
159
|
return [
|
|
154
160
|
pm === "npm" ? "install" : "add",
|
|
@@ -189,7 +195,7 @@ async function runCreate(argv, options) {
|
|
|
189
195
|
};
|
|
190
196
|
let result;
|
|
191
197
|
try {
|
|
192
|
-
result = scaffold(options.cwd, target);
|
|
198
|
+
result = scaffold(options.cwd, target, packageManagerPin(options.userAgent));
|
|
193
199
|
} catch (error) {
|
|
194
200
|
if (error instanceof ScaffoldError) return {
|
|
195
201
|
exitCode: 1,
|
|
@@ -234,6 +240,6 @@ if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.ar
|
|
|
234
240
|
}
|
|
235
241
|
/* v8 ignore stop */
|
|
236
242
|
//#endregion
|
|
237
|
-
export { detectPackageManager, runCreate };
|
|
243
|
+
export { detectPackageManager, packageManagerPin, runCreate };
|
|
238
244
|
|
|
239
245
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/template.ts","../src/scaffold.ts","../src/index.ts"],"sourcesContent":["/** Every file of the generated app, keyed by path relative to the project root. */\nexport function templateFiles(packageName: string): Record<string, string> {\n return {\n \"package.json\": `${JSON.stringify(\n {\n name: packageName,\n version: \"0.0.0\",\n private: true,\n type: \"module\",\n engines: { node: \">=24\" },\n scripts: {\n // Decorators need tsc (esbuild/tsx drop the metadata), so dev is \"compile once, then\n // recompile on change while node restarts on the new output\".\n dev: 'tsc -p tsconfig.json && concurrently -k -n tsc,app \"tsc -p tsconfig.json --watch --preserveWatchOutput\" \"node --watch dist/main.js\"',\n build: \"tsc -p tsconfig.json\",\n start: \"node dist/main.js\",\n typecheck: \"tsc --noEmit -p tsconfig.json\",\n },\n },\n null,\n 2,\n )}\\n`,\n\n \"tsconfig.json\": `${JSON.stringify(\n {\n compilerOptions: {\n target: \"es2023\",\n lib: [\"es2023\"],\n types: [\"node\"],\n module: \"nodenext\",\n moduleResolution: \"nodenext\",\n strict: true,\n experimentalDecorators: true,\n emitDecoratorMetadata: true,\n useDefineForClassFields: false,\n esModuleInterop: true,\n skipLibCheck: true,\n outDir: \"dist\",\n rootDir: \"src\",\n },\n include: [\"src\"],\n },\n null,\n 2,\n )}\\n`,\n\n \".gitignore\": \"node_modules\\ndist\\n\",\n\n \"README.md\": `# ${packageName}\n\nA [Blixis](https://blixis-io.github.io/framework/) app.\n\n\\`\\`\\`bash\nnpm run dev # rebuilds and restarts on every change\n# or: npm run build && npm start\ncurl http://localhost:3000/hello/world\n\\`\\`\\`\n\nDecorators need \\`tsc\\` (not tsx/esbuild) — see the\n[installation notes](https://blixis-io.github.io/framework/start-here/installation/).\n`,\n\n \"src/hello.service.ts\": `import { Injectable } from \"@blixis-io/di\";\n\n@Injectable()\nexport class HelloService {\n greet(name: string): string {\n return \\`Hello, \\${name}!\\`;\n }\n}\n`,\n\n \"src/hello.controller.ts\": `import { Controller, Get, Param } from \"@blixis-io/http\";\nimport { HelloService } from \"./hello.service.js\";\n\n@Controller(\"hello\")\nexport class HelloController {\n constructor(private readonly hello: HelloService) {}\n\n @Get(\":name\")\n greet(@Param(\"name\") name: string) {\n return { message: this.hello.greet(name) };\n }\n}\n`,\n\n \"src/app.module.ts\": `import { Module } from \"@blixis-io/core\";\nimport { HelloController } from \"./hello.controller.js\";\nimport { HelloService } from \"./hello.service.js\";\n\n@Module({\n providers: [HelloService],\n controllers: [HelloController],\n})\nexport class AppModule {}\n`,\n\n \"src/main.ts\": `import { createHttpApplication } from \"@blixis-io/http\";\nimport { AppModule } from \"./app.module.js\";\n\nconst app = await createHttpApplication(AppModule);\nconst port = Number(process.env[\"PORT\"] ?? 3000);\nawait app.listen(port);\n\nconsole.log(\\`Listening on http://localhost:\\${port}\\`);\n\nprocess.on(\"SIGTERM\", () => {\n void app.close(\"SIGTERM\").then(() => process.exit(0));\n});\n`,\n };\n}\n\nexport const RUNTIME_DEPENDENCIES = [\"@blixis-io/core\", \"@blixis-io/di\", \"@blixis-io/http\"] as const;\nexport const DEV_DEPENDENCIES = [\"typescript\", \"@types/node\", \"concurrently\"] as const;\n","import { existsSync, mkdirSync, readdirSync, writeFileSync } from \"node:fs\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport { templateFiles } from \"./template.js\";\n\nconst PACKAGE_NAME = /^[a-z0-9-~][a-z0-9-._~]*$/;\n\nexport class ScaffoldError extends Error {\n override readonly name = \"ScaffoldError\";\n}\n\nexport interface ScaffoldResult {\n directory: string;\n packageName: string;\n files: string[];\n}\n\n/** Writes the starter app into `cwd/<target>`. The directory may not exist yet, or must be empty. */\nexport function scaffold(cwd: string, target: string): ScaffoldResult {\n const directory = resolve(cwd, target);\n const packageName = basename(directory);\n\n if (!PACKAGE_NAME.test(packageName)) {\n throw new ScaffoldError(\n `\"${packageName}\" is not a valid package name — use lowercase letters, digits, \"-\", \".\" or \"_\", starting with a letter or digit.`,\n );\n }\n if (existsSync(directory) && readdirSync(directory).length > 0) {\n throw new ScaffoldError(`${target} already exists and is not empty.`);\n }\n\n const files = Object.entries(templateFiles(packageName));\n for (const [path, content] of files) {\n const absolute = join(directory, path);\n mkdirSync(dirname(absolute), { recursive: true });\n writeFileSync(absolute, content);\n }\n\n return { directory, packageName, files: files.map(([path]) => path) };\n}\n","#!/usr/bin/env node\nimport { spawn } from \"node:child_process\";\nimport { realpathSync } from \"node:fs\";\nimport { relative } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { ScaffoldError, scaffold } from \"./scaffold.js\";\nimport { DEV_DEPENDENCIES, RUNTIME_DEPENDENCIES } from \"./template.js\";\n\nconst USAGE = `create-blixis <directory> [--no-install]\n\n pnpm create blixis my-app\n npm create blixis@latest my-app\n\n --no-install write the files only; print the install commands instead\n`;\n\nexport type PackageManager = \"pnpm\" | \"npm\" | \"yarn\" | \"bun\";\n\nexport interface CreateResult {\n exitCode: number;\n stdout: string;\n stderr: string;\n}\n\n/** Runs one package-manager command; resolves with its exit code. Injected so tests never touch the network. */\nexport type InstallRunner = (command: string, args: readonly string[], cwd: string) => Promise<number>;\n\nexport interface CreateOptions {\n cwd: string;\n /** `npm_config_user_agent` — tells us which package manager invoked `create`. */\n userAgent?: string | undefined;\n install?: InstallRunner;\n}\n\nexport function detectPackageManager(userAgent: string | undefined): PackageManager {\n const name = userAgent?.split(\"/\")[0];\n return name === \"pnpm\" || name === \"yarn\" || name === \"bun\" ? name : \"npm\";\n}\n\nfunction addArgs(pm: PackageManager, dev: boolean, packages: readonly string[]): string[] {\n const verb = pm === \"npm\" ? \"install\" : \"add\";\n const devFlag = pm === \"bun\" ? \"-d\" : \"-D\";\n return [verb, ...(dev ? [devFlag] : []), ...packages];\n}\n\nconst runWithInheritedStdio: InstallRunner = (command, args, cwd) =>\n new Promise((resolve, reject) => {\n const child = spawn(command, args, { cwd, stdio: \"inherit\", shell: process.platform === \"win32\" });\n child.once(\"error\", reject);\n child.once(\"close\", (code) => {\n resolve(code ?? 1);\n });\n });\n\n/** The whole CLI as a function of argv + environment — no process.exit()/console.log(), so it is directly testable. */\nexport async function runCreate(argv: readonly string[], options: CreateOptions): Promise<CreateResult> {\n const flags = argv.filter((arg) => arg.startsWith(\"-\"));\n const [target, ...extra] = argv.filter((arg) => !arg.startsWith(\"-\"));\n\n if (flags.includes(\"--help\") || flags.includes(\"-h\")) {\n return { exitCode: 0, stdout: USAGE, stderr: \"\" };\n }\n const unknown = flags.find((flag) => flag !== \"--no-install\");\n if (unknown) {\n return { exitCode: 1, stdout: \"\", stderr: `Unknown option \"${unknown}\"\\n\\n${USAGE}` };\n }\n if (!target || extra.length > 0) {\n return { exitCode: 1, stdout: \"\", stderr: `Usage: ${USAGE}` };\n }\n\n let result;\n try {\n result = scaffold(options.cwd, target);\n } catch (error) {\n if (error instanceof ScaffoldError) {\n return { exitCode: 1, stdout: \"\", stderr: `${error.message}\\n` };\n }\n throw error;\n }\n\n const pm = detectPackageManager(options.userAgent);\n const runtime = addArgs(pm, false, RUNTIME_DEPENDENCIES);\n const dev = addArgs(pm, true, DEV_DEPENDENCIES);\n const dir = relative(options.cwd, result.directory) || \".\";\n let stdout = `Created ${result.packageName} in ${dir}\\n`;\n\n if (flags.includes(\"--no-install\")) {\n stdout += `\\nNext:\\n cd ${dir}\\n ${pm} ${runtime.join(\" \")}\\n ${pm} ${dev.join(\" \")}\\n`;\n } else {\n const install = options.install ?? runWithInheritedStdio;\n for (const args of [runtime, dev]) {\n const code = await install(pm, args, result.directory);\n if (code !== 0) {\n return {\n exitCode: code,\n stdout,\n stderr: `\\n\"${pm} ${args.join(\" \")}\" failed (exit ${code}). The files are in ${dir}; run the install yourself.\\n`,\n };\n }\n }\n const run = pm === \"npm\" ? \"npm run\" : pm;\n stdout += `\\nNext:\\n cd ${dir}\\n ${run} dev\\n curl http://localhost:3000/hello/world\\n`;\n }\n\n return { exitCode: 0, stdout, stderr: \"\" };\n}\n\n// Same entry-point check as @blixis-io/cli: pathToFileURL(realpathSync(...)) so a\n// bin shim's symlink and a path with spaces both still match import.meta.url.\n/* v8 ignore start -- @preserve: process wiring, exercised by index.test.ts spawning the real built binary */\nif (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {\n const result = await runCreate(process.argv.slice(2), {\n cwd: process.cwd(),\n userAgent: process.env[\"npm_config_user_agent\"],\n });\n if (result.stdout) {\n process.stdout.write(result.stdout);\n }\n if (result.stderr) {\n process.stderr.write(result.stderr);\n }\n process.exitCode = result.exitCode;\n}\n/* v8 ignore stop */\n"],"mappings":";;;;;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AU,QAAQ,KAAK,MAAM,CAAC,GAAG;EACpD,KAAK,QAAQ,IAAI;EACjB,WAAW,QAAQ,IAAI;CACzB,CAAC;CACD,IAAI,OAAO,QACT,QAAQ,OAAO,MAAM,OAAO,MAAM;CAEpC,IAAI,OAAO,QACT,QAAQ,OAAO,MAAM,OAAO,MAAM;CAEpC,QAAQ,WAAW,OAAO;AAC5B"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/template.ts","../src/scaffold.ts","../src/index.ts"],"sourcesContent":["/** Every file of the generated app, keyed by path relative to the project root. */\nexport function templateFiles(packageName: string, packageManagerPin?: string): Record<string, string> {\n return {\n \"package.json\": `${JSON.stringify(\n {\n name: packageName,\n version: \"0.0.0\",\n private: true,\n type: \"module\",\n // Pins the package manager (corepack honours it), so a Docker image or CI job installs with the same\n // major version the project was created with instead of whatever is newest.\n ...(packageManagerPin ? { packageManager: packageManagerPin } : {}),\n engines: { node: \">=24\" },\n scripts: {\n // Decorators need tsc (esbuild/tsx drop the metadata), so dev is \"compile once, then\n // recompile on change while node restarts on the new output\".\n dev: 'tsc -p tsconfig.json && concurrently -k -n tsc,app \"tsc -p tsconfig.json --watch --preserveWatchOutput\" \"node --watch dist/main.js\"',\n build: \"tsc -p tsconfig.json\",\n start: \"node dist/main.js\",\n typecheck: \"tsc --noEmit -p tsconfig.json\",\n },\n },\n null,\n 2,\n )}\\n`,\n\n \"tsconfig.json\": `${JSON.stringify(\n {\n compilerOptions: {\n target: \"es2023\",\n lib: [\"es2023\"],\n types: [\"node\"],\n module: \"nodenext\",\n moduleResolution: \"nodenext\",\n strict: true,\n experimentalDecorators: true,\n emitDecoratorMetadata: true,\n useDefineForClassFields: false,\n esModuleInterop: true,\n skipLibCheck: true,\n outDir: \"dist\",\n rootDir: \"src\",\n },\n include: [\"src\"],\n },\n null,\n 2,\n )}\\n`,\n\n \".gitignore\": \"node_modules\\ndist\\n\",\n\n \"README.md\": `# ${packageName}\n\nA [Blixis](https://blixis-io.github.io/framework/) app.\n\n\\`\\`\\`bash\nnpm run dev # rebuilds and restarts on every change\n# or: npm run build && npm start\ncurl http://localhost:3000/hello/world\n\\`\\`\\`\n\nDecorators need \\`tsc\\` (not tsx/esbuild) — see the\n[installation notes](https://blixis-io.github.io/framework/start-here/installation/).\n`,\n\n \"src/hello.service.ts\": `import { Injectable } from \"@blixis-io/di\";\n\n@Injectable()\nexport class HelloService {\n greet(name: string): string {\n return \\`Hello, \\${name}!\\`;\n }\n}\n`,\n\n \"src/hello.controller.ts\": `import { Controller, Get, Param } from \"@blixis-io/http\";\nimport { HelloService } from \"./hello.service.js\";\n\n@Controller(\"hello\")\nexport class HelloController {\n constructor(private readonly hello: HelloService) {}\n\n @Get(\":name\")\n greet(@Param(\"name\") name: string) {\n return { message: this.hello.greet(name) };\n }\n}\n`,\n\n \"src/app.module.ts\": `import { Module } from \"@blixis-io/core\";\nimport { HelloController } from \"./hello.controller.js\";\nimport { HelloService } from \"./hello.service.js\";\n\n@Module({\n providers: [HelloService],\n controllers: [HelloController],\n})\nexport class AppModule {}\n`,\n\n \"src/main.ts\": `import { createHttpApplication } from \"@blixis-io/http\";\nimport { AppModule } from \"./app.module.js\";\n\nconst app = await createHttpApplication(AppModule);\nconst port = Number(process.env[\"PORT\"] ?? 3000);\nawait app.listen(port);\n\nconsole.log(\\`Listening on http://localhost:\\${port}\\`);\n\nprocess.on(\"SIGTERM\", () => {\n void app.close(\"SIGTERM\").then(() => process.exit(0));\n});\n`,\n };\n}\n\nexport const RUNTIME_DEPENDENCIES = [\"@blixis-io/core\", \"@blixis-io/di\", \"@blixis-io/http\"] as const;\nexport const DEV_DEPENDENCIES = [\"typescript\", \"@types/node\", \"concurrently\"] as const;\n","import { existsSync, mkdirSync, readdirSync, writeFileSync } from \"node:fs\";\nimport { basename, dirname, join, resolve } from \"node:path\";\nimport { templateFiles } from \"./template.js\";\n\nconst PACKAGE_NAME = /^[a-z0-9-~][a-z0-9-._~]*$/;\n\nexport class ScaffoldError extends Error {\n override readonly name = \"ScaffoldError\";\n}\n\nexport interface ScaffoldResult {\n directory: string;\n packageName: string;\n files: string[];\n}\n\n/** Writes the starter app into `cwd/<target>`. The directory may not exist yet, or must be empty. */\nexport function scaffold(cwd: string, target: string, packageManagerPin?: string): ScaffoldResult {\n const directory = resolve(cwd, target);\n const packageName = basename(directory);\n\n if (!PACKAGE_NAME.test(packageName)) {\n throw new ScaffoldError(\n `\"${packageName}\" is not a valid package name — use lowercase letters, digits, \"-\", \".\" or \"_\", starting with a letter or digit.`,\n );\n }\n if (existsSync(directory) && readdirSync(directory).length > 0) {\n throw new ScaffoldError(`${target} already exists and is not empty.`);\n }\n\n const files = Object.entries(templateFiles(packageName, packageManagerPin));\n for (const [path, content] of files) {\n const absolute = join(directory, path);\n mkdirSync(dirname(absolute), { recursive: true });\n writeFileSync(absolute, content);\n }\n\n return { directory, packageName, files: files.map(([path]) => path) };\n}\n","#!/usr/bin/env node\nimport { spawn } from \"node:child_process\";\nimport { realpathSync } from \"node:fs\";\nimport { relative } from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { ScaffoldError, scaffold } from \"./scaffold.js\";\nimport { DEV_DEPENDENCIES, RUNTIME_DEPENDENCIES } from \"./template.js\";\n\nconst USAGE = `create-blixis <directory> [--no-install]\n\n pnpm create blixis my-app\n npm create blixis@latest my-app\n\n --no-install write the files only; print the install commands instead\n`;\n\nexport type PackageManager = \"pnpm\" | \"npm\" | \"yarn\" | \"bun\";\n\nexport interface CreateResult {\n exitCode: number;\n stdout: string;\n stderr: string;\n}\n\n/** Runs one package-manager command; resolves with its exit code. Injected so tests never touch the network. */\nexport type InstallRunner = (command: string, args: readonly string[], cwd: string) => Promise<number>;\n\nexport interface CreateOptions {\n cwd: string;\n /** `npm_config_user_agent` — tells us which package manager invoked `create`. */\n userAgent?: string | undefined;\n install?: InstallRunner;\n}\n\nexport function detectPackageManager(userAgent: string | undefined): PackageManager {\n const name = userAgent?.split(\"/\")[0];\n return name === \"pnpm\" || name === \"yarn\" || name === \"bun\" ? name : \"npm\";\n}\n\n/** `\"pnpm@11.25.0\"` from an `npm_config_user_agent` like `pnpm/11.25.0 npm/? node/v24.0.0`, for the `packageManager` field. Bun isn't managed by corepack, so it gets none. */\nexport function packageManagerPin(userAgent: string | undefined): string | undefined {\n const match = /^(pnpm|npm|yarn)\\/(\\d+\\.\\d+\\.\\d+)/.exec(userAgent ?? \"\");\n return match ? `${match[1]}@${match[2]}` : undefined;\n}\n\nfunction addArgs(pm: PackageManager, dev: boolean, packages: readonly string[]): string[] {\n const verb = pm === \"npm\" ? \"install\" : \"add\";\n const devFlag = pm === \"bun\" ? \"-d\" : \"-D\";\n return [verb, ...(dev ? [devFlag] : []), ...packages];\n}\n\nconst runWithInheritedStdio: InstallRunner = (command, args, cwd) =>\n new Promise((resolve, reject) => {\n const child = spawn(command, args, { cwd, stdio: \"inherit\", shell: process.platform === \"win32\" });\n child.once(\"error\", reject);\n child.once(\"close\", (code) => {\n resolve(code ?? 1);\n });\n });\n\n/** The whole CLI as a function of argv + environment — no process.exit()/console.log(), so it is directly testable. */\nexport async function runCreate(argv: readonly string[], options: CreateOptions): Promise<CreateResult> {\n const flags = argv.filter((arg) => arg.startsWith(\"-\"));\n const [target, ...extra] = argv.filter((arg) => !arg.startsWith(\"-\"));\n\n if (flags.includes(\"--help\") || flags.includes(\"-h\")) {\n return { exitCode: 0, stdout: USAGE, stderr: \"\" };\n }\n const unknown = flags.find((flag) => flag !== \"--no-install\");\n if (unknown) {\n return { exitCode: 1, stdout: \"\", stderr: `Unknown option \"${unknown}\"\\n\\n${USAGE}` };\n }\n if (!target || extra.length > 0) {\n return { exitCode: 1, stdout: \"\", stderr: `Usage: ${USAGE}` };\n }\n\n let result;\n try {\n result = scaffold(options.cwd, target, packageManagerPin(options.userAgent));\n } catch (error) {\n if (error instanceof ScaffoldError) {\n return { exitCode: 1, stdout: \"\", stderr: `${error.message}\\n` };\n }\n throw error;\n }\n\n const pm = detectPackageManager(options.userAgent);\n const runtime = addArgs(pm, false, RUNTIME_DEPENDENCIES);\n const dev = addArgs(pm, true, DEV_DEPENDENCIES);\n const dir = relative(options.cwd, result.directory) || \".\";\n let stdout = `Created ${result.packageName} in ${dir}\\n`;\n\n if (flags.includes(\"--no-install\")) {\n stdout += `\\nNext:\\n cd ${dir}\\n ${pm} ${runtime.join(\" \")}\\n ${pm} ${dev.join(\" \")}\\n`;\n } else {\n const install = options.install ?? runWithInheritedStdio;\n for (const args of [runtime, dev]) {\n const code = await install(pm, args, result.directory);\n if (code !== 0) {\n return {\n exitCode: code,\n stdout,\n stderr: `\\n\"${pm} ${args.join(\" \")}\" failed (exit ${code}). The files are in ${dir}; run the install yourself.\\n`,\n };\n }\n }\n const run = pm === \"npm\" ? \"npm run\" : pm;\n stdout += `\\nNext:\\n cd ${dir}\\n ${run} dev\\n curl http://localhost:3000/hello/world\\n`;\n }\n\n return { exitCode: 0, stdout, stderr: \"\" };\n}\n\n// Same entry-point check as @blixis-io/cli: pathToFileURL(realpathSync(...)) so a\n// bin shim's symlink and a path with spaces both still match import.meta.url.\n/* v8 ignore start -- @preserve: process wiring, exercised by index.test.ts spawning the real built binary */\nif (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {\n const result = await runCreate(process.argv.slice(2), {\n cwd: process.cwd(),\n userAgent: process.env[\"npm_config_user_agent\"],\n });\n if (result.stdout) {\n process.stdout.write(result.stdout);\n }\n if (result.stderr) {\n process.stderr.write(result.stderr);\n }\n process.exitCode = result.exitCode;\n}\n/* v8 ignore stop */\n"],"mappings":";;;;;;;AACA,SAAgB,cAAc,aAAqB,mBAAoD;CACrG,OAAO;EACL,gBAAgB,GAAG,KAAK,UACtB;GACE,MAAM;GACN,SAAS;GACT,SAAS;GACT,MAAM;GAGN,GAAI,oBAAoB,EAAE,gBAAgB,kBAAkB,IAAI,CAAC;GACjE,SAAS,EAAE,MAAM,OAAO;GACxB,SAAS;IAGP,KAAK;IACL,OAAO;IACP,OAAO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