1
0
Fork 0

update: rollup template

This commit is contained in:
ssube 2020-09-06 16:51:53 -05:00
parent 665d8b5b68
commit 116bae4980
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
12 changed files with 312 additions and 258 deletions

View File

@ -95,7 +95,7 @@ build: ## builds, bundles, and tests the application
build: build-page build-bundle build-docs
build-bundle: node_modules
$(NODE_BIN)/rollup --config $(CONFIG_PATH)/rollup.js
$(NODE_BIN)/rollup --config $(CONFIG_PATH)/rollup/config.js
sed -i '1s;^;#! /usr/bin/env node\n\n;' $(TARGET_PATH)/index.js
build-docs: ## generate html docs

View File

@ -1 +0,0 @@
{}

View File

@ -1,76 +0,0 @@
{
"node_modules/chai/index.js": [
"expect",
"use"
],
"node_modules/deep-diff/index.js": [
"applyDiff",
"diff"
],
"node_modules/lodash/lodash.js": [
"cloneDeep",
"defaultTo",
"flatten",
"intersection",
"isBoolean",
"isFunction",
"isMap",
"isNil",
"isObject",
"isString",
"kebabCase",
"merge",
"remove"
],
"node_modules/minimatch/minimatch.js": [
"Minimatch"
],
"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"
],
"node_modules/phaser/src/phaser.js": [
"AUTO",
"WEBGL",
"Cameras",
"Game",
"Input",
"Math",
"Renderer",
"Scene"
],
"node_modules/react/index.js": [
"useState",
"useRef",
"useMemo",
"useEffect",
"useCallback",
"useDebugValue",
"memo",
"forwardRef",
"Component",
"PureComponent",
"createElement"
],
"node_modules/react-dom/index.js": [
"unstable_batchedUpdates"
],
"node_modules/seedrandom/index.js": [
"alea"
]
}

View File

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

View File

