Skip to content

Commit 73a8249

Browse files
committed
handle package manager differently
Signed-off-by: Logan McAnsh <[email protected]>
1 parent c549c13 commit 73a8249

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

__scripts/test.mjs

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os from "node:os";
44
import path from "node:path";
55

6-
import { detect, getCommand } from "@antfu/ni";
76
import PackageJson from "@npmcli/package-json";
87
import { execa } from "execa";
98
import fse from "fs-extra";
@@ -15,14 +14,17 @@ console.log({ concurrency });
1514

1615
const queue = new PQueue({ concurrency, autoStart: false });
1716

18-
const TO_IGNORE = [
17+
const TO_IGNORE = new Set([
1918
"__scripts",
2019
".git",
2120
".github",
2221
".gitignore",
2322
"package.json",
2423
"yarn.lock",
25-
];
24+
]);
25+
26+
const yarnExamples = new Set(["yarn-pnp"]);
27+
const pnpmExamples = new Set([]);
2628

2729
let examples = [];
2830

@@ -42,12 +44,12 @@ if (process.env.CI) {
4244

4345
const dirs = files.map((f) => f.split("/").at(0));
4446

45-
examples = [...new Set(dirs)].filter((d) => !TO_IGNORE.includes(d));
47+
examples = [...new Set(dirs)].filter((d) => !TO_IGNORE.has(d));
4648
} else {
4749
const entries = await fse.readdir(process.cwd(), { withFileTypes: true });
4850
examples = entries
4951
.filter((entry) => entry.isDirectory())
50-
.filter((entry) => !TO_IGNORE.includes(entry.name))
52+
.filter((entry) => !TO_IGNORE.has(entry.name))
5153
.map((entry) => entry.name)
5254
.filter((entry) => fse.existsSync(path.join(entry, "package.json")));
5355
}
@@ -63,34 +65,33 @@ for (const example of examples) {
6365
/** @type {import('execa').Options} */
6466
const options = { cwd: example, reject: false };
6567

66-
// detect package manager
67-
const detected = await detect({ cwd: example });
68+
const pm = pnpmExamples.has(example)
69+
? "pnpm"
70+
: yarnExamples.has(example)
71+
? "yarn"
72+
: "npm";
6873

6974
const hasSetup = !!pkgJson.content.scripts?.__setup;
7075

7176
if (hasSetup) {
72-
const setup = await getCommand(detected, "run", ["__setup"]);
73-
const setupArgs = setup.split(" ").slice(1);
7477
console.log("🔧\u00A0Running setup script for", example);
75-
const setupResult = await execa(detected, setupArgs, options);
78+
const setupResult = await execa(pm, ["run", "__setup"], options);
7679
if (setupResult.exitCode) {
7780
console.error(setupResult.stderr);
78-
throw new Error(`Error running setup script for ${example}`);
81+
throw new Error(`🚨\u00A0Error running setup script for ${example}`);
7982
}
8083
}
8184

82-
const installCommand = await getCommand(detected, "install", [
83-
"--silent",
84-
"--legacy-peer-deps",
85-
]);
86-
// this is silly, but is needed in order for execa to work
87-
const installArgs = installCommand.split(" ").slice(1, -1);
88-
console.log(`📥\u00A0Installing ${example} with "${installCommand}"`);
89-
const installResult = await execa(detected, installArgs, options);
85+
console.log(`📥\u00A0Installing ${example} with "${pm}"`);
86+
const installResult = await execa(
87+
pm,
88+
["install", "--silent", "--legacy-peer-deps"],
89+
options
90+
);
9091

9192
if (installResult.exitCode) {
9293
console.error(installResult.stderr);
93-
throw new Error(`Error installing ${example}`);
94+
throw new Error(`🚨\u00A0Error installing ${example}`);
9495
}
9596

9697
const hasPrisma = fse.existsSync(
@@ -107,30 +108,24 @@ for (const example of examples) {
107108

108109
if (prismaGenerateCommand.exitCode) {
109110
console.error(prismaGenerateCommand.stderr);
110-
throw new Error(`Error generating prisma types for ${example}`);
111+
throw new Error(`🚨\u00A0Error generating prisma types for ${example}`);
111112
}
112113
}
113114

114-
const buildCommand = await getCommand(detected, "run", ["build"]);
115-
const buildArgs = buildCommand.split(" ").slice(1);
116-
console.log(`📦\u00A0Building ${example} with "${buildCommand}"`);
117-
const buildResult = await execa(detected, buildArgs, options);
115+
console.log(`📦\u00A0Building ${example}`);
116+
const buildResult = await execa(pm, ["run", "build"], options);
118117

119118
if (buildResult.exitCode) {
120119
console.error(buildResult.stderr);
121-
throw new Error(`Error building ${example}`);
120+
throw new Error(`🚨\u00A0Error building ${example}`);
122121
}
123122

124-
const typecheckCommand = await getCommand(detected, "run", ["typecheck"]);
125-
const typecheckArgs = typecheckCommand.split(" ").slice(1);
126-
console.log(
127-
`🕵️\u00A0\u00A0Typechecking ${example} with "${typecheckCommand}"`
128-
);
129-
const typecheckResult = await execa(detected, typecheckArgs, options);
123+
console.log(`🕵️\u00A0\u00A0Typechecking ${example}`);
124+
const typecheckResult = await execa(pm, ["run", "typecheck"], options);
130125

131126
if (typecheckResult.exitCode) {
132127
console.error(typecheckResult.stderr);
133-
throw new Error(`Error typechecking ${example}`);
128+
throw new Error(`🚨\u00A0Error typechecking ${example}`);
134129
}
135130
});
136131
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"node": ">=14"
2525
},
2626
"dependencies": {
27-
"@antfu/ni": "^0.21.3",
2827
"@npmcli/package-json": "^3.0.0",
2928
"execa": "^7.1.1",
3029
"fs-extra": "11.1.1",

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
"@jridgewell/gen-mapping" "^0.3.0"
1111
"@jridgewell/trace-mapping" "^0.3.9"
1212

13-
"@antfu/ni@^0.21.3":
14-
version "0.21.3"
15-
resolved "https://registry.npmjs.org/@antfu/ni/-/ni-0.21.3.tgz#c661fe5e16967a85ecd21ea501dc312cdf461474"
16-
integrity sha512-iDtQMeMW1kKV4nzQ+tjYOIPUm6nmh7pJe4sM0kx1jdAChKSCBLStqlgIoo5Tce++p+o8cBiWIzC3jg6oHyjzMA==
17-
1813
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.18.6":
1914
version "7.18.6"
2015
resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz#3b25d38c89600baa2dcc219edfa88a74eb2c427a"

0 commit comments

Comments
 (0)