Socket
Socket
Sign inDemoInstall

bunchee

Package Overview
Dependencies
Maintainers
1
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bunchee - npm Package Compare versions

Comparing version 4.2.7 to 4.2.8

2

dist/bin/cli.js

@@ -118,3 +118,3 @@ #!/usr/bin/env node

var version = "4.2.7";
var version = "4.2.8";

@@ -121,0 +121,0 @@ const helpMessage = `

@@ -6,2 +6,4 @@ Object.defineProperty(exports, '__esModule', { value: true });

var rollup = require('rollup');
var module$1 = require('module');
var require$$0 = require('tty');
var pluginWasm = require('@rollup/plugin-wasm');

@@ -16,5 +18,3 @@ var rollupPluginSwc3 = require('rollup-plugin-swc3');

var pluginutils = require('@rollup/pluginutils');
var require$$0 = require('tty');
var prettyBytes = require('pretty-bytes');
var module$1 = require('module');

@@ -25,2 +25,3 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var path__default = /*#__PURE__*/_interopDefault(path);
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);

@@ -31,147 +32,4 @@ var json__default = /*#__PURE__*/_interopDefault(json);

var preserveDirectives__default = /*#__PURE__*/_interopDefault(preserveDirectives);
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
var prettyBytes__default = /*#__PURE__*/_interopDefault(prettyBytes);
function minifyCSS(content) {
return content.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$|(?:^|\s)(\s+)|\s*([\{\};,:])\s*|\s+(!)\s+/g, (match, p1, p2, p3, p4)=>{
if (p1) return p1 === ' ' ? '' : p1;
if (p2) return ' ';
if (p3) return p3;
if (p4) return '!';
});
}
const helpers = {
cssImport: {
// have to assign r.type = 'text/css' to make it work in Safari
global: `\
function __insertCSS(code) {
if (!code || typeof document == 'undefined') return
let head = document.head || document.getElementsByTagName('head')[0]
let style = document.createElement('style')
style.type = 'text/css'
head.appendChild(style)
;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
}
`,
create (code) {
return `__insertCSS(${JSON.stringify(code)});`;
}
},
cssAssertionImport: {
global: '',
create (code) {
return `\
const sheet = new CSSStyleSheet()
sheet.replaceSync(${JSON.stringify(code)})
export default sheet`;
}
}
};
function inlineCss(options) {
const cssIds = new Set();
var _options_exclude;
const filter = pluginutils.createFilter([
'**/*.css'
], (_options_exclude = options.exclude) != null ? _options_exclude : []);
// Follow up for rollup 4 for better support of assertion support https://github.com/rollup/rollup/issues/4818
return {
name: 'inline-css',
transform (code, id) {
if (!filter(id)) return;
if (options.skip) return '';
const cssCode = minifyCSS(code);
cssIds.add(id);
return {
code: helpers.cssImport.create(cssCode),
map: {
mappings: ''
}
};
},
renderChunk (code, options) {
const dependenciesIds = this.getModuleIds();
let foundCss = false;
for (const depId of dependenciesIds){
if (depId && cssIds.has(depId)) {
foundCss = true;
break;
}
}
if (!foundCss) return;
return {
code: `${helpers.cssImport.global}\n${code}`,
map: {
mappings: ''
}
};
}
};
}
function rawContent({ exclude }) {
const filter = pluginutils.createFilter([
'**/*.data',
'**/*.txt'
], exclude);
return {
name: 'string',
transform (code, id) {
if (filter(id)) {
return {
code: `const data = ${JSON.stringify(code)};\nexport default data;`,
map: null
};
}
return null;
}
};
}
// Alias entries to import path
// e.g.
// For a resolved file, if it's one of the entries,
// aliases it as export path, such as <absolute file> -> <pkg>/<export path>
function aliasEntries({ entries }) {
return {
name: 'alias',
resolveId: {
async handler (source, importer, options) {
const resolvedId = await this.resolve(source, importer, options);
if (resolvedId != null) {
const aliasedId = entries[resolvedId.id];
if (aliasedId != null) {
return {
id: aliasedId,
external: true
};
}
}
return null;
}
}
};
}
function prependDirectives() {
return {
name: 'prependDirective',
transform: {
order: 'post',
handler (code, id) {
var _moduleInfo_meta;
const moduleInfo = this.getModuleInfo(id);
if (moduleInfo == null ? void 0 : (_moduleInfo_meta = moduleInfo.meta) == null ? void 0 : _moduleInfo_meta.preserveDirectives) {
const firstDirective = moduleInfo.meta.preserveDirectives.directives[0];
if (firstDirective) {
const directive = firstDirective.value;
const directiveCode = `'${directive}';`;
return directiveCode + '\n' + code;
}
}
return null;
}
}
};
}
const availableExtensions = [

@@ -364,2 +222,182 @@ 'js',

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 {
return null;
}
return {
tsCompilerOptions,
tsConfigPath
};
}
async function convertCompilerOptions(cwd, json) {
const ts = resolveTypescript(cwd);
return ts.convertCompilerOptionsFromJson(json, './');
}
function minifyCSS(content) {
return content.replace(/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$|(?:^|\s)(\s+)|\s*([\{\};,:])\s*|\s+(!)\s+/g, (match, p1, p2, p3, p4)=>{
if (p1) return p1 === ' ' ? '' : p1;
if (p2) return ' ';
if (p3) return p3;
if (p4) return '!';
});
}
const helpers = {
cssImport: {
// have to assign r.type = 'text/css' to make it work in Safari
global: `\
function __insertCSS(code) {
if (!code || typeof document == 'undefined') return
let head = document.head || document.getElementsByTagName('head')[0]
let style = document.createElement('style')
style.type = 'text/css'
head.appendChild(style)
;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
}
`,
create (code) {
return `__insertCSS(${JSON.stringify(code)});`;
}
},
cssAssertionImport: {
global: '',
create (code) {
return `\
const sheet = new CSSStyleSheet()
sheet.replaceSync(${JSON.stringify(code)})
export default sheet`;
}
}
};
function inlineCss(options) {
const cssIds = new Set();
var _options_exclude;
const filter = pluginutils.createFilter([
'**/*.css'
], (_options_exclude = options.exclude) != null ? _options_exclude : []);
// Follow up for rollup 4 for better support of assertion support https://github.com/rollup/rollup/issues/4818
return {
name: 'inline-css',
transform (code, id) {
if (!filter(id)) return;
if (options.skip) return '';
const cssCode = minifyCSS(code);
cssIds.add(id);
return {
code: helpers.cssImport.create(cssCode),
map: {
mappings: ''
}
};
},
renderChunk (code, options) {
const dependenciesIds = this.getModuleIds();
let foundCss = false;
for (const depId of dependenciesIds){
if (depId && cssIds.has(depId)) {
foundCss = true;
break;
}
}
if (!foundCss) return;
return {
code: `${helpers.cssImport.global}\n${code}`,
map: {
mappings: ''
}
};
}
};
}
function rawContent({ exclude }) {
const filter = pluginutils.createFilter([
'**/*.data',
'**/*.txt'
], exclude);
return {
name: 'string',
transform (code, id) {
if (filter(id)) {
return {
code: `const data = ${JSON.stringify(code)};\nexport default data;`,
map: null
};
}
return null;
}
};
}
// Alias entries to import path
// e.g.
// For a resolved file, if it's one of the entries,
// aliases it as export path, such as <absolute file> -> <pkg>/<export path>
function aliasEntries({ entries }) {
return {
name: 'alias',
resolveId: {
async handler (source, importer, options) {
const resolvedId = await this.resolve(source, importer, options);
if (resolvedId != null) {
const aliasedId = entries[resolvedId.id];
if (aliasedId != null) {
return {
id: aliasedId,
external: true
};
}
}
return null;
}
}
};
}
function prependDirectives() {
return {
name: 'prependDirective',
transform: {
order: 'post',
handler (code, id) {
var _moduleInfo_meta;
const moduleInfo = this.getModuleInfo(id);
if (moduleInfo == null ? void 0 : (_moduleInfo_meta = moduleInfo.meta) == null ? void 0 : _moduleInfo_meta.preserveDirectives) {
const firstDirective = moduleInfo.meta.preserveDirectives.directives[0];
if (firstDirective) {
const directive = firstDirective.value;
const directiveCode = `'${directive}';`;
return directiveCode + '\n' + code;
}
}
return null;
}
}
};
}
function getTypings(pkg) {

@@ -405,3 +443,3 @@ return pkg.types || pkg.typings;

}
function findExport(exportPath, exportCondition, paths, packageType) {
function findExport(exportPath, exportCondition, paths, packageType, currentPath) {
// Skip `types` field, it cannot be the entry point

@@ -411,6 +449,15 @@ if (exportPath === 'types') return;

const fullExportCondition = constructFullExportCondition(exportCondition, packageType);
paths[exportPath] = {
...paths[exportPath],
...fullExportCondition
};
if (exportPath.startsWith('.')) {
paths[exportPath] = {
...paths[exportPath],
...fullExportCondition
};
} else {
// exportPath is exportType, import, require, ...
// merge to currentPath
paths[currentPath] = {
...paths[currentPath],
[exportPath]: fullExportCondition.default
};
}
return;

@@ -421,5 +468,5 @@ }

// subpath is actual export path, ./a, ./b, ...
const nestedExportPath = joinRelativePath(exportPath, subpath);
const nestedExportPath = joinRelativePath(currentPath, subpath);
const nestedExportCondition = exportCondition[subpath];
findExport(nestedExportPath, nestedExportCondition, paths, packageType);
findExport(nestedExportPath, nestedExportCondition, paths, packageType, nestedExportPath);
} else {

@@ -432,3 +479,3 @@ // subpath is exportType, import, require, ...

};
findExport(exportPath, nestedExportCondition, paths, packageType);
findExport(exportPath, nestedExportCondition, paths, packageType, currentPath);
}

@@ -463,11 +510,12 @@ });

const paths = {};
const initialPath = '.';
if (typeof exportsCondition === 'string') {
paths['.'] = constructFullExportCondition(exportsCondition, packageType);
paths[initialPath] = constructFullExportCondition(exportsCondition, packageType);
} else if (typeof exportsCondition === 'object') {
if (isExportLike(exportsCondition)) {
paths['.'] = constructFullExportCondition(exportsCondition, packageType);
paths[initialPath] = constructFullExportCondition(exportsCondition, packageType);
} else {
Object.keys(exportsCondition).forEach((key)=>{
const exportCondition = exportsCondition[key];
findExport(key, exportCondition, paths, packageType);
findExport(key, exportCondition, paths, packageType, initialPath);
});

@@ -519,3 +567,3 @@ }

var _pathsMap_;
const pathsMap = {};
let pathsMap = {};
const packageType = pkgType != null ? pkgType : getPackageType(pkg);

@@ -526,3 +574,6 @@ const isEsmPackage = isESModulePackage(packageType);

const paths = parseExport(exportsConditions, packageType);
Object.assign(pathsMap, paths);
pathsMap = {
...pathsMap,
...paths
};
}

@@ -543,6 +594,12 @@ if (isEsmPackage && pkg.main && hasCjsExtension(pkg.main)) {

// Merge the main export into '.' paths
const mainExport = Object.assign({}, pathsMap['.'], defaultMainExport);
const mainExport = {
...pathsMap['.'],
...defaultMainExport
};
// main export is not empty
if (Object.keys(mainExport).length > 0) {
pathsMap['.'] = mainExport;
pathsMap['.'] = {
...pathsMap['.'],
...mainExport
};
}

@@ -755,3 +812,3 @@ return pathsMap;

if (useTypescript) {
const overrideResolvedTsOptions = {
const { options: overrideResolvedTsOptions } = await convertCompilerOptions(cwd, {
declaration: true,

@@ -764,18 +821,13 @@ noEmit: false,

skipLibCheck: true,
preserveSymlinks: false,
target: 'esnext',
module: 'esnext',
jsx: tsCompilerOptions.jsx || 'react-jsx'
};
const mergedOptions = {
...tsCompilerOptions,
...overrideResolvedTsOptions
};
// error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single
// file or when option '--tsBuildInfoFile' is specified.
delete mergedOptions.incremental;
delete mergedOptions.tsBuildInfoFile;
target: 'ESNext',
...!tsCompilerOptions.jsx ? {
jsx: 'react-jsx'
} : undefined,
// error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single
// file or when option '--tsBuildInfoFile' is specified.
incremental: false
});
const dtsPlugin = require('rollup-plugin-dts').default({
tsconfig: undefined,
compilerOptions: mergedOptions
tsconfig: tsConfigPath,
compilerOptions: overrideResolvedTsOptions
});

@@ -792,2 +844,3 @@ typesPlugins.push(dtsPlugin);

}),
esmShim__default.default(),
preserveDirectives__default.default(),

@@ -813,4 +866,3 @@ prependDirectives(),

...swcOptions
}),
esmShim__default.default()
})
]).filter(isNotNull);

@@ -1041,6 +1093,8 @@ return {

const exportCond = exportPaths[entryExport];
await collectEntry('', exportCond, entryExport);
for (const exportType of availableExportConventions){
if (exportCond[exportType]) {
await collectEntry(exportType, exportCond, entryExport);
if (entryExport.startsWith('.')) {
await collectEntry('', exportCond, entryExport);
for (const exportType of availableExportConventions){
if (exportCond[exportType]) {
await collectEntry(exportType, exportCond, entryExport);
}
}

@@ -1169,36 +1223,2 @@ }

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 {
return null;
}
return {
tsCompilerOptions,
tsConfigPath
};
}
// TODO: support nested wildcard exportsCondition (e.g. './foo/*')

@@ -1205,0 +1225,0 @@ const getWildcardExports = (exportsCondition)=>{

{
"name": "bunchee",
"version": "4.2.7",
"version": "4.2.8",
"description": "zero config bundler for js/ts/jsx libraries",

@@ -5,0 +5,0 @@ "bin": "./dist/bin/cli.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc