bunchee 2.0.0-beta.3 → 2.0.0
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 +65 -13
- 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} +130 -60
- package/dist/src/rollup-config.d.ts +1 -1
- package/dist/src/types.d.ts +9 -5
- package/dist/src/utils.d.ts +1 -0
- package/package.json +20 -13
- 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
|
@@ -54,7 +54,7 @@ Leverage `exports` field to support different conditions would be also ideal. Mo
|
|
|
54
54
|
"exports": {
|
|
55
55
|
"require": "dist/index.cjs",
|
|
56
56
|
"import": "dist/index.mjs",
|
|
57
|
-
"module": "dist/index.esm.js"
|
|
57
|
+
"module": "dist/index.esm.js"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "bunchee ./src/index.js"
|
|
@@ -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:
|
|
@@ -84,15 +85,7 @@ Usage:
|
|
|
84
85
|
$ bunchee ./src/index.ts -o ./dist/bundle.js # specify the dist file path
|
|
85
86
|
```
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
```js
|
|
90
|
-
import { bundle } from 'bunchee'
|
|
91
|
-
|
|
92
|
-
// options is same to CLI options
|
|
93
|
-
await bundle(entryFilePath, options)
|
|
94
|
-
```
|
|
95
|
-
#### Example Scripts
|
|
88
|
+
Run bunchee via CLI
|
|
96
89
|
|
|
97
90
|
```sh
|
|
98
91
|
cd <project-root-dir>
|
|
@@ -103,7 +96,16 @@ bunchee ./src/index.js -f esm -o ./dist/bundle.esm.js
|
|
|
103
96
|
# bunchee ./src/index.js -o ./dist/bundle.esm.js
|
|
104
97
|
```
|
|
105
98
|
|
|
106
|
-
###
|
|
99
|
+
### Node.js API
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
import { bundle } from 'bunchee'
|
|
103
|
+
|
|
104
|
+
// options is same to CLI options
|
|
105
|
+
await bundle(entryFilePath, options)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Typescript
|
|
107
109
|
|
|
108
110
|
By default bunchee includes Typescript v3.9.x inside as a dependency. If you want to use your own version, just install typescript as another dev dependency then bunchee will automatically pick it.
|
|
109
111
|
|
|
@@ -111,4 +113,54 @@ By default bunchee includes Typescript v3.9.x inside as a dependency. If you wan
|
|
|
111
113
|
yarn add -D bunchee typescript
|
|
112
114
|
```
|
|
113
115
|
|
|
116
|
+
Create `tsconfig.json` to specify any compiler options for TypeScript.
|
|
117
|
+
|
|
114
118
|
This library requires at least [TypeScript 3.7](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html).
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Advanced
|
|
122
|
+
|
|
123
|
+
### Multiple Exports
|
|
124
|
+
|
|
125
|
+
While `exports` filed is becoming the standard of exporting in node.js, bunchee also supports to build multiple exports all in one command.
|
|
126
|
+
|
|
127
|
+
What you need to do is just add an entry file with the name (`[name].[ext]`) that matches the exported name from exports field in package.json. For instance:
|
|
128
|
+
|
|
129
|
+
* `index.ts` will match `"."` export name or the if there's only one main export.
|
|
130
|
+
* `lite.ts` will match `"./lite"` export name.
|
|
131
|
+
|
|
132
|
+
The build script will be simplified to just `bunchee` in package.json without configure any input sources for each exports. Of course you can still specify other arguments as you need.
|
|
133
|
+
|
|
134
|
+
#### How it works
|
|
135
|
+
|
|
136
|
+
Assuming you have main entry export `"."` and subpath export `"./lite"` with different exports condition listed in package.json
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
{
|
|
140
|
+
"name": "example",
|
|
141
|
+
"scripts": {
|
|
142
|
+
"build": "bunchee"
|
|
143
|
+
},
|
|
144
|
+
"exports": {
|
|
145
|
+
"./lite": "./dist/lite.js"
|
|
146
|
+
".": {
|
|
147
|
+
"import": "./dist/index.mjs",
|
|
148
|
+
"require": "./dist/index.cjs"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Then you need to add two entry files `index.ts` and `lite.ts` in project root directory to match the export name `"."` and `"./lite"`, bunchee will associate these entry files with export names then use them as input source and output paths information.
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
- example/
|
|
158
|
+
|- lite.ts
|
|
159
|
+
|- index.ts
|
|
160
|
+
|- src/
|
|
161
|
+
|- package.json
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### License
|
|
165
|
+
|
|
166
|
+
MIT
|
|
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
|
|
90
|
+
var version = "2.0.0";
|
|
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,14 +156,14 @@ 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 = {
|
|
@@ -209,8 +221,7 @@ function createOutputOptions(options, pkg) {
|
|
|
209
221
|
var file = path.resolve(options.file);
|
|
210
222
|
return {
|
|
211
223
|
name: pkg.name,
|
|
212
|
-
|
|
213
|
-
entryFileNames: path.basename(file),
|
|
224
|
+
file: file,
|
|
214
225
|
format: format,
|
|
215
226
|
exports: "named",
|
|
216
227
|
esModule: useEsModuleMark && format !== "umd",
|
|
@@ -289,54 +300,53 @@ function getExportDist(pkg) {
|
|
|
289
300
|
}
|
|
290
301
|
if (dist.length === 0) {
|
|
291
302
|
dist.push({
|
|
292
|
-
format: "
|
|
303
|
+
format: "esm",
|
|
293
304
|
file: getDistPath("dist/index.js")
|
|
294
305
|
});
|
|
295
306
|
}
|
|
296
307
|
return dist;
|
|
297
308
|
}
|
|
298
|
-
function getSubExportDist(pkg,
|
|
299
|
-
var pkgExports = pkg.exports || {};
|
|
309
|
+
function getSubExportDist(pkg, exportCondition) {
|
|
300
310
|
var dist = [];
|
|
301
|
-
if (typeof
|
|
311
|
+
if (typeof exportCondition === "string") {
|
|
302
312
|
dist.push({
|
|
303
313
|
format: pkg.type === "module" ? "esm" : "cjs",
|
|
304
|
-
file: getDistPath(
|
|
314
|
+
file: getDistPath(exportCondition)
|
|
305
315
|
});
|
|
306
316
|
} else {
|
|
307
|
-
var
|
|
308
|
-
if (
|
|
309
|
-
if (typeof exports_1 === "string") {
|
|
317
|
+
var subExports = exportCondition;
|
|
318
|
+
if (typeof subExports === "string") {
|
|
310
319
|
dist.push({
|
|
311
320
|
format: "esm",
|
|
312
|
-
file: getDistPath(
|
|
321
|
+
file: getDistPath(subExports)
|
|
313
322
|
});
|
|
314
323
|
} else {
|
|
315
|
-
if (
|
|
324
|
+
if (subExports.require) {
|
|
316
325
|
dist.push({
|
|
317
326
|
format: "cjs",
|
|
318
|
-
file: getDistPath(
|
|
327
|
+
file: getDistPath(subExports.require)
|
|
319
328
|
});
|
|
320
329
|
}
|
|
321
|
-
if (
|
|
330
|
+
if (subExports.import) {
|
|
322
331
|
dist.push({
|
|
323
332
|
format: "esm",
|
|
324
|
-
file: getDistPath(
|
|
333
|
+
file: getDistPath(subExports.import)
|
|
325
334
|
});
|
|
326
335
|
}
|
|
327
336
|
}
|
|
328
337
|
}
|
|
329
338
|
return dist;
|
|
330
339
|
}
|
|
331
|
-
function createRollupConfig(entry, pkg, cliArgs
|
|
332
|
-
var
|
|
340
|
+
function createRollupConfig(entry, pkg, cliArgs) {
|
|
341
|
+
var _a, _b;
|
|
342
|
+
var file = cliArgs.file;
|
|
333
343
|
var ext = path.extname(entry);
|
|
334
344
|
var useTypescript = ext === ".ts" || ext === ".tsx";
|
|
335
345
|
var options = tslib.__assign(tslib.__assign({}, cliArgs), {
|
|
336
346
|
useTypescript: useTypescript
|
|
337
347
|
});
|
|
338
348
|
var inputOptions = createInputConfig(entry, pkg, options);
|
|
339
|
-
var outputExports =
|
|
349
|
+
var outputExports = options.exportCondition ? getSubExportDist(pkg, options.exportCondition.export) : getExportDist(pkg);
|
|
340
350
|
var outputConfigs = outputExports.map(function(exportDist) {
|
|
341
351
|
return createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), {
|
|
342
352
|
file: exportDist.file,
|
|
@@ -345,17 +355,19 @@ function createRollupConfig(entry, pkg, cliArgs, entryExport) {
|
|
|
345
355
|
}), pkg);
|
|
346
356
|
});
|
|
347
357
|
if (file) {
|
|
358
|
+
var format = (_a = outputExports[0]) === null || _a === void 0 ? void 0 : _a.format;
|
|
348
359
|
outputConfigs = [
|
|
349
360
|
createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), {
|
|
350
361
|
file: file,
|
|
351
|
-
format: format,
|
|
362
|
+
format: format || cliArgs.format,
|
|
352
363
|
useTypescript: useTypescript
|
|
353
364
|
}), pkg),
|
|
354
365
|
];
|
|
355
366
|
}
|
|
356
367
|
return {
|
|
357
368
|
input: inputOptions,
|
|
358
|
-
output: outputConfigs
|
|
369
|
+
output: outputConfigs,
|
|
370
|
+
exportName: ((_b = options.exportCondition) === null || _b === void 0 ? void 0 : _b.name) || pkg.name
|
|
359
371
|
};
|
|
360
372
|
}
|
|
361
373
|
|
|
@@ -364,6 +376,26 @@ function assignDefault(options, name, defaultValue) {
|
|
|
364
376
|
options[name] = defaultValue;
|
|
365
377
|
}
|
|
366
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
|
+
}
|
|
367
399
|
function bundle(entryPath, _a) {
|
|
368
400
|
if (_a === void 0) {
|
|
369
401
|
_a = {};
|
|
@@ -373,17 +405,23 @@ function bundle(entryPath, _a) {
|
|
|
373
405
|
]);
|
|
374
406
|
config.rootDir = path.resolve(process.cwd(), cwd || "");
|
|
375
407
|
assignDefault(options, "format", "es");
|
|
408
|
+
assignDefault(options, "minify", false);
|
|
409
|
+
assignDefault(options, "target", "es5");
|
|
376
410
|
if (options.format === "esm") {
|
|
377
411
|
options.format = "es";
|
|
378
412
|
}
|
|
379
|
-
var
|
|
380
|
-
var
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
var
|
|
384
|
-
|
|
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
|
+
};
|
|
385
423
|
if (isSingleEntry) {
|
|
386
|
-
entryPath =
|
|
424
|
+
entryPath = getSourcePathFromExportPath(config.rootDir, ".");
|
|
387
425
|
}
|
|
388
426
|
if (!fs__default["default"].existsSync(entryPath)) {
|
|
389
427
|
var hasEntryFile = entryPath === "" ? "" : fs__default["default"].statSync(entryPath).isFile();
|
|
@@ -393,26 +431,34 @@ function bundle(entryPath, _a) {
|
|
|
393
431
|
return Promise.reject(err);
|
|
394
432
|
}
|
|
395
433
|
if (hasMultiEntries) {
|
|
396
|
-
Object.
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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);
|
|
400
443
|
return rollupConfig;
|
|
444
|
+
}).filter(function(v) {
|
|
445
|
+
return !!v;
|
|
401
446
|
});
|
|
402
447
|
return Promise.all(rollupConfigs.map(function(rollupConfig) {
|
|
403
|
-
return
|
|
448
|
+
return bundleOrWatch(rollupConfig);
|
|
404
449
|
}));
|
|
405
450
|
}
|
|
406
451
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
452
|
+
var rollupConfig = createRollupConfig(entryPath, pkg, options);
|
|
453
|
+
return bundleOrWatch(rollupConfig);
|
|
454
|
+
}
|
|
455
|
+
function getExportPath(pkg, exportName) {
|
|
456
|
+
var name = pkg.name || "<package>";
|
|
457
|
+
if (exportName === "." || !exportName) return name;
|
|
458
|
+
return path.join(name, exportName);
|
|
413
459
|
}
|
|
414
|
-
function runWatch(_a) {
|
|
415
|
-
var input = _a.input, output = _a.output;
|
|
460
|
+
function runWatch(pkg, _a) {
|
|
461
|
+
var exportName = _a.exportName, input = _a.input, output = _a.output;
|
|
416
462
|
var watchOptions = [
|
|
417
463
|
tslib.__assign(tslib.__assign({}, input), {
|
|
418
464
|
output: output,
|
|
@@ -424,31 +470,55 @@ function runWatch(_a) {
|
|
|
424
470
|
}),
|
|
425
471
|
];
|
|
426
472
|
var watcher = rollup.watch(watchOptions);
|
|
473
|
+
var exportPath = getExportPath(pkg, exportName);
|
|
474
|
+
var startTime = Date.now();
|
|
427
475
|
watcher.on("event", function(event) {
|
|
428
|
-
|
|
429
|
-
|
|
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;
|
|
430
495
|
}
|
|
431
496
|
});
|
|
432
497
|
return watcher;
|
|
433
498
|
}
|
|
434
|
-
function runBundle(_a) {
|
|
435
|
-
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();
|
|
436
502
|
return rollup.rollup(input).then(function(bundle) {
|
|
437
503
|
var writeJobs = output.map(function(options) {
|
|
438
504
|
return bundle.write(options);
|
|
439
505
|
});
|
|
440
506
|
return Promise.all(writeJobs);
|
|
441
|
-
}, 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
|
+
});
|
|
442
513
|
}
|
|
443
514
|
function onError(error) {
|
|
444
515
|
if (!error) return;
|
|
445
516
|
if (error.frame) {
|
|
446
|
-
process.
|
|
447
|
-
}
|
|
448
|
-
if (error.stack) {
|
|
449
|
-
process.stdout.write(error.stack + "\n");
|
|
517
|
+
process.stderr.write(error.frame + "\n");
|
|
450
518
|
}
|
|
451
|
-
|
|
519
|
+
var err = new Error(error.message);
|
|
520
|
+
err.stack = error.stack;
|
|
521
|
+
throw err;
|
|
452
522
|
}
|
|
453
523
|
|
|
454
524
|
exports.bundle = bundle;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PackageMetadata, BuncheeRollupConfig, CliArgs } from './types';
|
|
2
|
-
declare function createRollupConfig(entry: string, pkg: PackageMetadata, cliArgs: CliArgs
|
|
2
|
+
declare function createRollupConfig(entry: string, pkg: PackageMetadata, cliArgs: CliArgs): BuncheeRollupConfig;
|
|
3
3
|
export default createRollupConfig;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JscTarget } from '@swc/core';
|
|
1
2
|
import type { InputOptions, OutputOptions, RollupOptions } from 'rollup';
|
|
2
3
|
declare type ExportType = 'require' | 'export' | 'default' | string;
|
|
3
4
|
declare type CommonConfig = {
|
|
@@ -5,10 +6,12 @@ declare type CommonConfig = {
|
|
|
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;
|
|
@@ -21,10 +24,10 @@ declare type PackageMetadata = {
|
|
|
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,6 +35,7 @@ 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;
|
package/dist/src/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
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
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
|
-
};
|