New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
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.3.0 to 0.3.1

lib/api-impl-9b70bf1a.js

0

bin/bump.js
#!/usr/bin/env node
require('../lib/cli.cjs')

420

lib/cli.cjs.js
'use strict';
var rollup = require('rollup');
var apiImpl = require('./api-impl-9b70bf1a.js');
var path = require('path');
var fs = require('fs');
var path = require('path');
var merge = require('lodash.merge');
var alias = require('@rollup/plugin-alias');
var define = require('@rollup/plugin-replace');
var rollupPluginSwc3 = require('rollup-plugin-swc3');
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
var commonjs = require('@rollup/plugin-commonjs');
var postcss = require('rollup-plugin-postcss');
var core = require('@swc/core');
require('rollup');
require('lodash.merge');
require('@rollup/plugin-alias');
require('@rollup/plugin-replace');
require('rollup-plugin-swc3');
require('@rollup/plugin-node-resolve');
require('@rollup/plugin-commonjs');
require('rollup-plugin-postcss');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
var alias__default = /*#__PURE__*/_interopDefaultLegacy(alias);
var define__default = /*#__PURE__*/_interopDefaultLegacy(define);
var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
var postcss__default = /*#__PURE__*/_interopDefaultLegacy(postcss);
var _object_spread = {};
var _define_property = {};
Object.defineProperty(_define_property, "__esModule", {
value: true
});
_define_property.default = _defineProperty$1;
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;
}
Object.defineProperty(_object_spread, "__esModule", {
value: true
});
var _default$1 = _object_spread.default = _objectSpread;
var _defineProperty = _interopRequireDefault(_define_property);
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).default(target, key, source[key]);
});
}
return target;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
var _object_spread_props = {};
Object.defineProperty(_object_spread_props, "__esModule", {
value: true
});
var _default = _object_spread_props.default = _objectSpreadProps;
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 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;
}
/**
* @default 'src/index.js'
* @description preset lib entry
*/ const universalInput = 'src/index.js';
/**
*@default ['cjs','esm']
@description preset generator formats
*/ const universalOutput = {
dir: 'dist',
sourceMap: true,
extractCss: true,
minifiy: false,
preserveModules: false,
extractHelpers: true,
exports: 'auto'
};
const PRESET_FORMAT = [
'cjs',
'esm'
];
const serialize = (source)=>Object.values(source);
const configFiles = [
'bump.config.js',
'bump.config.ts'
];
const BASIC_TYPES = {
Null: 'Null',
Undefined: 'Undefined',
String: 'String',
Number: 'Number',
Boolean: 'Boolean',
Array: 'Array',
Date: 'Date',
Function: 'Function',
RegExp: 'RegExp',
Object: 'Object'
};
const getUniversalType = (tar)=>Object.prototype.toString.call(tar).slice(8, -1);
const isPlainObject = (tar)=>getUniversalType(tar) === BASIC_TYPES.Object;
const omit = (source, picks)=>Object.keys(source).reduce((acc, cur)=>picks.includes(cur) ? acc : Object.assign(acc, {
[cur]: source[cur]
}), {});
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)];
}
};
const len = (tar)=>tar.length;
const readJson = (path)=>fs__default["default"].promises.readFile(path, 'utf-8').then((r)=>JSON.parse(r)).catch((e)=>e);
const existSync = (path)=>{
try {
fs__default["default"].accessSync(path, fs__default["default"].constants.F_OK);
return true;
} catch (error) {
return false;
}
};
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
};
return error(err);
};
const parserPlugins = (options = {})=>{
var ref;
const { userPlugins , internalPluginsOptions , options: userOptions } = options;
const internalPlugins = withIntenralPlugins(internalPluginsOptions, userOptions);
const plugins = serializePlugin(internalPlugins, userPlugins);
const getAliasPattern = (pattern)=>{
if (!pattern) return [];
if (Array.isArray(pattern)) return pattern;
return Object.entries(pattern).map(([find, replacement])=>({
['find']: find,
['replacement']: replacement
}));
};
/**
* Alias first
* then user plugins
* then internal plugins
* then minifiy
*/ if (userOptions === null || userOptions === void 0 ? void 0 : userOptions.minifiy) {
plugins.push(rollupPluginSwc3.minify({
sourceMap: userOptions === null || userOptions === void 0 ? void 0 : userOptions.sourceMap
}));
}
plugins.unshift(alias__default["default"]({
entries: getAliasPattern(userOptions === null || userOptions === void 0 ? void 0 : (ref = userOptions.resolve) === null || ref === void 0 ? void 0 : ref.alias)
}));
return plugins;
};
const withIntenralPlugins = (internalPluginOtions, options)=>{
var ref;
const internalPlugins = {
commonjs: commonjs__default["default"](merge__default["default"]({
esmExternals: true
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.commonjs)),
define: define__default["default"](options === null || options === void 0 ? void 0 : (ref = options.resolve) === null || ref === void 0 ? void 0 : ref.define),
nodeResolve: pluginNodeResolve.nodeResolve(internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.nodeResolve),
swc: rollupPluginSwc3.swc(rollupPluginSwc3.defineRollupSwcOption(merge__default["default"]({
sourceMaps: options === null || options === void 0 ? void 0 : options.sourceMap,
jsc: {
transform: {
react: options === null || options === void 0 ? void 0 : options.jsx
},
externalHelpers: options === null || options === void 0 ? void 0 : options.extractHelpers
}
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.swc))),
postcss: postcss__default["default"](merge__default["default"]({
extract: options === null || options === void 0 ? void 0 : options.extractCss
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.postcss))
};
return internalPlugins;
};
const serializePlugin = (plugins, userPlugins)=>{
if (!userPlugins || !len(Object.keys(userPlugins))) return serialize(plugins);
const merged = Object.assign({}, userPlugins, plugins);
return serialize(merged);
};
const build = (options)=>buildImpl(options);
const defaultExternal = async ()=>{
const tar = path__default["default"].join(process.cwd(), 'package.json');
const { dependencies , peerDependencies } = await readJson(tar);
return Object.keys(_default$1({}, dependencies, peerDependencies));
};
const buildImpl = async (options, extraOptions)=>{
var ref, ref1, ref2;
const external = await defaultExternal();
let optionImpl = {
input: universalInput,
output: universalOutput,
external
};
if (options) {
if (!isPlainObject(options)) throw throwInvalidateError('[Bump]: please set an object config');
optionImpl = parserOptions(optionImpl, options);
}
const format = (ref = optionImpl.output) === null || ref === void 0 ? void 0 : ref.format;
if (!format || Array.isArray(format) && !len(format)) {
optionImpl.output = _default(_default$1({}, optionImpl.output), {
format: PRESET_FORMAT
});
}
/**
* Because dts plugin will overwrites the out. so we
* only change value of dts to judge we should or not
* load the dts module plugin.
*/ if ((ref1 = optionImpl.output) === null || ref1 === void 0 ? void 0 : ref1.dts) {
if (!loadModule('typescript')) {
optionImpl.output.dts = false;
print.log('[Bump]: If you want to generate declaration file you should insatll typescript in your project and write with typescript :)');
}
}
var ref3;
const plugins = parserPlugins({
userPlugins: optionImpl === null || optionImpl === void 0 ? void 0 : optionImpl.plugins,
internalPluginsOptions: (ref3 = (ref2 = optionImpl.internalOptions) === null || ref2 === void 0 ? void 0 : ref2.plugins) !== null && ref3 !== void 0 ? ref3 : optionImpl.internalPlugins,
options: merge__default["default"]({}, optionImpl.output, {
resolve: optionImpl.resolve
})
});
try {
await runImpl(optionImpl, plugins, extraOptions);
} catch (error) {
throw error;
}
};
/**
* @description runImp is use for buildImpl .for future version i plan to add watch
* API so needs to realized.
*/ const runImpl = async (optionImpl, plugins, extraOptions)=>{
var ref;
let { input } = optionImpl;
if (!Array.isArray(input) && !isPlainObject(input)) input = [
input || universalInput
];
if (isPlainObject(input)) input = serialize(input);
if (!(input === null || input === void 0 ? void 0 : input.length)) input = [
universalInput
];
const formats = optionImpl.output.format;
/**
* Input parseing rules.
* We should translate user input as array. when user define a object array. we think it's mulitple
* tasks mulit-entry.
*/ const inputs = input;
const tasks = [];
for (const source of inputs){
for (const format of formats){
tasks.push({
getConfig () {
const rollupConfig = generatorRollupConfig({
source,
format,
config: optionImpl,
plugins
});
return rollupConfig;
}
});
}
}
if (((ref = optionImpl.output) === null || ref === void 0 ? void 0 : ref.dts) && !extraOptions) {
const dts = ()=>{
const canload = loadModule('rollup-plugin-dts');
if (canload) return [
canload()
];
return [];
};
// I should get all entryFileNames as input chunk.
await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
const bundle = await rollup.rollup(_default(_default$1({}, inputConfig), {
plugins: dts()
}));
await bundle.write(omit(outputConfig, [
'entryFileNames'
]));
}));
}
if (extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.watch) {
const configs = await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
return _default(_default$1({}, inputConfig), {
output: outputConfig,
watch: {}
});
}));
const watcher = rollup.watch(configs);
watcher.on('event', (e)=>{
if (e.code === 'ERROR') {
print.danger(e.error.message);
}
});
} else {
await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
const bundle = await rollup.rollup(inputConfig);
await bundle.write(outputConfig);
}));
}
};
/**
*@description Parser user options and preset options
*/ const parserOptions = (defaultOptions, userOptions)=>{
if (!Object.keys(userOptions)) return defaultOptions;
const options = Object.assign({}, defaultOptions, userOptions, {
output: merge__default["default"]({}, defaultOptions.output, userOptions.output)
});
return options;
};
/**
* @description generator rollup bundle config for input and output
*/ const generatorRollupConfig = (originalConfig)=>{
var ref, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11;
const { source , format , config , plugins } = originalConfig;
const fileNameRule = '[name].[format][min][ext]';
const fileName = ((ref = config.output) === null || ref === void 0 ? void 0 : ref.file) || fileNameRule;
let fileNameTemplate = typeof fileName === 'function' ? fileName({
format,
minify: Boolean((ref4 = config.output) === null || ref4 === void 0 ? void 0 : ref4.minifiy)
}, fileNameRule) : fileName;
fileNameTemplate = fileNameTemplate.replace(/\[min\]/, ((ref5 = config.output) === null || ref5 === void 0 ? void 0 : ref5.minifiy) ? '.min' : '').replace(/\[ext\]/, '.js').replace(/\[format\]/, format);
return {
inputConfig: {
input: source,
plugins,
external: config.external
},
outputConfig: {
format,
exports: (ref6 = config.output) === null || ref6 === void 0 ? void 0 : ref6.exports,
entryFileNames: fileNameTemplate,
dir: (ref7 = config.output) === null || ref7 === void 0 ? void 0 : ref7.dir,
sourcemap: (ref8 = config.output) === null || ref8 === void 0 ? void 0 : ref8.sourceMap,
globals: config.global,
name: (ref9 = config.output) === null || ref9 === void 0 ? void 0 : ref9.name,
preserveModules: (ref10 = config.output) === null || ref10 === void 0 ? void 0 : ref10.preserveModules,
preserveModulesRoot: (ref11 = config.output) === null || ref11 === void 0 ? void 0 : ref11.preserveModulesRoot
}
};
};
// For future we will support inline config from stdin
const resolveConfig = async ()=>{
try {
let count = len(configFiles);
let count = apiImpl.len(apiImpl.configFiles);
let file = '';
while(count){
const name = configFiles[count - 1];
const name = apiImpl.configFiles[count - 1];
const p = path__default["default"].resolve(process.cwd(), name);
if (existSync(p)) {
if (apiImpl.existSync(p)) {
file = p;

@@ -433,3 +47,3 @@ break;

} catch (err) {
throw throwInvalidateError(err);
throw apiImpl.throwInvalidateError(err);
}

@@ -457,5 +71,5 @@ };

const options = await resolveConfig();
await build(options);
await apiImpl.build(options);
} catch (error) {
if (error instanceof Error) print.danger(error.message);
if (error instanceof Error) apiImpl.print.danger(error.message);
process.exit(1);

@@ -462,0 +76,0 @@ }

@@ -1,395 +0,14 @@

import { rollup, watch } from 'rollup';
import { l as len, a as configFiles, e as existSync, t as throwInvalidateError, b as build, p as print } from './api-impl-f0675bba.js';
import path from 'path';
import fs from 'fs';
import path from 'path';
import merge from 'lodash.merge';
import alias from '@rollup/plugin-alias';
import define from '@rollup/plugin-replace';
import { minify, swc, defineRollupSwcOption } from 'rollup-plugin-swc3';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
import { transform } from '@swc/core';
import 'rollup';
import 'lodash.merge';
import '@rollup/plugin-alias';
import '@rollup/plugin-replace';
import 'rollup-plugin-swc3';
import '@rollup/plugin-node-resolve';
import '@rollup/plugin-commonjs';
import 'rollup-plugin-postcss';
var _object_spread = {};
var _define_property = {};
Object.defineProperty(_define_property, "__esModule", {
value: true
});
_define_property.default = _defineProperty$1;
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;
}
Object.defineProperty(_object_spread, "__esModule", {
value: true
});
var _default$1 = _object_spread.default = _objectSpread;
var _defineProperty = _interopRequireDefault(_define_property);
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).default(target, key, source[key]);
});
}
return target;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
var _object_spread_props = {};
Object.defineProperty(_object_spread_props, "__esModule", {
value: true
});
var _default = _object_spread_props.default = _objectSpreadProps;
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 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;
}
/**
* @default 'src/index.js'
* @description preset lib entry
*/ const universalInput = 'src/index.js';
/**
*@default ['cjs','esm']
@description preset generator formats
*/ const universalOutput = {
dir: 'dist',
sourceMap: true,
extractCss: true,
minifiy: false,
preserveModules: false,
extractHelpers: true,
exports: 'auto'
};
const PRESET_FORMAT = [
'cjs',
'esm'
];
const serialize = (source)=>Object.values(source);
const configFiles = [
'bump.config.js',
'bump.config.ts'
];
const BASIC_TYPES = {
Null: 'Null',
Undefined: 'Undefined',
String: 'String',
Number: 'Number',
Boolean: 'Boolean',
Array: 'Array',
Date: 'Date',
Function: 'Function',
RegExp: 'RegExp',
Object: 'Object'
};
const getUniversalType = (tar)=>Object.prototype.toString.call(tar).slice(8, -1);
const isPlainObject = (tar)=>getUniversalType(tar) === BASIC_TYPES.Object;
const omit = (source, picks)=>Object.keys(source).reduce((acc, cur)=>picks.includes(cur) ? acc : Object.assign(acc, {
[cur]: source[cur]
}), {});
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)];
}
};
const len = (tar)=>tar.length;
const readJson = (path)=>fs.promises.readFile(path, 'utf-8').then((r)=>JSON.parse(r)).catch((e)=>e);
const existSync = (path)=>{
try {
fs.accessSync(path, fs.constants.F_OK);
return true;
} catch (error) {
return false;
}
};
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
};
return error(err);
};
const parserPlugins = (options = {})=>{
var ref;
const { userPlugins , internalPluginsOptions , options: userOptions } = options;
const internalPlugins = withIntenralPlugins(internalPluginsOptions, userOptions);
const plugins = serializePlugin(internalPlugins, userPlugins);
const getAliasPattern = (pattern)=>{
if (!pattern) return [];
if (Array.isArray(pattern)) return pattern;
return Object.entries(pattern).map(([find, replacement])=>({
['find']: find,
['replacement']: replacement
}));
};
/**
* Alias first
* then user plugins
* then internal plugins
* then minifiy
*/ if (userOptions === null || userOptions === void 0 ? void 0 : userOptions.minifiy) {
plugins.push(minify({
sourceMap: userOptions === null || userOptions === void 0 ? void 0 : userOptions.sourceMap
}));
}
plugins.unshift(alias({
entries: getAliasPattern(userOptions === null || userOptions === void 0 ? void 0 : (ref = userOptions.resolve) === null || ref === void 0 ? void 0 : ref.alias)
}));
return plugins;
};
const withIntenralPlugins = (internalPluginOtions, options)=>{
var ref;
const internalPlugins = {
commonjs: commonjs(merge({
esmExternals: true
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.commonjs)),
define: define(options === null || options === void 0 ? void 0 : (ref = options.resolve) === null || ref === void 0 ? void 0 : ref.define),
nodeResolve: nodeResolve(internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.nodeResolve),
swc: swc(defineRollupSwcOption(merge({
sourceMaps: options === null || options === void 0 ? void 0 : options.sourceMap,
jsc: {
transform: {
react: options === null || options === void 0 ? void 0 : options.jsx
},
externalHelpers: options === null || options === void 0 ? void 0 : options.extractHelpers
}
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.swc))),
postcss: postcss(merge({
extract: options === null || options === void 0 ? void 0 : options.extractCss
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.postcss))
};
return internalPlugins;
};
const serializePlugin = (plugins, userPlugins)=>{
if (!userPlugins || !len(Object.keys(userPlugins))) return serialize(plugins);
const merged = Object.assign({}, userPlugins, plugins);
return serialize(merged);
};
const build = (options)=>buildImpl(options);
const defaultExternal = async ()=>{
const tar = path.join(process.cwd(), 'package.json');
const { dependencies , peerDependencies } = await readJson(tar);
return Object.keys(_default$1({}, dependencies, peerDependencies));
};
const buildImpl = async (options, extraOptions)=>{
var ref, ref1, ref2;
const external = await defaultExternal();
let optionImpl = {
input: universalInput,
output: universalOutput,
external
};
if (options) {
if (!isPlainObject(options)) throw throwInvalidateError('[Bump]: please set an object config');
optionImpl = parserOptions(optionImpl, options);
}
const format = (ref = optionImpl.output) === null || ref === void 0 ? void 0 : ref.format;
if (!format || Array.isArray(format) && !len(format)) {
optionImpl.output = _default(_default$1({}, optionImpl.output), {
format: PRESET_FORMAT
});
}
/**
* Because dts plugin will overwrites the out. so we
* only change value of dts to judge we should or not
* load the dts module plugin.
*/ if ((ref1 = optionImpl.output) === null || ref1 === void 0 ? void 0 : ref1.dts) {
if (!loadModule('typescript')) {
optionImpl.output.dts = false;
print.log('[Bump]: If you want to generate declaration file you should insatll typescript in your project and write with typescript :)');
}
}
var ref3;
const plugins = parserPlugins({
userPlugins: optionImpl === null || optionImpl === void 0 ? void 0 : optionImpl.plugins,
internalPluginsOptions: (ref3 = (ref2 = optionImpl.internalOptions) === null || ref2 === void 0 ? void 0 : ref2.plugins) !== null && ref3 !== void 0 ? ref3 : optionImpl.internalPlugins,
options: merge({}, optionImpl.output, {
resolve: optionImpl.resolve
})
});
try {
await runImpl(optionImpl, plugins, extraOptions);
} catch (error) {
throw error;
}
};
/**
* @description runImp is use for buildImpl .for future version i plan to add watch
* API so needs to realized.
*/ const runImpl = async (optionImpl, plugins, extraOptions)=>{
var ref;
let { input } = optionImpl;
if (!Array.isArray(input) && !isPlainObject(input)) input = [
input || universalInput
];
if (isPlainObject(input)) input = serialize(input);
if (!(input === null || input === void 0 ? void 0 : input.length)) input = [
universalInput
];
const formats = optionImpl.output.format;
/**
* Input parseing rules.
* We should translate user input as array. when user define a object array. we think it's mulitple
* tasks mulit-entry.
*/ const inputs = input;
const tasks = [];
for (const source of inputs){
for (const format of formats){
tasks.push({
getConfig () {
const rollupConfig = generatorRollupConfig({
source,
format,
config: optionImpl,
plugins
});
return rollupConfig;
}
});
}
}
if (((ref = optionImpl.output) === null || ref === void 0 ? void 0 : ref.dts) && !extraOptions) {
const dts = ()=>{
const canload = loadModule('rollup-plugin-dts');
if (canload) return [
canload()
];
return [];
};
// I should get all entryFileNames as input chunk.
await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
const bundle = await rollup(_default(_default$1({}, inputConfig), {
plugins: dts()
}));
await bundle.write(omit(outputConfig, [
'entryFileNames'
]));
}));
}
if (extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.watch) {
const configs = await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
return _default(_default$1({}, inputConfig), {
output: outputConfig,
watch: {}
});
}));
const watcher = watch(configs);
watcher.on('event', (e)=>{
if (e.code === 'ERROR') {
print.danger(e.error.message);
}
});
} else {
await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
const bundle = await rollup(inputConfig);
await bundle.write(outputConfig);
}));
}
};
/**
*@description Parser user options and preset options
*/ const parserOptions = (defaultOptions, userOptions)=>{
if (!Object.keys(userOptions)) return defaultOptions;
const options = Object.assign({}, defaultOptions, userOptions, {
output: merge({}, defaultOptions.output, userOptions.output)
});
return options;
};
/**
* @description generator rollup bundle config for input and output
*/ const generatorRollupConfig = (originalConfig)=>{
var ref, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11;
const { source , format , config , plugins } = originalConfig;
const fileNameRule = '[name].[format][min][ext]';
const fileName = ((ref = config.output) === null || ref === void 0 ? void 0 : ref.file) || fileNameRule;
let fileNameTemplate = typeof fileName === 'function' ? fileName({
format,
minify: Boolean((ref4 = config.output) === null || ref4 === void 0 ? void 0 : ref4.minifiy)
}, fileNameRule) : fileName;
fileNameTemplate = fileNameTemplate.replace(/\[min\]/, ((ref5 = config.output) === null || ref5 === void 0 ? void 0 : ref5.minifiy) ? '.min' : '').replace(/\[ext\]/, '.js').replace(/\[format\]/, format);
return {
inputConfig: {
input: source,
plugins,
external: config.external
},
outputConfig: {
format,
exports: (ref6 = config.output) === null || ref6 === void 0 ? void 0 : ref6.exports,
entryFileNames: fileNameTemplate,
dir: (ref7 = config.output) === null || ref7 === void 0 ? void 0 : ref7.dir,
sourcemap: (ref8 = config.output) === null || ref8 === void 0 ? void 0 : ref8.sourceMap,
globals: config.global,
name: (ref9 = config.output) === null || ref9 === void 0 ? void 0 : ref9.name,
preserveModules: (ref10 = config.output) === null || ref10 === void 0 ? void 0 : ref10.preserveModules,
preserveModulesRoot: (ref11 = config.output) === null || ref11 === void 0 ? void 0 : ref11.preserveModulesRoot
}
};
};
// For future we will support inline config from stdin

