Skip to content

Commit 758bb25

Browse files
authored
Merge pull request webpack#12387 from webpack/bugfix/12386
enable backward-compatible behavior for resolve.roots
2 parents 0331322 + 79de1a2 commit 758bb25

File tree

8 files changed

+52
-9
lines changed

8 files changed

+52
-9
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
- script: |
2727
set -e
2828
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
29-
export JEST_JUNIT_OUTPUT=./basic-junit.xml
29+
export JEST_JUNIT_OUTPUT_NAME=basic-junit.xml
3030
yarn test:basic --ci --reporters=jest-junit
31-
export JEST_JUNIT_OUTPUT=./unit-junit.xml
31+
export JEST_JUNIT_OUTPUT_NAME=unit-junit.xml
3232
yarn test:unit --ci --reporters=jest-junit
3333
displayName: "Run basic tests"
3434
- task: PublishTestResults@2

declarations/WebpackOptions.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ export interface ResolveOptions {
683683
fileSystem?: {
684684
[k: string]: any;
685685
};
686+
/**
687+
* Enable to ignore fatal errors happening during resolving of 'resolve.roots'. Usually such errors should not happen, but this option is provided for backward-compatibility.
688+
*/
689+
ignoreRootsErrors?: boolean;
686690
/**
687691
* Field names from the description file (package.json) which are used to find the default entry point
688692
*/
@@ -703,14 +707,18 @@ export interface ResolveOptions {
703707
* Plugins for the resolver
704708
*/
705709
plugins?: (WebpackPluginInstance | WebpackPluginFunction)[];
710+
/**
711+
* Prefer to resolve server-relative URLs (starting with '/') as absolute paths before falling back to resolve in 'resolve.roots'.
712+
*/
713+
preferAbsolute?: boolean;
706714
/**
707715
* Custom resolver
708716
*/
709717
resolver?: {
710718
[k: string]: any;
711719
};
712720
/**
713-
* 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.
721+
* A list of directories in which requests that are server-relative URLs (starting with '/') are resolved.
714722
*/
715723
roots?: string[];
716724
/**

lib/WebpackOptionsDefaulter.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,16 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
356356
options.resolve.plugins.length > 0
357357
);
358358
});
359+
this.set(
360+
"resolve.preferAbsolute",
361+
"make",
362+
options => !options.resolve.roots || options.resolve.roots.length === 0
363+
);
364+
this.set(
365+
"resolve.ignoreRootsErrors",
366+
"make",
367+
options => !options.resolve.roots || options.resolve.roots.length === 0
368+
);
359369
this.set("resolve.roots", "make", options => [options.context]);
360370

361371
this.set("resolveLoader", "call", value => Object.assign({}, value));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"ajv": "^6.10.2",
1414
"ajv-keywords": "^3.4.1",
1515
"chrome-trace-event": "^1.0.2",
16-
"enhanced-resolve": "^4.3.0",
16+
"enhanced-resolve": "^4.5.0",
1717
"eslint-scope": "^4.0.3",
1818
"json-parse-better-errors": "^1.0.2",
1919
"loader-runner": "^2.4.0",

schemas/WebpackOptions.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,10 @@
11791179
"fileSystem": {
11801180
"description": "Filesystem for the resolver"
11811181
},
1182+
"ignoreRootsErrors": {
1183+
"description": "Enable to ignore fatal errors happening during resolving of 'resolve.roots'. Usually such errors should not happen, but this option is provided for backward-compatibility.",
1184+
"type": "boolean"
1185+
},
11821186
"mainFields": {
11831187
"description": "Field names from the description file (package.json) which are used to find the default entry point",
11841188
"anyOf": [
@@ -1226,11 +1230,15 @@
12261230
]
12271231
}
12281232
},
1233+
"preferAbsolute": {
1234+
"description": "Prefer to resolve server-relative URLs (starting with '/') as absolute paths before falling back to resolve in 'resolve.roots'.",
1235+
"type": "boolean"
1236+
},
12291237
"resolver": {
12301238
"description": "Custom resolver"
12311239
},
12321240
"roots": {
1233-
"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.",
1241+
"description": "A list of directories in which requests that are server-relative URLs (starting with '/') are resolved.",
12341242
"type": "array",
12351243
"items": {
12361244
"description": "Directory in which requests that are server-relative URLs (starting with '/') are resolved.",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
it("should be possible to import an absolute path", () => {
2+
require(__filename);
3+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
resolve: {
3+
plugins: [
4+
{
5+
apply(resolver) {
6+
resolver.hooks.file.tap("Test", (request, resolverContext) => {
7+
if (/test.configCases.*test.configCases/.test(request.path))
8+
throw new Error("Trying to resolve outside of test cases");
9+
});
10+
}
11+
}
12+
]
13+
}
14+
};

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,10 +2015,10 @@ end-of-stream@^1.0.0, end-of-stream@^1.1.0:
20152015
dependencies:
20162016
once "^1.4.0"
20172017

2018-
enhanced-resolve@^4.3.0:
2019-
version "4.3.0"
2020-
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.3.0.tgz#3b806f3bfafc1ec7de69551ef93cca46c1704126"
2021-
integrity sha512-3e87LvavsdxyoCfGusJnrZ5G8SLPOFeHSNpZI/ATL9a5leXo2k0w6MKnbqhdBad9qTobSfB20Ld7UmgoNbAZkQ==
2018+
enhanced-resolve@^4.5.0:
2019+
version "4.5.0"
2020+
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.5.0.tgz#2f3cfd84dbe3b487f18f2db2ef1e064a571ca5ec"
2021+
integrity sha512-Nv9m36S/vxpsI+Hc4/ZGRs0n9mXqSWGGq49zxb/cJfPAQMbUtttJAlNPS4AQzaBdw/pKskw5bMbekT/Y7W/Wlg==
20222022
dependencies:
20232023
graceful-fs "^4.1.2"
20242024
memory-fs "^0.5.0"

0 commit comments

Comments
 (0)