Comparing version 3.5.0 to 3.5.1
@@ -100,3 +100,3 @@ #!/usr/bin/env node | ||
var version = "3.5.0"; | ||
var version = "3.5.1"; | ||
@@ -163,4 +163,4 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
} | ||
const { publint } = yield import('publint'); | ||
const { printMessage } = yield import('publint/utils'); | ||
const { publint } = yield import('publint'); | ||
const { printMessage } = yield import('publint/utils'); | ||
const messages = yield publint({ | ||
@@ -228,4 +228,4 @@ pkgDir: cwd, | ||
_run = _async_to_generator(function*(args) { | ||
var _args_external; | ||
const { source , format , watch , minify , sourcemap , target , runtime , dts , env } = args; | ||
var _args_external, _env; | ||
const { source, format, watch, minify, sourcemap, target, runtime, dts, env } = args; | ||
const cwd = args.cwd || process.cwd(); | ||
@@ -244,3 +244,3 @@ const file = args.file ? path__default.default.resolve(cwd, args.file) : undefined; | ||
sourcemap: sourcemap === false ? false : true, | ||
env: (env == null ? void 0 : env.split(',')) || [] | ||
env: ((_env = env) == null ? void 0 : _env.split(',')) || [] | ||
}; | ||
@@ -247,0 +247,0 @@ if (args.version) { |
@@ -13,2 +13,3 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
var prettyBytes = require('pretty-bytes'); | ||
var core = require('@swc/core'); | ||
var MagicString = require('magic-string'); | ||
@@ -65,35 +66,3 @@ var module$1 = require('module'); | ||
function preserveDirectivePlugin() { | ||
const directives = new Set(); | ||
return { | ||
name: 'use-directive', | ||
transform (code, id) { | ||
const regex = /^(?:['"]use[^'"]+['"][^\n]*|#![^\n]*)/gm; | ||
const replacedCode = code.replace(regex, (match)=>{ | ||
// replace double quotes with single quotes | ||
directives.add(match.replace(/["]/g, "'")); | ||
return ''; | ||
}); | ||
return { | ||
code: replacedCode, | ||
map: null | ||
}; | ||
}, | ||
renderChunk (code, _, { sourcemap }) { | ||
if (!directives.size) return null; | ||
const s = new MagicString__default.default(code); | ||
s.prepend(`${[ | ||
...directives | ||
].join('\n')}\n`); | ||
return { | ||
code: s.toString(), | ||
map: sourcemap ? s.generateMap({ | ||
hires: true | ||
}) : null | ||
}; | ||
} | ||
}; | ||
} | ||
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) { | ||
function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
@@ -112,3 +81,3 @@ var info = gen[key](arg); | ||
} | ||
function _async_to_generator$3(fn) { | ||
function _async_to_generator$4(fn) { | ||
return function() { | ||
@@ -119,6 +88,6 @@ var self = this, args = arguments; | ||
function _next(value) { | ||
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value); | ||
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err); | ||
asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
@@ -137,3 +106,3 @@ _next(undefined); | ||
function _getPackageMeta() { | ||
_getPackageMeta = _async_to_generator$3(function*(cwd) { | ||
_getPackageMeta = _async_to_generator$4(function*(cwd) { | ||
const pkgFilePath = path__default.default.resolve(cwd, 'package.json'); | ||
@@ -165,3 +134,3 @@ let targetPackageJson = {}; | ||
function _fileExists() { | ||
_fileExists = _async_to_generator$3(function*(filePath) { | ||
_fileExists = _async_to_generator$4(function*(filePath) { | ||
try { | ||
@@ -196,3 +165,3 @@ yield fs__default.default.access(filePath); | ||
function _findSourceEntryFile() { | ||
_findSourceEntryFile = _async_to_generator$3(function*(cwd, exportPath, exportTypeSuffix, ext) { | ||
_findSourceEntryFile = _async_to_generator$4(function*(cwd, exportPath, exportTypeSuffix, ext) { | ||
const filename = resolveSourceFile(cwd, `${exportPath}${exportTypeSuffix ? `.${exportTypeSuffix}` : ''}.${ext}`); | ||
@@ -213,2 +182,3 @@ if (yield fileExists(filename)) { | ||
// 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 = [ | ||
@@ -227,2 +197,3 @@ 'js', | ||
]; | ||
const availableESExtensionsRegex = /\.(m|c)?[jt]sx?$/; | ||
function getSourcePathFromExportPath(cwd, exportPath, exportType) { | ||
@@ -232,3 +203,3 @@ return _getSourcePathFromExportPath.apply(this, arguments); | ||
function _getSourcePathFromExportPath() { | ||
_getSourcePathFromExportPath = _async_to_generator$3(function*(cwd, exportPath, exportType) { | ||
_getSourcePathFromExportPath = _async_to_generator$4(function*(cwd, exportPath, exportType) { | ||
for (const ext of availableExtensions){ | ||
@@ -256,2 +227,105 @@ // ignore package.json | ||
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) { | ||
@@ -393,3 +467,3 @@ return pkg.types || pkg.typings; | ||
const packageType = getPackageType(pkg); | ||
const { exports: exportsConditions } = pkg; | ||
const { exports: exportsConditions } = pkg; | ||
if (exportsConditions) { | ||
@@ -477,5 +551,6 @@ const paths = parseExport(exportsConditions, packageType); | ||
function getTypeFilePath(entryFilePath, exportCondition, cwd) { | ||
var _exportCondition; | ||
const name = filenameWithoutExtension(entryFilePath); | ||
const firstDistPath = exportCondition ? Object.values(exportCondition.export)[0] : undefined; | ||
const exportName = (exportCondition == null ? void 0 : exportCondition.name) || 'index'; | ||
const exportName = ((_exportCondition = exportCondition) == null ? void 0 : _exportCondition.name) || 'index'; | ||
return entryFilePath ? name + '.d.ts' : path.resolve(firstDistPath ? path.dirname(firstDistPath) : path.join(cwd, 'dist'), (exportName === '.' ? 'index' : exportName) + '.d.ts'); | ||
@@ -527,3 +602,3 @@ } | ||
} | ||
const minifyOptions = { | ||
const swcMinifyOptions = { | ||
compress: true, | ||
@@ -554,3 +629,4 @@ format: { | ||
} | ||
function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath , tsCompilerOptions }, dts) { | ||
function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath, tsCompilerOptions }, dts) { | ||
var _tsCompilerOptions; | ||
var _options_external; | ||
@@ -564,7 +640,31 @@ const externals = options.noExternal ? [] : [ | ||
] : [])); | ||
const { useTypescript , runtime , target: jscTarget , minify } = options; | ||
const hasSpecifiedTsTarget = Boolean((tsCompilerOptions == null ? void 0 : tsCompilerOptions.target) && tsConfigPath); | ||
const { useTypescript, runtime, target: jscTarget, minify: shouldMinify } = options; | ||
const hasSpecifiedTsTarget = Boolean(((_tsCompilerOptions = tsCompilerOptions) == null ? void 0 : _tsCompilerOptions.target) && tsConfigPath); | ||
const swcParserConfig = { | ||
syntax: useTypescript ? 'typescript' : 'ecmascript', | ||
[useTypescript ? 'tsx' : 'jsx']: true, | ||
privateMethod: true, | ||
classPrivateProperty: true, | ||
exportDefaultFrom: true | ||
}; | ||
const swcOptions = { | ||
jsc: _extends$1({}, !hasSpecifiedTsTarget && { | ||
target: jscTarget | ||
}, { | ||
loose: true, | ||
externalHelpers: false, | ||
parser: swcParserConfig | ||
}, shouldMinify && { | ||
minify: _extends$1({}, swcMinifyOptions, { | ||
sourceMap: options.sourcemap | ||
}) | ||
}), | ||
sourceMaps: options.sourcemap, | ||
inlineSourcesContent: false | ||
}; | ||
const sizePlugin = sizeCollector.plugin(cwd); | ||
const commonPlugins = [ | ||
preserveDirectivePlugin(), | ||
swcRenderDirectivePlugin({ | ||
swcParserConfig | ||
}), | ||
sizePlugin | ||
@@ -612,26 +712,7 @@ ]; | ||
pluginWasm.wasm(), | ||
rollupPluginSwc3.swc({ | ||
include: /\.(m|c)?[jt]sx?$/, | ||
rollupPluginSwc3.swc(_extends$1({ | ||
include: availableESExtensionsRegex, | ||
exclude: 'node_modules', | ||
tsconfig: tsConfigPath, | ||
jsc: _extends$1({}, !hasSpecifiedTsTarget && { | ||
target: jscTarget | ||
}, { | ||
loose: true, | ||
externalHelpers: false, | ||
parser: { | ||
syntax: useTypescript ? 'typescript' : 'ecmascript', | ||
[useTypescript ? 'tsx' : 'jsx']: true, | ||
privateMethod: true, | ||
classPrivateProperty: true, | ||
exportDefaultFrom: true | ||
} | ||
}, minify && { | ||
minify: _extends$1({}, minifyOptions, { | ||
sourceMap: options.sourcemap | ||
}) | ||
}), | ||
sourceMaps: options.sourcemap, | ||
inlineSourcesContent: false | ||
}) | ||
tsconfig: tsConfigPath | ||
}, swcOptions)) | ||
]).filter(isNotNull); | ||
@@ -655,3 +736,4 @@ return { | ||
'UNRESOLVED_IMPORT', | ||
'THIS_IS_UNDEFINED' | ||
'THIS_IS_UNDEFINED', | ||
'MODULE_LEVEL_DIRECTIVE' // ignore warnings for directives like `use client` | ||
].includes(code)) return; | ||
@@ -667,2 +749,3 @@ // If the circular dependency warning is from node_modules, ignore it | ||
function hasEsmExport(exportPaths, tsCompilerOptions) { | ||
var _tsCompilerOptions; | ||
let hasEsm = false; | ||
@@ -677,6 +760,6 @@ for(const key in exportPaths){ | ||
} | ||
return Boolean(hasEsm || (tsCompilerOptions == null ? void 0 : tsCompilerOptions.esModuleInterop)); | ||
return Boolean(hasEsm || ((_tsCompilerOptions = tsCompilerOptions) == null ? void 0 : _tsCompilerOptions.esModuleInterop)); | ||
} | ||
function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, dts) { | ||
const { format } = options; | ||
function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, dts) { | ||
const { format } = options; | ||
// Add esm mark and interop helper if esm export is detected | ||
@@ -775,3 +858,3 @@ const useEsModuleMark = hasEsmExport(exportPaths, tsCompilerOptions); | ||
function buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dts) { | ||
const { file } = bundleConfig; | ||
const { file } = bundleConfig; | ||
const useTypescript = Boolean(tsOptions.tsConfigPath); | ||
@@ -970,5 +1053,6 @@ const options = _extends$1({}, bundleConfig, { | ||
_bundle = _async_to_generator(function*(entryPath, _param = {}) { | ||
var { cwd: _cwd } = _param, options = _object_without_properties_loose(_param, [ | ||
var { cwd: _cwd } = _param, options = _object_without_properties_loose(_param, [ | ||
"cwd" | ||
]); | ||
var _tsConfig, _tsConfig1, _tsConfig2; | ||
const cwd = path.resolve(process.cwd(), _cwd || ''); | ||
@@ -988,6 +1072,6 @@ assignDefault(options, 'format', 'es'); | ||
const tsConfig = yield resolveTsConfig(cwd); | ||
const hasTsConfig = Boolean(tsConfig == null ? void 0 : tsConfig.tsConfigPath); | ||
const hasTsConfig = Boolean((_tsConfig = tsConfig) == null ? void 0 : _tsConfig.tsConfigPath); | ||
const defaultTsOptions = { | ||
tsConfigPath: tsConfig == null ? void 0 : tsConfig.tsConfigPath, | ||
tsCompilerOptions: (tsConfig == null ? void 0 : tsConfig.tsCompilerOptions) || {} | ||
tsConfigPath: (_tsConfig1 = tsConfig) == null ? void 0 : _tsConfig1.tsConfigPath, | ||
tsCompilerOptions: ((_tsConfig2 = tsConfig) == null ? void 0 : _tsConfig2.tsCompilerOptions) || {} | ||
}; | ||
@@ -1020,3 +1104,3 @@ // Handle single entry file | ||
const bundleOrWatch = (rollupConfig)=>{ | ||
const { input , exportName } = rollupConfig; | ||
const { input, exportName } = rollupConfig; | ||
const exportPath = getExportPath(pkg, cwd, exportName); | ||
@@ -1053,3 +1137,3 @@ // Log original entry file relative path | ||
} | ||
function runWatch({ input , output }, metadata) { | ||
function runWatch({ input, output }, metadata) { | ||
const watchOptions = [ | ||
@@ -1087,3 +1171,3 @@ _extends({}, input, { | ||
} | ||
function runBundle({ input , output }) { | ||
function runBundle({ input, output }) { | ||
return rollup.rollup(input).then((bundle)=>{ | ||
@@ -1090,0 +1174,0 @@ const writeJobs = output.map((options)=>bundle.write(options)); |
{ | ||
"name": "bunchee", | ||
"version": "3.5.0", | ||
"version": "3.5.1", | ||
"description": "zero config bundler for js/ts/jsx libraries", | ||
@@ -48,17 +48,17 @@ "bin": { | ||
"dependencies": { | ||
"@rollup/plugin-commonjs": "24.0.1", | ||
"@rollup/plugin-json": "6.0.0", | ||
"@rollup/plugin-node-resolve": "15.0.2", | ||
"@rollup/plugin-replace": "5.0.2", | ||
"@rollup/plugin-wasm": "6.1.3", | ||
"@swc/core": "1.3.46", | ||
"@swc/helpers": "0.5.0", | ||
"arg": "5.0.2", | ||
"magic-string": "0.30.0", | ||
"pretty-bytes": "5.6.0", | ||
"publint": "0.1.11", | ||
"rollup": "3.20.2", | ||
"rollup-plugin-dts": "5.3.0", | ||
"rollup-plugin-swc3": "0.8.1", | ||
"tslib": "2.5.0" | ||
"@rollup/plugin-commonjs": "~24.0.1", | ||
"@rollup/plugin-json": "~6.0.0", | ||
"@rollup/plugin-node-resolve": "~15.0.2", | ||
"@rollup/plugin-replace": "~5.0.2", | ||
"@rollup/plugin-wasm": "~6.1.3", | ||
"@swc/core": "^1.3.46", | ||
"@swc/helpers": "^0.5.0", | ||
"arg": "~5.0.2", | ||
"magic-string": "~0.30.0", | ||
"pretty-bytes": "~5.6.0", | ||
"publint": "~0.1.11", | ||
"rollup": "~3.20.2", | ||
"rollup-plugin-dts": "~5.3.0", | ||
"rollup-plugin-swc3": "~0.8.1", | ||
"tslib": "~2.5.0" | ||
}, | ||
@@ -65,0 +65,0 @@ "peerDependencies": { |
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
61772
1458
+ Added@rollup/plugin-json@6.0.1(transitive)
+ Added@rollup/plugin-replace@5.0.7(transitive)
+ Added@swc/core@1.7.26(transitive)
+ Added@swc/core-darwin-arm64@1.7.26(transitive)
+ Added@swc/core-darwin-x64@1.7.26(transitive)
+ Added@swc/core-linux-arm-gnueabihf@1.7.26(transitive)
+ Added@swc/core-linux-arm64-gnu@1.7.26(transitive)
+ Added@swc/core-linux-arm64-musl@1.7.26(transitive)
+ Added@swc/core-linux-x64-gnu@1.7.26(transitive)
+ Added@swc/core-linux-x64-musl@1.7.26(transitive)
+ Added@swc/core-win32-arm64-msvc@1.7.26(transitive)
+ Added@swc/core-win32-ia32-msvc@1.7.26(transitive)
+ Added@swc/core-win32-x64-msvc@1.7.26(transitive)
+ Added@swc/counter@0.1.3(transitive)
+ Added@swc/helpers@0.5.13(transitive)
+ Added@swc/types@0.1.12(transitive)
+ Addedmagic-string@0.30.11(transitive)
+ Addedpublint@0.1.16(transitive)
+ Addedrollup@3.20.7(transitive)
+ Addedrollup-plugin-dts@5.3.1(transitive)
+ Addedrollup-plugin-swc3@0.8.2(transitive)
+ Addedtslib@2.5.3(transitive)
- Removed@rollup/plugin-json@6.0.0(transitive)
- Removed@rollup/plugin-replace@5.0.2(transitive)
- Removed@swc/core@1.3.46(transitive)
- Removed@swc/core-darwin-arm64@1.3.46(transitive)
- Removed@swc/core-darwin-x64@1.3.46(transitive)
- Removed@swc/core-linux-arm-gnueabihf@1.3.46(transitive)
- Removed@swc/core-linux-arm64-gnu@1.3.46(transitive)
- Removed@swc/core-linux-arm64-musl@1.3.46(transitive)
- Removed@swc/core-linux-x64-gnu@1.3.46(transitive)
- Removed@swc/core-linux-x64-musl@1.3.46(transitive)
- Removed@swc/core-win32-arm64-msvc@1.3.46(transitive)
- Removed@swc/core-win32-ia32-msvc@1.3.46(transitive)
- Removed@swc/core-win32-x64-msvc@1.3.46(transitive)
- Removed@swc/helpers@0.5.0(transitive)
- Removedmagic-string@0.30.0(transitive)
- Removedpublint@0.1.11(transitive)
- Removedrollup@3.20.2(transitive)
- Removedrollup-plugin-dts@5.3.0(transitive)
- Removedrollup-plugin-swc3@0.8.1(transitive)
- Removedtslib@2.5.0(transitive)
Updated@rollup/plugin-json@~6.0.0
Updated@rollup/plugin-wasm@~6.1.3
Updated@swc/core@^1.3.46
Updated@swc/helpers@^0.5.0
Updatedarg@~5.0.2
Updatedmagic-string@~0.30.0
Updatedpretty-bytes@~5.6.0
Updatedpublint@~0.1.11
Updatedrollup@~3.20.2
Updatedrollup-plugin-dts@~5.3.0
Updatedrollup-plugin-swc3@~0.8.1
Updatedtslib@~2.5.0