add roots option

This commit is contained in:
Ivan Kopeykin 2020-07-09 00:12:45 +03:00
parent c1c4b47e73
commit 38779b85ee
8 changed files with 103 additions and 6 deletions

View File

@ -1191,6 +1191,10 @@ export interface ResolveOptions {
* A list of resolve restrictions.
*/
restrictions?: (RegExp | string)[];
/**
* A list of root paths.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/

View File

@ -158,6 +158,7 @@ const applyWebpackOptionsDefaults = options => {
applyResolveDefaults(options.resolve, {
cache,
context: options.context,
mjs: options.experiments.mjs,
webTarget,
target,
@ -604,6 +605,7 @@ const applyOptimizationDefaults = (
* @param {ResolveOptions} resolve options
* @param {Object} options options
* @param {boolean} options.cache is cache enable
* @param {string} options.context build context
* @param {boolean} options.mjs is mjs enabled
* @param {boolean} options.webTarget is a web-like target
* @param {Target} options.target target
@ -612,7 +614,7 @@ const applyOptimizationDefaults = (
*/
const applyResolveDefaults = (
resolve,
{ cache, mjs, webTarget, target, mode }
{ cache, context, mjs, webTarget, target, mode }
) => {
D(resolve, "cache", cache);
D(resolve, "modules", ["node_modules"]);
@ -656,6 +658,7 @@ const applyResolveDefaults = (
F(resolve, "mainFields", () =>
webTarget ? ["browser", "module", "main"] : ["module", "main"]
);
D(resolve, "roots", [context]);
F(resolve.byDependency, "commonjs", () => ({}));
F(resolve.byDependency.commonjs, "conditionNames", () => [
"require",

View File

@ -12,7 +12,7 @@
"@webassemblyjs/wasm-parser": "1.9.0",
"acorn": "^7.3.0",
"chrome-trace-event": "^1.0.2",
"enhanced-resolve": "5.0.0-beta.7",
"enhanced-resolve": "5.0.0-beta.8",
"eslint-scope": "^5.0.0",
"events": "^3.0.0",
"glob-to-regexp": "^0.4.1",

View File

@ -2247,6 +2247,14 @@
]
}
},
"roots": {
"description": "A list of root paths.",
"type": "array",
"items": {
"description": "Root path.",
"type": "string"
}
},
"symlinks": {
"description": "Enable resolving symlinks to the original location.",
"type": "boolean"

View File

@ -295,6 +295,9 @@ describe("Defaults", () => {
"modules": Array [
"node_modules",
],
"roots": Array [
"<cwd>",
],
},
"resolveLoader": Object {
"cache": false,

View File

@ -3254,6 +3254,32 @@ Object {
"multiple": false,
"simpleType": "boolean",
},
"resolve-loader-roots": Object {
"configs": Array [
Object {
"description": "Root path.",
"multiple": true,
"path": "resolveLoader.roots[]",
"type": "string",
},
],
"description": "Root path.",
"multiple": true,
"simpleType": "string",
},
"resolve-loader-roots-reset": Object {
"configs": Array [
Object {
"description": "Clear all items provided in configuration. A list of root paths.",
"multiple": false,
"path": "resolveLoader.roots",
"type": "reset",
},
],
"description": "Clear all items provided in configuration. A list of root paths.",
"multiple": false,
"simpleType": "boolean",
},
"resolve-loader-symlinks": Object {
"configs": Array [
Object {
@ -3403,6 +3429,32 @@ Object {
"multiple": false,
"simpleType": "boolean",
},
"resolve-roots": Object {
"configs": Array [
Object {
"description": "Root path.",
"multiple": true,
"path": "resolve.roots[]",
"type": "string",
},
],
"description": "Root path.",
"multiple": true,
"simpleType": "string",
},
"resolve-roots-reset": Object {
"configs": Array [
Object {
"description": "Clear all items provided in configuration. A list of root paths.",
"multiple": false,
"path": "resolve.roots",
"type": "reset",
},
],
"description": "Clear all items provided in configuration. A list of root paths.",
"multiple": false,
"simpleType": "boolean",
},
"resolve-symlinks": Object {
"configs": Array [
Object {

27
types.d.ts vendored
View File

@ -5937,6 +5937,7 @@ declare interface ResolveOptionsTypes {
| ((this: Resolver, arg1: Resolver) => void)
)[];
pnpApi: PnpApiImpl;
roots: Set<string>;
resolveToContext: boolean;
restrictions: Set<string | RegExp>;
}
@ -6050,6 +6051,11 @@ declare interface ResolveOptionsWebpackOptions {
*/
restrictions?: (string | RegExp)[];
/**
* A list of root paths.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/
@ -6236,6 +6242,10 @@ declare abstract class ResolverFactory {
* A list of resolve restrictions.
*/
restrictions?: (string | RegExp)[];
/**
* A list of root paths.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/
@ -6347,6 +6357,10 @@ declare abstract class ResolverFactory {
* A list of resolve restrictions.
*/
restrictions?: (string | RegExp)[];
/**
* A list of root paths.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/
@ -6458,6 +6472,10 @@ declare abstract class ResolverFactory {
* A list of resolve restrictions.
*/
restrictions?: (string | RegExp)[];
/**
* A list of root paths.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/
@ -7940,6 +7958,11 @@ declare interface UserResolveOptions {
*/
pnpApi?: PnpApiImpl;
/**
* A list of root paths
*/
roots?: string[];
/**
* Resolve to a context instead of a file
*/
@ -8395,6 +8418,10 @@ declare interface WithOptions {
* A list of resolve restrictions.
*/
restrictions?: (string | RegExp)[];
/**
* A list of root paths.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/

View File

@ -2402,10 +2402,10 @@ end-of-stream@^1.1.0:
dependencies:
once "^1.4.0"
enhanced-resolve@5.0.0-beta.7:
version "5.0.0-beta.7"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.0.0-beta.7.tgz#174f085396ac8edc734253f5b6aa9a05cb0d73b2"
integrity sha512-4r9mhIEedx7IsNgutSPyFtD0hKukbknr8Fuee36IXg9dYcAeDLb7l6LzBAeiDBgUKeFv+OgMSkCyp/SGCZ5Xag==
enhanced-resolve@5.0.0-beta.8:
version "5.0.0-beta.8"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.0.0-beta.8.tgz#f399920cb9f73350e61ab10bf2c7f36c37dbf032"
integrity sha512-6MteIR5h29V8UAsBVXkW7P2cAf+5p/c+Gu79xNCpBPt+hgKcJ0vujcX4vAiMGJjyq3SCHaY5N64C8HXwwRS3gQ==
dependencies:
graceful-fs "^4.2.0"
tapable "^2.0.0-beta.10"