Skip to content

Commit 8fb953f

Browse files
committed
fix: more robust static site detection
1 parent 6778619 commit 8fb953f

File tree

7 files changed

+21606
-41706
lines changed

7 files changed

+21606
-41706
lines changed

helpers/isStaticExportProject.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const usesBuildCommand = require('./usesBuildCommand')
66
const isStaticExportProject = ({ build, scripts }) => {
77
const NEXT_EXPORT_COMMAND = 'next export'
88

9-
const isStaticExport = usesBuildCommand({ build, scripts, command: NEXT_EXPORT_COMMAND })
9+
const isStaticExport =
10+
usesBuildCommand({ build, scripts, command: NEXT_EXPORT_COMMAND }) ||
11+
(process.env.NEXT_IS_STATIC_EXPORT && process.env.NEXT_IS_STATIC_EXPORT !== 'false')
1012

1113
if (isStaticExport) {
1214
console.log(

helpers/usesBuildCommand.js

+8-4
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,13 @@ 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+
const { raw } = parseNpmScript({ scripts }, build.command)
15+
16+
return raw.some((script) => script.includes(command))
1317
}
1418

1519
module.exports = usesBuildCommand

0 commit comments

Comments
 (0)