Comparing version 3.5.1 to 3.6.0
280
dist/cli.js
@@ -12,31 +12,2 @@ #!/usr/bin/env node | ||
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _async_to_generator$1(fn) { | ||
return function() { | ||
var self = this, args = arguments; | ||
return new Promise(function(resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
function exit(err) { | ||
@@ -47,27 +18,15 @@ logger.error(err); | ||
const formatDuration = (duration)=>duration >= 1000 ? `${duration / 1000}s` : `${duration}ms`; | ||
function hasPackageJson(cwd) { | ||
return _hasPackageJson.apply(this, arguments); | ||
async function hasPackageJson(cwd) { | ||
return await fileExists(path__default.default.resolve(cwd, 'package.json')); | ||
} | ||
function _hasPackageJson() { | ||
_hasPackageJson = _async_to_generator$1(function*(cwd) { | ||
return yield fileExists(path__default.default.resolve(cwd, 'package.json')); | ||
}); | ||
return _hasPackageJson.apply(this, arguments); | ||
async function getPackageMeta(cwd) { | ||
const pkgFilePath = path__default.default.resolve(cwd, 'package.json'); | ||
let targetPackageJson = {}; | ||
try { | ||
targetPackageJson = JSON.parse(await fs__default.default.readFile(pkgFilePath, { | ||
encoding: 'utf-8' | ||
})); | ||
} catch (_) {} | ||
return targetPackageJson; | ||
} | ||
function getPackageMeta(cwd) { | ||
return _getPackageMeta.apply(this, arguments); | ||
} | ||
function _getPackageMeta() { | ||
_getPackageMeta = _async_to_generator$1(function*(cwd) { | ||
const pkgFilePath = path__default.default.resolve(cwd, 'package.json'); | ||
let targetPackageJson = {}; | ||
try { | ||
targetPackageJson = JSON.parse((yield fs__default.default.readFile(pkgFilePath, { | ||
encoding: 'utf-8' | ||
}))); | ||
} catch (_) {} | ||
return targetPackageJson; | ||
}); | ||
return _getPackageMeta.apply(this, arguments); | ||
} | ||
const logger = { | ||
@@ -84,51 +43,16 @@ log (arg) { | ||
}; | ||
function fileExists(filePath) { | ||
return _fileExists.apply(this, arguments); | ||
} | ||
function _fileExists() { | ||
_fileExists = _async_to_generator$1(function*(filePath) { | ||
try { | ||
yield fs__default.default.access(filePath); | ||
return true; | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return false; | ||
} | ||
throw err; | ||
async function fileExists(filePath) { | ||
try { | ||
await fs__default.default.access(filePath); | ||
return true; | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return false; | ||
} | ||
}); | ||
return _fileExists.apply(this, arguments); | ||
throw err; | ||
} | ||
} | ||
var version = "3.5.1"; | ||
var version = "3.6.0"; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _async_to_generator(fn) { | ||
return function() { | ||
var self = this, args = arguments; | ||
return new Promise(function(resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
const helpMessage = ` | ||
@@ -156,23 +80,17 @@ Usage: bunchee [options] | ||
} | ||
function lintPackage(cwd) { | ||
return _lintPackage.apply(this, arguments); | ||
} | ||
function _lintPackage() { | ||
_lintPackage = _async_to_generator(function*(cwd) { | ||
// Not package.json detected, skip package linting | ||
if (!(yield hasPackageJson(cwd))) { | ||
return; | ||
} | ||
const { publint } = yield import('publint'); | ||
const { printMessage } = yield import('publint/utils'); | ||
const messages = yield publint({ | ||
pkgDir: cwd, | ||
level: 'error' | ||
}); | ||
const pkg = yield getPackageMeta(cwd); | ||
for (const message of messages){ | ||
console.log(printMessage(message, pkg)); | ||
} | ||
async function lintPackage(cwd) { | ||
// Not package.json detected, skip package linting | ||
if (!await hasPackageJson(cwd)) { | ||
return; | ||
} | ||
const { publint } = await import('publint'); | ||
const { printMessage } = await import('publint/utils'); | ||
const messages = await publint({ | ||
pkgDir: cwd, | ||
level: 'error' | ||
}); | ||
return _lintPackage.apply(this, arguments); | ||
const pkg = await getPackageMeta(cwd); | ||
for (const message of messages){ | ||
console.log(printMessage(message, pkg)); | ||
} | ||
} | ||
@@ -225,75 +143,63 @@ function parseCliArgs(argv) { | ||
} | ||
function run(args) { | ||
return _run.apply(this, arguments); | ||
} | ||
function _run() { | ||
_run = _async_to_generator(function*(args) { | ||
var _args_external, _env; | ||
const { source, format, watch, minify, sourcemap, target, runtime, dts, env } = args; | ||
const cwd = args.cwd || process.cwd(); | ||
const file = args.file ? path__default.default.resolve(cwd, args.file) : undefined; | ||
const bundleConfig = { | ||
dts, | ||
file, | ||
format, | ||
cwd, | ||
target, | ||
runtime, | ||
external: ((_args_external = args.external) == null ? void 0 : _args_external.split(',')) || [], | ||
watch: !!watch, | ||
minify: !!minify, | ||
sourcemap: sourcemap === false ? false : true, | ||
env: ((_env = env) == null ? void 0 : _env.split(',')) || [] | ||
}; | ||
if (args.version) { | ||
return logger.log(version); | ||
async function run(args) { | ||
var _args_external, _env; | ||
const { source, format, watch, minify, sourcemap, target, runtime, dts, env } = args; | ||
const cwd = args.cwd || process.cwd(); | ||
const file = args.file ? path__default.default.resolve(cwd, args.file) : undefined; | ||
const bundleConfig = { | ||
dts, | ||
file, | ||
format, | ||
cwd, | ||
target, | ||
runtime, | ||
external: ((_args_external = args.external) == null ? void 0 : _args_external.split(',')) || [], | ||
watch: !!watch, | ||
minify: !!minify, | ||
sourcemap: sourcemap === false ? false : true, | ||
env: ((_env = env) == null ? void 0 : _env.split(',')) || [] | ||
}; | ||
if (args.version) { | ||
return logger.log(version); | ||
} | ||
if (args.help) { | ||
return help(); | ||
} | ||
const entry = source ? path__default.default.resolve(cwd, source) : ''; | ||
const bundle = require('./index').bundle; | ||
let timeStart = Date.now(); | ||
let timeEnd; | ||
try { | ||
await bundle(entry, bundleConfig); | ||
timeEnd = Date.now(); | ||
} catch (err) { | ||
if (err.name === 'NOT_EXISTED') { | ||
help(); | ||
return exit(err); | ||
} | ||
if (args.help) { | ||
return help(); | ||
} | ||
const entry = source ? path__default.default.resolve(cwd, source) : ''; | ||
const bundle = require('./index').bundle; | ||
let timeStart = Date.now(); | ||
let timeEnd; | ||
try { | ||
yield bundle(entry, bundleConfig); | ||
timeEnd = Date.now(); | ||
} catch (err) { | ||
if (err.name === 'NOT_EXISTED') { | ||
help(); | ||
return exit(err); | ||
} | ||
throw err; | ||
} | ||
const duration = timeEnd - timeStart; | ||
// watching mode | ||
if (watch) { | ||
logger.log(`🔍 Watching assets in ${cwd}...`); | ||
return; | ||
} | ||
// build mode | ||
logger.log(`✨ Finished in ${formatDuration(duration)}`); | ||
yield lintPackage(cwd); | ||
}); | ||
return _run.apply(this, arguments); | ||
throw err; | ||
} | ||
const duration = timeEnd - timeStart; | ||
// watching mode | ||
if (watch) { | ||
logger.log(`🔍 Watching assets in ${cwd}...`); | ||
return; | ||
} | ||
// build mode | ||
logger.log(`✨ Finished in ${formatDuration(duration)}`); | ||
await lintPackage(cwd); | ||
} | ||
function main() { | ||
return _main.apply(this, arguments); | ||
async function main() { | ||
let params, error; | ||
try { | ||
params = parseCliArgs(process.argv.slice(2)); | ||
} catch (err) { | ||
error = err; | ||
} | ||
if (error || !params) { | ||
if (!error) help(); | ||
return exit(error); | ||
} | ||
await run(params); | ||
} | ||
function _main() { | ||
_main = _async_to_generator(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); | ||
}); | ||
return _main.apply(this, arguments); | ||
} | ||
main().catch(exit); |
@@ -13,4 +13,3 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
var prettyBytes = require('pretty-bytes'); | ||
var core = require('@swc/core'); | ||
var MagicString = require('magic-string'); | ||
var swcPreserveDirectivePlugin = require('rollup-swc-preserve-directives'); | ||
var module$1 = require('module'); | ||
@@ -26,3 +25,3 @@ | ||
var prettyBytes__default = /*#__PURE__*/_interopDefault(prettyBytes); | ||
var MagicString__default = /*#__PURE__*/_interopDefault(MagicString); | ||
var swcPreserveDirectivePlugin__default = /*#__PURE__*/_interopDefault(swcPreserveDirectivePlugin); | ||
@@ -67,31 +66,20 @@ function chunkSizeCollector() { | ||
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _async_to_generator$4(fn) { | ||
return function() { | ||
var self = this, args = arguments; | ||
return new Promise(function(resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
const availableExtensions = [ | ||
'js', | ||
'cjs', | ||
'mjs', | ||
'jsx', | ||
'ts', | ||
'tsx', | ||
'cts', | ||
'mts' | ||
]; | ||
const availableExportConventions = [ | ||
'react-server', | ||
'react-native', | ||
'edge-light' | ||
]; | ||
const availableESExtensionsRegex = /\.(m|c)?[jt]sx?$/; | ||
const dtsExtensionRegex = /\.d\.(m|c)?ts$/; | ||
function exit(err) { | ||
@@ -101,18 +89,12 @@ logger.error(err); | ||
} | ||
function getPackageMeta(cwd) { | ||
return _getPackageMeta.apply(this, arguments); | ||
async function getPackageMeta(cwd) { | ||
const pkgFilePath = path__default.default.resolve(cwd, 'package.json'); | ||
let targetPackageJson = {}; | ||
try { | ||
targetPackageJson = JSON.parse(await fs__default.default.readFile(pkgFilePath, { | ||
encoding: 'utf-8' | ||
})); | ||
} catch (_) {} | ||
return targetPackageJson; | ||
} | ||
function _getPackageMeta() { | ||
_getPackageMeta = _async_to_generator$4(function*(cwd) { | ||
const pkgFilePath = path__default.default.resolve(cwd, 'package.json'); | ||
let targetPackageJson = {}; | ||
try { | ||
targetPackageJson = JSON.parse((yield fs__default.default.readFile(pkgFilePath, { | ||
encoding: 'utf-8' | ||
}))); | ||
} catch (_) {} | ||
return targetPackageJson; | ||
}); | ||
return _getPackageMeta.apply(this, arguments); | ||
} | ||
const logger = { | ||
@@ -129,18 +111,12 @@ log (arg) { | ||
}; | ||
function fileExists(filePath) { | ||
return _fileExists.apply(this, arguments); | ||
} | ||
function _fileExists() { | ||
_fileExists = _async_to_generator$4(function*(filePath) { | ||
try { | ||
yield fs__default.default.access(filePath); | ||
return true; | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return false; | ||
} | ||
throw err; | ||
async function fileExists(filePath) { | ||
try { | ||
await fs__default.default.access(filePath); | ||
return true; | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return false; | ||
} | ||
}); | ||
return _fileExists.apply(this, arguments); | ||
throw err; | ||
} | ||
} | ||
@@ -160,57 +136,30 @@ // . -> pkg name | ||
} | ||
function findSourceEntryFile(cwd, exportPath, exportTypeSuffix, ext) { | ||
return _findSourceEntryFile.apply(this, arguments); | ||
async function findSourceEntryFile(cwd, exportPath, exportTypeSuffix, ext) { | ||
const filename = resolveSourceFile(cwd, `${exportPath}${exportTypeSuffix ? `.${exportTypeSuffix}` : ''}.${ext}`); | ||
if (await fileExists(filename)) { | ||
return filename; | ||
} | ||
const subFolderIndexFilename = resolveSourceFile(cwd, `${exportPath}/index${exportTypeSuffix ? `.${exportTypeSuffix}` : ''}.${ext}`); | ||
if (await fileExists(subFolderIndexFilename)) { | ||
return subFolderIndexFilename; | ||
} | ||
return undefined; | ||
} | ||
function _findSourceEntryFile() { | ||
_findSourceEntryFile = _async_to_generator$4(function*(cwd, exportPath, exportTypeSuffix, ext) { | ||
const filename = resolveSourceFile(cwd, `${exportPath}${exportTypeSuffix ? `.${exportTypeSuffix}` : ''}.${ext}`); | ||
if (yield fileExists(filename)) { | ||
return filename; | ||
} | ||
const subFolderIndexFilename = resolveSourceFile(cwd, `${exportPath}/index${exportTypeSuffix ? `.${exportTypeSuffix}` : ''}.${ext}`); | ||
if (yield fileExists(subFolderIndexFilename)) { | ||
return subFolderIndexFilename; | ||
} | ||
return undefined; | ||
}); | ||
return _findSourceEntryFile.apply(this, arguments); | ||
} | ||
// Map '.' -> './index.[ext]' | ||
// Map './lite' -> './lite.[ext]' | ||
// Return undefined if no match or if it's package.json exports | ||
// TODO: add mts and cts once the types generation for dual package is supported | ||
const availableExtensions = [ | ||
'js', | ||
'cjs', | ||
'mjs', | ||
'jsx', | ||
'ts', | ||
'tsx' | ||
]; | ||
const availableExportConventions = [ | ||
'react-server', | ||
'react-native', | ||
'edge-light' | ||
]; | ||
const availableESExtensionsRegex = /\.(m|c)?[jt]sx?$/; | ||
function getSourcePathFromExportPath(cwd, exportPath, exportType) { | ||
return _getSourcePathFromExportPath.apply(this, arguments); | ||
} | ||
function _getSourcePathFromExportPath() { | ||
_getSourcePathFromExportPath = _async_to_generator$4(function*(cwd, exportPath, exportType) { | ||
for (const ext of availableExtensions){ | ||
// ignore package.json | ||
if (exportPath.endsWith('package.json')) return; | ||
if (exportPath === '.') exportPath = './index'; | ||
// Find convention-based source file for specific export types | ||
if (availableExportConventions.includes(exportType)) { | ||
const filename = yield findSourceEntryFile(cwd, exportPath, exportType, ext); | ||
if (filename) return filename; | ||
} | ||
const filename = yield findSourceEntryFile(cwd, exportPath, null, ext); | ||
async function getSourcePathFromExportPath(cwd, exportPath, exportType) { | ||
for (const ext of availableExtensions){ | ||
// ignore package.json | ||
if (exportPath.endsWith('package.json')) return; | ||
if (exportPath === '.') exportPath = './index'; | ||
// Find convention-based source file for specific export types | ||
if (availableExportConventions.includes(exportType)) { | ||
const filename = await findSourceEntryFile(cwd, exportPath, exportType, ext); | ||
if (filename) return filename; | ||
} | ||
return; | ||
}); | ||
return _getSourcePathFromExportPath.apply(this, arguments); | ||
const filename = await findSourceEntryFile(cwd, exportPath, null, ext); | ||
if (filename) return filename; | ||
} | ||
return; | ||
} | ||
@@ -223,105 +172,2 @@ // Unlike path.basename, forcedly removing extension | ||
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _async_to_generator$3(fn) { | ||
return function() { | ||
var self = this, args = arguments; | ||
return new Promise(function(resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
function _extends$2() { | ||
_extends$2 = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends$2.apply(this, arguments); | ||
} | ||
const directiveRegex = /^use (\w+)$/; | ||
function swcRenderDirectivePlugin({ swcParserConfig }) { | ||
const meta = { | ||
shebang: null, | ||
directives: new Set() | ||
}; | ||
const parseOptions = _extends$2({}, swcParserConfig, { | ||
script: false, | ||
target: 'es2018' | ||
}); | ||
return { | ||
name: 'swc-render-directive', | ||
transform (code, id) { | ||
return _async_to_generator$3(function*() { | ||
const ext = path.extname(id); | ||
if (!availableESExtensionsRegex.test(ext)) return code; | ||
const { body, interpreter } = yield core.parse(code, parseOptions); | ||
if (interpreter) { | ||
meta.shebang = `#!${interpreter}`; | ||
code = code.replace(new RegExp('^[\\s\\n]*' + meta.shebang.replace(/\//g, '\/') + '\\n*'), '') // Remove shebang from code | ||
; | ||
} | ||
for (const node of body){ | ||
if (node.type === 'ExpressionStatement') { | ||
if (node.expression.type === 'StringLiteral' && directiveRegex.test(node.expression.value)) { | ||
meta.directives.add(node.expression.value); | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
return { | ||
code, | ||
map: null, | ||
meta | ||
}; | ||
})(); | ||
}, | ||
renderChunk (code, _chunk, { sourcemap }) { | ||
const { shebang, directives } = meta; | ||
if (!directives.size && !shebang) return null; | ||
const s = new MagicString__default.default(code); | ||
if (directives.size) { | ||
s.prepend(`${[ | ||
...directives | ||
].map((directive)=>`'${directive}';`).join('\n')}\n`); | ||
} | ||
if (shebang) { | ||
s.prepend(`${shebang}\n`); | ||
} | ||
return { | ||
code: s.toString(), | ||
map: sourcemap ? s.generateMap({ | ||
hires: true | ||
}) : null | ||
}; | ||
} | ||
}; | ||
} | ||
function getTypings(pkg) { | ||
@@ -397,10 +243,10 @@ return pkg.types || pkg.typings; | ||
* Output: | ||
* { | ||
* "./sub": { | ||
* "import": "./sub.js", | ||
* "require": "./sub.cjs", | ||
* "types": "./sub.d.ts, | ||
* } | ||
* } | ||
* | ||
* { | ||
* "./sub": { | ||
* "import": "./sub.js", | ||
* "require": "./sub.cjs", | ||
* "types": "./sub.d.ts, | ||
* } | ||
* } | ||
* | ||
*/ function parseExport(exportsCondition, packageType) { | ||
@@ -462,4 +308,6 @@ const paths = {}; | ||
*/ function getExportPaths(pkg) { | ||
var _pathsMap_; | ||
const pathsMap = {}; | ||
const packageType = getPackageType(pkg); | ||
const isCjsPackage = packageType === 'commonjs'; | ||
const { exports: exportsConditions } = pkg; | ||
@@ -472,6 +320,11 @@ if (exportsConditions) { | ||
const defaultMainExport = constructFullExportCondition({ | ||
[packageType === 'commonjs' ? 'require' : 'import']: pkg.main, | ||
[isCjsPackage ? 'require' : 'import']: pkg.main, | ||
module: pkg.module, | ||
types: getTypings(pkg) | ||
}, packageType); | ||
if (isCjsPackage && ((_pathsMap_ = pathsMap['.']) == null ? void 0 : _pathsMap_['require'])) { | ||
// pathsMap's exports.require are prioritized. | ||
defaultMainExport['require'] = pathsMap['.']['require']; | ||
console.warn(`(warning) "exports.require" has overwritten "main" since they are duplicated.`); | ||
} | ||
// Merge the main export into '.' paths | ||
@@ -485,2 +338,32 @@ const mainExport = Object.assign({}, pathsMap['.'], defaultMainExport); | ||
} | ||
const getExportTypeDist = (parsedExportCondition, cwd)=>{ | ||
const existed = new Set(); | ||
const exportTypes = Object.keys(parsedExportCondition.export); | ||
for (const key of exportTypes){ | ||
if (key === 'module') { | ||
continue; | ||
} | ||
const filePath = parsedExportCondition.export[key]; | ||
if (key === 'types') { | ||
const typeFile = getDistPath(filePath, cwd); | ||
if (existed.has(typeFile)) { | ||
continue; | ||
} | ||
existed.add(typeFile); | ||
continue; | ||
} | ||
const ext = path.extname(filePath).slice(1); | ||
const dtsExtentions = { | ||
js: '.d.ts', | ||
cjs: '.d.cts', | ||
mjs: '.d.mts' | ||
}; | ||
const typeFile = getDistPath(`${filenameWithoutExtension(filePath) || ''}${dtsExtentions[ext]}`, cwd); | ||
if (existed.has(typeFile)) { | ||
continue; | ||
} | ||
existed.add(typeFile); | ||
} | ||
return Array.from(existed); | ||
}; | ||
function getPackageType(pkg) { | ||
@@ -557,45 +440,2 @@ return pkg.type || 'commonjs'; | ||
function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _async_to_generator$2(fn) { | ||
return function() { | ||
var self = this, args = arguments; | ||
return new Promise(function(resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends$1.apply(this, arguments); | ||
} | ||
const swcMinifyOptions = { | ||
@@ -647,13 +487,16 @@ compress: true, | ||
const swcOptions = { | ||
jsc: _extends$1({}, !hasSpecifiedTsTarget && { | ||
target: jscTarget | ||
}, { | ||
jsc: { | ||
...!hasSpecifiedTsTarget && { | ||
target: jscTarget | ||
}, | ||
loose: true, | ||
externalHelpers: false, | ||
parser: swcParserConfig | ||
}, shouldMinify && { | ||
minify: _extends$1({}, swcMinifyOptions, { | ||
sourceMap: options.sourcemap | ||
}) | ||
}), | ||
parser: swcParserConfig, | ||
...shouldMinify && { | ||
minify: { | ||
...swcMinifyOptions, | ||
sourceMap: options.sourcemap | ||
} | ||
} | ||
}, | ||
sourceMaps: options.sourcemap, | ||
@@ -664,5 +507,3 @@ inlineSourcesContent: false | ||
const commonPlugins = [ | ||
swcRenderDirectivePlugin({ | ||
swcParserConfig | ||
}), | ||
swcPreserveDirectivePlugin__default.default(), | ||
sizePlugin | ||
@@ -673,3 +514,4 @@ ]; | ||
useTypescript && require('rollup-plugin-dts').default({ | ||
compilerOptions: _extends$1({}, tsCompilerOptions, { | ||
compilerOptions: { | ||
...tsCompilerOptions, | ||
declaration: true, | ||
@@ -687,3 +529,3 @@ noEmit: false, | ||
jsx: tsCompilerOptions.jsx || 'react' | ||
}) | ||
} | ||
}) | ||
@@ -712,7 +554,8 @@ ] : [ | ||
pluginWasm.wasm(), | ||
rollupPluginSwc3.swc(_extends$1({ | ||
rollupPluginSwc3.swc({ | ||
include: availableESExtensionsRegex, | ||
exclude: 'node_modules', | ||
tsconfig: tsConfigPath | ||
}, swcOptions)) | ||
tsconfig: tsConfigPath, | ||
...swcOptions | ||
}) | ||
]).filter(isNotNull); | ||
@@ -736,4 +579,3 @@ return { | ||
'UNRESOLVED_IMPORT', | ||
'THIS_IS_UNDEFINED', | ||
'MODULE_LEVEL_DIRECTIVE' // ignore warnings for directives like `use client` | ||
'THIS_IS_UNDEFINED' | ||
].includes(code)) return; | ||
@@ -770,3 +612,3 @@ // If the circular dependency warning is from node_modules, ignore it | ||
// TODO: simplify dts file name detection | ||
const dtsFile = exportCondition.export['types'] ? path.resolve(cwd, exportCondition.export['types']) : file ? name + '.d.ts' : path.resolve(dtsDir, (exportCondition.name === '.' ? 'index' : exportCondition.name) + '.d.ts'); | ||
const dtsFile = file ? file : exportCondition.export['types'] ? path.resolve(cwd, exportCondition.export['types']) : path.resolve(dtsDir, (exportCondition.name === '.' ? 'index' : exportCondition.name) + '.d.ts'); | ||
// If there's dts file, use `output.file` | ||
@@ -778,7 +620,7 @@ const dtsPathConfig = dtsFile ? { | ||
}; | ||
return _extends$1({ | ||
name: pkg.name || name | ||
}, dts ? dtsPathConfig : { | ||
file: file | ||
}, { | ||
return { | ||
name: pkg.name || name, | ||
...dts ? dtsPathConfig : { | ||
file: file | ||
}, | ||
format, | ||
@@ -791,67 +633,55 @@ exports: 'named', | ||
sourcemap: options.sourcemap | ||
}); | ||
}; | ||
} | ||
// build configs for each entry from package exports | ||
function buildEntryConfig(pkg, entryPath, exportPaths, bundleConfig, cwd, tsOptions, dts) { | ||
return _buildEntryConfig.apply(this, arguments); | ||
} | ||
function _buildEntryConfig() { | ||
_buildEntryConfig = _async_to_generator$2(function*(pkg, entryPath, exportPaths, bundleConfig, cwd, tsOptions, dts) { | ||
const configs = []; | ||
Object.keys(exportPaths).forEach(/*#__PURE__*/ _async_to_generator$2(function*(entryExport) { | ||
// TODO: improve the source detection | ||
const exportCond = exportPaths[entryExport]; | ||
const buildConfigs = [ | ||
createBuildConfig('', exportCond) // default config | ||
]; | ||
// For dts job, only build the default config. | ||
// For assets job, build all configs. | ||
if (!dts) { | ||
if (exportCond['edge-light']) { | ||
buildConfigs.push(createBuildConfig('edge-light', exportCond)); | ||
} | ||
if (exportCond['react-server']) { | ||
buildConfigs.push(createBuildConfig('react-server', exportCond)); | ||
} | ||
if (exportCond['react-native']) { | ||
buildConfigs.push(createBuildConfig('react-native', exportCond)); | ||
} | ||
async function buildEntryConfig(pkg, entryPath, exportPaths, bundleConfig, cwd, tsOptions, dts) { | ||
const configs = []; | ||
Object.keys(exportPaths).forEach(async (entryExport)=>{ | ||
// TODO: improve the source detection | ||
const exportCond = exportPaths[entryExport]; | ||
const buildConfigs = [ | ||
createBuildConfig('', exportCond) | ||
]; | ||
// For dts job, only build the default config. | ||
// For assets job, build all configs. | ||
if (!dts) { | ||
if (exportCond['edge-light']) { | ||
buildConfigs.push(createBuildConfig('edge-light', exportCond)); | ||
} | ||
function createBuildConfig(exportType, exportCondRef) { | ||
return _createBuildConfig.apply(this, arguments); | ||
if (exportCond['react-server']) { | ||
buildConfigs.push(createBuildConfig('react-server', exportCond)); | ||
} | ||
function _createBuildConfig() { | ||
_createBuildConfig = _async_to_generator$2(function*(exportType, exportCondRef) { | ||
let exportCondForType = _extends$1({}, exportCondRef); | ||
// Special cases of export type, only pass down the exportPaths for the type | ||
if (availableExportConventions.includes(exportType)) { | ||
exportCondForType = { | ||
[entryExport]: exportCondRef[exportType] | ||
}; | ||
// Basic export type, pass down the exportPaths with erasing the special ones | ||
} else { | ||
for (const exportType of availableExportConventions){ | ||
delete exportCondForType[exportType]; | ||
} | ||
} | ||
const source = entryPath || (yield getSourcePathFromExportPath(cwd, entryExport, exportType)); | ||
if (!source) return undefined; | ||
// For dts, only build types filed | ||
if (dts && !exportCondRef['types']) return undefined; | ||
const exportCondition = { | ||
source, | ||
name: entryExport, | ||
export: exportCondForType | ||
}; | ||
const entry = resolveSourceFile(cwd, source); | ||
const rollupConfig = buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dts); | ||
return rollupConfig; | ||
}); | ||
return _createBuildConfig.apply(this, arguments); | ||
if (exportCond['react-native']) { | ||
buildConfigs.push(createBuildConfig('react-native', exportCond)); | ||
} | ||
configs.push(...buildConfigs); | ||
})); | ||
return (yield Promise.all(configs)).filter(nonNullable); | ||
} | ||
async function createBuildConfig(exportType, exportCondRef) { | ||
let exportCondForType = { | ||
...exportCondRef | ||
}; | ||
// Special cases of export type, only pass down the exportPaths for the type | ||
if (availableExportConventions.includes(exportType)) { | ||
exportCondForType = { | ||
[entryExport]: exportCondRef[exportType] | ||
}; | ||
// Basic export type, pass down the exportPaths with erasing the special ones | ||
} else { | ||
for (const exportType of availableExportConventions){ | ||
delete exportCondForType[exportType]; | ||
} | ||
} | ||
const source = entryPath || await getSourcePathFromExportPath(cwd, entryExport, exportType); | ||
if (!source) return undefined; | ||
const exportCondition = { | ||
source, | ||
name: entryExport, | ||
export: exportCondForType | ||
}; | ||
const entry = resolveSourceFile(cwd, source); | ||
const rollupConfig = buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dts); | ||
return rollupConfig; | ||
} | ||
configs.push(...buildConfigs); | ||
}); | ||
return _buildEntryConfig.apply(this, arguments); | ||
return (await Promise.all(configs)).filter(nonNullable); | ||
} | ||
@@ -861,5 +691,6 @@ function buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dts) { | ||
const useTypescript = Boolean(tsOptions.tsConfigPath); | ||
const options = _extends$1({}, bundleConfig, { | ||
const options = { | ||
...bundleConfig, | ||
useTypescript | ||
}); | ||
}; | ||
const inputOptions = buildInputConfig(entry, pkg, options, cwd, tsOptions, dts); | ||
@@ -870,16 +701,18 @@ const outputExports = getExportConditionDist(pkg, exportCondition, cwd); | ||
if (dts) { | ||
outputConfigs = [ | ||
buildOutputConfigs(pkg, exportPaths, _extends$1({}, bundleConfig, { | ||
const typeOutputExports = getExportTypeDist(exportCondition, cwd); | ||
outputConfigs = typeOutputExports.map((v)=>buildOutputConfigs(pkg, exportPaths, { | ||
...bundleConfig, | ||
format: 'es', | ||
useTypescript | ||
}), exportCondition, cwd, tsOptions, dts) | ||
]; | ||
useTypescript, | ||
file: v | ||
}, exportCondition, cwd, tsOptions, dts)); | ||
} else { | ||
// multi outputs with specified format | ||
outputConfigs = outputExports.map((exportDist)=>{ | ||
return buildOutputConfigs(pkg, exportPaths, _extends$1({}, bundleConfig, { | ||
return buildOutputConfigs(pkg, exportPaths, { | ||
...bundleConfig, | ||
file: exportDist.file, | ||
format: exportDist.format, | ||
useTypescript | ||
}), exportCondition, cwd, tsOptions, dts); | ||
}, exportCondition, cwd, tsOptions, dts); | ||
}); | ||
@@ -891,7 +724,8 @@ // CLI output option is always prioritized | ||
outputConfigs = [ | ||
buildOutputConfigs(pkg, exportPaths, _extends$1({}, bundleConfig, { | ||
buildOutputConfigs(pkg, exportPaths, { | ||
...bundleConfig, | ||
file, | ||
format: bundleConfig.format || fallbackFormat, | ||
useTypescript | ||
}), exportCondition, cwd, tsOptions, dts) | ||
}, exportCondition, cwd, tsOptions, dts) | ||
]; | ||
@@ -907,31 +741,2 @@ } | ||
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _async_to_generator$1(fn) { | ||
return function() { | ||
var self = this, args = arguments; | ||
return new Promise(function(resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
let hasLoggedTsWarning = false; | ||
@@ -953,26 +758,20 @@ function resolveTypescript(cwd) { | ||
} | ||
function resolveTsConfig(cwd) { | ||
return _resolveTsConfig.apply(this, arguments); | ||
async function resolveTsConfig(cwd) { | ||
let tsCompilerOptions = {}; | ||
let tsConfigPath; | ||
tsConfigPath = path.resolve(cwd, 'tsconfig.json'); | ||
if (await fileExists(tsConfigPath)) { | ||
const ts = resolveTypescript(cwd); | ||
const basePath = tsConfigPath ? path.dirname(tsConfigPath) : cwd; | ||
const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config; | ||
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, basePath).options; | ||
} else { | ||
tsConfigPath = undefined; | ||
return null; | ||
} | ||
return { | ||
tsCompilerOptions, | ||
tsConfigPath | ||
}; | ||
} | ||
function _resolveTsConfig() { | ||
_resolveTsConfig = _async_to_generator$1(function*(cwd) { | ||
let tsCompilerOptions = {}; | ||
let tsConfigPath; | ||
tsConfigPath = path.resolve(cwd, 'tsconfig.json'); | ||
if (yield fileExists(tsConfigPath)) { | ||
const ts = resolveTypescript(cwd); | ||
const basePath = tsConfigPath ? path.dirname(tsConfigPath) : cwd; | ||
const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config; | ||
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, basePath).options; | ||
} else { | ||
tsConfigPath = undefined; | ||
return null; | ||
} | ||
return { | ||
tsCompilerOptions, | ||
tsConfigPath | ||
}; | ||
}); | ||
return _resolveTsConfig.apply(this, arguments); | ||
} | ||
@@ -984,3 +783,3 @@ function logSizeStats() { | ||
const padding = ' '.repeat(maxLength - filename.length); | ||
const action = filename.endsWith('.d.ts') ? 'Typed' : 'Built'; | ||
const action = dtsExtensionRegex.test(filename) ? 'Typed' : 'Built'; | ||
logger.log(` ✓ ${action} ${filename}${padding} - ${prettiedSize}`); | ||
@@ -990,57 +789,2 @@ }); | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _async_to_generator(fn) { | ||
return function() { | ||
var self = this, args = arguments; | ||
return new Promise(function(resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
function _extends() { | ||
_extends = Object.assign || function(target) { | ||
for(var i = 1; i < arguments.length; i++){ | ||
var source = arguments[i]; | ||
for(var key in source){ | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _object_without_properties_loose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for(i = 0; i < sourceKeys.length; i++){ | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function assignDefault(options, name, defaultValue) { | ||
@@ -1055,91 +799,77 @@ if (!(name in options) || options[name] == null) { | ||
} | ||
function bundle(entryPath) { | ||
return _bundle.apply(this, arguments); | ||
} | ||
function _bundle() { | ||
_bundle = _async_to_generator(function*(entryPath, _param = {}) { | ||
var { cwd: _cwd } = _param, options = _object_without_properties_loose(_param, [ | ||
"cwd" | ||
]); | ||
var _tsConfig, _tsConfig1, _tsConfig2; | ||
const cwd = path.resolve(process.cwd(), _cwd || ''); | ||
assignDefault(options, 'format', 'es'); | ||
assignDefault(options, 'minify', false); | ||
assignDefault(options, 'target', 'es2015'); | ||
const pkg = yield getPackageMeta(cwd); | ||
const packageType = getPackageType(pkg); | ||
const exportPaths = getExportPaths(pkg); | ||
const exportKeys = Object.keys(exportPaths).filter((key)=>key !== './package.json'); | ||
// const exportPathsLength = Object.keys(exportPaths).length | ||
const isMultiEntries = hasMultiEntryExport(exportPaths) // exportPathsLength > 1 | ||
; | ||
// has `types` field in package.json or has `types` exports in any export condition for multi-entries | ||
const hasTypings = Object.values(exportPaths).some((condition)=>condition.hasOwnProperty('types')); | ||
const tsConfig = yield resolveTsConfig(cwd); | ||
const hasTsConfig = Boolean((_tsConfig = tsConfig) == null ? void 0 : _tsConfig.tsConfigPath); | ||
const defaultTsOptions = { | ||
tsConfigPath: (_tsConfig1 = tsConfig) == null ? void 0 : _tsConfig1.tsConfigPath, | ||
tsCompilerOptions: ((_tsConfig2 = tsConfig) == null ? void 0 : _tsConfig2.tsCompilerOptions) || {} | ||
}; | ||
// Handle single entry file | ||
if (!isMultiEntries) { | ||
// Use specified string file path if possible, then fallback to the default behavior entry picking logic | ||
// e.g. "exports": "./dist/index.js" -> use "./index.<ext>" as entry | ||
entryPath = entryPath || (yield getSourcePathFromExportPath(cwd, '.', 'default')) || ''; | ||
async function bundle(entryPath, { cwd: _cwd, ...options } = {}) { | ||
var _tsConfig, _tsConfig1, _tsConfig2; | ||
const cwd = path.resolve(process.cwd(), _cwd || ''); | ||
assignDefault(options, 'format', 'es'); | ||
assignDefault(options, 'minify', false); | ||
assignDefault(options, 'target', 'es2015'); | ||
const pkg = await getPackageMeta(cwd); | ||
const packageType = getPackageType(pkg); | ||
const exportPaths = getExportPaths(pkg); | ||
const exportKeys = Object.keys(exportPaths).filter((key)=>key !== './package.json'); | ||
// const exportPathsLength = Object.keys(exportPaths).length | ||
const isMultiEntries = hasMultiEntryExport(exportPaths) // exportPathsLength > 1 | ||
; | ||
const tsConfig = await resolveTsConfig(cwd); | ||
const hasTsConfig = Boolean((_tsConfig = tsConfig) == null ? void 0 : _tsConfig.tsConfigPath); | ||
const defaultTsOptions = { | ||
tsConfigPath: (_tsConfig1 = tsConfig) == null ? void 0 : _tsConfig1.tsConfigPath, | ||
tsCompilerOptions: ((_tsConfig2 = tsConfig) == null ? void 0 : _tsConfig2.tsCompilerOptions) || {} | ||
}; | ||
// Handle single entry file | ||
if (!isMultiEntries) { | ||
// Use specified string file path if possible, then fallback to the default behavior entry picking logic | ||
// e.g. "exports": "./dist/index.js" -> use "./index.<ext>" as entry | ||
entryPath = entryPath || await getSourcePathFromExportPath(cwd, '.', 'default') || ''; | ||
} | ||
if (entryPath) { | ||
let mainEntryPath; | ||
let typesEntryPath; | ||
// with -o option | ||
if (options.file) { | ||
mainEntryPath = options.file; | ||
} else if (exportKeys.length === 0) { | ||
mainEntryPath = path.resolve(cwd, 'dist/index.js'); | ||
} | ||
if (entryPath) { | ||
let mainEntryPath; | ||
let typesEntryPath; | ||
// with -o option | ||
if (options.file) { | ||
mainEntryPath = options.file; | ||
} else if (exportKeys.length === 0) { | ||
mainEntryPath = path.resolve(cwd, 'dist/index.js'); | ||
if (mainEntryPath) { | ||
if (options.dts) { | ||
typesEntryPath = getTypeFilePath(mainEntryPath, undefined, cwd); | ||
} | ||
if (mainEntryPath) { | ||
if (options.dts) { | ||
typesEntryPath = getTypeFilePath(mainEntryPath, undefined, cwd); | ||
} | ||
exportPaths['.'] = constructDefaultExportCondition({ | ||
main: mainEntryPath, | ||
types: typesEntryPath | ||
}, packageType); | ||
} | ||
exportPaths['.'] = constructDefaultExportCondition({ | ||
main: mainEntryPath, | ||
types: typesEntryPath | ||
}, packageType); | ||
} | ||
const bundleOrWatch = (rollupConfig)=>{ | ||
const { input, exportName } = rollupConfig; | ||
const exportPath = getExportPath(pkg, cwd, exportName); | ||
// Log original entry file relative path | ||
const source = typeof input.input === 'string' ? path.relative(cwd, input.input) : exportPath; | ||
const buildMetadata = { | ||
source | ||
}; | ||
if (options.watch) { | ||
return Promise.resolve(runWatch(rollupConfig, buildMetadata)); | ||
} | ||
return runBundle(rollupConfig); | ||
} | ||
const bundleOrWatch = (rollupConfig)=>{ | ||
const { input, exportName } = rollupConfig; | ||
const exportPath = getExportPath(pkg, cwd, exportName); | ||
// Log original entry file relative path | ||
const source = typeof input.input === 'string' ? path.relative(cwd, input.input) : exportPath; | ||
const buildMetadata = { | ||
source | ||
}; | ||
const hasSpecifiedEntryFile = entryPath ? (yield fileExists(entryPath)) && (yield fs__default.default.stat(entryPath)).isFile() : false; | ||
if (!hasSpecifiedEntryFile && !isMultiEntries) { | ||
const err = new Error(`Entry file \`${entryPath}\` is not existed`); | ||
err.name = 'NOT_EXISTED'; | ||
return Promise.reject(err); | ||
if (options.watch) { | ||
return Promise.resolve(runWatch(rollupConfig, buildMetadata)); | ||
} | ||
// Enable types generation if it's types field specified in package.json | ||
if (hasTypings) { | ||
options.dts = hasTypings; | ||
} | ||
let result; | ||
const buildConfigs = yield buildEntryConfig(pkg, entryPath, exportPaths, options, cwd, defaultTsOptions, false); | ||
const assetsJobs = buildConfigs.map((rollupConfig)=>bundleOrWatch(rollupConfig)); | ||
const typesJobs = hasTsConfig && options.dts ? (yield buildEntryConfig(pkg, entryPath, exportPaths, options, cwd, defaultTsOptions, true)).map((rollupConfig)=>bundleOrWatch(rollupConfig)) : []; | ||
result = yield Promise.all(assetsJobs.concat(typesJobs)); | ||
logSizeStats(); | ||
return result; | ||
}); | ||
return _bundle.apply(this, arguments); | ||
return runBundle(rollupConfig); | ||
}; | ||
const hasSpecifiedEntryFile = entryPath ? await fileExists(entryPath) && (await fs__default.default.stat(entryPath)).isFile() : false; | ||
if (!hasSpecifiedEntryFile && !isMultiEntries) { | ||
const err = new Error(`Entry file \`${entryPath}\` is not existed`); | ||
err.name = 'NOT_EXISTED'; | ||
return Promise.reject(err); | ||
} | ||
let result; | ||
const buildConfigs = await buildEntryConfig(pkg, entryPath, exportPaths, options, cwd, defaultTsOptions, false); | ||
const assetsJobs = buildConfigs.map((rollupConfig)=>bundleOrWatch(rollupConfig)); | ||
const typesJobs = hasTsConfig ? (await buildEntryConfig(pkg, entryPath, exportPaths, options, cwd, defaultTsOptions, true)).map((rollupConfig)=>bundleOrWatch(rollupConfig)) : []; | ||
result = await Promise.all(assetsJobs.concat(typesJobs)); | ||
logSizeStats(); | ||
return result; | ||
} | ||
function runWatch({ input, output }, metadata) { | ||
const watchOptions = [ | ||
_extends({}, input, { | ||
{ | ||
...input, | ||
output: output, | ||
@@ -1151,3 +881,3 @@ watch: { | ||
} | ||
}) | ||
} | ||
]; | ||
@@ -1154,0 +884,0 @@ const watcher = rollup.watch(watchOptions); |
{ | ||
"name": "bunchee", | ||
"version": "3.5.1", | ||
"version": "3.6.0", | ||
"description": "zero config bundler for js/ts/jsx libraries", | ||
@@ -12,9 +12,11 @@ "bin": { | ||
"test": "jest --env node", | ||
"test:update": "TEST_UPDATE_SNAPSHOT=1 yarn test", | ||
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test", | ||
"clean": "rm -rf ./dist", | ||
"typecheck": "tsc --noEmit", | ||
"prepublishOnly": "yarn clean && yarn build && chmod +x ./dist/cli.js && yarn test", | ||
"prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/cli.js && pnpm test", | ||
"build:cli": "tsx ./src/cli.ts ./src/cli.ts --runtime node -f cjs -o ./dist/cli.js", | ||
"build:main": "tsx ./src/cli.ts ./src/index.ts --runtime node -f cjs", | ||
"build": "yarn build:main && yarn build:cli" | ||
"build": "pnpm build:main && pnpm build:cli", | ||
"format": "prettier --write .", | ||
"prepare": "husky install" | ||
}, | ||
@@ -54,6 +56,5 @@ "type": "commonjs", | ||
"@rollup/plugin-wasm": "~6.1.3", | ||
"@swc/core": "^1.3.46", | ||
"@swc/core": "^1.3.68", | ||
"@swc/helpers": "^0.5.0", | ||
"arg": "~5.0.2", | ||
"magic-string": "~0.30.0", | ||
"pretty-bytes": "~5.6.0", | ||
@@ -64,2 +65,3 @@ "publint": "~0.1.11", | ||
"rollup-plugin-swc3": "~0.8.1", | ||
"rollup-swc-preserve-directives": "~0.3.0", | ||
"tslib": "~2.5.0" | ||
@@ -82,3 +84,7 @@ }, | ||
"@types/jest": "29.0.0", | ||
"@types/node": "^20.4.1", | ||
"husky": "8.0.3", | ||
"jest": "29.0.1", | ||
"lint-staged": "13.2.3", | ||
"prettier": "3.0.0", | ||
"react": "18.2.0", | ||
@@ -88,2 +94,5 @@ "tsx": "3.12.6", | ||
}, | ||
"lint-staged": { | ||
"*.{ts,tsx,js,jsx,md,json,yml}": "prettier --write" | ||
}, | ||
"jest": { | ||
@@ -101,3 +110,4 @@ "moduleDirectories": [ | ||
} | ||
} | ||
}, | ||
"packageManager": "pnpm@7.24.3" | ||
} |
# bunchee | ||
> zero config bundler for JavaScript/TypeScript/JSX library | ||
@@ -33,2 +34,3 @@ | ||
``` | ||
Configure module exports | ||
@@ -67,4 +69,4 @@ | ||
* It's CommonJS for `require` and ESM for `import` based on the exports condition. | ||
* It's CommonJS for `.js` and ESM for `.mjs` based on the extension regardless the exports condition. Then for export condition like "node" you could choose the format with your extension. | ||
- It's CommonJS for `require` and ESM for `import` based on the exports condition. | ||
- It's CommonJS for `.js` and ESM for `.mjs` based on the extension regardless the exports condition. Then for export condition like "node" you could choose the format with your extension. | ||
@@ -113,2 +115,3 @@ ## Configuration | ||
#### Bundling everything without external dependencies | ||
To bundle your library without external dependencies, use the `--no-external` option: | ||
@@ -119,5 +122,7 @@ | ||
``` | ||
This will include all dependencies within your output bundle. | ||
### Environment Variables | ||
To pass environment variables to your bundled code, use the --env option followed by a comma-separated list of environment variable names: | ||
@@ -137,4 +142,4 @@ | ||
* `<cwd>/src/index.ts` will match `"."` export name or the if there's only one main export. | ||
* `<cwd>/src/lite.ts` will match `"./lite"` export name. | ||
- `<cwd>/src/index.ts` will match `"."` export name or the if there's only one main export. | ||
- `<cwd>/src/lite.ts` will match `"./lite"` export name. | ||
@@ -209,3 +214,3 @@ 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. | ||
```sh | ||
yarn add -D bunchee typescript | ||
npm i -D bunchee typescript | ||
``` | ||
@@ -217,3 +222,2 @@ | ||
Adding `"types"` or `"typing"` field in your package.json, types will be generated with that path. | ||
@@ -220,0 +224,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
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
6
255
48884
11
1095
+ Added@napi-rs/magic-string@0.3.4(transitive)
+ Added@napi-rs/magic-string-android-arm-eabi@0.3.4(transitive)
+ Added@napi-rs/magic-string-android-arm64@0.3.4(transitive)
+ Added@napi-rs/magic-string-darwin-arm64@0.3.4(transitive)
+ Added@napi-rs/magic-string-darwin-x64@0.3.4(transitive)
+ Added@napi-rs/magic-string-freebsd-x64@0.3.4(transitive)
+ Added@napi-rs/magic-string-linux-arm-gnueabihf@0.3.4(transitive)
+ Added@napi-rs/magic-string-linux-arm64-gnu@0.3.4(transitive)
+ Added@napi-rs/magic-string-linux-arm64-musl@0.3.4(transitive)
+ Added@napi-rs/magic-string-linux-x64-gnu@0.3.4(transitive)
+ Added@napi-rs/magic-string-linux-x64-musl@0.3.4(transitive)
+ Added@napi-rs/magic-string-win32-arm64-msvc@0.3.4(transitive)
+ Added@napi-rs/magic-string-win32-ia32-msvc@0.3.4(transitive)
+ Added@napi-rs/magic-string-win32-x64-msvc@0.3.4(transitive)
+ Addedrollup-swc-preserve-directives@0.3.2(transitive)
- Removedmagic-string@~0.30.0
Updated@swc/core@^1.3.68