3
3
import os from "node:os" ;
4
4
import path from "node:path" ;
5
5
6
- import { detect , getCommand } from "@antfu/ni" ;
7
6
import PackageJson from "@npmcli/package-json" ;
8
7
import { execa } from "execa" ;
9
8
import fse from "fs-extra" ;
@@ -15,14 +14,17 @@ console.log({ concurrency });
15
14
16
15
const queue = new PQueue ( { concurrency, autoStart : false } ) ;
17
16
18
- const TO_IGNORE = [
17
+ const TO_IGNORE = new Set ( [
19
18
"__scripts" ,
20
19
".git" ,
21
20
".github" ,
22
21
".gitignore" ,
23
22
"package.json" ,
24
23
"yarn.lock" ,
25
- ] ;
24
+ ] ) ;
25
+
26
+ const yarnExamples = new Set ( [ "yarn-pnp" ] ) ;
27
+ const pnpmExamples = new Set ( [ ] ) ;
26
28
27
29
let examples = [ ] ;
28
30
@@ -42,12 +44,12 @@ if (process.env.CI) {
42
44
43
45
const dirs = files . map ( ( f ) => f . split ( "/" ) . at ( 0 ) ) ;
44
46
45
- examples = [ ...new Set ( dirs ) ] . filter ( ( d ) => ! TO_IGNORE . includes ( d ) ) ;
47
+ examples = [ ...new Set ( dirs ) ] . filter ( ( d ) => ! TO_IGNORE . has ( d ) ) ;
46
48
} else {
47
49
const entries = await fse . readdir ( process . cwd ( ) , { withFileTypes : true } ) ;
48
50
examples = entries
49
51
. filter ( ( entry ) => entry . isDirectory ( ) )
50
- . filter ( ( entry ) => ! TO_IGNORE . includes ( entry . name ) )
52
+ . filter ( ( entry ) => ! TO_IGNORE . has ( entry . name ) )
51
53
. map ( ( entry ) => entry . name )
52
54
. filter ( ( entry ) => fse . existsSync ( path . join ( entry , "package.json" ) ) ) ;
53
55
}
@@ -63,34 +65,33 @@ for (const example of examples) {
63
65
/** @type {import('execa').Options } */
64
66
const options = { cwd : example , reject : false } ;
65
67
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" ;
68
73
69
74
const hasSetup = ! ! pkgJson . content . scripts ?. __setup ;
70
75
71
76
if ( hasSetup ) {
72
- const setup = await getCommand ( detected , "run" , [ "__setup" ] ) ;
73
- const setupArgs = setup . split ( " " ) . slice ( 1 ) ;
74
77
console . log ( "🔧\u00A0Running setup script for" , example ) ;
75
- const setupResult = await execa ( detected , setupArgs , options ) ;
78
+ const setupResult = await execa ( pm , [ "run" , "__setup" ] , options ) ;
76
79
if ( setupResult . exitCode ) {
77
80
console . error ( setupResult . stderr ) ;
78
- throw new Error ( `Error running setup script for ${ example } ` ) ;
81
+ throw new Error ( `🚨\u00A0Error running setup script for ${ example } ` ) ;
79
82
}
80
83
}
81
84
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
+ ) ;
90
91
91
92
if ( installResult . exitCode ) {
92
93
console . error ( installResult . stderr ) ;
93
- throw new Error ( `Error installing ${ example } ` ) ;
94
+ throw new Error ( `🚨\u00A0Error installing ${ example } ` ) ;
94
95
}
95
96
96
97
const hasPrisma = fse . existsSync (
@@ -107,30 +108,24 @@ for (const example of examples) {
107
108
108
109
if ( prismaGenerateCommand . exitCode ) {
109
110
console . error ( prismaGenerateCommand . stderr ) ;
110
- throw new Error ( `Error generating prisma types for ${ example } ` ) ;
111
+ throw new Error ( `🚨\u00A0Error generating prisma types for ${ example } ` ) ;
111
112
}
112
113
}
113
114
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 ) ;
118
117
119
118
if ( buildResult . exitCode ) {
120
119
console . error ( buildResult . stderr ) ;
121
- throw new Error ( `Error building ${ example } ` ) ;
120
+ throw new Error ( `🚨\u00A0Error building ${ example } ` ) ;
122
121
}
123
122
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 ) ;
130
125
131
126
if ( typecheckResult . exitCode ) {
132
127
console . error ( typecheckResult . stderr ) ;
133
- throw new Error ( `Error typechecking ${ example } ` ) ;
128
+ throw new Error ( `🚨\u00A0Error typechecking ${ example } ` ) ;
134
129
}
135
130
} ) ;
136
131
}
0 commit comments