Comparing version 2.2.0 to 3.0.0-beta.10
362
dist/cli.js
@@ -6,7 +6,2 @@ #!/usr/bin/env node | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path); | ||
var arg__default = /*#__PURE__*/_interopDefaultLegacy(arg); | ||
function exit(err) { | ||
@@ -16,18 +11,16 @@ logger.error(err); | ||
} | ||
var formatDuration = function(duration) { | ||
return duration >= 1000 ? "" + duration / 1000 + "s" : "" + duration + "ms"; | ||
}; | ||
var logger = { | ||
log: function log(arg) { | ||
const formatDuration = (duration)=>duration >= 1000 ? `${duration / 1000}s` : `${duration}ms`; | ||
const logger = { | ||
log (arg) { | ||
console.log(arg); | ||
}, | ||
warn: function warn(arg) { | ||
console.log("\x1b[33m" + arg + "\x1b[0m"); | ||
warn (arg) { | ||
console.log('\x1b[33m' + arg + '\x1b[0m'); | ||
}, | ||
error: function error(arg) { | ||
console.error("\x1b[31m" + arg + "\x1b[0m"); | ||
error (arg) { | ||
console.error('\x1b[31m' + arg + '\x1b[0m'); | ||
} | ||
}; | ||
var version = "2.2.0"; | ||
var version = "3.0.0-beta.10"; | ||
@@ -63,98 +56,19 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
} | ||
var __generator = undefined && undefined.__generator || function(thisArg, body) { | ||
var f, y, t, g, _ = { | ||
label: 0, | ||
sent: function() { | ||
if (t[0] & 1) throw t[1]; | ||
return t[1]; | ||
}, | ||
trys: [], | ||
ops: [] | ||
}; | ||
return g = { | ||
next: verb(0), | ||
"throw": verb(1), | ||
"return": verb(2) | ||
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() { | ||
return this; | ||
}), g; | ||
function verb(n) { | ||
return function(v) { | ||
return step([ | ||
n, | ||
v | ||
]); | ||
}; | ||
} | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while(_)try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [ | ||
op[0] & 2, | ||
t.value | ||
]; | ||
switch(op[0]){ | ||
case 0: | ||
case 1: | ||
t = op; | ||
break; | ||
case 4: | ||
_.label++; | ||
return { | ||
value: op[1], | ||
done: false | ||
}; | ||
case 5: | ||
_.label++; | ||
y = op[1]; | ||
op = [ | ||
0 | ||
]; | ||
continue; | ||
case 7: | ||
op = _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { | ||
_ = 0; | ||
continue; | ||
} | ||
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { | ||
_.label = op[1]; | ||
break; | ||
} | ||
if (op[0] === 6 && _.label < t[1]) { | ||
_.label = t[1]; | ||
t = op; | ||
break; | ||
} | ||
if (t && _.label < t[2]) { | ||
_.label = t[2]; | ||
_.ops.push(op); | ||
break; | ||
} | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { | ||
op = [ | ||
6, | ||
e | ||
]; | ||
y = 0; | ||
} finally{ | ||
f = t = 0; | ||
} | ||
if (op[0] & 5) throw op[1]; | ||
return { | ||
value: op[0] ? op[1] : void 0, | ||
done: true | ||
}; | ||
} | ||
}; | ||
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. default: false\n -o, --output <file> specify output filename\n -f, --format <format> type of output (esm, amd, cjs, iife, umd, system), default: esm\n -e, --external <mod> specify an external dependency\n -h, --help output usage information\n --target <target> js features target: swc target es versions. default: es5\n --runtime <runtime> build runtime (nodejs, browser). default: browser\n --cwd <cwd> specify current working directory\n --sourcemap enable sourcemap generation, default: false\n --dts determine if need to generate types, default: false\n"; | ||
const helpMessage = ` | ||
Usage: bunchee [options] | ||
Options: | ||
-v, --version output the version number | ||
-w, --watch watch src files changes | ||
-m, --minify compress output. default: false | ||
-o, --output <file> specify output filename | ||
-f, --format <format> type of output (esm, amd, cjs, iife, umd, system), default: esm | ||
-e, --external <mod> specify an external dependency | ||
-h, --help output usage information | ||
--target <target> js features target: swc target es versions. default: es2015 | ||
--runtime <runtime> build runtime (nodejs, browser). default: browser | ||
--cwd <cwd> specify current working directory | ||
--sourcemap enable sourcemap generation, default: false | ||
--dts determine if need to generate types, default: false | ||
`; | ||
function help() { | ||
@@ -164,44 +78,44 @@ logger.log(helpMessage); | ||
function parseCliArgs(argv) { | ||
var args; | ||
args = arg__default["default"]({ | ||
"--cwd": String, | ||
"--dts": Boolean, | ||
"--output": String, | ||
"--format": String, | ||
"--watch": Boolean, | ||
"--minify": Boolean, | ||
"--help": Boolean, | ||
"--version": Boolean, | ||
"--runtime": String, | ||
"--target": String, | ||
"--sourcemap": Boolean, | ||
"--external": [ | ||
let args; | ||
args = arg({ | ||
'--cwd': String, | ||
'--dts': Boolean, | ||
'--output': String, | ||
'--format': String, | ||
'--watch': Boolean, | ||
'--minify': Boolean, | ||
'--help': Boolean, | ||
'--version': Boolean, | ||
'--runtime': String, | ||
'--target': String, | ||
'--sourcemap': Boolean, | ||
'--external': [ | ||
String | ||
], | ||
"-h": "--help", | ||
"-v": "--version", | ||
"-w": "--watch", | ||
"-o": "--output", | ||
"-f": "--format", | ||
"-m": "--minify", | ||
"-e": "--external" | ||
'-h': '--help', | ||
'-v': '--version', | ||
'-w': '--watch', | ||
'-o': '--output', | ||
'-f': '--format', | ||
'-m': '--minify', | ||
'-e': '--external' | ||
}, { | ||
permissive: true, | ||
argv: argv | ||
argv | ||
}); | ||
var source = args._[0]; | ||
var parsedArgs = { | ||
source: source, | ||
format: args["--format"], | ||
file: args["--output"], | ||
watch: args["--watch"], | ||
minify: args["--minify"], | ||
sourcemap: !!args["--sourcemap"], | ||
cwd: args["--cwd"], | ||
dts: args["--dts"], | ||
help: args["--help"], | ||
version: args["--version"], | ||
runtime: args["--runtime"], | ||
target: args["--target"], | ||
external: args["--external"] | ||
const source = args._[0]; | ||
const parsedArgs = { | ||
source, | ||
format: args['--format'], | ||
file: args['--output'], | ||
watch: args['--watch'], | ||
minify: args['--minify'], | ||
sourcemap: !!args['--sourcemap'], | ||
cwd: args['--cwd'], | ||
dts: args['--dts'], | ||
help: args['--help'], | ||
version: args['--version'], | ||
runtime: args['--runtime'], | ||
target: args['--target'], | ||
external: args['--external'] | ||
}; | ||
@@ -214,76 +128,42 @@ return parsedArgs; | ||
function _run() { | ||
_run = _asyncToGenerator(function(args) { | ||
var source, format, watch, minify, sourcemap, target, runtime, dts, cwd, file, cliArgs, entry, bundle, timeStart, timeEnd, err, duration; | ||
return __generator(this, function(_state) { | ||
switch(_state.label){ | ||
case 0: | ||
source = args.source, format = args.format, watch = args.watch, minify = args.minify, sourcemap = args.sourcemap, target = args.target, runtime = args.runtime, dts = args.dts; | ||
cwd = args.cwd || process.cwd(); | ||
file = args.file ? path__default["default"].resolve(cwd, args.file) : undefined; | ||
cliArgs = { | ||
dts: dts, | ||
file: file, | ||
format: format, | ||
cwd: cwd, | ||
target: target, | ||
runtime: runtime, | ||
external: args.external || [], | ||
watch: !!watch, | ||
minify: !!minify, | ||
sourcemap: sourcemap === false ? false : true | ||
}; | ||
if (args.version) { | ||
return [ | ||
2, | ||
logger.log(version) | ||
]; | ||
} | ||
if (args.help) { | ||
return [ | ||
2, | ||
help() | ||
]; | ||
} | ||
entry = source ? path__default["default"].resolve(cwd, source) : ""; | ||
bundle = require("./lib").bundle; | ||
timeStart = Date.now(); | ||
_state.label = 1; | ||
case 1: | ||
_state.trys.push([ | ||
1, | ||
3, | ||
, | ||
4 | ||
]); | ||
return [ | ||
4, | ||
bundle(entry, cliArgs) | ||
]; | ||
case 2: | ||
_state.sent(); | ||
timeEnd = Date.now(); | ||
return [ | ||
3, | ||
4 | ||
]; | ||
case 3: | ||
err = _state.sent(); | ||
if (err.name === "NOT_EXISTED") { | ||
help(); | ||
return [ | ||
2, | ||
exit(err) | ||
]; | ||
} | ||
throw err; | ||
case 4: | ||
duration = timeEnd - timeStart; | ||
if (!watch) { | ||
logger.log("✨ Finished in " + formatDuration(duration)); | ||
} | ||
return [ | ||
2 | ||
]; | ||
_run = _asyncToGenerator(function*(args) { | ||
const { source , format , watch , minify , sourcemap , target , runtime , dts } = args; | ||
const cwd = args.cwd || process.cwd(); | ||
const file = args.file ? path.resolve(cwd, args.file) : undefined; | ||
const cliArgs = { | ||
dts, | ||
file, | ||
format, | ||
cwd, | ||
target, | ||
runtime, | ||
external: args.external || [], | ||
watch: !!watch, | ||
minify: !!minify, | ||
sourcemap: sourcemap === false ? false : true | ||
}; | ||
if (args.version) { | ||
return logger.log(version); | ||
} | ||
if (args.help) { | ||
return help(); | ||
} | ||
const entry = source ? path.resolve(cwd, source) : ''; | ||
const { bundle } = require('./lib'); | ||
let timeStart = Date.now(); | ||
let timeEnd; | ||
try { | ||
yield bundle(entry, cliArgs); | ||
timeEnd = Date.now(); | ||
} catch (err) { | ||
if (err.name === 'NOT_EXISTED') { | ||
help(); | ||
return exit(err); | ||
} | ||
}); | ||
throw err; | ||
} | ||
const duration = timeEnd - timeStart; | ||
if (!watch) { | ||
logger.log(`✨ Finished in ${formatDuration(duration)}`); | ||
} | ||
}); | ||
@@ -296,30 +176,14 @@ return _run.apply(this, arguments); | ||
function _main() { | ||
_main = _asyncToGenerator(function() { | ||
var params, error; | ||
return __generator(this, function(_state) { | ||
switch(_state.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: | ||
_state.sent(); | ||
return [ | ||
2 | ||
]; | ||
} | ||
}); | ||
_main = _asyncToGenerator(function*() { | ||
let params, error; | ||
try { | ||
params = parseCliArgs(process.argv.slice(2)); | ||
} catch (err) { | ||
error = err; | ||
} | ||
if (error || !params) { | ||
if (!error) help(); | ||
return exit(error); | ||
} | ||
yield run(params); | ||
}); | ||
@@ -326,0 +190,0 @@ return _main.apply(this, arguments); |
import { JscTarget } from '@swc/core'; | ||
import { RollupOptions, InputOptions, OutputOptions } from 'rollup'; | ||
declare type ExportType = 'require' | 'export' | 'default' | string; | ||
declare type CommonConfig = { | ||
type ExportType = 'require' | 'export' | 'default' | string; | ||
type CommonConfig = { | ||
dts?: boolean; | ||
@@ -18,4 +18,4 @@ format?: OutputOptions['format']; | ||
}; | ||
declare type ExportCondition = string | Record<ExportType, string>; | ||
declare type BuncheeRollupConfig = Partial<Omit<RollupOptions, 'input' | 'output'>> & { | ||
type ExportCondition = string | Record<ExportType, string>; | ||
type BuncheeRollupConfig = Partial<Omit<RollupOptions, 'input' | 'output'>> & { | ||
exportName?: string; | ||
@@ -26,3 +26,3 @@ input: InputOptions; | ||
}; | ||
declare type CliArgs = CommonConfig & { | ||
type CliArgs = CommonConfig & { | ||
file?: string; | ||
@@ -29,0 +29,0 @@ watch?: boolean; |
648
dist/lib.js
@@ -6,2 +6,3 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
var rollup = require('rollup'); | ||
var module$1 = require('module'); | ||
var rollupPluginSwc3 = require('rollup-plugin-swc3'); | ||
@@ -12,15 +13,6 @@ var commonjs = require('@rollup/plugin-commonjs'); | ||
var pluginNodeResolve = require('@rollup/plugin-node-resolve'); | ||
var module$1 = require('module'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); | ||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path); | ||
var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs); | ||
var shebang__default = /*#__PURE__*/_interopDefaultLegacy(shebang); | ||
var json__default = /*#__PURE__*/_interopDefaultLegacy(json); | ||
var rootDir = process.cwd(); | ||
const rootDir = process.cwd(); | ||
var config = { | ||
rootDir: rootDir | ||
rootDir | ||
}; | ||
@@ -36,13 +28,13 @@ | ||
if (!field) return; | ||
if (typeof field === "string") return field; | ||
var value = field["."] || field["import"] || field["module"] || field["default"]; | ||
if (typeof field === 'string') return field; | ||
const value = field['.'] || field['import'] || field['module'] || field['default']; | ||
return findExport(value); | ||
} | ||
function parseExport(exportsCondition) { | ||
var paths = {}; | ||
if (typeof exportsCondition === "string") { | ||
const paths = {}; | ||
if (typeof exportsCondition === 'string') { | ||
paths.export = exportsCondition; | ||
} else { | ||
paths.main = paths.main || exportsCondition["require"] || exportsCondition["node"] || exportsCondition["default"]; | ||
paths.module = paths.module || exportsCondition["module"]; | ||
paths.main = paths.main || exportsCondition['require'] || exportsCondition['node'] || exportsCondition['default']; | ||
paths.module = paths.module || exportsCondition['module']; | ||
paths.export = findExport(exportsCondition); | ||
@@ -53,4 +45,4 @@ } | ||
function getExportPaths(pkg) { | ||
var pathsMap = {}; | ||
var mainExport = {}; | ||
const pathsMap = {}; | ||
const mainExport = {}; | ||
if (pkg.main) { | ||
@@ -62,13 +54,11 @@ mainExport.main = pkg.main; | ||
} | ||
pathsMap["."] = mainExport; | ||
var exportsConditions = pkg.exports; | ||
pathsMap['.'] = mainExport; | ||
const { exports: exportsConditions } = pkg; | ||
if (exportsConditions) { | ||
if (typeof exportsConditions === "string") { | ||
if (typeof exportsConditions === 'string') { | ||
mainExport.export = exportsConditions; | ||
} else { | ||
var exportKeys = Object.keys(exportsConditions); | ||
if (exportKeys.some(function(key) { | ||
return key.startsWith("."); | ||
})) { | ||
exportKeys.forEach(function(subExport) { | ||
const exportKeys = Object.keys(exportsConditions); | ||
if (exportKeys.some((key)=>key.startsWith('.'))) { | ||
exportKeys.forEach((subExport)=>{ | ||
pathsMap[subExport] = parseExport(exportsConditions[subExport]); | ||
@@ -81,11 +71,11 @@ }); | ||
} | ||
pathsMap["."] = mainExport; | ||
pathsMap['.'] = mainExport; | ||
return pathsMap; | ||
} | ||
function getExportDist(pkg) { | ||
var paths = getExportPaths(pkg)["."]; | ||
var dist = []; | ||
const paths = getExportPaths(pkg)['.']; | ||
const dist = []; | ||
if (paths.main) { | ||
dist.push({ | ||
format: "cjs", | ||
format: 'cjs', | ||
file: getDistPath(paths.main) | ||
@@ -96,3 +86,3 @@ }); | ||
dist.push({ | ||
format: "esm", | ||
format: 'esm', | ||
file: getDistPath(paths.module) | ||
@@ -103,3 +93,3 @@ }); | ||
dist.push({ | ||
format: "esm", | ||
format: 'esm', | ||
file: getDistPath(paths.export) | ||
@@ -111,4 +101,4 @@ }); | ||
dist.push({ | ||
format: "esm", | ||
file: getDistPath("dist/index.js") | ||
format: 'esm', | ||
file: getDistPath('dist/index.js') | ||
}); | ||
@@ -120,7 +110,7 @@ } | ||
// const pkgExports = pkg.exports || {} | ||
var dist = []; | ||
const dist = []; | ||
// "exports": "..." | ||
if (typeof exportCondition === "string") { | ||
if (typeof exportCondition === 'string') { | ||
dist.push({ | ||
format: pkg.type === "module" ? "esm" : "cjs", | ||
format: pkg.type === 'module' ? 'esm' : 'cjs', | ||
file: getDistPath(exportCondition) | ||
@@ -130,9 +120,9 @@ }); | ||
// "./<subexport>": { } | ||
var subExports = exportCondition // pkgExports[subExport] | ||
const subExports = exportCondition // pkgExports[subExport] | ||
; | ||
// Ignore json exports, like "./package.json" | ||
// if (subExport.endsWith('.json')) return dist | ||
if (typeof subExports === "string") { | ||
if (typeof subExports === 'string') { | ||
dist.push({ | ||
format: "esm", | ||
format: 'esm', | ||
file: getDistPath(subExports) | ||
@@ -143,3 +133,3 @@ }); | ||
dist.push({ | ||
format: "cjs", | ||
format: 'cjs', | ||
file: getDistPath(subExports.require) | ||
@@ -150,3 +140,3 @@ }); | ||
dist.push({ | ||
format: "esm", | ||
format: 'esm', | ||
file: getDistPath(subExports.import) | ||
@@ -164,11 +154,9 @@ }); | ||
} | ||
var formatDuration = function(duration) { | ||
return duration >= 1000 ? "" + duration / 1000 + "s" : "" + duration + "ms"; | ||
}; | ||
const formatDuration = (duration)=>duration >= 1000 ? `${duration / 1000}s` : `${duration}ms`; | ||
function getPackageMeta(cwd) { | ||
var pkgFilePath = path__default["default"].resolve(cwd, "package.json"); | ||
var targetPackageJson = {}; | ||
const pkgFilePath = path.resolve(cwd, 'package.json'); | ||
let targetPackageJson = {}; | ||
try { | ||
targetPackageJson = JSON.parse(fs__default["default"].readFileSync(pkgFilePath, { | ||
encoding: "utf-8" | ||
targetPackageJson = JSON.parse(fs.readFileSync(pkgFilePath, { | ||
encoding: 'utf-8' | ||
})); | ||
@@ -178,20 +166,18 @@ } catch (_) {} | ||
} | ||
var logger = { | ||
log: function log(arg) { | ||
const logger = { | ||
log (arg) { | ||
console.log(arg); | ||
}, | ||
warn: function warn(arg) { | ||
console.log("\x1b[33m" + arg + "\x1b[0m"); | ||
warn (arg) { | ||
console.log('\x1b[33m' + arg + '\x1b[0m'); | ||
}, | ||
error: function error(arg) { | ||
console.error("\x1b[31m" + arg + "\x1b[0m"); | ||
error (arg) { | ||
console.error('\x1b[31m' + arg + '\x1b[0m'); | ||
} | ||
}; | ||
function isTypescript(filename) { | ||
var ext = path__default["default"].extname(filename); | ||
return ext === ".ts" || ext === ".tsx"; | ||
const ext = path.extname(filename); | ||
return ext === '.ts' || ext === '.tsx'; | ||
} | ||
var isNotNull = function(n) { | ||
return Boolean(n); | ||
}; | ||
const isNotNull = (n)=>Boolean(n); | ||
@@ -212,18 +198,20 @@ function _extends$1() { | ||
} | ||
var minifyOptions = { | ||
const minifyOptions = { | ||
compress: true, | ||
format: { | ||
comments: "some", | ||
comments: 'some', | ||
wrapFuncArgs: false, | ||
preserveAnnotations: true | ||
}, | ||
mangle: true | ||
mangle: { | ||
toplevel: true | ||
} | ||
}; | ||
var hasLoggedTsWarning = false; | ||
let hasLoggedTsWarning = false; | ||
function resolveTypescript(cwd) { | ||
var ts; | ||
var m = new module$1.Module("", undefined); | ||
let ts; | ||
const m = new module$1.Module('', undefined); | ||
m.paths = module$1.Module._nodeModulePaths(cwd); | ||
try { | ||
ts = m.require("typescript"); | ||
ts = m.require('typescript'); | ||
} catch (_) { | ||
@@ -233,3 +221,3 @@ console.error(_); | ||
hasLoggedTsWarning = true; | ||
exit("Could not load TypeScript compiler. Try to install `typescript` as dev dependency"); | ||
exit('Could not load TypeScript compiler. Try to install `typescript` as dev dependency'); | ||
} | ||
@@ -239,24 +227,16 @@ } | ||
} | ||
function buildInputConfig(entry, pkg, options, param) { | ||
var tsConfigPath = param.tsConfigPath, tsCompilerOptions = param.tsCompilerOptions, dtsOnly = param.dtsOnly; | ||
var _external; | ||
var externals = [ | ||
function buildInputConfig(entry, pkg, options, { tsConfigPath , tsCompilerOptions , dtsOnly }) { | ||
var _options_external; | ||
const externals = [ | ||
pkg.peerDependencies, | ||
pkg.dependencies, | ||
pkg.peerDependenciesMeta | ||
].filter(function(n) { | ||
return Boolean(n); | ||
}).map(function(o) { | ||
return Object.keys(o); | ||
}).reduce(function(a, b) { | ||
return a.concat(b); | ||
}, []).concat(((_external = options.external) != null ? _external : []).concat(pkg.name ? [ | ||
].filter((n)=>Boolean(n)).map((o)=>Object.keys(o)).reduce((a, b)=>a.concat(b), []).concat(((_options_external = options.external) != null ? _options_external : []).concat(pkg.name ? [ | ||
pkg.name | ||
] : [])); | ||
var useTypescript = options.useTypescript, runtime = options.runtime, jscTarget = options.target, minify = options.minify; | ||
var hasSpecifiedTsTarget = Boolean((tsCompilerOptions == null ? void 0 : tsCompilerOptions.target) && tsConfigPath); | ||
var _obj; | ||
var plugins = (dtsOnly ? [ | ||
shebang__default["default"](), | ||
useTypescript && require("rollup-plugin-dts").default({ | ||
const { useTypescript , runtime , target: jscTarget , minify } = options; | ||
const hasSpecifiedTsTarget = Boolean((tsCompilerOptions == null ? void 0 : tsCompilerOptions.target) && tsConfigPath); | ||
const plugins = (dtsOnly ? [ | ||
shebang(), | ||
useTypescript && require('rollup-plugin-dts').default({ | ||
compilerOptions: _extends$1({}, tsCompilerOptions, { | ||
@@ -271,6 +251,6 @@ declaration: true, | ||
preserveSymlinks: false, | ||
target: "esnext", | ||
module: "esnext", | ||
target: 'esnext', | ||
module: 'esnext', | ||
incremental: false, | ||
jsx: tsCompilerOptions.jsx || "react" | ||
jsx: tsCompilerOptions.jsx || 'react' | ||
}) | ||
@@ -280,19 +260,19 @@ }) | ||
pluginNodeResolve.nodeResolve({ | ||
preferBuiltins: runtime === "node", | ||
preferBuiltins: runtime === 'node', | ||
extensions: [ | ||
".mjs", | ||
".js", | ||
".json", | ||
".node", | ||
".jsx" | ||
'.mjs', | ||
'.js', | ||
'.json', | ||
'.node', | ||
'.jsx' | ||
] | ||
}), | ||
commonjs__default["default"]({ | ||
commonjs({ | ||
include: /node_modules\// | ||
}), | ||
json__default["default"](), | ||
shebang__default["default"](), | ||
json(), | ||
shebang(), | ||
rollupPluginSwc3.swc({ | ||
include: /\.(m|c)?[jt]sx?$/, | ||
exclude: "node_modules", | ||
exclude: 'node_modules', | ||
tsconfig: tsConfigPath, | ||
@@ -304,5 +284,9 @@ jsc: _extends$1({}, !hasSpecifiedTsTarget && { | ||
externalHelpers: false, | ||
parser: (_obj = { | ||
syntax: useTypescript ? "typescript" : "ecmascript" | ||
}, _obj[useTypescript ? "tsx" : "jsx"] = true, _obj.privateMethod = true, _obj.classPrivateProperty = true, _obj.exportDefaultFrom = true, _obj) | ||
parser: { | ||
syntax: useTypescript ? 'typescript' : 'ecmascript', | ||
[useTypescript ? 'tsx' : 'jsx']: true, | ||
privateMethod: true, | ||
classPrivateProperty: true, | ||
exportDefaultFrom: true | ||
} | ||
}, minify && { | ||
@@ -319,23 +303,21 @@ minify: _extends$1({}, minifyOptions, { | ||
input: entry, | ||
external: function external(id) { | ||
return externals.some(function(name) { | ||
return id === name || id.startsWith(name + "/"); | ||
}); | ||
external (id) { | ||
return externals.some((name)=>id === name || id.startsWith(name + '/')); | ||
}, | ||
plugins: plugins, | ||
plugins, | ||
treeshake: { | ||
propertyReadSideEffects: false | ||
}, | ||
onwarn: function onwarn(warning, warn) { | ||
var code = warning.code || ""; | ||
onwarn (warning, warn) { | ||
const code = warning.code || ''; | ||
// Some may not have types, like CLI binary | ||
if (dtsOnly && code === "EMPTY_BUNDLE") return; | ||
if (dtsOnly && code === 'EMPTY_BUNDLE') return; | ||
if ([ | ||
"MIXED_EXPORTS", | ||
"PREFER_NAMED_EXPORTS", | ||
"UNRESOLVED_IMPORT", | ||
"THIS_IS_UNDEFINED" | ||
'MIXED_EXPORTS', | ||
'PREFER_NAMED_EXPORTS', | ||
'UNRESOLVED_IMPORT', | ||
'THIS_IS_UNDEFINED' | ||
].includes(code)) return; | ||
// If the circular dependency warning is from node_modules, ignore it | ||
if (code === "CIRCULAR_DEPENDENCY" && /Circular dependency: node_modules/.test(warning.message)) { | ||
if (code === 'CIRCULAR_DEPENDENCY' && /Circular dependency: node_modules/.test(warning.message)) { | ||
return; | ||
@@ -347,19 +329,18 @@ } | ||
} | ||
function buildOutputConfigs(options, pkg, param) { | ||
var tsCompilerOptions = param.tsCompilerOptions, dtsOnly = param.dtsOnly; | ||
var format = options.format, exportCondition = options.exportCondition; | ||
var exportPaths = getExportPaths(pkg); | ||
function buildOutputConfigs(options, pkg, { tsCompilerOptions , dtsOnly }) { | ||
const { format , exportCondition } = options; | ||
const exportPaths = getExportPaths(pkg); | ||
// respect if tsconfig.json has `esModuleInterop` config; | ||
// add ESModule mark if cjs and ESModule are both generated; | ||
// TODO: support `import` in exportCondition | ||
var mainExport = exportPaths["."]; | ||
var useEsModuleMark = Boolean(tsCompilerOptions.esModuleInterop || mainExport.main && mainExport.module); | ||
var typings = getTypings(pkg); | ||
var file = options.file && path.resolve(config.rootDir, options.file); | ||
var dtsDir = typings ? path.dirname(path.resolve(config.rootDir, typings)) : path.resolve(config.rootDir, "dist"); | ||
const mainExport = exportPaths['.']; | ||
const useEsModuleMark = Boolean(tsCompilerOptions.esModuleInterop || mainExport.main && mainExport.module); | ||
const typings = getTypings(pkg); | ||
const file = options.file && path.resolve(config.rootDir, options.file); | ||
const dtsDir = typings ? path.dirname(path.resolve(config.rootDir, typings)) : path.resolve(config.rootDir, 'dist'); | ||
// file base name without extension | ||
var name = file ? file.replace(new RegExp("" + path.extname(file) + "$"), "") : undefined; | ||
var dtsFile = file ? name + ".d.ts" : (exportCondition == null ? void 0 : exportCondition.name) ? path.resolve(dtsDir, (exportCondition.name === "." ? "index" : exportCondition.name) + ".d.ts") : typings && path.resolve(config.rootDir, typings); | ||
const name = file ? file.replace(new RegExp(`${path.extname(file)}$`), '') : undefined; | ||
const dtsFile = file ? name + '.d.ts' : (exportCondition == null ? void 0 : exportCondition.name) ? path.resolve(dtsDir, (exportCondition.name === '.' ? 'index' : exportCondition.name) + '.d.ts') : typings && path.resolve(config.rootDir, typings); | ||
// If there's dts file, use `output.file` | ||
var dtsPathConfig = dtsFile ? { | ||
const dtsPathConfig = dtsFile ? { | ||
file: dtsFile | ||
@@ -374,4 +355,4 @@ } : { | ||
}, { | ||
format: format, | ||
exports: "named", | ||
format, | ||
exports: 'named', | ||
esModule: useEsModuleMark, | ||
@@ -384,30 +365,30 @@ freeze: false, | ||
function buildConfig(entry, pkg, cliArgs, dtsOnly) { | ||
var ref; | ||
var file = cliArgs.file; | ||
var useTypescript = isTypescript(entry); | ||
var options = _extends$1({}, cliArgs, { | ||
useTypescript: useTypescript | ||
var _options_exportCondition; | ||
const { file } = cliArgs; | ||
const useTypescript = isTypescript(entry); | ||
const options = _extends$1({}, cliArgs, { | ||
useTypescript | ||
}); | ||
var tsCompilerOptions = {}; | ||
var tsConfigPath; | ||
let tsCompilerOptions = {}; | ||
let tsConfigPath; | ||
if (useTypescript) { | ||
var ts = resolveTypescript(config.rootDir); | ||
tsConfigPath = path.resolve(config.rootDir, "tsconfig.json"); | ||
if (fs__default["default"].existsSync(tsConfigPath)) { | ||
var basePath = tsConfigPath ? path.dirname(tsConfigPath) : config.rootDir; | ||
var tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config; | ||
const ts = resolveTypescript(config.rootDir); | ||
tsConfigPath = path.resolve(config.rootDir, 'tsconfig.json'); | ||
if (fs.existsSync(tsConfigPath)) { | ||
const basePath = tsConfigPath ? path.dirname(tsConfigPath) : config.rootDir; | ||
const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config; | ||
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, basePath).options; | ||
} else { | ||
tsConfigPath = undefined; | ||
exit("tsconfig.json is missing in your project directory"); | ||
exit('tsconfig.json is missing in your project directory'); | ||
} | ||
} | ||
var typescriptOptions = { | ||
dtsOnly: dtsOnly, | ||
tsConfigPath: tsConfigPath, | ||
tsCompilerOptions: tsCompilerOptions | ||
const typescriptOptions = { | ||
dtsOnly, | ||
tsConfigPath, | ||
tsCompilerOptions | ||
}; | ||
var inputOptions = buildInputConfig(entry, pkg, options, typescriptOptions); | ||
var outputExports = options.exportCondition ? getExportConditionDist(pkg, options.exportCondition.export) : getExportDist(pkg); | ||
var outputConfigs = []; | ||
const inputOptions = buildInputConfig(entry, pkg, options, typescriptOptions); | ||
const outputExports = options.exportCondition ? getExportConditionDist(pkg, options.exportCondition.export) : getExportDist(pkg); | ||
let outputConfigs = []; | ||
// Generate dts job - single config | ||
@@ -417,4 +398,4 @@ if (dtsOnly) { | ||
buildOutputConfigs(_extends$1({}, cliArgs, { | ||
format: "es", | ||
useTypescript: useTypescript | ||
format: 'es', | ||
useTypescript | ||
}), pkg, typescriptOptions) | ||
@@ -424,7 +405,7 @@ ]; | ||
// multi outputs with specified format | ||
outputConfigs = outputExports.map(function(exportDist) { | ||
outputConfigs = outputExports.map((exportDist)=>{ | ||
return buildOutputConfigs(_extends$1({}, cliArgs, { | ||
file: exportDist.file, | ||
format: exportDist.format, | ||
useTypescript: useTypescript | ||
useTypescript | ||
}), pkg, typescriptOptions); | ||
@@ -434,9 +415,9 @@ }); | ||
if (file) { | ||
var ref1; | ||
var fallbackFormat = (ref1 = outputExports[0]) == null ? void 0 : ref1.format; | ||
var _outputExports_; | ||
const fallbackFormat = (_outputExports_ = outputExports[0]) == null ? void 0 : _outputExports_.format; | ||
outputConfigs = [ | ||
buildOutputConfigs(_extends$1({}, cliArgs, { | ||
file: file, | ||
file, | ||
format: cliArgs.format || fallbackFormat, | ||
useTypescript: useTypescript | ||
useTypescript | ||
}), pkg, typescriptOptions) | ||
@@ -449,4 +430,4 @@ ]; | ||
output: outputConfigs, | ||
exportName: ((ref = options.exportCondition) == null ? void 0 : ref.name) || ".", | ||
dtsOnly: dtsOnly | ||
exportName: ((_options_exportCondition = options.exportCondition) == null ? void 0 : _options_exportCondition.name) || '.', | ||
dtsOnly | ||
}; | ||
@@ -510,117 +491,4 @@ } | ||
} | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (it) return (it = it.call(o)).next.bind(it); | ||
if (Array.isArray(o) || (it = unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function() { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var __generator = undefined && undefined.__generator || function(thisArg, body) { | ||
var f, y, t, g, _ = { | ||
label: 0, | ||
sent: function() { | ||
if (t[0] & 1) throw t[1]; | ||
return t[1]; | ||
}, | ||
trys: [], | ||
ops: [] | ||
}; | ||
return g = { | ||
next: verb(0), | ||
"throw": verb(1), | ||
"return": verb(2) | ||
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() { | ||
return this; | ||
}), g; | ||
function verb(n) { | ||
return function(v) { | ||
return step([ | ||
n, | ||
v | ||
]); | ||
}; | ||
} | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while(_)try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [ | ||
op[0] & 2, | ||
t.value | ||
]; | ||
switch(op[0]){ | ||
case 0: | ||
case 1: | ||
t = op; | ||
break; | ||
case 4: | ||
_.label++; | ||
return { | ||
value: op[1], | ||
done: false | ||
}; | ||
case 5: | ||
_.label++; | ||
y = op[1]; | ||
op = [ | ||
0 | ||
]; | ||
continue; | ||
case 7: | ||
op = _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { | ||
_ = 0; | ||
continue; | ||
} | ||
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { | ||
_.label = op[1]; | ||
break; | ||
} | ||
if (op[0] === 6 && _.label < t[1]) { | ||
_.label = t[1]; | ||
t = op; | ||
break; | ||
} | ||
if (t && _.label < t[2]) { | ||
_.label = t[2]; | ||
_.ops.push(op); | ||
break; | ||
} | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); | ||
continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { | ||
op = [ | ||
6, | ||
e | ||
]; | ||
y = 0; | ||
} finally{ | ||
f = t = 0; | ||
} | ||
if (op[0] & 5) throw op[1]; | ||
return { | ||
value: op[0] ? op[1] : void 0, | ||
done: true | ||
}; | ||
} | ||
}; | ||
function logBuild(exportPath, dtsOnly, duration) { | ||
logger.log(" ✓ " + (dtsOnly ? "Typed" : "Built") + " " + exportPath + " " + formatDuration(duration)); | ||
logger.log(` ✓ ${dtsOnly ? 'Typed' : 'Built'} ${exportPath} ${formatDuration(duration)}`); | ||
} | ||
@@ -635,17 +503,16 @@ function assignDefault(options, name, defaultValue) { | ||
function getSourcePathFromExportPath(cwd, exportPath) { | ||
var exts = [ | ||
"js", | ||
"cjs", | ||
"mjs", | ||
"jsx", | ||
"ts", | ||
"tsx" | ||
const exts = [ | ||
'js', | ||
'cjs', | ||
'mjs', | ||
'jsx', | ||
'ts', | ||
'tsx' | ||
]; | ||
for(var _iterator = _createForOfIteratorHelperLoose(exts), _step; !(_step = _iterator()).done;){ | ||
var ext = _step.value; | ||
for (const ext of exts){ | ||
// ignore package.json | ||
if (exportPath.endsWith("package.json")) return; | ||
if (exportPath === ".") exportPath = "./index"; | ||
var filename = path.resolve(cwd, exportPath + "." + ext); | ||
if (fs__default["default"].existsSync(filename)) { | ||
if (exportPath.endsWith('package.json')) return; | ||
if (exportPath === '.') exportPath = './index'; | ||
const filename = path.resolve(cwd, `${exportPath}.${ext}`); | ||
if (fs.existsSync(filename)) { | ||
return filename; | ||
@@ -660,115 +527,74 @@ } | ||
function _bundle() { | ||
_bundle = _asyncToGenerator(function(entryPath, _param) { | ||
var cwd, options, pkg, packageExports, isSingleEntry, hasMultiEntries, bundleOrWatch, hasSpecifiedEntryFile, err, hasTypings, assetsJobs, typesJobs, rollupConfig; | ||
_bundle = _asyncToGenerator(function*(entryPath, _param = {}) { | ||
var { cwd } = _param, options = _objectWithoutPropertiesLoose(_param, [ | ||
"cwd" | ||
]); | ||
config.rootDir = path.resolve(process.cwd(), cwd || ''); | ||
assignDefault(options, 'format', 'es'); | ||
assignDefault(options, 'minify', false); | ||
assignDefault(options, 'target', 'es2015'); | ||
if (options.dts === undefined && isTypescript(entryPath)) { | ||
options.dts = true; | ||
} | ||
const pkg = getPackageMeta(config.rootDir); | ||
const packageExports = pkg.exports || {}; | ||
const isSingleEntry = typeof packageExports === 'string'; | ||
const hasMultiEntries = packageExports && !isSingleEntry && Object.keys(packageExports).length > 0; | ||
if (isSingleEntry) { | ||
entryPath = getSourcePathFromExportPath(config.rootDir, '.'); | ||
} | ||
function buildEntryConfig(packageExports, dtsOnly) { | ||
var configs = Object.keys(packageExports).map(function(entryExport) { | ||
var source = getSourcePathFromExportPath(config.rootDir, entryExport); | ||
const configs = Object.keys(packageExports).map((entryExport)=>{ | ||
const source = getSourcePathFromExportPath(config.rootDir, entryExport); | ||
if (!source) return undefined; | ||
if (dtsOnly && !isTypescript(source)) return; | ||
options.exportCondition = { | ||
source: source, | ||
source, | ||
name: entryExport, | ||
export: packageExports[entryExport] | ||
}; | ||
var entry = path.resolve(cwd, source); | ||
var rollupConfig = buildConfig(entry, pkg, options, dtsOnly); | ||
const entry = path.resolve(cwd, source); | ||
const rollupConfig = buildConfig(entry, pkg, options, dtsOnly); | ||
return rollupConfig; | ||
}).filter(function(v) { | ||
return !!v; | ||
}); | ||
}).filter((v)=>!!v); | ||
return configs; | ||
} | ||
return __generator(this, function(_state) { | ||
switch(_state.label){ | ||
case 0: | ||
if (_param === void 0) _param = {}; | ||
cwd = _param.cwd, options = _objectWithoutPropertiesLoose(_param, [ | ||
"cwd" | ||
]); | ||
config.rootDir = path.resolve(process.cwd(), cwd || ""); | ||
assignDefault(options, "format", "es"); | ||
assignDefault(options, "minify", false); | ||
assignDefault(options, "target", "es5"); | ||
if (options.dts === undefined && isTypescript(entryPath)) { | ||
options.dts = true; | ||
} | ||
pkg = getPackageMeta(config.rootDir); | ||
packageExports = pkg.exports || {}; | ||
isSingleEntry = typeof packageExports === "string"; | ||
hasMultiEntries = packageExports && !isSingleEntry && Object.keys(packageExports).length > 0; | ||
if (isSingleEntry) { | ||
entryPath = getSourcePathFromExportPath(config.rootDir, "."); | ||
} | ||
bundleOrWatch = function(rollupConfig) { | ||
var input = rollupConfig.input, exportName = rollupConfig.exportName; | ||
var exportPath = getExportPath(pkg, exportName); | ||
// Log original entry file relative path | ||
var source = typeof input.input === "string" ? path.relative(config.rootDir, input.input) : exportPath; | ||
var buildMetadata = { | ||
source: source | ||
}; | ||
if (options.watch) { | ||
return Promise.resolve(runWatch(rollupConfig, buildMetadata)); | ||
} | ||
return runBundle(rollupConfig, buildMetadata); | ||
}; | ||
if (!!fs__default["default"].existsSync(entryPath)) return [ | ||
3, | ||
2 | ||
]; | ||
hasSpecifiedEntryFile = entryPath === "" ? false : fs__default["default"].statSync(entryPath).isFile(); | ||
if (!hasSpecifiedEntryFile && !hasMultiEntries) { | ||
err = new Error("Entry file `" + entryPath + "` is not existed"); | ||
err.name = "NOT_EXISTED"; | ||
return [ | ||
2, | ||
Promise.reject(err) | ||
]; | ||
} | ||
hasTypings = !!getTypings(pkg) || typeof packageExports === "object" && Array.from(Object.values(packageExports || {})).some(function(condition) { | ||
return condition.hasOwnProperty("types"); | ||
}); | ||
// If there's no entry file specified, should enable dts bundling based on package.json exports info | ||
if (!hasSpecifiedEntryFile && hasTypings) { | ||
options.dts = hasTypings; | ||
} | ||
if (!hasMultiEntries) return [ | ||
3, | ||
2 | ||
]; | ||
assetsJobs = buildEntryConfig(packageExports, false).map(function(rollupConfig) { | ||
return bundleOrWatch(rollupConfig); | ||
}); | ||
typesJobs = options.dts ? buildEntryConfig(packageExports, true).map(function(rollupConfig) { | ||
return bundleOrWatch(rollupConfig); | ||
}) : []; | ||
return [ | ||
4, | ||
Promise.all(assetsJobs.concat(typesJobs)) | ||
]; | ||
case 1: | ||
return [ | ||
2, | ||
_state.sent() | ||
]; | ||
case 2: | ||
if (!(isTypescript(entryPath) && options.dts)) return [ | ||
3, | ||
4 | ||
]; | ||
return [ | ||
4, | ||
bundleOrWatch(buildConfig(entryPath, pkg, options, true)) | ||
]; | ||
case 3: | ||
_state.sent(); | ||
_state.label = 4; | ||
case 4: | ||
rollupConfig = buildConfig(entryPath, pkg, options, false); | ||
return [ | ||
2, | ||
bundleOrWatch(rollupConfig) | ||
]; | ||
const bundleOrWatch = (rollupConfig)=>{ | ||
const { input , exportName } = rollupConfig; | ||
const exportPath = getExportPath(pkg, exportName); | ||
// Log original entry file relative path | ||
const source = typeof input.input === 'string' ? path.relative(config.rootDir, input.input) : exportPath; | ||
const buildMetadata = { | ||
source | ||
}; | ||
if (options.watch) { | ||
return Promise.resolve(runWatch(rollupConfig, buildMetadata)); | ||
} | ||
}); | ||
return runBundle(rollupConfig, buildMetadata); | ||
}; | ||
if (!fs.existsSync(entryPath)) { | ||
const hasSpecifiedEntryFile = entryPath === '' ? false : fs.statSync(entryPath).isFile(); | ||
if (!hasSpecifiedEntryFile && !hasMultiEntries) { | ||
const err = new Error(`Entry file \`${entryPath}\` is not existed`); | ||
err.name = 'NOT_EXISTED'; | ||
return Promise.reject(err); | ||
} | ||
// has `types` field in package.json or has `types` exports in any export condition for multi-entries | ||
const hasTypings = !!getTypings(pkg) || typeof packageExports === 'object' && Array.from(Object.values(packageExports || {})).some((condition)=>condition.hasOwnProperty('types')); | ||
// If there's no entry file specified, should enable dts bundling based on package.json exports info | ||
if (!hasSpecifiedEntryFile && hasTypings) { | ||
options.dts = hasTypings; | ||
} | ||
if (hasMultiEntries) { | ||
const assetsJobs = buildEntryConfig(packageExports, false).map((rollupConfig)=>bundleOrWatch(rollupConfig)); | ||
const typesJobs = options.dts ? buildEntryConfig(packageExports, true).map((rollupConfig)=>bundleOrWatch(rollupConfig)) : []; | ||
return yield Promise.all(assetsJobs.concat(typesJobs)); | ||
} | ||
} | ||
// Generate types | ||
if (isTypescript(entryPath) && options.dts) { | ||
yield bundleOrWatch(buildConfig(entryPath, pkg, options, true)); | ||
} | ||
const rollupConfig = buildConfig(entryPath, pkg, options, false); | ||
return bundleOrWatch(rollupConfig); | ||
}); | ||
@@ -780,9 +606,8 @@ return _bundle.apply(this, arguments); | ||
function getExportPath(pkg, exportName) { | ||
var name = pkg.name || path.basename(config.rootDir); | ||
if (exportName === "." || !exportName) return name; | ||
const name = pkg.name || path.basename(config.rootDir); | ||
if (exportName === '.' || !exportName) return name; | ||
return path.join(name, exportName); | ||
} | ||
function runWatch(param, metadata) { | ||
var input = param.input, output = param.output, dtsOnly = param.dtsOnly; | ||
var watchOptions = [ | ||
function runWatch({ input , output , dtsOnly }, metadata) { | ||
const watchOptions = [ | ||
_extends({}, input, { | ||
@@ -792,3 +617,3 @@ output: output, | ||
exclude: [ | ||
"node_modules/**" | ||
'node_modules/**' | ||
] | ||
@@ -798,19 +623,19 @@ } | ||
]; | ||
var watcher = rollup.watch(watchOptions); | ||
var startTime = Date.now(); | ||
watcher.on("event", function(event) { | ||
const watcher = rollup.watch(watchOptions); | ||
let startTime = Date.now(); | ||
watcher.on('event', (event)=>{ | ||
switch(event.code){ | ||
case "ERROR": | ||
case 'ERROR': | ||
{ | ||
return onError(event.error); | ||
} | ||
case "START": | ||
case 'START': | ||
{ | ||
startTime = Date.now(); | ||
logger.log("Start building " + metadata.source + " ..."); | ||
logger.log(`Start building ${metadata.source} ...`); | ||
break; | ||
} | ||
case "END": | ||
case 'END': | ||
{ | ||
var duration = Date.now() - startTime; | ||
const duration = Date.now() - startTime; | ||
logBuild(metadata.source, dtsOnly, duration); | ||
@@ -825,12 +650,9 @@ break; | ||
} | ||
function runBundle(param, jobOptions) { | ||
var input = param.input, output = param.output, dtsOnly = param.dtsOnly; | ||
var startTime = Date.now(); | ||
return rollup.rollup(input).then(function(bundle) { | ||
var writeJobs = output.map(function(options) { | ||
return bundle.write(options); | ||
}); | ||
function runBundle({ input , output , dtsOnly }, jobOptions) { | ||
const startTime = Date.now(); | ||
return rollup.rollup(input).then((bundle)=>{ | ||
const writeJobs = output.map((options)=>bundle.write(options)); | ||
return Promise.all(writeJobs); | ||
}, onError).then(function() { | ||
var duration = Date.now() - startTime; | ||
}, onError).then(()=>{ | ||
const duration = Date.now() - startTime; | ||
logBuild(jobOptions.source, dtsOnly, duration); | ||
@@ -843,6 +665,6 @@ }); | ||
if (error.frame) { | ||
process.stderr.write(error.frame + "\n"); | ||
process.stderr.write(error.frame + '\n'); | ||
} | ||
// filter out the rollup plugin error information such as loc/frame/code... | ||
var err = new Error(error.message); | ||
const err = new Error(error.message); | ||
err.stack = error.stack; | ||
@@ -849,0 +671,0 @@ throw err; |
{ | ||
"name": "bunchee", | ||
"version": "2.2.0", | ||
"version": "3.0.0-beta.10", | ||
"description": "zero config bundler for js/ts/jsx libraries", | ||
@@ -41,11 +41,11 @@ "bin": { | ||
"dependencies": { | ||
"@rollup/plugin-commonjs": "22.0.2", | ||
"@rollup/plugin-json": "4.1.0", | ||
"@rollup/plugin-node-resolve": "14.1.0", | ||
"@swc/core": "^1.3.5", | ||
"arg": "5.0.0", | ||
"rollup": "2.79.1", | ||
"rollup-plugin-dts": "4.2.3", | ||
"@rollup/plugin-commonjs": "24.0.1", | ||
"@rollup/plugin-json": "6.0.0", | ||
"@rollup/plugin-node-resolve": "15.0.1", | ||
"@swc/core": "1.3.35", | ||
"arg": "5.0.2", | ||
"rollup": "3.15.0", | ||
"rollup-plugin-dts": "5.1.1", | ||
"rollup-plugin-preserve-shebang": "1.0.1", | ||
"rollup-plugin-swc3": "0.6.0", | ||
"rollup-plugin-swc3": "0.8.0", | ||
"tslib": "2.4.0" | ||
@@ -66,4 +66,4 @@ }, | ||
"react": "18.2.0", | ||
"tsx": "3.9.0", | ||
"typescript": "4.8.2" | ||
"tsx": "3.12.3", | ||
"typescript": "4.9.5" | ||
}, | ||
@@ -70,0 +70,0 @@ "jest": { |
@@ -16,7 +16,4 @@ # bunchee | ||
Bunchee can help you to bundle your library into one file with zero configuration. It's built on top of rollup and SWC ⚡️. | ||
Bunchee makes bundling your library into one file effortless, with zero configuration required. It is built on top of Rollup and SWC ⚡️, allowing you to focus on writing code and generating multiple module types (CommonJS, ESModules) simultaneously. | ||
Let you focus on writing code and can generate multiple types of module (CommonJS, ESModules) at the same time. | ||
## Installation | ||
@@ -29,9 +26,8 @@ | ||
## Usage | ||
### Basic | ||
### Package.json Configuration | ||
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`. | ||
Declare the main and module fields in your package.json file, then call the bunchee CLI in the build scripts. If you are using TypeScript, types will be generated automatically based on the typings or types field in your package.json file. | ||
#### Configure `main` and `module` fields | ||
* `main` + `module` | ||
You can have Commonjs + ESModules output as the simple config | ||
@@ -50,6 +46,9 @@ | ||
* `exports` [sugar](https://nodejs.org/api/packages.html#exports-sugar) | ||
#### Configure `exports` field | ||
Leverage `exports` field to support different conditions would be also ideal. Most of the bundler such as `webpack` can already handle the [`package exports`](https://webpack.js.org/guides/package-exports/) well. It's convenient to define multiple conditions in exports. | ||
[exports sugar in Node.js](https://nodejs.org/api/packages.html#exports-sugar) | ||
You can use the exports field to support different conditions and leverage the same functionality as other bundlers, such as webpack. The exports field allows you to define multiple conditions. | ||
```json | ||
@@ -81,3 +80,3 @@ { | ||
-h, --help output usage information | ||
--target <target> js features target: swc target es versions. default: es5 | ||
--target <target> js features target: swc target es versions. default: es2015 | ||
--runtime <runtime> build runtime (nodejs, browser). default: browser | ||
@@ -123,2 +122,6 @@ --cwd <cwd> specify current working directory | ||
#### Watch Mode | ||
Bunchee offers a convenient watch mode for rebuilding your library whenever changes are made to the source files. To enable this feature, use either -w or --watch. | ||
### Typescript | ||
@@ -137,2 +140,6 @@ | ||
#### `target` | ||
If you specify `target` option in `tsconfig.json`, then you don't have to pass it again through CLI. | ||
## Advanced | ||
@@ -139,0 +146,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
185
36110
844
2
+ Added@fastify/deepmerge@1.3.0(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@rollup/plugin-commonjs@24.0.1(transitive)
+ Added@rollup/plugin-json@6.0.0(transitive)
+ Added@rollup/plugin-node-resolve@15.0.1(transitive)
+ Added@rollup/pluginutils@5.1.3(transitive)
+ Added@swc/core@1.3.35(transitive)
+ Added@swc/core-darwin-arm64@1.3.35(transitive)
+ Added@swc/core-darwin-x64@1.3.35(transitive)
+ Added@swc/core-linux-arm-gnueabihf@1.3.35(transitive)
+ Added@swc/core-linux-arm64-gnu@1.3.35(transitive)
+ Added@swc/core-linux-arm64-musl@1.3.35(transitive)
+ Added@swc/core-linux-x64-gnu@1.3.35(transitive)
+ Added@swc/core-linux-x64-musl@1.3.35(transitive)
+ Added@swc/core-win32-arm64-msvc@1.3.35(transitive)
+ Added@swc/core-win32-ia32-msvc@1.3.35(transitive)
+ Added@swc/core-win32-x64-msvc@1.3.35(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@types/resolve@1.20.2(transitive)
+ Addedarg@5.0.2(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedglob@8.1.0(transitive)
+ Addedmagic-string@0.27.0(transitive)
+ Addedminimatch@5.1.6(transitive)
+ Addedpicomatch@4.0.2(transitive)
+ Addedrollup@3.15.0(transitive)
+ Addedrollup-plugin-dts@5.1.1(transitive)
+ Addedrollup-plugin-swc3@0.8.0(transitive)
- Removed@rollup/plugin-commonjs@22.0.2(transitive)
- Removed@rollup/plugin-json@4.1.0(transitive)
- Removed@rollup/plugin-node-resolve@14.1.0(transitive)
- Removed@rollup/pluginutils@3.1.0(transitive)
- Removed@swc/core@1.8.0(transitive)
- Removed@swc/core-darwin-arm64@1.8.0(transitive)
- Removed@swc/core-darwin-x64@1.8.0(transitive)
- Removed@swc/core-linux-arm-gnueabihf@1.8.0(transitive)
- Removed@swc/core-linux-arm64-gnu@1.8.0(transitive)
- Removed@swc/core-linux-arm64-musl@1.8.0(transitive)
- Removed@swc/core-linux-x64-gnu@1.8.0(transitive)
- Removed@swc/core-linux-x64-musl@1.8.0(transitive)
- Removed@swc/core-win32-arm64-msvc@1.8.0(transitive)
- Removed@swc/core-win32-ia32-msvc@1.8.0(transitive)
- Removed@swc/core-win32-x64-msvc@1.8.0(transitive)
- Removed@swc/counter@0.1.3(transitive)
- Removed@swc/types@0.1.14(transitive)
- Removed@types/estree@0.0.39(transitive)
- Removed@types/node@22.9.0(transitive)
- Removed@types/resolve@1.17.1(transitive)
- Removedarg@5.0.0(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedestree-walker@1.0.1(transitive)
- Removedglob@7.2.3(transitive)
- Removedmagic-string@0.26.7(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedrollup@2.79.1(transitive)
- Removedrollup-plugin-dts@4.2.3(transitive)
- Removedrollup-plugin-swc3@0.6.0(transitive)
- Removedundici-types@6.19.8(transitive)
Updated@rollup/plugin-json@6.0.0
Updated@swc/core@1.3.35
Updatedarg@5.0.2
Updatedrollup@3.15.0
Updatedrollup-plugin-dts@5.1.1
Updatedrollup-plugin-swc3@0.8.0