ugly-app 0.1.425 → 0.1.426
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/build.d.ts.map +1 -1
- package/dist/cli/build.js +2 -2
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/resolveBin.d.ts +45 -8
- package/dist/cli/resolveBin.d.ts.map +1 -1
- package/dist/cli/resolveBin.js +120 -12
- package/dist/cli/resolveBin.js.map +1 -1
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +1 -1
- package/src/cli/build.ts +2 -0
- package/src/cli/resolveBin.ts +149 -12
- package/src/cli/version.ts +1 -1
package/dist/cli/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAOA,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAOA,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CA4F9C"}
|
package/dist/cli/build.js
CHANGED
|
@@ -44,7 +44,7 @@ export const buildId = '${buildId}';
|
|
|
44
44
|
console.log('[Build] Bundling server...');
|
|
45
45
|
const serverOutDir = path.join(distDir, 'server');
|
|
46
46
|
fs.mkdirSync(serverOutDir, { recursive: true });
|
|
47
|
-
execSync(nodeBinCommand('esbuild', 'server/index.ts --bundle --platform=node --format=esm --outfile=dist/server/index.mjs --external:ugly-app --external:ugly-app/*'), { stdio: 'inherit', cwd: process.cwd() });
|
|
47
|
+
execSync(nodeBinCommand('esbuild', 'server/index.ts --bundle --platform=node --format=esm --outfile=dist/server/index.mjs --external:ugly-app --external:ugly-app/*', { anchors: ['cwd', 'ugly-app'] }), { stdio: 'inherit', cwd: process.cwd() });
|
|
48
48
|
}
|
|
49
49
|
// Bundle task.ts if it exists (for cron/worker/GPU tasks)
|
|
50
50
|
const taskEntry = path.join(process.cwd(), 'server', 'task.ts');
|
|
@@ -62,7 +62,7 @@ export const buildId = '${buildId}';
|
|
|
62
62
|
'mediasoup', 'mediasoup-client',
|
|
63
63
|
];
|
|
64
64
|
const externalFlags = externals.map(e => `--external:${e}`).join(' ');
|
|
65
|
-
execSync(nodeBinCommand('esbuild', `server/task.ts --bundle --platform=node --format=esm --outfile=dist/tasks/task.js ${externalFlags}
|
|
65
|
+
execSync(nodeBinCommand('esbuild', `server/task.ts --bundle --platform=node --format=esm --outfile=dist/tasks/task.js ${externalFlags}`, { anchors: ['cwd', 'ugly-app'] }), { stdio: 'inherit', cwd: process.cwd() });
|
|
66
66
|
console.log('[Build] Task bundle: dist/tasks/task.js');
|
|
67
67
|
}
|
|
68
68
|
// Run tsc for typecheck
|
package/dist/cli/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,CAAC,KAAK,UAAU,QAAQ;IAC5B,qEAAqE;IACrE,wEAAwE;IACxE,MAAM,oBAAoB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1C,MAAM,gBAAgB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEtC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAEnC,wBAAwB;IACxB,MAAM,a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SAChC,CAAC;QACF,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtE,QAAQ,CACN,cAAc,CACZ,SAAS,EACT,qFAAqF,aAAa,EAAE,EACpG,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CACjC,EACD,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CACzC,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACzD,CAAC;IAED,wBAAwB;IACxB,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACtC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE;QACxD,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;KACnB,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,2BAA2B,OAAO,GAAG,CAAC,CAAC;AACrD,CAAC"}
|
package/dist/cli/resolveBin.d.ts
CHANGED
|
@@ -1,23 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anchors that can be used to resolve a package. `cwd` means resolve
|
|
3
|
+
* starting from the user project's `package.json`; `ugly-app` means
|
|
4
|
+
* resolve starting from this CLI's own location (so packages that are
|
|
5
|
+
* deps of `ugly-app` itself — like `esbuild` — are findable even when
|
|
6
|
+
* they aren't direct deps of the user's project).
|
|
7
|
+
*/
|
|
8
|
+
export type ResolveAnchor = 'cwd' | 'ugly-app';
|
|
9
|
+
interface ResolveOpts {
|
|
10
|
+
binName?: string;
|
|
11
|
+
cwd?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Ordered list of anchors to try. Defaults to `['cwd']` for backward
|
|
14
|
+
* compatibility. For ugly-app-owned tooling (esbuild, etc.), pass
|
|
15
|
+
* `['cwd', 'ugly-app']` so a missing dep in the user's project falls
|
|
16
|
+
* through to ugly-app's own copy instead of walking up parent dirs
|
|
17
|
+
* and surfacing a stray system-level install.
|
|
18
|
+
*/
|
|
19
|
+
anchors?: ResolveAnchor[];
|
|
20
|
+
}
|
|
1
21
|
/**
|
|
2
22
|
* Resolve a package's bin entry to an absolute path to the JS file —
|
|
3
23
|
* using Node's module resolution (pnpm-strict-safe) rather than
|
|
4
24
|
* assuming `node_modules/.bin/<name>` exists.
|
|
5
25
|
*
|
|
6
|
-
* Why this matters:
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
26
|
+
* Why this matters:
|
|
27
|
+
*
|
|
28
|
+
* 1. `npx <bin>` fails with `Unknown command: <bin>` inside a
|
|
29
|
+
* pnpm-style nested store because the binary lives in
|
|
30
|
+
* `node_modules/.pnpm/...` and was never linked to the top-level
|
|
31
|
+
* `.bin/`.
|
|
32
|
+
*
|
|
33
|
+
* 2. A naive `createRequire(cwd/package.json).resolve('<pkg>')` works
|
|
34
|
+
* for *direct* deps of the user's project, but for transitive deps
|
|
35
|
+
* (e.g. `esbuild`, which is a dep of `ugly-app` and not the user
|
|
36
|
+
* project) Node's resolver walks UP parent directories until it
|
|
37
|
+
* finds *any* `node_modules/<pkg>` — often a stray install in the
|
|
38
|
+
* user's home or `Documents/GitHub`. We've seen that happen and
|
|
39
|
+
* surface a Mach-O native binary as if it were a JS bin script.
|
|
40
|
+
*
|
|
41
|
+
* The fix: when the package is owned by `ugly-app` (esbuild and
|
|
42
|
+
* friends), pass `anchors: ['cwd', 'ugly-app']`. The `'ugly-app'`
|
|
43
|
+
* anchor resolves the package starting from this CLI's own location,
|
|
44
|
+
* so we always find ugly-app's own copy. We also reject any
|
|
45
|
+
* resolution that escapes both the cwd's `node_modules/` subtree and
|
|
46
|
+
* ugly-app's `node_modules/` subtree, so a stray ancestor install
|
|
47
|
+
* can't sneak in.
|
|
12
48
|
*
|
|
13
49
|
* Returns `null` when the package isn't installed or has no bin entry.
|
|
14
50
|
*/
|
|
15
|
-
export declare function resolveBinJs(pkg: string,
|
|
51
|
+
export declare function resolveBinJs(pkg: string, binNameOrOpts?: string | ResolveOpts, cwd?: string): string | null;
|
|
16
52
|
/**
|
|
17
53
|
* Build a `node <abs.js> <args>` command string for execSync. The
|
|
18
54
|
* binary is resolved via `resolveBinJs`; when it can't be found we
|
|
19
55
|
* fall back to `npx <pkg> <args>` and let the user see the original
|
|
20
56
|
* failure mode rather than a confusing error from this helper.
|
|
21
57
|
*/
|
|
22
|
-
export declare function nodeBinCommand(pkg: string, args: string,
|
|
58
|
+
export declare function nodeBinCommand(pkg: string, args: string, binNameOrOpts?: string | ResolveOpts, cwd?: string): string;
|
|
59
|
+
export {};
|
|
23
60
|
//# sourceMappingURL=resolveBin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBin.d.ts","sourceRoot":"","sources":["../../src/cli/resolveBin.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"resolveBin.d.ts","sourceRoot":"","sources":["../../src/cli/resolveBin.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,UAAU,CAAC;AAE/C,UAAU,WAAW;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,EACX,aAAa,CAAC,EAAE,MAAM,GAAG,WAAW,EACpC,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,GAAG,IAAI,CAsCf;AAgFD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,MAAM,GAAG,WAAW,EACpC,GAAG,CAAC,EAAE,MAAM,GACX,MAAM,CASR"}
|
package/dist/cli/resolveBin.js
CHANGED
|
@@ -6,26 +6,81 @@ import path from 'path';
|
|
|
6
6
|
* using Node's module resolution (pnpm-strict-safe) rather than
|
|
7
7
|
* assuming `node_modules/.bin/<name>` exists.
|
|
8
8
|
*
|
|
9
|
-
* Why this matters:
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
9
|
+
* Why this matters:
|
|
10
|
+
*
|
|
11
|
+
* 1. `npx <bin>` fails with `Unknown command: <bin>` inside a
|
|
12
|
+
* pnpm-style nested store because the binary lives in
|
|
13
|
+
* `node_modules/.pnpm/...` and was never linked to the top-level
|
|
14
|
+
* `.bin/`.
|
|
15
|
+
*
|
|
16
|
+
* 2. A naive `createRequire(cwd/package.json).resolve('<pkg>')` works
|
|
17
|
+
* for *direct* deps of the user's project, but for transitive deps
|
|
18
|
+
* (e.g. `esbuild`, which is a dep of `ugly-app` and not the user
|
|
19
|
+
* project) Node's resolver walks UP parent directories until it
|
|
20
|
+
* finds *any* `node_modules/<pkg>` — often a stray install in the
|
|
21
|
+
* user's home or `Documents/GitHub`. We've seen that happen and
|
|
22
|
+
* surface a Mach-O native binary as if it were a JS bin script.
|
|
23
|
+
*
|
|
24
|
+
* The fix: when the package is owned by `ugly-app` (esbuild and
|
|
25
|
+
* friends), pass `anchors: ['cwd', 'ugly-app']`. The `'ugly-app'`
|
|
26
|
+
* anchor resolves the package starting from this CLI's own location,
|
|
27
|
+
* so we always find ugly-app's own copy. We also reject any
|
|
28
|
+
* resolution that escapes both the cwd's `node_modules/` subtree and
|
|
29
|
+
* ugly-app's `node_modules/` subtree, so a stray ancestor install
|
|
30
|
+
* can't sneak in.
|
|
15
31
|
*
|
|
16
32
|
* Returns `null` when the package isn't installed or has no bin entry.
|
|
17
33
|
*/
|
|
18
|
-
export function resolveBinJs(pkg,
|
|
34
|
+
export function resolveBinJs(pkg, binNameOrOpts, cwd) {
|
|
35
|
+
const opts = typeof binNameOrOpts === 'object' && binNameOrOpts !== null
|
|
36
|
+
? binNameOrOpts
|
|
37
|
+
: {
|
|
38
|
+
...(binNameOrOpts ? { binName: binNameOrOpts } : {}),
|
|
39
|
+
...(cwd ? { cwd } : {}),
|
|
40
|
+
};
|
|
41
|
+
const projectCwd = opts.cwd ?? process.cwd();
|
|
42
|
+
const anchors = opts.anchors ?? ['cwd'];
|
|
43
|
+
const uglyAppPkgJson = findUglyAppPackageJson();
|
|
44
|
+
const acceptableRoots = [path.join(projectCwd, 'node_modules')];
|
|
45
|
+
if (uglyAppPkgJson) {
|
|
46
|
+
acceptableRoots.push(path.join(path.dirname(uglyAppPkgJson), 'node_modules'));
|
|
47
|
+
// pnpm: ugly-app's deps live as siblings under the same .pnpm
|
|
48
|
+
// store dir (e.g. `<store>/<ugly-app-id>/node_modules/ugly-app`
|
|
49
|
+
// and `<store>/<ugly-app-id>/node_modules/esbuild`). Accept the
|
|
50
|
+
// entire `.pnpm` subtree so transitive lookups don't get rejected.
|
|
51
|
+
const pnpmStore = findPnpmStoreRoot(path.dirname(uglyAppPkgJson));
|
|
52
|
+
if (pnpmStore)
|
|
53
|
+
acceptableRoots.push(pnpmStore);
|
|
54
|
+
}
|
|
55
|
+
for (const anchor of anchors) {
|
|
56
|
+
const anchorPkgJson = anchor === 'cwd'
|
|
57
|
+
? path.join(projectCwd, 'package.json')
|
|
58
|
+
: uglyAppPkgJson;
|
|
59
|
+
if (!anchorPkgJson)
|
|
60
|
+
continue;
|
|
61
|
+
if (!fs.existsSync(anchorPkgJson))
|
|
62
|
+
continue;
|
|
63
|
+
const resolved = tryResolveFrom(anchorPkgJson, pkg, opts.binName);
|
|
64
|
+
if (!resolved)
|
|
65
|
+
continue;
|
|
66
|
+
if (!isPathInsideAny(resolved, acceptableRoots))
|
|
67
|
+
continue;
|
|
68
|
+
return resolved;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function tryResolveFrom(fromPkgJson, pkg, binName) {
|
|
19
73
|
try {
|
|
20
|
-
const
|
|
21
|
-
const req = createRequire(fromCwd);
|
|
74
|
+
const req = createRequire(fromPkgJson);
|
|
22
75
|
const pkgJsonPath = req.resolve(`${pkg}/package.json`);
|
|
23
76
|
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
|
|
24
77
|
const pkgDir = path.dirname(pkgJsonPath);
|
|
25
78
|
const binField = pkgJson.bin;
|
|
26
79
|
if (!binField)
|
|
27
80
|
return null;
|
|
28
|
-
const rel = typeof binField === 'string'
|
|
81
|
+
const rel = typeof binField === 'string'
|
|
82
|
+
? binField
|
|
83
|
+
: binField[binName ?? pkgJson.name];
|
|
29
84
|
if (!rel)
|
|
30
85
|
return null;
|
|
31
86
|
return path.join(pkgDir, rel);
|
|
@@ -34,18 +89,71 @@ export function resolveBinJs(pkg, binName, cwd) {
|
|
|
34
89
|
return null;
|
|
35
90
|
}
|
|
36
91
|
}
|
|
92
|
+
function isPathInsideAny(target, roots) {
|
|
93
|
+
const resolvedTarget = path.resolve(target);
|
|
94
|
+
for (const root of roots) {
|
|
95
|
+
const resolvedRoot = path.resolve(root);
|
|
96
|
+
const rel = path.relative(resolvedRoot, resolvedTarget);
|
|
97
|
+
if (rel && !rel.startsWith('..') && !path.isAbsolute(rel))
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Find ugly-app's own `package.json` by walking up from this file.
|
|
104
|
+
* Cached after first lookup.
|
|
105
|
+
*/
|
|
106
|
+
let cachedUglyAppPkgJson;
|
|
107
|
+
function findUglyAppPackageJson() {
|
|
108
|
+
if (cachedUglyAppPkgJson !== undefined)
|
|
109
|
+
return cachedUglyAppPkgJson;
|
|
110
|
+
let dir = path.dirname(new URL(import.meta.url).pathname);
|
|
111
|
+
for (let i = 0; i < 8; i += 1) {
|
|
112
|
+
const candidate = path.join(dir, 'package.json');
|
|
113
|
+
if (fs.existsSync(candidate)) {
|
|
114
|
+
try {
|
|
115
|
+
const json = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
|
|
116
|
+
if (json.name === 'ugly-app') {
|
|
117
|
+
cachedUglyAppPkgJson = candidate;
|
|
118
|
+
return candidate;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// ignore
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const parent = path.dirname(dir);
|
|
126
|
+
if (parent === dir)
|
|
127
|
+
break;
|
|
128
|
+
dir = parent;
|
|
129
|
+
}
|
|
130
|
+
cachedUglyAppPkgJson = null;
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* From a directory inside `node_modules/.pnpm/<id>/node_modules/ugly-app/`,
|
|
135
|
+
* return the `node_modules/.pnpm/` root; otherwise return null.
|
|
136
|
+
*/
|
|
137
|
+
function findPnpmStoreRoot(uglyAppDir) {
|
|
138
|
+
const marker = `${path.sep}node_modules${path.sep}.pnpm${path.sep}`;
|
|
139
|
+
const idx = uglyAppDir.indexOf(marker);
|
|
140
|
+
if (idx < 0)
|
|
141
|
+
return null;
|
|
142
|
+
return uglyAppDir.slice(0, idx + marker.length - 1);
|
|
143
|
+
}
|
|
37
144
|
/**
|
|
38
145
|
* Build a `node <abs.js> <args>` command string for execSync. The
|
|
39
146
|
* binary is resolved via `resolveBinJs`; when it can't be found we
|
|
40
147
|
* fall back to `npx <pkg> <args>` and let the user see the original
|
|
41
148
|
* failure mode rather than a confusing error from this helper.
|
|
42
149
|
*/
|
|
43
|
-
export function nodeBinCommand(pkg, args,
|
|
44
|
-
const bin = resolveBinJs(pkg,
|
|
150
|
+
export function nodeBinCommand(pkg, args, binNameOrOpts, cwd) {
|
|
151
|
+
const bin = resolveBinJs(pkg, binNameOrOpts, cwd);
|
|
45
152
|
const q = (s) => `"${s.replace(/"/g, '\\"')}"`;
|
|
46
153
|
if (bin) {
|
|
47
154
|
return `${q(process.execPath)} ${q(bin)} ${args}`;
|
|
48
155
|
}
|
|
156
|
+
const binName = typeof binNameOrOpts === 'string' ? binNameOrOpts : binNameOrOpts?.binName;
|
|
49
157
|
return `npx ${binName ?? pkg} ${args}`;
|
|
50
158
|
}
|
|
51
159
|
//# sourceMappingURL=resolveBin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBin.js","sourceRoot":"","sources":["../../src/cli/resolveBin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"resolveBin.js","sourceRoot":"","sources":["../../src/cli/resolveBin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,IAAI,MAAM,MAAM,CAAC;AAwBxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAW,EACX,aAAoC,EACpC,GAAY;IAEZ,MAAM,IAAI,GACR,OAAO,aAAa,KAAK,QAAQ,IAAI,aAAa,KAAK,IAAI;QACzD,CAAC,CAAC,aAAa;QACf,CAAC,CAAC;YACE,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpD,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxB,CAAC;IACR,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;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,GAAG,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAW,EACX,IAAY,EACZ,aAAoC,EACpC,GAAY;IAEZ,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,CAAC,CAAC;IAClD,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IACvD,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;IACpD,CAAC;IACD,MAAM,OAAO,GACX,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,EAAE,OAAO,CAAC;IAC7E,OAAO,OAAO,OAAO,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;AACzC,CAAC"}
|
package/dist/cli/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const CLI_VERSION = "0.1.
|
|
1
|
+
export declare const CLI_VERSION = "0.1.426";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/cli/version.js
CHANGED
package/package.json
CHANGED
package/src/cli/build.ts
CHANGED
|
@@ -56,6 +56,7 @@ export const buildId = '${buildId}';
|
|
|
56
56
|
nodeBinCommand(
|
|
57
57
|
'esbuild',
|
|
58
58
|
'server/index.ts --bundle --platform=node --format=esm --outfile=dist/server/index.mjs --external:ugly-app --external:ugly-app/*',
|
|
59
|
+
{ anchors: ['cwd', 'ugly-app'] },
|
|
59
60
|
),
|
|
60
61
|
{ stdio: 'inherit', cwd: process.cwd() },
|
|
61
62
|
);
|
|
@@ -81,6 +82,7 @@ export const buildId = '${buildId}';
|
|
|
81
82
|
nodeBinCommand(
|
|
82
83
|
'esbuild',
|
|
83
84
|
`server/task.ts --bundle --platform=node --format=esm --outfile=dist/tasks/task.js ${externalFlags}`,
|
|
85
|
+
{ anchors: ['cwd', 'ugly-app'] },
|
|
84
86
|
),
|
|
85
87
|
{ stdio: 'inherit', cwd: process.cwd() },
|
|
86
88
|
);
|
package/src/cli/resolveBin.ts
CHANGED
|
@@ -2,28 +2,109 @@ import fs from 'fs';
|
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Anchors that can be used to resolve a package. `cwd` means resolve
|
|
7
|
+
* starting from the user project's `package.json`; `ugly-app` means
|
|
8
|
+
* resolve starting from this CLI's own location (so packages that are
|
|
9
|
+
* deps of `ugly-app` itself — like `esbuild` — are findable even when
|
|
10
|
+
* they aren't direct deps of the user's project).
|
|
11
|
+
*/
|
|
12
|
+
export type ResolveAnchor = 'cwd' | 'ugly-app';
|
|
13
|
+
|
|
14
|
+
interface ResolveOpts {
|
|
15
|
+
binName?: string;
|
|
16
|
+
cwd?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Ordered list of anchors to try. Defaults to `['cwd']` for backward
|
|
19
|
+
* compatibility. For ugly-app-owned tooling (esbuild, etc.), pass
|
|
20
|
+
* `['cwd', 'ugly-app']` so a missing dep in the user's project falls
|
|
21
|
+
* through to ugly-app's own copy instead of walking up parent dirs
|
|
22
|
+
* and surfacing a stray system-level install.
|
|
23
|
+
*/
|
|
24
|
+
anchors?: ResolveAnchor[];
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
/**
|
|
6
28
|
* Resolve a package's bin entry to an absolute path to the JS file —
|
|
7
29
|
* using Node's module resolution (pnpm-strict-safe) rather than
|
|
8
30
|
* assuming `node_modules/.bin/<name>` exists.
|
|
9
31
|
*
|
|
10
|
-
* Why this matters:
|
|
11
|
-
*
|
|
12
|
-
* `
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
32
|
+
* Why this matters:
|
|
33
|
+
*
|
|
34
|
+
* 1. `npx <bin>` fails with `Unknown command: <bin>` inside a
|
|
35
|
+
* pnpm-style nested store because the binary lives in
|
|
36
|
+
* `node_modules/.pnpm/...` and was never linked to the top-level
|
|
37
|
+
* `.bin/`.
|
|
38
|
+
*
|
|
39
|
+
* 2. A naive `createRequire(cwd/package.json).resolve('<pkg>')` works
|
|
40
|
+
* for *direct* deps of the user's project, but for transitive deps
|
|
41
|
+
* (e.g. `esbuild`, which is a dep of `ugly-app` and not the user
|
|
42
|
+
* project) Node's resolver walks UP parent directories until it
|
|
43
|
+
* finds *any* `node_modules/<pkg>` — often a stray install in the
|
|
44
|
+
* user's home or `Documents/GitHub`. We've seen that happen and
|
|
45
|
+
* surface a Mach-O native binary as if it were a JS bin script.
|
|
46
|
+
*
|
|
47
|
+
* The fix: when the package is owned by `ugly-app` (esbuild and
|
|
48
|
+
* friends), pass `anchors: ['cwd', 'ugly-app']`. The `'ugly-app'`
|
|
49
|
+
* anchor resolves the package starting from this CLI's own location,
|
|
50
|
+
* so we always find ugly-app's own copy. We also reject any
|
|
51
|
+
* resolution that escapes both the cwd's `node_modules/` subtree and
|
|
52
|
+
* ugly-app's `node_modules/` subtree, so a stray ancestor install
|
|
53
|
+
* can't sneak in.
|
|
16
54
|
*
|
|
17
55
|
* Returns `null` when the package isn't installed or has no bin entry.
|
|
18
56
|
*/
|
|
19
57
|
export function resolveBinJs(
|
|
20
58
|
pkg: string,
|
|
21
|
-
|
|
59
|
+
binNameOrOpts?: string | ResolveOpts,
|
|
22
60
|
cwd?: string,
|
|
61
|
+
): string | null {
|
|
62
|
+
const opts: ResolveOpts =
|
|
63
|
+
typeof binNameOrOpts === 'object' && binNameOrOpts !== null
|
|
64
|
+
? binNameOrOpts
|
|
65
|
+
: {
|
|
66
|
+
...(binNameOrOpts ? { binName: binNameOrOpts } : {}),
|
|
67
|
+
...(cwd ? { cwd } : {}),
|
|
68
|
+
};
|
|
69
|
+
const projectCwd = opts.cwd ?? process.cwd();
|
|
70
|
+
const anchors = opts.anchors ?? ['cwd'];
|
|
71
|
+
const uglyAppPkgJson = findUglyAppPackageJson();
|
|
72
|
+
|
|
73
|
+
const acceptableRoots = [path.join(projectCwd, 'node_modules')];
|
|
74
|
+
if (uglyAppPkgJson) {
|
|
75
|
+
acceptableRoots.push(
|
|
76
|
+
path.join(path.dirname(uglyAppPkgJson), 'node_modules'),
|
|
77
|
+
);
|
|
78
|
+
// pnpm: ugly-app's deps live as siblings under the same .pnpm
|
|
79
|
+
// store dir (e.g. `<store>/<ugly-app-id>/node_modules/ugly-app`
|
|
80
|
+
// and `<store>/<ugly-app-id>/node_modules/esbuild`). Accept the
|
|
81
|
+
// entire `.pnpm` subtree so transitive lookups don't get rejected.
|
|
82
|
+
const pnpmStore = findPnpmStoreRoot(path.dirname(uglyAppPkgJson));
|
|
83
|
+
if (pnpmStore) acceptableRoots.push(pnpmStore);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (const anchor of anchors) {
|
|
87
|
+
const anchorPkgJson =
|
|
88
|
+
anchor === 'cwd'
|
|
89
|
+
? path.join(projectCwd, 'package.json')
|
|
90
|
+
: uglyAppPkgJson;
|
|
91
|
+
if (!anchorPkgJson) continue;
|
|
92
|
+
if (!fs.existsSync(anchorPkgJson)) continue;
|
|
93
|
+
const resolved = tryResolveFrom(anchorPkgJson, pkg, opts.binName);
|
|
94
|
+
if (!resolved) continue;
|
|
95
|
+
if (!isPathInsideAny(resolved, acceptableRoots)) continue;
|
|
96
|
+
return resolved;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function tryResolveFrom(
|
|
102
|
+
fromPkgJson: string,
|
|
103
|
+
pkg: string,
|
|
104
|
+
binName?: string,
|
|
23
105
|
): string | null {
|
|
24
106
|
try {
|
|
25
|
-
const
|
|
26
|
-
const req = createRequire(fromCwd);
|
|
107
|
+
const req = createRequire(fromPkgJson);
|
|
27
108
|
const pkgJsonPath = req.resolve(`${pkg}/package.json`);
|
|
28
109
|
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')) as {
|
|
29
110
|
name: string;
|
|
@@ -33,7 +114,9 @@ export function resolveBinJs(
|
|
|
33
114
|
const binField = pkgJson.bin;
|
|
34
115
|
if (!binField) return null;
|
|
35
116
|
const rel =
|
|
36
|
-
typeof binField === 'string'
|
|
117
|
+
typeof binField === 'string'
|
|
118
|
+
? binField
|
|
119
|
+
: binField[binName ?? pkgJson.name];
|
|
37
120
|
if (!rel) return null;
|
|
38
121
|
return path.join(pkgDir, rel);
|
|
39
122
|
} catch {
|
|
@@ -41,6 +124,58 @@ export function resolveBinJs(
|
|
|
41
124
|
}
|
|
42
125
|
}
|
|
43
126
|
|
|
127
|
+
function isPathInsideAny(target: string, roots: string[]): boolean {
|
|
128
|
+
const resolvedTarget = path.resolve(target);
|
|
129
|
+
for (const root of roots) {
|
|
130
|
+
const resolvedRoot = path.resolve(root);
|
|
131
|
+
const rel = path.relative(resolvedRoot, resolvedTarget);
|
|
132
|
+
if (rel && !rel.startsWith('..') && !path.isAbsolute(rel)) return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Find ugly-app's own `package.json` by walking up from this file.
|
|
139
|
+
* Cached after first lookup.
|
|
140
|
+
*/
|
|
141
|
+
let cachedUglyAppPkgJson: string | null | undefined;
|
|
142
|
+
function findUglyAppPackageJson(): string | null {
|
|
143
|
+
if (cachedUglyAppPkgJson !== undefined) return cachedUglyAppPkgJson;
|
|
144
|
+
let dir = path.dirname(new URL(import.meta.url).pathname);
|
|
145
|
+
for (let i = 0; i < 8; i += 1) {
|
|
146
|
+
const candidate = path.join(dir, 'package.json');
|
|
147
|
+
if (fs.existsSync(candidate)) {
|
|
148
|
+
try {
|
|
149
|
+
const json = JSON.parse(fs.readFileSync(candidate, 'utf-8')) as {
|
|
150
|
+
name?: string;
|
|
151
|
+
};
|
|
152
|
+
if (json.name === 'ugly-app') {
|
|
153
|
+
cachedUglyAppPkgJson = candidate;
|
|
154
|
+
return candidate;
|
|
155
|
+
}
|
|
156
|
+
} catch {
|
|
157
|
+
// ignore
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const parent = path.dirname(dir);
|
|
161
|
+
if (parent === dir) break;
|
|
162
|
+
dir = parent;
|
|
163
|
+
}
|
|
164
|
+
cachedUglyAppPkgJson = null;
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* From a directory inside `node_modules/.pnpm/<id>/node_modules/ugly-app/`,
|
|
170
|
+
* return the `node_modules/.pnpm/` root; otherwise return null.
|
|
171
|
+
*/
|
|
172
|
+
function findPnpmStoreRoot(uglyAppDir: string): string | null {
|
|
173
|
+
const marker = `${path.sep}node_modules${path.sep}.pnpm${path.sep}`;
|
|
174
|
+
const idx = uglyAppDir.indexOf(marker);
|
|
175
|
+
if (idx < 0) return null;
|
|
176
|
+
return uglyAppDir.slice(0, idx + marker.length - 1);
|
|
177
|
+
}
|
|
178
|
+
|
|
44
179
|
/**
|
|
45
180
|
* Build a `node <abs.js> <args>` command string for execSync. The
|
|
46
181
|
* binary is resolved via `resolveBinJs`; when it can't be found we
|
|
@@ -50,13 +185,15 @@ export function resolveBinJs(
|
|
|
50
185
|
export function nodeBinCommand(
|
|
51
186
|
pkg: string,
|
|
52
187
|
args: string,
|
|
53
|
-
|
|
188
|
+
binNameOrOpts?: string | ResolveOpts,
|
|
54
189
|
cwd?: string,
|
|
55
190
|
): string {
|
|
56
|
-
const bin = resolveBinJs(pkg,
|
|
191
|
+
const bin = resolveBinJs(pkg, binNameOrOpts, cwd);
|
|
57
192
|
const q = (s: string) => `"${s.replace(/"/g, '\\"')}"`;
|
|
58
193
|
if (bin) {
|
|
59
194
|
return `${q(process.execPath)} ${q(bin)} ${args}`;
|
|
60
195
|
}
|
|
196
|
+
const binName =
|
|
197
|
+
typeof binNameOrOpts === 'string' ? binNameOrOpts : binNameOrOpts?.binName;
|
|
61
198
|
return `npx ${binName ?? pkg} ${args}`;
|
|
62
199
|
}
|
package/src/cli/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated by prebuild — do not edit manually
|
|
2
|
-
export const CLI_VERSION = "0.1.
|
|
2
|
+
export const CLI_VERSION = "0.1.426";
|