UNPKG

es2049package

Version:

ECMAScript 2049 package: zero-configuration libraries and command-line utilies by Harald Rudell

956 lines (877 loc) 30.7 kB
import fs from 'fs'; import path from 'path'; import fs$1 from 'fs-extra'; import { Hash } from 'crypto'; import babel from 'rollup-plugin-babel'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import _eslint from 'rollup-plugin-eslint'; import json from '@rollup/plugin-json'; import { shebang, chmod } from 'rollup-plugin-thatworks'; import functionBind from '@babel/plugin-proposal-function-bind'; import exportDefaultFrom from '@babel/plugin-proposal-export-default-from'; import logicalAssignmentOperators from '@babel/plugin-proposal-logical-assignment-operators'; import optionalChaining from '@babel/plugin-proposal-optional-chaining'; import pipelineOperator from '@babel/plugin-proposal-pipeline-operator'; import nullishCoalescingOperator from '@babel/plugin-proposal-nullish-coalescing-operator'; import doExpressions from '@babel/plugin-proposal-do-expressions'; import decorators from '@babel/plugin-proposal-decorators'; import functionSent from '@babel/plugin-proposal-function-sent'; import exportNamespaceFrom from '@babel/plugin-proposal-export-namespace-from'; import numericSeparator from '@babel/plugin-proposal-numeric-separator'; import throwExpressions from '@babel/plugin-proposal-throw-expressions'; import dynamicImport from '@babel/plugin-syntax-dynamic-import'; import importMeta from '@babel/plugin-syntax-import-meta'; import classProperties from '@babel/plugin-proposal-class-properties'; import jsonStrings from '@babel/plugin-proposal-json-strings'; import resolvePackage from 'resolve'; import util from 'util'; /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ class PackageJson { constructor(o) { const { filename = path.join(fs.realpathSync(process.cwd()), 'package.json') } = o || false; const json = JSON.parse(fs.readFileSync(filename, 'utf8')); Object.assign(this, { filename, json }); if (!json) this._throw('bad json'); } _throw(message, className) { throw new Error(`${className || 'PackageJson'}: ${message} in: ${this.filename}`); } } /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ class RollupPackageJson extends PackageJson { getRollupFromJson() { const { json: { name, main, module, rollup: ro } } = this; const { input, output, dependencies: dependenciesFlag, main: mainFlag, module: moduleFlag, shebang, clean, external, print, node, targets, eslint } = ro || false; return { name: this._getNonEmptyString(name, 'name'), main: this._getStringOrUndefined(main, 'main'), module: this._getStringOrUndefined(module, 'module'), print: this._getBoolean(print, 'rollup.print', false), clean: this._getArrayOfNonEmptyStringStringOrUndefined(clean, 'rollup.clean'), shebang: this._getBoolean(shebang, 'rollup.shebang', false), node: this._getBoolean(node, 'rollup.node', true), targets: this._getObjectStringOrUndefined(targets, 'rollup.targets', { node: '6.10' }), output: this._getArrayObjectOrUndefined(output), mainFlag: this._getBoolean(mainFlag, 'rollup.main', false), moduleFlag: this._getBoolean(moduleFlag, 'rollup.module', false), input: this._getArrayStringOrUndefined(input), external: this._getArrayOfNonEmptyStringStringOrUndefined(external, 'rollup.external'), dependencyList: this._getDependencyList(), eslint: this._getBoolean(eslint, 'rollup.eslint'), dependenciesFlag: dependenciesFlag !== false }; } _getDependencyList() { const { json: { dependencies } } = this; const list = Object.keys(Object(dependencies)); return list.length ? this._getArrayOfNonEmptyString(list) : undefined; } _getObjectStringOrUndefined(value, name, defaultValue) { return typeof value === 'object' ? value : this._getStringOrUndefined(value, name, defaultValue); } _getArrayObjectOrUndefined(output) { if (!Array.isArray(output) && typeof output !== 'object' && output !== undefined) { this._throw(`bad output value type: ${typeof output}`); } return output; } _getArrayStringOrUndefined(input) { if (!Array.isArray(input)) this._getStringOrUndefined(input, 'rollup.input'); return input; } _getArrayOfNonEmptyStringStringOrUndefined(value, name) { return !Array.isArray(value) ? this._getStringOrUndefined(value, name) : this._getArrayOfNonEmptyString(value, name); } _getArrayOfNonEmptyString(value, name) { if (!Array.isArray(value)) this._throw(`${name}: not array`); for (let [index, v] of value.entries()) this._getNonEmptyString(v, `${name} index ${index}`); return value; } _getStringOrUndefined(value, name, defaultValue) { return value !== undefined ? this._getNonEmptyString(value, name) : defaultValue; } _getNonEmptyString(value, name) { const vt = typeof value; if (vt !== 'string') this._throw(`${name} not non-empty string: ${vt}`); return value; } _getBoolean(value, name, defaultValue) { if (value !== undefined) { const vt = typeof value; if (vt !== 'boolean') this._throw(`${name} not boolean: ${vt}`); return value; } else return defaultValue; } _throw(message) { super._throw(message, 'RollupPackageJson'); } } /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ var nodeIgnores = ['assert', 'async_hooks', 'buffer', 'child_process', 'cluster', 'console', 'constants', 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http2', 'http', 'https', 'inspector', 'internal', 'module', 'net', 'os', 'path', 'process', 'punycode', 'querystring', 'readline', 'repl', 'stream', 'string_decoder', 'sys', 'timers', 'tls', 'tty', 'url', 'util', 'v8', 'vm', 'zlib']; /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ const defaultInputs = ['src/index.js', 'src/index.mjs']; const eslintFiles = ['.eslintrc.json', '.eslintrc.yaml']; const defaultOutputDir = 'build'; const cjsFormat = 'cjs'; const esFormat = 'es'; const defaultExtension = '.js'; const ltsMaintenance = '4.8'; const ltsActive = '6.10'; class RollupConfigurator extends RollupPackageJson { assembleConfig(getConfig) { const pkg = this.getRollupFromJson(); // package.json file cannot be imported because it is located by runtime cwd const configIsArray = Array.isArray(pkg.input); const config = configIsArray ? [] : {}; if (pkg.print) console.log('package.json rollup.print true: verbose output'); if (!configIsArray) { // input is undefined or non-empty string if (!pkg.input) pkg.input = this._getDefaultInput(); if (!pkg.output) pkg.output = this._getDefaultOutput(pkg); Object.assign(pkg, { external: this._assembleExternal(pkg), targets: this._getTargets(pkg.targets, 'rollup'), eslint: this._getEslint(pkg.eslint, `eslint`) }); Object.assign(config, getConfig(pkg)); } else { let { clean } = pkg; const { main, module, name, input: inputList, dependencyList } = pkg; for (let [index, inputElement] of inputList.entries()) { const m = `rollup.input index ${index}`; const { input, output, dependencies: dependenciesFlag = pkg.dependenciesFlag, main: mainFlag, module: moduleFlag, external = pkg.external, node = pkg.node, print = pkg.print, shebang = pkg.shebang, targets = pkg.targets, eslint = pkg.eslint } = inputElement || false; const o = { input: input ? this._getNonEmptyString(input, `${m}: input`) : this._getDefaultInput(), output: output ? this._getArrayObjectOrUndefined(output, `${m}: output`) : this._getElementOutput({ main, module, name, mainFlag, moduleFlag, shebang }), external: this._assembleExternal({ node, dependencyList, external, dependenciesFlag }), name, main, module, clean, targets: this._getTargets(targets, `${m}: nodelatest`), print: this._getBoolean(print, `${m}: print`), shebang: this._getBoolean(shebang, `${m}: shebang`), mainFlag: this._getBoolean(mainFlag, `${m}: main`), moduleFlag: this._getBoolean(moduleFlag, `${m}: module`), node: this._getBoolean(node, `${m}: node`), eslint: this._getEslint(eslint, `${m}: eslint`), dependenciesFlag }; config.push(getConfig(o)); clean = false; } } return config; } static deleteUndefined(config) { for (let [property, value] of Object.entries(Object(config))) if (value === undefined) delete config[property]; } _getTargets(targets, name) { if (targets === undefined) targets = { node: ltsActive };else if (targets === 'stable') targets = { node: ltsMaintenance };else if (targets === 'current') targets = { node: 'current' };else if (targets !== 'mini') { const tt = typeof targets; if (tt !== 'object') throw new Error(`${name} targets: not object 'stable' 'current' or undefined`); } return targets; } _assembleExternal({ node, dependencyList, external: ex, dependenciesFlag }) { let external = []; // use array b/c elements has to be added to Set one by one if (ex) if (!Array.isArray(ex)) external.push(ex);else external.push.apply(external, ex); if (node) external.push.apply(external, nodeIgnores); if (dependenciesFlag) external.push.apply(external, dependencyList); return external.length ? Array.from(new Set(external)).sort() : undefined; } _getEslint(eslint) { return eslint === true || eslint === false ? eslint : eslintFiles.every(file => !fs$1.pathExistsSync(path.resolve(file))); // if none exists: true } _getElementOutput({ main, module, name, mainFlag, moduleFlag, shebang }) { const o = { name, shebang }; if (moduleFlag) o.module = module; if (mainFlag) o.main = main; return this._getDefaultOutput(o); } _getDefaultOutput({ main, module, name, shebang }) { let output; if (module && !shebang && !this._hasExtension(module)) module += defaultExtension; const outputEs = { file: module, format: esFormat }; if (main) { if (!shebang && !this._hasExtension(main)) main += defaultExtension; output = { file: main, format: cjsFormat }; if (module) if (module !== main) output = [output, outputEs];else output = outputEs; } else if (module) output = outputEs;else { output = { file: path.join(defaultOutputDir, name), format: cjsFormat }; if (!shebang) output.file += defaultExtension; } return output; } _getDefaultInput() { for (let input of defaultInputs) if (fs$1.pathExistsSync(input)) return input; throw new Error(`RollupConfigurator cannot determine input: tried '${defaultInputs.join('\'\x20\'')}'`); } _hasExtension(filename) { return !!path.extname(filename).length; } } /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ const m = 'rollupconfig.warningsMuffler: muffled'; function rollupConfigWarningsMuffler(messageObject) { const { code, source, missing, message, id } = messageObject; /* https://github.com/rollup/rollup/issues/794 https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined { code: 'THIS_IS_UNDEFINED', message: 'The \'this\' keyword is equivalent to \'undefined\' at the top level of an ES module, and has been rewritten', url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined', pos: 12, loc: { file: '/opt/foxyboy/sw/packages/syslogtcp/src/Syslog.js', line: 1, column: 12 }, frame: '1: var _this = this;\n ^\n2: \n3: /*', id: '/opt/foxyboy/sw/packages/syslogtcp/src/Syslog.js', toString: [Function] } */ if (code === 'THIS_IS_UNDEFINED') { console.log(`${m} rollup issue 794`); return; } // https://github.com/rollup/rollup-plugin-babel/issues/13 if (code === 'UNRESOLVED_IMPORT' && source.startsWith('babel-runtime/')) { console.log(`${m} babel issue 13`); return; } /* https://github.com/rollup/rollup/issues/1408 { code: 'MISSING_EXPORT', missing: 'default', importer: '\u0000commonjs-proxy:/opt/foxyboy/sw/private/node_modules/core-js/library/modules/es6.object.to-string.js', exporter: '../../node_modules/core-js/library/modules/es6.object.to-string.js', message: '\'default\' is not exported by \'../../node_modules/core-js/library/modules/es6.object.to-string.js\'', url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module', pos: 185, loc: { file: '\u0000commonjs-proxy:/opt/foxyboy/sw/private/node_modules/core-js/library/modules/es6.object.to-string.js', line: 1, column: 185 }, */ if (code === 'MISSING_EXPORT' && missing === 'default' && message.endsWith('es6.object.to-string.js\'')) { console.log(`${m} rollup issue 1408`); return; } /* https://github.com/rollup/rollup/issues/825 { code: 'EVAL', message: 'Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification', url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval', pos: 248, loc: { file: '/opt/foxyboy/sw/private/packages/rollupconfig/node_modules/to-fast-properties/index.js', line: 10, column: 1 }, frame: ' 8: ic();\n 9: return o;\n10: eval("o" + o); // ensure no dead code elimination\n ^\n11: }', id: '/opt/foxyboy/sw/private/packages/rollupconfig/node_modules/to-fast-properties/index.js', toString: [Function] } */ if (code === 'EVAL' && id.includes('node_modules/to-fast-properties')) { console.log(`${m} rollup issue 825`); return; } console.error(messageObject); } /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ async function clean(args) { if (typeof args === 'string') args = [args];else if (!Array.isArray(args) || !args.length) throw new Error('clean: argument not non-empty string or array'); for (let [index, s] of args) { const st = typeof s; if (st !== 'string' || !s) throw new Error(`clean: index ${index}: not non-empty string: ${st}`); } console.log(`clean: ${args.join(' ')}…`); const projectDir = fs$1.realpathSync(process.cwd()); // project directory without symlinks await Promise.all(args.map(s => removeIfExist(path.resolve(projectDir, s)))); console.log('clean completed successfully.'); } async function removeIfExist(p) { if (await fs$1.exists(p)) await fs$1.remove(p); } /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ function cleanPlugin(dirs) { let didClean; return { name: 'cleanPlugin', async load() { if (!didClean) { didClean = true; await clean(dirs); } } }; } /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ const m$1 = rollupPrintPlugin.name; function rollupPrintPlugin(o) { const { ids = true, files = true, debug } = o || false; debug && console.log(`${m$1} instantiated:2`, { ids, files, debug }); return Object.assign({ name: 'print plugin' }, ids ? { resolveId: rollupPrintPluginPrintId } : {}, files ? { load: rollupPrintPluginPrintFile } : {}); } const idMap = {}; function rollupPrintPluginPrintId(importee, importer) { if (importee && idMap[importee]) return; idMap[importee] = true; let s = `resolving: ${ensureNonEmptyString(importee, 'resolve importee')}` + ` referenced by: ${importer !== undefined ? ensureNonEmptyString(importer, 'resolve importer') : 'Rollup configuration object'}`; console.log(s); } function rollupPrintPluginPrintFile(id) { const absolute = ensureNonEmptyString(id, 'load id'); const relative = path.relative('', absolute); console.log(`loading: ${relative}`); } function ensureNonEmptyString(value, message) { const tv = typeof value; if (!value || tv !== 'string') throw new Error(`${m$1} ${message}: not non-empty string: type: ${tv}`); return value; } /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ const m$2 = babelPrintFilenamePlugin.name; function babelPrintFilenamePlugin(o) { const { debug } = o || false; debug && console.log(`${m$2} instantiated: `, o); return { visitor: { Program: babelPrintFilenamePluginPrintFilename } }; } function babelPrintFilenamePluginPrintFilename(nodePass, pluginPass) { const filename = String(Object(Object(Object(pluginPass).file).opts).filename || ''); if (!filename) throw new Error(`${m$2}: filename empty`); const relative = path.relative('', filename); console.log(`babel processing: ${relative}`); } var root = true; var parser = "babel-eslint"; var rules = { "accessor-pairs": "off", "brace-style": [ "error", "1tbs" ], "comma-dangle": [ "error", "always-multiline" ], "consistent-return": "off", curly: "off", "dot-location": [ "error", "property" ], "dot-notation": "error", "eol-last": "error", eqeqeq: [ "error", "allow-null" ], indent: "off", "jsx-quotes": [ "error", "prefer-double" ], "keyword-spacing": [ "error", { after: true, before: true } ], "max-len": "off", "no-bitwise": "off", "no-console": "off", "no-inner-declarations": [ "error", "functions" ], "no-multi-spaces": "error", "no-restricted-syntax": [ "error", "WithStatement" ], semi: "off", "no-shadow": "error", "no-unused-expressions": [ "error", { allowShortCircuit: true } ], "no-unused-vars": [ "error", { args: "none" } ], "no-useless-concat": "off", quotes: [ "error", "single", { avoidEscape: true, allowTemplateLiterals: true } ], "space-before-blocks": "error", "space-before-function-paren": "off" }; var globals = { expectDev: true }; var eslintJson = { root: root, parser: parser, rules: rules, globals: globals }; var name = "es2049package"; var version = "1.3.0"; var description = "ECMAScript 2049 package: zero-configuration libraries and command-line utilies by Harald Rudell"; var author = "Harald Rudell <harald.rudell@gmail.com> (http://haraldrudell.com)"; var license = "ISC"; var scripts = { build: "node --experimental-json-modules ./node_modules/.bin/rollup --config config/rollup.config.mjs", clean: "rimraf bin lib", "clean:config": "rimraf config", reinstall: "npm-run-all reinstall:clean reinstall:install", "reinstall:clean": "rimraf node_modules ../../node_modules", "reinstall:install": "yarn", test: "jest" }; var type = "module"; var main = "lib/es2049package.mjs"; var bin = { clean: "bin/clean.js", rollup: "bin/rollup.js" }; var keywords = [ "ECMAScript", "ECMAScript 2049", "ES.Next", "JavaScript", "Transpile" ]; var engines = { node: ">=12" }; var repository = { type: "git", url: "https://github.com/haraldrudell/ECMAScript2049" }; var jest = { rootDir: "./../.." }; var devDependencies = { allspawn: ">=1.1.2 <2", "babel-core": "7.0.0-bridge.0", "babel-jest": ">=25.1.0 <26", jest: ">=25.1.0 <26", "js-yaml": ">=3.12.0 <4", "npm-run-all": ">=4.1.5 <5", rimraf: ">=3.0.2 <4" }; var dependencies = { "@babel/core": ">=7.8.7 <8", "@babel/plugin-proposal-class-properties": ">=7.8.3 <8", "@babel/plugin-proposal-decorators": ">=7.8.3 <8", "@babel/plugin-proposal-do-expressions": ">=7.8.3 <8", "@babel/plugin-proposal-export-default-from": ">=7.8.3 <8", "@babel/plugin-proposal-export-namespace-from": ">=7.8.3 <8", "@babel/plugin-proposal-function-bind": ">=7.8.3 <8", "@babel/plugin-proposal-function-sent": ">=7.8.3 <8", "@babel/plugin-proposal-json-strings": ">=7.8.3 <8", "@babel/plugin-proposal-logical-assignment-operators": ">=7.8.3 <8", "@babel/plugin-proposal-nullish-coalescing-operator": ">=7.8.3 <8", "@babel/plugin-proposal-numeric-separator": ">=7.8.3 <8", "@babel/plugin-proposal-optional-chaining": ">=7.8.3 <8", "@babel/plugin-proposal-pipeline-operator": ">=7.8.3 <8", "@babel/plugin-proposal-throw-expressions": ">=7.8.3 <8", "@babel/plugin-syntax-dynamic-import": ">=7.8.3 <8", "@babel/plugin-syntax-import-meta": ">=7.8.3 <8", "@babel/preset-env": ">=7.8.7 <8", "babel-eslint": ">=10.1.0 <11", eslint: ">=6.8.0 <7", "fs-extra": ">=8.1.0 <9", resolve: ">=1.15.1 <2", rollup: "npm:rollup-esm-206", "rollup-plugin-babel": ">=4.4.0 <5", "@rollup/plugin-commonjs": ">=11.0.2 <12", "rollup-plugin-eslint": ">=7.0.0 <8", "@rollup/plugin-json": ">=4.0.2 <5", "@rollup/plugin-node-resolve": ">=7.1.1 <8", "rollup-plugin-thatworks": ">=1.0.4 <2" }; var pjson = { name: name, version: version, description: description, author: author, license: license, scripts: scripts, type: type, main: main, bin: bin, keywords: keywords, engines: engines, repository: repository, jest: jest, devDependencies: devDependencies, dependencies: dependencies }; /* © 2018-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ const m$3 = rollupSha256Plugin.name; function rollupSha256Plugin(o) { const { debug } = o || false; debug && console.log(`${m$3} instantiated:`, o); return { name: 'sha256Plugin', // a rollup plugin onwrite: rollupSha256PluginPrintSha256 }; } function rollupSha256PluginPrintSha256(bundle, data) { const { file } = bundle || false; const { code } = data || false; const ft = typeof file; if (!file || ft !== 'string') throw new Error(`${m$3} bundle.file not non-empty string`); const fileBase = path.basename(file); const hash = new Hash('sha256').update(code).digest('hex'); const length = Object(code).length; console.log(`${fileBase} bytes: ${length} sha256: ${hash}`); } /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ var stage0Preset = { plugins: [// 181204 https://babeljs.io/docs/en/babel-preset-stage-0 // stage 0 functionBind, // Stage 1 exportDefaultFrom, logicalAssignmentOperators, [optionalChaining, { loose: false }], [pipelineOperator, { proposal: 'minimal' }], [nullishCoalescingOperator, { loose: false }], doExpressions, // Stage 2 [decorators, { legacy: true }], functionSent, exportNamespaceFrom, numericSeparator, throwExpressions, // Stage 3 dynamicImport, importMeta, [classProperties, { loose: false }], jsonStrings] }; /* © 2017-present Harald Rudell <harald.rudell@gmail.com> (http://www.haraldrudell.com) This source code is licensed under the ISC-style license found in the LICENSE file in the root directory of this source tree. */ const { eslint } = _eslint; const babelEslint = 'babel-eslint'; let eslintBaseOptions; const cwd = process.cwd(); // these output 1,000s of lines const debug = Boolean(process.env.ES2049PACKAGE_DEBUG); const printRollupResolve = Boolean(process.env.ES2049PACKAGE_RESOLVE); const printRollupLoad = Boolean(process.env.ES2049PACKAGE_LOAD); const useRollupPrintPlugin = printRollupResolve || printRollupLoad; if (debug || printRollupResolve || printRollupLoad) { const name = String(Object(pjson).name || 'name: UNKNOWN'); const version = String(Object(pjson).version || 'version: UNKNOWN'); console.log(`${name} version: ${version} ${new Date().toISOString()} debug: `, { debug, printRollupResolve, printRollupLoad }); } var rollup_config = new RollupConfigurator().assembleConfig(getConfig); function getConfig({ input, output, external, targets, shebang: shebang$1, clean, eslint: useEslint, dependenciesFlag }) { const isMini = targets === 'mini'; const includeExclude = { /* default is to include all files, including outside of the project directory if include is present, a file must match to be processed if exclude is present a file must not match to be processes if a pattern does not begin with '/' or '.' it applies only to entries in the project directory include: '**' will limit processing to the project directory a symlink is processed according to its canonical path, ie. true file system location exclude already transpiled code in the project directory's node_module tree node_modules must be excluded because eslint fails transpiled files */ exclude: 'node_modules/**', /* limit to .js files in the project directory tree this exludes for example node_modules in parent directories json is processed by the rollup plugin. If babel processes json, too, it will fail */ include: ['**/*.js', '**/*.mjs'] }; let rollupBabelOptions; let rollupEslintOptions; let rollupResolveOptions; const config = { input, output, external, onwarn: rollupConfigWarningsMuffler, plugins: (useRollupPrintPlugin ? [rollupPrintPlugin({ ids: printRollupResolve, files: printRollupLoad, debug })] : []).concat([ /* rollup-plugin-eslint https://github.com/TrySound/rollup-plugin-eslint CLIEngine options: https://eslint.org/docs/developer-guide/nodejs-api#cliengine */ eslint(rollupEslintOptions = { ...includeExclude, cwd: process.cwd(), ...(useEslint ? getEslintBaseOptions() : {}) }), /* rollup-plugin-node-resolve https://www.npmjs.com/package/rollup-plugin-node-resolve locates modules in node_module directories and parent node_module directories examines module and main fields of package.json prefer builtins, like 'util' over same-named other modules */ resolve(rollupResolveOptions = Object.assign({ extensions: ['.mjs', '.js', '.json'], customResolveOptions: { /* resolve https://www.npmjs.com/package/resolve some unused requires should fail while Rollup should still succeed this enables overriding mock modules solving such problems */ paths: [path.join(fs.realpathSync(process.cwd()), 'js_modules')] // modules in the js_modules directory will override real modules } }, dependenciesFlag ? { jail: cwd } : {})), json(), // required for import of .json files babel(rollupBabelOptions = { // rollup-plugin-babel https://www.npmjs.com/package/rollup-plugin-babel babelrc: false, // do not process package.json or .babelrc files, rollup has the canonical Babel configuraiton ...(isMini ? {} : {// bundle in Babel external helpers https://github.com/rollup/rollup-plugin-babel#usage //runtimeHelpers: true, }), presets: isMini ? [] : [['@babel/preset-env', { modules: false, targets }], stage0Preset], plugins: (isMini ? ['@babel/plugin-syntax-dynamic-import', ['@babel/plugin-proposal-class-properties', { loose: false }]] : []).concat(debug ? [babelPrintFilenamePlugin({ debug })] : []), ...includeExclude }), // only process files from the project /* rollup-plugin-commonjs https://github.com/rollup/rollup-plugin-commonjs converts commonJS modules to ECMAScript 2015 Only processes .js files that are of CommonJS format if imported modules are in common js format (using exports) rollup-plugin-commonjs is required */ commonjs()]).concat(shebang$1 ? [shebang(), chmod()] : []).concat(clean ? cleanPlugin(clean) : []).concat(debug ? [rollupSha256Plugin({ debug })] : []) }; RollupConfigurator.deleteUndefined(config); if (debug) { console.log(`Rollup options for ${input}: ${util.inspect(config, { colors: true, depth: null })}`); console.log(`Node Resolve options: ${util.inspect(rollupResolveOptions, { colors: true, depth: null })}`); console.log(`Eslint options: ${util.inspect(rollupEslintOptions, { colors: true, depth: null })}`); console.log(`Babel options: ${util.inspect(rollupBabelOptions, { colors: true, depth: null })}`); } return config; } function getEslintBaseOptions() { if (eslintBaseOptions) return eslintBaseOptions; const beFile = resolvePackage.sync(path.join(babelEslint, 'package.json')); const beDir = path.join(beFile, '..'); const beData = JSON.parse(fs.readFileSync(beFile, 'utf8')); const parser = path.join(beDir, Object(beData).main); // convert globals to array (eslint CLIEngine wants that) const globalsObject = Object(Object(eslintJson).globals); const globals = Object.keys(globalsObject).map(name => `${name}:${globalsObject[name]}`); return eslintBaseOptions = { ...eslintJson, parser, globals }; } export default rollup_config;