diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/@webpack-contrib/config-loader | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/@webpack-contrib/config-loader')
13 files changed, 692 insertions, 0 deletions
diff --git a/node_modules/@webpack-contrib/config-loader/CHANGELOG.md b/node_modules/@webpack-contrib/config-loader/CHANGELOG.md new file mode 100644 index 00000000..a72cd5aa --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/CHANGELOG.md @@ -0,0 +1,3 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. diff --git a/node_modules/@webpack-contrib/config-loader/LICENSE b/node_modules/@webpack-contrib/config-loader/LICENSE new file mode 100644 index 00000000..8c11fc72 --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/LICENSE @@ -0,0 +1,20 @@ +Copyright JS Foundation and other contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/@webpack-contrib/config-loader/README.md b/node_modules/@webpack-contrib/config-loader/README.md new file mode 100644 index 00000000..49656e4a --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/README.md @@ -0,0 +1,237 @@ +<div align="center"> + <a href="https://github.com/webpack/webpack"> + <img width="200" height="200" src="https://webpack.js.org/assets/icon-square-big.svg"> + </a> +</div> + +[![npm][npm]][npm-url] +[![node][node]][node-url] +[![deps][deps]][deps-url] +[![tests][tests]][tests-url] +[![chat][chat]][chat-url] + +# config-loader + +A webpack configuration loader. + +This module utilizes [`cosmiconfig`](https://github.com/davidtheclark/cosmiconfig) +which supports declaring a webpack configuration in a number of different file +formats including; `.webpackrc`, `webpack.config.js`, and a `webpack` property +in a `package.json`. + +`config-loader` supports configuration modules which export an `Object`, `Array`, +`Function`, `Promise`, and `Function` which returns a `Promise`. + +The module also validates found configurations against webpack's options schema +to ensure that the configuration is correct before webpack attempts to use it. + +## Requirements + +This module requires a minimum of Node v6.9.0 and Webpack v4.0.0. + +## Getting Started + +To begin, you'll need to install `config-loader`: + +```console +$ npm install @webpack-contrib/config-loader --save-dev +``` + +And get straight to loading a config: + +```js +const loader = require('@webpack-contrib/config-loader'); +const options = { ... }; + +loader(options).then((result) => { + // ... + // result = { config: Object, configPath: String } +}); + +``` + +## Extending Configuration Files + +This module supports extending webpack configuration files with +[ESLint-style](https://eslint.org/docs/user-guide/configuring#extending-configuration-files) +`extends` functionality. This feature allows users to create a "base" config and +in essence, "inherit" from that base config in a separate config. A bare-bones +example: + +```js +// base.config.js +module.exports = { + name: 'base', + mode: 'development', + plugins: [...] +} +``` + +```js +// webpack.config.js +module.exports = { + extends: path.join(..., 'base-config.js'), + name: 'dev' +``` + +The resulting configuration object would resemble: + +```js +// result +{ + name: 'dev', + mode: 'development', + plugins: [...] +} +``` + +The `webpack.config.js` file will be intelligently extended with properties +from `base.config.js`. + +The `extends` property also supports naming installed NPM modules which export +webpack configurations. Various configuration properties can also be filtered in +different ways based on need. + +[Read More about Extending Configuration Files](./docs/EXTENDS.md) + +## Gotchas + +When using a configuration file that exports a `Function`, users of `webpack-cli` +have become accustom to the function signature: + +``` +function config (env, argv) +``` + +`webpack-cli` provides any CLI flags prefixed with `--env` as a single object in +the `env` parameter, which is an unnecessary feature. +[Environment Variables](https://en.wikipedia.org/wiki/Environment_variable#Syntax) +have long served the same purpose, and are easily accessible within a +[Node environment](https://nodejs.org/api/process.html#process_process_env). + +As such, `config-loader` does not call `Function` configs with the `env` +parameter. Rather, it makes calls with only the `argv` parameter. + +## Supported Compilers + +This module can support non-standard JavaScript file formats when a compatible +compiler is registered via the `require` option. If the option is defined, +`config-loader` will attempt to require the specified module(s) before the +target config is found and loaded. + +As such, `config-loader` will also search for the following file extensions; +`.js`, `.es6`, `.flow`, `.mjs`, and `.ts`. + +The module is also tested with the following compilers: + +- [`babel-register`](https://github.com/babel/babel/tree/6.x/packages/babel-register) +- [`flow-remove-types/register`](https://github.com/flowtype/flow-remove-types) +- [`ts-node/register`](https://www.npmjs.com/package/ts-node) + +_Note: Compilers are not part of or built-into this module. To use a specific compiler, you +must install it and specify its use by using the `--require` CLI flag._ + +## API + +### loader([options]) + +Returns a `Promise`, which resolves with an `Object` containing: + +#### `config` + +Type: `Object` + +Contains the actual configuration object. + +#### `configPath` + +Type: `String` + +Contains the full, absolute filesystem path to the configuration file. + +## Options + +#### `allowMissing` + +Type: `Boolean` +Default: `false` + +Instructs the module to allow a missing config file, and returns an `Object` +with empty `config` and `configPath` properties in the event a config file was +not found. + +### `configPath` + +Type: `String` +Default: `undefined` + +Specifies an absolute path to a valid configuration file on the filesystem. + +### `cwd` + +Type: `String` +Default: `process.cwd()` + +Specifies an filesystem path from which point `config-loader` will begin looking +for a configuration file. + +### `require` + +Type: `String | Array[String]` +Default: `undefined` + +Specifies compiler(s) to use when loading modules from files containing the +configuration. For example: + +```js +const loader = require('@webpack-contrib/config-loader'); +const options = { require: 'ts-node/register' }; + +loader(options).then((result) => { ... }); + +``` + +See +[Supported Compilers](https://github.com/webpack-contrib/config-loader#supported-compilers) +for more information. + +### `schema` + +Type: `Object` +Default: `undefined` + +An object containing a valid +[JSON Schema Definition](http://json-schema.org/latest/json-schema-validation.html). + +By default, `config-loader` validates your webpack config against the +[webpack config schema](https://github.com/webpack/webpack/blob/master/schemas/WebpackOptions.json). +However, it can be useful to append additional schema data to allow configs, +which contain properties not present in the webpack schema, to pass validation. + +## Contributing + +Please take a moment to read our contributing guidelines if you haven't yet done so. + +#### [CONTRIBUTING](./.github/CONTRIBUTING) + +## License + +#### [MIT](./LICENSE) + +[npm]: https://img.shields.io/npm/v/@webpack-contrib/config-loader.svg +[npm-url]: https://npmjs.com/package/@webpack-contrib/config-loader + +[node]: https://img.shields.io/node/v/@webpack-contrib/config-loader.svg +[node-url]: https://nodejs.org + +[deps]: https://david-dm.org/webpack-contrib/config-loader.svg +[deps-url]: https://david-dm.org/webpack-contrib/config-loader + +[tests]: https://img.shields.io/circleci/project/github/webpack-contrib/config-loader.svg +[tests-url]: https://circleci.com/gh/webpack-contrib/config-loader + +[cover]: https://codecov.io/gh/webpack-contrib/config-loader/branch/master/graph/badge.svg +[cover-url]: https://codecov.io/gh/webpack-contrib/config-loader + +[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg +[chat-url]: https://gitter.im/webpack/webpack diff --git a/node_modules/@webpack-contrib/config-loader/lib/LoadConfigError.js b/node_modules/@webpack-contrib/config-loader/lib/LoadConfigError.js new file mode 100644 index 00000000..5c6e0c45 --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/lib/LoadConfigError.js @@ -0,0 +1,13 @@ +module.exports = class LoadConfigError extends Error { + constructor(error, configPath) { + super(error.message); + + this.name = 'LoadConfigError'; + + const stack = error.stack.split('\n').slice(1); + stack.unshift(this.toString()); + + this.stack = stack.join('\n'); + this.meta = { configPath }; + } +}; diff --git a/node_modules/@webpack-contrib/config-loader/lib/RequireModuleError.js b/node_modules/@webpack-contrib/config-loader/lib/RequireModuleError.js new file mode 100644 index 00000000..ecaeae33 --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/lib/RequireModuleError.js @@ -0,0 +1,13 @@ +module.exports = class RequireModuleError extends Error { + constructor(error, moduleName) { + super(error.message); + + this.name = 'RequireModuleError'; + + const stack = error.stack.split('\n').slice(1); + stack.unshift(this.toString()); + + this.stack = stack.join('\n'); + this.meta = { moduleName }; + } +}; diff --git a/node_modules/@webpack-contrib/config-loader/lib/extend.js b/node_modules/@webpack-contrib/config-loader/lib/extend.js new file mode 100644 index 00000000..0854032a --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/lib/extend.js @@ -0,0 +1,96 @@ +const path = require('path'); + +const isPlainObj = require('is-plain-obj'); +const merge = require('merge-options').bind({ concatArrays: true }); + +const load = require('./load'); +const resolve = require('./resolve'); +const pluginFilters = require('./filters/plugins'); +const ruleFilters = require('./filters/rules'); + +const loadExtends = (extent, options) => { + let result; + /* istanbul ignore else */ + if (path.isAbsolute(extent)) { + result = load({ allowMissing: true, configPath: extent }); + } else { + // eslint-disable-next-line import/no-dynamic-require, global-require + result = { config: require(extent), configPath: extent }; + } + + // eslint-disable-next-line no-use-before-define + return resolve(result).then(({ config }) => mergeExtend(config, options)); +}; + +const filterPlugins = (config, options = {}) => { + const filterName = options.plugins || 'default'; + const filter = pluginFilters[filterName] || pluginFilters.default; + + return filter(config); +}; + +const filterRules = (config, options = {}) => { + const filterName = options.rules || 'default'; + const filter = ruleFilters[filterName] || ruleFilters.default; + + return filter(config); +}; + +const filterModule = (config, options = {}) => { + const { module } = config; + /* istanbul ignore else */ + if (module) { + module.rules = filterRules(config, options); + } + + return module; +}; + +const filter = (config, options = {}) => { + /* eslint-disable no-param-reassign */ + config.module = filterModule(config, options); + config.plugins = filterPlugins(config, options); + + return config; +}; + +const mergeExtend = (config, options = {}) => { + let { extends: configExtends } = config; + + if (configExtends) { + if (isPlainObj(configExtends)) { + // eslint-disable-next-line no-param-reassign + options = configExtends.filters; + configExtends = configExtends.configs; + } + + configExtends = [].concat(configExtends); + + const result = configExtends.reduceRight( + (prev, conf) => + loadExtends(conf, options).then((extent) => + prev.then((prevConfig) => filter(merge(extent, prevConfig), options)) + ), + Promise.resolve(config) + ); + + return result; + } + + return Promise.resolve(config); +}; + +module.exports = { + extend(config, options) { + const promises = [].concat(config).map((conf) => + mergeExtend(conf, options).then((result) => { + delete result.extends; + return result; + }) + ); + + return Promise.all(promises).then( + (results) => (results.length > 1 ? results : results[0]) + ); + }, +}; diff --git a/node_modules/@webpack-contrib/config-loader/lib/filters/plugins.js b/node_modules/@webpack-contrib/config-loader/lib/filters/plugins.js new file mode 100644 index 00000000..925c2068 --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/lib/filters/plugins.js @@ -0,0 +1,21 @@ +module.exports = { + default: (config) => config.plugins, + + constructor: (config) => { + const { plugins } = config; + /* istanbul ignore if */ + if (!plugins || !plugins.length) { + return plugins; + } + + return plugins.reduceRight( + (array, other) => + array.findIndex( + (plugin) => plugin.constructor.name === other.constructor.name + ) < 0 + ? [...array, other] + : array, + [] + ); + }, +}; diff --git a/node_modules/@webpack-contrib/config-loader/lib/filters/rules.js b/node_modules/@webpack-contrib/config-loader/lib/filters/rules.js new file mode 100644 index 00000000..87a29303 --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/lib/filters/rules.js @@ -0,0 +1,30 @@ +const regexEqual = (reg, exp) => + reg instanceof RegExp && + exp instanceof RegExp && + reg.source === exp.source && + reg.global === exp.global && + reg.ignoreCase === exp.ignoreCase && + reg.multiline === exp.multiline; + +module.exports = { + default: (config) => { + const { rules } = config.module; + /* istanbul ignore if */ + if (!rules || !rules.length) { + return rules; + } + + return rules.reduce( + (array, other) => + array.findIndex( + (rule) => + rule.test === other.test || regexEqual(rule.test, other.test) + ) < 0 + ? [...array, other] + : array, + [] + ); + }, + + none: (config) => config.module.rules, +}; diff --git a/node_modules/@webpack-contrib/config-loader/lib/index.js b/node_modules/@webpack-contrib/config-loader/lib/index.js new file mode 100644 index 00000000..cafce44c --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/lib/index.js @@ -0,0 +1,29 @@ +const merge = require('merge-options'); +const webpackLog = require('webpack-log'); +const validate = require('@webpack-contrib/schema-utils'); +const webpackSchema = require('webpack/schemas/WebpackOptions.json'); + +const { extend } = require('./extend'); +const load = require('./load'); +const resolve = require('./resolve'); + +module.exports = (options = {}) => { + webpackLog({ name: 'config', id: 'webpack-config-loader' }); + + const name = 'config-loader'; + const raw = load(options); + const schema = merge({}, options.schema, webpackSchema); + + return resolve(raw).then((result) => { + const { config, configPath } = result; + + return extend(config).then((finalConfig) => { + // finalConfig may be a single Object or it may be an Array[Object] + // for simplicity, concat into an array and treat both types the same. + for (const target of [].concat(finalConfig)) { + validate({ name, schema, target }); + } + return { config: finalConfig, configPath }; + }); + }); +}; diff --git a/node_modules/@webpack-contrib/config-loader/lib/load.js b/node_modules/@webpack-contrib/config-loader/lib/load.js new file mode 100644 index 00000000..62279036 --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/lib/load.js @@ -0,0 +1,99 @@ +const chalk = require('chalk'); +const cosmiconfig = require('cosmiconfig'); +const resolvePath = require('resolve').sync; +const webpackLog = require('webpack-log'); + +const LoadConfigError = require('./LoadConfigError'); +const RequireModuleError = require('./RequireModuleError'); + +const cwd = process.cwd(); +const { loadJs } = cosmiconfig; +const prefix = 'webpack'; +const cosmicOptions = { + loaders: { + '.es6': loadJs, + '.flow': loadJs, + '.mjs': loadJs, + '.ts': loadJs, + }, + searchPlaces: [ + `${prefix}.config.js`, + `${prefix}.config.es6`, + `${prefix}.config.flow`, + `${prefix}.config.mjs`, + `${prefix}.config.ts`, + `.${prefix}rc`, + 'package.json', + `.${prefix}rc.json`, + `.${prefix}rc.yaml`, + `.${prefix}rc.yml`, + ], +}; + +module.exports = (options = {}) => { + const log = webpackLog({ name: 'config', id: 'webpack-config-loader' }); + const requires = [].concat(options.require).filter((r) => !!r); + + // eslint-disable-next-line no-param-reassign + options = Object.assign({ cwd: process.cwd() }, options); + + for (const module of requires) { + try { + const modulePath = resolvePath(module, { basedir: cwd }); + + log.info(chalk`Requiring the {cyan ${module}} module`); + + if (options.requireOptions) { + const { requireOptions } = options; + // eslint-disable-next-line import/no-dynamic-require, global-require + require(modulePath)(requireOptions); + } else { + // eslint-disable-next-line import/no-dynamic-require, global-require + require(modulePath); + } + } catch (e) { + log.error(chalk`An error occurred while requiring: {grey ${module}}`); + throw new RequireModuleError(e, module); + } + } + + let config = {}; + let { configPath } = options; + + const explorer = cosmiconfig(prefix, cosmicOptions); + + try { + let result; + if (configPath) { + result = explorer.loadSync(configPath) || {}; + } else { + result = explorer.searchSync(options.cwd) || {}; + } + + ({ config, filepath: configPath } = result); + + log.debug(chalk`Found config at {grey ${configPath}}`); + } catch (e) { + /* istanbul ignore else */ + if (configPath) { + log.error(chalk`An error occurred while trying to load {grey ${configPath}} + Did you forget to specify a --require?`); + } else { + log.error(chalk`An error occurred while trying to find a config file + Did you forget to specify a --require?`); + } + throw new LoadConfigError(e, configPath); + } + + if (!configPath && !options.allowMissing) { + // prettier-ignore + log.error(chalk`Unable to load a config from: {grey ${options.cwd}}`); + const e = new Error(`Unable to load a config from: ${options.cwd}`); + throw new LoadConfigError(e, configPath); + } else { + config = config || {}; + configPath = configPath || ''; + } + + return { config, configPath }; +}; diff --git a/node_modules/@webpack-contrib/config-loader/lib/resolve.js b/node_modules/@webpack-contrib/config-loader/lib/resolve.js new file mode 100644 index 00000000..2ed5cf1a --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/lib/resolve.js @@ -0,0 +1,30 @@ +const minimist = require('minimist'); + +const fromFunction = (config, argv) => { + const result = config(argv); + + return Promise.resolve(result); +}; + +const fromObject = (config) => Promise.resolve(config); + +const handlers = { + function: fromFunction, + object: fromObject, +}; + +module.exports = (configSet, argv) => { + const { config, configPath } = configSet; + const type = typeof (config.default || config); + const handler = handlers[type]; + + // eslint-disable-next-line no-param-reassign + argv = argv || minimist(process.argv.slice(2)); + + return handler(config.default || config, argv).then((configResult) => { + return { + config: configResult, + configPath, + }; + }); +}; diff --git a/node_modules/@webpack-contrib/config-loader/node_modules/.bin/webpack b/node_modules/@webpack-contrib/config-loader/node_modules/.bin/webpack new file mode 120000 index 00000000..324aada8 --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/node_modules/.bin/webpack @@ -0,0 +1 @@ +../../../../webpack/bin/webpack.js
\ No newline at end of file diff --git a/node_modules/@webpack-contrib/config-loader/package.json b/node_modules/@webpack-contrib/config-loader/package.json new file mode 100644 index 00000000..13f3afb5 --- /dev/null +++ b/node_modules/@webpack-contrib/config-loader/package.json @@ -0,0 +1,100 @@ +{ + "name": "@webpack-contrib/config-loader", + "version": "1.2.1", + "description": "A webpack configuration loader", + "license": "MIT", + "repository": "webpack-contrib/config-loader", + "author": "Andrew Powell <andrew@shellscape.org>", + "homepage": "https://github.com/webpack-contrib/config-loader", + "bugs": "https://github.com/webpack-contrib/config-loader/issues", + "main": "lib/index.js", + "engines": { + "node": ">= 6.9.0 <7.0.0 || >= 8.9.0" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "commitlint": "commitlint", + "commitmsg": "commitlint -e $GIT_PARAMS", + "lint": "eslint --cache lib test", + "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", + "lint-staged": "lint-staged", + "release": "standard-version", + "release:ci": "conventional-github-releaser -p angular", + "release:validate": "commitlint --from=$(git describe --tags --abbrev=0) --to=$(git rev-parse HEAD)", + "security": "nsp check", + "test": "mocha test/test.js --exit --mode=superman", + "test:coverage": "mkdir -p coverage && nyc --silent npm test && npm run test:coverage:report", + "test:coverage:report": "nyc report --reporter=lcov --reporter=text-lcov --reporter=json --reporter=clover > coverage/lcov.info", + "ci:lint": "npm run lint && npm run security", + "ci:test": "npm run test -- --runInBand", + "ci:coverage": "npm run test:coverage -- --runInBand", + "defaults": "webpack-defaults" + }, + "files": [ + "lib/", + "index.js" + ], + "peerDependencies": { + "webpack": "^4.3.0" + }, + "dependencies": { + "@webpack-contrib/schema-utils": "^1.0.0-beta.0", + "chalk": "^2.1.0", + "cosmiconfig": "^5.0.2", + "is-plain-obj": "^1.1.0", + "loud-rejection": "^1.6.0", + "merge-options": "^1.0.1", + "minimist": "^1.2.0", + "resolve": "^1.6.0", + "webpack-log": "^1.1.2" + }, + "devDependencies": { + "@commitlint/cli": "^7.0.0", + "@commitlint/config-conventional": "^7.0.1", + "@webpack-contrib/eslint-config-webpack": "^2.0.4", + "babel-cli": "^6.26.0", + "babel-core": "^6.26.0", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-polyfill": "^6.26.0", + "babel-preset-env": "^1.6.1", + "babel-register": "^6.26.0", + "conventional-github-releaser": "^3.1.2", + "cross-env": "^5.1.4", + "del": "^3.0.0", + "del-cli": "^1.1.0", + "eslint": "^4.19.1", + "eslint-plugin-import": "^2.10.0", + "eslint-plugin-prettier": "^2.6.0", + "esm": "^3.0.15", + "execa": "^0.10.0", + "expect": "^23.2.0", + "flow-remove-types": "^1.2.3", + "husky": "^0.14.3", + "jest-serializer-path": "^0.1.15", + "jest-snapshot": "^23.2.0", + "lint-staged": "^7.2.0", + "memory-fs": "^0.4.1", + "mocha": "^5.0.5", + "nsp": "^3.2.1", + "nyc": "^12.0.2", + "pre-commit": "^1.2.2", + "prettier": "^1.11.1", + "standard-version": "^4.3.0", + "ts-node": "^5.0.1", + "typescript": "^2.8.1", + "webpack": "^4.4.1", + "webpack-defaults": "^2.3.0" + }, + "keywords": [ + "webpack" + ], + "pre-commit": "lint-staged", + "lint-staged": { + "*.js": [ + "eslint --fix", + "git add" + ] + } +} |
