Skip to content

Commit

Permalink
Add(Pack): --entry-names and suffix with .bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Jul 6, 2023
1 parent 445ead3 commit a47821d
Show file tree
Hide file tree
Showing 13 changed files with 729 additions and 9 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"esbuild": "^0.18.11",
"esbuild-plugin-d.ts": "^1.1.0",
"explore-config": "",
"fast-glob": "^3.2.12",
"fast-glob": "^3.3.0",
"lodash.isequal": "^4.5.0",
"npm": "^9.7.2",
"techor": "",
Expand Down
9 changes: 7 additions & 2 deletions packages/pack/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import path from 'upath'
import line, { l } from '@techor/one-liner'
import type { PackageJson } from 'pkg-types'
import prettyBytes from 'pretty-bytes'
import normalizePath from 'normalize-path'
import fs from 'fs'
import isEqual from 'lodash.isequal'
import { esbuildOptionNames } from '../utils/esbuild-option-names'
Expand Down Expand Up @@ -45,6 +44,7 @@ program.command('pack [entryPaths...]', { isDefault: true })
.option('--srcdir <dir>', 'The source directory', 'src')
.option('--target [targets...]', 'This sets the target environment for the generated JavaScript and/or CSS code.')
.option('--mangle-props <regExp>', 'Pass a regular expression to esbuild to tell esbuild to automatically rename all properties that match this regular expression')
.option('--entry-names <[dir]/[name]>', 'Pass a regular expression to esbuild to tell esbuild to automatically rename all properties that match this regular expression')
.option('--no-declare', 'OFF: Emit typescript declarations', !!pkg.types)
.option('--no-minify', 'OFF: Minify the generated code')
.option('--no-clean', 'OFF: Clean up the previous output directory before the build starts')
Expand All @@ -61,8 +61,9 @@ program.command('pack [entryPaths...]', { isDefault: true })
const useConfig = exploreConfig('techor.*')
const buildTasks: BuildTask[] = []
const exploreEntries = (eachEntries: string[]) => {
console.log(process.cwd())
return fg.sync(
[...new Set(eachEntries)].map((eachEntry) => normalizePath(eachEntry))
[...new Set(eachEntries)].map((eachEntry) => path.normalize(eachEntry))
)
}
const exploreMapptedEntry = (filePath: string, targetExt: string) => {
Expand Down Expand Up @@ -99,6 +100,9 @@ program.command('pack [entryPaths...]', { isDefault: true })
if (eachOptions.outdir) eachOptions.outdir = path.normalize(eachOptions.outdir)
if (eachOptions.bundle === undefined) eachOptions.bundle = options.bundle
if (eachOptions.outfile) {
if (eachOptions.bundle) {
eachOptions.outfile = eachOptions.outfile.replace('.bundle', '')
}
eachOptions.outfile = path.normalize(eachOptions.outfile)
if (outputFilePaths.includes(eachOptions.outfile)) {
return
Expand Down Expand Up @@ -138,6 +142,7 @@ program.command('pack [entryPaths...]', { isDefault: true })
platform: eachOptions.platform || options.platform,
metafile: true,
bundle: eachOptions.bundle,
entryNames: options.entryNames ? options.entryNames : (eachOptions.bundle ? '[dir]/[name].bundle' : '[dir]/[name]'),
format: eachOptions.format,
keepNames: options.keepNames,
resolveExtensions: options.resolveExtensions,
Expand Down
2 changes: 1 addition & 1 deletion packages/pack/tests/args-externals/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expectFileIncludes } from '../../../../utils/expect-file-includes'

test('prevent bundling external packages by args', () => {
execSync('tsx ../../src/bin pack --external @master/css @master/style-element.react --bundle', { cwd: __dirname, stdio: 'inherit' })
expectFileIncludes('dist/index.js', [
expectFileIncludes('dist/index.bundle.js', [
'require("@master/css")',
'require("@master/style-element.react")'
], { cwd: __dirname })
Expand Down
Loading

0 comments on commit a47821d

Please sign in to comment.