Skip to content

Commit

Permalink
fix(command-dev): pass framework-info env to sub process
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Aug 17, 2021
1 parent c796c8e commit 637de69
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
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 = {},
} = framework

return {
Expand Down
20 changes: 20 additions & 0 deletions tests/framework-detection.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { platform } = require('process')

const test = require('ava')
const execa = require('execa')

Expand Down Expand Up @@ -283,3 +285,21 @@ test('should filter frameworks with no dev command', async (t) => {
})
})
})

test.only('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: platform === 'win32' ? 'echo %GATSBY_LOGGER%' : 'echo $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␊
> echo $GATSBY_LOGGER␊
yurnalist␊
◈ "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.

0 comments on commit 637de69

Please sign in to comment.