bunchee
Advanced tools
Comparing version 3.9.1 to 3.9.2
@@ -57,3 +57,3 @@ #!/usr/bin/env node | ||
var version = "3.9.1"; | ||
var version = "3.9.2"; | ||
@@ -60,0 +60,0 @@ const helpMessage = ` |
@@ -6,3 +6,2 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
var rollup = require('rollup'); | ||
var module$1 = require('module'); | ||
var pluginWasm = require('@rollup/plugin-wasm'); | ||
@@ -17,2 +16,3 @@ var rollupPluginSwc3 = require('rollup-plugin-swc3'); | ||
var swcPreserveDirectivePlugin = require('rollup-swc-preserve-directives'); | ||
var module$1 = require('module'); | ||
@@ -63,114 +63,2 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } | ||
function exit(err) { | ||
logger.error(err); | ||
process.exit(1); | ||
} | ||
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; | ||
} | ||
async function fileExists(filePath) { | ||
try { | ||
await fs__default.default.access(filePath); | ||
return true; | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return false; | ||
} | ||
throw err; | ||
} | ||
} | ||
// . -> pkg name | ||
// ./lite -> <pkg name>/lite | ||
function getExportPath(pkg, cwd, exportName) { | ||
const name = pkg.name || path__default.default.basename(cwd); | ||
if (exportName === '.' || !exportName) return name; | ||
return path__default.default.join(name, exportName); | ||
} | ||
const isNotNull = (n)=>Boolean(n); | ||
function resolveSourceFile(cwd, filename) { | ||
return path__default.default.resolve(cwd, SRC, filename); | ||
} | ||
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; | ||
} | ||
// Map '.' -> './index.[ext]' | ||
// Map './lite' -> './lite.[ext]' | ||
// Return undefined if no match or if it's package.json exports | ||
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; | ||
} | ||
const filename = await findSourceEntryFile(cwd, exportPath, null, ext); | ||
if (filename) return filename; | ||
} | ||
return; | ||
} | ||
// Unlike path.basename, forcedly removing extension | ||
function filenameWithoutExtension(file) { | ||
return file ? file.replace(new RegExp(`${path__default.default.extname(file)}$`), '') : undefined; | ||
} | ||
const nonNullable = (n)=>Boolean(n); | ||
const hasAvailableExtension = (filename)=>availableExtensions.includes(path__default.default.extname(filename).slice(1)); | ||
const hasCjsExtension = (filename)=>path__default.default.extname(filename) === '.cjs'; | ||
let hasLoggedTsWarning = false; | ||
function resolveTypescript(cwd) { | ||
let ts; | ||
const m = new module$1.Module('', undefined); | ||
m.paths = module$1.Module._nodeModulePaths(cwd); | ||
try { | ||
ts = m.require('typescript'); | ||
} catch (_) { | ||
console.error(_); | ||
if (!hasLoggedTsWarning) { | ||
hasLoggedTsWarning = true; | ||
exit('Could not load TypeScript compiler. Try to install `typescript` as dev dependency'); | ||
} | ||
} | ||
return ts; | ||
} | ||
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 | ||
}; | ||
} | ||
async function convertCompilerOptions(cwd, json) { | ||
const ts = resolveTypescript(cwd); | ||
return ts.convertCompilerOptionsFromJson(json, './'); | ||
} | ||
function createChunkSizeCollector() { | ||
@@ -298,2 +186,75 @@ const sizes = new Map(); | ||
function exit(err) { | ||
logger.error(err); | ||
process.exit(1); | ||
} | ||
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; | ||
} | ||
async function fileExists(filePath) { | ||
try { | ||
await fs__default.default.access(filePath); | ||
return true; | ||
} catch (err) { | ||
if (err.code === 'ENOENT') { | ||
return false; | ||
} | ||
throw err; | ||
} | ||
} | ||
// . -> pkg name | ||
// ./lite -> <pkg name>/lite | ||
function getExportPath(pkg, cwd, exportName) { | ||
const name = pkg.name || path__default.default.basename(cwd); | ||
if (exportName === '.' || !exportName) return name; | ||
return path__default.default.join(name, exportName); | ||
} | ||
const isNotNull = (n)=>Boolean(n); | ||
function resolveSourceFile(cwd, filename) { | ||
return path__default.default.resolve(cwd, SRC, filename); | ||
} | ||
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; | ||
} | ||
// Map '.' -> './index.[ext]' | ||
// Map './lite' -> './lite.[ext]' | ||
// Return undefined if no match or if it's package.json exports | ||
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; | ||
} | ||
const filename = await findSourceEntryFile(cwd, exportPath, null, ext); | ||
if (filename) return filename; | ||
} | ||
return; | ||
} | ||
// Unlike path.basename, forcedly removing extension | ||
function filenameWithoutExtension(file) { | ||
return file ? file.replace(new RegExp(`${path__default.default.extname(file)}$`), '') : undefined; | ||
} | ||
const nonNullable = (n)=>Boolean(n); | ||
const hasAvailableExtension = (filename)=>availableExtensions.includes(path__default.default.extname(filename).slice(1)); | ||
const hasCjsExtension = (filename)=>path__default.default.extname(filename) === '.cjs'; | ||
function getTypings(pkg) { | ||
@@ -594,3 +555,3 @@ return pkg.types || pkg.typings; | ||
} | ||
function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath, tsCompilerOptions }, dts) { | ||
async function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath, tsCompilerOptions }, dts) { | ||
const hasNoExternal = options.external === null; | ||
@@ -606,3 +567,3 @@ var _options_external; | ||
const { useTypescript, runtime, target: jscTarget, minify: shouldMinify } = options; | ||
const hasSpecifiedTsTarget = Boolean((tsCompilerOptions == null ? void 0 : tsCompilerOptions.target) && tsConfigPath); | ||
const hasSpecifiedTsTarget = Boolean(tsCompilerOptions.target && tsConfigPath); | ||
const swcParserConfig = { | ||
@@ -637,32 +598,43 @@ syntax: useTypescript ? 'typescript' : 'ecmascript', | ||
]; | ||
let baseResolvedTsOptions; | ||
if (dts && useTypescript) { | ||
baseResolvedTsOptions = convertCompilerOptions(cwd, { | ||
declaration: true, | ||
noEmit: false, | ||
noEmitOnError: true, | ||
emitDeclarationOnly: true, | ||
checkJs: false, | ||
declarationMap: false, | ||
skipLibCheck: true, | ||
preserveSymlinks: false, | ||
target: 'esnext', | ||
module: 'esnext', | ||
incremental: false, | ||
jsx: tsCompilerOptions.jsx || 'react' | ||
}); | ||
} | ||
const plugins = (dts ? [ | ||
const baseResolvedTsOptions = { | ||
declaration: true, | ||
noEmit: false, | ||
noEmitOnError: true, | ||
emitDeclarationOnly: true, | ||
checkJs: false, | ||
declarationMap: false, | ||
skipLibCheck: true, | ||
preserveSymlinks: false, | ||
// disable incremental build | ||
incremental: false, | ||
// use default tsBuildInfoFile value | ||
tsBuildInfoFile: '.tsbuildinfo', | ||
target: 'esnext', | ||
module: 'esnext', | ||
jsx: tsCompilerOptions.jsx || 'react' | ||
}; | ||
const typesPlugins = [ | ||
...commonPlugins, | ||
inlineCss({ | ||
skip: true | ||
}), | ||
useTypescript && require('rollup-plugin-dts').default({ | ||
tsconfig: tsConfigPath, | ||
compilerOptions: { | ||
...tsCompilerOptions, | ||
...baseResolvedTsOptions | ||
} | ||
}) | ||
] : [ | ||
]; | ||
if (useTypescript) { | ||
const mergedOptions = { | ||
...baseResolvedTsOptions, | ||
...tsCompilerOptions | ||
}; | ||
// error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single | ||
// file or when option '--tsBuildInfoFile' is specified. | ||
if (!mergedOptions.incremental) { | ||
delete mergedOptions.incremental; | ||
delete mergedOptions.tsBuildInfoFile; | ||
} | ||
const dtsPlugin = require('rollup-plugin-dts').default({ | ||
tsconfig: undefined, | ||
compilerOptions: mergedOptions | ||
}); | ||
typesPlugins.push(dtsPlugin); | ||
} | ||
const plugins = (dts ? typesPlugins : [ | ||
...commonPlugins, | ||
@@ -821,3 +793,3 @@ inlineCss({ | ||
} | ||
function buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dts) { | ||
async function buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dts) { | ||
const { file } = bundleConfig; | ||
@@ -829,3 +801,3 @@ const useTypescript = Boolean(tsOptions.tsConfigPath); | ||
}; | ||
const inputOptions = buildInputConfig(entry, pkg, options, cwd, tsOptions, dts); | ||
const inputOptions = await buildInputConfig(entry, pkg, options, cwd, tsOptions, dts); | ||
const outputExports = getExportConditionDist(pkg, exportCondition, cwd); | ||
@@ -873,2 +845,37 @@ let outputConfigs = []; | ||
let hasLoggedTsWarning = false; | ||
function resolveTypescript(cwd) { | ||
let ts; | ||
const m = new module$1.Module('', undefined); | ||
m.paths = module$1.Module._nodeModulePaths(cwd); | ||
try { | ||
ts = m.require('typescript'); | ||
} catch (_) { | ||
console.error(_); | ||
if (!hasLoggedTsWarning) { | ||
hasLoggedTsWarning = true; | ||
exit('Could not load TypeScript compiler. Try to install `typescript` as dev dependency'); | ||
} | ||
} | ||
return ts; | ||
} | ||
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 | ||
}; | ||
} | ||
// TODO: support nested wildcard exportsCondition (e.g. './foo/*') | ||
@@ -875,0 +882,0 @@ const getWildcardExports = (exportsCondition)=>{ |
{ | ||
"name": "bunchee", | ||
"version": "3.9.1", | ||
"version": "3.9.2", | ||
"description": "zero config bundler for js/ts/jsx libraries", | ||
@@ -89,3 +89,3 @@ "bin": { | ||
"react": "^18.2.0", | ||
"tsx": "^3.12.6", | ||
"tsx": "^3.14.0", | ||
"typescript": "^4.9.5" | ||
@@ -92,0 +92,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
57067
1262