-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
DefaultResolver.js
44 lines (39 loc) · 1.37 KB
/
DefaultResolver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// @flow
import {Resolver} from '@parcel/plugin';
import NodeResolver from '@parcel/node-resolver-core';
// Throw user friendly errors on special webpack loader syntax
// ex. `imports-loader?$=jquery!./example.js`
const WEBPACK_IMPORT_REGEX = /^\w+-loader(?:\?\S*)?!/;
export default (new Resolver({
async loadConfig({config, options, logger}) {
let conf = await config.getConfig([], {
packageKey: '@parcel/resolver-default',
});
return new NodeResolver({
fs: options.inputFS,
projectRoot: options.projectRoot,
packageManager: options.packageManager,
shouldAutoInstall: options.shouldAutoInstall,
mode: options.mode,
logger,
packageExports: conf?.contents?.packageExports ?? false,
});
},
resolve({dependency, specifier, config: resolver}) {
if (WEBPACK_IMPORT_REGEX.test(dependency.specifier)) {
throw new Error(
`The import path: ${dependency.specifier} is using webpack specific loader import syntax, which isn't supported by Parcel.`,
);
}
return resolver.resolve({
filename: specifier,
specifierType: dependency.specifierType,
range: dependency.range,
parent: dependency.resolveFrom,
env: dependency.env,
sourcePath: dependency.sourcePath,
loc: dependency.loc,
packageConditions: dependency.packageConditions,
});
},
}): Resolver);