Skip to content

Commit f47a9bf

Browse files
committed
add preferAbsolute option to prefer absolute paths over roots
1 parent 349a506 commit f47a9bf

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ myResolver.resolve({}, lookupStartPath, request, resolveContext, (
9696
| resolver | undefined | A prepared Resolver to which the plugins are attached |
9797
| resolveToContext | false | Resolve to a context instead of a file |
9898
| preferRelative | false | Prefer to resolve module requests as relative request and fallback to resolving as module |
99+
| preferAbsolute | false | Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots |
99100
| restrictions | [] | A list of resolve restrictions |
100101
| roots | [] | A list of root paths |
101102
| symlinks | true | Whether to resolve symlinks to their symlinked location |

lib/ResolverFactory.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const UseFilePlugin = require("./UseFilePlugin");
7575
* @property {(string|RegExp)[]=} restrictions A list of resolve restrictions
7676
* @property {boolean=} useSyncFileSystemCalls Use only the sync constiants of the file system calls
7777
* @property {boolean=} preferRelative Prefer to resolve module requests as relative requests before falling back to modules
78+
* @property {boolean=} preferAbsolute Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots
7879
*/
7980

8081
/**
@@ -104,6 +105,7 @@ const UseFilePlugin = require("./UseFilePlugin");
104105
* @property {boolean} resolveToContext
105106
* @property {Set<string|RegExp>} restrictions
106107
* @property {boolean} preferRelative
108+
* @property {boolean} preferAbsolute
107109
*/
108110

109111
/**
@@ -113,7 +115,7 @@ const UseFilePlugin = require("./UseFilePlugin");
113115
function processPnpApiOption(option) {
114116
if (
115117
option === undefined &&
116-
/** @type {NodeJS.ProcessVersions & {pnp: string}} */ (versions).pnp
118+
/** @type {NodeJS.ProcessVersions & {pnp: string}} */ versions.pnp
117119
) {
118120
// @ts-ignore
119121
return require("pnpapi"); // eslint-disable-line node/no-missing-require
@@ -222,6 +224,7 @@ function createOptions(options) {
222224
fullySpecified: options.fullySpecified || false,
223225
resolveToContext: options.resolveToContext || false,
224226
preferRelative: options.preferRelative || false,
227+
preferAbsolute: options.preferAbsolute || false,
225228
restrictions: new Set(options.restrictions)
226229
};
227230
}
@@ -254,6 +257,7 @@ exports.createResolver = function (options) {
254257
pnpApi,
255258
resolveToContext,
256259
preferRelative,
260+
preferAbsolute,
257261
symlinks,
258262
unsafeCache,
259263
resolver: customResolver,
@@ -364,10 +368,13 @@ exports.createResolver = function (options) {
364368
"internal"
365369
)
366370
);
371+
if (preferAbsolute) {
372+
plugins.push(new JoinRequestPlugin("after-normal-resolve", "relative"));
373+
}
367374
if (roots.size > 0) {
368375
plugins.push(new RootsPlugin("after-normal-resolve", roots, "relative"));
369376
}
370-
if (!preferRelative) {
377+
if (!preferRelative && !preferAbsolute) {
371378
plugins.push(new JoinRequestPlugin("after-normal-resolve", "relative"));
372379
}
373380

0 commit comments

Comments
 (0)