Skip to content

Commit 4604aaf

Browse files
committed
refactor: Swap out @antfu/install-pkg, invoke execa directly to fix yarn
1 parent 6fb1312 commit 4604aaf

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"README.md"
1919
],
2020
"dependencies": {
21-
"@antfu/install-pkg": "^0.3.1",
2221
"@clack/prompts": "^0.6.3",
22+
"execa": "^8.0.1",
2323
"kolorist": "^1.8.0"
2424
},
2525
"devDependencies": {

src/index.js

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { promises as fs, existsSync } from 'node:fs';
33
import { dirname, resolve } from 'node:path';
44
import { fileURLToPath } from 'node:url';
55
import * as prompts from '@clack/prompts';
6-
import { installPackage, detectPackageManager } from '@antfu/install-pkg';
6+
import { execa } from 'execa';
77
import * as kl from 'kolorist';
88

99
const s = prompts.spinner();
@@ -16,13 +16,11 @@ const brandColor = /** @type {const} */ ([174, 128, 255]);
1616
//
1717
// Don't love the flag, need to find a better name.
1818
const skipHint = process.argv.slice(2).includes('--skip-hints');
19-
const packageManager =
20-
(await detectPackageManager()) ??
21-
(/yarn/.test(process.env.npm_execpath)
22-
? 'yarn'
23-
: process.env.PNPM_PACKAGE_NAME
24-
? 'pnpm'
25-
: 'npm');
19+
const packageManager = /yarn/.test(process.env.npm_execpath)
20+
? 'yarn'
21+
: process.env.PNPM_PACKAGE_NAME
22+
? 'pnpm'
23+
: 'npm';
2624

2725
prompts.intro(
2826
kl.trueColor(...brandColor)(
@@ -214,7 +212,7 @@ async function templateDir(from, to, useTS) {
214212

215213
/**
216214
* @param {string} to
217-
* @param {import('@antfu/install-pkg').Agent} packageManager
215+
* @param {'yarn' | 'pnpm' | 'npm'} packageManager
218216
* @param {ConfigOptions} opts
219217
*/
220218
async function installDeps(to, packageManager, opts) {
@@ -223,15 +221,34 @@ async function installDeps(to, packageManager, opts) {
223221

224222
const installOpts = {
225223
packageManager,
226-
cwd: to,
227-
silent: true,
228-
}
224+
to,
225+
};
229226

230227
if (opts.useTS) devDependencies.push('typescript');
231228
if (opts.useRouter) dependencies.push('preact-iso');
232229
if (opts.usePrerender) dependencies.push('preact-iso', 'preact-render-to-string')
233230
if (opts.useESLint) devDependencies.push('eslint', 'eslint-config-preact');
234231

235-
await installPackage(dependencies, { ...installOpts });
236-
devDependencies.length && installPackage(devDependencies, { ...installOpts, dev: true});
232+
await installPackages(dependencies, { ...installOpts });
233+
devDependencies.length && installPackages(devDependencies, { ...installOpts, dev: true });
234+
}
235+
236+
/**
237+
* @param {string[]} pkgs
238+
* @param {{ packageManager: 'yarn' | 'pnpm' | 'npm', to: string, dev?: boolean }} opts
239+
*/
240+
function installPackages(pkgs, opts) {
241+
return execa(
242+
opts.packageManager,
243+
[
244+
// `yarn add` will fail if nothing is provided
245+
opts.packageManager === 'yarn' ? (pkgs.length ? 'add' : '') : 'install',
246+
opts.dev ? '-D' : '',
247+
...pkgs,
248+
].filter(Boolean),
249+
{
250+
stdio: 'ignore',
251+
cwd: opts.to,
252+
},
253+
);
237254
}

yarn.lock

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
# yarn lockfile v1
33

44

5-
"@antfu/install-pkg@^0.3.1":
6-
version "0.3.1"
7-
resolved "https://registry.yarnpkg.com/@antfu/install-pkg/-/install-pkg-0.3.1.tgz#f63b3c98f92b455cd0929d4503eab276c9680943"
8-
integrity sha512-A3zWY9VeTPnxlMiZtsGHw2lSd3ghwvL8s9RiGOtqvDxhhFfZ781ynsGBa/iUnDJ5zBrmTFQrJDud3TGgRISaxw==
9-
dependencies:
10-
execa "^8.0.1"
11-
125
"@clack/core@^0.3.2":
136
version "0.3.2"
147
resolved "https://registry.npmjs.org/@clack/core/-/core-0.3.2.tgz"
@@ -72,7 +65,7 @@ is-stream@^3.0.0:
7265

7366
isexe@^2.0.0:
7467
version "2.0.0"
75-
resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz"
68+
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
7669
integrity sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==
7770

7871
kolorist@^1.8.0:
@@ -91,9 +84,9 @@ mimic-fn@^4.0.0:
9184
integrity sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==
9285

9386
npm-run-path@^5.1.0:
94-
version "5.2.0"
95-
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-5.2.0.tgz#224cdd22c755560253dd71b83a1ef2f758b2e955"
96-
integrity sha512-W4/tgAXFqFA0iL7fk0+uQ3g7wkL8xJmx3XdK0VGb4cHW//eZTtKGvFBBoRKVTpY7n6ze4NL9ly7rgXcHufqXKg==
87+
version "5.3.0"
88+
resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-5.3.0.tgz#e23353d0ebb9317f174e93417e4a4d82d0249e9f"
89+
integrity sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==
9790
dependencies:
9891
path-key "^4.0.0"
9992

0 commit comments

Comments
 (0)