Skip to content
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

fix(command-dev): pass framework-info env to sub process #3194

Merged
merged 7 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const startFrameworkServer = async function ({ settings, exit }) {
log(`${NETLIFYDEVLOG} Starting Netlify Dev with ${settings.framework || 'custom config'}`)

// we use reject=false to avoid rejecting synchronously when the command doesn't exist
const frameworkProcess = execa.command(settings.command, { preferLocal: true, reject: false })
const frameworkProcess = execa.command(settings.command, { preferLocal: true, reject: false, env: settings.env })
frameworkProcess.stdout.pipe(stripAnsiCc.stream()).pipe(process.stdout)
frameworkProcess.stderr.pipe(stripAnsiCc.stream()).pipe(process.stderr)
process.stdin.pipe(frameworkProcess.stdin)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/detect-server-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const getSettingsFromFramework = (framework) => {
},
name: frameworkName,
staticAssetsDirectory: staticDir,
env,
env = {},
erezrokah marked this conversation as resolved.
Show resolved Hide resolved
} = framework

return {
Expand Down
18 changes: 18 additions & 0 deletions tests/framework-detection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,21 @@ test('should filter frameworks with no dev command', async (t) => {
})
})
})

test('should pass framework-info env to framework sub process', async (t) => {
await withSiteBuilder('site-with-gatsby', async (builder) => {
await builder
.withPackageJson({
packageJson: {
dependencies: { gatsby: '^3.0.0' },
scripts: { develop: 'node -p process.env.GATSBY_LOGGER' },
},
})
.withContentFile({ path: 'gatsby-config.js', content: '' })
.buildAsync()

// a failure is expected since this is not a true Gatsby project
const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true))
t.snapshot(normalize(error.stdout))
})
})
13 changes: 13 additions & 0 deletions tests/snapshots/framework-detection.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,16 @@ Generated by [AVA](https://avajs.dev).
└──────────────────────────────────────────────────┘␊
`

## should pass framework-info env to framework sub process

> Snapshot 1

`◈ Netlify Dev ◈␊
◈ Starting Netlify Dev with Gatsby␊
> develop␊
> node -p process.env.GATSBY_LOGGER␊
yurnalist␊
erezrokah marked this conversation as resolved.
Show resolved Hide resolved
◈ "npm run develop" exited with code *. Shutting down Netlify Dev server`
Binary file modified tests/snapshots/framework-detection.test.js.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/utils/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const normalizers = [
// normalize exit code from different OSes
{ pattern: /code \d+/, value: 'code *' },
// this is specific to npm v6
{ pattern: /@ start.+\/.+netlify-cli-tests-v10.+/, value: 'start' },
{ pattern: /@ (\w+?) .+\/.+netlify-cli-tests-v10.+/, value: '$1' },
{ pattern: /It should be one of.+/gm, value: 'It should be one of: *' },
]

Expand Down