@ -1,174 +0,0 @@
import { join, sep } from 'path';
import alias from 'rollup-plugin-alias';
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 polyfills from 'rollup-plugin-node-polyfills';
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import serve from 'rollup-plugin-serve';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import visualizer from 'rollup-plugin-visualizer';
import yaml from 'rollup-plugin-yaml';
const flag_debug = process.env['DEBUG'] === 'TRUE';
const flag_serve = process.env['SERVE'] === 'TRUE';
const metadata = require('../package.json');
const external = require('./rollup-external.json').names;
const namedExports = require('./rollup-named.json');
const rootPath = process.env['ROOT_PATH'];
const targetPath = process.env['TARGET_PATH'];
const testModules = [
'chai',
'chai-as-promised',
'sinon',
'sinon-chai',
];
const bundle = {
external,
input: {
include: [
join(rootPath, 'src', 'index.ts'),
join(rootPath, 'test', 'harness.ts'),
join(rootPath, 'test', '**', 'Test*.ts'),
],
},
manualChunks(id) {
if (id.includes(`${sep}test${sep}`)) {
return 'test';
}
if (id.match(/commonjs-external/i) || id.match(/commonjsHelpers/)) {
return 'vendor';
}
if (id.match(/node-resolve:/) || id.match(/virtual:/)) {
return 'vendor';
}
if (testModules.some(mod => id.includes(`${sep}${mod}${sep}`))) {
return 'test';
}
if (id.includes(`node_modules${sep}`)) {
return 'vendor';
}
if (id.includes(`${sep}src${sep}index`)) {
return 'index';
}
if (id.includes(`${sep}src${sep}`) || id.includes(`${sep}rules${sep}`)) {
return 'main';
}
if (id.includes(process.env['HOME'])) {
return 'linked';
}
if (id.length === 30 && id.match(/^[a-f0-9]+$/)) {
return 'vendor';
}
if (flag_debug) {
console.log('file does not belong to any chunk:', id);
}
return 'nochunk';
},
output: {
dir: targetPath,
chunkFileNames: '[name].js',
entryFileNames: 'entry-[name].js',
exports: 'named',
format: 'cjs',
minifyInternalExports: false,
sourcemap: true,
},
plugins: [
multiEntry(),
json(),
yaml(),
replace({
delimiters: ['{{ ', ' }}'],
values: {
BUILD_JOB: process.env['CI_JOB_ID'],
BUILD_RUNNER: process.env['CI_RUNNER_DESCRIPTION'],
GIT_BRANCH: process.env['CI_COMMIT_REF_SLUG'],
GIT_COMMIT: process.env['CI_COMMIT_SHA'],
NODE_VERSION: process.env['NODE_VERSION'],
PACKAGE_NAME: metadata.name,
PACKAGE_VERSION: metadata.version,
},
}),
alias({
resolve: ['.tsx', '.ts'],
entries: {
'@gitbeaker/node': require.resolve('@gitbeaker/node'),
'universal-user-agent': join('.', 'node_modules', 'universal-user-agent', 'dist-node', 'index.js'),
'universal-github-app-jwt': join('.', 'node_modules', 'universal-github-app-jwt', 'dist-node', 'index.js'),
},
}),
resolve({
browser: false,
preferBuiltins: true,
}),
commonjs({
namedExports,
}),
eslint({
configFile: join('.', 'config', 'eslint.json'),
exclude: [
join('node_modules', '**'),
join('src', 'resource'),
join('src', '**', '*.json'),
join('src', '**', '*.yml'),
],
include: [
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,
}),
/*
terser({
keep_classnames: true,
}),
*/
],
};
if (flag_serve) {
bundle.plugins.push(serve({
host: '0.0.0.0',
open: true,
verbose: true,
contentBase: [
join(rootPath, 'out'),
join(rootPath, 'resources'),
],
mimeTypes: {
'application/javascript': ['mjs'],
},
}));
}
export default [
bundle,
];

43
config/rollup/chunks.json Normal file
View File

@ -0,0 +1,43 @@
{
"chunks": [
{
"name": "index",
"includes": [
"/src/index"
],
"match": []
},
{
"name": "test",
"includes": [
"/test/"
],
"match": [
"node_modules/chai",
"node_modules/chai-as-promised",
"node_modules/sinon",
"node_modules/sinon-chai"
]
},
{
"name": "vendor",
"includes": [
"node_modules/"
],
"match": [
"commonjs-external",
"commonjsHelpers",
"node-resolve:",
"virtual:"
]
},
{
"name": "main",
"includes": [
"/src/",
"/rules/"
],
"match": []
}
]
}

111
config/rollup/config.js Normal file
View File

@ -0,0 +1,111 @@
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import multiEntry from '@rollup/plugin-multi-entry';
import resolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import yaml from '@rollup/plugin-yaml';
import { join } from 'path';
import { eslint } from 'rollup-plugin-eslint';
import serve from 'rollup-plugin-serve';
import { terser } from 'rollup-plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import visualizer from 'rollup-plugin-visualizer';
const { chunkMap } = require('./map.js');
const { plugins } = require('./project.js');
const flag_debug = process.env['DEBUG'] === 'TRUE';
const flag_devel = process.env['NODE_ENV'] === 'production';
const flag_serve = flag_devel || process.env['SERVE'] === 'TRUE';
const metadata = require('../../package.json');
const chunks = require('./chunks.json').chunks;
const external = require('./external.json').names;
const rootPath = process.env['ROOT_PATH'];
const targetPath = process.env['TARGET_PATH'];
const bundle = {
external,
input: {
include: [
join(rootPath, 'src', 'index.ts'),
join(rootPath, 'test', 'harness.ts'),
join(rootPath, 'test', '**', 'Test*.ts'),
],
},
manualChunks: chunkMap(chunks, flag_debug),
output: {
dir: targetPath,
chunkFileNames: '[name].js',
entryFileNames: 'entry-[name].js',
exports: 'named',
format: 'cjs',
minifyInternalExports: false,
sourcemap: true,
},
plugins: [
multiEntry(),
json(),
yaml(),
replace({
delimiters: ['{{ ', ' }}'],
values: {
BUILD_JOB: process.env['CI_JOB_ID'],
BUILD_RUNNER: process.env['CI_RUNNER_DESCRIPTION'],
GIT_BRANCH: process.env['CI_COMMIT_REF_SLUG'],
GIT_COMMIT: process.env['CI_COMMIT_SHA'],
NODE_VERSION: process.env['NODE_VERSION'],
PACKAGE_NAME: metadata.name,
PACKAGE_VERSION: metadata.version,
},
}),
...plugins,
resolve({
preferBuiltins: true,
}),
commonjs(),
eslint({
configFile: join('.', 'config', 'eslint.json'),
exclude: [
join('node_modules', '**'),
join('src', 'resource'),
join('src', '**', '*.json'),
join('src', '**', '*.yml'),
],
include: [
join('src', '**', '*.ts'),
join('test', '**', '*.ts'),
],
throwOnError: true,
useEslintrc: false,
}),
typescript({
cacheRoot: join(targetPath, 'cache', 'rts2'),
rollupCommonJSResolveHack: true,
}),
/*terser({
keep_classnames: true,
}),*/
visualizer({
filename: join(rootPath, 'out', 'bundle-graph.html'),
sourcemap: true,
}),
(flag_serve ? serve({
host: '0.0.0.0',
open: true,
verbose: true,
contentBase: [
join(rootPath, 'out'),
join(rootPath, 'resources'),
],
mimeTypes: {
'application/javascript': ['mjs'],
},
}) : undefined),
],
};
export default [
bundle,
];

View File

@ -1,6 +1,7 @@
{
"names": [
"@gitbeaker/node",
"@octokit",
"async_hooks",
"chai",
"dtrace-provider",

45
config/rollup/map.js Normal file
View File

@ -0,0 +1,45 @@
function chunkMap(map, debug = false) {
return function (name) {
for (const def of map) {
const chunk = def.name;
for (const include of def.includes) {
if (name.includes(include)) {
if (debug) {
console.info('chunk includes name', chunk, name);
}
return chunk;
}
}
for (const match of def.match) {
if (name.match(match)) {
if (debug) {
console.info('chunk matches name', chunk, name);
}
return chunk;
}
}
}
if (name.length === 30 && name.match(/^[a-f0-9]+$/)) {
if (debug) {
console.info('generated chunk name', chunk, name);
}
return 'vendor';
}
if (debug) {
console.info('name does not match any chunk', chunk, name);
}
return 'unknown';
}
}
module.exports = {
chunkMap,
};

15
config/rollup/project.js Normal file
View File

@ -0,0 +1,15 @@
const { join } = require('path');
const alias = require('rollup-plugin-alias');
module.exports = {
plugins: [
alias({
resolve: ['.tsx', '.ts'],
entries: {
'@gitbeaker/node': require.resolve('@gitbeaker/node'),
'universal-user-agent': join('.', 'node_modules', 'universal-user-agent', 'dist-node', 'index.js'),
'universal-github-app-jwt': join('.', 'node_modules', 'universal-github-app-jwt', 'dist-node', 'index.js'),
},
}),
],
};

View File

@ -22,6 +22,12 @@
"@microsoft/api-extractor": "7.9.12",
"@octokit/auth-app": "2.4.15",
"@octokit/rest": "18.0.5",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-multi-entry": "^4.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
"@rollup/plugin-yaml": "^2.1.1",
"@types/bunyan": "1.8.6",
"@types/chai": "4.2.12",
"@types/chai-as-promised": "7.1.3",

View File

@ -473,7 +473,69 @@
dependencies:
esquery "^1.0.1"
"@rollup/pluginutils@^3.1.0":
"@rollup/plugin-commonjs@^15.0.0":
version "15.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@rollup/plugin-commonjs/-/plugin-commonjs-15.0.0.tgz#690d15a9d54ba829db93555bff9b98ff34e08574"
integrity sha512-8uAdikHqVyrT32w1zB9VhW6uGwGjhKgnDNP4pQJsjdnyF4FgCj6/bmv24c7v2CuKhq32CcyCwRzMPEElaKkn0w==
dependencies:
"@rollup/pluginutils" "^3.1.0"
commondir "^1.0.1"
estree-walker "^2.0.1"
glob "^7.1.6"
is-reference "^1.2.1"
magic-string "^0.25.7"
resolve "^1.17.0"
"@rollup/plugin-json@^4.1.0":
version "4.1.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3"
integrity sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==
dependencies:
"@rollup/pluginutils" "^3.0.8"
"@rollup/plugin-multi-entry@^4.0.0":
version "4.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@rollup/plugin-multi-entry/-/plugin-multi-entry-4.0.0.tgz#8e105f16ec1bb26639eb3302c8db5665f44b9939"
integrity sha512-1Sw86rwFxrNS7ECY3iSZ7T940xKnruNGpmQDgSDVTp+VTa1g5cPXNzBgp+IoOer41CiVeGFLwYwvicVoJLHEDQ==
dependencies:
"@rollup/plugin-virtual" "^2.0.3"
matched "^5.0.0"
"@rollup/plugin-node-resolve@^9.0.0":
version "9.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@rollup/plugin-node-resolve/-/plugin-node-resolve-9.0.0.tgz#39bd0034ce9126b39c1699695f440b4b7d2b62e6"
integrity sha512-gPz+utFHLRrd41WMP13Jq5mqqzHL3OXrfj3/MkSyB6UBIcuNt9j60GCbarzMzdf1VHFpOxfQh/ez7wyadLMqkg==
dependencies:
"@rollup/pluginutils" "^3.1.0"
"@types/resolve" "1.17.1"
builtin-modules "^3.1.0"
deepmerge "^4.2.2"
is-module "^1.0.0"
resolve "^1.17.0"
"@rollup/plugin-replace@^2.3.3":
version "2.3.3"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@rollup/plugin-replace/-/plugin-replace-2.3.3.tgz#cd6bae39444de119f5d905322b91ebd4078562e7"
integrity sha512-XPmVXZ7IlaoWaJLkSCDaa0Y6uVo5XQYHhiMFzOd5qSv5rE+t/UJToPIOE56flKIxBFQI27ONsxb7dqHnwSsjKQ==
dependencies:
"@rollup/pluginutils" "^3.0.8"
magic-string "^0.25.5"
"@rollup/plugin-virtual@^2.0.3":
version "2.0.3"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@rollup/plugin-virtual/-/plugin-virtual-2.0.3.tgz#0afc88d75c1e1378ab290b8e9898d4edb5be0d74"
integrity sha512-pw6ziJcyjZtntQ//bkad9qXaBx665SgEL8C8KI5wO8G5iU5MPxvdWrQyVaAvjojGm9tJoS8M9Z/EEepbqieYmw==
"@rollup/plugin-yaml@^2.1.1":
version "2.1.1"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@rollup/plugin-yaml/-/plugin-yaml-2.1.1.tgz#6c864adee22004eb325d53bc4ee5553828e056d8"
integrity sha512-CnGD3dbDhP+JeKFX7kJuaBOa7jVzXpl3G8lXp1hasB87cDYOz7qNWd4cFPmYbxMsT/8OCVsceIpRtQ+cj9uxBw==
dependencies:
"@rollup/pluginutils" "^3.0.1"
js-yaml "^3.13.1"
tosource "^1.0.0"
"@rollup/pluginutils@^3.0.1", "@rollup/pluginutils@^3.0.8", "@rollup/pluginutils@^3.1.0":
version "3.1.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b"
integrity sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==
@ -713,6 +775,13 @@
dependencies:
"@types/node" "*"
"@types/resolve@1.17.1":
version "1.17.1"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6"
integrity sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==
dependencies:
"@types/node" "*"
"@types/responselike@*", "@types/responselike@^1.0.0":
version "1.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29"
@ -1739,6 +1808,11 @@ deep-is@^0.1.3, deep-is@~0.1.3:
resolved "https://artifacts.apextoaster.com/repository/group-npm/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
deepmerge@^4.2.2:
version "4.2.2"
resolved "https://artifacts.apextoaster.com/repository/group-npm/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
default-require-extensions@^3.0.0:
version "3.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/default-require-extensions/-/default-require-extensions-3.0.0.tgz#e03f93aac9b2b6443fc52e5e4a37b3ad9ad8df96"
@ -2204,6 +2278,11 @@ estree-walker@^1.0.1:
resolved "https://artifacts.apextoaster.com/repository/group-npm/estree-walker/-/estree-walker-1.0.1.tgz#31bc5d612c96b704106b477e6dd5d8aa138cb700"
integrity sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==
estree-walker@^2.0.1:
version "2.0.1"
resolved "https://artifacts.apextoaster.com/repository/group-npm/estree-walker/-/estree-walker-2.0.1.tgz#f8e030fb21cefa183b44b7ad516b747434e7a3e0"
integrity sha512-tF0hv+Yi2Ot1cwj9eYHtxC0jB9bmjacjQs6ZBTj82H8JwUywFuc+7E83NWfNMwHXZc11mjfFcVXPe9gEP4B8dg==
esutils@^2.0.2:
version "2.0.3"
resolved "https://artifacts.apextoaster.com/repository/group-npm/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
@ -2993,7 +3072,7 @@ is-potential-custom-element-name@^1.0.0:
resolved "https://artifacts.apextoaster.com/repository/group-npm/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.0.tgz#0c52e54bcca391bb2c494b21e8626d7336c6e397"
integrity sha1-DFLlS8yjkbssSUsh6GJtczbG45c=
is-reference@^1.1.2:
is-reference@^1.1.2, is-reference@^1.2.1:
version "1.2.1"
resolved "https://artifacts.apextoaster.com/repository/group-npm/is-reference/-/is-reference-1.2.1.tgz#8b2dac0b371f4bc994fdeaba9eb542d03002d0b7"
integrity sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==
@ -3584,7 +3663,7 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"
magic-string@^0.25.2, magic-string@^0.25.3:
magic-string@^0.25.2, magic-string@^0.25.3, magic-string@^0.25.5, magic-string@^0.25.7:
version "0.25.7"
resolved "https://artifacts.apextoaster.com/repository/group-npm/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051"
integrity sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==
@ -3625,6 +3704,14 @@ matched@^1.0.2:
is-valid-glob "^1.0.0"
resolve-dir "^1.0.0"
matched@^5.0.0:
version "5.0.0"
resolved "https://artifacts.apextoaster.com/repository/group-npm/matched/-/matched-5.0.0.tgz#4b10735a89f87b6f9bf457136472631e19df05d7"
integrity sha512-O0LCuxYYBNBjP2dmAg0i6PME0Mb0dvjulpMC0tTIeMRh6kXYsugOT5GOWpFkSzqjQjgOUs/eiyvpVhXdN2La4g==
dependencies:
glob "^7.1.6"
picomatch "^2.2.1"
memoize-decorator@^1.0.2:
version "1.0.2"
resolved "https://artifacts.apextoaster.com/repository/group-npm/memoize-decorator/-/memoize-decorator-1.0.2.tgz#605a41715c4171db192a90098b00ab8d6e1102f5"