Skip to content

fix: more robust static site detection #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions helpers/usesBuildCommand.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const parseNpmScript = require('@netlify/parse-npm-script')
// Does the build command include this value, either directly or via an npm script?
const usesBuildCommand = ({ build, scripts, command }) => {
if (!build.command) return false
Expand All @@ -6,10 +7,16 @@ const usesBuildCommand = ({ build, scripts, command }) => {
return true
}

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

module.exports = usesBuildCommand
Loading