Skip to content

Commit

Permalink
refactor: simplify Netlify Dev detectors env (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored Aug 2, 2020
1 parent dd7d90f commit 582e17f
Show file tree
Hide file tree
Showing 29 changed files with 6 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/commands/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ async function startDevServer(settings, log) {
throw err
})
const ps = child_process.spawn(commandBin, settings.args, {
env: { ...settings.env, FORCE_COLOR: 'true' },
env: { ...process.env, ...settings.env, FORCE_COLOR: 'true' },
stdio: 'pipe',
})

Expand Down
2 changes: 1 addition & 1 deletion src/detectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function() {
framework: 'gitbook',
command: getYarnOrNPMCommand(),
frameworkPort: 4000,
env: { ...process.env },
env: { NAME: 'value' },
possibleArgsArrs,
dist: 'public',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = function() {
framework: 'angular',
command: getYarnOrNPMCommand(),
frameworkPort: 4200,
env: { ...process.env },
possibleArgsArrs,
dist: 'dist',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/brunch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = function() {
framework: 'brunch',
command: getYarnOrNPMCommand(),
frameworkPort: 3333,
env: { ...process.env },
possibleArgsArrs,
dist: 'app/assets',
}
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/create-react-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function() {
framework: 'create-react-app',
command: getYarnOrNPMCommand(),
frameworkPort: 3000, // the port that create-react-app normally outputs
env: { ...process.env, BROWSER: 'none', PORT: 3000 },
env: { BROWSER: 'none', PORT: 3000 },
stdio: ['inherit', 'pipe', 'pipe'],
possibleArgsArrs,
dist: 'public',
Expand Down
1 change: 0 additions & 1 deletion src/detectors/docusaurus.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = function() {
framework: 'docusaurus',
command: getYarnOrNPMCommand(),
frameworkPort: 3000,
env: { ...process.env },
possibleArgsArrs,
dist: 'static',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = function() {
return {
framework: 'eleventy',
frameworkPort: 8080,
env: { ...process.env },
command: 'npx',
possibleArgsArrs: [['eleventy', '--serve', '--watch']],
dist: '_site',
Expand Down
1 change: 0 additions & 1 deletion src/detectors/ember.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = function() {
framework: 'ember',
command: getYarnOrNPMCommand(),
frameworkPort: 4200,
env: { ...process.env },
possibleArgsArrs,
dist: 'dist',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/expo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = function() {
framework: 'expo',
command: getYarnOrNPMCommand(),
frameworkPort: 19006,
env: { ...process.env },
possibleArgsArrs,
dist: 'web-build',
}
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/gatsby.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function() {
framework: 'gatsby',
command: getYarnOrNPMCommand(),
frameworkPort: 8000,
env: { ...process.env, GATSBY_LOGGER: 'yurnalist' },
env: { GATSBY_LOGGER: 'yurnalist' },
possibleArgsArrs,
dist: 'public',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/gridsome.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = function() {
framework: 'gridsome',
command: getYarnOrNPMCommand(),
frameworkPort: 8080,
env: { ...process.env },
possibleArgsArrs,
dist: 'dist',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/hexo.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = function() {
framework: 'hexo',
command: getYarnOrNPMCommand(),
frameworkPort: 4000,
env: { ...process.env },
possibleArgsArrs,
dist: 'public',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/hugo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = function() {
return {
framework: 'hugo',
frameworkPort: 1313,
env: { ...process.env },
command: 'hugo',
possibleArgsArrs: [['server', '-w']],
dist: 'public',
Expand Down
1 change: 0 additions & 1 deletion src/detectors/jekyll.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = function() {
return {
framework: 'jekyll',
frameworkPort: 4000,
env: { ...process.env },
command: 'bundle',
possibleArgsArrs: [['exec', 'jekyll', 'serve', '-w']],
dist: '_site',
Expand Down
1 change: 0 additions & 1 deletion src/detectors/middleman.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = function() {
return {
framework: 'middleman',
frameworkPort: 4567,
env: { ...process.env },
command: 'bundle',
possibleArgsArrs: [['exec', 'middleman', 'server']],
dist: 'build',
Expand Down
1 change: 0 additions & 1 deletion src/detectors/next.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = function() {
framework: 'next',
command: getYarnOrNPMCommand(),
frameworkPort: 3000,
env: { ...process.env },
possibleArgsArrs,
dist: 'out',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/nuxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = function() {
framework: 'nuxt',
command: getYarnOrNPMCommand(),
frameworkPort: 3000,
env: { ...process.env },
possibleArgsArrs,
dist: 'dist',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/parcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = function() {
framework: 'parcel',
command: getYarnOrNPMCommand(),
frameworkPort: 1234,
env: { ...process.env },
possibleArgsArrs,
dist: 'dist',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/phenomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = function() {
framework: 'phenomic',
command: getYarnOrNPMCommand(),
frameworkPort: 3333,
env: { ...process.env },
possibleArgsArrs,
dist: 'public',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/quasar-v0.17.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = function() {
framework: 'quasar-cli-v0.17',
command: getYarnOrNPMCommand(),
frameworkPort: 8080,
env: { ...process.env },
possibleArgsArrs,
dist: '.quasar',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/quasar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = function() {
framework: 'quasar',
command: getYarnOrNPMCommand(),
frameworkPort: 8081,
env: { ...process.env },
possibleArgsArrs,
dist: '.quasar',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/react-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = function() {
framework: 'react-static',
command: getYarnOrNPMCommand(),
frameworkPort: 3000,
env: { ...process.env },
possibleArgsArrs,
dist: 'dist',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/sapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = function() {
framework: 'sapper',
command: getYarnOrNPMCommand(),
frameworkPort: 3000,
env: { ...process.env },
possibleArgsArrs,
dist: 'static',
}
Expand Down
2 changes: 1 addition & 1 deletion src/detectors/stencil.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = function() {
framework: 'stencil',
command: getYarnOrNPMCommand(),
frameworkPort: 3333, // the port that stencil normally outputs
env: { ...process.env, BROWSER: 'none', PORT: 3000 },
env: { BROWSER: 'none', PORT: 3000 },
possibleArgsArrs,
dist: 'www',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = function() {
framework: 'svelte',
command: getYarnOrNPMCommand(),
frameworkPort: 5000,
env: { ...process.env },
possibleArgsArrs,
dist: 'public',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = function() {
framework: 'vue',
command: getYarnOrNPMCommand(),
frameworkPort: 8080,
env: { ...process.env },
possibleArgsArrs,
dist: 'dist',
}
Expand Down
1 change: 0 additions & 1 deletion src/detectors/vuepress.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module.exports = function() {
framework: 'vuepress',
command: getYarnOrNPMCommand(),
frameworkPort: 8080,
env: { ...process.env },
possibleArgsArrs,
dist: '.vuepress/dist',
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils/detect-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fuzzy = require('fuzzy')
const fs = require('fs')

module.exports.serverSettings = async (devConfig, flags, projectDir, log) => {
let settings = { env: { ...process.env } }
let settings = {}
const detectorsFiles = fs.readdirSync(path.join(__dirname, '..', 'detectors')).filter(x => x.endsWith('.js')) // only accept .js detector files

if (typeof devConfig.framework !== 'string') throw new Error('Invalid "framework" option provided in config')
Expand Down Expand Up @@ -180,7 +180,6 @@ async function getStaticServerSettings(settings, flags, projectDir, log) {
}
log(`${NETLIFYDEVWARN} Running static server from "${path.relative(path.dirname(projectDir), dist)}"`)
return {
env: { ...process.env },
noCmd: true,
frameworkPort: await getPort({ port: 3999 }),
dist,
Expand Down
8 changes: 0 additions & 8 deletions src/utils/detect-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ test('loadDetector: invalid', t => {
})

test('serverSettings: minimal config', async t => {
const env = { ...process.env }
const settings = await serverSettings({ framework: '#auto' }, {}, sitePath, () => {})
t.deepEqual(settings.env, env)
t.is(settings.framework, undefined)
})

Expand All @@ -37,33 +35,27 @@ test('serverSettings: throw if "port" not available', async t => {
})

test('serverSettings: "command" override npm', async t => {
const env = { ...process.env }
const devConfig = { framework: '#custom', command: 'npm run dev', targetPort: 1234 }
const settings = await serverSettings(devConfig, {}, sitePath, () => {})
t.is(settings.framework, devConfig.framework)
t.is(settings.command, devConfig.command.split(' ')[0])
t.deepEqual(settings.args, devConfig.command.split(' ').slice(1))
t.deepEqual(settings.env, env)
})

test('serverSettings: "command" override yarn', async t => {
const env = { ...process.env }
const devConfig = { framework: '#custom', command: 'yarn dev', targetPort: 1234 }
const settings = await serverSettings(devConfig, {}, sitePath, () => {})
t.is(settings.framework, devConfig.framework)
t.is(settings.command, devConfig.command.split(' ')[0])
t.deepEqual(settings.args, devConfig.command.split(' ').slice(1))
t.deepEqual(settings.env, env)
})

test('serverSettings: custom framework parameters', async t => {
const env = { ...process.env }
const devConfig = { framework: '#custom', command: 'yarn dev', targetPort: 3000, publish: sitePath }
const settings = await serverSettings(devConfig, {}, sitePath, () => {})
t.is(settings.framework, '#custom')
t.is(settings.command, devConfig.command.split(' ')[0])
t.deepEqual(settings.args, devConfig.command.split(' ').slice(1))
t.deepEqual(settings.env, env)
t.is(settings.targetPort, devConfig.frameworkPort)
t.is(settings.dist, devConfig.publish)
})
Expand Down

0 comments on commit 582e17f

Please sign in to comment.