Skip to content

Commit 0ce0f32

Browse files
justin808claude
andcommitted
Move pack-config-diff from optionalDependencies to dependencies
Remove the entire npx fallback path (~60 lines per binstub) since pack-config-diff is small and should always be installed. This eliminates the npx --separator issue, the getNpxSpec() no-op in user projects, and the CI guard complexity. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 3babdee commit 0ce0f32

4 files changed

Lines changed: 12 additions & 140 deletions

File tree

bin/diff-bundler-config

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
11
#!/usr/bin/env node
22

3-
const { spawnSync } = require("child_process")
4-
const path = require("path")
5-
63
const PACK_CONFIG_DIFF_PACKAGE = "pack-config-diff"
74

8-
function getNpxSpec() {
9-
try {
10-
const pkg = require(path.join(__dirname, "..", "package.json"))
11-
const version =
12-
(pkg.optionalDependencies &&
13-
pkg.optionalDependencies[PACK_CONFIG_DIFF_PACKAGE]) ||
14-
(pkg.dependencies && pkg.dependencies[PACK_CONFIG_DIFF_PACKAGE])
15-
if (version) return `${PACK_CONFIG_DIFF_PACKAGE}@${version}`
16-
} catch (_) {
17-
// Fall through to default
18-
}
19-
return `${PACK_CONFIG_DIFF_PACKAGE}@^0.1.0`
20-
}
21-
225
function formatError(error) {
236
return error instanceof Error ? error.message : String(error)
247
}
258

