Skip to content

Commit 41184bc

Browse files
authored
fix: catch more export cases (#529)
1 parent c43f518 commit 41184bc

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

helpers/usesBuildCommand.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
const parseNpmScript = require('@netlify/parse-npm-script')
2+
3+
const COMMAND_PLACEHOLDER = '___netlifybuildcommand'
4+
25
// Does the build command include this value, either directly or via an npm script?
36
const usesBuildCommand = ({ build, scripts, command }) => {
47
if (!build.command) return false
@@ -10,12 +13,23 @@ const usesBuildCommand = ({ build, scripts, command }) => {
1013
if (!build.command.includes('npm run') && !build.command.includes('yarn')) {
1114
return false
1215
}
16+
17+
// Insert a fake script to represent the build command
18+
19+
const commands = { ...scripts, [COMMAND_PLACEHOLDER]: build.command }
20+
1321
// This resolves the npm script that is actually being run
1422
try {
15-
const { raw } = parseNpmScript({ scripts }, build.command)
23+
const { raw } = parseNpmScript({ scripts: commands }, COMMAND_PLACEHOLDER)
1624
return raw.some((script) => script.includes(command))
1725
} catch (error) {
18-
console.error('There was an error parsing your build command', error)
26+
console.error(
27+
'There was an error parsing your build command:',
28+
error.message,
29+
`\n\nThe build command is "${build.command}" and the available npm scripts are: ${Object.keys(scripts)
30+
.map((script) => `"${script}"`)
31+
.join(', ')}`,
32+
)
1933
}
2034
}
2135

test/fixtures/not-static.json

+7
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,12 @@
5353
"build:types": "tsc",
5454
"build": "run-p build:types"
5555
}
56+
},
57+
{
58+
"command": "npm run build && npm run export",
59+
"scripts": {
60+
"export": "echo export",
61+
"build": "next build"
62+
}
5663
}
5764
]

test/fixtures/static.json

+13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
"build": "npm run build:export"
1313
}
1414
},
15+
{
16+
"command": "npm run build && npm run export",
17+
"scripts": {
18+
"export": "next export",
19+
"build": "next build"
20+
}
21+
},
22+
{
23+
"command": "npm run build && next export",
24+
"scripts": {
25+
"build": "next build"
26+
}
27+
},
1528
{
1629
"command": "npm run build",
1730
"scripts": {

0 commit comments

Comments
 (0)