create-atom.io 0.0.7 → 0.0.9
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/{create-atom-Bs3iurKr.js → create-atom-C-qP8t8P.js} +15 -2
- package/dist/create-atom-C-qP8t8P.js.map +1 -0
- package/dist/create-atom.d.ts.map +1 -1
- package/dist/create-atom.js +1 -1
- package/dist/create-atom.x.js +1 -1
- package/package.json +1 -1
- package/src/create-atom.ts +24 -2
- package/dist/create-atom-Bs3iurKr.js.map +0 -1
|
@@ -59,10 +59,23 @@ async function useSpinner(startMessage, fn, finishMessage) {
|
|
|
59
59
|
}
|
|
60
60
|
async function scaffold(to, opts) {
|
|
61
61
|
await promises.mkdir(to, { recursive: true });
|
|
62
|
-
const templateInfo = await getPackageInfo(`@atom.io/template-${opts.templateName}
|
|
62
|
+
const templateInfo = await getPackageInfo(`@atom.io/template-${opts.templateName}`, { paths: [process.cwd(), import.meta.dirname] });
|
|
63
63
|
if (!templateInfo) throw new Error(`Could not find template package`);
|
|
64
64
|
const { rootPath } = templateInfo;
|
|
65
65
|
await templateDir(rootPath, to, opts);
|
|
66
|
+
const nodeDirPath = resolve(to, `node`);
|
|
67
|
+
try {
|
|
68
|
+
await promises.access(nodeDirPath);
|
|
69
|
+
} catch {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!(await promises.stat(nodeDirPath)).isDirectory()) return;
|
|
73
|
+
const nodeFiles = await promises.readdir(nodeDirPath, { withFileTypes: true });
|
|
74
|
+
await Promise.all(nodeFiles.map(async (dirent) => {
|
|
75
|
+
if (!dirent.isFile()) return;
|
|
76
|
+
const filename = resolve(nodeDirPath, dirent.name);
|
|
77
|
+
await promises.chmod(filename, 493);
|
|
78
|
+
}));
|
|
66
79
|
}
|
|
67
80
|
/**
|
|
68
81
|
* Recursive fs copy, swiped from `create-wmr`:
|
|
@@ -118,4 +131,4 @@ function getPkgManager() {
|
|
|
118
131
|
|
|
119
132
|
//#endregion
|
|
120
133
|
export { createAtom as t };
|
|
121
|
-
//# sourceMappingURL=create-atom-
|
|
134
|
+
//# sourceMappingURL=create-atom-C-qP8t8P.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-atom-C-qP8t8P.js","names":["pico: Colors","opts: CreateAtomOptions","fs","dependencies: string[]","devDependencies: string[]"],"sources":["../src/create-atom.ts"],"sourcesContent":["import { existsSync, promises as fs } from \"node:fs\"\nimport { resolve } from \"node:path\"\n\nimport * as prompts from \"@clack/prompts\"\nimport { getPackageInfo } from \"local-pkg\"\nimport picocolors from \"picocolors\"\nimport type { Colors } from \"picocolors/types\"\nimport { x } from \"tinyexec\"\n\nconst pico: Colors = picocolors.createColors(true)\n\nconst s = prompts.spinner()\n\nexport type PackageManager = `bun` | `npm` | `pnpm` | `yarn`\nexport type TemplateName = `preact-svg-editor` | `react-node-backend`\n\nexport type CreateAtomOptions = {\n\tpackageManager: PackageManager\n\ttemplateName: TemplateName\n}\n\nexport type CreateAtomOptionsPreloaded = {\n\t[K in keyof CreateAtomOptions]?: CreateAtomOptions[K] | undefined\n} & { skipHints?: boolean | undefined }\n\nexport async function createAtom(\n\targDir: string | undefined,\n\toptions: CreateAtomOptionsPreloaded,\n): Promise<void> {\n\tconst skipHint = options.skipHints ?? false\n\tconst packageManager = options.packageManager ?? getPkgManager()\n\n\tprompts.intro(pico.greenBright(`atom.io - Data Components for TypeScript`))\n\n\tconst { dir, templateName } = await prompts.group(\n\t\t{\n\t\t\ttemplateName: () =>\n\t\t\t\tprompts.select<TemplateName>({\n\t\t\t\t\tmessage: `Template:`,\n\t\t\t\t\tinitialValue: `preact-svg-editor`,\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: `Preact SVG Editor`,\n\t\t\t\t\t\t\tvalue: `preact-svg-editor`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: `React Node Backend`,\n\t\t\t\t\t\t\tvalue: `react-node-backend`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\tdir: () =>\n\t\t\t\targDir\n\t\t\t\t\t? Promise.resolve(argDir)\n\t\t\t\t\t: prompts.text({\n\t\t\t\t\t\t\tmessage: `Project directory:`,\n\t\t\t\t\t\t\tplaceholder: `my-app`,\n\t\t\t\t\t\t\tvalidate(value) {\n\t\t\t\t\t\t\t\tif (value.length === 0) {\n\t\t\t\t\t\t\t\t\treturn `Directory name is required!`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (existsSync(value)) {\n\t\t\t\t\t\t\t\t\treturn `Refusing to overwrite existing directory or file! Please provide a non-clashing name.`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t},\n\t\t{\n\t\t\tonCancel: () => {\n\t\t\t\tprompts.cancel(pico.yellow(`Cancelled`))\n\t\t\t\tprocess.exit(0)\n\t\t\t},\n\t\t},\n\t)\n\tconst targetDir = resolve(process.cwd(), dir)\n\tconst opts: CreateAtomOptions = { packageManager, templateName }\n\n\tawait useSpinner(\n\t\t`Setting up your project directory...`,\n\t\t() => scaffold(targetDir, opts),\n\t\t`Set up project directory`,\n\t)\n\n\tawait useSpinner(\n\t\t`Installing project dependencies...`,\n\t\t() => installDeps(targetDir, opts),\n\t\t`Installed project dependencies`,\n\t)\n\n\tif (skipHint === false) {\n\t\tconst gettingStarted = `\n\t\t\t${pico.dim(`$`)} ${pico.blueBright(`cd ${dir}`)}\n\t\t\t${pico.dim(`$`)} ${pico.blueBright(\n\t\t\t\t`${\n\t\t\t\t\tpackageManager === `npm`\n\t\t\t\t\t\t? `npm run`\n\t\t\t\t\t\t: packageManager === `bun`\n\t\t\t\t\t\t\t? `bun run`\n\t\t\t\t\t\t\t: packageManager\n\t\t\t\t} dev`,\n\t\t\t)}\n\t\t`\n\t\tprompts.note(\n\t\t\tgettingStarted.trim().replace(/^\\t\\t\\t/gm, ``),\n\t\t\t`Getting Started`,\n\t\t)\n\t}\n\n\tprompts.outro(pico.green(`You're all set!`))\n}\n\nasync function useSpinner(\n\tstartMessage: string,\n\tfn: () => Promise<void>,\n\tfinishMessage: string,\n): Promise<void> {\n\ts.start(startMessage)\n\tawait fn()\n\ts.stop(pico.green(finishMessage))\n}\n\nasync function scaffold(to: string, opts: CreateAtomOptions): Promise<void> {\n\tawait fs.mkdir(to, { recursive: true })\n\n\tconst templateInfo = await getPackageInfo(\n\t\t`@atom.io/template-${opts.templateName}`,\n\t\t{\n\t\t\tpaths: [process.cwd(), import.meta.dirname],\n\t\t},\n\t)\n\tif (!templateInfo) throw new Error(`Could not find template package`)\n\tconst { rootPath } = templateInfo\n\tawait templateDir(rootPath, to, opts)\n\tconst nodeDirPath = resolve(to, `node`)\n\n\ttry {\n\t\tawait fs.access(nodeDirPath)\n\t} catch {\n\t\treturn\n\t}\n\n\tconst nodeDir = await fs.stat(nodeDirPath)\n\tif (!nodeDir.isDirectory()) return\n\n\tconst nodeFiles = await fs.readdir(nodeDirPath, { withFileTypes: true })\n\n\tawait Promise.all(\n\t\tnodeFiles.map(async (dirent) => {\n\t\t\tif (!dirent.isFile()) return\n\t\t\tconst filename = resolve(nodeDirPath, dirent.name)\n\t\t\tawait fs.chmod(filename, 0o755)\n\t\t}),\n\t)\n}\n\n/**\n * Recursive fs copy, swiped from `create-wmr`:\n * https://github.com/preactjs/wmr/blob/3c5672ecd2f958c8eaf372d33c084dc69228ae3f/packages/create-wmr/src/index.js#L108-L124\n */\nasync function templateDir(\n\tfrom: string,\n\tto: string,\n\topts: CreateAtomOptions,\n): Promise<void[]> {\n\tconst files = await fs.readdir(from)\n\tconst results = await Promise.all(\n\t\tfiles.map(async (f) => {\n\t\t\tif (f === `.` || f === `..`) return\n\t\t\tconst filename = resolve(from, f)\n\t\t\tif ((await fs.stat(filename)).isDirectory()) {\n\t\t\t\tawait fs.mkdir(resolve(to, f), { recursive: true })\n\t\t\t\treturn templateDir(filename, resolve(to, f), opts)\n\t\t\t}\n\t\t\tif (opts.packageManager !== `npm` && f === `README.md`) {\n\t\t\t\tawait fs.writeFile(\n\t\t\t\t\tresolve(to, f),\n\t\t\t\t\t(await fs.readFile(filename, `utf-8`)).replace(\n\t\t\t\t\t\t/npm run/g,\n\t\t\t\t\t\topts.packageManager === `bun` ? `bun run` : opts.packageManager,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\treturn\n\t\t\t}\n\t\t\t// Publishing to npm renames the .gitignore to .npmignore\n\t\t\t// https://github.com/npm/npm/issues/7252#issuecomment-253339460\n\t\t\tif (f === `_gitignore`) f = `.gitignore`\n\t\t\tawait fs.copyFile(filename, resolve(to, f))\n\t\t}),\n\t)\n\treturn results.flat(99)\n}\n\nasync function installDeps(to: string, opts: CreateAtomOptions) {\n\tconst dependencies: string[] = []\n\tconst devDependencies: string[] = []\n\n\tconst installOpts = {\n\t\tpackageManager: opts.packageManager,\n\t\tto,\n\t}\n\n\tawait installPackages(dependencies, { ...installOpts })\n\tdevDependencies.length &&\n\t\t(await installPackages(devDependencies, { ...installOpts, dev: true }))\n}\n\ntype InstallOptions = {\n\tpackageManager: `bun` | `npm` | `pnpm` | `yarn`\n\tto: string\n\tdev?: boolean\n}\n\nfunction installPackages(pkgs: string[], opts: InstallOptions) {\n\treturn x(\n\t\topts.packageManager,\n\t\t[\n\t\t\t// `yarn add` will fail if nothing is provided\n\t\t\topts.packageManager === `yarn` ? (pkgs.length ? `add` : ``) : `install`,\n\t\t\topts.dev ? `-D` : ``,\n\t\t\t...pkgs,\n\t\t].filter(Boolean),\n\t\t{\n\t\t\tnodeOptions: {\n\t\t\t\tstdio: `ignore`,\n\t\t\t\tcwd: opts.to,\n\t\t\t},\n\t\t},\n\t)\n}\n\nfunction getPkgManager(): `bun` | `npm` | `pnpm` | `yarn` {\n\tconst userAgent = process.env[`npm_config_user_agent`] ?? ``\n\tif (userAgent.startsWith(`yarn`)) return `yarn`\n\tif (user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
1
|
+
{"version":3,"file":"create-atom.d.ts","names":[],"sources":["../src/create-atom.ts"],"sourcesContent":[],"mappings":";KAaY,cAAA;AAAA,KACA,YAAA,GADA,mBAAA,GAAA,oBAAA;AACA,KAEA,iBAAA,GAFA;EAEZ,cAAY,EACK,cADL;EAKZ,YAAY,EAHG,YAGH;CACC;AAAqB,KADtB,0BAAA,GACsB,QAAA,MAArB,iBAAqB,IAAA,iBAAA,CAAkB,CAAlB,CAAA,GAAA,SAAA,EAAA,GAAA;EAAkB,SAAA,CAAA,EAAA,OAAA,GAAA,SAAA;CAAA;AAG9B,iBAAA,UAAA,CAEZ,MAAA,EAAA,MAAA,GAAA,SACP,EAAA,OAAA,EADO,0BACP,CAAA,EAAA,OAAA,CAAA,IAAA,CAAA"}
|
package/dist/create-atom.js
CHANGED
package/dist/create-atom.x.js
CHANGED
package/package.json
CHANGED
package/src/create-atom.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { existsSync, promises as fs } from "node:fs"
|
|
2
|
-
import {
|
|
3
|
-
import { fileURLToPath } from "node:url"
|
|
2
|
+
import { resolve } from "node:path"
|
|
4
3
|
|
|
5
4
|
import * as prompts from "@clack/prompts"
|
|
6
5
|
import { getPackageInfo } from "local-pkg"
|
|
@@ -125,10 +124,33 @@ async function scaffold(to: string, opts: CreateAtomOptions): Promise<void> {
|
|
|
125
124
|
|
|
126
125
|
const templateInfo = await getPackageInfo(
|
|
127
126
|
`@atom.io/template-${opts.templateName}`,
|
|
127
|
+
{
|
|
128
|
+
paths: [process.cwd(), import.meta.dirname],
|
|
129
|
+
},
|
|
128
130
|
)
|
|
129
131
|
if (!templateInfo) throw new Error(`Could not find template package`)
|
|
130
132
|
const { rootPath } = templateInfo
|
|
131
133
|
await templateDir(rootPath, to, opts)
|
|
134
|
+
const nodeDirPath = resolve(to, `node`)
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
await fs.access(nodeDirPath)
|
|
138
|
+
} catch {
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const nodeDir = await fs.stat(nodeDirPath)
|
|
143
|
+
if (!nodeDir.isDirectory()) return
|
|
144
|
+
|
|
145
|
+
const nodeFiles = await fs.readdir(nodeDirPath, { withFileTypes: true })
|
|
146
|
+
|
|
147
|
+
await Promise.all(
|
|
148
|
+
nodeFiles.map(async (dirent) => {
|
|
149
|
+
if (!dirent.isFile()) return
|
|
150
|
+
const filename = resolve(nodeDirPath, dirent.name)
|
|
151
|
+
await fs.chmod(filename, 0o755)
|
|
152
|
+
}),
|
|
153
|
+
)
|
|
132
154
|
}
|
|
133
155
|
|
|
134
156
|
/**
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-atom-Bs3iurKr.js","names":["pico: Colors","opts: CreateAtomOptions","fs","dependencies: string[]","devDependencies: string[]"],"sources":["../src/create-atom.ts"],"sourcesContent":["import { existsSync, promises as fs } from \"node:fs\"\nimport { dirname, resolve } from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\n\nimport * as prompts from \"@clack/prompts\"\nimport { getPackageInfo } from \"local-pkg\"\nimport picocolors from \"picocolors\"\nimport type { Colors } from \"picocolors/types\"\nimport { x } from \"tinyexec\"\n\nconst pico: Colors = picocolors.createColors(true)\n\nconst s = prompts.spinner()\n\nexport type PackageManager = `bun` | `npm` | `pnpm` | `yarn`\nexport type TemplateName = `preact-svg-editor` | `react-node-backend`\n\nexport type CreateAtomOptions = {\n\tpackageManager: PackageManager\n\ttemplateName: TemplateName\n}\n\nexport type CreateAtomOptionsPreloaded = {\n\t[K in keyof CreateAtomOptions]?: CreateAtomOptions[K] | undefined\n} & { skipHints?: boolean | undefined }\n\nexport async function createAtom(\n\targDir: string | undefined,\n\toptions: CreateAtomOptionsPreloaded,\n): Promise<void> {\n\tconst skipHint = options.skipHints ?? false\n\tconst packageManager = options.packageManager ?? getPkgManager()\n\n\tprompts.intro(pico.greenBright(`atom.io - Data Components for TypeScript`))\n\n\tconst { dir, templateName } = await prompts.group(\n\t\t{\n\t\t\ttemplateName: () =>\n\t\t\t\tprompts.select<TemplateName>({\n\t\t\t\t\tmessage: `Template:`,\n\t\t\t\t\tinitialValue: `preact-svg-editor`,\n\t\t\t\t\toptions: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: `Preact SVG Editor`,\n\t\t\t\t\t\t\tvalue: `preact-svg-editor`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tlabel: `React Node Backend`,\n\t\t\t\t\t\t\tvalue: `react-node-backend`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\t\tdir: () =>\n\t\t\t\targDir\n\t\t\t\t\t? Promise.resolve(argDir)\n\t\t\t\t\t: prompts.text({\n\t\t\t\t\t\t\tmessage: `Project directory:`,\n\t\t\t\t\t\t\tplaceholder: `my-app`,\n\t\t\t\t\t\t\tvalidate(value) {\n\t\t\t\t\t\t\t\tif (value.length === 0) {\n\t\t\t\t\t\t\t\t\treturn `Directory name is required!`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (existsSync(value)) {\n\t\t\t\t\t\t\t\t\treturn `Refusing to overwrite existing directory or file! Please provide a non-clashing name.`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t},\n\t\t{\n\t\t\tonCancel: () => {\n\t\t\t\tprompts.cancel(pico.yellow(`Cancelled`))\n\t\t\t\tprocess.exit(0)\n\t\t\t},\n\t\t},\n\t)\n\tconst targetDir = resolve(process.cwd(), dir)\n\tconst opts: CreateAtomOptions = { packageManager, templateName }\n\n\tawait useSpinner(\n\t\t`Setting up your project directory...`,\n\t\t() => scaffold(targetDir, opts),\n\t\t`Set up project directory`,\n\t)\n\n\tawait useSpinner(\n\t\t`Installing project dependencies...`,\n\t\t() => installDeps(targetDir, opts),\n\t\t`Installed project dependencies`,\n\t)\n\n\tif (skipHint === false) {\n\t\tconst gettingStarted = `\n\t\t\t${pico.dim(`$`)} ${pico.blueBright(`cd ${dir}`)}\n\t\t\t${pico.dim(`$`)} ${pico.blueBright(\n\t\t\t\t`${\n\t\t\t\t\tpackageManager === `npm`\n\t\t\t\t\t\t? `npm run`\n\t\t\t\t\t\t: packageManager === `bun`\n\t\t\t\t\t\t\t? `bun run`\n\t\t\t\t\t\t\t: packageManager\n\t\t\t\t} dev`,\n\t\t\t)}\n\t\t`\n\t\tprompts.note(\n\t\t\tgettingStarted.trim().replace(/^\\t\\t\\t/gm, ``),\n\t\t\t`Getting Started`,\n\t\t)\n\t}\n\n\tprompts.outro(pico.green(`You're all set!`))\n}\n\nasync function useSpinner(\n\tstartMessage: string,\n\tfn: () => Promise<void>,\n\tfinishMessage: string,\n): Promise<void> {\n\ts.start(startMessage)\n\tawait fn()\n\ts.stop(pico.green(finishMessage))\n}\n\nasync function scaffold(to: string, opts: CreateAtomOptions): Promise<void> {\n\tawait fs.mkdir(to, { recursive: true })\n\n\tconst templateInfo = await getPackageInfo(\n\t\t`@atom.io/template-${opts.templateName}`,\n\t)\n\tif (!templateInfo) throw new Error(`Could not find template package`)\n\tconst { rootPath } = templateInfo\n\tawait templateDir(rootPath, to, opts)\n}\n\n/**\n * Recursive fs copy, swiped from `create-wmr`:\n * https://github.com/preactjs/wmr/blob/3c5672ecd2f958c8eaf372d33c084dc69228ae3f/packages/create-wmr/src/index.js#L108-L124\n */\nasync function templateDir(\n\tfrom: string,\n\tto: string,\n\topts: CreateAtomOptions,\n): Promise<void[]> {\n\tconst files = await fs.readdir(from)\n\tconst results = await Promise.all(\n\t\tfiles.map(async (f) => {\n\t\t\tif (f === `.` || f === `..`) return\n\t\t\tconst filename = resolve(from, f)\n\t\t\tif ((await fs.stat(filename)).isDirectory()) {\n\t\t\t\tawait fs.mkdir(resolve(to, f), { recursive: true })\n\t\t\t\treturn templateDir(filename, resolve(to, f), opts)\n\t\t\t}\n\t\t\tif (opts.packageManager !== `npm` && f === `README.md`) {\n\t\t\t\tawait fs.writeFile(\n\t\t\t\t\tresolve(to, f),\n\t\t\t\t\t(await fs.readFile(filename, `utf-8`)).replace(\n\t\t\t\t\t\t/npm run/g,\n\t\t\t\t\t\topts.packageManager === `bun` ? `bun run` : opts.packageManager,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\treturn\n\t\t\t}\n\t\t\t// Publishing to npm renames the .gitignore to .npmignore\n\t\t\t// https://github.com/npm/npm/issues/7252#issuecomment-253339460\n\t\t\tif (f === `_gitignore`) f = `.gitignore`\n\t\t\tawait fs.copyFile(filename, resolve(to, f))\n\t\t}),\n\t)\n\treturn results.flat(99)\n}\n\nasync function installDeps(to: string, opts: CreateAtomOptions) {\n\tconst dependencies: string[] = []\n\tconst devDependencies: string[] = []\n\n\tconst installOpts = {\n\t\tpackageManager: opts.packageManager,\n\t\tto,\n\t}\n\n\tawait installPackages(dependencies, { ...installOpts })\n\tdevDependencies.length &&\n\t\t(await installPackages(devDependencies, { ...installOpts, dev: true }))\n}\n\ntype InstallOptions = {\n\tpackageManager: `bun` | `npm` | `pnpm` | `yarn`\n\tto: string\n\tdev?: boolean\n}\n\nfunction installPackages(pkgs: string[], opts: InstallOptions) {\n\treturn x(\n\t\topts.packageManager,\n\t\t[\n\t\t\t// `yarn add` will fail if nothing is provided\n\t\t\topts.packageManager === `yarn` ? (pkgs.length ? `add` : ``) : `install`,\n\t\t\topts.dev ? `-D` : ``,\n\t\t\t...pkgs,\n\t\t].filter(Boolean),\n\t\t{\n\t\t\tnodeOptions: {\n\t\t\t\tstdio: `ignore`,\n\t\t\t\tcwd: opts.to,\n\t\t\t},\n\t\t},\n\t)\n}\n\nfunction getPkgManager(): `bun` | `npm` | `pnpm` | `yarn` {\n\tconst userAgent = process.env[`npm_config_user_agent`] ?? ``\n\tif (userAgent.startsWith(`yarn`)) return `yarn`\n\tif (userAgent.startsWith(`pnpm`)) return `pnpm`\n\tif (userAgent.startsWith(`bun`)) return `bun`\n\treturn `npm`\n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