Skip to content

Commit

Permalink
feat(build): bundle as ES module
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removes the umd module in favor of a smaller, standard
ES module. Consumers will need native support for ES modules (recent
evergreen browsers) or a bundler with the same (rollup, webpack, etc).
  • Loading branch information
ssube committed Jun 29, 2020
1 parent 9d5be03 commit 040fecc
Show file tree
Hide file tree
Showing 74 changed files with 899 additions and 174 deletions.
5 changes: 4 additions & 1 deletion Makefile
Expand Up @@ -109,7 +109,10 @@ test: ## run mocha unit tests
test: test-cover

test-check: ## run mocha unit tests with coverage reports
$(NODE_BIN)/nyc $(COVER_OPTS) $(NODE_BIN)/mocha $(MOCHA_OPTS) $(TARGET_PATH)/test.js
$(NODE_BIN)/nyc $(COVER_OPTS) \
$(NODE_BIN)/mocha $(MOCHA_OPTS) \
--require esm \
$(TARGET_PATH)/test.js

test-cover: ## run mocha unit tests with coverage reports
test-cover: test-check
Expand Down
56 changes: 29 additions & 27 deletions config/rollup.js
Expand Up @@ -3,22 +3,20 @@ import commonjs from 'rollup-plugin-commonjs';
import { eslint } from 'rollup-plugin-eslint';
import json from 'rollup-plugin-json';
import multiEntry from 'rollup-plugin-multi-entry';
import externals from 'rollup-plugin-node-externals';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import typescript from 'rollup-plugin-typescript2';
import visualizer from 'rollup-plugin-visualizer';
import yaml from 'rollup-plugin-yaml';

const debug = process.env['DEBUG'] === 'TRUE';
const flag_debug = process.env['DEBUG'] === 'TRUE';

const metadata = require('../package.json');

const external = require('./rollup-external.json').names;
const globals = require('./rollup-globals.json');
const namedExports = require('./rollup-named.json');
const stubNames = require('./rollup-stub.json').names;

const passStub = 'require("pass-stub")';
const stubs = stubNames.reduce((p, c) => (p[c] = passStub, p), {});

const rootPath = process.env['ROOT_PATH'];
const targetPath = process.env['TARGET_PATH'];
Expand All @@ -41,6 +39,14 @@ const bundle = {
return 'vendor';
}

if (id.match(/node-resolve:/)) {
return 'vendor';
}

/* if (id.includes(`chai`) || id.includes(`sinon`)) {
return 'test';
} */

if (id.includes(`${sep}node_modules${sep}`)) {
return 'vendor';
}
Expand All @@ -49,12 +55,16 @@ const bundle = {
return 'index';
}

