10000 fix: more robust static site detection (#505) · opennextjs/opennextjs-netlify@b1fd513 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1fd513

Browse files
authored
fix: more robust static site detection (#505)
* fix: more robust static site detection * fix: fix tests * fix: package lock fixes * fix: remove env var
1 parent bc7695d commit b1fd513

File tree

6 files changed

+10609
-175
lines changed

6 files changed

+10609
-175
lines changed

helpers/usesBuildCommand.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const parseNpmScript = require('@netlify/parse-npm-script')
12
// Does the build command include this value, either directly or via an npm script?
23
const usesBuildCommand = ({ build, scripts, command }) => {
34
if (!build.command) return false
@@ -6,10 +7,16 @@ const usesBuildCommand = ({ build, scripts, command }) => {
67
return true
78
}
89

9-
return Object.entries(scripts).some(
10-
// Search for a npm script that is being called by the build command, and includes the searched-for command
11-
([scriptName, scriptValue]) => build.command.includes(scriptName) && scriptValue.includes(command),
12-
)
10+
if (!build.command.includes('npm run') && !build.command.includes('yarn')) {
11+
return false
12+
}
13+
// This resolves the npm script that is actually being run
14+
try {
15+
const { raw } = parseNpmScript({ scripts }, build.command)
16+
return raw.some((script) => script.includes(command))
17+
} catch (error) {
18+
console.error('There was an error parsing your build command', error)
19+
}
1320
}
1421

1522
module.exports = usesBuildCommand

0 commit comments

Comments
 (0)
0