smol-symphony 0.3.1 → 0.3.2
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/package.json +1 -1
- package/scripts/postinstall.mjs +24 -1
package/package.json
CHANGED
package/scripts/postinstall.mjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { createRequire } from 'node:module';
|
|
19
19
|
import { spawnSync } from 'node:child_process';
|
|
20
|
-
import { readFileSync } from 'node:fs';
|
|
20
|
+
import { readFileSync, existsSync, writeFileSync, rmSync } from 'node:fs';
|
|
21
21
|
import { dirname, join, resolve, relative, sep } from 'node:path';
|
|
22
22
|
import { fileURLToPath } from 'node:url';
|
|
23
23
|
|
|
@@ -55,9 +55,32 @@ const appRoot = idx === -1 ? process.cwd() : depPkgJson.slice(0, idx);
|
|
|
55
55
|
// patch-package REQUIRES --patch-dir to be relative to its CWD (it rejects an
|
|
56
56
|
// absolute path), so express our bundled patches dir relative to appRoot.
|
|
57
57
|
const relPatchDir = relative(appRoot, patchDir) || '.';
|
|
58
|
+
|
|
59
|
+
// patch-package's getAppRootPath() walks up from CWD for a package.json and
|
|
60
|
+
// THROWS "no package.json found for this project" if none exists. Under `npx`,
|
|
61
|
+
// the install root (~/.npm/_npx/<hash>/) has a node_modules but NO package.json,
|
|
62
|
+
// so patch-package crashes there and the whole npx invocation aborts before the
|
|
63
|
+
// bin ever runs. If appRoot lacks one, drop a minimal placeholder for the
|
|
64
|
+
// duration of the run and remove it after. (A normal `npm install`/-g already has
|
|
65
|
+
// one, so we leave it untouched.)
|
|
66
|
+
const appPkgJson = join(appRoot, 'package.json');
|
|
67
|
+
const createdTempPkgJson = !existsSync(appPkgJson);
|
|
68
|
+
if (createdTempPkgJson) {
|
|
69
|
+
try {
|
|
70
|
+
writeFileSync(appPkgJson, '{"name":"_symphony-patch-root","version":"0.0.0"}\n');
|
|
71
|
+
} catch {
|
|
72
|
+
// Can't write (read-only root) — let patch-package surface whatever it can.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
58
76
|
const patchPackageBin = join(dirname(require.resolve('patch-package/package.json')), 'index.js');
|
|
59
77
|
const res = spawnSync(process.execPath, [patchPackageBin, '--patch-dir', relPatchDir], {
|
|
60
78
|
cwd: appRoot,
|
|
61
79
|
stdio: 'inherit',
|
|
62
80
|
});
|
|
81
|
+
|
|
82
|
+
// Remove the placeholder BEFORE exiting (process.exit skips finally blocks).
|
|
83
|
+
if (createdTempPkgJson) {
|
|
84
|
+
try { rmSync(appPkgJson); } catch { /* best-effort cleanup */ }
|
|
85
|
+
}
|
|
63
86
|
process.exit(res.status ?? 0);
|