Socket
Socket
Sign inDemoInstall

bundt

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bundt - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0

115

index.js

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

const { dirname, normalize, resolve } = require('path');
const { white, cyan, dim } = require('kleur');
const { white, red, cyan, dim } = require('kleur');

@@ -16,2 +16,8 @@ const _ = ' ';

function bail(err) {
let msg = (err.message || err || 'Unknown error').replace(/(\r?\n)/g, '$1 ');
console.error(red().bold('bundt ') + msg);
process.exit(1);
}
function size(val=0) {

@@ -30,4 +36,7 @@ if (val < 1e3) return `${val} ${UNITS[0]}`;

function write(file, data, isUMD) {
function write(file, data, isUMD, toDir) {
file = normalize(file);
if (toDir && toDir !== 'default') {
file = normalize(file.replace(dirname(file), toDir));
}
return mkdir(dirname(file)).then(() => {

@@ -52,2 +61,3 @@ let { code } = minify(data, Object.assign({ toplevel:!isUMD }, terser));

msg += `\n • ${bullet('"umd:name"')} – the name of your UMD factory ${dim().italic(`(default: "${pkg.name}")`)}`;
msg += `\n • ${bullet('"modes"')} – a mapping of custom mode names to their entries`;
msg += `\n • ${bullet('"terser"')} – a config object to customize Terser behavior\n`;

@@ -70,3 +80,3 @@ msg += `\n You may use a ${filename('.terserrc')} file to store configuration instead of the ${bullet('"terser"')} key.\n`;

const pkg = existsSync(pkgfile) && require(pkgfile);
if (!pkg) return console.log('Does not exist: %s', pkgfile);
if (!pkg) return bail(`File not found: ${pkgfile}`);

@@ -77,4 +87,5 @@ const argv = process.argv.slice(2);

const isIndex = !argv[0] || /^-/.test(argv[0]);
const entry = resolve(!argv[0] || /^-/.test(argv[0]) ? 'src/index.js' : argv.shift());
if (!existsSync(entry)) return console.error('Does not exist: %s', entry);
if (!existsSync(entry) && !pkg.modes) return bail(`File not found: ${entry}`);

@@ -101,5 +112,2 @@ // We'll actually do something – require deps

const ESM = readFileSync(entry, 'utf8');
const isDefault = /export default/.test(ESM);
const name = pkg['umd:name'] || pkg.name;

@@ -109,46 +117,67 @@ const mount = /(.|-|@)/.test(name) ? `['${name}']` : `.${name}`;

let keys = [];
let CJS = imports(ESM)
.replace(/(^|\s|;)export default/, '$1module.exports =')
.replace(/(^|\s|;)export (const|function|class|let|var) (.+?)(?=(\(|\s|\=))/gi, (_, x, type, name) => {
return keys.push(name) && `${x}${type} ${name}`;
});
if (keys.length > 0) {
keys.sort().forEach(key => {
CJS += `\nexports.${key} = ${key};`;
});
function capitalize(str) {
return str[0].toUpperCase() + str.substring(1);
}
const UMD = isDefault
? `!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global${mount}=factory()}(this,function(){${CJS.replace('module.exports = ', 'return ')}});`
: `!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory(global${mount}={})}(this,function(exports){${CJS}});`
function run(filepath, isMode) {
if (!existsSync(filepath)) return bail(`File not found: ${entry}`);
// Writes
Promise.all([
fields.main && write(fields.main, CJS, isMin),
fields.module && write(fields.module, ESM, isMin),
fields.browser && write(fields.browser, ESM, isMin),
fields.unpkg && write(fields.unpkg, UMD, isMin || 1),
].filter(Boolean)).then(arr => {
let f=8, s=8, g=6, out='';
const keys = [];
const ESM = readFileSync(filepath, 'utf8');
const isDefault = /export default/.test(ESM);
arr.forEach(obj => {
f = Math.max(f, obj.file.length);
s = Math.max(s, obj.size.length);
g = Math.max(g, obj.gzip.length);
});
let CJS = imports(ESM)
.replace(/(^|\s|;)export default/, '$1module.exports =')
.replace(/(^|\s|;)export (const|function|class|let|var) (.+?)(?=(\(|\s|\=))/gi, (_, x, type, name) => {
return keys.push(name) && `${x}${type} ${name}`;
});
f += 4; // spacing
if (keys.length > 0) {
keys.sort().forEach(key => {
CJS += `\nexports.${key} = ${key};`;
});
}
out += th(rpad('Filename', f)) + _.repeat(4) + th(lpad('Filesize', s)) + ' ' + dim().bold().italic(lpad('(gzip)', g));
const UMD = isDefault
? `!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global${mount}=factory()}(this,function(){${CJS.replace('module.exports = ', 'return ')}});`
: `!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory(global${mount}={})}(this,function(exports){${CJS}});`
arr.forEach(obj => {
out += ('\n' + white(rpad(obj.file, f)) + _.repeat(4) + cyan(lpad(obj.size, s)) + ' ' + dim().italic(lpad(obj.gzip, g)));
// Writes
return Promise.all(
[
fields.main && write(fields.main, CJS, isMin, isMode),
fields.module && write(fields.module, ESM, isMin, isMode),
fields.browser && write(fields.browser, ESM, isMin, isMode),
fields.unpkg && write(fields.unpkg, UMD, isMin || 1, isMode),
].filter(Boolean)
).then(arr => {
let label = capitalize(isMode || 'filename');
let f=label.length, s=8, g=6, out='';
arr.forEach(obj => {
f = Math.max(f, obj.file.length);
s = Math.max(s, obj.size.length);
g = Math.max(g, obj.gzip.length);
});
f += 4; // spacing
out += th(rpad(label, f)) + _.repeat(4) + th(lpad('Filesize', s)) + ' ' + dim().bold().italic(lpad('(gzip)', g));
arr.forEach(obj => {
out += ('\n' + white(rpad(obj.file, f)) + _.repeat(4) + cyan(lpad(obj.size, s)) + ' ' + dim().italic(lpad(obj.gzip, g)));
});
console.log('\n' + out + '\n');
});
}
console.log('\n' + out + '\n');
}).catch(err => {
console.error(err);
process.exit(1);
});
if (pkg.modes && isIndex) {
Promise.all(
Object.keys(pkg.modes).map(k => {
return run(pkg.modes[k], k);
})
).catch(bail);
} else {
run(entry).catch(bail);
}
{
"name": "bundt",
"version": "0.4.0",
"version": "1.0.0",
"repository": "lukeed/bundt",
"description": "WIP",
"description": "A simple bundler for your delcious modules~!",
"license": "MIT",

@@ -16,3 +16,3 @@ "bin": {

"email": "luke.edwards05@gmail.com",
"url": "lukeed.com"
"url": "https://lukeed.com"
},

@@ -25,3 +25,8 @@ "scripts": {

},
"keywords": [],
"keywords": [
"bundler",
"release",
"library",
"targets"
],
"dependencies": {

@@ -31,5 +36,6 @@ "kleur": "^3.0.1",

"rewrite-imports": "^2.0.0",
"terser": "^3.14.0"
"terser": "^4.6.0"
},
"devDependencies": {
"premove": "^1.0.0",
"tap-spec": "^5.0.0",

@@ -36,0 +42,0 @@ "tape": "^4.9.1"

<div align="center">
<img src="shots/logo.png" alt="bundt" height="120" />
<img src="logo.png" alt="bundt" height="110" />
</div>

@@ -7,9 +7,9 @@

<a href="https://npmjs.org/package/bundt">
<img src="https://badgen.now.sh/npm/v/bundt" alt="version" />
<img src="https://badgen.net/npm/v/bundt" alt="version" />
</a>
<a href="https://travis-ci.org/lukeed/bundt">
<img src="https://badgen.now.sh/travis/lukeed/bundt" alt="travis" />
<a href="https://github.com/lukeed/bundt/actions">
<img src="https://badgen.net/github/status/lukeed/bundt" alt="status" />
</a>
<a href="https://npmjs.org/package/bundt">
<img src="https://badgen.now.sh/npm/dm/bundt" alt="downloads" />
<img src="https://badgen.net/npm/dm/bundt" alt="downloads" />
</a>

@@ -33,3 +33,3 @@ </div>

If you need either of these, using [`microbundle`](https://github.com/developit/microbundle) comes ***highly recommend***~!
If you need either of these, using [`microbundle`](https://github.com/developit/microbundle) comes ***highly recommend***!

@@ -71,2 +71,4 @@ > Seriously, I write wonky ES5 code in a single file...<br>`bundt` only puts a name to the builder script I copy & paste between libraries.<br>You are 99.9999% more likely to do better with `microbundle` and/or to not outgrow it.

* **"modes"** &mdash; a map of "mode" names and their entry files<br>_Your `"default"` mode will use the destinations defined above.<br>All other modes replace `dist` with its name as the new directory._
* **"terser"** &mdash; custom [Terser options](https://github.com/terser-js/terser#minify-options) for minification<br>_Alternatively, you may use a `.terserrc` file~!_

@@ -73,0 +75,0 @@

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