Comparing version 3.1.0 to 3.1.1
@@ -6,2 +6,8 @@ #!/usr/bin/env node | ||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
var path__default = /*#__PURE__*/_interopDefault(path); | ||
var arg__default = /*#__PURE__*/_interopDefault(arg); | ||
var fs__default = /*#__PURE__*/_interopDefault(fs); | ||
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) { | ||
@@ -46,3 +52,3 @@ try { | ||
_hasPackageJson = _async_to_generator$1(function*(cwd) { | ||
return yield fileExists(path.resolve(cwd, 'package.json')); | ||
return yield fileExists(path__default.default.resolve(cwd, 'package.json')); | ||
}); | ||
@@ -56,6 +62,6 @@ return _hasPackageJson.apply(this, arguments); | ||
_getPackageMeta = _async_to_generator$1(function*(cwd) { | ||
const pkgFilePath = path.resolve(cwd, 'package.json'); | ||
const pkgFilePath = path__default.default.resolve(cwd, 'package.json'); | ||
let targetPackageJson = {}; | ||
try { | ||
targetPackageJson = JSON.parse((yield fs.readFile(pkgFilePath, { | ||
targetPackageJson = JSON.parse((yield fs__default.default.readFile(pkgFilePath, { | ||
encoding: 'utf-8' | ||
@@ -85,3 +91,3 @@ }))); | ||
try { | ||
yield fs.access(filePath); | ||
yield fs__default.default.access(filePath); | ||
return true; | ||
@@ -98,3 +104,3 @@ } catch (err) { | ||
var version = "3.1.0"; | ||
var version = "3.1.1"; | ||
@@ -176,3 +182,3 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
let args; | ||
args = arg({ | ||
args = arg__default.default({ | ||
'--cwd': String, | ||
@@ -229,3 +235,3 @@ '--dts': Boolean, | ||
const cwd = args.cwd || process.cwd(); | ||
const file = args.file ? path.resolve(cwd, args.file) : undefined; | ||
const file = args.file ? path__default.default.resolve(cwd, args.file) : undefined; | ||
const bundleConfig = { | ||
@@ -250,3 +256,3 @@ dts, | ||
} | ||
const entry = source ? path.resolve(cwd, source) : ''; | ||
const entry = source ? path__default.default.resolve(cwd, source) : ''; | ||
const bundle = require('./index').bundle; | ||
@@ -253,0 +259,0 @@ let timeStart = Date.now(); |
@@ -15,2 +15,12 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
var fs__default = /*#__PURE__*/_interopDefault(fs); | ||
var path__default = /*#__PURE__*/_interopDefault(path); | ||
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs); | ||
var shebang__default = /*#__PURE__*/_interopDefault(shebang); | ||
var json__default = /*#__PURE__*/_interopDefault(json); | ||
var replace__default = /*#__PURE__*/_interopDefault(replace); | ||
var prettyBytes__default = /*#__PURE__*/_interopDefault(prettyBytes); | ||
function chunkSizeCollector() { | ||
@@ -29,6 +39,6 @@ const sizes = new Map(); | ||
renderChunk (code, chunk, options) { | ||
const dir = options.dir || options.file && path.dirname(options.file); | ||
const dir = options.dir || options.file && path__default.default.dirname(options.file); | ||
let fileName = chunk.fileName; | ||
if (dir) { | ||
fileName = path.relative(cwd, path.join(dir, fileName)); | ||
fileName = path__default.default.relative(cwd, path__default.default.join(dir, fileName)); | ||
} | ||
@@ -45,3 +55,3 @@ addSize(fileName, code.length); | ||
name, | ||
prettyBytes(size), | ||
prettyBytes__default.default(size), | ||
size | ||
@@ -78,3 +88,42 @@ ]); | ||
} | ||
function getExportPaths(pkg) { | ||
/** | ||
* Get package exports paths | ||
* | ||
* Example: | ||
* | ||
* ```json | ||
* { | ||
* "exports": { | ||
* ".": { | ||
* "require": "./dist/index.cjs", | ||
* "module": "./dist/index.esm.js", | ||
* "default": "./dist/index.esm.js" | ||
* }, | ||
* "./foo": { | ||
* "require": "./dist/foo.cjs", | ||
* "module": "./dist/foo.esm.js", | ||
* "default": "./dist/foo.esm.js" | ||
* } | ||
* } | ||
* | ||
* ``` | ||
* | ||
* will be parsed to: | ||
* | ||
* ```js | ||
* { | ||
* '.': { | ||
* main: './dist/index.cjs', | ||
* module: './dist/index.esm.js', | ||
* export: './dist/index.esm.js' | ||
* }, | ||
* './foo': { | ||
* main: './dist/foo.cjs', | ||
* module: './dist/foo.esm.js', | ||
* export: './dist/foo.esm.js' | ||
* } | ||
* | ||
* | ||
* pkg.main and pkg.module will be added to ['.'] if exists | ||
*/ function getExportPaths(pkg) { | ||
const pathsMap = {}; | ||
@@ -210,6 +259,6 @@ const mainExport = {}; | ||
_getPackageMeta = _async_to_generator$3(function*(cwd) { | ||
const pkgFilePath = path.resolve(cwd, 'package.json'); | ||
const pkgFilePath = path__default.default.resolve(cwd, 'package.json'); | ||
let targetPackageJson = {}; | ||
try { | ||
targetPackageJson = JSON.parse((yield fs.readFile(pkgFilePath, { | ||
targetPackageJson = JSON.parse((yield fs__default.default.readFile(pkgFilePath, { | ||
encoding: 'utf-8' | ||
@@ -239,3 +288,3 @@ }))); | ||
try { | ||
yield fs.access(filePath); | ||
yield fs__default.default.access(filePath); | ||
return true; | ||
@@ -254,5 +303,5 @@ } catch (err) { | ||
function getExportPath(pkg, cwd, exportName) { | ||
const name = pkg.name || path.basename(cwd); | ||
const name = pkg.name || path__default.default.basename(cwd); | ||
if (exportName === '.' || !exportName) return name; | ||
return path.join(name, exportName); | ||
return path__default.default.join(name, exportName); | ||
} | ||
@@ -263,3 +312,3 @@ const isNotNull = (n)=>Boolean(n); | ||
function resolveSourceFile(cwd, filename) { | ||
return path.resolve(cwd, SRC, filename); | ||
return path__default.default.resolve(cwd, SRC, filename); | ||
} | ||
@@ -378,3 +427,3 @@ // Map '.' -> './index.[ext]' | ||
const commonPlugins = [ | ||
shebang(), | ||
shebang__default.default(), | ||
sizePlugin | ||
@@ -402,3 +451,3 @@ ]; | ||
...commonPlugins, | ||
replace({ | ||
replace__default.default({ | ||
values: getBuildEnv(options.env || []), | ||
@@ -417,6 +466,6 @@ preventAssignment: true | ||
}), | ||
commonjs({ | ||
commonjs__default.default({ | ||
include: /node_modules\// | ||
}), | ||
json(), | ||
json__default.default(), | ||
rollupPluginSwc3.swc({ | ||
@@ -474,9 +523,18 @@ include: /\.(m|c)?[jt]sx?$/, | ||
} | ||
function hasEsmExport(exportPaths, tsCompilerOptions) { | ||
let hasEsm = false; | ||
for(const key in exportPaths){ | ||
const exportInfo = exportPaths[key]; | ||
if (exportInfo.import || exportInfo.module) { | ||
hasEsm = true; | ||
break; | ||
} | ||
} | ||
return Boolean(hasEsm || (tsCompilerOptions == null ? void 0 : tsCompilerOptions.esModuleInterop)); | ||
} | ||
function buildOutputConfigs(pkg, options, cwd, { 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; | ||
const mainExport = exportPaths['.']; | ||
const useEsModuleMark = Boolean(tsCompilerOptions.esModuleInterop || mainExport.main && mainExport.module); | ||
// Add esm mark and interop helper if esm export is detected | ||
const useEsModuleMark = hasEsmExport(exportPaths, tsCompilerOptions); | ||
const typings = getTypings(pkg); | ||
@@ -501,3 +559,4 @@ const file = options.file && path.resolve(cwd, options.file); | ||
exports: 'named', | ||
esModule: useEsModuleMark, | ||
esModule: useEsModuleMark || 'if-default-prop', | ||
interop: 'auto', | ||
freeze: false, | ||
@@ -765,3 +824,3 @@ strict: false, | ||
}; | ||
const hasSpecifiedEntryFile = entryPath ? (yield fileExists(entryPath)) && (yield fs.stat(entryPath)).isFile() : false; | ||
const hasSpecifiedEntryFile = entryPath ? (yield fileExists(entryPath)) && (yield fs__default.default.stat(entryPath)).isFile() : false; | ||
if (!hasSpecifiedEntryFile && !isMultiEntries) { | ||
@@ -768,0 +827,0 @@ const err = new Error(`Entry file \`${entryPath}\` is not existed`); |
{ | ||
"name": "bunchee", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "zero config bundler for js/ts/jsx libraries", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -42,5 +42,5 @@ # bunchee | ||
"exports": { | ||
"require": "dist/index.cjs", | ||
"module": "dist/index.esm.js", | ||
"import": "dist/index.mjs", | ||
"module": "dist/index.esm.js" | ||
"require": "dist/index.cjs" | ||
}, | ||
@@ -47,0 +47,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49820
1196