@@ -396,0 +15,0 @@ const resolveConfig = async ()=>{

@@ -5,416 +5,18 @@ 'use strict';

var rollup = require('rollup');
var fs = require('fs');
var path = require('path');
var merge = require('lodash.merge');
var alias = require('@rollup/plugin-alias');
var define$1 = require('@rollup/plugin-replace');
var rollupPluginSwc3 = require('rollup-plugin-swc3');
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
var commonjs = require('@rollup/plugin-commonjs');
var postcss = require('rollup-plugin-postcss');
var apiImpl = require('./api-impl-9b70bf1a.js');
require('rollup');
require('fs');
require('path');
require('lodash.merge');
require('@rollup/plugin-alias');
require('@rollup/plugin-replace');
require('rollup-plugin-swc3');
require('@rollup/plugin-node-resolve');
require('@rollup/plugin-commonjs');
require('rollup-plugin-postcss');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
var alias__default = /*#__PURE__*/_interopDefaultLegacy(alias);
var define__default = /*#__PURE__*/_interopDefaultLegacy(define$1);
var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
var postcss__default = /*#__PURE__*/_interopDefaultLegacy(postcss);
var _object_spread = {};
var _define_property = {};
Object.defineProperty(_define_property, "__esModule", {
value: true
});
_define_property.default = _defineProperty$1;
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;
}
Object.defineProperty(_object_spread, "__esModule", {
value: true
});
var _default$1 = _object_spread.default = _objectSpread;
var _defineProperty = _interopRequireDefault(_define_property);
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).default(target, key, source[key]);
});
}
return target;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
var _object_spread_props = {};
Object.defineProperty(_object_spread_props, "__esModule", {
value: true
});
var _default = _object_spread_props.default = _objectSpreadProps;
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 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;
}
/**
* @default 'src/index.js'
* @description preset lib entry
*/ const universalInput = 'src/index.js';
/**
*@default ['cjs','esm']
@description preset generator formats
*/ const universalOutput = {
dir: 'dist',
sourceMap: true,
extractCss: true,
minifiy: false,
preserveModules: false,
extractHelpers: true,
exports: 'auto'
};
const PRESET_FORMAT = [
'cjs',
'esm'
];
const serialize = (source)=>Object.values(source);
const BASIC_TYPES = {
Null: 'Null',
Undefined: 'Undefined',
String: 'String',
Number: 'Number',
Boolean: 'Boolean',
Array: 'Array',
Date: 'Date',
Function: 'Function',
RegExp: 'RegExp',
Object: 'Object'
};
const getUniversalType = (tar)=>Object.prototype.toString.call(tar).slice(8, -1);
const isPlainObject = (tar)=>getUniversalType(tar) === BASIC_TYPES.Object;
const omit = (source, picks)=>Object.keys(source).reduce((acc, cur)=>picks.includes(cur) ? acc : Object.assign(acc, {
[cur]: source[cur]
}), {});
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)];
}
};
const len = (tar)=>tar.length;
const readJson = (path)=>fs__default["default"].promises.readFile(path, 'utf-8').then((r)=>JSON.parse(r)).catch((e)=>e);
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
};
return error(err);
};
const parserPlugins = (options = {})=>{
var ref;
const { userPlugins , internalPluginsOptions , options: userOptions } = options;
const internalPlugins = withIntenralPlugins(internalPluginsOptions, userOptions);
const plugins = serializePlugin(internalPlugins, userPlugins);
const getAliasPattern = (pattern)=>{
if (!pattern) return [];
if (Array.isArray(pattern)) return pattern;
return Object.entries(pattern).map(([find, replacement])=>({
['find']: find,
['replacement']: replacement
}));
};
/**
* Alias first
* then user plugins
* then internal plugins
* then minifiy
*/ if (userOptions === null || userOptions === void 0 ? void 0 : userOptions.minifiy) {
plugins.push(rollupPluginSwc3.minify({
sourceMap: userOptions === null || userOptions === void 0 ? void 0 : userOptions.sourceMap
}));
}
plugins.unshift(alias__default["default"]({
entries: getAliasPattern(userOptions === null || userOptions === void 0 ? void 0 : (ref = userOptions.resolve) === null || ref === void 0 ? void 0 : ref.alias)
}));
return plugins;
};
const withIntenralPlugins = (internalPluginOtions, options)=>{
var ref;
const internalPlugins = {
commonjs: commonjs__default["default"](merge__default["default"]({
esmExternals: true
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.commonjs)),
define: define__default["default"](options === null || options === void 0 ? void 0 : (ref = options.resolve) === null || ref === void 0 ? void 0 : ref.define),
nodeResolve: pluginNodeResolve.nodeResolve(internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.nodeResolve),
swc: rollupPluginSwc3.swc(rollupPluginSwc3.defineRollupSwcOption(merge__default["default"]({
sourceMaps: options === null || options === void 0 ? void 0 : options.sourceMap,
jsc: {
transform: {
react: options === null || options === void 0 ? void 0 : options.jsx
},
externalHelpers: options === null || options === void 0 ? void 0 : options.extractHelpers
}
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.swc))),
postcss: postcss__default["default"](merge__default["default"]({
extract: options === null || options === void 0 ? void 0 : options.extractCss
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.postcss))
};
return internalPlugins;
};
const serializePlugin = (plugins, userPlugins)=>{
if (!userPlugins || !len(Object.keys(userPlugins))) return serialize(plugins);
const merged = Object.assign({}, userPlugins, plugins);
return serialize(merged);
};
/**
*@description dine bump config.
*/ const define = (options)=>options;
/**
*@description create a bundle configuration exports watch and build api
* Example:
* plugins: `Record<string,RollupPlugin>`
*/ const createBundle = (options)=>{
return {
build (conf) {
return buildImpl(merge__default["default"](conf, options), {
watch: false
});
},
watch (conf) {
return buildImpl(merge__default["default"](conf, options), {
watch: true
});
}
};
};
const build = (options)=>buildImpl(options);
const defaultExternal = async ()=>{
const tar = path__default["default"].join(process.cwd(), 'package.json');
const { dependencies , peerDependencies } = await readJson(tar);
return Object.keys(_default$1({}, dependencies, peerDependencies));
};
const buildImpl = async (options, extraOptions)=>{
var ref, ref1, ref2;
const external = await defaultExternal();
let optionImpl = {
input: universalInput,
output: universalOutput,
external
};
if (options) {
if (!isPlainObject(options)) throw throwInvalidateError('[Bump]: please set an object config');
optionImpl = parserOptions(optionImpl, options);
}
const format = (ref = optionImpl.output) === null || ref === void 0 ? void 0 : ref.format;
if (!format || Array.isArray(format) && !len(format)) {
optionImpl.output = _default(_default$1({}, optionImpl.output), {
format: PRESET_FORMAT
});
}
/**
* Because dts plugin will overwrites the out. so we
* only change value of dts to judge we should or not
* load the dts module plugin.
*/ if ((ref1 = optionImpl.output) === null || ref1 === void 0 ? void 0 : ref1.dts) {
if (!loadModule('typescript')) {
optionImpl.output.dts = false;
print.log('[Bump]: If you want to generate declaration file you should insatll typescript in your project and write with typescript :)');
}
}
var ref3;
const plugins = parserPlugins({
userPlugins: optionImpl === null || optionImpl === void 0 ? void 0 : optionImpl.plugins,
internalPluginsOptions: (ref3 = (ref2 = optionImpl.internalOptions) === null || ref2 === void 0 ? void 0 : ref2.plugins) !== null && ref3 !== void 0 ? ref3 : optionImpl.internalPlugins,
options: merge__default["default"]({}, optionImpl.output, {
resolve: optionImpl.resolve
})
});
try {
await runImpl(optionImpl, plugins, extraOptions);
} catch (error) {
throw error;
}
};
/**
* @description runImp is use for buildImpl .for future version i plan to add watch
* API so needs to realized.
*/ const runImpl = async (optionImpl, plugins, extraOptions)=>{
var ref;
let { input } = optionImpl;
if (!Array.isArray(input) && !isPlainObject(input)) input = [
input || universalInput
];
if (isPlainObject(input)) input = serialize(input);
if (!(input === null || input === void 0 ? void 0 : input.length)) input = [
universalInput
];
const formats = optionImpl.output.format;
/**
* Input parseing rules.
* We should translate user input as array. when user define a object array. we think it's mulitple
* tasks mulit-entry.
*/ const inputs = input;
const tasks = [];
for (const source of inputs){
for (const format of formats){
tasks.push({
getConfig () {
const rollupConfig = generatorRollupConfig({
source,
format,
config: optionImpl,
plugins
});
return rollupConfig;
}
});
}
}
if (((ref = optionImpl.output) === null || ref === void 0 ? void 0 : ref.dts) && !extraOptions) {
const dts = ()=>{
const canload = loadModule('rollup-plugin-dts');
if (canload) return [
canload()
];
return [];
};
// I should get all entryFileNames as input chunk.
await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
const bundle = await rollup.rollup(_default(_default$1({}, inputConfig), {
plugins: dts()
}));
await bundle.write(omit(outputConfig, [
'entryFileNames'
]));
}));
}
if (extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.watch) {
const configs = await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
return _default(_default$1({}, inputConfig), {
output: outputConfig,
watch: {}
});
}));
const watcher = rollup.watch(configs);
watcher.on('event', (e)=>{
if (e.code === 'ERROR') {
print.danger(e.error.message);
}
});
} else {
await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
const bundle = await rollup.rollup(inputConfig);
await bundle.write(outputConfig);
}));
}
};
/**
*@description Parser user options and preset options
*/ const parserOptions = (defaultOptions, userOptions)=>{
if (!Object.keys(userOptions)) return defaultOptions;
const options = Object.assign({}, defaultOptions, userOptions, {
output: merge__default["default"]({}, defaultOptions.output, userOptions.output)
});
return options;
};
/**
* @description generator rollup bundle config for input and output
*/ const generatorRollupConfig = (originalConfig)=>{
var ref, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11;
const { source , format , config , plugins } = originalConfig;
const fileNameRule = '[name].[format][min][ext]';
const fileName = ((ref = config.output) === null || ref === void 0 ? void 0 : ref.file) || fileNameRule;
let fileNameTemplate = typeof fileName === 'function' ? fileName({
format,
minify: Boolean((ref4 = config.output) === null || ref4 === void 0 ? void 0 : ref4.minifiy)
}, fileNameRule) : fileName;
fileNameTemplate = fileNameTemplate.replace(/\[min\]/, ((ref5 = config.output) === null || ref5 === void 0 ? void 0 : ref5.minifiy) ? '.min' : '').replace(/\[ext\]/, '.js').replace(/\[format\]/, format);
return {
inputConfig: {
input: source,
plugins,
external: config.external
},
outputConfig: {
format,
exports: (ref6 = config.output) === null || ref6 === void 0 ? void 0 : ref6.exports,
entryFileNames: fileNameTemplate,
dir: (ref7 = config.output) === null || ref7 === void 0 ? void 0 : ref7.dir,
sourcemap: (ref8 = config.output) === null || ref8 === void 0 ? void 0 : ref8.sourceMap,
globals: config.global,
name: (ref9 = config.output) === null || ref9 === void 0 ? void 0 : ref9.name,
preserveModules: (ref10 = config.output) === null || ref10 === void 0 ? void 0 : ref10.preserveModules,
preserveModulesRoot: (ref11 = config.output) === null || ref11 === void 0 ? void 0 : ref11.preserveModulesRoot
}
};
};
exports.build = build;
exports.createBundle = createBundle;
exports.define = define;
exports.build = apiImpl.build;
exports.createBundle = apiImpl.createBundle;
exports.define = apiImpl.define;

