Socket
Socket
Sign inDemoInstall

microbundle

Package Overview
Dependencies
485
Maintainers
4
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.13.3 to 0.14.0

18

CHANGELOG.md
# microbundle
## 0.14.0
### Minor Changes
- [`1b61029`](https://github.com/developit/microbundle/commit/1b6102966440bd7000e0e457f8c0b7eeb7e05593) [#867](https://github.com/developit/microbundle/pull/867) Thanks [@bouchenoiremarc](https://github.com/bouchenoiremarc)! - - Add support for Module Workers with a new `--workers` flag
### Patch Changes
- [`5e93a0e`](https://github.com/developit/microbundle/commit/5e93a0e4cc28ea8f080a08e3a8530b6bfdf25f42) [#853](https://github.com/developit/microbundle/pull/853) Thanks [@developit](https://github.com/developit)! - Fix crash when traversing `"exports"` objects (#852)
* [`96b85da`](https://github.com/developit/microbundle/commit/96b85da1e32b4ffbef9d83387ff399d8b3ee3852) [#887](https://github.com/developit/microbundle/pull/887) Thanks [@developit](https://github.com/developit)! - When using `--target node`, resolve "node" conditional Package Export keys, otherwise resolve "browser" keys.
- [`5d0465b`](https://github.com/developit/microbundle/commit/5d0465b39bccff31673d351fc9d29cb4c470407d) [#875](https://github.com/developit/microbundle/pull/875) Thanks [@dwightjack](https://github.com/dwightjack)! - Preserve terser annotations in compressed bundle
* [`b1a6374`](https://github.com/developit/microbundle/commit/b1a637486234a2ae784ccf0c512321e2d3efef7c) [#858](https://github.com/developit/microbundle/pull/858) Thanks [@bouchenoiremarc](https://github.com/bouchenoiremarc)! - - Allow the minify options `compress` and `mangle` to be set as booleans
- [`2980336`](https://github.com/developit/microbundle/commit/29803364fe54cc1a7a8543d61e694c90b4cdce6a) [#865](https://github.com/developit/microbundle/pull/865) Thanks [@rschristian](https://github.com/rschristian)! - Expands generateTypes flag to support libs with TS entrypoints
## 0.13.3

@@ -4,0 +22,0 @@

39

dist/cli.js

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

var json = require('@rollup/plugin-json');
var OMT = require('@surma/rollup-plugin-off-main-thread');
var gzipSize = require('gzip-size');

@@ -46,2 +47,3 @@ var brotliSize = require('brotli-size');

var json__default = /*#__PURE__*/_interopDefaultLegacy(json);
var OMT__default = /*#__PURE__*/_interopDefaultLegacy(OMT);
var gzipSize__default = /*#__PURE__*/_interopDefaultLegacy(gzipSize);

@@ -427,2 +429,4 @@ var brotliSize__default = /*#__PURE__*/_interopDefaultLegacy(brotliSize);

function normalizeMinifyOptions(minifyOptions) {
// ignore normalization if "mangle" is a boolean:
if (typeof minifyOptions.mangle === 'boolean') return;
const mangle = minifyOptions.mangle || (minifyOptions.mangle = {});

@@ -810,5 +814,8 @@ let properties = mangle.properties; // allow top-level "properties" key to override mangle.properties (including {properties:false}):

function walk(exports) {
function walk(exports, includeDefault) {
if (!exports) return null;
if (typeof exports === 'string') return exports;
return walk(exports['.'] || exports.import || exports.module);
let p = exports['.'] || exports.import || exports.module;
if (!p && includeDefault) p = exports.default;
return walk(p, includeDefault);
}

@@ -840,3 +847,3 @@

mainsByFormat.es = replaceName(pkg.module && !pkg.module.match(/src\//) ? pkg.module : pkg['jsnext:main'] || 'x.esm.js', mainNoExtension);
mainsByFormat.modern = replaceName(pkg.exports && walk(pkg.exports) || pkg.syntax && pkg.syntax.esmodules || pkg.esmodule || 'x.modern.js', mainNoExtension);
mainsByFormat.modern = replaceName(pkg.exports && walk(pkg.exports, pkg.type === 'module') || pkg.syntax && pkg.syntax.esmodules || pkg.esmodule || 'x.modern.js', mainNoExtension);
mainsByFormat.cjs = replaceName(pkg['cjs:main'] || (pkg.type && pkg.type === 'module' ? 'x.cjs' : 'x.js'), mainNoExtension);

@@ -908,2 +915,3 @@ mainsByFormat.umd = replaceName(pkg['umd:main'] || pkg.unpkg || 'x.umd.js', mainNoExtension);

const emitDeclaration = options.generateTypes == null ? !!(pkg.types || pkg.typings) : options.generateTypes;
const useWorkerLoader = options.workers !== false;

@@ -942,3 +950,3 @@ const escapeStringExternals = ext => ext instanceof RegExp ? ext.source : escapeStringRegexp__default['default'](ext);

inputOptions: {
// disable Rollup's cache for the modern build to prevent re-use of legacy transpiled modules:
// disable Rollup's cache for modern builds to prevent re-use of legacy transpiled modules:
cache,

@@ -987,2 +995,3 @@ input: entry,

browser: options.target !== 'node',
exportConditions: [options.target === 'node' ? 'node' : 'browser'],
// defaults + .jsx

@@ -1011,8 +1020,10 @@ extensions: ['.mjs', '.js', '.jsx', '.json', '.node'],

sourceMap: options.sourcemap,
declaration: true,
declaration: options.generateTypes !== false,
allowJs: true,
emitDeclarationOnly: options.generateTypes && !useTypescript,
declarationDir: getDeclarationDir({
options,
pkg
...(options.generateTypes !== false && {
declarationDir: getDeclarationDir({
options,
pkg
})
}),

@@ -1068,3 +1079,3 @@ jsx: 'preserve',

passes: 10
}, minifyOptions.compress || {}),
}, typeof minifyOptions.compress === 'boolean' ? minifyOptions.compress : minifyOptions.compress || {}),
format: {

@@ -1074,3 +1085,3 @@ // By default, Terser wraps function arguments in extra parens to trigger eager parsing.

wrap_func_args: false,
comments: /^\s*([@#]__[A-Z]__\s*$|@cc_on)/,
comments: /^\s*([@#]__[A-Z]+__\s*$|@cc_on)/,
preserve_annotations: true

@@ -1081,3 +1092,3 @@ },

toplevel: modern || format === 'cjs' || format === 'es',
mangle: Object.assign({}, minifyOptions.mangle || {}),
mangle: typeof minifyOptions.mangle === 'boolean' ? minifyOptions.mangle : Object.assign({}, minifyOptions.mangle || {}),
nameCache

@@ -1095,3 +1106,5 @@ }), nameCache && {

}],
}], // NOTE: OMT only works with amd and esm
// Source: https://github.com/surma/rollup-plugin-off-main-thread#config
useWorkerLoader && (format === 'es' || modern) && OMT__default['default'](),
/** @type {import('rollup').Plugin} */

@@ -1184,3 +1197,3 @@ {

let prog = sade__default['default']('microbundle');
prog.version(version).option('--entry, -i', 'Entry module(s)').option('--output, -o', 'Directory to place build files into').option('--format, -f', `Only build specified formats (any of ${DEFAULT_FORMATS} or iife)`, DEFAULT_FORMATS).option('--watch, -w', 'Rebuilds on any change', false).option('--pkg-main', 'Outputs files analog to package.json main entries', true).option('--target', 'Specify your target environment (node or web)', 'web').option('--external', `Specify external dependencies, or 'none'`).option('--globals', `Specify globals dependencies, or 'none'`).example('microbundle --globals react=React,jquery=$').option('--define', 'Replace constants with hard-coded values').example('microbundle --define API_KEY=1234').option('--alias', `Map imports to different modules`).example('microbundle --alias react=preact').option('--compress', 'Compress output using Terser', null).option('--strict', 'Enforce undefined global context and add "use strict"').option('--name', 'Specify name exposed in UMD builds').option('--cwd', 'Use an alternative working directory', '.').option('--sourcemap', 'Generate source map').option('--css', 'Where to output CSS: "inline" or "external"', 'external').option('--css-modules', 'Turns on css-modules for all .css imports. Passing a string will override the scopeName. eg --css-modules="_[hash]"', null).example("microbundle --no-sourcemap # don't generate sourcemaps").option('--raw', 'Show raw byte size', false).option('--jsx', 'A custom JSX pragma like React.createElement (default: h)').option('--tsconfig', 'Specify the path to a custom tsconfig.json').option('--generateTypes', 'Whether or not to generate types , if `types` or `typings` is set in `package.json` then it will default to be `true`').example('microbundle build --tsconfig tsconfig.build.json');
prog.version(version).option('--entry, -i', 'Entry module(s)').option('--output, -o', 'Directory to place build files into').option('--format, -f', `Only build specified formats (any of ${DEFAULT_FORMATS} or iife)`, DEFAULT_FORMATS).option('--watch, -w', 'Rebuilds on any change', false).option('--pkg-main', 'Outputs files analog to package.json main entries', true).option('--target', 'Specify your target environment (node or web)', 'web').option('--external', `Specify external dependencies, or 'none'`).option('--globals', `Specify globals dependencies, or 'none'`).example('microbundle --globals react=React,jquery=$').option('--define', 'Replace constants with hard-coded values').example('microbundle --define API_KEY=1234').option('--alias', `Map imports to different modules`).example('microbundle --alias react=preact').option('--compress', 'Compress output using Terser', null).option('--strict', 'Enforce undefined global context and add "use strict"').option('--name', 'Specify name exposed in UMD builds').option('--cwd', 'Use an alternative working directory', '.').option('--sourcemap', 'Generate source map').option('--css', 'Where to output CSS: "inline" or "external"', 'external').option('--workers', 'Bundle module workers - see https://git.io/J3oSF', false).option('--css-modules', 'Turns on css-modules for all .css imports. Passing a string will override the scopeName. eg --css-modules="_[hash]"', null).example("microbundle --no-sourcemap # don't generate sourcemaps").option('--raw', 'Show raw byte size', false).option('--jsx', 'A custom JSX pragma like React.createElement (default: h)').option('--tsconfig', 'Specify the path to a custom tsconfig.json').option('--generateTypes', 'Whether or not to generate types , if `types` or `typings` is set in `package.json` then it will default to be `true`').example('microbundle build --tsconfig tsconfig.build.json');
prog.command('build [...entries]', '', {

@@ -1187,0 +1200,0 @@ default: true

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

var json = require('@rollup/plugin-json');
var OMT = require('@surma/rollup-plugin-off-main-thread');
var gzipSize = require('gzip-size');

@@ -45,2 +46,3 @@ var brotliSize = require('brotli-size');

var json__default = /*#__PURE__*/_interopDefaultLegacy(json);
var OMT__default = /*#__PURE__*/_interopDefaultLegacy(OMT);
var gzipSize__default = /*#__PURE__*/_interopDefaultLegacy(gzipSize);

@@ -425,2 +427,4 @@ var brotliSize__default = /*#__PURE__*/_interopDefaultLegacy(brotliSize);

function normalizeMinifyOptions(minifyOptions) {
// ignore normalization if "mangle" is a boolean:
if (typeof minifyOptions.mangle === 'boolean') return;
const mangle = minifyOptions.mangle || (minifyOptions.mangle = {});

@@ -808,5 +812,8 @@ let properties = mangle.properties; // allow top-level "properties" key to override mangle.properties (including {properties:false}):

function walk(exports) {
function walk(exports, includeDefault) {
if (!exports) return null;
if (typeof exports === 'string') return exports;
return walk(exports['.'] || exports.import || exports.module);
let p = exports['.'] || exports.import || exports.module;
if (!p && includeDefault) p = exports.default;
return walk(p, includeDefault);
}

@@ -838,3 +845,3 @@

mainsByFormat.es = replaceName(pkg.module && !pkg.module.match(/src\//) ? pkg.module : pkg['jsnext:main'] || 'x.esm.js', mainNoExtension);
mainsByFormat.modern = replaceName(pkg.exports && walk(pkg.exports) || pkg.syntax && pkg.syntax.esmodules || pkg.esmodule || 'x.modern.js', mainNoExtension);
mainsByFormat.modern = replaceName(pkg.exports && walk(pkg.exports, pkg.type === 'module') || pkg.syntax && pkg.syntax.esmodules || pkg.esmodule || 'x.modern.js', mainNoExtension);
mainsByFormat.cjs = replaceName(pkg['cjs:main'] || (pkg.type && pkg.type === 'module' ? 'x.cjs' : 'x.js'), mainNoExtension);

@@ -906,2 +913,3 @@ mainsByFormat.umd = replaceName(pkg['umd:main'] || pkg.unpkg || 'x.umd.js', mainNoExtension);

const emitDeclaration = options.generateTypes == null ? !!(pkg.types || pkg.typings) : options.generateTypes;
const useWorkerLoader = options.workers !== false;

@@ -940,3 +948,3 @@ const escapeStringExternals = ext => ext instanceof RegExp ? ext.source : escapeStringRegexp__default['default'](ext);

inputOptions: {
// disable Rollup's cache for the modern build to prevent re-use of legacy transpiled modules:
// disable Rollup's cache for modern builds to prevent re-use of legacy transpiled modules:
cache,

@@ -985,2 +993,3 @@ input: entry,

browser: options.target !== 'node',
exportConditions: [options.target === 'node' ? 'node' : 'browser'],
// defaults + .jsx

@@ -1009,8 +1018,10 @@ extensions: ['.mjs', '.js', '.jsx', '.json', '.node'],

sourceMap: options.sourcemap,
declaration: true,
declaration: options.generateTypes !== false,
allowJs: true,
emitDeclarationOnly: options.generateTypes && !useTypescript,
declarationDir: getDeclarationDir({
options,
pkg
...(options.generateTypes !== false && {
declarationDir: getDeclarationDir({
options,
pkg
})
}),

@@ -1066,3 +1077,3 @@ jsx: 'preserve',

passes: 10
}, minifyOptions.compress || {}),
}, typeof minifyOptions.compress === 'boolean' ? minifyOptions.compress : minifyOptions.compress || {}),
format: {

@@ -1072,3 +1083,3 @@ // By default, Terser wraps function arguments in extra parens to trigger eager parsing.

wrap_func_args: false,
comments: /^\s*([@#]__[A-Z]__\s*$|@cc_on)/,
comments: /^\s*([@#]__[A-Z]+__\s*$|@cc_on)/,
preserve_annotations: true

@@ -1079,3 +1090,3 @@ },

toplevel: modern || format === 'cjs' || format === 'es',
mangle: Object.assign({}, minifyOptions.mangle || {}),
mangle: typeof minifyOptions.mangle === 'boolean' ? minifyOptions.mangle : Object.assign({}, minifyOptions.mangle || {}),
nameCache

@@ -1093,3 +1104,5 @@ }), nameCache && {

}],
}], // NOTE: OMT only works with amd and esm
// Source: https://github.com/surma/rollup-plugin-off-main-thread#config
useWorkerLoader && (format === 'es' || modern) && OMT__default['default'](),
/** @type {import('rollup').Plugin} */

@@ -1096,0 +1109,0 @@ {

{
"name": "microbundle",
"version": "0.13.3",
"version": "0.14.0",
"description": "Zero-configuration bundler for tiny JS libs, powered by Rollup.",

@@ -91,2 +91,3 @@ "main": "dist/microbundle.js",

"@rollup/plugin-node-resolve": "^11.0.1",
"@surma/rollup-plugin-off-main-thread": "^2.2.2",
"asyncro": "^3.0.0",

@@ -93,0 +94,0 @@ "autoprefixer": "^10.1.0",

@@ -136,3 +136,3 @@ <p align="center">

"./lite": "./dist/lite.modern.js", // import "foo/lite"
"./full": "./dist/full.modern.js" // import "foo"
"./full": "./dist/full.modern.js" // import "foo/full"
},

@@ -227,2 +227,4 @@ "scripts": {

To ensure Microbundle does not process extraneous files, by default it only includes your entry point. If you want to include other files for compilation, such as ambient declarations, make sure to add either "[files](https://www.typescriptlang.org/tsconfig#files)" or "[include](https://www.typescriptlang.org/tsconfig#include)" into your `tsconfig.json`.
If you're using TypeScript with CSS Modules, you will want to set `"include": ["node_modules/microbundle/index.d.ts"]` in your `tsconfig.json` to tell TypeScript how to handle your CSS Module imports.

@@ -258,2 +260,22 @@

### Building Module Workers
Microbundle is able to detect and bundle Module Workers when generating bundles in the
`es`, `umd` and `modern` formats. To use this feature, instantiate your Web Worker as follows:
```js
worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
// or simply:
worker = new Worker('./worker.js', { type: 'module' });
```
... then add the `--workers` flag to your build command:
```bash
microbundle --workers
```
For more information see
[@surma/rollup-plugin-off-main-thread](https://github.com/surma/rollup-plugin-off-main-thread#config).
### Mangling Properties

@@ -322,2 +344,3 @@

--css-modules Configures .css to be treated as modules (default: null)
--workers Bundle module workers - see https://git.io/J3oSF (default false)
-h, --help Displays this message

@@ -324,0 +347,0 @@

@@ -21,2 +21,3 @@ import fs from 'fs';

import json from '@rollup/plugin-json';
import OMT from '@surma/rollup-plugin-off-main-thread';
import logError from './log-error';

@@ -263,5 +264,8 @@ import { isDir, isFile, stdout, isTruthy, removeScope } from './utils';

function walk(exports) {
function walk(exports, includeDefault) {
if (!exports) return null;
if (typeof exports === 'string') return exports;
return walk(exports['.'] || exports.import || exports.module);
let p = exports['.'] || exports.import || exports.module;
if (!p && includeDefault) p = exports.default;
return walk(p, includeDefault);
}

@@ -300,3 +304,3 @@

mainsByFormat.modern = replaceName(
(pkg.exports && walk(pkg.exports)) ||
(pkg.exports && walk(pkg.exports, pkg.type === 'module')) ||
(pkg.syntax && pkg.syntax.esmodules) ||

@@ -395,2 +399,4 @@ pkg.esmodule ||

: options.generateTypes;
const useWorkerLoader = options.workers !== false;
const escapeStringExternals = ext =>

@@ -434,3 +440,3 @@ ext instanceof RegExp ? ext.source : escapeStringRegexp(ext);

inputOptions: {
// disable Rollup's cache for the modern build to prevent re-use of legacy transpiled modules:
// disable Rollup's cache for modern builds to prevent re-use of legacy transpiled modules:
cache,

@@ -495,2 +501,3 @@ input: entry,

browser: options.target !== 'node',
exportConditions: [options.target === 'node' ? 'node' : 'browser'],
// defaults + .jsx

@@ -527,6 +534,8 @@ extensions: ['.mjs', '.js', '.jsx', '.json', '.node'],

sourceMap: options.sourcemap,
declaration: true,
declaration: options.generateTypes !== false,
allowJs: true,
emitDeclarationOnly: options.generateTypes && !useTypescript,
declarationDir: getDeclarationDir({ options, pkg }),
...(options.generateTypes !== false && {
declarationDir: getDeclarationDir({ options, pkg }),
}),
jsx: 'preserve',

@@ -591,3 +600,5 @@ jsxFactory:

},
minifyOptions.compress || {},
typeof minifyOptions.compress === 'boolean'
? minifyOptions.compress
: minifyOptions.compress || {},
),

@@ -598,3 +609,3 @@ format: {

wrap_func_args: false,
comments: /^\s*([@#]__[A-Z]__\s*$|@cc_on)/,
comments: /^\s*([@#]__[A-Z]+__\s*$|@cc_on)/,
preserve_annotations: true,

@@ -605,3 +616,6 @@ },

toplevel: modern || format === 'cjs' || format === 'es',
mangle: Object.assign({}, minifyOptions.mangle || {}),
mangle:
typeof minifyOptions.mangle === 'boolean'
? minifyOptions.mangle
: Object.assign({}, minifyOptions.mangle || {}),
nameCache,

@@ -624,2 +638,5 @@ }),

],
// NOTE: OMT only works with amd and esm
// Source: https://github.com/surma/rollup-plugin-off-main-thread#config
useWorkerLoader && (format === 'es' || modern) && OMT(),
/** @type {import('rollup').Plugin} */

@@ -626,0 +643,0 @@ ({

// Normalize Terser options from microbundle's relaxed JSON format (mutates argument in-place)
export function normalizeMinifyOptions(minifyOptions) {
// ignore normalization if "mangle" is a boolean:
if (typeof minifyOptions.mangle === 'boolean') return;
const mangle = minifyOptions.mangle || (minifyOptions.mangle = {});

@@ -4,0 +7,0 @@ let properties = mangle.properties;

@@ -61,2 +61,7 @@ import sade from 'sade';

.option(
'--workers',
'Bundle module workers - see https://git.io/J3oSF',
false,
)
.option(
'--css-modules',

@@ -63,0 +68,0 @@ 'Turns on css-modules for all .css imports. Passing a string will override the scopeName. eg --css-modules="_[hash]"',

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc