bunchee 2.0.1 → 2.0.2

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.
Files changed (3) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/lib.js +38 -22
  3. package/package.json +2 -1
package/dist/cli.js CHANGED
@@ -87,7 +87,7 @@ var logger = {
87
87
  }
88
88
  };
89
89
 
90
- var version = "2.0.1";
90
+ var version = "2.0.2";
91
91
 
92
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';
93
93
  function help() {
package/dist/lib.js CHANGED
@@ -96,9 +96,10 @@ function resolveTypescript() {
96
96
  function getDistPath(distPath) {
97
97
  return path.resolve(config.rootDir, distPath);
98
98
  }
99
- function createInputConfig(entry, pkg, options) {
100
- var _a;
99
+ function createInputConfig(entry, pkg, options, _a) {
101
100
  var _b;
101
+ var _c;
102
+ var tsCompilerOptions = _a.tsCompilerOptions;
102
103
  var externals = [
103
104
  pkg.peerDependencies,
104
105
  pkg.dependencies,
@@ -109,7 +110,7 @@ function createInputConfig(entry, pkg, options) {
109
110
  return Object.keys(o);
110
111
  }).reduce(function(a, b) {
111
112
  return a.concat(b);
112
- }, []).concat(((_b = options.external) !== null && _b !== void 0 ? _b : []).concat(pkg.name ? [
113
+ }, []).concat(((_c = options.external) !== null && _c !== void 0 ? _c : []).concat(pkg.name ? [
113
114
  pkg.name
114
115
  ] : []));
115
116
  var useTypescript = options.useTypescript, runtime = options.runtime, jscTarget = options.target, minify = options.minify, exportCondition = options.exportCondition;
@@ -148,7 +149,7 @@ function createInputConfig(entry, pkg, options) {
148
149
  useTypescript && isMainExport && require("@rollup/plugin-typescript")(tslib.__assign({
149
150
  tsconfig: tsPath,
150
151
  typescript: resolveTypescript(),
151
- jsx: "react",
152
+ jsx: (tsCompilerOptions === null || tsCompilerOptions === void 0 ? void 0 : tsCompilerOptions.jsx) || "react",
152
153
  module: "ES6",
153
154
  target: jscTarget,
154
155
  noEmitOnError: !options.watch,
@@ -166,9 +167,17 @@ function createInputConfig(entry, pkg, options) {
166
167
  target: jscTarget,
167
168
  loose: true,
168
169
  externalHelpers: false,
169
- parser: (_a = {
170
+ parser: (_b = {
170
171
  syntax: useTypescript ? "typescript" : "ecmascript"
171
- }, _a[useTypescript ? "tsx" : "jsx"] = true, _a.privateMethod = true, _a.classPrivateProperty = true, _a.exportDefaultFrom = true, _a)
172
+ }, _b[useTypescript ? "tsx" : "jsx"] = true, _b.privateMethod = true, _b.classPrivateProperty = true, _b.exportDefaultFrom = true, _b),
173
+ transform: {
174
+ react: {
175
+ runtime: [
176
+ "react-jsx",
177
+ "react-jsx-dev"
178
+ ].includes(tsCompilerOptions === null || tsCompilerOptions === void 0 ? void 0 : tsCompilerOptions.jsx) ? "automatic" : "classic"
179
+ }
180
+ }
172
181
  }, minify && {
173
182
  minify: tslib.__assign(tslib.__assign({}, minifyOptions), {
174
183
  sourceMap: options.sourcemap
@@ -205,17 +214,9 @@ function createInputConfig(entry, pkg, options) {
205
214
  }
206
215
  };
207
216
  }
208
- function createOutputOptions(options, pkg) {
209
- var format = options.format, useTypescript = options.useTypescript;
210
- var tsCompilerOptions = {};
211
- if (useTypescript) {
212
- var ts = resolveTypescript();
213
- var tsconfigPath = path.resolve(config.rootDir, "tsconfig.json");
214
- if (fs__default["default"].existsSync(tsconfigPath)) {
215
- var tsconfigJSON = ts.readConfigFile(tsconfigPath, ts.sys.readFile).config;
216
- tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, "./").options;
217
- }
218
- }
217
+ function createOutputOptions(options, pkg, _a) {
218
+ var tsCompilerOptions = _a.tsCompilerOptions;
219
+ var format = options.format;
219
220
  var exportPaths = getExportPaths(pkg);
220
221
  var useEsModuleMark = Boolean(tsCompilerOptions.esModuleInterop || exportPaths.main && exportPaths.module);
221
222
  var file = path.resolve(options.file);
@@ -345,14 +346,27 @@ function createRollupConfig(entry, pkg, cliArgs) {
345
346
  var options = tslib.__assign(tslib.__assign({}, cliArgs), {
346
347
  useTypescript: useTypescript
347
348
  });
348
- var inputOptions = createInputConfig(entry, pkg, options);
349
+ var tsCompilerOptions = {};
350
+ if (useTypescript) {
351
+ var ts = resolveTypescript();
352
+ var tsconfigPath = path.resolve(config.rootDir, "tsconfig.json");
353
+ if (fs__default["default"].existsSync(tsconfigPath)) {
354
+ var tsconfigJSON = ts.readConfigFile(tsconfigPath, ts.sys.readFile).config;
355
+ tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, "./").options;
356
+ }
357
+ }
358
+ var inputOptions = createInputConfig(entry, pkg, options, {
359
+ tsCompilerOptions: tsCompilerOptions
360
+ });
349
361
  var outputExports = options.exportCondition ? getSubExportDist(pkg, options.exportCondition.export) : getExportDist(pkg);
350
362
  var outputConfigs = outputExports.map(function(exportDist) {
351
363
  return createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), {
352
364
  file: exportDist.file,
353
365
  format: exportDist.format,
354
366
  useTypescript: useTypescript
355
- }), pkg);
367
+ }), pkg, {
368
+ tsCompilerOptions: tsCompilerOptions
369
+ });
356
370
  });
357
371
  if (file) {
358
372
  var format = (_a = outputExports[0]) === null || _a === void 0 ? void 0 : _a.format;
@@ -361,13 +375,15 @@ function createRollupConfig(entry, pkg, cliArgs) {
361
375
  file: file,
362
376
  format: format || cliArgs.format,
363
377
  useTypescript: useTypescript
364
- }), pkg),
378
+ }), pkg, {
379
+ tsCompilerOptions: tsCompilerOptions
380
+ }),
365
381
  ];
366
382
  }
367
383
  return {
368
384
  input: inputOptions,
369
385
  output: outputConfigs,
370
- exportName: ((_b = options.exportCondition) === null || _b === void 0 ? void 0 : _b.name) || pkg.name
386
+ exportName: ((_b = options.exportCondition) === null || _b === void 0 ? void 0 : _b.name) || "."
371
387
  };
372
388
  }
373
389
 
@@ -453,7 +469,7 @@ function bundle(entryPath, _a) {
453
469
  return bundleOrWatch(rollupConfig);
454
470
  }
455
471
  function getExportPath(pkg, exportName) {
456
- var name = pkg.name || "<package>";
472
+ var name = pkg.name || path.basename(config.rootDir);
457
473
  if (exportName === "." || !exportName) return name;
458
474
  return path.join(name, exportName);
459
475
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": {
6
6
  "bunchee": "./dist/cli.js"
@@ -55,6 +55,7 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "jest": "29.0.1",
58
+ "react": "18.2.0",
58
59
  "tsx": "3.4.3",
59
60
  "typescript": "4.8.2"
60
61
  },