33import os from "node:os" ;
44import path from "node:path" ;
55
6- import { detect , getCommand } from "@antfu/ni" ;
76import PackageJson from "@npmcli/package-json" ;
87import { execa } from "execa" ;
98import fse from "fs-extra" ;
@@ -15,14 +14,17 @@ console.log({ concurrency });
1514
1615const 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
2729let 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}
0 commit comments