-
-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from johnnyreilly/master
upgrade enhanced-resolve to v3
- Loading branch information
Showing
4 changed files
with
14 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,9 @@ | ||
// This file serves as a hacky workaround for the lack of "resolveSync" support in webpack. | ||
// We make our own resolver using a sync file system but using the same plugins & options | ||
// that webpack does. | ||
import interfaces = require('./interfaces'); | ||
|
||
const Resolver = require("enhanced-resolve/lib/Resolver"); | ||
const SyncNodeJsInputFileSystem = require("enhanced-resolve/lib/SyncNodeJsInputFileSystem"); | ||
const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem"); | ||
const UnsafeCachePlugin = require("enhanced-resolve/lib/UnsafeCachePlugin"); | ||
const ModulesInDirectoriesPlugin = require("enhanced-resolve/lib/ModulesInDirectoriesPlugin"); | ||
const ModulesInRootPlugin = require("enhanced-resolve/lib/ModulesInRootPlugin"); | ||
const ModuleAsFilePlugin = require("enhanced-resolve/lib/ModuleAsFilePlugin"); | ||
const ModuleAsDirectoryPlugin = require("enhanced-resolve/lib/ModuleAsDirectoryPlugin"); | ||
const ModuleAliasPlugin = require("enhanced-resolve/lib/ModuleAliasPlugin"); | ||
const DirectoryDefaultFilePlugin = require("enhanced-resolve/lib/DirectoryDefaultFilePlugin"); | ||
const DirectoryDescriptionFilePlugin = require("enhanced-resolve/lib/DirectoryDescriptionFilePlugin"); | ||
const DirectoryDescriptionFileFieldAliasPlugin = require("enhanced-resolve/lib/DirectoryDescriptionFileFieldAliasPlugin"); | ||
const FileAppendPlugin = require("enhanced-resolve/lib/FileAppendPlugin"); | ||
const ResultSymlinkPlugin = require("enhanced-resolve/lib/ResultSymlinkPlugin"); | ||
const node = require("enhanced-resolve/lib/node"); | ||
|
||
function makeRootPlugin(name: string, root: string | string[]) { | ||
if (typeof root === "string") { | ||
return new ModulesInRootPlugin(name, root); | ||
} else if (Array.isArray(root)) { | ||
return function() { | ||
root.forEach(function(root) { | ||
this.apply(new ModulesInRootPlugin(name, root)); | ||
}, this); | ||
}; | ||
} | ||
return function() {}; | ||
} | ||
|
||
function makeResolver(options: { resolve: interfaces.Resolve }) { | ||
let fileSystem = new CachedInputFileSystem(new SyncNodeJsInputFileSystem(), 60000); | ||
|
||
let resolver = new Resolver(fileSystem); | ||
|
||
// apply the same plugins that webpack does, see webpack/lib/WebpackOptionsApply.js | ||
resolver.apply( | ||
new UnsafeCachePlugin(options.resolve.unsafeCache), | ||
options.resolve.packageAlias ? new DirectoryDescriptionFileFieldAliasPlugin("package.json", options.resolve.packageAlias) : function() {}, | ||
new ModuleAliasPlugin(options.resolve.alias), | ||
makeRootPlugin("module", options.resolve.root), | ||
new ModulesInDirectoriesPlugin("module", options.resolve.modulesDirectories), | ||
makeRootPlugin("module", options.resolve.fallback), | ||
new ModuleAsFilePlugin("module"), | ||
new ModuleAsDirectoryPlugin("module"), | ||
new DirectoryDescriptionFilePlugin("package.json", options.resolve.packageMains), | ||
new DirectoryDefaultFilePlugin(["index"]), | ||
new FileAppendPlugin(options.resolve.extensions), | ||
new ResultSymlinkPlugin() | ||
); | ||
|
||
return resolver; | ||
function makeResolver(options: { resolve: interfaces.Resolve }): interfaces.ResolveSync { | ||
return node.create.sync(options.resolve); | ||
} | ||
|
||
export = makeResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters