bunchee 2.0.0-beta.2 → 2.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/{src/cli.d.ts → cli.d.ts} +0 -0
- package/dist/cli.js +18 -8
- package/dist/lib.d.ts +2 -0
- package/dist/{index.js → lib.js} +143 -66
- package/dist/src/bundle.d.ts +1 -1
- package/dist/src/rollup-config.d.ts +2 -2
- package/dist/src/types.d.ts +14 -10
- package/dist/src/utils.d.ts +2 -1
- package/package.json +21 -14
- package/dist/src/index.d.ts +0 -2
- package/dist/src/src/bundle.d.ts +0 -3
- package/dist/src/src/cli.d.ts +0 -2
- package/dist/src/src/config.d.ts +0 -4
- package/dist/src/src/index.d.ts +0 -2
- package/dist/src/src/rollup-config.d.ts +0 -3
- package/dist/src/src/types.d.ts +0 -39
- package/dist/src/src/utils.d.ts +0 -21
package/README.md
CHANGED
|
@@ -75,8 +75,9 @@ Options:
|
|
|
75
75
|
-f, --format <format> specify bundle type: "esm", "cjs", "umd". "esm" by default
|
|
76
76
|
-e, --external <mod> specify an external dependency
|
|
77
77
|
-h, --help output usage information
|
|
78
|
-
--target <target>
|
|
79
|
-
--
|
|
78
|
+
--target <target> js features target: swc target es versions. "es5" by default
|
|
79
|
+
--runtime <runtime> build runtime: "nodejs", "browser". "browser" by default
|
|
80
|
+
--sourcemap enable sourcemap generation, false by default
|
|
80
81
|
--cwd <cwd> specify current working directory
|
|
81
82
|
|
|
82
83
|
Usage:
|
|
File without changes
|
package/dist/cli.js
CHANGED
|
@@ -21,6 +21,7 @@ function parseCliArgs(argv) {
|
|
|
21
21
|
"--minify": Boolean,
|
|
22
22
|
"--help": Boolean,
|
|
23
23
|
"--version": Boolean,
|
|
24
|
+
"--runtime": String,
|
|
24
25
|
"--target": String,
|
|
25
26
|
"--sourcemap": Boolean,
|
|
26
27
|
"--external": [
|
|
@@ -48,6 +49,7 @@ function parseCliArgs(argv) {
|
|
|
48
49
|
cwd: args["--cwd"],
|
|
49
50
|
help: args["--help"],
|
|
50
51
|
version: args["--version"],
|
|
52
|
+
runtime: args["--runtime"],
|
|
51
53
|
target: args["--target"],
|
|
52
54
|
external: args["--external"]
|
|
53
55
|
};
|
|
@@ -85,23 +87,23 @@ var logger = {
|
|
|
85
87
|
}
|
|
86
88
|
};
|
|
87
89
|
|
|
88
|
-
var version = "2.0.0-beta.
|
|
90
|
+
var version = "2.0.0-beta.5";
|
|
89
91
|
|
|
90
|
-
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 -e, --external <mod> specify an external dependency\n --target <target> build
|
|
92
|
+
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 -e, --external <mod> specify an external dependency\n --target <target> js features target: swc target es versions. "es5" by default\n --runtime <runtime> build runtime: "nodejs", "browser". "browser" by default\n --sourcemap enable sourcemap generation, false by default\n --cwd <cwd> specify current working directory\n -h, --help output usage information\n';
|
|
91
93
|
function help() {
|
|
92
94
|
console.log(helpMessage);
|
|
93
95
|
}
|
|
94
96
|
function exit(err) {
|
|
95
97
|
logger.error(err);
|
|
96
|
-
process.exit(
|
|
98
|
+
process.exit(1);
|
|
97
99
|
}
|
|
98
100
|
function run(args) {
|
|
99
101
|
return tslib.__awaiter(this, void 0, void 0, function() {
|
|
100
|
-
var source, format, watch, minify, sourcemap, target, cwd, file, outputConfig, entry, bundle, err_1;
|
|
102
|
+
var source, format, watch, minify, sourcemap, target, runtime, cwd, file, outputConfig, entry, bundle, timeStart, timeEnd, err_1, duration;
|
|
101
103
|
return tslib.__generator(this, function(_a) {
|
|
102
104
|
switch(_a.label){
|
|
103
105
|
case 0:
|
|
104
|
-
source = args.source, format = args.format, watch = args.watch, minify = args.minify, sourcemap = args.sourcemap, target = args.target;
|
|
106
|
+
source = args.source, format = args.format, watch = args.watch, minify = args.minify, sourcemap = args.sourcemap, target = args.target, runtime = args.runtime;
|
|
105
107
|
cwd = args.cwd || process.cwd();
|
|
106
108
|
file = args.file ? path__default["default"].resolve(cwd, args.file) : args.file;
|
|
107
109
|
outputConfig = {
|
|
@@ -109,6 +111,7 @@ function run(args) {
|
|
|
109
111
|
format: format,
|
|
110
112
|
cwd: cwd,
|
|
111
113
|
target: target,
|
|
114
|
+
runtime: runtime,
|
|
112
115
|
external: args.external || [],
|
|
113
116
|
watch: !!watch,
|
|
114
117
|
minify: !!minify,
|
|
@@ -127,7 +130,8 @@ function run(args) {
|
|
|
127
130
|
];
|
|
128
131
|
}
|
|
129
132
|
entry = source ? path__default["default"].resolve(cwd, source) : "";
|
|
130
|
-
bundle = require("
|
|
133
|
+
bundle = require("./lib").bundle;
|
|
134
|
+
timeStart = Date.now();
|
|
131
135
|
_a.label = 1;
|
|
132
136
|
case 1:
|
|
133
137
|
_a.trys.push([
|
|
@@ -141,9 +145,11 @@ function run(args) {
|
|
|
141
145
|
bundle(entry, outputConfig)
|
|
142
146
|
];
|
|
143
147
|
case 2:
|
|
148
|
+
_a.sent();
|
|
149
|
+
timeEnd = Date.now();
|
|
144
150
|
return [
|
|
145
|
-
|
|
146
|
-
|
|
151
|
+
3,
|
|
152
|
+
4
|
|
147
153
|
];
|
|
148
154
|
case 3:
|
|
149
155
|
err_1 = _a.sent();
|
|
@@ -156,6 +162,10 @@ function run(args) {
|
|
|
156
162
|
}
|
|
157
163
|
throw err_1;
|
|
158
164
|
case 4:
|
|
165
|
+
duration = timeEnd - timeStart;
|
|
166
|
+
if (!watch) {
|
|
167
|
+
logger.log("✅ Finished in ".concat(duration, " ms"));
|
|
168
|
+
}
|
|
159
169
|
return [
|
|
160
170
|
2
|
|
161
171
|
];
|
package/dist/lib.d.ts
ADDED
package/dist/{index.js → lib.js}
RENAMED
|
@@ -87,7 +87,8 @@ function resolveTypescript() {
|
|
|
87
87
|
} catch (_) {
|
|
88
88
|
if (!hasLoggedTsWarning) {
|
|
89
89
|
hasLoggedTsWarning = true;
|
|
90
|
-
logger.
|
|
90
|
+
logger.error("Could not load TypeScript compiler. Try `yarn add --dev typescript`");
|
|
91
|
+
process.exit(1);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
return ts;
|
|
@@ -111,12 +112,26 @@ function createInputConfig(entry, pkg, options) {
|
|
|
111
112
|
}, []).concat(((_b = options.external) !== null && _b !== void 0 ? _b : []).concat(pkg.name ? [
|
|
112
113
|
pkg.name
|
|
113
114
|
] : []));
|
|
114
|
-
var useTypescript = options.useTypescript,
|
|
115
|
+
var useTypescript = options.useTypescript, runtime = options.runtime, jscTarget = options.target, minify = options.minify, exportCondition = options.exportCondition;
|
|
115
116
|
var typings = pkg.types || pkg.typings;
|
|
116
117
|
var cwd = config.rootDir;
|
|
118
|
+
var tsPath;
|
|
119
|
+
var declarationDir;
|
|
120
|
+
if (useTypescript) {
|
|
121
|
+
var tsconfig = path.resolve(cwd, "tsconfig.json");
|
|
122
|
+
tsPath = fs__default["default"].existsSync(tsconfig) ? tsconfig : undefined;
|
|
123
|
+
if (typings) {
|
|
124
|
+
declarationDir = path.dirname(path.resolve(cwd, typings));
|
|
125
|
+
}
|
|
126
|
+
if (exportCondition) {
|
|
127
|
+
var exportConditionDistFolder = path.dirname(typeof exportCondition.export === "string" ? exportCondition.export : Object.values(exportCondition.export)[0]);
|
|
128
|
+
declarationDir = path.resolve(config.rootDir, exportConditionDistFolder);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
var isMainExport = !exportCondition || exportCondition.name === ".";
|
|
117
132
|
var plugins = [
|
|
118
133
|
nodeResolve__default["default"]({
|
|
119
|
-
preferBuiltins:
|
|
134
|
+
preferBuiltins: runtime === "node",
|
|
120
135
|
extensions: [
|
|
121
136
|
".mjs",
|
|
122
137
|
".js",
|
|
@@ -130,11 +145,8 @@ function createInputConfig(entry, pkg, options) {
|
|
|
130
145
|
}),
|
|
131
146
|
json__default["default"](),
|
|
132
147
|
shebang__default["default"](),
|
|
133
|
-
useTypescript && require("@rollup/plugin-typescript")(tslib.__assign({
|
|
134
|
-
tsconfig:
|
|
135
|
-
var tsconfig = path.resolve(cwd, "tsconfig.json");
|
|
136
|
-
return fs__default["default"].existsSync(tsconfig) ? tsconfig : undefined;
|
|
137
|
-
}(),
|
|
148
|
+
useTypescript && isMainExport && require("@rollup/plugin-typescript")(tslib.__assign({
|
|
149
|
+
tsconfig: tsPath,
|
|
138
150
|
typescript: resolveTypescript(),
|
|
139
151
|
jsx: "react",
|
|
140
152
|
module: "ES6",
|
|
@@ -144,21 +156,23 @@ function createInputConfig(entry, pkg, options) {
|
|
|
144
156
|
declaration: !!typings,
|
|
145
157
|
emitDeclarationOnly: true
|
|
146
158
|
}, !!typings && {
|
|
147
|
-
declarationDir:
|
|
159
|
+
declarationDir: declarationDir
|
|
148
160
|
})),
|
|
149
161
|
rollupPluginSwc3.swc({
|
|
150
162
|
include: /\.(m|c)?[jt]sx?$/,
|
|
151
163
|
exclude: "node_modules",
|
|
152
164
|
tsconfig: "tsconfig.json",
|
|
153
165
|
jsc: tslib.__assign({
|
|
154
|
-
target:
|
|
166
|
+
target: jscTarget,
|
|
155
167
|
loose: true,
|
|
156
168
|
externalHelpers: false,
|
|
157
169
|
parser: (_a = {
|
|
158
170
|
syntax: useTypescript ? "typescript" : "ecmascript"
|
|
159
171
|
}, _a[useTypescript ? "tsx" : "jsx"] = true, _a.privateMethod = true, _a.classPrivateProperty = true, _a.exportDefaultFrom = true, _a)
|
|
160
172
|
}, minify && {
|
|
161
|
-
minify: minifyOptions
|
|
173
|
+
minify: tslib.__assign(tslib.__assign({}, minifyOptions), {
|
|
174
|
+
sourceMap: options.sourcemap
|
|
175
|
+
})
|
|
162
176
|
}),
|
|
163
177
|
sourceMaps: options.sourcemap,
|
|
164
178
|
inlineSourcesContent: false
|
|
@@ -178,10 +192,15 @@ function createInputConfig(entry, pkg, options) {
|
|
|
178
192
|
propertyReadSideEffects: false
|
|
179
193
|
},
|
|
180
194
|
onwarn: function onwarn(warning, warn) {
|
|
181
|
-
|
|
195
|
+
var code = warning.code || "";
|
|
196
|
+
if ([
|
|
182
197
|
"MIXED_EXPORTS",
|
|
183
|
-
"PREFER_NAMED_EXPORTS"
|
|
184
|
-
|
|
198
|
+
"PREFER_NAMED_EXPORTS",
|
|
199
|
+
"THIS_IS_UNDEFINED"
|
|
200
|
+
].includes(code)) return;
|
|
201
|
+
if (code === "CIRCULAR_DEPENDENCY" && /Circular dependency: node_modules/.test(warning.message)) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
185
204
|
warn(warning);
|
|
186
205
|
}
|
|
187
206
|
};
|
|
@@ -202,8 +221,7 @@ function createOutputOptions(options, pkg) {
|
|
|
202
221
|
var file = path.resolve(options.file);
|
|
203
222
|
return {
|
|
204
223
|
name: pkg.name,
|
|
205
|
-
|
|
206
|
-
entryFileNames: path.basename(file),
|
|
224
|
+
file: file,
|
|
207
225
|
format: format,
|
|
208
226
|
exports: "named",
|
|
209
227
|
esModule: useEsModuleMark && format !== "umd",
|
|
@@ -282,54 +300,53 @@ function getExportDist(pkg) {
|
|
|
282
300
|
}
|
|
283
301
|
if (dist.length === 0) {
|
|
284
302
|
dist.push({
|
|
285
|
-
format: "
|
|
303
|
+
format: "esm",
|
|
286
304
|
file: getDistPath("dist/index.js")
|
|
287
305
|
});
|
|
288
306
|
}
|
|
289
307
|
return dist;
|
|
290
308
|
}
|
|
291
|
-
function getSubExportDist(pkg,
|
|
292
|
-
var pkgExports = pkg.exports || {};
|
|
309
|
+
function getSubExportDist(pkg, exportCondition) {
|
|
293
310
|
var dist = [];
|
|
294
|
-
if (typeof
|
|
311
|
+
if (typeof exportCondition === "string") {
|
|
295
312
|
dist.push({
|
|
296
313
|
format: pkg.type === "module" ? "esm" : "cjs",
|
|
297
|
-
file: getDistPath(
|
|
314
|
+
file: getDistPath(exportCondition)
|
|
298
315
|
});
|
|
299
316
|
} else {
|
|
300
|
-
var
|
|
301
|
-
if (
|
|
302
|
-
if (typeof exports_1 === "string") {
|
|
317
|
+
var subExports = exportCondition;
|
|
318
|
+
if (typeof subExports === "string") {
|
|
303
319
|
dist.push({
|
|
304
320
|
format: "esm",
|
|
305
|
-
file: getDistPath(
|
|
321
|
+
file: getDistPath(subExports)
|
|
306
322
|
});
|
|
307
323
|
} else {
|
|
308
|
-
if (
|
|
324
|
+
if (subExports.require) {
|
|
309
325
|
dist.push({
|
|
310
326
|
format: "cjs",
|
|
311
|
-
file: getDistPath(
|
|
327
|
+
file: getDistPath(subExports.require)
|
|
312
328
|
});
|
|
313
329
|
}
|
|
314
|
-
if (
|
|
330
|
+
if (subExports.import) {
|
|
315
331
|
dist.push({
|
|
316
332
|
format: "esm",
|
|
317
|
-
file: getDistPath(
|
|
333
|
+
file: getDistPath(subExports.import)
|
|
318
334
|
});
|
|
319
335
|
}
|
|
320
336
|
}
|
|
321
337
|
}
|
|
322
338
|
return dist;
|
|
323
339
|
}
|
|
324
|
-
function createRollupConfig(entry, pkg, cliArgs
|
|
325
|
-
var
|
|
340
|
+
function createRollupConfig(entry, pkg, cliArgs) {
|
|
341
|
+
var _a, _b;
|
|
342
|
+
var file = cliArgs.file;
|
|
326
343
|
var ext = path.extname(entry);
|
|
327
344
|
var useTypescript = ext === ".ts" || ext === ".tsx";
|
|
328
345
|
var options = tslib.__assign(tslib.__assign({}, cliArgs), {
|
|
329
346
|
useTypescript: useTypescript
|
|
330
347
|
});
|
|
331
348
|
var inputOptions = createInputConfig(entry, pkg, options);
|
|
332
|
-
var outputExports =
|
|
349
|
+
var outputExports = options.exportCondition ? getSubExportDist(pkg, options.exportCondition.export) : getExportDist(pkg);
|
|
333
350
|
var outputConfigs = outputExports.map(function(exportDist) {
|
|
334
351
|
return createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), {
|
|
335
352
|
file: exportDist.file,
|
|
@@ -338,17 +355,19 @@ function createRollupConfig(entry, pkg, cliArgs, entryExport) {
|
|
|
338
355
|
}), pkg);
|
|
339
356
|
});
|
|
340
357
|
if (file) {
|
|
358
|
+
var format = (_a = outputExports[0]) === null || _a === void 0 ? void 0 : _a.format;
|
|
341
359
|
outputConfigs = [
|
|
342
360
|
createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), {
|
|
343
361
|
file: file,
|
|
344
|
-
format: format,
|
|
362
|
+
format: format || cliArgs.format,
|
|
345
363
|
useTypescript: useTypescript
|
|
346
|
-
}), pkg)
|
|
364
|
+
}), pkg),
|
|
347
365
|
];
|
|
348
366
|
}
|
|
349
367
|
return {
|
|
350
368
|
input: inputOptions,
|
|
351
|
-
output: outputConfigs
|
|
369
|
+
output: outputConfigs,
|
|
370
|
+
exportName: ((_b = options.exportCondition) === null || _b === void 0 ? void 0 : _b.name) || pkg.name
|
|
352
371
|
};
|
|
353
372
|
}
|
|
354
373
|
|
|
@@ -357,6 +376,26 @@ function assignDefault(options, name, defaultValue) {
|
|
|
357
376
|
options[name] = defaultValue;
|
|
358
377
|
}
|
|
359
378
|
}
|
|
379
|
+
function getSourcePathFromExportPath(cwd, exportPath) {
|
|
380
|
+
var exts = [
|
|
381
|
+
"js",
|
|
382
|
+
"cjs",
|
|
383
|
+
"mjs",
|
|
384
|
+
"jsx",
|
|
385
|
+
"ts",
|
|
386
|
+
"tsx"
|
|
387
|
+
];
|
|
388
|
+
for(var _i = 0, exts_1 = exts; _i < exts_1.length; _i++){
|
|
389
|
+
var ext = exts_1[_i];
|
|
390
|
+
if (exportPath.endsWith("package.json")) return;
|
|
391
|
+
if (exportPath === ".") exportPath = "./index";
|
|
392
|
+
var filename = path.resolve(cwd, "".concat(exportPath, ".").concat(ext));
|
|
393
|
+
if (fs__default["default"].existsSync(filename)) {
|
|
394
|
+
return filename;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
360
399
|
function bundle(entryPath, _a) {
|
|
361
400
|
if (_a === void 0) {
|
|
362
401
|
_a = {};
|
|
@@ -366,17 +405,23 @@ function bundle(entryPath, _a) {
|
|
|
366
405
|
]);
|
|
367
406
|
config.rootDir = path.resolve(process.cwd(), cwd || "");
|
|
368
407
|
assignDefault(options, "format", "es");
|
|
408
|
+
assignDefault(options, "minify", false);
|
|
409
|
+
assignDefault(options, "target", "es5");
|
|
369
410
|
if (options.format === "esm") {
|
|
370
411
|
options.format = "es";
|
|
371
412
|
}
|
|
372
|
-
var
|
|
373
|
-
var
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
var
|
|
377
|
-
|
|
413
|
+
var pkg = getPackageMeta();
|
|
414
|
+
var packageExports = pkg.exports;
|
|
415
|
+
var isSingleEntry = typeof packageExports === "string";
|
|
416
|
+
var hasMultiEntries = packageExports && !isSingleEntry && Object.keys(packageExports).length > 0;
|
|
417
|
+
var bundleOrWatch = function bundleOrWatch(rollupConfig) {
|
|
418
|
+
if (options.watch) {
|
|
419
|
+
return Promise.resolve(runWatch(pkg, rollupConfig));
|
|
420
|
+
}
|
|
421
|
+
return runBundle(pkg, rollupConfig);
|
|
422
|
+
};
|
|
378
423
|
if (isSingleEntry) {
|
|
379
|
-
entryPath =
|
|
424
|
+
entryPath = getSourcePathFromExportPath(config.rootDir, ".");
|
|
380
425
|
}
|
|
381
426
|
if (!fs__default["default"].existsSync(entryPath)) {
|
|
382
427
|
var hasEntryFile = entryPath === "" ? "" : fs__default["default"].statSync(entryPath).isFile();
|
|
@@ -386,26 +431,34 @@ function bundle(entryPath, _a) {
|
|
|
386
431
|
return Promise.reject(err);
|
|
387
432
|
}
|
|
388
433
|
if (hasMultiEntries) {
|
|
389
|
-
Object.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
434
|
+
var rollupConfigs = Object.keys(packageExports).map(function(entryExport) {
|
|
435
|
+
var source = getSourcePathFromExportPath(config.rootDir, entryExport);
|
|
436
|
+
if (!source) return;
|
|
437
|
+
options.exportCondition = {
|
|
438
|
+
source: source,
|
|
439
|
+
name: entryExport,
|
|
440
|
+
export: packageExports[entryExport]
|
|
441
|
+
};
|
|
442
|
+
var rollupConfig = createRollupConfig(path.resolve(cwd, source), pkg, options);
|
|
393
443
|
return rollupConfig;
|
|
444
|
+
}).filter(function(v) {
|
|
445
|
+
return !!v;
|
|
394
446
|
});
|
|
395
447
|
return Promise.all(rollupConfigs.map(function(rollupConfig) {
|
|
396
|
-
return
|
|
448
|
+
return bundleOrWatch(rollupConfig);
|
|
397
449
|
}));
|
|
398
450
|
}
|
|
399
451
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (options.watch) {
|
|
403
|
-
return Promise.resolve(runWatch(rollupConfig));
|
|
404
|
-
}
|
|
405
|
-
return runBundle(rollupConfig);
|
|
452
|
+
var rollupConfig = createRollupConfig(entryPath, pkg, options);
|
|
453
|
+
return bundleOrWatch(rollupConfig);
|
|
406
454
|
}
|
|
407
|
-
function
|
|
408
|
-
var
|
|
455
|
+
function getExportPath(pkg, exportName) {
|
|
456
|
+
var name = pkg.name || "<package>";
|
|
457
|
+
if (exportName === "." || !exportName) return name;
|
|
458
|
+
return path.join(name, exportName);
|
|
459
|
+
}
|
|
460
|
+
function runWatch(pkg, _a) {
|
|
461
|
+
var exportName = _a.exportName, input = _a.input, output = _a.output;
|
|
409
462
|
var watchOptions = [
|
|
410
463
|
tslib.__assign(tslib.__assign({}, input), {
|
|
411
464
|
output: output,
|
|
@@ -414,34 +467,58 @@ function runWatch(_a) {
|
|
|
414
467
|
"node_modules/**"
|
|
415
468
|
]
|
|
416
469
|
}
|
|
417
|
-
})
|
|
470
|
+
}),
|
|
418
471
|
];
|
|
419
472
|
var watcher = rollup.watch(watchOptions);
|
|
473
|
+
var exportPath = getExportPath(pkg, exportName);
|
|
474
|
+
var startTime = Date.now();
|
|
420
475
|
watcher.on("event", function(event) {
|
|
421
|
-
|
|
422
|
-
|
|
476
|
+
switch(event.code){
|
|
477
|
+
case "ERROR":
|
|
478
|
+
{
|
|
479
|
+
return onError(event.error);
|
|
480
|
+
}
|
|
481
|
+
case "START":
|
|
482
|
+
{
|
|
483
|
+
startTime = Date.now();
|
|
484
|
+
logger.log("Start building ".concat(exportPath, " ..."));
|
|
485
|
+
}
|
|
486
|
+
case "END":
|
|
487
|
+
{
|
|
488
|
+
var duration = Date.now() - startTime;
|
|
489
|
+
if (duration > 0) {
|
|
490
|
+
logger.log("✨ Built ".concat(exportPath));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
default:
|
|
494
|
+
return;
|
|
423
495
|
}
|
|
424
496
|
});
|
|
425
497
|
return watcher;
|
|
426
498
|
}
|
|
427
|
-
function runBundle(_a) {
|
|
428
|
-
var input = _a.input, output = _a.output;
|
|
499
|
+
function runBundle(pkg, _a) {
|
|
500
|
+
var exportName = _a.exportName, input = _a.input, output = _a.output;
|
|
501
|
+
var startTime = Date.now();
|
|
429
502
|
return rollup.rollup(input).then(function(bundle) {
|
|
430
503
|
var writeJobs = output.map(function(options) {
|
|
431
504
|
return bundle.write(options);
|
|
432
505
|
});
|
|
433
506
|
return Promise.all(writeJobs);
|
|
434
|
-
}, onError)
|
|
507
|
+
}, onError).then(function() {
|
|
508
|
+
var duration = Date.now() - startTime;
|
|
509
|
+
if (duration > 0) {
|
|
510
|
+
logger.log("✨ Built ".concat(getExportPath(pkg, exportName)));
|
|
511
|
+
}
|
|
512
|
+
});
|
|
435
513
|
}
|
|
436
514
|
function onError(error) {
|
|
437
515
|
if (!error) return;
|
|
438
516
|
if (error.frame) {
|
|
439
|
-
process.
|
|
440
|
-
}
|
|
441
|
-
if (error.stack) {
|
|
442
|
-
process.stdout.write(error.stack + "\n");
|
|
517
|
+
process.stderr.write(error.frame + "\n");
|
|
443
518
|
}
|
|
444
|
-
|
|
519
|
+
var err = new Error(error.message);
|
|
520
|
+
err.stack = error.stack;
|
|
521
|
+
throw err;
|
|
445
522
|
}
|
|
446
523
|
|
|
447
524
|
exports.bundle = bundle;
|
package/dist/src/bundle.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { PackageMetadata, BuncheeRollupConfig, CliArgs } from
|
|
2
|
-
declare function createRollupConfig(entry: string, pkg: PackageMetadata, cliArgs: CliArgs
|
|
1
|
+
import type { PackageMetadata, BuncheeRollupConfig, CliArgs } from './types';
|
|
2
|
+
declare function createRollupConfig(entry: string, pkg: PackageMetadata, cliArgs: CliArgs): BuncheeRollupConfig;
|
|
3
3
|
export default createRollupConfig;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { JscTarget } from '@swc/core';
|
|
2
|
+
import type { InputOptions, OutputOptions, RollupOptions } from 'rollup';
|
|
3
|
+
declare type ExportType = 'require' | 'export' | 'default' | string;
|
|
3
4
|
declare type CommonConfig = {
|
|
4
|
-
format?: OutputOptions[
|
|
5
|
+
format?: OutputOptions['format'];
|
|
5
6
|
minify?: boolean;
|
|
6
7
|
sourcemap?: boolean;
|
|
7
8
|
external?: string[];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
runtime?: string;
|
|
10
|
+
exportCondition?: {
|
|
11
|
+
source: string;
|
|
12
|
+
name: string;
|
|
13
|
+
export: ExportCondition;
|
|
14
|
+
};
|
|
12
15
|
};
|
|
13
16
|
declare type PackageMetadata = {
|
|
14
17
|
name?: string;
|
|
15
18
|
main?: string;
|
|
16
19
|
module?: string;
|
|
17
|
-
type?:
|
|
20
|
+
type?: 'commonjs' | 'module';
|
|
18
21
|
dependencies?: Record<string, string>;
|
|
19
22
|
peerDependencies?: Record<string, string>;
|
|
20
23
|
peerDependenciesMeta?: Record<string, Record<string, string>>;
|
|
21
24
|
exports?: string | Record<string, ExportCondition>;
|
|
22
25
|
types?: string;
|
|
23
26
|
typings?: string;
|
|
24
|
-
bunchee?: BuildConfig;
|
|
25
27
|
};
|
|
26
28
|
declare type ExportCondition = string | Record<ExportType, string>;
|
|
27
29
|
declare type BuncheeRollupConfig = Partial<Omit<RollupOptions, 'input' | 'output'>> & {
|
|
30
|
+
exportName?: string;
|
|
28
31
|
input: InputOptions;
|
|
29
32
|
output: OutputOptions[];
|
|
30
33
|
};
|
|
@@ -32,8 +35,9 @@ declare type CliArgs = CommonConfig & {
|
|
|
32
35
|
file?: string;
|
|
33
36
|
watch?: boolean;
|
|
34
37
|
cwd?: string;
|
|
38
|
+
target?: JscTarget;
|
|
35
39
|
};
|
|
36
40
|
declare type BundleOptions = CliArgs & {
|
|
37
41
|
useTypescript: boolean;
|
|
38
42
|
};
|
|
39
|
-
export type { CliArgs, ExportType, BundleOptions, ExportCondition, PackageMetadata, BuncheeRollupConfig
|
|
43
|
+
export type { CliArgs, ExportType, BundleOptions, ExportCondition, PackageMetadata, BuncheeRollupConfig };
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PackageMetadata } from
|
|
1
|
+
import type { PackageMetadata } from './types';
|
|
2
2
|
export declare function getPackageMeta(): PackageMetadata;
|
|
3
3
|
export declare function resolvePackagePath(pathname: string): string;
|
|
4
4
|
export declare function parseCliArgs(argv: string[]): {
|
|
@@ -11,6 +11,7 @@ export declare function parseCliArgs(argv: string[]): {
|
|
|
11
11
|
cwd: any;
|
|
12
12
|
help: any;
|
|
13
13
|
version: any;
|
|
14
|
+
runtime: any;
|
|
14
15
|
target: any;
|
|
15
16
|
external: any;
|
|
16
17
|
};
|
package/package.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.5",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bunchee": "./dist/cli.js"
|
|
7
7
|
},
|
|
8
|
-
"main": "./dist/
|
|
9
|
-
"types": "./dist/
|
|
8
|
+
"main": "./dist/lib.js",
|
|
9
|
+
"types": "./dist/lib.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "jest --env node",
|
|
12
12
|
"test:update": "TEST_UPDATE_SNAPSHOT=1 yarn test",
|
|
13
13
|
"clean": "rm -rf ./dist",
|
|
14
|
-
"types": "tsc --declaration --declarationDir dist --emitDeclarationOnly",
|
|
15
14
|
"typecheck": "tsc --noEmit",
|
|
16
|
-
"prepublishOnly": "yarn clean && yarn build && chmod +x dist/cli.js && yarn test",
|
|
17
|
-
"build:cli": "tsx
|
|
18
|
-
"build:main": "tsx
|
|
19
|
-
"build": "yarn build:main && yarn build:cli
|
|
15
|
+
"prepublishOnly": "yarn clean && yarn build && chmod +x ./dist/cli.js && yarn test",
|
|
16
|
+
"build:cli": "tsx ./cli.ts ./cli.ts --runtime node -f cjs -o ./dist/cli.js",
|
|
17
|
+
"build:main": "tsx ./cli.ts ./lib.ts --runtime node -f cjs",
|
|
18
|
+
"build": "yarn build:main && yarn build:cli"
|
|
20
19
|
},
|
|
21
20
|
"type": "commonjs",
|
|
22
21
|
"keywords": [
|
|
@@ -35,16 +34,16 @@
|
|
|
35
34
|
"author": "huozhi (github.com/huozhi)",
|
|
36
35
|
"license": "MIT",
|
|
37
36
|
"dependencies": {
|
|
38
|
-
"@rollup/plugin-commonjs": "
|
|
37
|
+
"@rollup/plugin-commonjs": "22.0.2",
|
|
39
38
|
"@rollup/plugin-json": "4.1.0",
|
|
40
39
|
"@rollup/plugin-node-resolve": "13.3.0",
|
|
41
|
-
"@rollup/plugin-typescript": "8.
|
|
40
|
+
"@rollup/plugin-typescript": "8.4.0",
|
|
42
41
|
"@swc/core": "^1.2.244",
|
|
43
42
|
"arg": "5.0.0",
|
|
44
43
|
"rollup": "2.74.1",
|
|
45
44
|
"rollup-plugin-preserve-shebang": "1.0.1",
|
|
46
|
-
"rollup-plugin-swc3": "0.
|
|
47
|
-
"tslib": "2.
|
|
45
|
+
"rollup-plugin-swc3": "0.4.1",
|
|
46
|
+
"tslib": "2.4.0"
|
|
48
47
|
},
|
|
49
48
|
"peerDependencies": {
|
|
50
49
|
"typescript": ">= 3.7.0"
|
|
@@ -55,8 +54,16 @@
|
|
|
55
54
|
}
|
|
56
55
|
},
|
|
57
56
|
"devDependencies": {
|
|
58
|
-
"jest": "
|
|
57
|
+
"jest": "29.0.1",
|
|
59
58
|
"tsx": "3.4.3",
|
|
60
|
-
"typescript": "4.
|
|
59
|
+
"typescript": "4.8.2"
|
|
60
|
+
},
|
|
61
|
+
"jest": {
|
|
62
|
+
"moduleDirectories": [
|
|
63
|
+
"node_modules"
|
|
64
|
+
],
|
|
65
|
+
"moduleNameMapper": {
|
|
66
|
+
"bunchee": "<rootDir>/dist/lib.js"
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
69
|
}
|
package/dist/src/index.d.ts
DELETED
package/dist/src/src/bundle.d.ts
DELETED
package/dist/src/src/cli.d.ts
DELETED
package/dist/src/src/config.d.ts
DELETED
package/dist/src/src/index.d.ts
DELETED
package/dist/src/src/types.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { InputOptions, OutputOptions, RollupOptions } from "rollup";
|
|
2
|
-
declare type ExportType = "require" | "export" | "default" | string;
|
|
3
|
-
declare type CommonConfig = {
|
|
4
|
-
format?: OutputOptions["format"];
|
|
5
|
-
minify?: boolean;
|
|
6
|
-
sourcemap?: boolean;
|
|
7
|
-
external?: string[];
|
|
8
|
-
target?: string;
|
|
9
|
-
};
|
|
10
|
-
declare type BuildConfig = CommonConfig & {
|
|
11
|
-
entry: string | Record<string, string>;
|
|
12
|
-
};
|
|
13
|
-
declare type PackageMetadata = {
|
|
14
|
-
name?: string;
|
|
15
|
-
main?: string;
|
|
16
|
-
module?: string;
|
|
17
|
-
type?: "commonjs" | "module";
|
|
18
|
-
dependencies?: Record<string, string>;
|
|
19
|
-
peerDependencies?: Record<string, string>;
|
|
20
|
-
peerDependenciesMeta?: Record<string, Record<string, string>>;
|
|
21
|
-
exports?: string | Record<string, ExportCondition>;
|
|
22
|
-
types?: string;
|
|
23
|
-
typings?: string;
|
|
24
|
-
bunchee?: BuildConfig;
|
|
25
|
-
};
|
|
26
|
-
declare type ExportCondition = string | Record<ExportType, string>;
|
|
27
|
-
declare type BuncheeRollupConfig = Partial<Omit<RollupOptions, 'input' | 'output'>> & {
|
|
28
|
-
input: InputOptions;
|
|
29
|
-
output: OutputOptions[];
|
|
30
|
-
};
|
|
31
|
-
declare type CliArgs = CommonConfig & {
|
|
32
|
-
file?: string;
|
|
33
|
-
watch?: boolean;
|
|
34
|
-
cwd?: string;
|
|
35
|
-
};
|
|
36
|
-
declare type BundleOptions = CliArgs & {
|
|
37
|
-
useTypescript: boolean;
|
|
38
|
-
};
|
|
39
|
-
export type { CliArgs, ExportType, BundleOptions, ExportCondition, PackageMetadata, BuncheeRollupConfig, };
|
package/dist/src/src/utils.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { PackageMetadata } from "./types";
|
|
2
|
-
export declare function getPackageMeta(): PackageMetadata;
|
|
3
|
-
export declare function resolvePackagePath(pathname: string): string;
|
|
4
|
-
export declare function parseCliArgs(argv: string[]): {
|
|
5
|
-
source: string;
|
|
6
|
-
format: any;
|
|
7
|
-
file: any;
|
|
8
|
-
watch: any;
|
|
9
|
-
minify: any;
|
|
10
|
-
sourcemap: boolean;
|
|
11
|
-
cwd: any;
|
|
12
|
-
help: any;
|
|
13
|
-
version: any;
|
|
14
|
-
target: any;
|
|
15
|
-
external: any;
|
|
16
|
-
};
|
|
17
|
-
export declare const logger: {
|
|
18
|
-
log(...args: any[]): void;
|
|
19
|
-
warn(...args: any[]): void;
|
|
20
|
-
error(...args: any[]): void;
|
|
21
|
-
};
|