feat(cli): use cjs dist stub in package (#4243)

* feat: use cjs dist stub for cli package

* fix: spawn nuxtBin directly

* keep node -r esm for optimal windows compatibility
This commit is contained in:
Pim 2018-11-01 05:00:28 +01:00 committed by Sébastien Chopin
parent 78e3563687
commit 90325c35ae
2 changed files with 22 additions and 2 deletions

View File

@ -5,6 +5,26 @@ import consola from 'consola'
import Package from './package.js'
const useCjs = new Set([
'@nuxt/cli'
])
const stub = {
es: `export * from '../src/index'`,
cjs: `const esm = require('esm')
const _require = esm(module, {
cache: false,
cjs: {
cache: true,
vars: true,
namedExports: true
}
})
module.exports = _require('../src/index')
`}
async function main() {
// Read package at current directory
const rootPackage = new Package()
@ -18,7 +38,7 @@ async function main() {
consola.info(pkg.pkg.main)
const distMain = pkg.resolvePath(pkg.pkg.main)
await fs.mkdirp(path.dirname(distMain))
await fs.writeFile(distMain, `export * from '../src/index'`)
await fs.writeFile(distMain, useCjs.has(pkg.pkg.name) ? stub.cjs : stub.es)
}
}

View File

@ -9,7 +9,7 @@ const rootDir = resolve(__dirname, '..', 'fixtures/cli')
const url = route => 'http://localhost:' + port + route
const nuxtBin = resolve(__dirname, '../../packages/cli/bin/nuxt.js')
const spawnNuxt = (command, opts) => spawn('node', ['-r', 'esm', nuxtBin, command, rootDir], opts)
const spawnNuxt = (command, opts) => spawn(nuxtBin, [command, rootDir], opts)
const close = async (nuxtInt) => {
nuxtInt.kill('SIGKILL')