Comparing version 1.4.0 to 1.5.1
@@ -15,2 +15,5 @@ #!/usr/bin/env node | ||
.option("-f, --format <format>", "specify output file format") | ||
.option("-m, --minify", "compress output") | ||
.option("--cwd <cwd>", "specify current working directory") | ||
.option("--no-sourcemap", "disable sourcemap") | ||
.action(run); | ||
@@ -20,7 +23,7 @@ program.parse(process.argv); | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
var format, file, bin, watch, outputConfig, entry, module, bunchee, e_1; | ||
var format, file, watch, minify, cwd, sourcemap, outputConfig, entry, module, bunchee, e_1; | ||
return tslib.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
format = program.format, file = program.output, bin = program.bin, watch = program.watch; | ||
format = program.format, file = program.output, watch = program.watch, minify = program.minify, cwd = program.cwd, sourcemap = program.sourcemap; | ||
outputConfig = { | ||
@@ -30,3 +33,4 @@ file: file, | ||
watch: !!watch, | ||
shebang: !!bin, | ||
minify: !!minify, | ||
sourcemap: sourcemap === false ? false : true, | ||
}; | ||
@@ -36,3 +40,3 @@ if (typeof entryFilePath !== "string") { | ||
} | ||
entry = path.resolve(process.cwd(), entryFilePath); | ||
entry = path.resolve(cwd || process.cwd(), entryFilePath); | ||
if (!fs.existsSync(entry)) { | ||
@@ -39,0 +43,0 @@ return [2, help()]; |
@@ -5,3 +5,4 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var rollup = require('rollup'); | ||
var fs = _interopDefault(require('fs')); | ||
var fs = require('fs'); | ||
var fs__default = _interopDefault(fs); | ||
var path = require('path'); | ||
@@ -15,2 +16,3 @@ var path__default = _interopDefault(path); | ||
var typescript = _interopDefault(require('@rollup/plugin-typescript')); | ||
var rollupPluginTerser = require('rollup-plugin-terser'); | ||
@@ -22,2 +24,3 @@ var rootDir = process.cwd(); | ||
var Module = require("module").Module; | ||
var mainFieldsConfig = [ | ||
@@ -33,3 +36,2 @@ { | ||
]; | ||
var Module = require("module").Module; | ||
function resolveTypescript() { | ||
@@ -47,8 +49,14 @@ var ts; | ||
} | ||
function createInputConfig(entry, npmPackage, options) { | ||
var externals = [npmPackage.peerDependencies, npmPackage.dependencies] | ||
function getDistPath(pkg, filed) { | ||
if (filed === void 0) { filed = 'main'; } | ||
return pkg[filed] || 'dist/index.js'; | ||
} | ||
function createInputConfig(entry, pkg, options) { | ||
var externals = [pkg.peerDependencies, pkg.dependencies] | ||
.filter(function (n) { return Boolean(n); }) | ||
.map(function (o) { return Object.keys(o); }) | ||
.reduce(function (a, b) { return a.concat(b); }, []); | ||
var useTypescript = options.useTypescript; | ||
var useTypescript = options.useTypescript, _a = options.minify, minify = _a === void 0 ? false : _a; | ||
var typings = pkg.types || pkg.typings; | ||
var cwd = config.rootDir; | ||
var plugins = [ | ||
@@ -63,8 +71,8 @@ nodeResolve({ | ||
shebang(), | ||
useTypescript && typescript({ | ||
tsconfig: path.resolve(config.rootDir, "tsconfig.json"), | ||
typescript: require("typescript"), | ||
module: "ES6", | ||
target: "ES5", | ||
}), | ||
useTypescript && typescript(tslib.__assign({ tsconfig: (function () { | ||
var tsconfig = path.resolve(cwd, "tsconfig.json"); | ||
return fs.existsSync(tsconfig) ? tsconfig : undefined; | ||
})(), typescript: resolveTypescript(), noEmitHelpers: false, importHelpers: false, module: "ES6", target: "ES5", sourceMap: options.sourcemap, declaration: !!typings }, (!!typings && { | ||
declarationDir: path.dirname(path.resolve(cwd, typings)), | ||
}))), | ||
!useTypescript && babel({ | ||
@@ -78,3 +86,13 @@ babelHelpers: "bundled", | ||
], | ||
}) | ||
}), | ||
minify && rollupPluginTerser.terser({ | ||
compress: { | ||
"keep_infinity": true, | ||
}, | ||
format: { | ||
"comments": /^\s*([@#]__[A-Z]__\s*$|@[a-zA-Z]\s*$)/, | ||
"wrap_func_args": false, | ||
"preserve_annotations": true, | ||
} | ||
}), | ||
].filter(function (n) { return Boolean(n); }); | ||
@@ -87,9 +105,10 @@ return { | ||
} | ||
function createOutputOptions(options, npmPackage) { | ||
var file = options.file, format = options.format, useTypescript = options.useTypescript; | ||
function createOutputOptions(options, pkg) { | ||
var format = options.format, useTypescript = options.useTypescript; | ||
var cwd = config.rootDir; | ||
var tsconfigOptions = {}; | ||
var ts = resolveTypescript(); | ||
var tsconfigPath = path.resolve(config.rootDir, "tsconfig.json"); | ||
if (useTypescript) { | ||
if (fs.existsSync(tsconfigPath)) { | ||
var ts = resolveTypescript(); | ||
var tsconfigPath = path.resolve(cwd, "tsconfig.json"); | ||
if (fs__default.existsSync(tsconfigPath)) { | ||
var tsconfigJSON = ts.readConfigFile(tsconfigPath, ts.sys.readFile) | ||
@@ -101,39 +120,35 @@ .config; | ||
var useEsModuleMark = !!tsconfigOptions.esModuleInterop || | ||
(npmPackage.hasOwnProperty("main") && | ||
npmPackage.hasOwnProperty("module")); | ||
(pkg.hasOwnProperty("main") && | ||
pkg.hasOwnProperty("module")); | ||
var file = path.resolve(options.file); | ||
return { | ||
name: npmPackage.name, | ||
file: file, | ||
name: pkg.name, | ||
dir: path.dirname(file), | ||
entryFileNames: path.basename(file), | ||
format: format, | ||
esModule: !useEsModuleMark && format !== "umd", | ||
esModule: useEsModuleMark && format !== "umd", | ||
freeze: false, | ||
strict: false, | ||
sourcemap: true, | ||
sourcemap: options.sourcemap, | ||
}; | ||
} | ||
function createRollupConfig(entry, npmPackage, cliArgs) { | ||
var file = cliArgs.file, _a = cliArgs.format, format = _a === void 0 ? "esm" : _a; | ||
function createRollupConfig(entry, pkg, cliArgs) { | ||
var file = cliArgs.file, format = cliArgs.format; | ||
var ext = path.extname(entry); | ||
var useTypescript = ext === ".ts" || ext === ".tsx"; | ||
var options = tslib.__assign(tslib.__assign({}, cliArgs), { useTypescript: useTypescript }); | ||
var inputOptions = createInputConfig(entry, npmPackage, options); | ||
var inputOptions = createInputConfig(entry, pkg, options); | ||
var outputConfigs = mainFieldsConfig | ||
.filter(function (config) { | ||
return Boolean(npmPackage[config.field]); | ||
return Boolean(pkg[config.field]); | ||
}) | ||
.map(function (config) { | ||
var filename = npmPackage[config.field]; | ||
return createOutputOptions({ | ||
file: filename, | ||
format: config.format, | ||
useTypescript: useTypescript, | ||
}, npmPackage); | ||
var filename = getDistPath(pkg, config.field); | ||
return createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), { file: filename, format: config.format, useTypescript: useTypescript }), pkg); | ||
}); | ||
if (file) { | ||
outputConfigs = [ | ||
createOutputOptions({ | ||
file: file, | ||
createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), { file: file, | ||
format: format, | ||
useTypescript: useTypescript, | ||
}, npmPackage) | ||
useTypescript: useTypescript }), pkg) | ||
]; | ||
@@ -159,3 +174,3 @@ } | ||
} | ||
var name = targetPackageJson.name, main = targetPackageJson.main, module = targetPackageJson.module, dependencies = targetPackageJson.dependencies, peerDependencies = targetPackageJson.peerDependencies; | ||
var name = targetPackageJson.name, main = targetPackageJson.main, module = targetPackageJson.module, dependencies = targetPackageJson.dependencies, peerDependencies = targetPackageJson.peerDependencies, types = targetPackageJson.types, typings = targetPackageJson.typings; | ||
return { | ||
@@ -167,2 +182,4 @@ name: name, | ||
peerDependencies: peerDependencies, | ||
types: types, | ||
typings: typings, | ||
}; | ||
@@ -178,5 +195,13 @@ } | ||
function assignDefault(options, name, defaultValue) { | ||
if (!(name in options) || options[name] == null) { | ||
options[name] = defaultValue; | ||
} | ||
} | ||
function bundle(entry, _a) { | ||
if (_a === void 0) { _a = {}; } | ||
var watch = _a.watch, options = tslib.__rest(_a, ["watch"]); | ||
var watch = _a.watch, cwd = _a.cwd, options = tslib.__rest(_a, ["watch", "cwd"]); | ||
config.rootDir = cwd || config.rootDir; | ||
assignDefault(options, "format", "esm"); | ||
assignDefault(options, "sourcemap", true); | ||
var npmPackage = utils.getPackageMeta(); | ||
@@ -183,0 +208,0 @@ var rollupConfig = createRollupConfig(entry, npmPackage, options); |
{ | ||
"name": "bunchee", | ||
"version": "1.4.0", | ||
"version": "1.5.1", | ||
"description": "zero config bundler for js/ts/jsx libraries", | ||
@@ -9,6 +9,7 @@ "bin": { | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"test": "jest", | ||
"clean": "rm -rf ./dist", | ||
"prerelease": "yarn clean && yarn build && chmod +x dist/cli.js", | ||
"prepublishOnly": "yarn clean && yarn build && chmod +x dist/cli.js", | ||
"build:cli": "ts-node src/cli.ts src/cli.ts -f cjs -o dist/cli.js", | ||
@@ -37,3 +38,3 @@ "build:main": "ts-node src/cli.ts src/index.ts -f cjs", | ||
"@rollup/plugin-node-resolve": "8.1.0", | ||
"@rollup/plugin-typescript": "3.1.1", | ||
"@rollup/plugin-typescript": "8.2.0", | ||
"babel-preset-o": "0.2.1", | ||
@@ -44,2 +45,3 @@ "commander": "2.20.3", | ||
"rollup-plugin-preserve-shebang": "1.0.1", | ||
"rollup-plugin-terser": "7.0.2", | ||
"tslib": "2.0.0", | ||
@@ -52,2 +54,3 @@ "typescript": "^3.9.6" | ||
"devDependencies": { | ||
"@types/node": "14.14.32", | ||
"jest": "26.6.1", | ||
@@ -54,0 +57,0 @@ "ts-node": "9.1.1" |
@@ -29,5 +29,8 @@ # bunchee | ||
-w, --watch watch src files changes | ||
-m, --minify compress output. false by default | ||
-o, --output <file> specify output filename | ||
-f, --format <format> specify bundle type. esm, cjs, umd. default is esm | ||
-f, --format <format> specify bundle type. esm, cjs, umd. "esm" by default | ||
-h, --help output usage information | ||
--no-sourcemap disable sourcemap generation, sourcemap generation is enabled by default | ||
--cwd <cwd> specify current working directory | ||
@@ -41,3 +44,3 @@ Usage: | ||
Declare your main field and module field in package.json, then call bunchee cli in build scripts | ||
Declare your main field and module field in package.json, then call bunchee cli in build scripts. If you're using typescript, types will be generated automatically based on your package.json field `typings` or `types`. | ||
@@ -50,3 +53,4 @@ ```json | ||
"build": "bunchee ./src/index.js" | ||
} | ||
}, | ||
"types": "dist/index.d.ts" | ||
} | ||
@@ -65,1 +69,5 @@ ``` | ||
``` | ||
### Using Typescript | ||
This plugin requires at least [TypeScript 3.7](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14
339
70
24189
13
3
+ Addedrollup-plugin-terser@7.0.2
+ Added@jridgewell/source-map@0.3.6(transitive)
+ Added@rollup/plugin-typescript@8.2.0(transitive)
+ Addedacorn@8.14.0(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedjest-worker@26.6.2(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedrollup@2.79.2(transitive)
+ Addedrollup-plugin-terser@7.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedserialize-javascript@4.0.0(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedsource-map-support@0.5.21(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedterser@5.36.0(transitive)
- Removed@rollup/plugin-typescript@3.1.1(transitive)