mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
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:
parent
78e3563687
commit
90325c35ae
22
scripts/dev
22
scripts/dev
@ -5,6 +5,26 @@ import consola from 'consola'
|
|||||||
|
|
||||||
import Package from './package.js'
|
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() {
|
async function main() {
|
||||||
// Read package at current directory
|
// Read package at current directory
|
||||||
const rootPackage = new Package()
|
const rootPackage = new Package()
|
||||||
@ -18,7 +38,7 @@ async function main() {
|
|||||||
consola.info(pkg.pkg.main)
|
consola.info(pkg.pkg.main)
|
||||||
const distMain = pkg.resolvePath(pkg.pkg.main)
|
const distMain = pkg.resolvePath(pkg.pkg.main)
|
||||||
await fs.mkdirp(path.dirname(distMain))
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ const rootDir = resolve(__dirname, '..', 'fixtures/cli')
|
|||||||
const url = route => 'http://localhost:' + port + route
|
const url = route => 'http://localhost:' + port + route
|
||||||
|
|
||||||
const nuxtBin = resolve(__dirname, '../../packages/cli/bin/nuxt.js')
|
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) => {
|
const close = async (nuxtInt) => {
|
||||||
nuxtInt.kill('SIGKILL')
|
nuxtInt.kill('SIGKILL')
|
||||||
|
Loading…
Reference in New Issue
Block a user