Comparing version 1.5.4 to 1.6.0
128
dist/cli.js
@@ -7,22 +7,61 @@ #!/usr/bin/env node | ||
var path = _interopDefault(require('path')); | ||
var program = _interopDefault(require('commander')); | ||
var arg = _interopDefault(require('arg')); | ||
program | ||
.name("bunchee") | ||
.version(require('../package.json').version, "-v, --version") | ||
.option("-w, --watch", "watch src files changes") | ||
.option("-o, --output <file>", "specify output filename") | ||
.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); | ||
program.parse(process.argv); | ||
function run(entryFilePath) { | ||
var rootDir = process.cwd(); | ||
function parseCliArgs(argv) { | ||
var args; | ||
args = arg({ | ||
"--cwd": String, | ||
"--output": String, | ||
"--format": String, | ||
"--watch": Boolean, | ||
"--minify": Boolean, | ||
"--help": Boolean, | ||
"--version": Boolean, | ||
"--target": String, | ||
"--no-sourcemap": Boolean, | ||
"-h": "--help", | ||
"-v": "--version", | ||
"-w": "--watch", | ||
"-o": "--output", | ||
"-f": "--format", | ||
"-m": "--minify", | ||
}, { | ||
permissive: true, | ||
argv: argv | ||
}); | ||
var source = args._[0]; | ||
var parsedArgs = { | ||
source: source, | ||
format: args["--format"], | ||
file: args["--output"], | ||
watch: args["--watch"], | ||
minify: args["--minify"], | ||
sourcemap: args["--no-sourcemap"] !== true, | ||
cwd: args["--cwd"], | ||
help: args["--help"], | ||
version: args["--version"], | ||
target: args["--target"], | ||
}; | ||
return parsedArgs; | ||
} | ||
var version = "1.6.0"; | ||
var helpMessage = "\nUsage: bunchee [options]\n\nOptions:\n -v, --version output the version number\n -w, --watch watch src files changes\n -m, --minify compress output. false by default\n -o, --output <file> specify output filename\n -f, --format <format> specify bundle type: \"esm\", \"cjs\", \"umd\". \"esm\" by default\n --target <target> build environment, use \"node\" for nodejs runtime\n --no-sourcemap disable sourcemap generation, sourcemap generation is enabled by default\n --cwd <cwd> specify current working directory\n -h, --help output usage information\n"; | ||
function help() { | ||
console.log(helpMessage); | ||
} | ||
function exit(error) { | ||
console.error(error); | ||
process.exit(2); | ||
} | ||
function run(args) { | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
var format, file, watch, minify, cwd, sourcemap, outputConfig, entry, module, bunchee, e_1; | ||
var source, format, file, watch, minify, cwd, sourcemap, target, outputConfig, entry, err, bundle; | ||
return tslib.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
format = program.format, file = program.output, watch = program.watch, minify = program.minify, cwd = program.cwd, sourcemap = program.sourcemap; | ||
source = args.source, format = args.format, file = args.file, watch = args.watch, minify = args.minify, cwd = args.cwd, sourcemap = args.sourcemap, target = args.target; | ||
outputConfig = { | ||
@@ -32,28 +71,47 @@ file: file, | ||
cwd: cwd, | ||
watch: !!watch, | ||
target: target, | ||
watch: watch, | ||
minify: !!minify, | ||
sourcemap: sourcemap === false ? false : true, | ||
}; | ||
if (typeof entryFilePath !== "string") { | ||
return [2, help()]; | ||
if (args.version) { | ||
return [2, console.log(version)]; | ||
} | ||
entry = path.resolve(cwd || process.cwd(), entryFilePath); | ||
if (!fs.existsSync(entry)) { | ||
if (args.help || !source) { | ||
return [2, help()]; | ||
} | ||
module = require('.'); | ||
bunchee = module.default ? module.default : module; | ||
_a.label = 1; | ||
entry = path.resolve(cwd || process.cwd(), source); | ||
if (!fs.existsSync(entry) || !fs.statSync(entry).isFile()) { | ||
err = new Error('Entry file is not existed'); | ||
help(); | ||
return [2, exit(err)]; | ||
} | ||
bundle = require(".").bundle; | ||
return [4, bundle(entry, outputConfig)]; | ||
case 1: return [2, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
function main() { | ||
return tslib.__awaiter(this, void 0, void 0, function () { | ||
var params, error; | ||
return tslib.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
try { | ||
params = parseCliArgs(process.argv.slice(2)); | ||
} | ||
catch (err) { | ||
error = err; | ||
} | ||
if (error || !params) { | ||
if (!error) | ||
help(); | ||
return [2, exit(error)]; | ||
} | ||
return [4, run(params)]; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4, bunchee(entry, outputConfig)]; | ||
case 2: | ||
_a.sent(); | ||
return [3, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
console.error(e_1); | ||
process.exit(2); | ||
return [3, 4]; | ||
case 4: return [2]; | ||
return [2]; | ||
} | ||
@@ -63,5 +121,3 @@ }); | ||
} | ||
function help() { | ||
program.help(); | ||
} | ||
main().catch(exit); | ||
//# sourceMappingURL=cli.js.map |
@@ -0,1 +1,3 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
@@ -16,2 +18,3 @@ | ||
var rollupPluginTerser = require('rollup-plugin-terser'); | ||
require('arg'); | ||
@@ -55,3 +58,3 @@ var rootDir = process.cwd(); | ||
.reduce(function (a, b) { return a.concat(b); }, []); | ||
var useTypescript = options.useTypescript, _a = options.minify, minify = _a === void 0 ? false : _a; | ||
var useTypescript = options.useTypescript, target = options.target, _a = options.minify, minify = _a === void 0 ? false : _a; | ||
var typings = pkg.types || pkg.typings; | ||
@@ -61,3 +64,3 @@ var cwd = config.rootDir; | ||
nodeResolve({ | ||
preferBuiltins: false, | ||
preferBuiltins: target === 'node', | ||
extensions: ['.mjs', '.js', '.json', '.node', '.jsx'], | ||
@@ -166,3 +169,3 @@ }), | ||
try { | ||
targetPackageJson = require(pkgFilePath); | ||
targetPackageJson = JSON.parse(fs__default.readFileSync(pkgFilePath, { encoding: 'utf-8' })); | ||
} | ||
@@ -235,3 +238,3 @@ catch (e) { | ||
module.exports = bundle; | ||
exports.bundle = bundle; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "bunchee", | ||
"version": "1.5.4", | ||
"version": "1.6.0", | ||
"description": "zero config bundler for js/ts/jsx libraries", | ||
@@ -13,7 +13,9 @@ "bin": { | ||
"clean": "rm -rf ./dist", | ||
"typecheck": "tsc --noEmit", | ||
"prepublishOnly": "yarn clean && yarn build && chmod +x dist/cli.js && yarn test", | ||
"build:cli": "ts-node src/cli.ts src/cli.ts -f cjs -o dist/cli.js", | ||
"build:main": "ts-node src/cli.ts src/index.ts -f cjs", | ||
"build:cli": "node -r ts-node/register src/cli.ts src/cli.ts --target node -f cjs -o dist/cli.js", | ||
"build:main": "node -r ts-node/register src/cli.ts src/index.ts --target node -f cjs", | ||
"build": "yarn build:main && yarn build:cli" | ||
}, | ||
"type": "commonjs", | ||
"keywords": [ | ||
@@ -39,4 +41,4 @@ "bundler", | ||
"@rollup/plugin-typescript": "8.2.0", | ||
"arg": "5.0.0", | ||
"babel-preset-o": "0.4.1", | ||
"commander": "2.20.3", | ||
"rollup": "1.32.0", | ||
@@ -50,3 +52,3 @@ "rollup-plugin-commonjs": "10.1.0", | ||
"peerDependencies": { | ||
"typescript": ">= 3.4.0" | ||
"typescript": ">= 3.7.0" | ||
}, | ||
@@ -56,4 +58,4 @@ "devDependencies": { | ||
"jest": "26.6.1", | ||
"ts-node": "9.1.1" | ||
"ts-node": "10.0.0" | ||
} | ||
} |
@@ -52,4 +52,5 @@ # bunchee | ||
-o, --output <file> specify output filename | ||
-f, --format <format> specify bundle type. esm, cjs, umd. "esm" by default | ||
-f, --format <format> specify bundle type: "esm", "cjs", "umd". "esm" by default | ||
-h, --help output usage information | ||
--target <target> build environment, use "node" for nodejs runtime | ||
--no-sourcemap disable sourcemap generation, sourcemap generation is enabled by default | ||
@@ -56,0 +57,0 @@ --cwd <cwd> specify current working directory |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
28780
410
77
4
+ Addedarg@5.0.0
+ Addedarg@5.0.0(transitive)
- Removedcommander@2.20.3