Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

no-bump

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

no-bump - npm Package Compare versions

Comparing version
0.6.2
to
0.7.0
+478
lib/api-587fccc0.js
import fsp from 'fs/promises';
import * as rollup from 'rollup';
import alias from '@rollup/plugin-alias';
import replace from '@rollup/plugin-replace';
import { swc } from 'rollup-plugin-swc3';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import merge from 'lodash.merge';
import path from 'path';
function len(tar) {
return tar.length;
}
function hasOwn(source, key) {
return Object.prototype.hasOwnProperty.call(source, key);
}
function isPlainObject(tar) {
return Object.prototype.toString.call(tar).slice(8, -1) === 'Object';
}
function loadModule(alias) {
try {
const raw = require(alias);
return raw.__esModule ? raw.default : raw;
} catch (err) {
return false;
} finally{
delete require.cache[require.resolve(alias)];
}
}
function _defineProperty$1(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread$1(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty$1(target, key, source[key]);
});
}
return target;
}
function _objectWithoutProperties$1(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose$1(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose$1(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 createPlugins(options) {
var _rest_internalOptions, _rest_resolve;
const { plugins: userPlugins = [] } = options, rest = _objectWithoutProperties$1(options, [
"plugins"
]);
const plugins = [];
const internalPlugins = {
replace: (config)=>{
var _rest_resolve;
return replace(merge(_objectSpread$1({
preventAssignment: true
}, (_rest_resolve = rest.resolve) === null || _rest_resolve === void 0 ? void 0 : _rest_resolve.define), config));
},
commonjs: (config)=>commonjs(merge({
esmExternals: true
}, config)),
nodeResolve: nodeResolve,
swc: (config)=>swc(merge({
sourceMaps: rest.sourceMap,
jsc: {
transform: {
react: rest.jsx
},
externalHelpers: rest.extractHelpers
},
minify: rest.minify
}, config))
};
var _rest_internalOptions_plugins;
const internalPluginsOptions = (_rest_internalOptions_plugins = (_rest_internalOptions = rest.internalOptions) === null || _rest_internalOptions === void 0 ? void 0 : _rest_internalOptions.plugins) !== null && _rest_internalOptions_plugins !== void 0 ? _rest_internalOptions_plugins : {};
Object.entries(internalPlugins).forEach(([name, plugin])=>{
if (hasOwn(internalPluginsOptions, name)) {
// @ts-ignored
const original = internalPluginsOptions[name];
if (original) {
const config = typeof original === 'boolean' ? {} : original;
plugins.push(plugin(config));
return;
}
return;
}
plugins.push(plugin({}));
});
// rollup internal logic will verfiy each plugin. So that we only merge user plugin is enough
plugins.push(...userPlugins);
const serializeAliasPattern = (pattern)=>{
if (!pattern) return [];
if (Array.isArray(pattern)) return pattern;
return Object.entries(pattern).map(([find, replacement])=>({
['find']: find,
['replacement']: replacement
}));
};
plugins.unshift(alias({
entries: serializeAliasPattern((_rest_resolve = rest.resolve) === null || _rest_resolve === void 0 ? void 0 : _rest_resolve.alias)
}));
return {
plugins
};
}
const print = {
log: (text)=>console.log('\x1b[37m%s \x1b[2m%s\x1b[0m', '>', text),
danger: (text)=>console.log('\x1b[31m%s \x1b[31m%s\x1b[0m', '>', text),
tip: (text)=>console.log('\x1b[36m%s \x1b[36m%s\x1b[0m', '>', text)
};
function error(base) {
if (!(base instanceof Error)) base = Object.assign(new Error(base.message), base);
return base;
}
function throwInvalidateError(err) {
if (typeof err === 'string') err = {
message: err
};
throw error(err);
}
function handleError(error) {
let declaration = error.message || error;
if (error.name) declaration = `${error.name}: ${declaration}`;
const message = error.plugin ? `(plugin ${error.plugin}) ${declaration}` : declaration || error;
print.tip(message);
if (error.url) print.log(error.url);
if (error.loc) print.danger(`${error.loc.file || error.id}:${error.loc.line}:${error.loc.column}`);
else if (error.id) print.danger(error.id);
if (error.frame) print.danger(error.frame);
if (error.stack) print.danger(error.stack);
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpreadProps(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose(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;
}
async function defaultExternal() {
const tar = path.join(process.cwd(), 'package.json');
const pkgJSON = await fsp.readFile(tar, 'utf8').catch(()=>'{}');
const { dependencies ={} , peerDependencies ={} } = JSON.parse(pkgJSON);
return Object.keys(_objectSpread({}, dependencies, peerDependencies));
}
async function parseOptions(userOptions) {
var _userOptions_output, _userOptions_output1, _userOptions_output2, _userOptions_output3, _userOptions_output4, _userOptions_output5, _userOptions_output6, _userOptions_output7, _userOptions_output8, _userOptions_output9, _userOptions_output10, _userOptions_output11, _userOptions_output12;
const external = await defaultExternal();
const ensureFormat = (userFormat)=>{
if (!userFormat || Array.isArray(userFormat) && !len(userFormat)) return [
'cjs',
'esm'
];
const formats = Array.isArray(userFormat) ? userFormat : [
userFormat
];
return formats.map((format)=>{
if (format === 'commonjs') return 'cjs';
if (format === 'es') return 'esm';
return format;
});
};
var _userOptions_external, _userOptions_output_dir;
const rollupOptions = {
external: (_userOptions_external = userOptions.external) !== null && _userOptions_external !== void 0 ? _userOptions_external : external,
output: {
dir: (_userOptions_output_dir = (_userOptions_output = userOptions.output) === null || _userOptions_output === void 0 ? void 0 : _userOptions_output.dir) !== null && _userOptions_output_dir !== void 0 ? _userOptions_output_dir : 'dist',
sourcemap: (_userOptions_output1 = userOptions.output) === null || _userOptions_output1 === void 0 ? void 0 : _userOptions_output1.sourceMap,
globals: userOptions.global,
name: (_userOptions_output2 = userOptions.output) === null || _userOptions_output2 === void 0 ? void 0 : _userOptions_output2.name,
preserveModules: (_userOptions_output3 = userOptions.output) === null || _userOptions_output3 === void 0 ? void 0 : _userOptions_output3.preserveModules,
preserveModulesRoot: (_userOptions_output4 = userOptions.output) === null || _userOptions_output4 === void 0 ? void 0 : _userOptions_output4.preserveModulesRoot,
exports: (_userOptions_output5 = userOptions.output) === null || _userOptions_output5 === void 0 ? void 0 : _userOptions_output5.exports
}
};
var _userOptions_input;
const internalOptions = {
minify: (_userOptions_output6 = userOptions.output) === null || _userOptions_output6 === void 0 ? void 0 : _userOptions_output6.minify,
extractHelpers: (_userOptions_output7 = userOptions.output) === null || _userOptions_output7 === void 0 ? void 0 : _userOptions_output7.extractHelpers,
dts: (_userOptions_output8 = userOptions.output) === null || _userOptions_output8 === void 0 ? void 0 : _userOptions_output8.dts,
jsx: (_userOptions_output9 = userOptions.output) === null || _userOptions_output9 === void 0 ? void 0 : _userOptions_output9.jsx,
format: ensureFormat((_userOptions_output10 = userOptions.output) === null || _userOptions_output10 === void 0 ? void 0 : _userOptions_output10.format),
clean: userOptions.clean,
input: (_userOptions_input = userOptions.input) !== null && _userOptions_input !== void 0 ? _userOptions_input : 'src/index.js',
plugins: userOptions.plugins,
internalOptions: userOptions.internalOptions,
sourceMap: (_userOptions_output11 = userOptions.output) === null || _userOptions_output11 === void 0 ? void 0 : _userOptions_output11.sourceMap,
resolve: userOptions.resolve,
file: (_userOptions_output12 = userOptions.output) === null || _userOptions_output12 === void 0 ? void 0 : _userOptions_output12.file
};
return {
rollupOptions,
internalOptions
};
}
async function buildImpl(userOptions = {}) {
if (userOptions) {
if (!isPlainObject(userOptions)) throwInvalidateError('[Bump]: please check your config. config should be an Object.');
}
const { internalOptions , rollupOptions } = await parseOptions(userOptions);
const { plugins } = createPlugins(internalOptions);
return runServer(rollupOptions, internalOptions, plugins, async ({ rollupConfig , dts , formats , tasks })=>{
try {
if (internalOptions.clean) {
var _rollupOptions_output;
if (!Array.isArray(rollupOptions.output) && ((_rollupOptions_output = rollupOptions.output) === null || _rollupOptions_output === void 0 ? void 0 : _rollupOptions_output.dir)) {
await fsp.rm(rollupOptions.output.dir, {
recursive: true,
force: true
});
}
}
const instances = [];
const results = [];
await Promise.all(tasks.map(async (task)=>{
const { plugins , external } = rollupConfig, rest = _objectWithoutProperties(rollupConfig, [
"plugins",
"external"
]);
const bundle = await rollup.rollup({
plugins,
external,
input: task
});
formats.forEach(async (format)=>{
const entryFileNames = replaceEntryFileNames(format, {
file: internalOptions.file,
minify: internalOptions.minify
});
const result = await bundle.write(_objectSpreadProps(_objectSpread({}, rest.output), {
format,
entryFileNames
}));
instances.push(bundle);
results.push(result);
});
if (dts) {
const dtsBundle = await rollup.rollup({
external,
input: task,
plugins: dts
});
const result = await dtsBundle.write(_objectSpreadProps(_objectSpread({}, rest.output), {
format: 'esm'
}));
instances.push(dtsBundle);
results.push(result);
}
}));
await Promise.all(instances.map((instance)=>instance.close()));
return results;
} catch (error) {
throw error;
}
});
}
async function watchImpl(userOptions = {}) {
if (userOptions) {
if (!isPlainObject(userOptions)) throwInvalidateError('[Bump]: please check your config. config should be an Object.');
}
const { internalOptions , rollupOptions } = await parseOptions(userOptions);
const { plugins } = createPlugins(internalOptions);
return runServer(rollupOptions, internalOptions, plugins, async ({ rollupConfig , dts , formats , tasks })=>{
const { external , plugins } = rollupConfig, rest = _objectWithoutProperties(rollupConfig, [
"external",
"plugins"
]);
const watcherOptions = tasks.flatMap((task)=>{
return formats.map((format)=>{
const entryFileNames = replaceEntryFileNames(format, {
file: internalOptions.file,
minify: internalOptions.minify
});
return {
plugins,
external,
input: task,
output: _objectSpreadProps(_objectSpread({}, rest.output), {
entryFileNames,
format
}),
watch: {}
};
});
});
if (dts) {
tasks.forEach((task)=>{
watcherOptions.push({
external,
input: task,
plugins: dts,
output: _objectSpreadProps(_objectSpread({}, rest.output), {
format: 'esm'
}),
watch: {}
});
});
}
const watcher = rollup.watch(watcherOptions);
watcher.on('event', (evt)=>{
if (evt.code === 'ERROR') {
print.danger(evt.error.message);
}
});
return watcher;
});
}
async function runServer(rollupOptions, internalOptions, plugins, handler) {
const { input , format: formats } = internalOptions;
const tasks = [];
if (Array.isArray(input)) tasks.push(...input);
if (typeof input === 'string') tasks.push(input);
if (!Array.isArray(input) && typeof input === 'object') {
const entry = Object.values(input);
if (!len(entry)) tasks.push('src/index.js');
tasks.push(...entry);
}
const internalRollupConfig = _objectSpreadProps(_objectSpread({}, rollupOptions), {
plugins
});
const dts = (()=>{
if (!(internalOptions === null || internalOptions === void 0 ? void 0 : internalOptions.dts)) return null;
const load = loadModule('rollup-plugin-dts');
if (!load) {
print.tip('[Bump]: please install rollup-plugin-dts.');
return null;
}
return [
load({
compilerOptions: {
preserveSymlinks: false
}
})
];
})();
return handler({
rollupConfig: internalRollupConfig,
tasks,
formats,
dts
});
}
function replaceEntryFileNames(format, { file , minify }) {
const rule = '[name][min][ext]';
const fileName = file || rule;
const tpl = typeof fileName === 'function' ? fileName({
format,
minify: Boolean(minify)
}, rule) : fileName;
return tpl.replace(/\[min\]/, minify ? '.min' : '').replace(/\[ext\]/, format === 'cjs' ? '.js' : '.mjs');
}
/**
*@description dine bump config.
*/ function define(options) {
return options;
}
function build(options) {
return buildImpl(options);
}
function watch(options) {
return watchImpl(options);
}
export { build as b, define as d, handleError as h, len as l, print as p, throwInvalidateError as t, watch as w };
'use strict';
var fsp = require('fs/promises');
var rollup = require('rollup');
var alias = require('@rollup/plugin-alias');
var replace = require('@rollup/plugin-replace');
var rollupPluginSwc3 = require('rollup-plugin-swc3');
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
var commonjs = require('@rollup/plugin-commonjs');
var merge = require('lodash.merge');
var path = require('path');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var rollup__namespace = /*#__PURE__*/_interopNamespaceDefault(rollup);
function len(tar) {
return tar.length;
}
function hasOwn(source, key) {
return Object.prototype.hasOwnProperty.call(source, key);
}
function isPlainObject(tar) {
return Object.prototype.toString.call(tar).slice(8, -1) === 'Object';
}
function loadModule(alias) {
try {
const raw = require(alias);
return raw.__esModule ? raw.default : raw;
} catch (err) {
return false;
} finally{
delete require.cache[require.resolve(alias)];
}
}
function _defineProperty$1(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread$1(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty$1(target, key, source[key]);
});
}
return target;
}
function _objectWithoutProperties$1(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose$1(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose$1(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 createPlugins(options) {
var _rest_internalOptions, _rest_resolve;
const { plugins: userPlugins = [] } = options, rest = _objectWithoutProperties$1(options, [
"plugins"
]);
const plugins = [];
const internalPlugins = {
replace: (config)=>{
var _rest_resolve;
return replace(merge(_objectSpread$1({
preventAssignment: true
}, (_rest_resolve = rest.resolve) === null || _rest_resolve === void 0 ? void 0 : _rest_resolve.define), config));
},
commonjs: (config)=>commonjs(merge({
esmExternals: true
}, config)),
nodeResolve: pluginNodeResolve.nodeResolve,
swc: (config)=>rollupPluginSwc3.swc(merge({
sourceMaps: rest.sourceMap,
jsc: {
transform: {
react: rest.jsx
},
externalHelpers: rest.extractHelpers
},
minify: rest.minify
}, config))
};
var _rest_internalOptions_plugins;
const internalPluginsOptions = (_rest_internalOptions_plugins = (_rest_internalOptions = rest.internalOptions) === null || _rest_internalOptions === void 0 ? void 0 : _rest_internalOptions.plugins) !== null && _rest_internalOptions_plugins !== void 0 ? _rest_internalOptions_plugins : {};
Object.entries(internalPlugins).forEach(([name, plugin])=>{
if (hasOwn(internalPluginsOptions, name)) {
// @ts-ignored
const original = internalPluginsOptions[name];
if (original) {
const config = typeof original === 'boolean' ? {} : original;
plugins.push(plugin(config));
return;
}
return;
}
plugins.push(plugin({}));
});
// rollup internal logic will verfiy each plugin. So that we only merge user plugin is enough
plugins.push(...userPlugins);
const serializeAliasPattern = (pattern)=>{
if (!pattern) return [];
if (Array.isArray(pattern)) return pattern;
return Object.entries(pattern).map(([find, replacement])=>({
['find']: find,
['replacement']: replacement
}));
};
plugins.unshift(alias({
entries: serializeAliasPattern((_rest_resolve = rest.resolve) === null || _rest_resolve === void 0 ? void 0 : _rest_resolve.alias)
}));
return {
plugins
};
}
const print = {
log: (text)=>console.log('\x1b[37m%s \x1b[2m%s\x1b[0m', '>', text),
danger: (text)=>console.log('\x1b[31m%s \x1b[31m%s\x1b[0m', '>', text),
tip: (text)=>console.log('\x1b[36m%s \x1b[36m%s\x1b[0m', '>', text)
};
function error(base) {
if (!(base instanceof Error)) base = Object.assign(new Error(base.message), base);
return base;
}
function throwInvalidateError(err) {
if (typeof err === 'string') err = {
message: err
};
throw error(err);
}
function handleError(error) {
let declaration = error.message || error;
if (error.name) declaration = `${error.name}: ${declaration}`;
const message = error.plugin ? `(plugin ${error.plugin}) ${declaration}` : declaration || error;
print.tip(message);
if (error.url) print.log(error.url);
if (error.loc) print.danger(`${error.loc.file || error.id}:${error.loc.line}:${error.loc.column}`);
else if (error.id) print.danger(error.id);
if (error.frame) print.danger(error.frame);
if (error.stack) print.danger(error.stack);
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpreadProps(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose(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;
}
async function defaultExternal() {
const tar = path.join(process.cwd(), 'package.json');
const pkgJSON = await fsp.readFile(tar, 'utf8').catch(()=>'{}');
const { dependencies ={} , peerDependencies ={} } = JSON.parse(pkgJSON);
return Object.keys(_objectSpread({}, dependencies, peerDependencies));
}
async function parseOptions(userOptions) {
var _userOptions_output, _userOptions_output1, _userOptions_output2, _userOptions_output3, _userOptions_output4, _userOptions_output5, _userOptions_output6, _userOptions_output7, _userOptions_output8, _userOptions_output9, _userOptions_output10, _userOptions_output11, _userOptions_output12;
const external = await defaultExternal();
const ensureFormat = (userFormat)=>{
if (!userFormat || Array.isArray(userFormat) && !len(userFormat)) return [
'cjs',
'esm'
];
const formats = Array.isArray(userFormat) ? userFormat : [
userFormat
];
return formats.map((format)=>{
if (format === 'commonjs') return 'cjs';
if (format === 'es') return 'esm';
return format;
});
};
var _userOptions_external, _userOptions_output_dir;
const rollupOptions = {
external: (_userOptions_external = userOptions.external) !== null && _userOptions_external !== void 0 ? _userOptions_external : external,
output: {
dir: (_userOptions_output_dir = (_userOptions_output = userOptions.output) === null || _userOptions_output === void 0 ? void 0 : _userOptions_output.dir) !== null && _userOptions_output_dir !== void 0 ? _userOptions_output_dir : 'dist',
sourcemap: (_userOptions_output1 = userOptions.output) === null || _userOptions_output1 === void 0 ? void 0 : _userOptions_output1.sourceMap,
globals: userOptions.global,
name: (_userOptions_output2 = userOptions.output) === null || _userOptions_output2 === void 0 ? void 0 : _userOptions_output2.name,
preserveModules: (_userOptions_output3 = userOptions.output) === null || _userOptions_output3 === void 0 ? void 0 : _userOptions_output3.preserveModules,
preserveModulesRoot: (_userOptions_output4 = userOptions.output) === null || _userOptions_output4 === void 0 ? void 0 : _userOptions_output4.preserveModulesRoot,
exports: (_userOptions_output5 = userOptions.output) === null || _userOptions_output5 === void 0 ? void 0 : _userOptions_output5.exports
}
};
var _userOptions_input;
const internalOptions = {
minify: (_userOptions_output6 = userOptions.output) === null || _userOptions_output6 === void 0 ? void 0 : _userOptions_output6.minify,
extractHelpers: (_userOptions_output7 = userOptions.output) === null || _userOptions_output7 === void 0 ? void 0 : _userOptions_output7.extractHelpers,
dts: (_userOptions_output8 = userOptions.output) === null || _userOptions_output8 === void 0 ? void 0 : _userOptions_output8.dts,
jsx: (_userOptions_output9 = userOptions.output) === null || _userOptions_output9 === void 0 ? void 0 : _userOptions_output9.jsx,
format: ensureFormat((_userOptions_output10 = userOptions.output) === null || _userOptions_output10 === void 0 ? void 0 : _userOptions_output10.format),
clean: userOptions.clean,
input: (_userOptions_input = userOptions.input) !== null && _userOptions_input !== void 0 ? _userOptions_input : 'src/index.js',
plugins: userOptions.plugins,
internalOptions: userOptions.internalOptions,
sourceMap: (_userOptions_output11 = userOptions.output) === null || _userOptions_output11 === void 0 ? void 0 : _userOptions_output11.sourceMap,
resolve: userOptions.resolve,
file: (_userOptions_output12 = userOptions.output) === null || _userOptions_output12 === void 0 ? void 0 : _userOptions_output12.file
};
return {
rollupOptions,
internalOptions
};
}
async function buildImpl(userOptions = {}) {
if (userOptions) {
if (!isPlainObject(userOptions)) throwInvalidateError('[Bump]: please check your config. config should be an Object.');
}
const { internalOptions , rollupOptions } = await parseOptions(userOptions);
const { plugins } = createPlugins(internalOptions);
return runServer(rollupOptions, internalOptions, plugins, async ({ rollupConfig , dts , formats , tasks })=>{
try {
if (internalOptions.clean) {
var _rollupOptions_output;
if (!Array.isArray(rollupOptions.output) && ((_rollupOptions_output = rollupOptions.output) === null || _rollupOptions_output === void 0 ? void 0 : _rollupOptions_output.dir)) {
await fsp.rm(rollupOptions.output.dir, {
recursive: true,
force: true
});
}
}
const instances = [];
const results = [];
await Promise.all(tasks.map(async (task)=>{
const { plugins , external } = rollupConfig, rest = _objectWithoutProperties(rollupConfig, [
"plugins",
"external"
]);
const bundle = await rollup__namespace.rollup({
plugins,
external,
input: task
});
formats.forEach(async (format)=>{
const entryFileNames = replaceEntryFileNames(format, {
file: internalOptions.file,
minify: internalOptions.minify
});
const result = await bundle.write(_objectSpreadProps(_objectSpread({}, rest.output), {
format,
entryFileNames
}));
instances.push(bundle);
results.push(result);
});
if (dts) {
const dtsBundle = await rollup__namespace.rollup({
external,
input: task,
plugins: dts
});
const result = await dtsBundle.write(_objectSpreadProps(_objectSpread({}, rest.output), {
format: 'esm'
}));
instances.push(dtsBundle);
results.push(result);
}
}));
await Promise.all(instances.map((instance)=>instance.close()));
return results;
} catch (error) {
throw error;
}
});
}
async function watchImpl(userOptions = {}) {
if (userOptions) {
if (!isPlainObject(userOptions)) throwInvalidateError('[Bump]: please check your config. config should be an Object.');
}
const { internalOptions , rollupOptions } = await parseOptions(userOptions);
const { plugins } = createPlugins(internalOptions);
return runServer(rollupOptions, internalOptions, plugins, async ({ rollupConfig , dts , formats , tasks })=>{
const { external , plugins } = rollupConfig, rest = _objectWithoutProperties(rollupConfig, [
"external",
"plugins"
]);
const watcherOptions = tasks.flatMap((task)=>{
return formats.map((format)=>{
const entryFileNames = replaceEntryFileNames(format, {
file: internalOptions.file,
minify: internalOptions.minify
});
return {
plugins,
external,
input: task,
output: _objectSpreadProps(_objectSpread({}, rest.output), {
entryFileNames,
format
}),
watch: {}
};
});
});
if (dts) {
tasks.forEach((task)=>{
watcherOptions.push({
external,
input: task,
plugins: dts,
output: _objectSpreadProps(_objectSpread({}, rest.output), {
format: 'esm'
}),
watch: {}
});
});
}
const watcher = rollup__namespace.watch(watcherOptions);
watcher.on('event', (evt)=>{
if (evt.code === 'ERROR') {
print.danger(evt.error.message);
}
});
return watcher;
});
}
async function runServer(rollupOptions, internalOptions, plugins, handler) {
const { input , format: formats } = internalOptions;
const tasks = [];
if (Array.isArray(input)) tasks.push(...input);
if (typeof input === 'string') tasks.push(input);
if (!Array.isArray(input) && typeof input === 'object') {
const entry = Object.values(input);
if (!len(entry)) tasks.push('src/index.js');
tasks.push(...entry);
}
const internalRollupConfig = _objectSpreadProps(_objectSpread({}, rollupOptions), {
plugins
});
const dts = (()=>{
if (!(internalOptions === null || internalOptions === void 0 ? void 0 : internalOptions.dts)) return null;
const load = loadModule('rollup-plugin-dts');
if (!load) {
print.tip('[Bump]: please install rollup-plugin-dts.');
return null;
}
return [
load({
compilerOptions: {
preserveSymlinks: false
}
})
];
})();
return handler({
rollupConfig: internalRollupConfig,
tasks,
formats,
dts
});
}
function replaceEntryFileNames(format, { file , minify }) {
const rule = '[name][min][ext]';
const fileName = file || rule;
const tpl = typeof fileName === 'function' ? fileName({
format,
minify: Boolean(minify)
}, rule) : fileName;
return tpl.replace(/\[min\]/, minify ? '.min' : '').replace(/\[ext\]/, format === 'cjs' ? '.js' : '.mjs');
}
/**
*@description dine bump config.
*/ function define(options) {
return options;
}
function build(options) {
return buildImpl(options);
}
function watch(options) {
return watchImpl(options);
}
exports.build = build;
exports.define = define;
exports.handleError = handleError;
exports.len = len;
exports.print = print;
exports.throwInvalidateError = throwInvalidateError;
exports.watch = watch;
'use strict';
var yargsParser = require('yargs-parser');
var api = require('./api-ec579d41.js');
var path = require('path');
var fs = require('fs');
var core = require('@swc/core');
require('fs/promises');
require('rollup');
require('@rollup/plugin-alias');
require('@rollup/plugin-replace');
require('rollup-plugin-swc3');
require('@rollup/plugin-node-resolve');
require('@rollup/plugin-commonjs');
require('lodash.merge');
var version = "0.7.0";
function _objectWithoutProperties$1(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose$1(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose$1(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;
}
const configFiles = [
'bump.config.js',
'bump.config.ts'
];
const commandFlags = {
help: {
command: [
'-h',
'--help'
],
description: ''
},
watch: {
command: [
'-w',
'--watch'
],
description: 'Watch files in bundle and rebuild on changes'
},
dir: {
command: [
'-d',
'--dir'
],
description: 'Directory for chunks(if absent, will be dist)'
},
input: {
command: [
'-i',
'--input'
],
description: 'Input (alternative to <entry file>, default is src/index.js)'
},
version: {
command: [
'-v',
'--version'
],
description: 'Show version number'
},
format: {
command: [
'-f',
'--format'
],
description: 'Type of output (amd, cjs, es, iife, umd, system)'
}
};
function generatorHelperText() {
const rest = _objectWithoutProperties$1(commandFlags, [
"help"
]);
return `
Runing version ${version}.
Usage: bump [options]
Options:
${Object.values(rest).reduce((acc, { command , description })=>acc += `${command} ${description}.\n`, '')}
`;
}
async function resolveConfig() {
try {
let count = api.len(configFiles);
let file = '';
while(count){
const name = configFiles[count - 1];
const p = path.resolve(process.cwd(), name);
if (fs.existsSync(p)) {
file = p;
break;
}
count--;
}
if (!file) return {};
let code = await fs.promises.readFile(file, 'utf-8');
({ code } = await core.transform(code, {
filename: file,
isModule: 'unknown',
sourceMaps: false,
module: {
type: 'commonjs'
}
}));
return loadConfigFromBundledFile(file, code);
} catch (err) {
throw api.throwInvalidateError(err);
}
}
async function getConfig(command) {
const config = await resolveConfig();
if (api.len(Object.keys(command))) {
if (!config.output) config.output = {};
if (command.watch) config.watch = true;
if (command.format) config.output.format = command.format;
if (command.dir) config.output.dir = command.dir;
if (command.input) config.input = command.input;
}
return config;
}
async function runCliImpl(command) {
try {
const config = await getConfig(command);
if (config.watch) {
await api.watch(config);
return;
}
await api.build(config);
} catch (error) {
api.handleError(error);
}
}
const loadConfigFromBundledFile = async (fileName, bundledCode)=>{
const extension = path.extname(fileName);
const defaultLoader = require.extensions[extension];
require.extensions[extension] = (module, filename)=>{
if (filename === fileName) {
module._compile(bundledCode, filename);
} else {
defaultLoader(module, filename);
}
};
delete require.cache[require.resolve(fileName)];
const raw = require(fileName);
const config = raw.__esModule ? raw.default : raw;
require.extensions[extension] = defaultLoader;
return config;
};
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose(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 main() {
const argvs = yargsParser(process.argv.slice(2), {
alias: Object.entries(commandFlags).reduce((acc, [_, { command }])=>{
const [s, n] = command;
return Object.assign(acc, {
[s.replace('-', '')]: n.replace('--', '')
});
}, {}),
array: [
'input',
'format'
],
configuration: {
'greedy-arrays': true
}
});
if (argvs.help && process.stdin.isTTY) return api.print.log(generatorHelperText());
if (argvs.version) return api.print.log(`Running version: ${version}`);
const command = _objectWithoutProperties(argvs, [
"_"
]);
runCliImpl(command);
}
main();
import yargsParser from 'yargs-parser';
import { w as watch, b as build, h as handleError, l as len, t as throwInvalidateError, p as print } from './api-587fccc0.js';
import path from 'path';
import fs from 'fs';
import { transform } from '@swc/core';
import 'fs/promises';
import 'rollup';
import '@rollup/plugin-alias';
import '@rollup/plugin-replace';
import 'rollup-plugin-swc3';
import '@rollup/plugin-node-resolve';
import '@rollup/plugin-commonjs';
import 'lodash.merge';
var version = "0.7.0";
function _objectWithoutProperties$1(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose$1(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose$1(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;
}
const configFiles = [
'bump.config.js',
'bump.config.ts'
];
const commandFlags = {
help: {
command: [
'-h',
'--help'
],
description: ''
},
watch: {
command: [
'-w',
'--watch'
],
description: 'Watch files in bundle and rebuild on changes'
},
dir: {
command: [
'-d',
'--dir'
],
description: 'Directory for chunks(if absent, will be dist)'
},
input: {
command: [
'-i',
'--input'
],
description: 'Input (alternative to <entry file>, default is src/index.js)'
},
version: {
command: [
'-v',
'--version'
],
description: 'Show version number'
},
format: {
command: [
'-f',
'--format'
],
description: 'Type of output (amd, cjs, es, iife, umd, system)'
}
};
function generatorHelperText() {
const rest = _objectWithoutProperties$1(commandFlags, [
"help"
]);
return `
Runing version ${version}.
Usage: bump [options]
Options:
${Object.values(rest).reduce((acc, { command , description })=>acc += `${command} ${description}.\n`, '')}
`;
}
async function resolveConfig() {
try {
let count = len(configFiles);
let file = '';
while(count){
const name = configFiles[count - 1];
const p = path.resolve(process.cwd(), name);
if (fs.existsSync(p)) {
file = p;
break;
}
count--;
}
if (!file) return {};
let code = await fs.promises.readFile(file, 'utf-8');
({ code } = await transform(code, {
filename: file,
isModule: 'unknown',
sourceMaps: false,
module: {
type: 'commonjs'
}
}));
return loadConfigFromBundledFile(file, code);
} catch (err) {
throw throwInvalidateError(err);
}
}
async function getConfig(command) {
const config = await resolveConfig();
if (len(Object.keys(command))) {
if (!config.output) config.output = {};
if (command.watch) config.watch = true;
if (command.format) config.output.format = command.format;
if (command.dir) config.output.dir = command.dir;
if (command.input) config.input = command.input;
}
return config;
}
async function runCliImpl(command) {
try {
const config = await getConfig(command);
if (config.watch) {
await watch(config);
return;
}
await build(config);
} catch (error) {
handleError(error);
}
}
const loadConfigFromBundledFile = async (fileName, bundledCode)=>{
const extension = path.extname(fileName);
const defaultLoader = require.extensions[extension];
require.extensions[extension] = (module, filename)=>{
if (filename === fileName) {
module._compile(bundledCode, filename);
} else {
defaultLoader(module, filename);
}
};
delete require.cache[require.resolve(fileName)];
const raw = require(fileName);
const config = raw.__esModule ? raw.default : raw;
require.extensions[extension] = defaultLoader;
return config;
};
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose(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 main() {
const argvs = yargsParser(process.argv.slice(2), {
alias: Object.entries(commandFlags).reduce((acc, [_, { command }])=>{
const [s, n] = command;
return Object.assign(acc, {
[s.replace('-', '')]: n.replace('--', '')
});
}, {}),
array: [
'input',
'format'
],
configuration: {
'greedy-arrays': true
}
});
if (argvs.help && process.stdin.isTTY) return print.log(generatorHelperText());
if (argvs.version) return print.log(`Running version: ${version}`);
const command = _objectWithoutProperties(argvs, [
"_"
]);
runCliImpl(command);
}
main();
'use strict';
var api = require('./api-ec579d41.js');
require('fs/promises');
require('rollup');
require('@rollup/plugin-alias');
require('@rollup/plugin-replace');
require('rollup-plugin-swc3');
require('@rollup/plugin-node-resolve');
require('@rollup/plugin-commonjs');
require('lodash.merge');
require('path');
exports.build = api.build;
exports.define = api.define;
exports.watch = api.watch;
export { b as build, d as define, w as watch } from './api-587fccc0.js';
import 'fs/promises';
import 'rollup';
import '@rollup/plugin-alias';
import '@rollup/plugin-replace';
import 'rollup-plugin-swc3';
import '@rollup/plugin-node-resolve';
import '@rollup/plugin-commonjs';
import 'lodash.merge';
import 'path';
+1
-2

@@ -1,3 +0,2 @@

declare const _default: Promise<void>;
export { _default as default };
export { }

@@ -123,6 +123,6 @@ import * as rollup from 'rollup';

*/
declare const define: (options?: BumpOptions) => BumpOptions | undefined;
declare const build: (options?: BumpOptions) => Promise<rollup.RollupOutput[]>;
declare const watch: (options?: BumpOptions) => Promise<rollup.RollupWatcher>;
declare function define(options?: BumpOptions): BumpOptions | undefined;
declare function build(options?: BumpOptions): Promise<rollup.RollupOutput[]>;
declare function watch(options?: BumpOptions): Promise<rollup.RollupWatcher>;
export { BumpOptions, BumpOutputOptions, build, define, watch };
{
"name": "no-bump",
"version": "0.6.2",
"version": "0.7.0",
"description": "A zero config bundler.",
"main": "lib/index.cjs.js",
"module": "lib/index.esm.js",
"main": "lib/index.js",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",

@@ -28,4 +28,6 @@ "scripts": {

"devDependencies": {
"@rollup/plugin-json": "^6.0.0",
"@types/lodash.merge": "^4.6.7",
"@types/node": "^17.0.40",
"@types/yargs-parser": "^21.0.0",
"ava": "^4.3.1",

@@ -48,3 +50,4 @@ "c8": "^7.12.0",

"rollup": "^3.5.0",
"rollup-plugin-swc3": "^0.7.0"
"rollup-plugin-swc3": "^0.7.0",
"yargs-parser": "21.1.1"
},

@@ -51,0 +54,0 @@ "ava": {

'use strict';
var fsp = require('fs/promises');
var rollup = require('rollup');
var alias = require('@rollup/plugin-alias');
var replace = require('@rollup/plugin-replace');
var rollupPluginSwc3 = require('rollup-plugin-swc3');
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
var commonjs = require('@rollup/plugin-commonjs');
var merge = require('lodash.merge');
var path = require('path');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var rollup__namespace = /*#__PURE__*/_interopNamespaceDefault(rollup);
const len = (tar)=>tar.length;
const hasOwn = (source, key)=>Object.prototype.hasOwnProperty.call(source, key);
const isPlainObject = (tar)=>Object.prototype.toString.call(tar).slice(8, -1) === 'Object';
const loadModule = (alias)=>{
try {
const raw = require(alias);
return raw.__esModule ? raw.default : raw;
} catch (err) {
return false;
} finally{
delete require.cache[require.resolve(alias)];
}
};
function _defineProperty$1(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread$1(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty$1(target, key, source[key]);
});
}
return target;
}
function _objectWithoutProperties$1(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose$1(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose$1(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;
}
const createPlugins = (options)=>{
var _rest_internalOptions, _rest_resolve;
const { plugins: userPlugins = [] } = options, rest = _objectWithoutProperties$1(options, [
"plugins"
]);
const plugins = [];
const internalPlugins = {
replace: (config)=>{
var _rest_resolve;
return replace(merge(_objectSpread$1({
preventAssignment: true
}, (_rest_resolve = rest.resolve) === null || _rest_resolve === void 0 ? void 0 : _rest_resolve.define), config));
},
commonjs: (config)=>commonjs(merge({
esmExternals: true
}, config)),
nodeResolve: pluginNodeResolve.nodeResolve,
swc: (config)=>rollupPluginSwc3.swc(merge({
sourceMaps: rest.sourceMap,
jsc: {
transform: {
react: rest.jsx
},
externalHelpers: rest.extractHelpers
},
minify: rest.minify
}, config))
};
var _rest_internalOptions_plugins;
const internalPluginsOptions = (_rest_internalOptions_plugins = (_rest_internalOptions = rest.internalOptions) === null || _rest_internalOptions === void 0 ? void 0 : _rest_internalOptions.plugins) !== null && _rest_internalOptions_plugins !== void 0 ? _rest_internalOptions_plugins : {};
Object.entries(internalPlugins).forEach(([name, plugin])=>{
if (hasOwn(internalPluginsOptions, name)) {
// @ts-ignored
const original = internalPluginsOptions[name];
if (original) {
const config = typeof original === 'boolean' ? {} : original;
plugins.push(plugin(config));
return;
}
return;
}
plugins.push(plugin({}));
});
// rollup internal logic will verfiy each plugin. So that we only merge user plugin is enough
plugins.push(...userPlugins);
const serializeAliasPattern = (pattern)=>{
if (!pattern) return [];
if (Array.isArray(pattern)) return pattern;
return Object.entries(pattern).map(([find, replacement])=>({
['find']: find,
['replacement']: replacement
}));
};
plugins.unshift(alias({
entries: serializeAliasPattern((_rest_resolve = rest.resolve) === null || _rest_resolve === void 0 ? void 0 : _rest_resolve.alias)
}));
return {
plugins
};
};
const print = {
log: (text)=>console.log('\x1b[37m%s \x1b[2m%s\x1b[0m', '>', text),
danger: (text)=>console.log('\x1b[31m%s \x1b[31m%s\x1b[0m', '>', text),
tip: (text)=>console.log('\x1b[36m%s \x1b[36m%s\x1b[0m', '>', text)
};
const error = (base)=>{
if (!(base instanceof Error)) base = Object.assign(new Error(base.message), base);
return base;
};
const throwInvalidateError = (err)=>{
if (typeof err === 'string') err = {
message: err
};
throw error(err);
};
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpreadProps(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose(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;
}
const defaultExternal = async ()=>{
const tar = path.join(process.cwd(), 'package.json');
const pkgJSON = await fsp.readFile(tar, 'utf8').catch(()=>'{}');
const { dependencies ={} , peerDependencies ={} } = JSON.parse(pkgJSON);
return Object.keys(_objectSpread({}, dependencies, peerDependencies));
};
const parseOptions = async (userOptions)=>{
var _userOptions_output, _userOptions_output1, _userOptions_output2, _userOptions_output3, _userOptions_output4, _userOptions_output5, _userOptions_output6, _userOptions_output7, _userOptions_output8, _userOptions_output9, _userOptions_output10, _userOptions_output11, _userOptions_output12;
const external = await defaultExternal();
const ensureFormat = (userFormat)=>{
if (!userFormat || Array.isArray(userFormat) && !len(userFormat)) return [
'cjs',
'esm'
];
const formats = Array.isArray(userFormat) ? userFormat : [
userFormat
];
return formats.map((format)=>{
if (format === 'commonjs') return 'cjs';
if (format === 'es') return 'esm';
return format;
});
};
var _userOptions_external, _userOptions_output_dir;
const rollupOptions = {
external: (_userOptions_external = userOptions.external) !== null && _userOptions_external !== void 0 ? _userOptions_external : external,
output: {
dir: (_userOptions_output_dir = (_userOptions_output = userOptions.output) === null || _userOptions_output === void 0 ? void 0 : _userOptions_output.dir) !== null && _userOptions_output_dir !== void 0 ? _userOptions_output_dir : 'dist',
sourcemap: (_userOptions_output1 = userOptions.output) === null || _userOptions_output1 === void 0 ? void 0 : _userOptions_output1.sourceMap,
globals: userOptions.global,
name: (_userOptions_output2 = userOptions.output) === null || _userOptions_output2 === void 0 ? void 0 : _userOptions_output2.name,
preserveModules: (_userOptions_output3 = userOptions.output) === null || _userOptions_output3 === void 0 ? void 0 : _userOptions_output3.preserveModules,
preserveModulesRoot: (_userOptions_output4 = userOptions.output) === null || _userOptions_output4 === void 0 ? void 0 : _userOptions_output4.preserveModulesRoot,
exports: (_userOptions_output5 = userOptions.output) === null || _userOptions_output5 === void 0 ? void 0 : _userOptions_output5.exports
}
};
var _userOptions_input;
const internalOptions = {
minify: (_userOptions_output6 = userOptions.output) === null || _userOptions_output6 === void 0 ? void 0 : _userOptions_output6.minify,
extractHelpers: (_userOptions_output7 = userOptions.output) === null || _userOptions_output7 === void 0 ? void 0 : _userOptions_output7.extractHelpers,
dts: (_userOptions_output8 = userOptions.output) === null || _userOptions_output8 === void 0 ? void 0 : _userOptions_output8.dts,
jsx: (_userOptions_output9 = userOptions.output) === null || _userOptions_output9 === void 0 ? void 0 : _userOptions_output9.jsx,
format: ensureFormat((_userOptions_output10 = userOptions.output) === null || _userOptions_output10 === void 0 ? void 0 : _userOptions_output10.format),
clean: userOptions.clean,
input: (_userOptions_input = userOptions.input) !== null && _userOptions_input !== void 0 ? _userOptions_input : 'src/index.js',
plugins: userOptions.plugins,
internalOptions: userOptions.internalOptions,
sourceMap: (_userOptions_output11 = userOptions.output) === null || _userOptions_output11 === void 0 ? void 0 : _userOptions_output11.sourceMap,
resolve: userOptions.resolve,
file: (_userOptions_output12 = userOptions.output) === null || _userOptions_output12 === void 0 ? void 0 : _userOptions_output12.file
};
return {
rollupOptions,
internalOptions
};
};
const buildImpl = async (userOptions = {})=>{
if (userOptions) {
if (!isPlainObject(userOptions)) throwInvalidateError('[Bump]: please check your config. config should be an Object.');
}
const { internalOptions , rollupOptions } = await parseOptions(userOptions);
const { plugins } = createPlugins(internalOptions);
return runServer(rollupOptions, internalOptions, plugins, async ({ rollupConfig , dts , formats , tasks })=>{
try {
if (internalOptions.clean) {
var _rollupOptions_output;
if (!Array.isArray(rollupOptions.output) && ((_rollupOptions_output = rollupOptions.output) === null || _rollupOptions_output === void 0 ? void 0 : _rollupOptions_output.dir)) {
await fsp.rm(rollupOptions.output.dir, {
recursive: true,
force: true
});
}
}
const instances = [];
const results = [];
await Promise.all(tasks.map(async (task)=>{
const { plugins , external } = rollupConfig, rest = _objectWithoutProperties(rollupConfig, [
"plugins",
"external"
]);
const bundle = await rollup__namespace.rollup({
plugins,
external,
input: task
});
formats.forEach(async (format)=>{
const entryFileNames = replaceEntryFileNames(format, {
file: internalOptions.file,
minify: internalOptions.minify
});
const result = await bundle.write(_objectSpreadProps(_objectSpread({}, rest.output), {
format,
entryFileNames
}));
instances.push(bundle);
results.push(result);
});
if (dts) {
const dtsBundle = await rollup__namespace.rollup({
external,
input: task,
plugins: dts
});
const result = await dtsBundle.write(_objectSpreadProps(_objectSpread({}, rest.output), {
format: 'esm'
}));
instances.push(dtsBundle);
results.push(result);
}
}));
await Promise.all(instances.map((instance)=>instance.close()));
return results;
} catch (error) {
throw error;
}
});
};
const watchImpl = async (userOptions = {})=>{
if (userOptions) {
if (!isPlainObject(userOptions)) throwInvalidateError('[Bump]: please check your config. config should be an Object.');
}
const { internalOptions , rollupOptions } = await parseOptions(userOptions);
const { plugins } = createPlugins(internalOptions);
return runServer(rollupOptions, internalOptions, plugins, async ({ rollupConfig , dts , formats , tasks })=>{
const { external , plugins } = rollupConfig, rest = _objectWithoutProperties(rollupConfig, [
"external",
"plugins"
]);
const watcherOptions = tasks.flatMap((task)=>{
return formats.map((format)=>{
const entryFileNames = replaceEntryFileNames(format, {
file: internalOptions.file,
minify: internalOptions.minify
});
return {
plugins,
external,
input: task,
output: _objectSpreadProps(_objectSpread({}, rest.output), {
entryFileNames,
format
}),
watch: {}
};
});
});
if (dts) {
tasks.forEach((task)=>{
watcherOptions.push({
external,
input: task,
plugins: dts,
output: _objectSpreadProps(_objectSpread({}, rest.output), {
format: 'esm'
}),
watch: {}
});
});
}
const watcher = rollup__namespace.watch(watcherOptions);
watcher.on('event', (evt)=>{
if (evt.code === 'ERROR') {
print.danger(evt.error.message);
}
});
return watcher;
});
};
const runServer = async (rollupOptions, internalOptions, plugins, handler)=>{
const { input , format: formats } = internalOptions;
const tasks = [];
if (Array.isArray(input)) tasks.push(...input);
if (typeof input === 'string') tasks.push(input);
if (!Array.isArray(input) && typeof input === 'object') {
const entry = Object.values(input);
if (!len(entry)) tasks.push('src/index.js');
tasks.push(...entry);
}
const internalRollupConfig = _objectSpreadProps(_objectSpread({}, rollupOptions), {
plugins
});
const dts = (()=>{
if (!(internalOptions === null || internalOptions === void 0 ? void 0 : internalOptions.dts)) return null;
const load = loadModule('rollup-plugin-dts');
if (!load) {
print.tip('[Bump]: please install rollup-plugin-dts.');
return null;
}
return [
load({
compilerOptions: {
preserveSymlinks: false
}
})
];
})();
return handler({
rollupConfig: internalRollupConfig,
tasks,
formats,
dts
});
};
const replaceEntryFileNames = (format, { file , minify })=>{
const fileNameRule = '[name].[format][min][ext]';
const fileName = file || fileNameRule;
let fileNameTemplate = typeof fileName === 'function' ? fileName({
format,
minify: Boolean(minify)
}, fileNameRule) : fileName;
fileNameTemplate = fileNameTemplate.replace(/\[min\]/, minify ? '.min' : '').replace(/\[ext\]/, '.js').replace(/\[format\]/, format);
return fileNameTemplate;
};
/**
*@description dine bump config.
*/ const define = (options)=>options;
const build = (options)=>buildImpl(options);
const watch = (options)=>watchImpl(options);
exports.build = build;
exports.define = define;
exports.len = len;
exports.print = print;
exports.throwInvalidateError = throwInvalidateError;
exports.watch = watch;
import fsp from 'fs/promises';
import * as rollup from 'rollup';
import alias from '@rollup/plugin-alias';
import replace from '@rollup/plugin-replace';
import { swc } from 'rollup-plugin-swc3';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import merge from 'lodash.merge';
import path from 'path';
const len = (tar)=>tar.length;
const hasOwn = (source, key)=>Object.prototype.hasOwnProperty.call(source, key);
const isPlainObject = (tar)=>Object.prototype.toString.call(tar).slice(8, -1) === 'Object';
const loadModule = (alias)=>{
try {
const raw = require(alias);
return raw.__esModule ? raw.default : raw;
} catch (err) {
return false;
} finally{
delete require.cache[require.resolve(alias)];
}
};
function _defineProperty$1(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread$1(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty$1(target, key, source[key]);
});
}
return target;
}
function _objectWithoutProperties$1(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose$1(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose$1(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;
}
const createPlugins = (options)=>{
var _rest_internalOptions, _rest_resolve;
const { plugins: userPlugins = [] } = options, rest = _objectWithoutProperties$1(options, [
"plugins"
]);
const plugins = [];
const internalPlugins = {
replace: (config)=>{
var _rest_resolve;
return replace(merge(_objectSpread$1({
preventAssignment: true
}, (_rest_resolve = rest.resolve) === null || _rest_resolve === void 0 ? void 0 : _rest_resolve.define), config));
},
commonjs: (config)=>commonjs(merge({
esmExternals: true
}, config)),
nodeResolve: nodeResolve,
swc: (config)=>swc(merge({
sourceMaps: rest.sourceMap,
jsc: {
transform: {
react: rest.jsx
},
externalHelpers: rest.extractHelpers
},
minify: rest.minify
}, config))
};
var _rest_internalOptions_plugins;
const internalPluginsOptions = (_rest_internalOptions_plugins = (_rest_internalOptions = rest.internalOptions) === null || _rest_internalOptions === void 0 ? void 0 : _rest_internalOptions.plugins) !== null && _rest_internalOptions_plugins !== void 0 ? _rest_internalOptions_plugins : {};
Object.entries(internalPlugins).forEach(([name, plugin])=>{
if (hasOwn(internalPluginsOptions, name)) {
// @ts-ignored
const original = internalPluginsOptions[name];
if (original) {
const config = typeof original === 'boolean' ? {} : original;
plugins.push(plugin(config));
return;
}
return;
}
plugins.push(plugin({}));
});
// rollup internal logic will verfiy each plugin. So that we only merge user plugin is enough
plugins.push(...userPlugins);
const serializeAliasPattern = (pattern)=>{
if (!pattern) return [];
if (Array.isArray(pattern)) return pattern;
return Object.entries(pattern).map(([find, replacement])=>({
['find']: find,
['replacement']: replacement
}));
};
plugins.unshift(alias({
entries: serializeAliasPattern((_rest_resolve = rest.resolve) === null || _rest_resolve === void 0 ? void 0 : _rest_resolve.alias)
}));
return {
plugins
};
};
const print = {
log: (text)=>console.log('\x1b[37m%s \x1b[2m%s\x1b[0m', '>', text),
danger: (text)=>console.log('\x1b[31m%s \x1b[31m%s\x1b[0m', '>', text),
tip: (text)=>console.log('\x1b[36m%s \x1b[36m%s\x1b[0m', '>', text)
};
const error = (base)=>{
if (!(base instanceof Error)) base = Object.assign(new Error(base.message), base);
return base;
};
const throwInvalidateError = (err)=>{
if (typeof err === 'string') err = {
message: err
};
throw error(err);
};
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectSpread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_defineProperty(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpreadProps(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for(i = 0; i < sourceSymbolKeys.length; i++){
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _objectWithoutPropertiesLoose(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;
}
const defaultExternal = async ()=>{
const tar = path.join(process.cwd(), 'package.json');
const pkgJSON = await fsp.readFile(tar, 'utf8').catch(()=>'{}');
const { dependencies ={} , peerDependencies ={} } = JSON.parse(pkgJSON);
return Object.keys(_objectSpread({}, dependencies, peerDependencies));
};
const parseOptions = async (userOptions)=>{
var _userOptions_output, _userOptions_output1, _userOptions_output2, _userOptions_output3, _userOptions_output4, _userOptions_output5, _userOptions_output6, _userOptions_output7, _userOptions_output8, _userOptions_output9, _userOptions_output10, _userOptions_output11, _userOptions_output12;
const external = await defaultExternal();
const ensureFormat = (userFormat)=>{
if (!userFormat || Array.isArray(userFormat) && !len(userFormat)) return [
'cjs',
'esm'
];
const formats = Array.isArray(userFormat) ? userFormat : [
userFormat
];
return formats.map((format)=>{
if (format === 'commonjs') return 'cjs';
if (format === 'es') return 'esm';
return format;
});
};
var _userOptions_external, _userOptions_output_dir;
const rollupOptions = {
external: (_userOptions_external = userOptions.external) !== null && _userOptions_external !== void 0 ? _userOptions_external : external,
output: {
dir: (_userOptions_output_dir = (_userOptions_output = userOptions.output) === null || _userOptions_output === void 0 ? void 0 : _userOptions_output.dir) !== null && _userOptions_output_dir !== void 0 ? _userOptions_output_dir : 'dist',
sourcemap: (_userOptions_output1 = userOptions.output) === null || _userOptions_output1 === void 0 ? void 0 : _userOptions_output1.sourceMap,
globals: userOptions.global,
name: (_userOptions_output2 = userOptions.output) === null || _userOptions_output2 === void 0 ? void 0 : _userOptions_output2.name,
preserveModules: (_userOptions_output3 = userOptions.output) === null || _userOptions_output3 === void 0 ? void 0 : _userOptions_output3.preserveModules,
preserveModulesRoot: (_userOptions_output4 = userOptions.output) === null || _userOptions_output4 === void 0 ? void 0 : _userOptions_output4.preserveModulesRoot,
exports: (_userOptions_output5 = userOptions.output) === null || _userOptions_output5 === void 0 ? void 0 : _userOptions_output5.exports
}
};
var _userOptions_input;
const internalOptions = {
minify: (_userOptions_output6 = userOptions.output) === null || _userOptions_output6 === void 0 ? void 0 : _userOptions_output6.minify,
extractHelpers: (_userOptions_output7 = userOptions.output) === null || _userOptions_output7 === void 0 ? void 0 : _userOptions_output7.extractHelpers,
dts: (_userOptions_output8 = userOptions.output) === null || _userOptions_output8 === void 0 ? void 0 : _userOptions_output8.dts,
jsx: (_userOptions_output9 = userOptions.output) === null || _userOptions_output9 === void 0 ? void 0 : _userOptions_output9.jsx,
format: ensureFormat((_userOptions_output10 = userOptions.output) === null || _userOptions_output10 === void 0 ? void 0 : _userOptions_output10.format),
clean: userOptions.clean,
input: (_userOptions_input = userOptions.input) !== null && _userOptions_input !== void 0 ? _userOptions_input : 'src/index.js',
plugins: userOptions.plugins,
internalOptions: userOptions.internalOptions,
sourceMap: (_userOptions_output11 = userOptions.output) === null || _userOptions_output11 === void 0 ? void 0 : _userOptions_output11.sourceMap,
resolve: userOptions.resolve,
file: (_userOptions_output12 = userOptions.output) === null || _userOptions_output12 === void 0 ? void 0 : _userOptions_output12.file
};
return {
rollupOptions,
internalOptions
};
};
const buildImpl = async (userOptions = {})=>{
if (userOptions) {
if (!isPlainObject(userOptions)) throwInvalidateError('[Bump]: please check your config. config should be an Object.');
}
const { internalOptions , rollupOptions } = await parseOptions(userOptions);
const { plugins } = createPlugins(internalOptions);
return runServer(rollupOptions, internalOptions, plugins, async ({ rollupConfig , dts , formats , tasks })=>{
try {
if (internalOptions.clean) {
var _rollupOptions_output;
if (!Array.isArray(rollupOptions.output) && ((_rollupOptions_output = rollupOptions.output) === null || _rollupOptions_output === void 0 ? void 0 : _rollupOptions_output.dir)) {
await fsp.rm(rollupOptions.output.dir, {
recursive: true,
force: true
});
}
}
const instances = [];
const results = [];
await Promise.all(tasks.map(async (task)=>{
const { plugins , external } = rollupConfig, rest = _objectWithoutProperties(rollupConfig, [
"plugins",
"external"
]);
const bundle = await rollup.rollup({
plugins,
external,
input: task
});
formats.forEach(async (format)=>{
const entryFileNames = replaceEntryFileNames(format, {
file: internalOptions.file,
minify: internalOptions.minify
});
const result = await bundle.write(_objectSpreadProps(_objectSpread({}, rest.output), {
format,
entryFileNames
}));
instances.push(bundle);
results.push(result);
});
if (dts) {
const dtsBundle = await rollup.rollup({
external,
input: task,
plugins: dts
});
const result = await dtsBundle.write(_objectSpreadProps(_objectSpread({}, rest.output), {
format: 'esm'
}));
instances.push(dtsBundle);
results.push(result);
}
}));
await Promise.all(instances.map((instance)=>instance.close()));
return results;
} catch (error) {
throw error;
}
});
};
const watchImpl = async (userOptions = {})=>{
if (userOptions) {
if (!isPlainObject(userOptions)) throwInvalidateError('[Bump]: please check your config. config should be an Object.');
}
const { internalOptions , rollupOptions } = await parseOptions(userOptions);
const { plugins } = createPlugins(internalOptions);
return runServer(rollupOptions, internalOptions, plugins, async ({ rollupConfig , dts , formats , tasks })=>{
const { external , plugins } = rollupConfig, rest = _objectWithoutProperties(rollupConfig, [
"external",
"plugins"
]);
const watcherOptions = tasks.flatMap((task)=>{
return formats.map((format)=>{
const entryFileNames = replaceEntryFileNames(format, {
file: internalOptions.file,
minify: internalOptions.minify
});
return {
plugins,
external,
input: task,
output: _objectSpreadProps(_objectSpread({}, rest.output), {
entryFileNames,
format
}),
watch: {}
};
});
});
if (dts) {
tasks.forEach((task)=>{
watcherOptions.push({
external,
input: task,
plugins: dts,
output: _objectSpreadProps(_objectSpread({}, rest.output), {
format: 'esm'
}),
watch: {}
});
});
}
const watcher = rollup.watch(watcherOptions);
watcher.on('event', (evt)=>{
if (evt.code === 'ERROR') {
print.danger(evt.error.message);
}
});
return watcher;
});
};
const runServer = async (rollupOptions, internalOptions, plugins, handler)=>{
const { input , format: formats } = internalOptions;
const tasks = [];
if (Array.isArray(input)) tasks.push(...input);
if (typeof input === 'string') tasks.push(input);
if (!Array.isArray(input) && typeof input === 'object') {
const entry = Object.values(input);
if (!len(entry)) tasks.push('src/index.js');
tasks.push(...entry);
}
const internalRollupConfig = _objectSpreadProps(_objectSpread({}, rollupOptions), {
plugins
});
const dts = (()=>{
if (!(internalOptions === null || internalOptions === void 0 ? void 0 : internalOptions.dts)) return null;
const load = loadModule('rollup-plugin-dts');
if (!load) {
print.tip('[Bump]: please install rollup-plugin-dts.');
return null;
}
return [
load({
compilerOptions: {
preserveSymlinks: false
}
})
];
})();
return handler({
rollupConfig: internalRollupConfig,
tasks,
formats,
dts
});
};
const replaceEntryFileNames = (format, { file , minify })=>{
const fileNameRule = '[name].[format][min][ext]';
const fileName = file || fileNameRule;
let fileNameTemplate = typeof fileName === 'function' ? fileName({
format,
minify: Boolean(minify)
}, fileNameRule) : fileName;
fileNameTemplate = fileNameTemplate.replace(/\[min\]/, minify ? '.min' : '').replace(/\[ext\]/, '.js').replace(/\[format\]/, format);
return fileNameTemplate;
};
/**
*@description dine bump config.
*/ const define = (options)=>options;
const build = (options)=>buildImpl(options);
const watch = (options)=>watchImpl(options);
export { build as b, define as d, len as l, print as p, throwInvalidateError as t, watch as w };
'use strict';
var api = require('./api-23dc07a5.js');
var path = require('path');
var fs = require('fs');
var core = require('@swc/core');
require('fs/promises');
require('rollup');
require('@rollup/plugin-alias');
require('@rollup/plugin-replace');
require('rollup-plugin-swc3');
require('@rollup/plugin-node-resolve');
require('@rollup/plugin-commonjs');
require('lodash.merge');
const configFiles = [
'bump.config.js',
'bump.config.ts'
];
// For future we will support inline config from stdin
const resolveConfig = async ()=>{
try {
let count = api.len(configFiles);
let file = '';
while(count){
const name = configFiles[count - 1];
const p = path.resolve(process.cwd(), name);
if (fs.existsSync(p)) {
file = p;
break;
}
count--;
}
if (!file) return {};
let code = await fs.promises.readFile(file, 'utf-8');
({ code } = await core.transform(code, {
filename: file,
isModule: 'unknown',
sourceMaps: false,
module: {
type: 'commonjs'
}
}));
return loadConfigFromBundledFile(file, code);
} catch (err) {
throw api.throwInvalidateError(err);
}
};
const loadConfigFromBundledFile = async (fileName, bundledCode)=>{
const extension = path.extname(fileName);
const defaultLoader = require.extensions[extension];
require.extensions[extension] = (module, filename)=>{
if (filename === fileName) {
module._compile(bundledCode, filename);
} else {
defaultLoader(module, filename);
}
};
delete require.cache[require.resolve(fileName)];
const raw = require(fileName);
const config = raw.__esModule ? raw.default : raw;
require.extensions[extension] = defaultLoader;
return config;
};
const handleError = (error)=>{
let declaration = error.message || error;
if (error.name) declaration = `${error.name}: ${declaration}`;
const message = error.plugin ? `(plugin ${error.plugin}) ${declaration}` : declaration || error;
api.print.tip(message);
if (error.url) api.print.log(error.url);
if (error.loc) api.print.danger(`${error.loc.file || error.id}:${error.loc.line}:${error.loc.column}`);
else if (error.id) api.print.danger(error.id);
if (error.frame) api.print.danger(error.frame);
if (error.stack) api.print.danger(error.stack);
};
var cli = (async function() {
try {
const options = await resolveConfig();
if (!options.watch) {
await api.build(options);
return;
}
await api.watch(options);
} catch (error) {
handleError(error);
process.exit(1);
}
})();
module.exports = cli;
import { l as len, t as throwInvalidateError, b as build, w as watch, p as print } from './api-b12b4e26.js';
import path from 'path';
import fs from 'fs';
import { transform } from '@swc/core';
import 'fs/promises';
import 'rollup';
import '@rollup/plugin-alias';
import '@rollup/plugin-replace';
import 'rollup-plugin-swc3';
import '@rollup/plugin-node-resolve';
import '@rollup/plugin-commonjs';
import 'lodash.merge';
const configFiles = [
'bump.config.js',
'bump.config.ts'
];
// For future we will support inline config from stdin
const resolveConfig = async ()=>{
try {
let count = len(configFiles);
let file = '';
while(count){
const name = configFiles[count - 1];
const p = path.resolve(process.cwd(), name);
if (fs.existsSync(p)) {
file = p;
break;
}
count--;
}
if (!file) return {};
let code = await fs.promises.readFile(file, 'utf-8');
({ code } = await transform(code, {
filename: file,
isModule: 'unknown',
sourceMaps: false,
module: {
type: 'commonjs'
}
}));
return loadConfigFromBundledFile(file, code);
} catch (err) {
throw throwInvalidateError(err);
}
};
const loadConfigFromBundledFile = async (fileName, bundledCode)=>{
const extension = path.extname(fileName);
const defaultLoader = require.extensions[extension];
require.extensions[extension] = (module, filename)=>{
if (filename === fileName) {
module._compile(bundledCode, filename);
} else {
defaultLoader(module, filename);
}
};
delete require.cache[require.resolve(fileName)];
const raw = require(fileName);
const config = raw.__esModule ? raw.default : raw;
require.extensions[extension] = defaultLoader;
return config;
};
const handleError = (error)=>{
let declaration = error.message || error;
if (error.name) declaration = `${error.name}: ${declaration}`;
const message = error.plugin ? `(plugin ${error.plugin}) ${declaration}` : declaration || error;
print.tip(message);
if (error.url) print.log(error.url);
if (error.loc) print.danger(`${error.loc.file || error.id}:${error.loc.line}:${error.loc.column}`);
else if (error.id) print.danger(error.id);
if (error.frame) print.danger(error.frame);
if (error.stack) print.danger(error.stack);
};
var cli = (async function() {
try {
const options = await resolveConfig();
if (!options.watch) {
await build(options);
return;
}
await watch(options);
} catch (error) {
handleError(error);
process.exit(1);
}
})();
export { cli as default };
'use strict';
var api = require('./api-23dc07a5.js');
require('fs/promises');
require('rollup');
require('@rollup/plugin-alias');
require('@rollup/plugin-replace');
require('rollup-plugin-swc3');
require('@rollup/plugin-node-resolve');
require('@rollup/plugin-commonjs');
require('lodash.merge');
require('path');
exports.build = api.build;
exports.define = api.define;
exports.watch = api.watch;
export { b as build, d as define, w as watch } from './api-b12b4e26.js';
import 'fs/promises';
import 'rollup';
import '@rollup/plugin-alias';
import '@rollup/plugin-replace';
import 'rollup-plugin-swc3';
import '@rollup/plugin-node-resolve';
import '@rollup/plugin-commonjs';
import 'lodash.merge';
import 'path';