mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 22:55:13 +00:00
dec8f99fc3
Co-authored-by: Clark Du <clark.duxin@gmail.com>
40 lines
988 B
JavaScript
Executable File
40 lines
988 B
JavaScript
Executable File
import path from 'path'
|
|
import fs from 'fs-extra'
|
|
import consola from 'consola'
|
|
|
|
import Package from './package.js'
|
|
|
|
const useCjs = [
|
|
'@nuxt/cli'
|
|
]
|
|
|
|
const stub = {
|
|
es: 'export * from \'../src/index\'',
|
|
cjs: `const _require = typeof jest === 'undefined' ? require('jiti')(__dirname) : require
|
|
global.__NUXT_DEV__ = true
|
|
module.exports = _require('../src/index')
|
|
`
|
|
}
|
|
|
|
async function main () {
|
|
// Read package at current directory
|
|
const rootPackage = new Package()
|
|
const workspacePackages = await rootPackage.getWorkspacePackages()
|
|
|
|
// Create a dev-only entrypoint to the src
|
|
for (const pkg of workspacePackages) {
|
|
if (!pkg.pkg.main || !pkg.options.build) {
|
|
continue
|
|
}
|
|
consola.info(pkg.pkg.main)
|
|
const distMain = pkg.resolvePath(pkg.pkg.main)
|
|
await fs.mkdirp(path.dirname(distMain))
|
|
await fs.writeFile(distMain, useCjs.includes(pkg.pkg.name) ? stub.cjs : stub.es)
|
|
}
|
|
}
|
|
|
|
main().catch((error) => {
|
|
consola.error(error)
|
|
process.exit(1)
|
|
})
|