From 80d3cb8903c667b264748aaf443d0da990dd7d9f Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 9 Nov 2019 21:26:04 -0600 Subject: [PATCH] fix(build): update rollup config from template --- Makefile | 5 +- config/rollup-external.json | 8 +++ config/rollup-globals.json | 1 + config/rollup-named.json | 37 +++++++++++ config/rollup-stub.json | 3 + config/rollup.js | 122 +++++++++++++++++++----------------- package.json | 2 + yarn.lock | 24 ++++++- 8 files changed, 140 insertions(+), 62 deletions(-) create mode 100644 config/rollup-external.json create mode 100644 config/rollup-globals.json create mode 100644 config/rollup-named.json create mode 100644 config/rollup-stub.json diff --git a/Makefile b/Makefile index f2ba722..fdebe11 100755 --- a/Makefile +++ b/Makefile @@ -10,11 +10,14 @@ export GIT_TAG ?= $(shell git tag -l --points-at HEAD | head -1) export MAKE_PATH ?= $(abspath $(lastword $(MAKEFILE_LIST))) export ROOT_PATH ?= $(dir $(MAKE_PATH)) export CONFIG_PATH ?= $(ROOT_PATH)/config -export DOCS_PATH ?= $(ROOT_PATH)/docs +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) diff --git a/config/rollup-external.json b/config/rollup-external.json new file mode 100644 index 0000000..e149f08 --- /dev/null +++ b/config/rollup-external.json @@ -0,0 +1,8 @@ +{ + "names": [ + "async_hooks", + "chai", + "dtrace-provider", + "sinon" + ] +} diff --git a/config/rollup-globals.json b/config/rollup-globals.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/config/rollup-globals.json @@ -0,0 +1 @@ +{} diff --git a/config/rollup-named.json b/config/rollup-named.json new file mode 100644 index 0000000..d8d362d --- /dev/null +++ b/config/rollup-named.json @@ -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" + ] +} \ No newline at end of file diff --git a/config/rollup-stub.json b/config/rollup-stub.json new file mode 100644 index 0000000..782e0e2 --- /dev/null +++ b/config/rollup-stub.json @@ -0,0 +1,3 @@ +{ + "names": [] +} diff --git a/config/rollup.js b/config/rollup.js index 30ee6af..3fbd6ae 100644 --- a/config/rollup.js +++ b/config/rollup.js @@ -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', + typescript({ + cacheRoot: join(targetPath, 'cache', 'rts2'), rollupCommonJSResolveHack: true, }), ], @@ -115,4 +119,4 @@ const bundle = { export default [ bundle, -]; \ No newline at end of file +]; diff --git a/package.json b/package.json index eefba0b..ccb0510 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 51968ae..433fc75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"