if (id.includes(`${sep}src${sep}`)) {
if (id.includes(`${sep}src${sep}`) || id.includes(`${sep}rules${sep}`)) {
return 'main';
}

if (debug) {
console.log('file belongs to no chunk', id);
if (flag_debug) {
console.log('file does not belong to any chunk:', id);
}

if (id.length === 30 && id.match(/^[a-f0-9]+$/)) {
return 'vendor';
}

return 'nochunk';
Expand All @@ -63,28 +73,13 @@ const bundle = {
dir: targetPath,
chunkFileNames: '[name].js',
entryFileNames: 'entry-[name].js',
format: 'cjs',
globals,
format: 'module',
sourcemap: true,
},
plugins: [
multiEntry(),
json(),
yaml(),
externals({
builtins: true,
deps: true,
devDeps: false,
peerDeps: false,
}),
replace({
delimiters: ['require("', '")'],
values: stubs,
}),
replace({
delimiters: ['require(\'', '\')'],
values: stubs,
}),
replace({
delimiters: ['{{ ', ' }}'],
values: {
Expand All @@ -103,6 +98,7 @@ const bundle = {
commonjs({
namedExports,
}),
globals(),
eslint({
configFile: join('.', 'config', 'eslint.json'),
exclude: [
Expand All @@ -112,14 +108,20 @@ const bundle = {
join('src', '**', '*.yml'),
],
include: [
join('**', '*.ts'),
join('src', '**', '*.ts'),
join('test', '**', '*.ts'),
],
throwOnError: true,
useEslintrc: false,
}),
typescript({
cacheRoot: join(targetPath, 'cache', 'rts2'),
rollupCommonJSResolveHack: true,
}),
visualizer({
filename: join(rootPath, 'out', 'bundle-graph.html'),
sourcemap: true,
}),
],
};

Expand Down
2 changes: 1 addition & 1 deletion docs/api/js-utils.arraymapper._constructor_.md
Expand Up @@ -16,5 +16,5 @@ constructor(options: ArrayMapperOptions);

| Parameter | Type | Description |
| --- | --- | --- |
| options | <code>ArrayMapperOptions</code> | |
| options | [ArrayMapperOptions](./js-utils.arraymapperoptions.md) | |

4 changes: 2 additions & 2 deletions docs/api/js-utils.arraymapper.map.md
Expand Up @@ -16,9 +16,9 @@ map(input: Array<string>): Map<string, Array<string>>;

| Parameter | Type | Description |
| --- | --- | --- |
| input | <code>Array&lt;string&gt;</code> | |
| input | Array&lt;string&gt; | |

<b>Returns:</b>

`Map<string, Array<string>>`
Map&lt;string, Array&lt;string&gt;&gt;

6 changes: 3 additions & 3 deletions docs/api/js-utils.arraymapper.md
Expand Up @@ -22,9 +22,9 @@ export declare class ArrayMapper

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [rest](./js-utils.arraymapper.rest.md) | | <code>string</code> | |
| [skip](./js-utils.arraymapper.skip.md) | | <code>number</code> | |
| [take](./js-utils.arraymapper.take.md) | | <code>Array&lt;string&gt;</code> | |
| [rest](./js-utils.arraymapper.rest.md) | | string | |
| [skip](./js-utils.arraymapper.skip.md) | | number | |
| [take](./js-utils.arraymapper.take.md) | | Array&lt;string&gt; | |

## Methods

Expand Down
6 changes: 3 additions & 3 deletions docs/api/js-utils.arraymapperoptions.md
Expand Up @@ -14,7 +14,7 @@ export interface ArrayMapperOptions

| Property | Type | Description |
| --- | --- | --- |
| [rest](./js-utils.arraymapperoptions.rest.md) | <code>string</code> | Key for any remaining, unmatched elements. |
| [skip](./js-utils.arraymapperoptions.skip.md) | <code>number</code> | Number of initial elements to skip. |
| [take](./js-utils.arraymapperoptions.take.md) | <code>Array&lt;string&gt;</code> | List of element keys. |
| [rest](./js-utils.arraymapperoptions.rest.md) | string | Key for any remaining, unmatched elements. |
| [skip](./js-utils.arraymapperoptions.skip.md) | number | Number of initial elements to skip. |
| [take](./js-utils.arraymapperoptions.take.md) | Array&lt;string&gt; | List of element keys. |

2 changes: 1 addition & 1 deletion docs/api/js-utils.asynctracker.clear.md
Expand Up @@ -11,5 +11,5 @@ clear(): void;
```
<b>Returns:</b>

`void`
void

2 changes: 1 addition & 1 deletion docs/api/js-utils.asynctracker.disable.md
Expand Up @@ -11,5 +11,5 @@ disable(): void;
```
<b>Returns:</b>

`void`
void

2 changes: 1 addition & 1 deletion docs/api/js-utils.asynctracker.dump.md
Expand Up @@ -13,5 +13,5 @@ dump(): void;
```
<b>Returns:</b>

`void`
void

2 changes: 1 addition & 1 deletion docs/api/js-utils.asynctracker.enable.md
Expand Up @@ -11,5 +11,5 @@ enable(): void;
```
<b>Returns:</b>

`void`
void

2 changes: 1 addition & 1 deletion docs/api/js-utils.asynctracker.getstack.md
Expand Up @@ -13,5 +13,5 @@ getStack(): string;
```
<b>Returns:</b>

`string`
string

4 changes: 2 additions & 2 deletions docs/api/js-utils.asynctracker.md
Expand Up @@ -24,8 +24,8 @@ export declare class AsyncTracker

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [filter](./js-utils.asynctracker.filter.md) | | <code>Optional&lt;StackFilter&gt;</code> | |
| [size](./js-utils.asynctracker.size.md) | | <code>number</code> | |
| [filter](./js-utils.asynctracker.filter.md) | | [Optional](./js-utils.optional.md)<!-- -->&lt;StackFilter&gt; | |
| [size](./js-utils.asynctracker.size.md) | | number | |

## Methods

Expand Down
2 changes: 1 addition & 1 deletion docs/api/js-utils.checklist._constructor_.md
Expand Up @@ -16,5 +16,5 @@ constructor(options: ChecklistOptions<T>);

| Parameter | Type | Description |
| --- | --- | --- |
| options | <code>ChecklistOptions&lt;T&gt;</code> | |
| options | [ChecklistOptions](./js-utils.checklistoptions.md)<!-- -->&lt;T&gt; | |

4 changes: 2 additions & 2 deletions docs/api/js-utils.checklist.check.md
Expand Up @@ -14,9 +14,9 @@ check(value: T): boolean;

| Parameter | Type | Description |
| --- | --- | --- |
| value | <code>T</code> | |
| value | T | |

<b>Returns:</b>

`boolean`
boolean

5 changes: 3 additions & 2 deletions docs/api/js-utils.checklist.md
Expand Up @@ -11,6 +11,7 @@ Check whether items are included or not (blacklist or whitelist, depending on `m
```typescript
export declare class Checklist<T> implements ChecklistOptions<T>
```
<b>Implements:</b> [ChecklistOptions](./js-utils.checklistoptions.md)<!-- -->&lt;T&gt;
## Constructors
Expand All @@ -22,8 +23,8 @@ export declare class Checklist<T> implements ChecklistOptions<T>
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [data](./js-utils.checklist.data.md) | | <code>Array&lt;T&gt;</code> | TODO: switch to Set |
| [mode](./js-utils.checklist.mode.md) | | <code>ChecklistMode</code> | |
| [data](./js-utils.checklist.data.md) | | Array&lt;T&gt; | TODO: switch to Set |
| [mode](./js-utils.checklist.mode.md) | | [ChecklistMode](./js-utils.checklistmode.md) | |
## Methods
Expand Down
4 changes: 2 additions & 2 deletions docs/api/js-utils.checklistoptions.md
Expand Up @@ -14,6 +14,6 @@ export interface ChecklistOptions<T>

| Property | Type | Description |
| --- | --- | --- |
| [data](./js-utils.checklistoptions.data.md) | <code>Array&lt;T&gt;</code> | |
| [mode](./js-utils.checklistoptions.mode.md) | <code>ChecklistMode</code> | |
| [data](./js-utils.checklistoptions.data.md) | Array&lt;T&gt; | |
| [mode](./js-utils.checklistoptions.mode.md) | [ChecklistMode](./js-utils.checklistmode.md) | |

5 changes: 3 additions & 2 deletions docs/api/js-utils.childoptions.md
Expand Up @@ -9,11 +9,12 @@
```typescript
export interface ChildOptions extends ChildProcessOptions
```
<b>Extends:</b> ChildProcessOptions
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [args](./js-utils.childoptions.args.md) | <code>Array&lt;string&gt;</code> | |
| [command](./js-utils.childoptions.command.md) | <code>string</code> | |
| [args](./js-utils.childoptions.args.md) | Array&lt;string&gt; | |
| [command](./js-utils.childoptions.command.md) | string | |
4 changes: 2 additions & 2 deletions docs/api/js-utils.childprocesserror._constructor_.md
Expand Up @@ -16,6 +16,6 @@ constructor(msg?: string, ...nested: Array<Error>);

| Parameter | Type | Description |
| --- | --- | --- |
| msg | <code>string</code> | |
| nested | <code>Array&lt;Error&gt;</code> | |
| msg | string | |
| nested | Array&lt;Error&gt; | |

1 change: 1 addition & 0 deletions docs/api/js-utils.childprocesserror.md
Expand Up @@ -11,6 +11,7 @@ Error indicating that a child process exited with an error status.
```typescript
export declare class ChildProcessError extends BaseError
```
<b>Extends:</b> BaseError
## Constructors
Expand Down
6 changes: 3 additions & 3 deletions docs/api/js-utils.childresult.md
Expand Up @@ -14,7 +14,7 @@ export interface ChildResult

| Property | Type | Description |
| --- | --- | --- |
| [status](./js-utils.childresult.status.md) | <code>number</code> | |
| [stderr](./js-utils.childresult.stderr.md) | <code>string</code> | |
| [stdout](./js-utils.childresult.stdout.md) | <code>string</code> | |
| [status](./js-utils.childresult.status.md) | number | |
| [stderr](./js-utils.childresult.stderr.md) | string | |
| [stdout](./js-utils.childresult.stdout.md) | string | |

4 changes: 2 additions & 2 deletions docs/api/js-utils.concat.md
Expand Up @@ -16,9 +16,9 @@ export declare function concat(chunks: Array<Buffer>): Buffer;

| Parameter | Type | Description |
| --- | --- | --- |
| chunks | <code>Array&lt;Buffer&gt;</code> | |
| chunks | Array&lt;Buffer&gt; | |

<b>Returns:</b>

`Buffer`
Buffer

4 changes: 2 additions & 2 deletions docs/api/js-utils.constructorname.md
Expand Up @@ -16,9 +16,9 @@ export declare function constructorName(val: object): string;

| Parameter | Type | Description |
| --- | --- | --- |
| val | <code>object</code> | |
| val | object | |

<b>Returns:</b>

`string`
string

4 changes: 2 additions & 2 deletions docs/api/js-utils.countof.md
Expand Up @@ -18,9 +18,9 @@ export declare function countOf(val: unknown): number;

| Parameter | Type | Description |
| --- | --- | --- |
| val | <code>unknown</code> | |
| val | unknown | |

<b>Returns:</b>

`number`
number

6 changes: 3 additions & 3 deletions docs/api/js-utils.defaultwhen.md
Expand Up @@ -16,10 +16,10 @@ export declare function defaultWhen<TVal>(condition: boolean, ...items: Array<TV

| Parameter | Type | Description |
| --- | --- | --- |
| condition | <code>boolean</code> | |
| items | <code>Array&lt;TVal&gt;</code> | |
| condition | boolean | |
| items | Array&lt;TVal&gt; | |

<b>Returns:</b>

`TVal`
TVal

6 changes: 3 additions & 3 deletions docs/api/js-utils.defer.md
Expand Up @@ -16,10 +16,10 @@ export declare function defer<T = undefined>(ms: number, val?: T): Promise<T>;

| Parameter | Type | Description |
| --- | --- | --- |
| ms | <code>number</code> | |
| val | <code>T</code> | |
| ms | number | |
| val | T | |

<b>Returns:</b>

`Promise<T>`
Promise&lt;T&gt;

4 changes: 2 additions & 2 deletions docs/api/js-utils.doesexist.md
Expand Up @@ -16,9 +16,9 @@ export declare function doesExist<T>(val: Optional<T>): val is T;

| Parameter | Type | Description |
| --- | --- | --- |
| val | <code>Optional&lt;T&gt;</code> | |
| val | [Optional](./js-utils.optional.md)<!-- -->&lt;T&gt; | |

<b>Returns:</b>

`val is T`
val is T

0 comments on commit 040fecc

Please sign in to comment.