Skip to content

Commit 2a93754

Browse files
fix: npm 12 post-install scripts bug with npx (#70)
* fix: update to @lydell/node-pty which has no post install scripts * feat: update to node-pty latest (1.2 beta) which has pre-compiled binaries and does not rely on post install scripts (node-gyp) * fix: additional fixes for oclif (for npm 12) and remove windows in pretarball now. Bumped to official version 1.2.3
1 parent c913806 commit 2a93754

19 files changed

Lines changed: 112 additions & 39 deletions

‎README.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
> ⚠️ **This package has been migrated and re-purposed.** The original package by [Andrew Stone](https://www.npmjs.com/~andrewjstone)
2-
> for transforming integers to base36 strings. To continue to use that functionality, please pin to version 0.3.0 or below.
3-
41
# Codify - Your Development Environment as Code
52

63
**Stop manually setting up your development environment. Define it once, replicate it everywhere.**

‎package-lock.json‎

Lines changed: 51 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dependencies": {
77
"@codifycli/ink-form": "0.0.12",
88
"@codifycli/schemas": "1.2.0",
9-
"@homebridge/node-pty-prebuilt-multiarch": "^0.13.1",
9+
"@homebridge/node-pty-prebuilt-multiarch": "npm:node-pty@1.2.0-beta.15",
1010
"@mischnic/json-sourcemap": "^0.1.1",
1111
"@oclif/core": "^4.0.8",
1212
"@oclif/plugin-autocomplete": "^3.2.24",
@@ -36,6 +36,7 @@
3636
"kill-port": "^2.0.1",
3737
"latest-semver": "^4.0.0",
3838
"nanoid": "^5.0.9",
39+
"node-pty": "1.2.0-beta.15",
3940
"open": "^10.1.2",
4041
"parse-json": "^8.1.0",
4142
"react": "^18.3.1",
@@ -133,7 +134,7 @@
133134
"build:release": "npm run pkg && ./scripts/notarize.sh",
134135
"lint": "tsc",
135136
"postpack": "shx rm -f oclif.manifest.json",
136-
"pretarball": "../../../scripts/codesign.sh",
137+
"pretarball": "../../../scripts/pretarball.sh",
137138
"pkg": "tsx ./scripts/pkg.ts",
138139
"notarize": "./scripts/notarize.sh",
139140
"upload": "./scripts/upload.sh",
@@ -149,7 +150,7 @@
149150
"prepublishOnly": "npm run build && npm run build:npm",
150151
"postpublish": "npm run restore-npm"
151152
},
152-
"version": "1.2.2",
153+
"version": "1.2.3",
153154
"bugs": "https://github.com/codifycli/codify/issues",
154155
"keywords": [
155156
"oclif",

‎scripts/codesign.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
APPLE_DEVELOPER_APPLICATION_PROFILE=$(cat package.json | jq -r '.oclif.macos."application-certificate"')
44

5-
codesign --verbose=4 --timestamp --strict --options runtime -s "$APPLE_DEVELOPER_APPLICATION_PROFILE" node_modules/@homebridge/node-pty-prebuilt-multiarch/build/Release/spawn-helper --force
6-
codesign --verbose=4 --timestamp --strict --options runtime -s "$APPLE_DEVELOPER_APPLICATION_PROFILE" node_modules/@homebridge/node-pty-prebuilt-multiarch/build/Release/pty.node --force
5+
# node-pty ships its native binaries for every platform in prebuilds/<platform>-<arch>. Sign the copy installed under the
6+
# @homebridge alias too, since plugins built before the node-pty switch load that one.
7+
for dir in node_modules/node-pty/prebuilds/darwin-* node_modules/@homebridge/node-pty-prebuilt-multiarch/prebuilds/darwin-*; do
8+
codesign --verbose=4 --timestamp --strict --options runtime -s "$APPLE_DEVELOPER_APPLICATION_PROFILE" "$dir/spawn-helper" --force
9+
codesign --verbose=4 --timestamp --strict --options runtime -s "$APPLE_DEVELOPER_APPLICATION_PROFILE" "$dir/pty.node" --force
10+
done

‎scripts/patch-oclif.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
// on fresh installs, causing the old cached version to be used. The patch must happen before
2626
// `oclif pack macos` runs — modifying the .pkg after the fact breaks notarization.
2727
//
28+
// Also patches node_modules/oclif/lib/tarballs/build.js to drop `--unsafe-perm` from its `npm pack` call. npm 12 removed
29+
// the flag (it has been a no-op since npm 7) and now fails with EUNKNOWNCONFIG. Still present as of oclif 6.0.15.
30+
//
2831
// If oclif upgrades and changes either file's structure, this script exits with code 1 so the
2932
// breakage is immediately visible.
3033
import { existsSync } from 'node:fs';
@@ -35,6 +38,7 @@ import { fileURLToPath } from 'node:url';
3538
const __dirname = path.dirname(fileURLToPath(import.meta.url));
3639
const BIN_JS = path.join(__dirname, '../node_modules/oclif/lib/tarballs/bin.js');
3740
const MACOS_JS = path.join(__dirname, '../node_modules/oclif/lib/commands/pack/macos.js');
41+
const BUILD_JS = path.join(__dirname, '../node_modules/oclif/lib/tarballs/build.js');
3842

3943
if (!existsSync(BIN_JS)) {
4044
console.log('oclif bin.js not found (likely production install). Skipping.');
@@ -130,3 +134,22 @@ if (!existsSync(MACOS_JS)) {
130134
console.log('Successfully patched oclif macos.js preinstall script');
131135
}
132136
}
137+
138+
// Patch build.js to drop `--unsafe-perm` from `npm pack`. npm 12 rejects the unknown flag.
139+
const SEARCH_NPM_PACK = "exec('npm pack --unsafe-perm'";
140+
const PATCH_NPM_PACK = "exec('npm pack'";
141+
142+
if (!existsSync(BUILD_JS)) {
143+
console.log('oclif build.js not found. Skipping npm pack patch.');
144+
} else {
145+
const buildContent = await fs.readFile(BUILD_JS, 'utf8');
146+
if (buildContent.includes(SEARCH_NPM_PACK)) {
147+
await fs.writeFile(BUILD_JS, buildContent.replace(SEARCH_NPM_PACK, PATCH_NPM_PACK), 'utf8');
148+
console.log('Successfully patched oclif build.js npm pack command');
149+
} else if (buildContent.includes(PATCH_NPM_PACK)) {
150+
console.log('oclif build.js npm pack already patched. Skipping.');
151+
} else {
152+
console.error('ERROR: Could not find npm pack command in oclif build.js. The oclif version may have changed.');
153+
process.exit(1);
154+
}
155+
}

‎scripts/pretarball.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# Runs via the `pretarball` npm script inside oclif's packing workspace (.build/tmp/codify), after oclif has installed
3+
# production dependencies there and before it builds each target. Changes to node_modules must happen here: oclif
4+
# re-installs dependencies into this workspace, so edits to .build/node_modules never reach the tarballs.
5+
set -e
6+
7+
# node-pty bundles prebuilt binaries for every platform. The Windows ones are ~23MB per copy and no tarball targets Windows.
8+
rm -rf node_modules/node-pty/prebuilds/win32-* node_modules/@homebridge/node-pty-prebuilt-multiarch/prebuilds/win32-*
9+
10+
"$(dirname "$0")/codesign.sh"

‎src/connect/http-routes/create-command.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IPty, spawn } from '@homebridge/node-pty-prebuilt-multiarch';
1+
import { IPty, spawn } from 'node-pty';
22
import chalk from 'chalk';
33
import { Router } from 'express';
44
import WebSocket from 'ws';

‎src/connect/http-routes/handlers/apply-handler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from '@homebridge/node-pty-prebuilt-multiarch';
1+
import { spawn } from 'node-pty';
22
import { ConfigFileSchema } from '@codifycli/schemas';
33
import * as fs from 'node:fs/promises';
44
import os from 'node:os';

‎src/connect/http-routes/handlers/destroy-handler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from '@homebridge/node-pty-prebuilt-multiarch';
1+
import { spawn } from 'node-pty';
22
import { ConfigFileSchema } from '@codifycli/schemas';
33
import * as fs from 'node:fs/promises';
44
import os from 'node:os';

‎src/connect/http-routes/handlers/import-handler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from '@homebridge/node-pty-prebuilt-multiarch';
1+
import { spawn } from 'node-pty';
22
import { ConfigFileSchema } from '@codifycli/schemas';
33
import { diffChars } from 'diff';
44
import * as fs from 'node:fs/promises';

0 commit comments

Comments
 (0)