@gjsify/cli 0.4.39 → 0.4.41
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/cli.gjs.mjs +2 -2
- package/lib/commands/pack.js +77 -15
- package/package.json +16 -16
package/dist/cli.gjs.mjs
CHANGED
|
@@ -794,8 +794,8 @@ jobs:
|
|
|
794
794
|
--- gjsify post-install checks ---`);let n=runMinimalChecks().filter(n=>!n.found&&n.severity===`required`);if(n.length>0){Ae.warn(`Missing required system dependencies:
|
|
795
795
|
`);for(let a of n)Ae.warn(` ✗ ${a.name}`);let a=buildInstallCommand(detectPackageManager$2(),n);a&&Ae.warn(`\nInstall with:\n ${a}`)}else Ae.log(`System dependencies OK.`);let a=detectNativePackages(process.cwd());if(a.length>0){Ae.log(`\nDetected ${a.length} @gjsify/* package(s) with native prebuilds:`);for(let n of a)Ae.log(` • ${n.name}`);Ae.log("\nUse `gjsify run <bundle>` to launch with LD_LIBRARY_PATH/GI_TYPELIB_PATH set.")}maybeInstallGitHooks()}function maybeInstallGitHooks(){let n=process.cwd(),a=jo(n,`scripts`,`install-git-hooks.mjs`);if(existsSync(a)&&existsSync(jo(n,`.git`)))try{let S=spawnSync(process.execPath,[a,`--quiet`],{cwd:n,stdio:`inherit`,env:process.env});S.status!==0&&Ae.warn(`[gjsify install] scripts/install-git-hooks.mjs exited ${S.status} — git hooks may not be active.`)}catch(n){Ae.warn(`[gjsify install] git hook installation skipped: ${n instanceof Error?n.message:String(n)}`)}}je(),Gb(),Tf();const xE={command:`foreach [script] [args..]`,description:"Run a workspace script across all (or filtered) workspaces. Drop-in for `yarn workspaces foreach`: -A/--all, -p/--parallel, -t/--topological, --include, --exclude, --no-private. Pass --exec to run an arbitrary command instead of a script.",builder:n=>n.positional(`script`,{description:"Script name to run in each workspace (`run <name>`-equivalent). With --exec, the command to run instead.",type:`string`}).positional(`args`,{description:`Extra arguments forwarded to each child invocation.`,type:`string`,array:!0}).option(`all`,{description:"Include workspaces declared as `private: true`.",type:`boolean`,alias:`A`,default:!1}).option(`parallel`,{description:`Run workspaces in parallel (capped by --jobs).`,type:`boolean`,alias:`p`,default:!1}).option(`topological`,{description:`Wait for each workspace's deps to finish before starting it (production deps only).`,type:`boolean`,alias:`t`,default:!1}).option(`topological-dev`,{description:`Like --topological but also respects devDependencies (often cyclic — use sparingly).`,type:`boolean`,default:!1}).option(`include`,{description:`Glob pattern to include workspaces by name (repeatable).`,type:`string`,array:!0}).option(`exclude`,{description:`Glob pattern to exclude workspaces by name (repeatable).`,type:`string`,array:!0}).option(`private`,{description:`Include private workspaces (default true). Pass --no-private to skip them.`,type:`boolean`,default:!0}).option(`verbose`,{description:`Echo every spawned command before running it.`,type:`boolean`,alias:`v`,default:!1}).option(`jobs`,{description:`Maximum concurrent workspaces in --parallel mode (default: cpu count).`,type:`number`,alias:`j`}).option(`exec`,{description:"Treat <script> [args..] as an arbitrary command (yarn `workspaces foreach exec`-equivalent) instead of a package.json script lookup. Workspace filtering by script presence is skipped. Use `-- <cmd> <args...>` to pass flags to the command without yargs intercepting them.",type:`boolean`,default:!1}).parserConfiguration({"populate--":!0}),handler:async n=>{let a=discoverWorkspaces(findWorkspaceRoot(process.cwd())??process.cwd()),S=n.exec===!0,C=n.script,N=n.args??[];if(S){let a=(n[`--`]??[]).filter(n=>typeof n==`string`);a.length>0&&(C?N=[...N,...a]:(C=a[0],N=[...N,...a.slice(1)])),C||(Ae.error("gjsify foreach --exec: missing command. Pass it after `--`, e.g. `gjsify foreach --exec -- npm publish --tag latest`."),process.exit(1))}let F=filterWorkspaces(a,{include:n.include,exclude:n.exclude,noPrivate:n.private===!1});if(!S){C||(Ae.error(`gjsify foreach: missing <script> positional. Pass --exec to run an arbitrary command instead.`),process.exit(1));let n=C;F=F.filter(a=>typeof(a.manifest.scripts??{})[n]==`string`)}if(F.length===0){Ae.log(`gjsify foreach: no workspaces match (${S?`exec`:`script`}="${C}", include=${JSON.stringify(n.include??[])}, exclude=${JSON.stringify(n.exclude??[])})`);return}(n.topological||n[`topological-dev`])&&(F=topologicalSort(buildDependencyGraph(F,{includeDev:n[`topological-dev`]===!0})));let I=n.verbose===!0,H=C;try{if(n.parallel&&!n.topological&&!n[`topological-dev`]){let a=n.jobs&&n.jobs>0?n.jobs:cpus().length;await runParallel(F,H,N,a,I,S)}else if(n.parallel){let a=n.jobs&&n.jobs>0?n.jobs:cpus().length;await runTopologicalParallel(F,H,N,a,I,n[`topological-dev`]===!0,S)}else await runSequential(F,H,N,I,S)}catch(n){Ae.error(n.message),process.exit(1)}process.exit(0)}};async function runSequential(n,a,S,C,N){for(let F of n)await runOne$1(F,a,S,!1,C,N)}async function runParallel(n,a,S,C,N,F){let I=0,H=[];for(let W=0;W<C;W++)H.push((async()=>{for(;I<n.length;)await runOne$1(n[I++],a,S,!0,N,F)})());await Promise.all(H)}async function runTopologicalParallel(n,a,S,C,N,F,I){let H=new Set(n.map(n=>n.name)),W=new Map;for(let a of n){let n=new Set,S=a.manifest;for(let a of[S.dependencies,F?S.devDependencies:void 0,S.optionalDependencies])if(a)for(let[S,C]of Object.entries(a))typeof C==`string`&&C.startsWith(`workspace:`)&&H.has(S)&&n.add(S);W.set(a.name,n)}let K=new Map(n.map(n=>[n.name,n])),q=new Set,Y=0;return new Promise((n,F)=>{let H=null,pump=()=>{if(!H){for(;Y<C;){let C=[...W.entries()].filter(([,n])=>[...n].every(n=>q.has(n))).map(([n])=>n);if(C.length===0)break;let X=C.sort()[0];W.delete(X),Y++,runOne$1(K.get(X),a,S,!0,N,I).then(()=>{if(Y--,q.add(X),W.size===0&&Y===0){n();return}pump()}).catch(n=>{H=n instanceof Error?n:Error(String(n)),Y===0&&F(H)})}W.size>0&&Y===0&&!H&&F(Error(`gjsify foreach --topological: stuck — workspaces ${[...W.keys()].join(`, `)} have unsatisfied deps in the selected set`))}};pump()})}async function runOne$1(n,a,S,C,N,F){if(F){N&&Ae.error(`[${n.name}] $ ${a} ${S.join(` `)}`),await spawnPrefixed(a,S,n.location,C?`[${n.name}] `:null);return}let I=detectPackageManager$1(),H=I===`gjsify`?[`run`,a,...S]:[`run`,a,...S.length>0?[`--`,...S]:[]];N&&Ae.error(`[${n.name}] $ ${I} ${H.join(` `)}`),await spawnPrefixed(I,H,n.location,C?`[${n.name}] `:null)}__name$1(runOne$1,`runOne`);function detectPackageManager$1(){let n=process.env.npm_config_user_agent??``;return n.startsWith(`yarn/`)?`yarn`:n.startsWith(`gjsify/`)?`gjsify`:`npm`}__name$1(detectPackageManager$1,`detectPackageManager`);function spawnPrefixed(n,a,S,C){let N=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`};return new Promise((F,I)=>{let H=spawn(n,a,{cwd:S,stdio:C?[`ignore`,`pipe`,`pipe`]:`inherit`,env:{...process.env,...N}});C&&H.stdout&&H.stderr&&(prefixLines(H.stdout,process.stdout,C),prefixLines(H.stderr,process.stderr,C)),H.on(`close`,S=>{S===0?F():I(Error(`${n} ${a.join(` `)} exited with code ${S}`))}),H.on(`error`,n=>I(n))})}function prefixLines(n,a,S){let C=``;n.setEncoding(`utf-8`),n.on(`data`,n=>{C+=n;let N;for(;(N=C.indexOf(`
|
|
796
796
|
`))!==-1;)a.write(S+C.slice(0,N+1)),C=C.slice(N+1)}),n.on(`end`,()=>{C.length>0&&a.write(S+C+`
|
|
797
|
-
`)})}je(),Gb();const SE={command:`workspace <name> <script> [args..]`,description:"Run a workspace script (`yarn workspace <name> run <script>` equivalent).",builder:n=>n.positional(`name`,{description:"Workspace name (matches package.json `name` field).",type:`string`,demandOption:!0}).positional(`script`,{description:`Script name to run inside that workspace.`,type:`string`,demandOption:!0}).positional(`args`,{description:`Extra arguments forwarded to the script.`,type:`string`,array:!0}).option(`with-dependencies`,{description:"Pre-build the target workspace's transitive workspace dependencies in topological order before running the script in the target. Deps that don't declare the script are skipped (--if-present behaviour). Replaces manual `gjsify workspace A build && gjsify workspace B build && …` chains.",type:`boolean`,alias:[`d`,`t`,`topological`],default:!1}).option(`include-dev`,{description:"When --with-dependencies is set, also walk devDependencies (production deps only by default — matches `gjsify foreach -t`).",type:`boolean`,default:!1}).option(`continue-on-error`,{description:`When --with-dependencies is set, keep running remaining deps after one fails (default: stop on first failure).`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo every spawned command before running it.`,type:`boolean`,alias:`v`,default:!1}),handler:async n=>{let a=discoverWorkspaces(findWorkspaceRoot(process.cwd())??process.cwd()),S=a.find(a=>a.name===n.name);S||(Ae.error(`gjsify workspace: no workspace named "${n.name}" — discovered ${a.length} workspace(s)`),process.exit(1));let C=detectPackageManager(),N=n.verbose===!0,F=n[`with-dependencies`]===!0,I=n[`continue-on-error`]===!0;typeof(S.manifest.scripts??{})[n.script]!=`string`&&(Ae.error(`gjsify workspace: workspace "${n.name}" has no script "${n.script}"`),process.exit(1));let H;H=F?topologicalSort(buildDependencyGraph(collectTransitiveClosure(S,a,n[`include-dev`]===!0),{includeDev:n[`include-dev`]===!0})):[S];let W=[];for(let a of H){if(typeof(a.manifest.scripts??{})[n.script]!=`string`){N&&Ae.error(`[${a.name}] (no "${n.script}" script — skipping)`);continue}try{await runOne(a,n.script,n.args??[],C,N)}catch(n){let S=n instanceof Error?n:Error(String(n));Ae.error(`[${a.name}] ${S.message}`),I||process.exit(1),W.push({workspace:a.name,error:S})}}W.length>0&&(Ae.error(`gjsify workspace: ${W.length} workspace(s) failed: ${W.map(n=>n.workspace).join(`, `)}`),process.exit(1)),process.exit(0)}};function collectTransitiveClosure(n,a,S){let C=new Map;for(let n of a)C.set(n.name,n);let N=new Set,F=[],I=[n];for(;I.length>0;){let n=I.pop();if(N.has(n.name))continue;N.add(n.name),F.push(n);let a=n.manifest,H=[a.dependencies,S?a.devDependencies:void 0,a.optionalDependencies];for(let n of H)if(n)for(let[a,S]of Object.entries(n)){if(typeof S!=`string`||!S.startsWith(`workspace:`))continue;let n=C.get(a);n&&(N.has(n.name)||I.push(n))}}return F}async function runOne(n,a,S,C,N){let F=C===`gjsify`?[`run`,a,...S]:[`run`,a,...S.length>0?[`--`,...S]:[]];N&&Ae.error(`[${n.name}] $ ${C} ${F.join(` `)}`);let I=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`};await new Promise((a,S)=>{let N=spawn(C,F,{cwd:n.location,stdio:`inherit`,env:{...process.env,...I}});N.on(`close`,n=>{n===0?a():S(Error(`${C} ${F.join(` `)} exited with code ${n}`))}),N.on(`error`,S)})}function detectPackageManager(){let n=process.env.npm_config_user_agent??``;return n.startsWith(`yarn/`)?`yarn`:n.startsWith(`gjsify/`)?`gjsify`:`npm`}Gb(),Ho();async function runLifecycleScript(n,a,S,C={}){let N=(a.scripts??{})[S];if(typeof N!=`string`){if(C.optional!==!1)return!1;throw Error(`gjsify lifecycle-script: no "${S}" in ${n}/package.json`)}let F=findWorkspaceRoot(n),I=[jo(n,`node_modules`,`.bin`)];F&&F!==n&&I.push(jo(F,`node_modules`,`.bin`));let H=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`},W={...process.env,...H,PATH:[...I,process.env.PATH??``].filter(Boolean).join(Bo),npm_lifecycle_event:S,npm_package_name:a.name??``,npm_package_version:a.version??``,...C.env},K=C.stdio===`inherit-stderr`?[`inherit`,2,2]:C.stdio??`inherit`;return await new Promise((a,C)=>{let F=spawn(N,[],{cwd:n,env:W,stdio:K,shell:!0});F.on(`close`,N=>{N===0?a():C(Error(`gjsify lifecycle-script: "${S}" in ${n} exited with code ${N}`))}),F.on(`error`,C)}),!0}
|
|
798
|
-
`,X=collectFiles(n,K),te=[{name:`package/`,directory:!0,mode:493}],ne=[],re=0;for(let a of X){let S;S=a===`package.json`?new TextEncoder().encode(Y):new Uint8Array(readFileSync(jo(n,a)));let C=statSync(jo(n,a)).mode&511;te.push({name:`package/${a}`,body:S,mode:C,mtime:0}),ne.push({path:a,size:S.byteLength,mode:C}),re+=S.byteLength}let ie=await gzip(createTarball(te)),ae=`${F.startsWith(`@`)?F.slice(1).replace(`/`,`-`):F}-${I}.tgz`,oe=createHash(`sha1`).update(ie).digest(`hex`),Z=`sha512-${createHash(`sha512`).update(ie).digest(`base64`)}`,se=a.destination?Oo(a.destination):n,ce=jo(se,ae);return a.dryRun||(mkdirSync(se,{recursive:!0}),writeFileSync(ce,ie)),{filename:ae,name:F,version:I,size:ie.byteLength,unpackedSize:re,shasum:oe,integrity:Z,entryCount:ne.length,files:ne,absolutePath:a.dryRun?null:ce}}function collectFiles(n,a){let S=forceIncluded(a),C=Array.isArray(a.files)?a.files.filter(n=>typeof n==`string`):null,N;N=C?expandFilesPatterns(n,C):walkAll(n);let F=loadIgnore(n),I=new Set;for(let n of N)F(n)||I.add(n);for(let a of S)existsSync(jo(n,a))&&I.add(a);return[...I].sort()}const wE=new Set([`.git`,`.svn`,`.hg`,`.gitignore`,`.gitattributes`,`.npmrc`,`CVS`,`.DS_Store`,`node_modules`,`.npmignore`,`package-lock.json`,`gjsify-lock.json`,`yarn.lock`,`yarn-error.log`,`.yarn`,`.pnp.cjs`,`.pnp.loader.mjs`,`tsconfig.tsbuildinfo`]);function forceIncluded(n){let a=new Set;a.add(`package.json`);for(let n of[`README`,`README.md`,`LICENSE`,`LICENSE.md`,`NOTICE`,`NOTICE.md`])a.add(n);let S=typeof n.main==`string`?n.main:null;S&&a.add(S.replace(/^\.\//,``));let C=n.bin;if(typeof C==`string`)a.add(C.replace(/^\.\//,``));else if(C&&typeof C==`object`)for(let n of Object.values(C))typeof n==`string`&&a.add(n.replace(/^\.\//,``));return[...a]}function walkAll(n,a=``){let S=[],C=a?jo(n,a):n,N;try{N=readdirSync(C,{withFileTypes:!0})}catch{return S}for(let C of N){if(wE.has(C.name)||C.name.startsWith(`.tsbuildinfo`))continue;let N=a?`${a}/${C.name}`:C.name;C.isDirectory()?S.push(...walkAll(n,N)):C.isFile()&&S.push(N)}return S}function expandFilesPatterns(n,a){let S=new Set;for(let
|
|
797
|
+
`)})}je(),Gb();const SE={command:`workspace <name> <script> [args..]`,description:"Run a workspace script (`yarn workspace <name> run <script>` equivalent).",builder:n=>n.positional(`name`,{description:"Workspace name (matches package.json `name` field).",type:`string`,demandOption:!0}).positional(`script`,{description:`Script name to run inside that workspace.`,type:`string`,demandOption:!0}).positional(`args`,{description:`Extra arguments forwarded to the script.`,type:`string`,array:!0}).option(`with-dependencies`,{description:"Pre-build the target workspace's transitive workspace dependencies in topological order before running the script in the target. Deps that don't declare the script are skipped (--if-present behaviour). Replaces manual `gjsify workspace A build && gjsify workspace B build && …` chains.",type:`boolean`,alias:[`d`,`t`,`topological`],default:!1}).option(`include-dev`,{description:"When --with-dependencies is set, also walk devDependencies (production deps only by default — matches `gjsify foreach -t`).",type:`boolean`,default:!1}).option(`continue-on-error`,{description:`When --with-dependencies is set, keep running remaining deps after one fails (default: stop on first failure).`,type:`boolean`,default:!1}).option(`verbose`,{description:`Echo every spawned command before running it.`,type:`boolean`,alias:`v`,default:!1}),handler:async n=>{let a=discoverWorkspaces(findWorkspaceRoot(process.cwd())??process.cwd()),S=a.find(a=>a.name===n.name);S||(Ae.error(`gjsify workspace: no workspace named "${n.name}" — discovered ${a.length} workspace(s)`),process.exit(1));let C=detectPackageManager(),N=n.verbose===!0,F=n[`with-dependencies`]===!0,I=n[`continue-on-error`]===!0;typeof(S.manifest.scripts??{})[n.script]!=`string`&&(Ae.error(`gjsify workspace: workspace "${n.name}" has no script "${n.script}"`),process.exit(1));let H;H=F?topologicalSort(buildDependencyGraph(collectTransitiveClosure(S,a,n[`include-dev`]===!0),{includeDev:n[`include-dev`]===!0})):[S];let W=[];for(let a of H){if(typeof(a.manifest.scripts??{})[n.script]!=`string`){N&&Ae.error(`[${a.name}] (no "${n.script}" script — skipping)`);continue}try{await runOne(a,n.script,n.args??[],C,N)}catch(n){let S=n instanceof Error?n:Error(String(n));Ae.error(`[${a.name}] ${S.message}`),I||process.exit(1),W.push({workspace:a.name,error:S})}}W.length>0&&(Ae.error(`gjsify workspace: ${W.length} workspace(s) failed: ${W.map(n=>n.workspace).join(`, `)}`),process.exit(1)),process.exit(0)}};function collectTransitiveClosure(n,a,S){let C=new Map;for(let n of a)C.set(n.name,n);let N=new Set,F=[],I=[n];for(;I.length>0;){let n=I.pop();if(N.has(n.name))continue;N.add(n.name),F.push(n);let a=n.manifest,H=[a.dependencies,S?a.devDependencies:void 0,a.optionalDependencies];for(let n of H)if(n)for(let[a,S]of Object.entries(n)){if(typeof S!=`string`||!S.startsWith(`workspace:`))continue;let n=C.get(a);n&&(N.has(n.name)||I.push(n))}}return F}async function runOne(n,a,S,C,N){let F=C===`gjsify`?[`run`,a,...S]:[`run`,a,...S.length>0?[`--`,...S]:[]];N&&Ae.error(`[${n.name}] $ ${C} ${F.join(` `)}`);let I=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`};await new Promise((a,S)=>{let N=spawn(C,F,{cwd:n.location,stdio:`inherit`,env:{...process.env,...I}});N.on(`close`,n=>{n===0?a():S(Error(`${C} ${F.join(` `)} exited with code ${n}`))}),N.on(`error`,S)})}function detectPackageManager(){let n=process.env.npm_config_user_agent??``;return n.startsWith(`yarn/`)?`yarn`:n.startsWith(`gjsify/`)?`gjsify`:`npm`}Gb(),Ho();async function runLifecycleScript(n,a,S,C={}){let N=(a.scripts??{})[S];if(typeof N!=`string`){if(C.optional!==!1)return!1;throw Error(`gjsify lifecycle-script: no "${S}" in ${n}/package.json`)}let F=findWorkspaceRoot(n),I=[jo(n,`node_modules`,`.bin`)];F&&F!==n&&I.push(jo(F,`node_modules`,`.bin`));let H=process.env.FORCE_COLOR!==void 0||process.env.NO_COLOR!==void 0?{}:{FORCE_COLOR:`1`},W={...process.env,...H,PATH:[...I,process.env.PATH??``].filter(Boolean).join(Bo),npm_lifecycle_event:S,npm_package_name:a.name??``,npm_package_version:a.version??``,...C.env},K=C.stdio===`inherit-stderr`?[`inherit`,2,2]:C.stdio??`inherit`;return await new Promise((a,C)=>{let F=spawn(N,[],{cwd:n,env:W,stdio:K,shell:!0});F.on(`close`,N=>{N===0?a():C(Error(`gjsify lifecycle-script: "${S}" in ${n} exited with code ${N}`))}),F.on(`error`,C)}),!0}As(),Ga(),Ho(),sE();const CE={command:`pack [path]`,description:`Produce an npm-compatible .tgz tarball for the workspace at <path> (default: cwd). Rewrites workspace:^/~/* deps to resolved versions.`,builder:n=>n.positional(`path`,{description:`Workspace path (default: cwd).`,type:`string`}).option(`pack-destination`,{description:`Directory to write the tarball into. Default: workspace cwd.`,type:`string`}).option(`json`,{description:"Emit pack metadata as JSON on stdout (mirrors `npm pack --json`).",type:`boolean`,default:!1}).option(`dry-run`,{description:`Compute everything but do not write the .tgz.`,type:`boolean`,default:!1}).option(`ignore-scripts`,{description:"Skip the `prepack` lifecycle script before packing. Mirrors `npm pack --ignore-scripts`. Use when scripts are already run by the outer workflow.",type:`boolean`,default:!1}),handler:async n=>{let a=await packWorkspace(Oo(n.path??process.cwd()),{destination:n[`pack-destination`],dryRun:n[`dry-run`]===!0,lifecycleScripts:n[`ignore-scripts`]?[]:[`prepack`],lifecycleStdio:n.json?`inherit-stderr`:`inherit`});n.json?process.stdout.write(`${JSON.stringify([a],null,2)}\n`):process.stdout.write(`${a.filename}\n`)}};async function packWorkspace(n,a={}){let S=jo(n,`package.json`);if(!existsSync(S))throw Error(`gjsify pack: no package.json at ${n}`);let C=readFileSync(S,`utf-8`),N=JSON.parse(C),F=typeof N.name==`string`?N.name:``,I=typeof N.version==`string`?N.version:`0.0.0`;if(!F)throw Error(`gjsify pack: package.json at ${n} has no "name"`);let H=a.lifecycleScripts??[`prepack`];for(let S of H)await runLifecycleScript(n,N,S,{optional:!0,stdio:a.lifecycleStdio});let W=readFileSync(S,`utf-8`),K=W===C?N:JSON.parse(W),q=a.skipWorkspaceRewrite?K:rewriteWorkspaceDeps(K,n),Y=JSON.stringify(q,null,indentOf(W))+`
|
|
798
|
+
`,X=collectFiles(n,K),te=[{name:`package/`,directory:!0,mode:493}],ne=[],re=0;for(let a of X){let S;S=a===`package.json`?new TextEncoder().encode(Y):new Uint8Array(readFileSync(jo(n,a)));let C=statSync(jo(n,a)).mode&511;te.push({name:`package/${a}`,body:S,mode:C,mtime:0}),ne.push({path:a,size:S.byteLength,mode:C}),re+=S.byteLength}let ie=await gzip(createTarball(te)),ae=`${F.startsWith(`@`)?F.slice(1).replace(`/`,`-`):F}-${I}.tgz`,oe=createHash(`sha1`).update(ie).digest(`hex`),Z=`sha512-${createHash(`sha512`).update(ie).digest(`base64`)}`,se=a.destination?Oo(a.destination):n,ce=jo(se,ae);return a.dryRun||(mkdirSync(se,{recursive:!0}),writeFileSync(ce,ie)),{filename:ae,name:F,version:I,size:ie.byteLength,unpackedSize:re,shasum:oe,integrity:Z,entryCount:ne.length,files:ne,absolutePath:a.dryRun?null:ce}}function collectFiles(n,a){let S=forceIncluded(a),C=Array.isArray(a.files)?a.files.filter(n=>typeof n==`string`):null,N;N=C?expandFilesPatterns(n,C):walkAll(n);let F=loadIgnore(n),I=new Set;for(let n of N)F(n)||I.add(n);for(let a of S)existsSync(jo(n,a))&&I.add(a);return[...I].sort()}const wE=new Set([`.git`,`.svn`,`.hg`,`.gitignore`,`.gitattributes`,`.npmrc`,`CVS`,`.DS_Store`,`node_modules`,`.npmignore`,`package-lock.json`,`gjsify-lock.json`,`yarn.lock`,`yarn-error.log`,`.yarn`,`.pnp.cjs`,`.pnp.loader.mjs`,`tsconfig.tsbuildinfo`]);function forceIncluded(n){let a=new Set;a.add(`package.json`);for(let n of[`README`,`README.md`,`LICENSE`,`LICENSE.md`,`NOTICE`,`NOTICE.md`])a.add(n);let S=typeof n.main==`string`?n.main:null;S&&a.add(S.replace(/^\.\//,``));let C=n.bin;if(typeof C==`string`)a.add(C.replace(/^\.\//,``));else if(C&&typeof C==`object`)for(let n of Object.values(C))typeof n==`string`&&a.add(n.replace(/^\.\//,``));return[...a]}function walkAll(n,a=``){let S=[],C=a?jo(n,a):n,N;try{N=readdirSync(C,{withFileTypes:!0})}catch{return S}for(let C of N){if(wE.has(C.name)||C.name.startsWith(`.tsbuildinfo`))continue;let N=a?`${a}/${C.name}`:C.name;C.isDirectory()?S.push(...walkAll(n,N)):C.isFile()&&S.push(N)}return S}function expandFilesPatterns(n,a){let S=new Set,C=null;for(let N of a){let a=N.replace(/^\.\//,``).replace(/\/$/,``);if(!a)continue;if(!/[*?[\]]/.test(a)){let C=jo(n,a);if(!existsSync(C))continue;let N=statSync(C);if(N.isDirectory())for(let C of walkAll(n,a))S.add(C);else N.isFile()&&S.add(a);continue}C??=walkAll(n);let F=filesGlobToRegExp(a),I=filesGlobToRegExp(`${a}/**`);for(let n of C)(F.test(n)||I.test(n))&&S.add(n)}return[...S]}function filesGlobToRegExp(n){let a=`^`;for(let S=0;S<n.length;S++){let C=n[S];if(C===`*`)n[S+1]===`*`?(a+=`.*`,S++,n[S+1]===`/`&&S++):a+=`[^/]*`;else if(C===`?`)a+=`[^/]`;else if(C===`[`){let C=S+1,N=`[`;for(n[C]===`!`&&(N+=`^`,C++);C<n.length&&n[C]!==`]`;C++)N+=n[C];C<n.length?(a+=`${N}]`,S=C):a+=`\\[`}else ".+^${}()|\\]".includes(C)?a+=`\\${C}`:a+=C}return RegExp(`${a}$`)}function loadIgnore(n){let a=jo(n,`.npmignore`),S=jo(n,`.gitignore`),C=[],N=existsSync(a)?a:existsSync(S)?S:null;if(N){let n=readFileSync(N,`utf-8`).split(`
|
|
799
799
|
`);for(let a of n){let n=a.trim();!n||n.startsWith(`#`)||n.startsWith(`!`)||C.push(globToRegex(n))}}return n=>{for(let a of C)if(a.test(n))return!0;return!1}}function globToRegex(n){let a=n.replace(/^\//,``);return a=a.replace(/[.+^${}()|[\]\\]/g,`\\$&`),a=a.replace(/\*\*/g,`__DOUBLESTAR__`).replace(/\*/g,`[^/]*`).replace(/__DOUBLESTAR__/g,`.*`),a=a.replace(/\?/g,`[^/]`),RegExp(`^${a}($|/)`)}function rewriteWorkspaceDeps(n,a){let S=findWorkspaceRoot(a);if(!S)return n;let C=new Map;for(let n of discoverWorkspaces(S))n.name&&n.version&&C.set(n.name,n.version);let N=JSON.parse(JSON.stringify(n));for(let n of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let a=N[n];if(a)for(let[n,F]of Object.entries(a)){if(typeof F!=`string`||!F.startsWith(`workspace:`))continue;let I=C.get(n);if(!I)throw Error(`gjsify pack: ${N.name} declares workspace:^ on ${n} but no sibling workspace with that name exists in the monorepo at ${S}`);let H=F.slice(10);H===`*`||H===``?a[n]=I:H===`^`||H===`~`?a[n]=`${H}${I}`:a[n]=H}}return N}function indentOf(n){let a=n.match(/\n([ \t]+)"/);return a?a[1]:` `}var OidcUnavailableError=class extends Error{reason;constructor(n,a){super(n),this.reason=a,this.name=`OidcUnavailableError`}},OidcExchangeError=class extends Error{status;body;packageName;constructor(n,a,S,C){super(n),this.status=a,this.body=S,this.packageName=C,this.name=`OidcExchangeError`}};function hasGithubOidcEnv(){return!!(process.env.ACTIONS_ID_TOKEN_REQUEST_URL&&process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN)}async function fetchGithubOidcToken(n,a){let S=process.env.ACTIONS_ID_TOKEN_REQUEST_URL,C=process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;if(!S||!C)throw new OidcUnavailableError("GitHub Actions OIDC env vars (ACTIONS_ID_TOKEN_REQUEST_{URL,TOKEN}) not set. The calling workflow needs `permissions: id-token: write`.",`no-env`);let N=new URL(S);N.searchParams.set(`audience`,n),a?.(`gjsify oidc: GET ${N.href.replace(C,`<bearer>`)}`);let F=await fetch(N.href,{method:`GET`,headers:{Accept:`application/json`,Authorization:`Bearer ${C}`}});if(!F.ok){let n=await F.text().catch(()=>`<no body>`);throw new OidcUnavailableError(`Failed to fetch GitHub OIDC id_token: ${F.status} ${F.statusText} — ${n.slice(0,200)}`,`fetch-id-token`)}let I=await F.json().catch(()=>({}));if(!I.value)throw new OidcUnavailableError("GitHub OIDC response missing `value` field",`no-id-token`);return I.value}async function exchangeOidcForNpmToken(n){let{packageName:a,registry:S,idToken:C,log:N}=n,F=`${S.endsWith(`/`)?S.slice(0,-1):S}/-/npm/v1/oidc/token/exchange/package/${a.startsWith(`@`)?(()=>{let n=a.indexOf(`/`),S=a.slice(1,n),C=a.slice(n+1);return`@${encodeURIComponent(S)}%2f${encodeURIComponent(C)}`})():encodeURIComponent(a)}`;N?.(`gjsify oidc: POST ${F}`);let I=await fetch(F,{method:`POST`,headers:{Authorization:`Bearer ${C}`,"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),H=await I.text().catch(()=>``);if(!I.ok)throw new OidcExchangeError(`npm OIDC token exchange failed for ${a}: ${I.status} ${I.statusText} — ${H.slice(0,300)}`,I.status,H,a);let W;try{W=JSON.parse(H)}catch{throw new OidcExchangeError(`npm OIDC token exchange returned non-JSON body for ${a}: ${H.slice(0,200)}`,I.status,H,a)}if(!W.token)throw new OidcExchangeError(`npm OIDC token exchange returned no \`token\` field for ${a}`,I.status,H,a);return W.token}async function getNpmTrustedToken(n){let a=`npm:${new URL(n.registry).hostname}`,S=await fetchGithubOidcToken(a,n.log);return{token:await exchangeOidcForNpmToken({...n,idToken:S}),audience:a}}nE();async function diagnose404(n){let{packageName:a,version:S,registry:C,npmrc:N}=n,F={};try{F=await whoami(C,N)}catch{return{reason:`unknown`,message:formatUnknown(a,S)}}return F.username&&F.username.length>0?{reason:`live-token-404`,username:F.username,message:formatLiveToken404(a,S,F.username)}:{reason:`dead-token`,message:formatDeadToken(a,S)}}function formatDeadToken(n,a){return[`gjsify publish: ${n}@${a} — 404 Not Found`,``,`The npm token in ~/.npmrc appears to be revoked or expired (the /-/whoami probe`,`returned {} instead of {"username": "..."}). The 404 is npm's response to a PUT`,`authenticated with an invalid bearer token.`,``,`To refresh:`,` npm login`,` # or, future: gjsify login (tracked as project_gjsify_login_goal)`,``,`Then verify before publishing:`,` curl -s -H "Authorization: Bearer $(grep registry.npmjs.org ~/.npmrc | sed 's|.*=||')" \\`,` https://registry.npmjs.org/-/whoami`,` # Healthy: {"username":"<you>"}`,` # Dead: {}`].join(`
|
|
800
800
|
`)}function formatLiveToken404(n,a,S){return[`gjsify publish: ${n}@${a} — 404 Not Found`,``,`Authenticated as: ${S}`,``,`Your token authenticates, so this is NOT a dead-token problem. The package`,`${n} is not (yet) on npmjs.com. Two cases:`,``,` 1. First publish of a brand-new scoped package — do the one-time bootstrap`,` (see AGENTS.md > "New @gjsify/* package: first-publish + Trusted`,` Publisher bootstrap"). The npm registry can also 404 *transiently*`,` while provisioning a brand-new package: simply re-run, or do the very`," first publish with `npm publish` (then configure the Trusted Publisher)."," 2. You lack publish access to the scope — verify with `npm access ls-packages`."].join(`
|
|
801
801
|
`)}function formatUnknown(n,a){return`gjsify publish: ${n}@${a} — 404 Not Found`}function is404DiagnosticCandidate(n){let a=n.trim();return!!(a.length===0||/^not found$/i.test(a)||/"error"\s*:\s*"Not Found"/i.test(a))}As(),Tf(),Ho(),nE();async function loadNpmrc(n){let a=[],S=jo(n,`.npmrc`);existsSync(S)&&a.push(readFileSync(S,`utf-8`));let C=process.env.NPM_CONFIG_USERCONFIG;if(C&&existsSync(C))a.push(readFileSync(C,`utf-8`));else{let n=jo(homedir(),`.npmrc`);existsSync(n)&&a.push(readFileSync(n,`utf-8`))}return parseNpmrc(a.join(`
|
package/lib/commands/pack.js
CHANGED
|
@@ -272,29 +272,91 @@ function walkAll(root, sub = '') {
|
|
|
272
272
|
}
|
|
273
273
|
function expandFilesPatterns(wsDir, patterns) {
|
|
274
274
|
const out = new Set();
|
|
275
|
+
let allFiles = null;
|
|
275
276
|
for (const pattern of patterns) {
|
|
276
|
-
// Drop leading ./
|
|
277
|
+
// Drop leading ./ and trailing /
|
|
277
278
|
const normalized = pattern.replace(/^\.\//, '').replace(/\/$/, '');
|
|
278
|
-
|
|
279
|
-
if (!existsSync(full))
|
|
279
|
+
if (!normalized)
|
|
280
280
|
continue;
|
|
281
|
-
|
|
282
|
-
if (
|
|
283
|
-
|
|
281
|
+
// Literal file or directory (the common case: lib, dist, prebuilds).
|
|
282
|
+
if (!/[*?[\]]/.test(normalized)) {
|
|
283
|
+
const full = join(wsDir, normalized);
|
|
284
|
+
if (!existsSync(full))
|
|
285
|
+
continue;
|
|
286
|
+
const st = statSync(full);
|
|
287
|
+
if (st.isDirectory()) {
|
|
288
|
+
for (const f of walkAll(wsDir, normalized))
|
|
289
|
+
out.add(f);
|
|
290
|
+
}
|
|
291
|
+
else if (st.isFile()) {
|
|
292
|
+
out.add(normalized);
|
|
293
|
+
}
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
// Glob pattern (e.g. `lib/lib*.d.ts`, `dist/*.js`). Match every file in
|
|
297
|
+
// the tree against the pattern AND against `<pattern>/**` (npm semantics:
|
|
298
|
+
// a glob that resolves to a directory includes everything under it). `*`
|
|
299
|
+
// does not cross `/`; `**` does. This is what npm-packlist does — without
|
|
300
|
+
// it, `@gjsify/tsc`'s `files: ["lib/lib*.d.ts"]` shipped ZERO libs.
|
|
301
|
+
allFiles ??= walkAll(wsDir);
|
|
302
|
+
const fileRe = filesGlobToRegExp(normalized);
|
|
303
|
+
const dirRe = filesGlobToRegExp(`${normalized}/**`);
|
|
304
|
+
for (const f of allFiles) {
|
|
305
|
+
if (fileRe.test(f) || dirRe.test(f))
|
|
284
306
|
out.add(f);
|
|
285
307
|
}
|
|
286
|
-
|
|
287
|
-
|
|
308
|
+
}
|
|
309
|
+
return [...out];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Translate an npm-`files`-style glob to an anchored RegExp. `*` matches any run
|
|
313
|
+
* of non-`/` chars, `**` matches across `/`, `?` one non-`/` char, `[…]` a class.
|
|
314
|
+
* All other regex metacharacters are escaped. Mirrors the subset of glob syntax
|
|
315
|
+
* npm-packlist accepts in the `files` field.
|
|
316
|
+
*/
|
|
317
|
+
function filesGlobToRegExp(glob) {
|
|
318
|
+
let re = '^';
|
|
319
|
+
for (let i = 0; i < glob.length; i++) {
|
|
320
|
+
const c = glob[i];
|
|
321
|
+
if (c === '*') {
|
|
322
|
+
if (glob[i + 1] === '*') {
|
|
323
|
+
re += '.*';
|
|
324
|
+
i++;
|
|
325
|
+
if (glob[i + 1] === '/')
|
|
326
|
+
i++; // consume the `/` after `**`
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
re += '[^/]*';
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else if (c === '?') {
|
|
333
|
+
re += '[^/]';
|
|
288
334
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
335
|
+
else if (c === '[') {
|
|
336
|
+
let j = i + 1;
|
|
337
|
+
let cls = '[';
|
|
338
|
+
if (glob[j] === '!') {
|
|
339
|
+
cls += '^';
|
|
340
|
+
j++;
|
|
341
|
+
}
|
|
342
|
+
for (; j < glob.length && glob[j] !== ']'; j++)
|
|
343
|
+
cls += glob[j];
|
|
344
|
+
if (j < glob.length) {
|
|
345
|
+
re += `${cls}]`;
|
|
346
|
+
i = j;
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
re += '\\['; // unmatched `[` → literal
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
else if ('.+^${}()|\\]'.includes(c)) {
|
|
353
|
+
re += `\\${c}`;
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
re += c;
|
|
295
357
|
}
|
|
296
358
|
}
|
|
297
|
-
return
|
|
359
|
+
return new RegExp(`${re}$`);
|
|
298
360
|
}
|
|
299
361
|
function loadIgnore(wsDir) {
|
|
300
362
|
// .npmignore takes precedence over .gitignore (npm semantics).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.41",
|
|
4
4
|
"description": "CLI for Gjsify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -120,19 +120,19 @@
|
|
|
120
120
|
"cli"
|
|
121
121
|
],
|
|
122
122
|
"dependencies": {
|
|
123
|
-
"@gjsify/buffer": "^0.4.
|
|
124
|
-
"@gjsify/create-app": "^0.4.
|
|
125
|
-
"@gjsify/node-globals": "^0.4.
|
|
126
|
-
"@gjsify/node-polyfills": "^0.4.
|
|
127
|
-
"@gjsify/npm-registry": "^0.4.
|
|
128
|
-
"@gjsify/resolve-npm": "^0.4.
|
|
129
|
-
"@gjsify/rolldown-plugin-gjsify": "^0.4.
|
|
130
|
-
"@gjsify/rolldown-plugin-pnp": "^0.4.
|
|
131
|
-
"@gjsify/semver": "^0.4.
|
|
132
|
-
"@gjsify/tar": "^0.4.
|
|
133
|
-
"@gjsify/tsc": "^0.4.
|
|
134
|
-
"@gjsify/web-polyfills": "^0.4.
|
|
135
|
-
"@gjsify/workspace": "^0.4.
|
|
123
|
+
"@gjsify/buffer": "^0.4.41",
|
|
124
|
+
"@gjsify/create-app": "^0.4.41",
|
|
125
|
+
"@gjsify/node-globals": "^0.4.41",
|
|
126
|
+
"@gjsify/node-polyfills": "^0.4.41",
|
|
127
|
+
"@gjsify/npm-registry": "^0.4.41",
|
|
128
|
+
"@gjsify/resolve-npm": "^0.4.41",
|
|
129
|
+
"@gjsify/rolldown-plugin-gjsify": "^0.4.41",
|
|
130
|
+
"@gjsify/rolldown-plugin-pnp": "^0.4.41",
|
|
131
|
+
"@gjsify/semver": "^0.4.41",
|
|
132
|
+
"@gjsify/tar": "^0.4.41",
|
|
133
|
+
"@gjsify/tsc": "^0.4.41",
|
|
134
|
+
"@gjsify/web-polyfills": "^0.4.41",
|
|
135
|
+
"@gjsify/workspace": "^0.4.41",
|
|
136
136
|
"cosmiconfig": "^9.0.1",
|
|
137
137
|
"get-tsconfig": "^4.14.0",
|
|
138
138
|
"pkg-types": "^2.3.1",
|
|
@@ -140,12 +140,12 @@
|
|
|
140
140
|
"yargs": "^18.0.0"
|
|
141
141
|
},
|
|
142
142
|
"devDependencies": {
|
|
143
|
-
"@gjsify/unit": "^0.4.
|
|
143
|
+
"@gjsify/unit": "^0.4.41",
|
|
144
144
|
"@types/yargs": "^17.0.35",
|
|
145
145
|
"typescript": "^6.0.3"
|
|
146
146
|
},
|
|
147
147
|
"peerDependencies": {
|
|
148
|
-
"@gjsify/rolldown-native": "^0.4.
|
|
148
|
+
"@gjsify/rolldown-native": "^0.4.41"
|
|
149
149
|
},
|
|
150
150
|
"peerDependenciesMeta": {
|
|
151
151
|
"@gjsify/rolldown-native": {
|