1
0
Fork 0

fix(build): update rollup config from template

This commit is contained in:
ssube 2019-11-09 21:26:04 -06:00 committed by Sean Sube
parent 91fb1aff34
commit 80d3cb8903
8 changed files with 140 additions and 62 deletions

View File

@ -14,7 +14,10 @@ export DOCS_PATH ?= $(ROOT_PATH)/docs
export SCRIPT_PATH ?= $(ROOT_PATH)/scripts
export SOURCE_PATH ?= $(ROOT_PATH)/src
export TARGET_PATH ?= $(ROOT_PATH)/out
export TARGET_LOG ?= $(TARGET_PATH)/make.log
export TARGET_MAIN ?= $(TARGET_PATH)/index.js
export TEST_PATH ?= $(ROOT_PATH)/test
export VENDOR_PATH ?= $(ROOT_PATH)/vendor
# CI
export CI_COMMIT_REF_SLUG ?= $(GIT_BRANCH)

View File

@ -0,0 +1,8 @@
{
"names": [
"async_hooks",
"chai",
"dtrace-provider",
"sinon"
]
}

View File

@ -0,0 +1 @@
{}

37
config/rollup-named.json Normal file
View File

@ -0,0 +1,37 @@
{
"node_modules/chai/index.js": [
"expect",
"use"
],
"node_modules/deep-diff/index.js": [
"applyDiff",
"diff"
],
"node_modules/lodash/lodash.js": [
"cloneDeep",
"defaultTo",
"intersection",
"isNil",
"isString",
"kebabCase"
],
"node_modules/noicejs/out/main-bundle.js": [
"BaseError",
"ConsoleLogger",
"NullLogger",
"logWithLevel"
],
"node_modules/js-yaml/index.js": [
"DEFAULT_SAFE_SCHEMA",
"SAFE_SCHEMA",
"safeDump",
"safeLoad",
"safeLoadAll",
"Schema",
"Type"
],
"node_modules/yargs/index.js": [
"showCompletionScript",
"usage"
]
}

3
config/rollup-stub.json Normal file
View File

@ -0,0 +1,3 @@
{
"names": []
}

View File

