Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: require is not defined in ES module scope
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Oct 13, 2021
1 parent 5feef12 commit 66cdf96
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tools/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async function build(): Promise<void> {
clean: { outDir: argv.clean || undefined }
}

// Build project
// Build project (type checking not available)
!dryRun && tsc.build(options)
!dryRun && format === 'cjs' && useDualExports(`./${format}/**`)
dryRun && logger(argv, `build ${format}`)
Expand All @@ -242,23 +242,19 @@ async function build(): Promise<void> {
to: `${format === 'cjs' ? 'c' : 'm'}js`
}

// Convert TypeScript output to .cjs or .mjs
!dryRun && (await trext<'js' | 'cjs' | 'mjs'>(`${format}/`, trext_opts))
logger(argv, `use .${trext_opts.to} extensions`)

// Create bundles
// Create bundles (type checking enabled)
// See: https://github.com/vercel/ncc
const BUNDLES = [$WNS, `${$WNS}.min`].map(async name => {
const bundle = `${format}/${name}.${trext_opts.to}`
const filename = `${format}/index.${trext_opts.to}`
const minify = path.extname(name) === '.min'
// ! Bundle source code to enable type checking
const filename = 'src/index.ts'

if (!dryRun) {
const { code } = await ncc(`${CWD}/${filename}`, {
esm: format === 'esm',
externals: Object.keys($PACKAGE?.peerDependencies ?? {}),
filename,
minify: minify,
minify: path.extname(name) === '.min',
production: env === 'production',
quiet: true,
target: options.compilerOptions?.target
Expand All @@ -267,9 +263,9 @@ async function build(): Promise<void> {
await fs.writeFile(bundle, code, { flag: 'wx+' })
await fs.copyFile(`${format}/index.d.ts`, `${format}/${name}.d.ts`)
await replace.replaceInFile({
files: bundle,
from: ';// CONCATENATED MODULE: ./src/',
to: ';// CONCATENATED MODULE: ../src/'
files: format,
from: '// CONCATENATED MODULE: .src/',
to: '// CONCATENATED MODULE: ../src/'
})
}

Expand All @@ -278,6 +274,10 @@ async function build(): Promise<void> {

// Complete bundle promises
logger(argv, `bundle ${format}`, await Promise.all(BUNDLES))

// Convert TypeScript output to .cjs or .mjs
!dryRun && (await trext<'js' | 'cjs' | 'mjs'>(`${format}/`, trext_opts))
logger(argv, `use .${trext_opts.to} extensions`)
}
}

Expand Down

0 comments on commit 66cdf96

Please sign in to comment.