@@ -95,6 +95,6 @@ import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';

interface BumpInternalPlugins {
commonjs?: RollupCommonJSOptions;
nodeResolve?: RollupNodeResolveOptions;
swc?: PluginOptions;
postcss?: PostCSSPluginConf;
commonjs?: RollupCommonJSOptions | boolean;
nodeResolve?: RollupNodeResolveOptions | boolean;
swc?: PluginOptions | boolean;
postcss?: PostCSSPluginConf | boolean;
}

@@ -101,0 +101,0 @@ interface BumpOptions {

@@ -1,403 +0,11 @@

import { rollup, watch } from 'rollup';
import fs from 'fs';
import path from 'path';
import merge from 'lodash.merge';
import alias from '@rollup/plugin-alias';
import define$1 from '@rollup/plugin-replace';
import { minify, swc, defineRollupSwcOption } from 'rollup-plugin-swc3';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
var _object_spread = {};
var _define_property = {};
Object.defineProperty(_define_property, "__esModule", {
value: true
});
_define_property.default = _defineProperty$1;
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;
}
Object.defineProperty(_object_spread, "__esModule", {
value: true
});
var _default$1 = _object_spread.default = _objectSpread;
var _defineProperty = _interopRequireDefault(_define_property);
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).default(target, key, source[key]);
});
}
return target;
}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
var _object_spread_props = {};
Object.defineProperty(_object_spread_props, "__esModule", {
value: true
});
var _default = _object_spread_props.default = _objectSpreadProps;
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 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;
}
/**
* @default 'src/index.js'
* @description preset lib entry
*/ const universalInput = 'src/index.js';
/**
*@default ['cjs','esm']
@description preset generator formats
*/ const universalOutput = {
dir: 'dist',
sourceMap: true,
extractCss: true,
minifiy: false,
preserveModules: false,
extractHelpers: true,
exports: 'auto'
};
const PRESET_FORMAT = [
'cjs',
'esm'
];
const serialize = (source)=>Object.values(source);
const BASIC_TYPES = {
Null: 'Null',
Undefined: 'Undefined',
String: 'String',
Number: 'Number',
Boolean: 'Boolean',
Array: 'Array',
Date: 'Date',
Function: 'Function',
RegExp: 'RegExp',
Object: 'Object'
};
const getUniversalType = (tar)=>Object.prototype.toString.call(tar).slice(8, -1);
const isPlainObject = (tar)=>getUniversalType(tar) === BASIC_TYPES.Object;
const omit = (source, picks)=>Object.keys(source).reduce((acc, cur)=>picks.includes(cur) ? acc : Object.assign(acc, {
[cur]: source[cur]
}), {});
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)];
}
};
const len = (tar)=>tar.length;
const readJson = (path)=>fs.promises.readFile(path, 'utf-8').then((r)=>JSON.parse(r)).catch((e)=>e);
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
};
return error(err);
};
const parserPlugins = (options = {})=>{
var ref;
const { userPlugins , internalPluginsOptions , options: userOptions } = options;
const internalPlugins = withIntenralPlugins(internalPluginsOptions, userOptions);
const plugins = serializePlugin(internalPlugins, userPlugins);
const getAliasPattern = (pattern)=>{
if (!pattern) return [];
if (Array.isArray(pattern)) return pattern;
return Object.entries(pattern).map(([find, replacement])=>({
['find']: find,
['replacement']: replacement
}));
};
/**
* Alias first
* then user plugins
* then internal plugins
* then minifiy
*/ if (userOptions === null || userOptions === void 0 ? void 0 : userOptions.minifiy) {
plugins.push(minify({
sourceMap: userOptions === null || userOptions === void 0 ? void 0 : userOptions.sourceMap
}));
}
plugins.unshift(alias({
entries: getAliasPattern(userOptions === null || userOptions === void 0 ? void 0 : (ref = userOptions.resolve) === null || ref === void 0 ? void 0 : ref.alias)
}));
return plugins;
};
const withIntenralPlugins = (internalPluginOtions, options)=>{
var ref;
const internalPlugins = {
commonjs: commonjs(merge({
esmExternals: true
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.commonjs)),
define: define$1(options === null || options === void 0 ? void 0 : (ref = options.resolve) === null || ref === void 0 ? void 0 : ref.define),
nodeResolve: nodeResolve(internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.nodeResolve),
swc: swc(defineRollupSwcOption(merge({
sourceMaps: options === null || options === void 0 ? void 0 : options.sourceMap,
jsc: {
transform: {
react: options === null || options === void 0 ? void 0 : options.jsx
},
externalHelpers: options === null || options === void 0 ? void 0 : options.extractHelpers
}
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.swc))),
postcss: postcss(merge({
extract: options === null || options === void 0 ? void 0 : options.extractCss
}, internalPluginOtions === null || internalPluginOtions === void 0 ? void 0 : internalPluginOtions.postcss))
};
return internalPlugins;
};
const serializePlugin = (plugins, userPlugins)=>{
if (!userPlugins || !len(Object.keys(userPlugins))) return serialize(plugins);
const merged = Object.assign({}, userPlugins, plugins);
return serialize(merged);
};
/**
*@description dine bump config.
*/ const define = (options)=>options;
/**
*@description create a bundle configuration exports watch and build api
* Example:
* plugins: `Record<string,RollupPlugin>`
*/ const createBundle = (options)=>{
return {
build (conf) {
return buildImpl(merge(conf, options), {
watch: false
});
},
watch (conf) {
return buildImpl(merge(conf, options), {
watch: true
});
}
};
};
const build = (options)=>buildImpl(options);
const defaultExternal = async ()=>{
const tar = path.join(process.cwd(), 'package.json');
const { dependencies , peerDependencies } = await readJson(tar);
return Object.keys(_default$1({}, dependencies, peerDependencies));
};
const buildImpl = async (options, extraOptions)=>{
var ref, ref1, ref2;
const external = await defaultExternal();
let optionImpl = {
input: universalInput,
output: universalOutput,
external
};
if (options) {
if (!isPlainObject(options)) throw throwInvalidateError('[Bump]: please set an object config');
optionImpl = parserOptions(optionImpl, options);
}
const format = (ref = optionImpl.output) === null || ref === void 0 ? void 0 : ref.format;
if (!format || Array.isArray(format) && !len(format)) {
optionImpl.output = _default(_default$1({}, optionImpl.output), {
format: PRESET_FORMAT
});
}
/**
* Because dts plugin will overwrites the out. so we
* only change value of dts to judge we should or not
* load the dts module plugin.
*/ if ((ref1 = optionImpl.output) === null || ref1 === void 0 ? void 0 : ref1.dts) {
if (!loadModule('typescript')) {
optionImpl.output.dts = false;
print.log('[Bump]: If you want to generate declaration file you should insatll typescript in your project and write with typescript :)');
}
}
var ref3;
const plugins = parserPlugins({
userPlugins: optionImpl === null || optionImpl === void 0 ? void 0 : optionImpl.plugins,
internalPluginsOptions: (ref3 = (ref2 = optionImpl.internalOptions) === null || ref2 === void 0 ? void 0 : ref2.plugins) !== null && ref3 !== void 0 ? ref3 : optionImpl.internalPlugins,
options: merge({}, optionImpl.output, {
resolve: optionImpl.resolve
})
});
try {
await runImpl(optionImpl, plugins, extraOptions);
} catch (error) {
throw error;
}
};
/**
* @description runImp is use for buildImpl .for future version i plan to add watch
* API so needs to realized.
*/ const runImpl = async (optionImpl, plugins, extraOptions)=>{
var ref;
let { input } = optionImpl;
if (!Array.isArray(input) && !isPlainObject(input)) input = [
input || universalInput
];
if (isPlainObject(input)) input = serialize(input);
if (!(input === null || input === void 0 ? void 0 : input.length)) input = [
universalInput
];
const formats = optionImpl.output.format;
/**
* Input parseing rules.
* We should translate user input as array. when user define a object array. we think it's mulitple
* tasks mulit-entry.
*/ const inputs = input;
const tasks = [];
for (const source of inputs){
for (const format of formats){
tasks.push({
getConfig () {
const rollupConfig = generatorRollupConfig({
source,
format,
config: optionImpl,
plugins
});
return rollupConfig;
}
});
}
}
if (((ref = optionImpl.output) === null || ref === void 0 ? void 0 : ref.dts) && !extraOptions) {
const dts = ()=>{
const canload = loadModule('rollup-plugin-dts');
if (canload) return [
canload()
];
return [];
};
// I should get all entryFileNames as input chunk.
await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
const bundle = await rollup(_default(_default$1({}, inputConfig), {
plugins: dts()
}));
await bundle.write(omit(outputConfig, [
'entryFileNames'
]));
}));
}
if (extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.watch) {
const configs = await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
return _default(_default$1({}, inputConfig), {
output: outputConfig,
watch: {}
});
}));
const watcher = watch(configs);
watcher.on('event', (e)=>{
if (e.code === 'ERROR') {
print.danger(e.error.message);
}
});
} else {
await Promise.all(tasks.map(async (task)=>{
const { inputConfig , outputConfig } = task.getConfig();
const bundle = await rollup(inputConfig);
await bundle.write(outputConfig);
}));
}
};
/**
*@description Parser user options and preset options
*/ const parserOptions = (defaultOptions, userOptions)=>{
if (!Object.keys(userOptions)) return defaultOptions;
const options = Object.assign({}, defaultOptions, userOptions, {
output: merge({}, defaultOptions.output, userOptions.output)
});
return options;
};
/**
* @description generator rollup bundle config for input and output
*/ const generatorRollupConfig = (originalConfig)=>{
var ref, ref4, ref5, ref6, ref7, ref8, ref9, ref10, ref11;
const { source , format , config , plugins } = originalConfig;
const fileNameRule = '[name].[format][min][ext]';
const fileName = ((ref = config.output) === null || ref === void 0 ? void 0 : ref.file) || fileNameRule;
let fileNameTemplate = typeof fileName === 'function' ? fileName({
format,
minify: Boolean((ref4 = config.output) === null || ref4 === void 0 ? void 0 : ref4.minifiy)
}, fileNameRule) : fileName;
fileNameTemplate = fileNameTemplate.replace(/\[min\]/, ((ref5 = config.output) === null || ref5 === void 0 ? void 0 : ref5.minifiy) ? '.min' : '').replace(/\[ext\]/, '.js').replace(/\[format\]/, format);
return {
inputConfig: {
input: source,
plugins,
external: config.external
},
outputConfig: {
format,
exports: (ref6 = config.output) === null || ref6 === void 0 ? void 0 : ref6.exports,
entryFileNames: fileNameTemplate,
dir: (ref7 = config.output) === null || ref7 === void 0 ? void 0 : ref7.dir,
sourcemap: (ref8 = config.output) === null || ref8 === void 0 ? void 0 : ref8.sourceMap,
globals: config.global,
name: (ref9 = config.output) === null || ref9 === void 0 ? void 0 : ref9.name,
preserveModules: (ref10 = config.output) === null || ref10 === void 0 ? void 0 : ref10.preserveModules,
preserveModulesRoot: (ref11 = config.output) === null || ref11 === void 0 ? void 0 : ref11.preserveModulesRoot
}
};
};
export { build, createBundle, define };
export { b as build, c as createBundle, d as define } from './api-impl-f0675bba.js';
import 'rollup';
import 'fs';
import 'path';
import 'lodash.merge';
import '@rollup/plugin-alias';
import '@rollup/plugin-replace';
import 'rollup-plugin-swc3';
import '@rollup/plugin-node-resolve';
import '@rollup/plugin-commonjs';
import 'rollup-plugin-postcss';
{
"name": "no-bump",
"version": "0.3.0",
"version": "0.3.1",
"description": "A zero config bundler.",

@@ -5,0 +5,0 @@ "main": "lib/index.cjs.js",

@@ -0,0 +0,0 @@ # Bump

Sorry, the diff of this file is not supported yet

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