@ -1,54 +1,84 @@
import { join, sep } from 'path';
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 resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import typescript from 'rollup-plugin-typescript2';
import yaml from 'rollup-plugin-yaml';
const debug = process.env['DEBUG'] === 'TRUE';
const metadata = require('../package.json');
const shebang = '#! /usr/bin/env node';
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'];
const bundle = {
external: [
'chai',
'dtrace-provider',
],
input: [
'src/index.ts',
'test/harness.ts',
'test/**/Test*.ts',
external,
input: {
include: [
join(rootPath, 'src', 'index.ts'),
join(rootPath, 'test', 'harness.ts'),
join(rootPath, 'test', '**', 'Test*.ts'),
],
},
manualChunks(id) {
if (id.includes('/test/') /* || id.includes('/chai/') */ || id.includes('/sinon/')) {
return 'test'
if (id.includes(`${sep}test${sep}`)) {
return 'test';
}
if (id.includes('/node_modules/')) {
if (id.match(/commonjs-external/i) || id.match(/commonjsHelpers/)) {
return 'vendor';
}
if (id.includes('/src/index')) {
if (id.includes(`${sep}node_modules${sep}`)) {
return 'vendor';
}
if (id.includes(`${sep}src${sep}index`)) {
return 'index';
}
if (id.includes('/src/')) {
if (id.includes(`${sep}src${sep}`)) {
return 'main';
}
},
output: {
dir: 'out/',
dir: targetPath,
chunkFileNames: '[name].js',
entryFileNames: 'entry-[name].js',
format: 'cjs',
globals,
sourcemap: true,
banner: () => {
return shebang + '\n\n';
},
},
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: {
@ -65,49 +95,23 @@ const bundle = {
preferBuiltins: true,
}),
commonjs({
namedExports: {
'node_modules/chai/index.js': [
'expect',
],
'node_modules/deep-diff/index.js': [
'applyDiff',
'diff',
],
'node_modules/lodash/lodash.js': [
'cloneDeep',
'defaultTo',
'intersection',
'isNil',
'isString',
'kebabCase',
],
'node_modules/noicejs/out/main-bundle.js': [
'BaseError',
'ConsoleLogger',
'NullLogger',
'logWithLevel',
],
'node_modules/js-yaml/index.js': [
'DEFAULT_SAFE_SCHEMA',
'SAFE_SCHEMA',
'safeDump',
'safeLoad',
'safeLoadAll',
'Schema',
'Type',
],
'node_modules/yargs/index.js': [
'showCompletionScript',
'usage',
],
},
namedExports,
}),
eslint({
configFile: './config/eslint.json',
configFile: join('.', 'config', 'eslint.json'),
exclude: [
join('node_modules', '**'),
join('src', 'resource'),
join('src', '**', '*.json'),
join('src', '**', '*.yml'),
],
include: [
join('**', '*.ts'),
],
throwOnError: true,
}),
typescript({
cacheRoot: 'out/cache/rts2',
cacheRoot: join(targetPath, 'cache', 'rts2'),
rollupCommonJSResolveHack: true,
}),
],

View File

@ -73,10 +73,12 @@
"rollup-plugin-eslint": "7.0.0",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-multi-entry": "2.1.0",
"rollup-plugin-node-externals": "^2.1.2",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-tslint": "0.2.2",
"rollup-plugin-typescript2": "0.25.2",
"rollup-plugin-yaml": "^2.0.0",
"sinon": "7.5.0",
"sinon-chai": "3.3.0",
"source-map-support": "0.5.16",

View File

@ -2959,7 +2959,7 @@ rollup-plugin-eslint@7.0.0:
eslint "^6.0.0"
rollup-pluginutils "^2.7.1"
rollup-plugin-json@4.0.0:
rollup-plugin-json@4.0.0, rollup-plugin-json@^4.0.0:
version "4.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/rollup-plugin-json/-/rollup-plugin-json-4.0.0.tgz#a18da0a4b30bf5ca1ee76ddb1422afbb84ae2b9e"
integrity sha512-hgb8N7Cgfw5SZAkb3jf0QXii6QX/FOkiIq2M7BAQIEydjHvTyxXHQiIzZaTFgx1GK0cRCHOCBHIyEkkLdWKxow==
@ -2973,6 +2973,11 @@ rollup-plugin-multi-entry@2.1.0:
dependencies:
matched "^1.0.2"
rollup-plugin-node-externals@^2.1.2:
version "2.1.2"
resolved "https://artifacts.apextoaster.com/repository/group-npm/rollup-plugin-node-externals/-/rollup-plugin-node-externals-2.1.2.tgz#13d15abad2a123b614bdd4908097e88753a98e54"
integrity sha512-8YhU16BuONV8aubHx59tYbLFgw/oP+pb4Tzdh2h62OaaBR16Kb0mXEpAmlBs7TNc8xtT0JzGaslUjxBzO03mgw==
rollup-plugin-node-resolve@5.2.0:
version "5.2.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz#730f93d10ed202473b1fb54a5997a7db8c6d8523"
@ -3012,6 +3017,16 @@ rollup-plugin-typescript2@0.25.2:
rollup-pluginutils "2.8.1"
tslib "1.10.0"
rollup-plugin-yaml@^2.0.0:
version "2.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/rollup-plugin-yaml/-/rollup-plugin-yaml-2.0.0.tgz#80a67b59e00f010f5f2a2bb6fa70aad4718f85f8"
integrity sha512-aBfREZIkvKjfwHbcpqVsst0iB2PvsdEpvGNw02N2kQ8rOP7ZClZDpxwylkpcmO9/xgD2uInA/AY3mGursT37zw==
dependencies:
js-yaml "^3.13.1"
rollup-plugin-json "^4.0.0"
rollup-pluginutils "^2.8.2"
tosource "^1.0.0"
rollup-pluginutils@2.8.1:
version "2.8.1"
resolved "https://artifacts.apextoaster.com/repository/group-npm/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz#8fa6dd0697344938ef26c2c09d2488ce9e33ce97"
@ -3019,7 +3034,7 @@ rollup-pluginutils@2.8.1:
dependencies:
estree-walker "^0.6.1"
rollup-pluginutils@^2.0.1, rollup-pluginutils@^2.5.0, rollup-pluginutils@^2.6.0, rollup-pluginutils@^2.7.1, rollup-pluginutils@^2.8.1:
rollup-pluginutils@^2.0.1, rollup-pluginutils@^2.5.0, rollup-pluginutils@^2.6.0, rollup-pluginutils@^2.7.1, rollup-pluginutils@^2.8.1, rollup-pluginutils@^2.8.2:
version "2.8.2"
resolved "https://artifacts.apextoaster.com/repository/group-npm/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e"
integrity sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==
@ -3430,6 +3445,11 @@ to-fast-properties@^2.0.0:
resolved "https://artifacts.apextoaster.com/repository/group-npm/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"
integrity sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=
tosource@^1.0.0:
version "1.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/tosource/-/tosource-1.0.0.tgz#42d88dd116618bcf00d6106dd5446f3427902ff1"
integrity sha1-QtiN0RZhi88A1hBt1URvNCeQL/E=
trim-newlines@^1.0.0:
version "1.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"