Skip to content

Commit

Permalink
chore(tools): update extension conversion logic in build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Oct 5, 2021
1 parent 6952c62 commit d12d950
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintrc.base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module.exports = {
'extensionless',
'fixme',
'loadenv',
'mjs',
'nullable',
'nullish',
'perf',
Expand Down
14 changes: 10 additions & 4 deletions tools/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { hideBin } from 'yargs/helpers'
import exec from '../helpers/exec'
import fixNodeModulePaths from '../helpers/fix-node-module-paths'
import pkg, { $workspace } from '../helpers/pkg'
// @ts-expect-error ts(2307)
import useDualExports from '../helpers/use-dual-exports.mjs'

/**
Expand Down Expand Up @@ -195,11 +196,16 @@ async function build(): Promise<void> {
logger(argv, `build ${format}`)
}

// Get module extension
const ext = `${format === 'esm' ? 'm' : 'c'}js`
// Convert TypeScript output to .cjs or .mjs
// See: https://github.com/peterjwest/convert-extension
if (format !== 'types') {
// Get output extension
const ext = `${format === 'cjs' ? 'c' : 'm'}js`

// Convert extensions
await convertExtension(`${format}/`, 'js', ext, { minified: true })
// Convert extensions
!argv.dryRun && (await convertExtension(`${format}/`, 'js', ext))
logger(argv, `use .${ext} extensions`)
}
}

// Fix node module import paths
Expand Down

0 comments on commit d12d950

Please sign in to comment.