Merge pull request #11143 from vankop/add-roots

add roots option
This commit is contained in:
Tobias Koppers 2020-07-09 13:15:30 +02:00 committed by GitHub
commit 3d36f75f88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 121 additions and 24 deletions

View File

@ -1188,9 +1188,13 @@ export interface ResolveOptions {
*/
resolver?: import("enhanced-resolve").Resolver;
/**
* A list of resolve restrictions.
* A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.
*/
restrictions?: (RegExp | string)[];
/**
* A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.
*/
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"]
);
F(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

@ -2232,10 +2232,10 @@
"tsType": "(import('enhanced-resolve').Resolver)"
},
"restrictions": {
"description": "A list of resolve restrictions.",
"description": "A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.",
"type": "array",
"items": {
"description": "Resolve restriction.",
"description": "Resolve restriction. Resolve result must fulfill this restriction.",
"anyOf": [
{
"instanceof": "RegExp",
@ -2247,6 +2247,14 @@
]
}
},
"roots": {
"description": "A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.",
"type": "array",
"items": {
"description": "Directory in which requests that are server-relative URLs (starting with '/') are resolved.",
"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

@ -3225,32 +3225,58 @@ Object {
"resolve-loader-restrictions": Object {
"configs": Array [
Object {
"description": "Resolve restriction.",
"description": "Resolve restriction. Resolve result must fulfill this restriction.",
"multiple": true,
"path": "resolveLoader.restrictions[]",
"type": "RegExp",
},
Object {
"description": "Resolve restriction.",
"description": "Resolve restriction. Resolve result must fulfill this restriction.",
"multiple": true,
"path": "resolveLoader.restrictions[]",
"type": "string",
},
],
"description": "Resolve restriction.",
"description": "Resolve restriction. Resolve result must fulfill this restriction.",
"multiple": true,
"simpleType": "string",
},
"resolve-loader-restrictions-reset": Object {
"configs": Array [
Object {
"description": "Clear all items provided in configuration. A list of resolve restrictions.",
"description": "Clear all items provided in configuration. A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.",
"multiple": false,
"path": "resolveLoader.restrictions",
"type": "reset",
},
],
"description": "Clear all items provided in configuration. A list of resolve restrictions.",
"description": "Clear all items provided in configuration. A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.",
"multiple": false,
"simpleType": "boolean",
},
"resolve-loader-roots": Object {
"configs": Array [
Object {
"description": "Directory in which requests that are server-relative URLs (starting with '/') are resolved.",
"multiple": true,
"path": "resolveLoader.roots[]",
"type": "string",
},
],
"description": "Directory in which requests that are server-relative URLs (starting with '/') are resolved.",
"multiple": true,
"simpleType": "string",
},
"resolve-loader-roots-reset": Object {
"configs": Array [
Object {
"description": "Clear all items provided in configuration. A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.",
"multiple": false,
"path": "resolveLoader.roots",
"type": "reset",
},
],
"description": "Clear all items provided in configuration. A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.",
"multiple": false,
"simpleType": "boolean",
},
@ -3374,32 +3400,58 @@ Object {
"resolve-restrictions": Object {
"configs": Array [
Object {
"description": "Resolve restriction.",
"description": "Resolve restriction. Resolve result must fulfill this restriction.",
"multiple": true,
"path": "resolve.restrictions[]",
"type": "RegExp",
},
Object {
"description": "Resolve restriction.",
"description": "Resolve restriction. Resolve result must fulfill this restriction.",
"multiple": true,
"path": "resolve.restrictions[]",
"type": "string",
},
],
"description": "Resolve restriction.",
"description": "Resolve restriction. Resolve result must fulfill this restriction.",
"multiple": true,
"simpleType": "string",
},
"resolve-restrictions-reset": Object {
"configs": Array [
Object {
"description": "Clear all items provided in configuration. A list of resolve restrictions.",
"description": "Clear all items provided in configuration. A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.",
"multiple": false,
"path": "resolve.restrictions",
"type": "reset",
},
],
"description": "Clear all items provided in configuration. A list of resolve restrictions.",
"description": "Clear all items provided in configuration. A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.",
"multiple": false,
"simpleType": "boolean",
},
"resolve-roots": Object {
"configs": Array [
Object {
"description": "Directory in which requests that are server-relative URLs (starting with '/') are resolved.",
"multiple": true,
"path": "resolve.roots[]",
"type": "string",
},
],
"description": "Directory in which requests that are server-relative URLs (starting with '/') are resolved.",
"multiple": true,
"simpleType": "string",
},
"resolve-roots-reset": Object {
"configs": Array [
Object {
"description": "Clear all items provided in configuration. A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.",
"multiple": false,
"path": "resolve.roots",
"type": "reset",
},
],
"description": "Clear all items provided in configuration. A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.",
"multiple": false,
"simpleType": "boolean",
},

37
types.d.ts vendored
View File

@ -5936,6 +5936,7 @@ declare interface ResolveOptionsTypes {
| ((this: Resolver, arg1: Resolver) => void)
)[];
pnpApi: PnpApiImpl;
roots: Set<string>;
resolveToContext: boolean;
restrictions: Set<string | RegExp>;
}
@ -6045,10 +6046,15 @@ declare interface ResolveOptionsWebpackOptions {
resolver?: Resolver;
/**
* A list of resolve restrictions.
* A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.
*/
restrictions?: (string | RegExp)[];
/**
* A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/
@ -6232,9 +6238,13 @@ declare abstract class ResolverFactory {
*/
resolver?: Resolver;
/**
* A list of resolve restrictions.
* A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.
*/
restrictions?: (string | RegExp)[];
/**
* A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/
@ -6343,9 +6353,13 @@ declare abstract class ResolverFactory {
*/
resolver?: Resolver;
/**
* A list of resolve restrictions.
* A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.
*/
restrictions?: (string | RegExp)[];
/**
* A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/
@ -6454,9 +6468,13 @@ declare abstract class ResolverFactory {
*/
resolver?: Resolver;
/**
* A list of resolve restrictions.
* A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.
*/
restrictions?: (string | RegExp)[];
/**
* A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.
*/
roots?: string[];
/**
* Enable resolving symlinks to the original location.
*/
@ -7939,6 +7957,11 @@ declare interface UserResolveOptions {
*/
pnpApi?: PnpApiImpl;
/**
* A list of root paths
*/
roots?: string[];
/**
* Resolve to a context instead of a file
*/
@ -8391,9 +8414,13 @@ declare interface WithOptions {
*/
resolver?: Resolver;
/**
* A list of resolve restrictions.
* A list of resolve restrictions. Resolve results must fulfill all of these restrictions to resolve successfully. Other resolve paths are taken when restrictions are not met.
*/
restrictions?: (string | RegExp)[];
/**
* A list of directories in which requests that are server-relative URLs (starting with '/') are resolved. On non-windows system these requests are tried to resolve as absolute path first.
*/
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"