26-
function isMissingPackConfigDiff(error) {
27-
return (
28-
error &&
29-
error.code === "MODULE_NOT_FOUND" &&
30-
typeof error.message === "string" &&
31-
error.message.includes(`'${PACK_CONFIG_DIFF_PACKAGE}'`)
32-
)
33-
}
34-
359
function exitWithCode(exitCode) {
3610
if (!Number.isInteger(exitCode)) {
3711
console.error(
@@ -41,57 +15,20 @@ function exitWithCode(exitCode) {
4115
}
4216

4317
// Forward only pack-config-diff's documented exit codes (0 = no diffs, 1 = diffs found).
44-
// Any other code is a tool failure — normalize to 2, matching the npx fallback path.
18+
// Any other code is a tool failure — normalize to 2.
4519
process.exit(exitCode <= 1 ? exitCode : 2)
4620
}
4721

48-
function runViaNpx() {
49-
if (process.env.CI) {
50-
console.error(
51-
`[Shakapacker] ${PACK_CONFIG_DIFF_PACKAGE} is not installed locally, and npx fallback requires an interactive prompt. ` +
52-
`Install ${PACK_CONFIG_DIFF_PACKAGE} locally before running in CI.`
53-
)
54-
process.exit(2)
55-
}
56-
57-
console.error(
58-
`[Shakapacker] ${PACK_CONFIG_DIFF_PACKAGE} is not installed locally. ` +
59-
"Falling back to npx and prompting before download."
60-
)
61-
const result = spawnSync("npx", [getNpxSpec(), ...process.argv.slice(2)], {
62-
stdio: "inherit"
63-
})
64-
65-
if (result.error) {
66-
console.error(
67-
`[Shakapacker] Failed to run ${PACK_CONFIG_DIFF_PACKAGE} via npx: ${formatError(result.error)}`
68-
)
69-
process.exit(2)
70-
}
71-
72-
if (result.signal || result.status == null) {
73-
process.exit(2)
74-
}
75-
76-
// Forward only pack-config-diff's documented exit codes (0 = no diffs, 1 = diffs found).
77-
// Any other code (e.g. 127 = npx not found, 126 = permission denied) is a tool failure.
78-
process.exit(result.status <= 1 ? result.status : 2)
79-
}
80-
8122
let run
8223

8324
try {
8425
const loadedModule = require("pack-config-diff")
8526
run = loadedModule.run
8627
} catch (error) {
87-
if (isMissingPackConfigDiff(error)) {
88-
runViaNpx()
89-
} else {
90-
console.error(
91-
`[Shakapacker] Failed to load ${PACK_CONFIG_DIFF_PACKAGE}: ${formatError(error)}`
92-
)
93-
process.exit(2)
94-
}
28+
console.error(
29+
`[Shakapacker] Failed to load ${PACK_CONFIG_DIFF_PACKAGE}: ${formatError(error)}`
30+
)
31+
process.exit(2)
9532
}
9633

9734
if (typeof run !== "function") {

docs/config-diff.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ bin/diff-bundler-config --left=a.yaml --right=b.yaml --format=yaml
128128

129129
- `0`: no differences found
130130
- `1`: differences found
131-
- `2`: wrapper/runtime error (module load error, invalid return code, npx fallback failure)
131+
- `2`: wrapper/runtime error (module load error, invalid return code)
132132

133133
For CI usage, treat `1` as "configs differ" and `2` as "tool/runtime failure".
134134

lib/install/bin/diff-bundler-config

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
11
#!/usr/bin/env node
22

3-
const { spawnSync } = require("child_process")
4-
const path = require("path")
5-
63
const PACK_CONFIG_DIFF_PACKAGE = "pack-config-diff"
74

8-
function getNpxSpec() {
9-
try {
10-
const pkg = require(path.join(__dirname, "..", "package.json"))
11-
const version =
12-
(pkg.optionalDependencies &&
13-
pkg.optionalDependencies[PACK_CONFIG_DIFF_PACKAGE]) ||
14-
(pkg.dependencies && pkg.dependencies[PACK_CONFIG_DIFF_PACKAGE])
15-
if (version) return `${PACK_CONFIG_DIFF_PACKAGE}@${version}`
16-
} catch (_) {
17-
// Fall through to default
18-
}
19-
return `${PACK_CONFIG_DIFF_PACKAGE}@^0.1.0`
20-
}
21-
225
function formatError(error) {
236
return error instanceof Error ? error.message : String(error)
247
}
258

26-
function isMissingPackConfigDiff(error) {
27-
return (
28-
error &&
29-
error.code === "MODULE_NOT_FOUND" &&
30-
typeof error.message === "string" &&
31-
error.message.includes(`'${PACK_CONFIG_DIFF_PACKAGE}'`)
32-
)
33-
}
34-
359
function exitWithCode(exitCode) {
3610
if (!Number.isInteger(exitCode)) {
3711
console.error(
@@ -41,57 +15,20 @@ function exitWithCode(exitCode) {
4115
}
4216

4317
// Forward only pack-config-diff's documented exit codes (0 = no diffs, 1 = diffs found).
44-
// Any other code is a tool failure — normalize to 2, matching the npx fallback path.
18+
// Any other code is a tool failure — normalize to 2.
4519
process.exit(exitCode <= 1 ? exitCode : 2)
4620
}
4721

48-
function runViaNpx() {
49-
if (process.env.CI) {
50-
console.error(
51-
`[Shakapacker] ${PACK_CONFIG_DIFF_PACKAGE} is not installed locally, and npx fallback requires an interactive prompt. ` +
52-
`Install ${PACK_CONFIG_DIFF_PACKAGE} locally before running in CI.`
53-
)
54-
process.exit(2)
55-
}
56-
57-
console.error(
58-
`[Shakapacker] ${PACK_CONFIG_DIFF_PACKAGE} is not installed locally. ` +
59-
"Falling back to npx and prompting before download."
60-
)
61-
const result = spawnSync("npx", [getNpxSpec(), ...process.argv.slice(2)], {
62-
stdio: "inherit"
63-
})
64-
65-
if (result.error) {
66-
console.error(
67-
`[Shakapacker] Failed to run ${PACK_CONFIG_DIFF_PACKAGE} via npx: ${formatError(result.error)}`
68-
)
69-
process.exit(2)
70-
}
71-
72-
if (result.signal || result.status == null) {
73-
process.exit(2)
74-
}
75-
76-
// Forward only pack-config-diff's documented exit codes (0 = no diffs, 1 = diffs found).
77-
// Any other code (e.g. 127 = npx not found, 126 = permission denied) is a tool failure.
78-
process.exit(result.status <= 1 ? result.status : 2)
79-
}
80-
8122
let run
8223

8324
try {
8425
const loadedModule = require("pack-config-diff")
8526
run = loadedModule.run
8627
} catch (error) {
87-
if (isMissingPackConfigDiff(error)) {
88-
runViaNpx()
89-
} else {
90-
console.error(
91-
`[Shakapacker] Failed to load ${PACK_CONFIG_DIFF_PACKAGE}: ${formatError(error)}`
92-
)
93-
process.exit(2)
94-
}
28+
console.error(
29+
`[Shakapacker] Failed to load ${PACK_CONFIG_DIFF_PACKAGE}: ${formatError(error)}`
30+
)
31+
process.exit(2)
9532
}
9633

9734
if (typeof run !== "function") {

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@
4444
},
4545
"dependencies": {
4646
"js-yaml": "^4.1.0",
47+
"pack-config-diff": "^0.1.0",
4748
"path-complete-extname": "^1.0.0",
4849
"webpack-merge": "^5.8.0",
4950
"yargs": "^17.7.2"
5051
},
51-
"optionalDependencies": {
52-
"pack-config-diff": "^0.1.0"
53-
},
5452
"devDependencies": {
5553
"@eslint/eslintrc": "^3.2.0",
5654
"@eslint/js": "^9.37.0",

0 commit comments

Comments
 (0)