pax_global_header00006660000000000000000000000064131353645130014516gustar00rootroot0000000000000052 comment=91752e92f0bb4c4384d2127a6d57d0dacb435bb3 enhanced-resolve-3.4.1/000077500000000000000000000000001313536451300147455ustar00rootroot00000000000000enhanced-resolve-3.4.1/.editorconfig000066400000000000000000000001021313536451300174130ustar00rootroot00000000000000root = true [*.js] indent_style=tab trim_trailing_whitespace=trueenhanced-resolve-3.4.1/.eslintignore000066400000000000000000000000221313536451300174420ustar00rootroot00000000000000test/fixtures/**/*enhanced-resolve-3.4.1/.eslintrc000066400000000000000000000025621313536451300165760ustar00rootroot00000000000000{ "root": true, "plugins": ["node", "eslint-plugin-node"], "extends": ["eslint:recommended", "plugin:node/recommended"], "env": { "node": true, "es6": true }, "rules": { "quotes": ["error", "double"], "no-undef": "error", "no-extra-semi": "error", "semi": "error", "no-template-curly-in-string": "error", "no-caller": "error", "yoda": "error", "eqeqeq": "error", "global-require": "off", "brace-style": "error", "eol-last": "error", "indent": ["error", "tab", { "SwitchCase": 1 }], "no-extra-bind": "warn", "no-empty": "off", "no-multiple-empty-lines": "error", "no-multi-spaces": "error", "no-process-exit": "warn", "space-in-parens": "error", "no-trailing-spaces": "error", "no-use-before-define": "off", "no-unused-vars": ["error", {"args": "none"}], "key-spacing": "error", "space-infix-ops": "error", "no-unsafe-negation": "error", "no-loop-func": "warn", "space-before-function-paren": ["error", "never"], "space-before-blocks": "error", "object-curly-spacing": ["error", "always"], "keyword-spacing": ["error", { "after": false, "overrides": { "try": {"after": true}, "else": {"after": true}, "throw": {"after": true}, "case": {"after": true}, "return": {"after": true}, "finally": {"after": true}, "do": {"after": true} } }], "no-console": "off", "valid-jsdoc": "error" } } enhanced-resolve-3.4.1/.gitignore000066400000000000000000000000271313536451300167340ustar00rootroot00000000000000/node_modules /coverageenhanced-resolve-3.4.1/.jsbeautifyrc000066400000000000000000000013021313536451300174340ustar00rootroot00000000000000{ "js": { "allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"], "brace_style": "collapse", "break_chained_methods": false, "e4x": true, "eval_code": false, "end_with_newline": true, "indent_char": "\t", "indent_level": 0, "indent_size": 1, "indent_with_tabs": true, "jslint_happy": false, "jslint_happy_align_switch_case": true, "space_after_anon_function": false, "keep_array_indentation": false, "keep_function_indentation": false, "max_preserve_newlines": 2, "preserve_newlines": true, "space_before_conditional": false, "space_in_paren": false, "unescape_strings": false, "wrap_line_length": 0 } }enhanced-resolve-3.4.1/.travis.yml000066400000000000000000000004201313536451300170520ustar00rootroot00000000000000sudo: false language: node_js node_js: - "8" - "6" - "4.3" script: npm run travis after_success: - cat ./coverage/lcov.info | node_modules/.bin/coveralls --verbose - cat ./coverage/coverage.json | node_modules/codecov.io/bin/codecov.io.js - rm -rf ./coverage enhanced-resolve-3.4.1/README.md000066400000000000000000000130711313536451300162260ustar00rootroot00000000000000# enhanced-resolve Offers an async require.resolve function. It's highly configurable. ## Features * plugin system * provide a custom filesystem * sync and async node.js filesystems included ## Getting Started ### Install ```sh # npm npm install enhanced-resolve # or Yarn yarn add enhanced-resolve ``` ### Creating a Resolver The easiest way to create a resolver is to use the `createResolver` function on `ResolveFactory`, along with one of the supplied File System implementations. ```js const { NodeJsInputFileSystem, CachedInputFileSystem, ResolverFactory } = require('enhanced-resolve'); // create a resolver const myResolver = ResolverFactory.createResolver({ // Typical usage will consume the `NodeJsInputFileSystem` + `CachedInputFileSystem`, which wraps the Node.js `fs` wrapper to add resilience + caching. fileSystem: new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000), extensions: ['.js', '.json'] /* any other resolver options here. Options/defaults can be seen below */ }); // resolve a file with the new resolver const context = {}; const lookupStartPath = '/Users/webpack/some/root/dir'; const request = './path/to-look-up.js'; myResolver.resolve({}, lookupStartPath, request, (err/*Error*/, filepath/*string*/) => { // Do something with the path }); ``` For more examples creating different types resolvers (sync/async, context, etc) see `lib/node.js`. #### Resolver Options | Field | Default | Description | | ------------------------ | --------------------------- | ---------------------------------------------------------------------------------- | | modules | ["node_modules"] | A list of directories to resolve modules from, can be absolute path or folder name | | descriptionFiles | ["package.json"] | A list of description files to read from | | plugins | [] | A list of additional resolve plugins which should be applied | | mainFields | ["main"] | A list of main fields in description files | | aliasFields | [] | A list of alias fields in description files | | mainFiles | ["index"] | A list of main files in directories | | extensions | [".js", ".json", ".node"] | A list of extensions which should be tried for files | | enforceExtension | false | Enforce that a extension from extensions must be used | | moduleExtensions | [] | A list of module extensions which should be tried for modules | | enforceModuleExtension | false | Enforce that a extension from moduleExtensions must be used | | alias | [] | A list of module alias configurations or an object which maps key to value | | resolveToContext | false | Resolve to a context instead of a file | | unsafeCache | false | Use this cache object to unsafely cache the successful requests | | cacheWithContext | true | If unsafe cache is enabled, includes `request.context` in the cache key | | cachePredicate | function() { return true }; | A function which decides whether a request should be cached or not. An object is passed to the function with `path` and `request` properties. | | fileSystem | | The file system which should be used | | resolver | undefined | A prepared Resolver to which the plugins are attached | ## Plugins Similar to `webpack`, the core of `enhanced-resolve` functionality is implemented as individual plugins that are executed using [`Tapable`](https://github.com/webpack/tapable). These plugins can extend the functionality of the library, adding other ways for files/contexts to be resolved. A plugin should be a `class` (or its ES5 equivalent) with an `apply` method. The `apply` method will receive a `resolver` instance, that can be used to hook in to the event system. ### Plugin Boilerplate ```js class MyResolverPlugin { constructor(source, target) { this.source = source; this.target = target; } apply(resolver) { resolver.plugin(this.source, (request, callback) => { // Any logic you need to create a new `request` can go here resolver.doResolve(this.target, request, null, callback); }); } } ``` Plugins are executed in a pipeline, and register which event they should be executed before/after. In the example above, `source` is the name of the event that starts the pipeline, and `target` is what event this plugin should fire, which is what continues the execution of the pipeline. For an example of how these different plugin events create a chain, see `lib/ResolverFactory.js`, in the `//// pipeline ////` section. ## Tests ``` javascript npm test ``` [![Build Status](https://secure.travis-ci.org/webpack/enhanced-resolve.png?branch=master)](http://travis-ci.org/webpack/enhanced-resolve) ## Passing options from webpack If you are using `webpack`, and you want to pass custom options to `enhanced-resolve`, the options are passed from the `resolve` key of your webpack configuration e.g.: ``` resolve: { extensions: ['', '.js', '.jsx'], modules: ['src', 'node_modules'], plugins: [new DirectoryNamedWebpackPlugin()] ... }, ``` ## License Copyright (c) 2012-2016 Tobias Koppers MIT (http://www.opensource.org/licenses/mit-license.php) enhanced-resolve-3.4.1/lib/000077500000000000000000000000001313536451300155135ustar00rootroot00000000000000enhanced-resolve-3.4.1/lib/AliasFieldPlugin.js000066400000000000000000000034661313536451300212360ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var DescriptionFileUtils = require("./DescriptionFileUtils"); var createInnerCallback = require("./createInnerCallback"); var getInnerRequest = require("./getInnerRequest"); function AliasFieldPlugin(source, field, target) { this.source = source; this.field = field; this.target = target; } module.exports = AliasFieldPlugin; AliasFieldPlugin.prototype.apply = function(resolver) { var target = this.target; var field = this.field; resolver.plugin(this.source, function(request, callback) { if(!request.descriptionFileData) return callback(); var innerRequest = getInnerRequest(resolver, request); if(!innerRequest) return callback(); var fieldData = DescriptionFileUtils.getField(request.descriptionFileData, field); if(typeof fieldData !== "object") { if(callback.log) callback.log("Field '" + field + "' doesn't contain a valid alias configuration"); return callback(); } var data1 = fieldData[innerRequest]; var data2 = fieldData[innerRequest.replace(/^\.\//, "")]; var data = typeof data1 !== "undefined" ? data1 : data2; if(data === innerRequest) return callback(); if(data === undefined) return callback(); if(data === false) { var ignoreObj = Object.assign({}, request, { path: false }); return callback(null, ignoreObj); } var obj = Object.assign({}, request, { path: request.descriptionFileRoot, request: data }); resolver.doResolve(target, obj, "aliased from description file " + request.descriptionFilePath + " with mapping '" + innerRequest + "' to '" + data + "'", createInnerCallback(function(err, result) { if(arguments.length > 0) return callback(err, result); // Don't allow other aliasing or raw request callback(null, null); }, callback)); }); }; enhanced-resolve-3.4.1/lib/AliasPlugin.js000066400000000000000000000033331313536451300202630ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var createInnerCallback = require("./createInnerCallback"); function startsWith(string, searchString) { var stringLength = string.length; var searchLength = searchString.length; // early out if the search length is greater than the search string if(searchLength > stringLength) { return false; } var index = -1; while(++index < searchLength) { if(string.charCodeAt(index) !== searchString.charCodeAt(index)) { return false; } } return true; } function AliasPlugin(source, options, target) { this.source = source; this.name = options.name; this.alias = options.alias; this.onlyModule = options.onlyModule; this.target = target; } module.exports = AliasPlugin; AliasPlugin.prototype.apply = function(resolver) { var target = this.target; var name = this.name; var alias = this.alias; var onlyModule = this.onlyModule; resolver.plugin(this.source, function(request, callback) { var innerRequest = request.request; if(!innerRequest) return callback(); if(innerRequest === name || (!onlyModule && startsWith(innerRequest, name + "/"))) { if(innerRequest !== alias && !startsWith(innerRequest, alias + "/")) { var newRequestStr = alias + innerRequest.substr(name.length); var obj = Object.assign({}, request, { request: newRequestStr }); return resolver.doResolve(target, obj, "aliased with mapping '" + name + "': '" + alias + "' to '" + newRequestStr + "'", createInnerCallback(function(err, result) { if(arguments.length > 0) return callback(err, result); // don't allow other aliasing or raw request callback(null, null); }, callback)); } } return callback(); }); }; enhanced-resolve-3.4.1/lib/AppendPlugin.js000066400000000000000000000012161313536451300204370ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function AppendPlugin(source, appending, target) { this.source = source; this.appending = appending; this.target = target; } module.exports = AppendPlugin; AppendPlugin.prototype.apply = function(resolver) { var target = this.target; var appending = this.appending; resolver.plugin(this.source, function(request, callback) { var obj = Object.assign({}, request, { path: request.path + appending, relativePath: request.relativePath && (request.relativePath + appending) }); resolver.doResolve(target, obj, appending, callback); }); }; enhanced-resolve-3.4.1/lib/CachedInputFileSystem.js000066400000000000000000000172301313536451300222500ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function Storage(duration) { this.duration = duration; this.running = new Map(); this.data = new Map(); this.levels = []; if(duration > 0) { this.levels.push(new Set(), new Set(), new Set(), new Set(), new Set(), new Set(), new Set(), new Set(), new Set()); for(var i = 8000; i < duration; i += 500) this.levels.push(new Set()); } this.count = 0; this.interval = null; this.needTickCheck = false; this.nextTick = null; this.passive = true; this.tick = this.tick.bind(this); } Storage.prototype.ensureTick = function() { if(!this.interval && this.duration > 0 && !this.nextTick) this.interval = setInterval(this.tick, Math.floor(this.duration / this.levels.length)); }; Storage.prototype.finished = function(name, err, result) { var callbacks = this.running.get(name); this.running.delete(name); if(this.duration > 0) { this.data.set(name, [err, result]); var levelData = this.levels[0]; this.count -= levelData.size; levelData.add(name); this.count += levelData.size; this.ensureTick(); } for(var i = 0; i < callbacks.length; i++) { callbacks[i](err, result); } }; Storage.prototype.finishedSync = function(name, err, result) { if(this.duration > 0) { this.data.set(name, [err, result]); var levelData = this.levels[0]; this.count -= levelData.size; levelData.add(name); this.count += levelData.size; this.ensureTick(); } }; Storage.prototype.provide = function(name, provider, callback) { if(typeof name !== "string") { callback(new TypeError("path must be a string")); return; } var running = this.running.get(name); if(running) { running.push(callback); return; } if(this.duration > 0) { this.checkTicks(); var data = this.data.get(name); if(data) { return process.nextTick(function() { callback.apply(null, data); }); } } this.running.set(name, running = [callback]); var _this = this; provider(name, function(err, result) { _this.finished(name, err, result); }); }; Storage.prototype.provideSync = function(name, provider) { if(typeof name !== "string") { throw new TypeError("path must be a string"); } if(this.duration > 0) { this.checkTicks(); var data = this.data.get(name); if(data) { if(data[0]) throw data[0]; return data[1]; } } try { var result = provider(name); } catch(e) { this.finishedSync(name, e); throw e; } this.finishedSync(name, null, result); return result; }; Storage.prototype.tick = function() { var decay = this.levels.pop(); for(var item of decay) { this.data.delete(item); } this.count -= decay.size; decay.clear(); this.levels.unshift(decay); if(this.count === 0) { clearInterval(this.interval); this.interval = null; this.nextTick = null; return true; } else if(this.nextTick) { this.nextTick += Math.floor(this.duration / this.levels.length); var time = new Date().getTime(); if(this.nextTick > time) { this.nextTick = null; this.interval = setInterval(this.tick, Math.floor(this.duration / this.levels.length)); return true; } } else if(this.passive) { clearInterval(this.interval); this.interval = null; this.nextTick = new Date().getTime() + Math.floor(this.duration / this.levels.length); } else { this.passive = true; } }; Storage.prototype.checkTicks = function() { this.passive = false; if(this.nextTick) { while(!this.tick()); } }; Storage.prototype.purge = function(what) { if(!what) { this.count = 0; clearInterval(this.interval); this.nextTick = null; this.data.clear(); this.levels.forEach(function(level) { level.clear(); }); } else if(typeof what === "string") { for(var key of this.data.keys()) { if(key.startsWith(what)) this.data.delete(key); } } else { for(var i = what.length - 1; i >= 0; i--) { this.purge(what[i]); } } }; function CachedInputFileSystem(fileSystem, duration) { this.fileSystem = fileSystem; this._statStorage = new Storage(duration); this._readdirStorage = new Storage(duration); this._readFileStorage = new Storage(duration); this._readJsonStorage = new Storage(duration); this._readlinkStorage = new Storage(duration); this._stat = this.fileSystem.stat ? this.fileSystem.stat.bind(this.fileSystem) : null; if(!this._stat) this.stat = null; this._statSync = this.fileSystem.statSync ? this.fileSystem.statSync.bind(this.fileSystem) : null; if(!this._statSync) this.statSync = null; this._readdir = this.fileSystem.readdir ? this.fileSystem.readdir.bind(this.fileSystem) : null; if(!this._readdir) this.readdir = null; this._readdirSync = this.fileSystem.readdirSync ? this.fileSystem.readdirSync.bind(this.fileSystem) : null; if(!this._readdirSync) this.readdirSync = null; this._readFile = this.fileSystem.readFile ? this.fileSystem.readFile.bind(this.fileSystem) : null; if(!this._readFile) this.readFile = null; this._readFileSync = this.fileSystem.readFileSync ? this.fileSystem.readFileSync.bind(this.fileSystem) : null; if(!this._readFileSync) this.readFileSync = null; if(this.fileSystem.readJson) { this._readJson = this.fileSystem.readJson.bind(this.fileSystem); } else if(this.readFile) { this._readJson = function(path, callback) { this.readFile(path, function(err, buffer) { if(err) return callback(err); try { var data = JSON.parse(buffer.toString("utf-8")); } catch(e) { return callback(e); } callback(null, data); }); }.bind(this); } else { this.readJson = null; } if(this.fileSystem.readJsonSync) { this._readJsonSync = this.fileSystem.readJsonSync.bind(this.fileSystem); } else if(this.readFileSync) { this._readJsonSync = function(path) { var buffer = this.readFileSync(path); var data = JSON.parse(buffer.toString("utf-8")); return data; }.bind(this); } else { this.readJsonSync = null; } this._readlink = this.fileSystem.readlink ? this.fileSystem.readlink.bind(this.fileSystem) : null; if(!this._readlink) this.readlink = null; this._readlinkSync = this.fileSystem.readlinkSync ? this.fileSystem.readlinkSync.bind(this.fileSystem) : null; if(!this._readlinkSync) this.readlinkSync = null; } module.exports = CachedInputFileSystem; CachedInputFileSystem.prototype.stat = function(path, callback) { this._statStorage.provide(path, this._stat, callback); }; CachedInputFileSystem.prototype.readdir = function(path, callback) { this._readdirStorage.provide(path, this._readdir, callback); }; CachedInputFileSystem.prototype.readFile = function(path, callback) { this._readFileStorage.provide(path, this._readFile, callback); }; CachedInputFileSystem.prototype.readJson = function(path, callback) { this._readJsonStorage.provide(path, this._readJson, callback); }; CachedInputFileSystem.prototype.readlink = function(path, callback) { this._readlinkStorage.provide(path, this._readlink, callback); }; CachedInputFileSystem.prototype.statSync = function(path) { return this._statStorage.provideSync(path, this._statSync); }; CachedInputFileSystem.prototype.readdirSync = function(path) { return this._readdirStorage.provideSync(path, this._readdirSync); }; CachedInputFileSystem.prototype.readFileSync = function(path) { return this._readFileStorage.provideSync(path, this._readFileSync); }; CachedInputFileSystem.prototype.readJsonSync = function(path) { return this._readJsonStorage.provideSync(path, this._readJsonSync); }; CachedInputFileSystem.prototype.readlinkSync = function(path) { return this._readlinkStorage.provideSync(path, this._readlinkSync); }; CachedInputFileSystem.prototype.purge = function(what) { this._statStorage.purge(what); this._readdirStorage.purge(what); this._readFileStorage.purge(what); this._readlinkStorage.purge(what); this._readJsonStorage.purge(what); }; enhanced-resolve-3.4.1/lib/CloneBasenamePlugin.js000066400000000000000000000013661313536451300217320ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var basename = require("./getPaths").basename; function CloneBasenamePlugin(source, target) { this.source = source; this.target = target; } module.exports = CloneBasenamePlugin; CloneBasenamePlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { var filename = basename(request.path); var filePath = resolver.join(request.path, filename); var obj = Object.assign({}, request, { path: filePath, relativePath: request.relativePath && resolver.join(request.relativePath, filename) }); resolver.doResolve(target, obj, "using path: " + filePath, callback); }); }; enhanced-resolve-3.4.1/lib/ConcordExtensionsPlugin.js000066400000000000000000000025341313536451300227030ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var concord = require("./concord"); var DescriptionFileUtils = require("./DescriptionFileUtils"); var forEachBail = require("./forEachBail"); var createInnerCallback = require("./createInnerCallback"); function ConcordExtensionsPlugin(source, options, target) { this.source = source; this.options = options; this.target = target; } module.exports = ConcordExtensionsPlugin; ConcordExtensionsPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { var concordField = DescriptionFileUtils.getField(request.descriptionFileData, "concord"); if(!concordField) return callback(); var extensions = concord.getExtensions(request.context, concordField); if(!extensions) return callback(); var topLevelCallback = callback; forEachBail(extensions, function(appending, callback) { var obj = Object.assign({}, request, { path: request.path + appending, relativePath: request.relativePath && (request.relativePath + appending) }); resolver.doResolve(target, obj, "concord extension: " + appending, createInnerCallback(callback, topLevelCallback)); }, function(err, result) { if(arguments.length > 0) return callback(err, result); callback(null, null); }); }); }; enhanced-resolve-3.4.1/lib/ConcordMainPlugin.js000066400000000000000000000020621313536451300214240ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var path = require("path"); var concord = require("./concord"); var DescriptionFileUtils = require("./DescriptionFileUtils"); function ConcordMainPlugin(source, options, target) { this.source = source; this.options = options; this.target = target; } module.exports = ConcordMainPlugin; ConcordMainPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { if(request.path !== request.descriptionFileRoot) return callback(); var concordField = DescriptionFileUtils.getField(request.descriptionFileData, "concord"); if(!concordField) return callback(); var mainModule = concord.getMain(request.context, concordField); if(!mainModule) return callback(); var obj = Object.assign({}, request, { request: mainModule }); var filename = path.basename(request.descriptionFilePath); return resolver.doResolve(target, obj, "use " + mainModule + " from " + filename, callback); }); }; enhanced-resolve-3.4.1/lib/ConcordModulesPlugin.js000066400000000000000000000031241313536451300221500ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var concord = require("./concord"); var DescriptionFileUtils = require("./DescriptionFileUtils"); var createInnerCallback = require("./createInnerCallback"); var getInnerRequest = require("./getInnerRequest"); function ConcordModulesPlugin(source, options, target) { this.source = source; this.options = options; this.target = target; } module.exports = ConcordModulesPlugin; ConcordModulesPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { var innerRequest = getInnerRequest(resolver, request); if(!innerRequest) return callback(); var concordField = DescriptionFileUtils.getField(request.descriptionFileData, "concord"); if(!concordField) return callback(); var data = concord.matchModule(request.context, concordField, innerRequest); if(data === innerRequest) return callback(); if(data === undefined) return callback(); if(data === false) { var ignoreObj = Object.assign({}, request, { path: false }); return callback(null, ignoreObj); } var obj = Object.assign({}, request, { path: request.descriptionFileRoot, request: data }); resolver.doResolve(target, obj, "aliased from description file " + request.descriptionFilePath + " with mapping '" + innerRequest + "' to '" + data + "'", createInnerCallback(function(err, result) { if(arguments.length > 0) return callback(err, result); // Don't allow other aliasing or raw request callback(null, null); }, callback)); }); }; enhanced-resolve-3.4.1/lib/DescriptionFilePlugin.js000066400000000000000000000032331313536451300223140ustar00rootroot00000000000000"use strict"; /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ const createInnerCallback = require("./createInnerCallback"); const DescriptionFileUtils = require("./DescriptionFileUtils"); class DescriptionFilePlugin { constructor(source, filenames, target) { this.source = source; this.filenames = [].concat(filenames); this.target = target; } apply(resolver) { const filenames = this.filenames; const target = this.target; resolver.plugin(this.source, (request, callback) => { const directory = request.path; DescriptionFileUtils.loadDescriptionFile(resolver, directory, filenames, ((err, result) => { if(err) return callback(err); if(!result) { if(callback.missing) { filenames.forEach((filename) => { callback.missing.push(resolver.join(directory, filename)); }); } if(callback.log) callback.log("No description file found"); return callback(); } const relativePath = "." + request.path.substr(result.directory.length).replace(/\\/g, "/"); const obj = Object.assign({}, request, { descriptionFilePath: result.path, descriptionFileData: result.content, descriptionFileRoot: result.directory, relativePath: relativePath }); resolver.doResolve(target, obj, "using description file: " + result.path + " (relative path: " + relativePath + ")", createInnerCallback((err, result) => { if(err) return callback(err); if(result) return callback(null, result); // Don't allow other description files or none at all callback(null, null); }, callback)); })); }); } } module.exports = DescriptionFilePlugin; enhanced-resolve-3.4.1/lib/DescriptionFileUtils.js000066400000000000000000000044561313536451300221660ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var forEachBail = require("./forEachBail"); function loadDescriptionFile(resolver, directory, filenames, callback) { (function findDescriptionFile() { forEachBail(filenames, function(filename, callback) { var descriptionFilePath = resolver.join(directory, filename); if(resolver.fileSystem.readJson) { resolver.fileSystem.readJson(descriptionFilePath, function(err, content) { if(err) { if(typeof err.code !== "undefined") return callback(); return onJson(err); } onJson(null, content); }); } else { resolver.fileSystem.readFile(descriptionFilePath, function(err, content) { if(err) return callback(); try { var json = JSON.parse(content); } catch(e) { onJson(e); } onJson(null, json); }); } function onJson(err, content) { if(err) { if(callback.log) callback.log(descriptionFilePath + " (directory description file): " + err); else err.message = descriptionFilePath + " (directory description file): " + err; return callback(err); } callback(null, { content: content, directory: directory, path: descriptionFilePath }); } }, function(err, result) { if(err) return callback(err); if(result) { return callback(null, result); } else { directory = cdUp(directory); if(!directory) { return callback(); } else { return findDescriptionFile(); } } }); }()); } function getField(content, field) { if(!content) return undefined; if(Array.isArray(field)) { var current = content; for(var j = 0; j < field.length; j++) { if(current === null || typeof current !== "object") { current = null; break; } current = current[field[j]]; } if(typeof current === "object") { return current; } } else { if(typeof content[field] === "object") { return content[field]; } } } function cdUp(directory) { if(directory === "/") return null; var i = directory.lastIndexOf("/"), j = directory.lastIndexOf("\\"); var p = i < 0 ? j : j < 0 ? i : i < j ? j : i; if(p < 0) return null; return directory.substr(0, p || 1); } exports.loadDescriptionFile = loadDescriptionFile; exports.getField = getField; exports.cdUp = cdUp; enhanced-resolve-3.4.1/lib/DirectoryExistsPlugin.js000066400000000000000000000016561313536451300224040ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function DirectoryExistsPlugin(source, target) { this.source = source; this.target = target; } module.exports = DirectoryExistsPlugin; DirectoryExistsPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { var fs = this.fileSystem; var directory = request.path; fs.stat(directory, function(err, stat) { if(err || !stat) { if(callback.missing) callback.missing.push(directory); if(callback.log) callback.log(directory + " doesn't exist"); return callback(); } if(!stat.isDirectory()) { if(callback.missing) callback.missing.push(directory); if(callback.log) callback.log(directory + " is not a directory"); return callback(); } this.doResolve(target, request, "existing directory", callback); }.bind(this)); }); }; enhanced-resolve-3.4.1/lib/FileExistsPlugin.js000066400000000000000000000016011313536451300213050ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function FileExistsPlugin(source, target) { this.source = source; this.target = target; } module.exports = FileExistsPlugin; FileExistsPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { var fs = this.fileSystem; var file = request.path; fs.stat(file, function(err, stat) { if(err || !stat) { if(callback.missing) callback.missing.push(file); if(callback.log) callback.log(file + " doesn't exist"); return callback(); } if(!stat.isFile()) { if(callback.missing) callback.missing.push(file); if(callback.log) callback.log(file + " is not a file"); return callback(); } this.doResolve(target, request, "existing file: " + file, callback, true); }.bind(this)); }); }; enhanced-resolve-3.4.1/lib/FileKindPlugin.js000066400000000000000000000010231313536451300207110ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function FileKindPlugin(source, target) { this.source = source; this.target = target; } module.exports = FileKindPlugin; FileKindPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { if(request.directory) return callback(); var obj = Object.assign({}, request); delete obj.directory; resolver.doResolve(target, obj, null, callback); }); }; enhanced-resolve-3.4.1/lib/JoinRequestPlugin.js000066400000000000000000000012141313536451300214760ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function JoinRequestPlugin(source, target) { this.source = source; this.target = target; } module.exports = JoinRequestPlugin; JoinRequestPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { var obj = Object.assign({}, request, { path: resolver.join(request.path, request.request), relativePath: request.relativePath && resolver.join(request.relativePath, request.request), request: undefined }); resolver.doResolve(target, obj, null, callback); }); }; enhanced-resolve-3.4.1/lib/LogInfoPlugin.js000066400000000000000000000020231313536451300205620ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function LogInfoPlugin(source) { this.source = source; } module.exports = LogInfoPlugin; LogInfoPlugin.prototype.apply = function(resolver) { var source = this.source; resolver.plugin(this.source, function(request, callback) { if(!callback.log) return callback(); var log = callback.log; var prefix = "[" + source + "] "; if(request.path) log(prefix + "Resolving in directory: " + request.path); if(request.request) log(prefix + "Resolving request: " + request.request); if(request.module) log(prefix + "Request is an module request."); if(request.directory) log(prefix + "Request is a directory request."); if(request.query) log(prefix + "Resolving request query: " + request.query); if(request.descriptionFilePath) log(prefix + "Has description data from " + request.descriptionFilePath); if(request.relativePath) log(prefix + "Relative path from description file is: " + request.relativePath); callback(); }); }; enhanced-resolve-3.4.1/lib/MainFieldPlugin.js000066400000000000000000000026131313536451300210620ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var path = require("path"); function MainFieldPlugin(source, options, target) { this.source = source; this.options = options; this.target = target; } module.exports = MainFieldPlugin; MainFieldPlugin.prototype.apply = function(resolver) { var target = this.target; var options = this.options; resolver.plugin(this.source, function mainField(request, callback) { if(request.path !== request.descriptionFileRoot) return callback(); var content = request.descriptionFileData; var filename = path.basename(request.descriptionFilePath); var mainModule; var field = options.name; if(Array.isArray(field)) { var current = content; for(var j = 0; j < field.length; j++) { if(current === null || typeof current !== "object") { current = null; break; } current = current[field[j]]; } if(typeof current === "string") { mainModule = current; } } else { if(typeof content[field] === "string") { mainModule = content[field]; } } if(!mainModule) return callback(); if(options.forceRelative && !/^\.\.?\//.test(mainModule)) mainModule = "./" + mainModule; var obj = Object.assign({}, request, { request: mainModule }); return resolver.doResolve(target, obj, "use " + mainModule + " from " + options.name + " in " + filename, callback); }); }; enhanced-resolve-3.4.1/lib/ModuleAppendPlugin.js000066400000000000000000000021141313536451300216030ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function ModuleAppendPlugin(source, appending, target) { this.source = source; this.appending = appending; this.target = target; } module.exports = ModuleAppendPlugin; ModuleAppendPlugin.prototype.apply = function(resolver) { var appending = this.appending; var target = this.target; resolver.plugin(this.source, function(request, callback) { var i = request.request.indexOf("/"), j = request.request.indexOf("\\"); var p = i < 0 ? j : j < 0 ? i : i < j ? i : j; var moduleName, remainingRequest; if(p < 0) { moduleName = request.request; remainingRequest = ""; } else { moduleName = request.request.substr(0, p); remainingRequest = request.request.substr(p); } if(moduleName === "." || moduleName === "..") return callback(); var moduleFinalName = moduleName + appending; var obj = Object.assign({}, request, { request: moduleFinalName + remainingRequest }); resolver.doResolve(target, obj, "module variation " + moduleFinalName, callback); }); }; enhanced-resolve-3.4.1/lib/ModuleKindPlugin.js000066400000000000000000000014131313536451300212620ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var createInnerCallback = require("./createInnerCallback"); function ModuleKindPlugin(source, target) { this.source = source; this.target = target; } module.exports = ModuleKindPlugin; ModuleKindPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { if(!request.module) return callback(); var obj = Object.assign({}, request); delete obj.module; resolver.doResolve(target, obj, "resolve as module", createInnerCallback(function(err, result) { if(arguments.length > 0) return callback(err, result); // Don't allow other alternatives callback(null, null); }, callback)); }); }; enhanced-resolve-3.4.1/lib/ModulesInHierachicDirectoriesPlugin.js000066400000000000000000000030701313536451300251240ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var createInnerCallback = require("./createInnerCallback"); var forEachBail = require("./forEachBail"); var getPaths = require("./getPaths"); function ModulesInHierachicDirectoriesPlugin(source, directories, target) { this.source = source; this.directories = [].concat(directories); this.target = target; } module.exports = ModulesInHierachicDirectoriesPlugin; ModulesInHierachicDirectoriesPlugin.prototype.apply = function(resolver) { var directories = this.directories; var target = this.target; resolver.plugin(this.source, function(request, callback) { var fs = this.fileSystem; var topLevelCallback = callback; var addrs = getPaths(request.path).paths.map(function(p) { return directories.map(function(d) { return this.join(p, d); }, this); }, this).reduce(function(array, p) { array.push.apply(array, p); return array; }, []); forEachBail(addrs, function(addr, callback) { fs.stat(addr, function(err, stat) { if(!err && stat && stat.isDirectory()) { var obj = Object.assign({}, request, { path: addr, request: "./" + request.request }); var message = "looking for modules in " + addr; return resolver.doResolve(target, obj, message, createInnerCallback(callback, topLevelCallback)); } if(topLevelCallback.log) topLevelCallback.log(addr + " doesn't exist or is not a directory"); if(topLevelCallback.missing) topLevelCallback.missing.push(addr); return callback(); }); }, callback); }); }; enhanced-resolve-3.4.1/lib/ModulesInRootPlugin.js000066400000000000000000000011521313536451300217720ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function ModulesInRootPlugin(source, path, target) { this.source = source; this.path = path; this.target = target; } module.exports = ModulesInRootPlugin; ModulesInRootPlugin.prototype.apply = function(resolver) { var target = this.target; var path = this.path; resolver.plugin(this.source, function(request, callback) { var obj = Object.assign({}, request, { path: path, request: "./" + request.request }); resolver.doResolve(target, obj, "looking for modules in " + path, callback, true); }); }; enhanced-resolve-3.4.1/lib/NextPlugin.js000066400000000000000000000006401313536451300201460ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function NextPlugin(source, target) { this.source = source; this.target = target; } module.exports = NextPlugin; NextPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { resolver.doResolve(target, request, null, callback); }); }; enhanced-resolve-3.4.1/lib/NodeJsInputFileSystem.js000066400000000000000000000020561313536451300222630ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var fs = require("graceful-fs"); function NodeJsInputFileSystem() {} module.exports = NodeJsInputFileSystem; NodeJsInputFileSystem.prototype.stat = fs.stat.bind(fs); NodeJsInputFileSystem.prototype.readdir = function readdir(path, callback) { fs.readdir(path, function(err, files) { callback(err, files && files.map(function(file) { return file.normalize ? file.normalize("NFC") : file; })); }); }; NodeJsInputFileSystem.prototype.readFile = fs.readFile.bind(fs); NodeJsInputFileSystem.prototype.readlink = fs.readlink.bind(fs); NodeJsInputFileSystem.prototype.statSync = fs.statSync.bind(fs); NodeJsInputFileSystem.prototype.readdirSync = function readdirSync(path) { var files = fs.readdirSync(path); return files && files.map(function(file) { return file.normalize ? file.normalize("NFC") : file; }); }; NodeJsInputFileSystem.prototype.readFileSync = fs.readFileSync.bind(fs); NodeJsInputFileSystem.prototype.readlinkSync = fs.readlinkSync.bind(fs); enhanced-resolve-3.4.1/lib/ParsePlugin.js000066400000000000000000000013731313536451300203060ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function ParsePlugin(source, target) { this.source = source; this.target = target; } module.exports = ParsePlugin; ParsePlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { var parsed = resolver.parse(request.request); var obj = Object.assign({}, request, parsed); if(request.query && !parsed.query) { obj.query = request.query; } if(parsed && callback.log) { if(parsed.module) callback.log("Parsed request is a module"); if(parsed.directory) callback.log("Parsed request is a directory"); } resolver.doResolve(target, obj, null, callback); }); }; enhanced-resolve-3.4.1/lib/Resolver.js000066400000000000000000000135741313536451300176640ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var Tapable = require("tapable"); var createInnerCallback = require("./createInnerCallback"); function Resolver(fileSystem) { Tapable.call(this); this.fileSystem = fileSystem; } module.exports = Resolver; Resolver.prototype = Object.create(Tapable.prototype); Resolver.prototype.constructor = Resolver; Resolver.prototype.resolveSync = function resolveSync(context, path, request) { var err, result, sync = false; this.resolve(context, path, request, function(e, r) { err = e; result = r; sync = true; }); if(!sync) throw new Error("Cannot 'resolveSync' because the fileSystem is not sync. Use 'resolve'!"); if(err) throw err; return result; }; Resolver.prototype.resolve = function resolve(context, path, request, callback) { if(arguments.length === 3) { throw new Error("Signature changed: context parameter added"); } var resolver = this; var obj = { context: context, path: path, request: request }; var localMissing; var log; var message = "resolve '" + request + "' in '" + path + "'"; function writeLog(msg) { log.push(msg); } function logAsString() { return log.join("\n"); } function onError(err, result) { if(callback.log) { for(var i = 0; i < log.length; i++) callback.log(log[i]); } if(err) return callback(err); var error = new Error("Can't " + message); error.details = logAsString(); error.missing = localMissing; resolver.applyPlugins("no-resolve", obj, error); return callback(error); } function onResolve(err, result) { if(!err && result) { return callback(null, result.path === false ? false : result.path + (result.query || ""), result); } localMissing = []; log = []; return resolver.doResolve("resolve", obj, message, createInnerCallback(onError, { log: writeLog, missing: localMissing, stack: callback.stack })); } onResolve.missing = callback.missing; onResolve.stack = callback.stack; return this.doResolve("resolve", obj, message, onResolve); }; Resolver.prototype.doResolve = function doResolve(type, request, message, callback) { var resolver = this; var stackLine = type + ": (" + request.path + ") " + (request.request || "") + (request.query || "") + (request.directory ? " directory" : "") + (request.module ? " module" : ""); var newStack = [stackLine]; if(callback.stack) { newStack = callback.stack.concat(newStack); if(callback.stack.indexOf(stackLine) >= 0) { // Prevent recursion var recursionError = new Error("Recursion in resolving\nStack:\n " + newStack.join("\n ")); recursionError.recursion = true; if(callback.log) callback.log("abort resolving because of recursion"); return callback(recursionError); } } resolver.applyPlugins("resolve-step", type, request); var beforePluginName = "before-" + type; if(resolver.hasPlugins(beforePluginName)) { resolver.applyPluginsAsyncSeriesBailResult1(beforePluginName, request, createInnerCallback(beforeInnerCallback, { log: callback.log, missing: callback.missing, stack: newStack }, message && ("before " + message), true)); } else { runNormal(); } function beforeInnerCallback(err, result) { if(arguments.length > 0) { if(err) return callback(err); if(result) return callback(null, result); return callback(); } runNormal(); } function runNormal() { if(resolver.hasPlugins(type)) { return resolver.applyPluginsAsyncSeriesBailResult1(type, request, createInnerCallback(innerCallback, { log: callback.log, missing: callback.missing, stack: newStack }, message)); } else { runAfter(); } } function innerCallback(err, result) { if(arguments.length > 0) { if(err) return callback(err); if(result) return callback(null, result); return callback(); } runAfter(); } function runAfter() { var afterPluginName = "after-" + type; if(resolver.hasPlugins(afterPluginName)) { return resolver.applyPluginsAsyncSeriesBailResult1(afterPluginName, request, createInnerCallback(afterInnerCallback, { log: callback.log, missing: callback.missing, stack: newStack }, message && ("after " + message), true)); } else { callback(); } } function afterInnerCallback(err, result) { if(arguments.length > 0) { if(err) return callback(err); if(result) return callback(null, result); return callback(); } return callback(); } }; Resolver.prototype.parse = function parse(identifier) { if(identifier === "") return null; var part = { request: "", query: "", module: false, directory: false, file: false }; var idxQuery = identifier.indexOf("?"); if(idxQuery === 0) { part.query = identifier; } else if(idxQuery > 0) { part.request = identifier.slice(0, idxQuery); part.query = identifier.slice(idxQuery); } else { part.request = identifier; } if(part.request) { part.module = this.isModule(part.request); part.directory = this.isDirectory(part.request); if(part.directory) { part.request = part.request.substr(0, part.request.length - 1); } } return part; }; var notModuleRegExp = /^\.$|^\.[\\\/]|^\.\.$|^\.\.[\/\\]|^\/|^[A-Z]:[\\\/]/i; Resolver.prototype.isModule = function isModule(path) { return !notModuleRegExp.test(path); }; var directoryRegExp = /[\/\\]$/i; Resolver.prototype.isDirectory = function isDirectory(path) { return directoryRegExp.test(path); }; var memoryFsJoin = require("memory-fs/lib/join"); var memoizedJoin = new Map(); Resolver.prototype.join = function(path, request) { var cacheEntry; var pathCache = memoizedJoin.get(path); if(typeof pathCache === "undefined") { memoizedJoin.set(path, pathCache = new Map()); } else { cacheEntry = pathCache.get(request); if(typeof cacheEntry !== "undefined") return cacheEntry; } cacheEntry = memoryFsJoin(path, request); pathCache.set(request, cacheEntry); return cacheEntry; }; Resolver.prototype.normalize = require("memory-fs/lib/normalize"); enhanced-resolve-3.4.1/lib/ResolverFactory.js000066400000000000000000000215031313536451300212030ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var Resolver = require("./Resolver"); var SyncAsyncFileSystemDecorator = require("./SyncAsyncFileSystemDecorator"); var ParsePlugin = require("./ParsePlugin"); var DescriptionFilePlugin = require("./DescriptionFilePlugin"); var NextPlugin = require("./NextPlugin"); var TryNextPlugin = require("./TryNextPlugin"); var ModuleKindPlugin = require("./ModuleKindPlugin"); var FileKindPlugin = require("./FileKindPlugin"); var JoinRequestPlugin = require("./JoinRequestPlugin"); var ModulesInHierachicDirectoriesPlugin = require("./ModulesInHierachicDirectoriesPlugin"); var ModulesInRootPlugin = require("./ModulesInRootPlugin"); var AliasPlugin = require("./AliasPlugin"); var AliasFieldPlugin = require("./AliasFieldPlugin"); var ConcordExtensionsPlugin = require("./ConcordExtensionsPlugin"); var ConcordMainPlugin = require("./ConcordMainPlugin"); var ConcordModulesPlugin = require("./ConcordModulesPlugin"); var DirectoryExistsPlugin = require("./DirectoryExistsPlugin"); var FileExistsPlugin = require("./FileExistsPlugin"); var SymlinkPlugin = require("./SymlinkPlugin"); var MainFieldPlugin = require("./MainFieldPlugin"); var UseFilePlugin = require("./UseFilePlugin"); var AppendPlugin = require("./AppendPlugin"); var ResultPlugin = require("./ResultPlugin"); var ModuleAppendPlugin = require("./ModuleAppendPlugin"); var UnsafeCachePlugin = require("./UnsafeCachePlugin"); exports.createResolver = function(options) { //// OPTIONS //// // A list of directories to resolve modules from, can be absolute path or folder name var modules = options.modules || ["node_modules"]; // A list of description files to read from var descriptionFiles = options.descriptionFiles || ["package.json"]; // A list of additional resolve plugins which should be applied // The slice is there to create a copy, because otherwise pushing into plugins // changes the original options.plugins array, causing duplicate plugins var plugins = (options.plugins && options.plugins.slice()) || []; // A list of main fields in description files var mainFields = options.mainFields || ["main"]; // A list of alias fields in description files var aliasFields = options.aliasFields || []; // A list of main files in directories var mainFiles = options.mainFiles || ["index"]; // A list of extensions which should be tried for files var extensions = options.extensions || [".js", ".json", ".node"]; // Enforce that a extension from extensions must be used var enforceExtension = options.enforceExtension || false; // A list of module extensions which should be tried for modules var moduleExtensions = options.moduleExtensions || []; // Enforce that a extension from moduleExtensions must be used var enforceModuleExtension = options.enforceModuleExtension || false; // A list of module alias configurations or an object which maps key to value var alias = options.alias || []; // Resolve symlinks to their symlinked location var symlinks = typeof options.symlinks !== "undefined" ? options.symlinks : true; // Resolve to a context instead of a file var resolveToContext = options.resolveToContext || false; // Use this cache object to unsafely cache the successful requests var unsafeCache = options.unsafeCache || false; // Whether or not the unsafeCache should include request context as part of the cache key. var cacheWithContext = typeof options.cacheWithContext !== "undefined" ? options.cacheWithContext : true; // A function which decides whether a request should be cached or not. // an object is passed with `path` and `request` properties. var cachePredicate = options.cachePredicate || function() { return true; }; // The file system which should be used var fileSystem = options.fileSystem; // Use only the sync variants of the file system calls var useSyncFileSystemCalls = options.useSyncFileSystemCalls; // A prepared Resolver to which the plugins are attached var resolver = options.resolver; //// options processing //// if(!resolver) { resolver = new Resolver(useSyncFileSystemCalls ? new SyncAsyncFileSystemDecorator(fileSystem) : fileSystem); } extensions = [].concat(extensions); moduleExtensions = [].concat(moduleExtensions); modules = mergeFilteredToArray([].concat(modules), function(item) { return !isAbsolutePath(item); }); mainFields = mainFields.map(function(item) { if(typeof item === "string") { item = { name: item, forceRelative: true }; } return item; }); if(typeof alias === "object" && !Array.isArray(alias)) { alias = Object.keys(alias).map(function(key) { var onlyModule = false; var obj = alias[key]; if(/\$$/.test(key)) { onlyModule = true; key = key.substr(0, key.length - 1); } if(typeof obj === "string") { obj = { alias: obj }; } obj = Object.assign({ name: key, onlyModule: onlyModule }, obj); return obj; }); } if(unsafeCache && typeof unsafeCache !== "object") { unsafeCache = {}; } //// pipeline //// // resolve if(unsafeCache) { plugins.push(new UnsafeCachePlugin("resolve", cachePredicate, unsafeCache, cacheWithContext, "new-resolve")); plugins.push(new ParsePlugin("new-resolve", "parsed-resolve")); } else { plugins.push(new ParsePlugin("resolve", "parsed-resolve")); } // parsed-resolve plugins.push(new DescriptionFilePlugin("parsed-resolve", descriptionFiles, "described-resolve")); plugins.push(new NextPlugin("after-parsed-resolve", "described-resolve")); // described-resolve alias.forEach(function(item) { plugins.push(new AliasPlugin("described-resolve", item, "resolve")); }); plugins.push(new ConcordModulesPlugin("described-resolve", {}, "resolve")); aliasFields.forEach(function(item) { plugins.push(new AliasFieldPlugin("described-resolve", item, "resolve")); }); plugins.push(new ModuleKindPlugin("after-described-resolve", "raw-module")); plugins.push(new JoinRequestPlugin("after-described-resolve", "relative")); // raw-module moduleExtensions.forEach(function(item) { plugins.push(new ModuleAppendPlugin("raw-module", item, "module")); }); if(!enforceModuleExtension) plugins.push(new TryNextPlugin("raw-module", null, "module")); // module modules.forEach(function(item) { if(Array.isArray(item)) plugins.push(new ModulesInHierachicDirectoriesPlugin("module", item, "resolve")); else plugins.push(new ModulesInRootPlugin("module", item, "resolve")); }); // relative plugins.push(new DescriptionFilePlugin("relative", descriptionFiles, "described-relative")); plugins.push(new NextPlugin("after-relative", "described-relative")); // described-relative plugins.push(new FileKindPlugin("described-relative", "raw-file")); plugins.push(new TryNextPlugin("described-relative", "as directory", "directory")); // directory plugins.push(new DirectoryExistsPlugin("directory", "existing-directory")); if(resolveToContext) { // existing-directory plugins.push(new NextPlugin("existing-directory", "resolved")); } else { // existing-directory plugins.push(new ConcordMainPlugin("existing-directory", {}, "resolve")); mainFields.forEach(function(item) { plugins.push(new MainFieldPlugin("existing-directory", item, "resolve")); }); mainFiles.forEach(function(item) { plugins.push(new UseFilePlugin("existing-directory", item, "undescribed-raw-file")); }); // undescribed-raw-file plugins.push(new DescriptionFilePlugin("undescribed-raw-file", descriptionFiles, "raw-file")); plugins.push(new NextPlugin("after-undescribed-raw-file", "raw-file")); // raw-file if(!enforceExtension) plugins.push(new TryNextPlugin("raw-file", "no extension", "file")); plugins.push(new ConcordExtensionsPlugin("raw-file", {}, "file")); extensions.forEach(function(item) { plugins.push(new AppendPlugin("raw-file", item, "file")); }); // file alias.forEach(function(item) { plugins.push(new AliasPlugin("file", item, "resolve")); }); plugins.push(new ConcordModulesPlugin("file", {}, "resolve")); aliasFields.forEach(function(item) { plugins.push(new AliasFieldPlugin("file", item, "resolve")); }); if(symlinks) plugins.push(new SymlinkPlugin("file", "relative")); plugins.push(new FileExistsPlugin("file", "existing-file")); // existing-file plugins.push(new NextPlugin("existing-file", "resolved")); } // resolved plugins.push(new ResultPlugin("resolved")); //// RESOLVER //// plugins.forEach(function(plugin) { resolver.apply(plugin); }); return resolver; }; function mergeFilteredToArray(array, filter) { return array.reduce(function(array, item) { if(filter(item)) { var lastElement = array[array.length - 1]; if(Array.isArray(lastElement)) { lastElement.push(item); } else { array.push([item]); } return array; } else { array.push(item); return array; } }, []); } function isAbsolutePath(path) { return /^[A-Z]:|^\//.test(path); } enhanced-resolve-3.4.1/lib/ResultPlugin.js000066400000000000000000000007371313536451300205150ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function ResultPlugin(source) { this.source = source; } module.exports = ResultPlugin; ResultPlugin.prototype.apply = function(resolver) { resolver.plugin(this.source, function(request, callback) { var obj = Object.assign({}, request); resolver.applyPluginsAsyncSeries1("result", obj, function(err) { if(err) return callback(err); callback(null, obj); }); }); }; enhanced-resolve-3.4.1/lib/SymlinkPlugin.js000066400000000000000000000026251313536451300206630ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var getPaths = require("./getPaths"); var forEachBail = require("./forEachBail"); function SymlinkPlugin(source, target) { this.source = source; this.target = target; } module.exports = SymlinkPlugin; SymlinkPlugin.prototype.apply = function(resolver) { var target = this.target; resolver.plugin(this.source, function(request, callback) { var _this = this; var fs = _this.fileSystem; var pathsResult = getPaths(request.path); var pathSeqments = pathsResult.seqments; var paths = pathsResult.paths; var containsSymlink = false; forEachBail.withIndex(paths, function(path, idx, callback) { fs.readlink(path, function(err, result) { if(!err && result) { pathSeqments[idx] = result; containsSymlink = true; // Shortcut when absolute symlink found if(/^(\/|[a-zA-z]:($|\\))/.test(result)) return callback(null, idx); } callback(); }); }, function(err, idx) { if(!containsSymlink) return callback(); var resultSeqments = typeof idx === "number" ? pathSeqments.slice(0, idx + 1) : pathSeqments.slice(); var result = resultSeqments.reverse().reduce(function(a, b) { return _this.join(a, b); }); var obj = Object.assign({}, request, { path: result }); resolver.doResolve(target, obj, "resolved symlink to " + result, callback); }); }); }; enhanced-resolve-3.4.1/lib/SyncAsyncFileSystemDecorator.js000066400000000000000000000022201313536451300236270ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function SyncAsyncFileSystemDecorator(fs) { this.fs = fs; if(fs.statSync) { this.stat = function(arg, callback) { try { var result = fs.statSync(arg); } catch(e) { return callback(e); } callback(null, result); }; } if(fs.readdirSync) { this.readdir = function(arg, callback) { try { var result = fs.readdirSync(arg); } catch(e) { return callback(e); } callback(null, result); }; } if(fs.readFileSync) { this.readFile = function(arg, callback) { try { var result = fs.readFileSync(arg); } catch(e) { return callback(e); } callback(null, result); }; } if(fs.readlinkSync) { this.readlink = function(arg, callback) { try { var result = fs.readlinkSync(arg); } catch(e) { return callback(e); } callback(null, result); }; } if(fs.readJsonSync) { this.readJson = function(arg, callback) { try { var result = fs.readJsonSync(arg); } catch(e) { return callback(e); } callback(null, result); }; } } module.exports = SyncAsyncFileSystemDecorator; enhanced-resolve-3.4.1/lib/TryNextPlugin.js000066400000000000000000000007531313536451300206520ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function TryNextPlugin(source, message, target) { this.source = source; this.message = message; this.target = target; } module.exports = TryNextPlugin; TryNextPlugin.prototype.apply = function(resolver) { var target = this.target; var message = this.message; resolver.plugin(this.source, function(request, callback) { resolver.doResolve(target, request, message, callback); }); }; enhanced-resolve-3.4.1/lib/UnsafeCachePlugin.js000066400000000000000000000024211313536451300213740ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var createInnerCallback = require("./createInnerCallback"); function UnsafeCachePlugin(source, filterPredicate, cache, withContext, target) { this.source = source; this.filterPredicate = filterPredicate; this.withContext = withContext; this.cache = cache || {}; this.target = target; } module.exports = UnsafeCachePlugin; function getCacheId(request, withContext) { return JSON.stringify({ context: withContext ? request.context : "", path: request.path, query: request.query, request: request.request }); } UnsafeCachePlugin.prototype.apply = function(resolver) { var filterPredicate = this.filterPredicate; var cache = this.cache; var target = this.target; var withContext = this.withContext; resolver.plugin(this.source, function(request, callback) { if(!filterPredicate(request)) return callback(); var cacheId = getCacheId(request, withContext); var cacheEntry = cache[cacheId]; if(cacheEntry) { return callback(null, cacheEntry); } resolver.doResolve(target, request, null, createInnerCallback(function(err, result) { if(err) return callback(err); if(result) return callback(null, cache[cacheId] = result); callback(); }, callback)); }); }; enhanced-resolve-3.4.1/lib/UseFilePlugin.js000066400000000000000000000013171313536451300205660ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function UseFilePlugin(source, filename, target) { this.source = source; this.filename = filename; this.target = target; } module.exports = UseFilePlugin; UseFilePlugin.prototype.apply = function(resolver) { var filename = this.filename; var target = this.target; resolver.plugin(this.source, function(request, callback) { var filePath = resolver.join(request.path, filename); var obj = Object.assign({}, request, { path: filePath, relativePath: request.relativePath && resolver.join(request.relativePath, filename) }); resolver.doResolve(target, obj, "using path: " + filePath, callback); }); }; enhanced-resolve-3.4.1/lib/concord.js000066400000000000000000000122101313536451300174740ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var globToRegExp = require("./globToRegExp").globToRegExp; function parseType(type) { var items = type.split("+"); var t = items.shift(); return { type: t === "*" ? null : t, features: items }; } function isTypeMatched(baseType, testedType) { if(typeof baseType === "string") baseType = parseType(baseType); if(typeof testedType === "string") testedType = parseType(testedType); if(testedType.type && testedType.type !== baseType.type) return false; return testedType.features.every(function(requiredFeature) { return baseType.features.indexOf(requiredFeature) >= 0; }); } function isResourceTypeMatched(baseType, testedType) { baseType = baseType.split("/"); testedType = testedType.split("/"); if(baseType.length !== testedType.length) return false; for(var i = 0; i < baseType.length; i++) { if(!isTypeMatched(baseType[i], testedType[i])) return false; } return true; } function isResourceTypeSupported(context, type) { return context.supportedResourceTypes && context.supportedResourceTypes.some(function(supportedType) { return isResourceTypeMatched(supportedType, type); }); } function isEnvironment(context, env) { return context.environments && context.environments.every(function(environment) { return isTypeMatched(environment, env); }); } var globCache = {}; function getGlobRegExp(glob) { var regExp = globCache[glob] || (globCache[glob] = globToRegExp(glob)); return regExp; } function matchGlob(glob, relativePath) { var regExp = getGlobRegExp(glob); return regExp.exec(relativePath); } function isGlobMatched(glob, relativePath) { return !!matchGlob(glob, relativePath); } function isConditionMatched(context, condition) { var items = condition.split("|"); return items.some(function testFn(item) { item = item.trim(); var inverted = /^!/.test(item); if(inverted) return !testFn(item.substr(1)); if(/^[a-z]+:/.test(item)) { // match named condition var match = /^([a-z]+):\s*/.exec(item); var value = item.substr(match[0].length); var name = match[1]; switch(name) { case "referrer": return isGlobMatched(value, context.referrer); default: return false; } } else if(item.indexOf("/") >= 0) { // match supported type return isResourceTypeSupported(context, item); } else { // match environment return isEnvironment(context, item); } }); } function isKeyMatched(context, key) { while(true) { //eslint-disable-line var match = /^\[([^\]]+)\]\s*/.exec(key); if(!match) return key; key = key.substr(match[0].length); var condition = match[1]; if(!isConditionMatched(context, condition)) { return false; } } } function getField(context, configuration, field) { var value; Object.keys(configuration).forEach(function(key) { var pureKey = isKeyMatched(context, key); if(pureKey === field) { value = configuration[key]; } }); return value; } function getMain(context, configuration) { return getField(context, configuration, "main"); } function getExtensions(context, configuration) { return getField(context, configuration, "extensions"); } function matchModule(context, configuration, request) { var modulesField = getField(context, configuration, "modules"); if(!modulesField) return request; var newRequest = request; var keys = Object.keys(modulesField); var iteration = 0; for(var i = 0; i < keys.length; i++) { var key = keys[i]; var pureKey = isKeyMatched(context, key); var match = matchGlob(pureKey, newRequest); if(match) { var value = modulesField[key]; if(typeof value !== "string") { return value; } else if(/^\(.+\)$/.test(pureKey)) { newRequest = newRequest.replace(getGlobRegExp(pureKey), value); } else { var index = 1; newRequest = value.replace(/(\/?\*)?\*/g, replaceMatcher); } i = -1; if(iteration++ > keys.length) { throw new Error("Request '" + request + "' matches recursively"); } } } return newRequest; function replaceMatcher(find) { switch(find) { case "/**": var m = match[index++]; return m ? "/" + m : ""; case "**": case "*": return match[index++]; } } } function matchType(context, configuration, relativePath) { var typesField = getField(context, configuration, "types"); if(!typesField) return undefined; var type; Object.keys(typesField).forEach(function(key) { var pureKey = isKeyMatched(context, key); if(isGlobMatched(pureKey, relativePath)) { var value = typesField[key]; if(!type && /\/\*$/.test(value)) throw new Error("value ('" + value + "') of key '" + key + "' contains '*', but there is no previous value defined"); type = value.replace(/\/\*$/, "/" + type); } }); return type; } exports.parseType = parseType; exports.isTypeMatched = isTypeMatched; exports.isResourceTypeSupported = isResourceTypeSupported; exports.isEnvironment = isEnvironment; exports.isGlobMatched = isGlobMatched; exports.isConditionMatched = isConditionMatched; exports.isKeyMatched = isKeyMatched; exports.getField = getField; exports.getMain = getMain; exports.getExtensions = getExtensions; exports.matchModule = matchModule; exports.matchType = matchType; enhanced-resolve-3.4.1/lib/createInnerCallback.js000066400000000000000000000020501313536451300217220ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ module.exports = function createInnerCallback(callback, options, message, messageOptional) { var log = options.log; if(!log) { if(options.stack !== callback.stack) { var callbackWrapper = function callbackWrapper() { return callback.apply(this, arguments); }; callbackWrapper.stack = options.stack; callbackWrapper.missing = options.missing; return callbackWrapper; } return callback; } function loggingCallbackWrapper() { var i; if(message) { if(!messageOptional || theLog.length > 0) { log(message); for(i = 0; i < theLog.length; i++) log(" " + theLog[i]); } } else { for(i = 0; i < theLog.length; i++) log(theLog[i]); } return callback.apply(this, arguments); } var theLog = []; loggingCallbackWrapper.log = function writeLog(msg) { theLog.push(msg); }; loggingCallbackWrapper.stack = options.stack; loggingCallbackWrapper.missing = options.missing; return loggingCallbackWrapper; }; enhanced-resolve-3.4.1/lib/forEachBail.js000066400000000000000000000031431313536451300202110ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ module.exports = function forEachBail(array, iterator, callback) { if(array.length === 0) return callback(); var currentPos = array.length; var currentResult; var done = []; for(var i = 0; i < array.length; i++) { var itCb = createIteratorCallback(i); iterator(array[i], itCb); if(currentPos === 0) break; } function createIteratorCallback(i) { return function() { if(i >= currentPos) return; // ignore var args = Array.prototype.slice.call(arguments); done.push(i); if(args.length > 0) { currentPos = i + 1; done = done.filter(function(item) { return item <= i; }); currentResult = args; } if(done.length === currentPos) { callback.apply(null, currentResult); currentPos = 0; } }; } }; module.exports.withIndex = function forEachBailWithIndex(array, iterator, callback) { if(array.length === 0) return callback(); var currentPos = array.length; var currentResult; var done = []; for(var i = 0; i < array.length; i++) { var itCb = createIteratorCallback(i); iterator(array[i], i, itCb); if(currentPos === 0) break; } function createIteratorCallback(i) { return function() { if(i >= currentPos) return; // ignore var args = Array.prototype.slice.call(arguments); done.push(i); if(args.length > 0) { currentPos = i + 1; done = done.filter(function(item) { return item <= i; }); currentResult = args; } if(done.length === currentPos) { callback.apply(null, currentResult); currentPos = 0; } }; } }; enhanced-resolve-3.4.1/lib/getInnerRequest.js000066400000000000000000000014271313536451300212010ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ module.exports = function getInnerRequest(resolver, request) { if(typeof request.__innerRequest === "string" && request.__innerRequest_request === request.request && request.__innerRequest_relativePath === request.relativePath) return request.__innerRequest; var innerRequest; if(request.request) { innerRequest = request.request; if(/^\.\.?\//.test(innerRequest) && request.relativePath) { innerRequest = resolver.join(request.relativePath, innerRequest); } } else { innerRequest = request.relativePath; } request.__innerRequest_request = request.request; request.__innerRequest_relativePath = request.relativePath; return request.__innerRequest = innerRequest; }; enhanced-resolve-3.4.1/lib/getPaths.js000066400000000000000000000016461313536451300176370ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ module.exports = function getPaths(path) { var parts = path.split(/(.*?[\\\/]+)/); var paths = [path]; var seqments = [parts[parts.length - 1]]; var part = parts[parts.length - 1]; path = path.substr(0, path.length - part.length - 1); paths.push(path); for(var i = parts.length - 2; i > 2; i -= 2) { part = parts[i]; path = path.substr(0, path.length - part.length) || "/"; paths.push(path); seqments.push(part.substr(0, part.length - 1)); } part = parts[1]; seqments.push(part.length > 1 ? part.substr(0, part.length - 1) : part); return { paths: paths, seqments: seqments }; }; module.exports.basename = function basename(path) { var i = path.lastIndexOf("/"), j = path.lastIndexOf("\\"); var p = i < 0 ? j : j < 0 ? i : i < j ? j : i; if(p < 0) return null; var s = path.substr(p + 1); return s; }; enhanced-resolve-3.4.1/lib/globToRegExp.js000066400000000000000000000076601313536451300204230ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ function globToRegExp(glob) { // * [^\\\/]* // /**/ /.+/ // ^* \./.+ (concord special) // ? [^\\\/] // [!...] [^...] // [^...] [^...] // / [\\\/] // {...,...} (...|...) // ?(...|...) (...|...)? // +(...|...) (...|...)+ // *(...|...) (...|...)* // @(...|...) (...|...) if(/^\(.+\)$/.test(glob)) { // allow to pass an RegExp in brackets return new RegExp(glob.substr(1, glob.length - 2)); } var tokens = tokenize(glob); var process = createRoot(); var regExpStr = tokens.map(process).join(""); return new RegExp("^" + regExpStr + "$"); } var SIMPLE_TOKENS = { "@(": "one", "?(": "zero-one", "+(": "one-many", "*(": "zero-many", "|": "segment-sep", "/**/": "any-path-segments", "**": "any-path", "*": "any-path-segment", "?": "any-char", "{": "or", "/": "path-sep", ",": "comma", ")": "closing-segment", "}": "closing-or" }; function tokenize(glob) { return glob.split(/([@?+*]\(|\/\*\*\/|\*\*|[?*]|\[[\!\^]?(?:[^\]\\]|\\.)+\]|\{|,|\/|[|)}])/g).map(function(item) { if(!item) return null; var t = SIMPLE_TOKENS[item]; if(t) { return { type: t }; } if(item[0] === "[") { if(item[1] === "^" || item[1] === "!") { return { type: "inverted-char-set", value: item.substr(2, item.length - 3) }; } else { return { type: "char-set", value: item.substr(1, item.length - 2) }; } } return { type: "string", value: item }; }).filter(Boolean).concat({ type: "end" }); } function createRoot() { var inOr = []; var process = createSeqment(); var initial = true; return function(token) { switch(token.type) { case "or": inOr.push(initial); return "("; case "comma": if(inOr.length) { initial = inOr[inOr.length - 1]; return "|"; } else { return process({ type: "string", value: "," }, initial); } case "closing-or": if(inOr.length === 0) throw new Error("Unmatched '}'"); inOr.pop(); return ")"; case "end": if(inOr.length) throw new Error("Unmatched '{'"); return process(token, initial); default: var result = process(token, initial); initial = false; return result; } }; } function createSeqment() { var inSeqment = []; var process = createSimple(); return function(token, initial) { switch(token.type) { case "one": case "one-many": case "zero-many": case "zero-one": inSeqment.push(token.type); return "("; case "segment-sep": if(inSeqment.length) { return "|"; } else { return process({ type: "string", value: "|" }, initial); } case "closing-segment": var segment = inSeqment.pop(); switch(segment) { case "one": return ")"; case "one-many": return ")+"; case "zero-many": return ")*"; case "zero-one": return ")?"; } throw new Error("Unexcepted segment " + segment); case "end": if(inSeqment.length > 0) { throw new Error("Unmatched segment, missing ')'"); } return process(token, initial); default: return process(token, initial); } }; } function createSimple() { return function(token, initial) { switch(token.type) { case "path-sep": return "[\\\\/]+"; case "any-path-segments": return "[\\\\/]+(?:(.+)[\\\\/]+)?"; case "any-path": return "(.*)"; case "any-path-segment": if(initial) { return "\\.[\\\\/]+(?:.*[\\\\/]+)?([^\\\\/]+)"; } else { return "([^\\\\/]*)"; } case "any-char": return "[^\\\\/]"; case "inverted-char-set": return "[^" + token.value + "]"; case "char-set": return "[" + token.value + "]"; case "string": return token.value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); case "end": return ""; default: throw new Error("Unsupported token '" + token.type + "'"); } }; } exports.globToRegExp = globToRegExp; enhanced-resolve-3.4.1/lib/node.js000066400000000000000000000077671313536451300170170ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var ResolverFactory = require("./ResolverFactory"); var NodeJsInputFileSystem = require("./NodeJsInputFileSystem"); var CachedInputFileSystem = require("./CachedInputFileSystem"); var nodeFileSystem = new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000); var nodeContext = { environments: [ "node+es3+es5+process+native" ] }; var asyncResolver = ResolverFactory.createResolver({ extensions: [".js", ".json", ".node"], fileSystem: nodeFileSystem }); module.exports = function resolve(context, path, request, callback) { if(typeof context === "string") { callback = request; request = path; path = context; context = nodeContext; } asyncResolver.resolve(context, path, request, callback); }; var syncResolver = ResolverFactory.createResolver({ extensions: [".js", ".json", ".node"], useSyncFileSystemCalls: true, fileSystem: nodeFileSystem }); module.exports.sync = function resolveSync(context, path, request) { if(typeof context === "string") { request = path; path = context; context = nodeContext; } return syncResolver.resolveSync(context, path, request); }; var asyncContextResolver = ResolverFactory.createResolver({ extensions: [".js", ".json", ".node"], resolveToContext: true, fileSystem: nodeFileSystem }); module.exports.context = function resolveContext(context, path, request, callback) { if(typeof context === "string") { callback = request; request = path; path = context; context = nodeContext; } asyncContextResolver.resolve(context, path, request, callback); }; var syncContextResolver = ResolverFactory.createResolver({ extensions: [".js", ".json", ".node"], resolveToContext: true, useSyncFileSystemCalls: true, fileSystem: nodeFileSystem }); module.exports.context.sync = function resolveContextSync(context, path, request) { if(typeof context === "string") { request = path; path = context; context = nodeContext; } return syncContextResolver.resolveSync(context, path, request); }; var asyncLoaderResolver = ResolverFactory.createResolver({ extensions: [".js", ".json", ".node"], moduleExtensions: ["-loader"], mainFields: ["loader", "main"], fileSystem: nodeFileSystem }); module.exports.loader = function resolveLoader(context, path, request, callback) { if(typeof context === "string") { callback = request; request = path; path = context; context = nodeContext; } asyncLoaderResolver.resolve(context, path, request, callback); }; var syncLoaderResolver = ResolverFactory.createResolver({ extensions: [".js", ".json", ".node"], moduleExtensions: ["-loader"], mainFields: ["loader", "main"], useSyncFileSystemCalls: true, fileSystem: nodeFileSystem }); module.exports.loader.sync = function resolveLoaderSync(context, path, request) { if(typeof context === "string") { request = path; path = context; context = nodeContext; } return syncLoaderResolver.resolveSync(context, path, request); }; module.exports.create = function create(options) { options = Object.assign({ fileSystem: nodeFileSystem }, options); var resolver = ResolverFactory.createResolver(options); return function(context, path, request, callback) { if(typeof context === "string") { callback = request; request = path; path = context; context = nodeContext; } resolver.resolve(context, path, request, callback); }; }; module.exports.create.sync = function createSync(options) { options = Object.assign({ useSyncFileSystemCalls: true, fileSystem: nodeFileSystem }, options); var resolver = ResolverFactory.createResolver(options); return function(context, path, request) { if(typeof context === "string") { request = path; path = context; context = nodeContext; } return resolver.resolveSync(context, path, request); }; }; // Export Resolver, FileSystems and Plugins module.exports.ResolverFactory = ResolverFactory; module.exports.NodeJsInputFileSystem = NodeJsInputFileSystem; module.exports.CachedInputFileSystem = CachedInputFileSystem; enhanced-resolve-3.4.1/open-bot.yaml000066400000000000000000000076701313536451300173660ustar00rootroot00000000000000bot: "webpack-bot" rules: # Add ci-ok, ci-not-ok labels depending on travis status # comment to point the user to the results # comment in case of success - filters: open: true pull_request: mergeable: true status_1: context: "continuous-integration/travis-ci/pr" ensure_1: value: "{{status_1.state}}" equals: "success" actions: label: add: "PR: CI-ok" remove: "PR: CI-not-ok" comment: identifier: "ci-result" message: |- Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. - filters: open: true pull_request: mergeable: true status_1: context: "continuous-integration/travis-ci/pr" any: ensure_1: value: "{{status_1.state}}" equals: "failure" actions: label: add: "PR: CI-not-ok" remove: "PR: CI-ok" # add conflict label to pull requests with conflict # on conflict all result labels are removed - filters: open: true pull_request: mergeable: false actions: label: add: "PR: conflict" remove: - "PR: tests-needed" - "PR: CI-ok" - "PR: CI-not-ok" - filters: open: true pull_request: mergeable: true actions: label: remove: "PR: conflict" # add unreviewed, reviewed, review-outdated labels # comment to ping reviewer # comment on new PR - filters: open: true in_order: commit: true review: state: APPROVED|CHANGES_REQUESTED ensure: value: "{{review.state}}" equals: APPROVED actions: label: add: "PR: reviewed-approved" remove: - "PR: review-outdated" - "PR: unreviewed" - "PR: reviewed" - filters: open: true in_order: commit: true review: state: APPROVED|CHANGES_REQUESTED ensure: value: "{{review.state}}" equals: CHANGES_REQUESTED actions: label: add: "PR: reviewed-changes-requested" remove: - "PR: review-outdated" - "PR: unreviewed" - "PR: reviewed" - filters: open: true in_order: review: state: APPROVED|CHANGES_REQUESTED commit: true not: label: "review-outdated" ensure: value: "{{commit.author.login}}" notEquals: "{{review.user.login}}" actions: label: add: "PR: review-outdated" remove: - "PR: reviewed-approved" - "PR: reviewed-changes-requested" - "PR: unreviewed" - "PR: reviewed" comment: identifier: "review-outdated" message: |- @{{commit.author.login}} Thanks for your update. I labeled the Pull Request so reviewers will review it again. @{{review.user.login}} Please review the new changes. - filters: open: true commit: true not: review: state: APPROVED|CHANGES_REQUESTED actions: label: "PR: unreviewed" # add non-master label to pull request to other branch - filters: pull_request: base_ref: "^(?!master)" actions: label: "PR: non-master" # add small label to small pull requests - filters: open: true pull_request: additions: "<= 10" deletions: "<= 10" changed_files: "<= 2" actions: label: "PR: small" # Move issue task - filters: open: true comment: "\\s*@webpack-bot\\s+move\\s+(?:to\\s+)?([a-z0-9_\\-\\.]+/[a-z0-9_\\-\\.]+)\\s*([\\s\\S]*)$" not: comment_1: matching: "moved\\-by\\-bot" author: "." permission: user: "{{comment.actor.login}}" actions: new_issue: target: "{{{comment_match.[1]}}}" body: |- {{{issue.body}}} --- This issue was moved from {{owner}}/{{repo}}#{{issue.number}} by @{{comment.actor.login}}. Orginal issue was by @{{issue.user.login}}. {{{comment_match.[2]}}} comment: identifier: moved-by-bot message: |- I've moved it to {{comment_match.[1]}}. close: true enhanced-resolve-3.4.1/package.json000066400000000000000000000026661313536451300172450ustar00rootroot00000000000000{ "name": "enhanced-resolve", "version": "3.4.1", "author": "Tobias Koppers @sokra", "description": "Offers a async require.resolve function. It's highly configurable.", "files": [ "lib" ], "dependencies": { "graceful-fs": "^4.1.2", "memory-fs": "^0.4.0", "object-assign": "^4.0.1", "tapable": "^0.2.7" }, "licenses": [ { "type": "MIT", "url": "http://www.opensource.org/licenses/mit-license.php" } ], "devDependencies": { "beautify-lint": "^1.0.3", "codecov.io": "^0.1.6", "coveralls": "^2.11.6", "eslint": "^3.14.1", "eslint-plugin-node": "^3.0.5", "eslint-plugin-nodeca": "^1.0.3", "istanbul": "^0.4.1", "js-beautify": "^1.5.10", "mocha": "^2.3.4", "should": "^8.0.2" }, "engines": { "node": ">=4.3.0 <5.0.0 || >=5.10" }, "main": "lib/node.js", "homepage": "http://github.com/webpack/enhanced-resolve", "scripts": { "beautify-lint": "beautify-lint lib/**.js test/*.js", "beautify": "beautify-rewrite lib/**.js test/*.js", "lint": "eslint lib test", "pretest": "npm run lint && npm run beautify-lint", "test": "mocha --full-trace --check-leaks", "precover": "npm run lint && npm run beautify-lint", "cover": "istanbul cover node_modules/mocha/bin/_mocha", "travis": "npm run cover -- --report lcovonly" }, "repository": { "type": "git", "url": "git://github.com/webpack/enhanced-resolve.git" } } enhanced-resolve-3.4.1/test/000077500000000000000000000000001313536451300157245ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/.eslintrc000066400000000000000000000001021313536451300175410ustar00rootroot00000000000000{ "extends": "../.eslintrc", "env": { "mocha": true } } enhanced-resolve-3.4.1/test/CachedInputFileSystem.js000066400000000000000000000047251313536451300224660ustar00rootroot00000000000000var CachedInputFileSystem = require("../lib/CachedInputFileSystem"); var should = require("should"); describe("CachedInputFileSystem", function() { this.timeout(3000); var fs; beforeEach(function() { fs = new CachedInputFileSystem({ stat: function(path, callback) { setTimeout(callback.bind(null, null, { path: path }), 100); } }, 1000); }); afterEach(function() { fs.purge(); }); it("should join accesses", function(done) { fs.stat("a", function(err, result) { result.a = true; }); fs.stat("a", function(err, result) { should.exist(result.a); done(); }); }); it("should cache accesses", function(done) { fs.stat("a", function(err, result) { result.a = true; var sync = true; fs.stat("a", function(err, result) { should.exist(result.a); sync.should.be.eql(true); setTimeout(function() { fs.stat("a", function(err, result) { should.not.exist(result.a); result.b = true; var sync2 = true; fs.stat("a", function(err, result) { should.not.exist(result.a); should.exist(result.b); sync2.should.be.eql(true); done(); }); setTimeout(function() { sync2 = false; }, 50); }); }, 1100); }); setTimeout(function() { sync = false; }, 50); }); }); it("should recover after passive periods", function(done) { fs.stat("a", function(err, result) { result.a = true; setTimeout(function() { fs.stat("a", function(err, result) { should.exist(result.a); setTimeout(function() { fs.stat("a", function(err, result) { should.not.exist(result.a); result.b = true; setTimeout(function() { fs.stat("a", function(err, result) { should.not.exist(result.a); should.exist(result.b); done(); }); }, 500); }); }, 600); }); }, 500); }); }); it("should restart after timeout", function(done) { fs.stat("a", function(err, result) { result.a = true; setTimeout(function() { fs.stat("a", function(err, result) { should.not.exist(result.a); result.b = true; setTimeout(function() { fs.stat("a", function(err, result) { should.not.exist(result.a); should.exist(result.b); done(); }); }, 50); }); }, 1100); }); }); it("should cache undefined value", function(done) { fs.stat(undefined, function(err, result) { fs.purge("a"); fs.purge(); done(); }); }); }); enhanced-resolve-3.4.1/test/alias.js000066400000000000000000000056621313536451300173640ustar00rootroot00000000000000var ResolverFactory = require("../lib/ResolverFactory"); var MemoryFileSystem = require("memory-fs"); describe("alias", function() { var resolver; beforeEach(function() { var buf = new Buffer(""); // eslint-disable-line node/no-deprecated-api var fileSystem = new MemoryFileSystem({ "": true, a: { "": true, index: buf, dir: { "": true, index: buf } }, recursive: { "": true, index: buf, dir: { "": true, index: buf } }, b: { "": true, index: buf, dir: { "": true, index: buf } }, c: { "": true, index: buf, dir: { "": true, index: buf } } }); resolver = ResolverFactory.createResolver({ alias: { aliasA: "a", "b$": "a/index", "c$": "/a/index", "recursive": "recursive/dir" }, modules: "/", useSyncFileSystemCalls: true, fileSystem: fileSystem }); }); it("should resolve a not aliased module", function() { resolver.resolveSync({}, "/", "a").should.be.eql("/a/index"); resolver.resolveSync({}, "/", "a/index").should.be.eql("/a/index"); resolver.resolveSync({}, "/", "a/dir").should.be.eql("/a/dir/index"); resolver.resolveSync({}, "/", "a/dir/index").should.be.eql("/a/dir/index"); }); it("should resolve an aliased module", function() { resolver.resolveSync({}, "/", "aliasA").should.be.eql("/a/index"); resolver.resolveSync({}, "/", "aliasA/index").should.be.eql("/a/index"); resolver.resolveSync({}, "/", "aliasA/dir").should.be.eql("/a/dir/index"); resolver.resolveSync({}, "/", "aliasA/dir/index").should.be.eql("/a/dir/index"); }); it("should resolve a recursive aliased module", function() { resolver.resolveSync({}, "/", "recursive").should.be.eql("/recursive/dir/index"); resolver.resolveSync({}, "/", "recursive/index").should.be.eql("/recursive/dir/index"); resolver.resolveSync({}, "/", "recursive/dir").should.be.eql("/recursive/dir/index"); resolver.resolveSync({}, "/", "recursive/dir/index").should.be.eql("/recursive/dir/index"); }); it("should resolve a file aliased module", function() { resolver.resolveSync({}, "/", "b").should.be.eql("/a/index"); resolver.resolveSync({}, "/", "c").should.be.eql("/a/index"); }); it("should resolve a file aliased module with a query", function() { resolver.resolveSync({}, "/", "b?query").should.be.eql("/a/index?query"); resolver.resolveSync({}, "/", "c?query").should.be.eql("/a/index?query"); }); it("should resolve a path in a file aliased module", function() { resolver.resolveSync({}, "/", "b/index").should.be.eql("/b/index"); resolver.resolveSync({}, "/", "b/dir").should.be.eql("/b/dir/index"); resolver.resolveSync({}, "/", "b/dir/index").should.be.eql("/b/dir/index"); resolver.resolveSync({}, "/", "c/index").should.be.eql("/c/index"); resolver.resolveSync({}, "/", "c/dir").should.be.eql("/c/dir/index"); resolver.resolveSync({}, "/", "c/dir/index").should.be.eql("/c/dir/index"); }); }); enhanced-resolve-3.4.1/test/browserField.js000066400000000000000000000037261313536451300207210ustar00rootroot00000000000000var path = require("path"); var ResolverFactory = require("../lib/ResolverFactory"); var NodeJsInputFileSystem = require("../lib/NodeJsInputFileSystem"); var browserModule = path.join(__dirname, "fixtures", "browser-module"); function p() { return path.join.apply(path, [browserModule].concat(Array.prototype.slice.call(arguments))); } describe("browserField", function() { var resolver; beforeEach(function() { resolver = ResolverFactory.createResolver({ aliasFields: ["browser"], useSyncFileSystemCalls: true, fileSystem: new NodeJsInputFileSystem() }); }); it("should ignore", function(done) { resolver.resolve({}, p(), "./lib/ignore", function(err, result) { if(err) throw err; result.should.be.eql(false); done(); }); }); it("should ignore", function() { resolver.resolveSync({}, p(), "./lib/ignore").should.be.eql(false); resolver.resolveSync({}, p(), "./lib/ignore.js").should.be.eql(false); resolver.resolveSync({}, p("lib"), "./ignore").should.be.eql(false); resolver.resolveSync({}, p("lib"), "./ignore.js").should.be.eql(false); }); it("should replace a file", function() { resolver.resolveSync({}, p(), "./lib/replaced").should.be.eql(p("lib", "browser.js")); resolver.resolveSync({}, p(), "./lib/replaced.js").should.be.eql(p("lib", "browser.js")); resolver.resolveSync({}, p("lib"), "./replaced").should.be.eql(p("lib", "browser.js")); resolver.resolveSync({}, p("lib"), "./replaced.js").should.be.eql(p("lib", "browser.js")); }); it("should replace a module with a file", function() { resolver.resolveSync({}, p(), "module-a").should.be.eql(p("browser", "module-a.js")); resolver.resolveSync({}, p("lib"), "module-a").should.be.eql(p("browser", "module-a.js")); }); it("should replace a module with a module", function() { resolver.resolveSync({}, p(), "module-b").should.be.eql(p("node_modules", "module-c.js")); resolver.resolveSync({}, p("lib"), "module-b").should.be.eql(p("node_modules", "module-c.js")); }); }); enhanced-resolve-3.4.1/test/concord-resolve.js000066400000000000000000000106271313536451300213740ustar00rootroot00000000000000var should = require("should"); var path = require("path"); var resolve = require("../"); var fixtures = path.join(__dirname, "concord"); function testResolve(name, context, moduleName, result) { it(name, function(done) { /*var logData = []; callback.log = function(line) { logData.push(line); }*/ resolve({ environments: [ "web+es5+dom+xhr" ], referrer: "test" }, context, moduleName, callback); function callback(err, filename) { if(err) { console.log(err.details); return done(err); } //console.log(logData.join("\n")); should.exist(filename); filename.should.equal(result); done(); } }); it(name + " (sync)", function() { /*var logData = []; callback.log = function(line) { logData.push(line); }*/ var filename = resolve.sync({ environments: [ "web+es5+dom+xhr" ], referrer: "test" }, context, moduleName); should.exist(filename); filename.should.equal(result); }); } describe("concord-resolve", function() { testResolve("should prefer concord main field over normal main field (outside)", fixtures, "./main-field", path.join(fixtures, "main-field", "correct.js")); testResolve("should prefer concord main field over normal main field (inside)", path.join(fixtures, "main-field"), "./", path.join(fixtures, "main-field", "correct.js")); testResolve("should use specified extensions (outside over main)", fixtures, "./extensions", path.join(fixtures, "extensions", "file.css")); testResolve("should use specified extensions (outside)", fixtures, "./extensions/file", path.join(fixtures, "extensions", "file.css")); testResolve("should use specified extensions (inside over main)", path.join(fixtures, "extensions"), "./", path.join(fixtures, "extensions", "file.css")); testResolve("should use specified extensions (inside)", path.join(fixtures, "extensions"), "./file", path.join(fixtures, "extensions", "file.css")); testResolve("should use specified extensions (outside) (dir index)", fixtures, "./extensions/dir", path.join(fixtures, "extensions", "dir", "index.ts")); testResolve("should use specified extensions (inside) (dir index)", path.join(fixtures, "extensions"), "./dir", path.join(fixtures, "extensions", "dir", "index.ts")); testResolve("should use modules configuration, module (over main)", fixtures, "./modules", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, module (direct)", path.join(fixtures, "modules"), "module-a", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, file (direct)", path.join(fixtures, "modules"), "./wrong.js", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, file (without extension)", path.join(fixtures, "modules"), "./wrong", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, file (from sub dir)", path.join(fixtures, "modules", "sub"), "../wrong.js", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, directory (direct 1)", path.join(fixtures, "modules"), "./dir1/any", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, directory (direct 2)", path.join(fixtures, "modules"), "./dir1/any/path", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, directory (from sub dir)", path.join(fixtures, "modules", "sub"), "../dir1/any/path", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, files in directory (direct 2)", path.join(fixtures, "modules"), "./dir2/correct.js", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, files in directory (from dir)", path.join(fixtures, "modules", "dir2"), "./correct.js", path.join(fixtures, "modules", "correct.js")); testResolve("should use modules configuration, module (module)", path.join(fixtures, "modules"), "jquery", path.join(fixtures, "modules", "modules", "jquery", "index.js")); testResolve("should use modules configuration, module (file in module)", path.join(fixtures, "modules"), "jquery/file", path.join(fixtures, "modules", "modules", "jquery", "file.js")); testResolve("should use modules configuration, module (from dir)", path.join(fixtures, "modules", "dir2"), "jquery", path.join(fixtures, "modules", "modules", "jquery", "index.js")); }); enhanced-resolve-3.4.1/test/concord.js000066400000000000000000000253241313536451300177170ustar00rootroot00000000000000var concord = require("../lib/concord"); describe("concord", function() { describe("parseType", function() { var TESTS = { "hello-world": { type: "hello-world", features: [] }, "hello+world": { type: "hello", features: ["world"] }, "node+es5+es6+esmodules": { type: "node", features: ["es5", "es6", "esmodules"] }, "*+dom": { type: null, features: ["dom"] }, "*": { type: null, features: [] }, "*+hello-world": { type: null, features: ["hello-world"] } }; Object.keys(TESTS).forEach(function(key) { it("should parse " + key, function() { concord.parseType(key).should.be.eql(TESTS[key]); }); }); }); describe("isTypeMatched", function() { var TESTS = [ ["node+es5", "node+es5", true], ["node+es5", "node", true], ["node+es5", "node+es6", false], ["node+es5", "web", false], ["node+es5", "web+es5", false], ["node+es5+es6", "node+es6", true], ["node+es5+es6", "node+es7", false], ["node+es5+es6", "node+es6+es5", true], ["node+es5+es6", "node+es6+es7", false], ["node+es5+es6", "*+es5", true], ["node+es5+es6", "*+es6", true], ["node+es5+es6", "*+es7", false], ["node+es5+es6", "*", true], [{ type: "node", features: ["es5", "es6"] }, { type: "node", features: ["es5"] }, true], ["node+es5+es6", { type: "node", features: ["es5"] }, true], [{ type: "node", features: ["es5", "es6"] }, "*+es5", true] ]; TESTS.forEach(function(testCase) { it("should say '" + testCase[1] + "' is " + (testCase[2] ? "matched" : "not matched") + " in '" + testCase[0] + "'", function() { concord.isTypeMatched(testCase[0], testCase[1]).should.be.eql(testCase[2]); }); }); }); describe("isGlobMatched", function() { var TESTS = [ ["module", "module", true], ["moduleA", "moduleB", false], ["./a.js", "./a.js", true], ["./a.js", ".\\a.js", true], ["./*.js", "./abc.js", true], ["./*.js", "./dir/abc.js", false], ["./**/*.js", "./dir/abc.js", true], ["./**/*.js", "./abc.js", true], ["./**.js", "./dir/abc.js", true], ["./**.js", "./abc.js", true], ["./**", "./dir/abc.js", true], ["./**", "./abc.js", true], ["./abc-**.js", "./abc-x.js", true], ["./abc-**.js", "./abc-xyz.js", true], ["./abc-**.js", "./xyz.js", false], ["./???.js", "./abc.js", true], ["./???.js", "./abcd.js", false], ["./???.js", "./ab.js", false], ["*.js", "./abc.js", true], ["*.js", "./dir/abc.js", true], ["*.js", "./dir/abc.jsx", false], ["*.{js,jsx}", "./dir/abc.js", true], ["*.{js,jsx}", "./dir/abc.jsx", true], ["{*.js,*.jsx}", "./dir/abc.jsx", true], ["{*.js,*.jsx}", "./dir/abc.js", true], ["{module,{*.js,*.jsx}}", "module", true], ["{module,{*.js,*.jsx}}", "./dir/abc.js", true], ["{module,{*.js,*.jsx}}", "./dir/abc.jsx", true], ["module[1-5]", "module4", true], ["module[1-5]", "module7", false], ["module[!1-5]", "module4", false], ["module[!1-5]", "module7", true], ["module[!1-5]", "module77", false], ["./a,{b,c},d.js", "./a,b,d.js", true], ["./a,{b,c},d.js", "./a,c,d.js", true], ["./a,{b,c},d.js", "./a.js", false], ["./@(a|b|c).js", "./.js", false], ["./@(a|b|c).js", "./a.js", true], ["./@(a|b|c).js", "./ab.js", false], ["./@(a|b|c).js", "./abc.js", false], ["./?(a|b|c).js", "./.js", true], ["./?(a|b|c).js", "./a.js", true], ["./?(a|b|c).js", "./ab.js", false], ["./?(a|b|c).js", "./abc.js", false], ["./+(a|b|c).js", "./.js", false], ["./+(a|b|c).js", "./a.js", true], ["./+(a|b|c).js", "./ab.js", true], ["./+(a|b|c).js", "./abc.js", true], ["./*(a|b|c).js", "./.js", true], ["./*(a|b|c).js", "./a.js", true], ["./*(a|b|c).js", "./ab.js", true], ["./a|b.js", "./a.js", false], ["./a|b.js", "./a|b.js", true], ["(\\.js$)", "./dir/abc.js", true], ["(\\.js$)", "./dir/abc.js.css", false], ]; TESTS.forEach(function(testCase) { it("should say '" + testCase[1] + "' is " + (testCase[2] ? "matched" : "not matched") + " in '" + testCase[0] + "'", function() { concord.isGlobMatched(testCase[0], testCase[1]).should.be.eql(testCase[2]); }); }); }); describe("isConditionMatched", function() { var context = { supportedResourceTypes: ["promise+lazy/*", "stylesheet/sass+mixins", "stylesheet/sass+functions/incorrect"], environments: ["web+es5+dom+xhr", "web+es5+xhr"], referrer: "./main.css" }; var TESTS = { "web": true, "web+es5": true, "*+es6": false, "*+es5": true, "*+es6|*+es5": true, "*+dom": false, "!*+xhr": false, "!*+es6": true, "!*+es5|!node": true, "!*+es5|!web": false, "promise/*": true, "promise+lazy/*": true, "promise+eager/*": false, "stylesheet/sass": true, "stylesheet/sass+mixins": true, "stylesheet/sass+functions": false, "stylesheet/sass+mixins+functions": false, "referrer:*.css": true, "referrer: *.css": true, "referrer:*.js": false, "referrer: *.js": false, "referrer:./**/*": true, "referrer:./**": true, "referrer:!./**": false, "unknown:any": false, }; Object.keys(TESTS).forEach(function(key) { var expected = TESTS[key]; it("should say '" + key + "' is " + (expected ? "matched" : "not matched"), function() { concord.isConditionMatched(context, key).should.be.eql(expected); }); }); }); describe("getMain", function() { var context = { supportedResourceTypes: [], environments: ["web+es5+dom+xhr"], referrer: "module" }; var TESTS = [{ "main": "yes" }, { "main": "no", "[web]main": "yes" }, { "main": "no", "[ web ] [\t*+es5]\t\tmain": "yes" }, { "[web] main": "yes" }, { "main": "yes", "[ node ] main": "no" }, { "main": "no", "[ web ] main": "yes", "[ node ] main": "no" }, { "main": "no", "[ referrer: module ] main": "yes" }, { "main": "no", "[ web] main": "no", "[*+es5 ] main": "yes" }]; TESTS.forEach(function(testCase) { it("should get the main from " + JSON.stringify(testCase), function() { concord.getMain(context, testCase).should.be.eql("yes"); }); }); }); describe("getExtensions", function() { it("should allow to access the extensions field", function() { concord.getExtensions({}, { extensions: [".js"] }).should.be.eql([".js"]); }); }); describe("matchModule", function() { var context = { supportedResourceTypes: [], environments: ["web+es5+dom+xhr"] }; var config1 = { modules: { "./a.js": "./new-a.js", "./b.js": "./new/b.js", "./ccc/c.js": "./c.js", "./ddd/d.js": "./ddd/dd.js", "./dir/**": "./new/**", "./empty.js": false, "module": "./replacement-module.js", "templates/**": "./templates/**", "fs": "fake-fs", "abc": "./abc", "abc/**": "./dir-abc/**", "jquery**": "./jquery**", "xyz/*.js": "./not-used.js", "xyz/*.css": "./xxx/*.css", "fff/**/*.css": "./ggg/**/*.js" } }; var config2 = { modules: { "./overwrite.*": "./overwritten.*", "./overwrite.js": "./wrong", "./*.css": "./*.match", "./*.match": "./success-*.matched-css", "(regexp-([^\-]*))": "regexp/$1" } }; var TESTS = [ [{}, "./no-field.js", "./no-field.js"], [config1, "./normal.js", "./normal.js"], [config1, "./a.js", "./new-a.js"], [config1, "./b.js", "./new/b.js"], [config1, "./ccc/c.js", "./c.js"], [config1, "./ddd/d.js", "./ddd/dd.js"], [config1, "./dir/c.js", "./new/c.js"], [config1, "./dir/sub/c.js", "./new/sub/c.js"], [config1, "./empty.js", false], [config1, "module", "./replacement-module.js"], [config1, "templates/abc.ring", "./templates/abc.ring"], [config1, "fs", "fake-fs"], [config1, "abc", "./abc"], [config1, "abc/def", "./dir-abc/def"], [config1, "abc/def/ghi", "./dir-abc/def/ghi"], [config1, "jquery", "./jquery"], [config1, "jquery/jquery.js", "./jquery/jquery.js"], [config1, "xyz/rrr.js", "./not-used.js"], [config1, "xyz/rrr.css", "./xxx/rrr.css"], [config1, "fff/wfe.css", "./ggg/wfe.js"], [config1, "fff/jht/wfe.css", "./ggg/jht/wfe.js"], [config1, "fff/jht/222/wfe.css", "./ggg/jht/222/wfe.js"], [config2, "./overwrite.js", "./overwritten.js"], [config2, "./matched-again.css", "./success-matched-again.matched-css"], [config2, "./some/regexp-match.js", "./some/regexp/match.js"], [config2, "./overwrite.regexp-test.css", "./success-overwritten.regexp/test.matched-css"], ]; TESTS.forEach(function(testCase) { it("should map '" + testCase[1] + "' to '" + testCase[2] + "'", function() { var actual = concord.matchModule(context, testCase[0], testCase[1]); actual.should.be.eql(testCase[2]); }); }); it("should throw an exception on recursive configuration", function() { (function() { concord.matchModule({}, { modules: { "a": "b", "b": "c", "c": "a" } }, "b"); }).should.throw("Request 'b' matches recursively"); }); }); describe("matchType", function() { var context = { supportedResourceTypes: [], environments: ["web+es5+dom+xhr"] }; var TESTS = [ ["should get a type", { "types": { "*.test": "hello/world" } }, "hello/world"], ["should get a type from list", { "types": { "*.js": "any/javascript+commonjs", "*.test": "hello/world", "*.css": "stylesheet/css" } }, "hello/world"], ["should get a type with conditions", { "types": { "*.test": "hello/world", "[*+es5] *.test": "hello/es5", "[web] *.test": "hello/web", } }, "hello/web"], ["should get a type with complete override", { "types": { "*.test": "hello/world", "[web] *.test": "hello/wrong" }, "[web] types": { "*.js": "hello/web" } }, undefined], ["should get a type with multiple matches", { "types": { "*.test": "hello/world", "./abc.test": "hello/abs" } }, "hello/abs"], ["should get a type with multiple matches 2", { "types": { "./abc.test": "hello/abs", "*.test": "hello/world" } }, "hello/world"], ["should get a type with star match", { "types": { "./abc.test": "hello/world", "*.test": "super/*" } }, "super/hello/world"], ["should get a type without types field", {}, undefined], ]; TESTS.forEach(function(testCase) { it(testCase[0], function() { var result = concord.matchType(context, testCase[1], "./abc.test"); if(testCase[2]) result.should.be.eql(testCase[2]); else (typeof result).should.be.eql(typeof testCase[2]); }); }); it("should throw an exception on incomplete star match", function() { (function() { concord.matchType({}, { types: { "*.test": "super/*" } }, "./abc.test"); }).should.throw("value ('super/*') of key '*.test' contains '*', but there is no previous value defined"); }); }); }); enhanced-resolve-3.4.1/test/concord/000077500000000000000000000000001313536451300173535ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/extensions/000077500000000000000000000000001313536451300215525ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/extensions/dir/000077500000000000000000000000001313536451300223305ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/extensions/dir/index.js000066400000000000000000000000001313536451300237630ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/extensions/dir/index.ts000066400000000000000000000000001313536451300237750ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/extensions/file.css000066400000000000000000000000001313536451300231710ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/extensions/file.js000066400000000000000000000000001313536451300230150ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/extensions/package.json000066400000000000000000000001161313536451300240360ustar00rootroot00000000000000{ "main": "./file", "concord": { "extensions": [".css", ".ts", ".js"] } }enhanced-resolve-3.4.1/test/concord/main-field/000077500000000000000000000000001313536451300213605ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/main-field/correct.js000066400000000000000000000000001313536451300233450ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/main-field/package.json000066400000000000000000000001021313536451300236370ustar00rootroot00000000000000{ "main": "wrong.js", "concord": { "main": "./correct.js" } }enhanced-resolve-3.4.1/test/concord/main-field/wrong.js000066400000000000000000000000001313536451300230400ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/000077500000000000000000000000001313536451300210235ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/correct.js000066400000000000000000000000001313536451300230100ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/modules/000077500000000000000000000000001313536451300224735ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/modules/jquery/000077500000000000000000000000001313536451300240125ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/modules/jquery/file.js000066400000000000000000000000001313536451300252550ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/modules/jquery/index.js000066400000000000000000000000001313536451300254450ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/package.json000066400000000000000000000003351313536451300233120ustar00rootroot00000000000000{ "concord": { "main": "module-a", "modules": { "module-a": "./correct.js", "./wrong.js": "./correct.js", "./dir1/**": "./correct.js", "./dir2/*.js": "./*.js", "jquery**": "./modules/jquery**" } } }enhanced-resolve-3.4.1/test/concord/modules/sub/000077500000000000000000000000001313536451300216145ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/sub/file.txt000066400000000000000000000000001313536451300232620ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/concord/modules/wrong.js000066400000000000000000000000001313536451300225030ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/extensions.js000066400000000000000000000023221313536451300204600ustar00rootroot00000000000000var path = require("path"); require("should"); var ResolverFactory = require("../lib/ResolverFactory"); var NodeJsInputFileSystem = require("../lib/NodeJsInputFileSystem"); var CachedInputFileSystem = require("../lib/CachedInputFileSystem"); var nodeFileSystem = new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000); var resolver = ResolverFactory.createResolver({ extensions: [".ts", ".js"], fileSystem: nodeFileSystem }); var fixture = path.resolve(__dirname, "fixtures", "extensions"); describe("extensions", function() { it("should resolve according to order of provided extensions", function(done) { resolver.resolve({}, fixture, "./foo", function(err, result) { result.should.equal(path.resolve(fixture, "foo.ts")); done(); }); }); it("should resolve according to order of provided extensions (dir index)", function(done) { resolver.resolve({}, fixture, "./dir", function(err, result) { result.should.equal(path.resolve(fixture, "dir", "index.ts")); done(); }); }); it("should resolve according to main field in module root", function(done) { resolver.resolve({}, fixture, ".", function(err, result) { result.should.equal(path.resolve(fixture, "index.js")); done(); }); }); }); enhanced-resolve-3.4.1/test/fixtures/000077500000000000000000000000001313536451300175755ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/a.js000066400000000000000000000000701313536451300203500ustar00rootroot00000000000000module.exports = function a() { return "This is a"; }; enhanced-resolve-3.4.1/test/fixtures/abc.txt000066400000000000000000000000031313536451300210540ustar00rootroot00000000000000abcenhanced-resolve-3.4.1/test/fixtures/b.js000066400000000000000000000000701313536451300203510ustar00rootroot00000000000000module.exports = function b() { return "This is b"; }; enhanced-resolve-3.4.1/test/fixtures/browser-module/000077500000000000000000000000001313536451300225435ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/browser/000077500000000000000000000000001313536451300242265ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/browser/module-a.js000066400000000000000000000000001313536451300262550ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/lib/000077500000000000000000000000001313536451300233115ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/lib/browser.js000066400000000000000000000000001313536451300253200ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/lib/ignore.js000066400000000000000000000000001313536451300251200ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/lib/replaced.js000066400000000000000000000000001313536451300254140ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/node_modules/000077500000000000000000000000001313536451300252205ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/node_modules/module-a.js000066400000000000000000000000001313536451300272470ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/node_modules/module-b.js000066400000000000000000000000001313536451300272500ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/node_modules/module-c.js000066400000000000000000000000001313536451300272510ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/browser-module/package.json000066400000000000000000000002301313536451300250240ustar00rootroot00000000000000{ "browser": { "./lib/ignore.js": false, "./lib/replaced.js": "./lib/browser", "module-a": "./browser/module-a.js", "module-b": "module-c" } }enhanced-resolve-3.4.1/test/fixtures/c.js000066400000000000000000000001111313536451300203460ustar00rootroot00000000000000module.exports = function b() { require("./a"); return "This is c"; }; enhanced-resolve-3.4.1/test/fixtures/complex.js000066400000000000000000000006151313536451300216040ustar00rootroot00000000000000var complex1 = require("./lib/complex1"); require.ensure(["./lib/complex1", "complexm/step2"], function(require) { require("./lib/complex1"); var a = function() {} require.ensure(["complexm/step1"], function(require) { require("./lib/complex1"); var s1 = require("complexm/step1"); var s2 = require("complexm/step2"); console.log(s1); console.log(s2); }); }); console.log(complex1); enhanced-resolve-3.4.1/test/fixtures/dirOrFile.js000066400000000000000000000000311313536451300220040ustar00rootroot00000000000000module.exports = "file"; enhanced-resolve-3.4.1/test/fixtures/dirOrFile/000077500000000000000000000000001313536451300214545ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/dirOrFile/index.js000066400000000000000000000000301313536451300231120ustar00rootroot00000000000000module.exports = "dir"; enhanced-resolve-3.4.1/test/fixtures/directory-default/000077500000000000000000000000001313536451300232235ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/directory-default/directory-default.js000066400000000000000000000000001313536451300271750ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/000077500000000000000000000000001313536451300217745ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/dir/000077500000000000000000000000001313536451300225525ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/dir/index.js000066400000000000000000000000001313536451300242050ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/dir/index.ts000066400000000000000000000000001313536451300242170ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/foo.js000066400000000000000000000000001313536451300231030ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/foo.ts000066400000000000000000000000001313536451300231150ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/index.js000066400000000000000000000000001313536451300234270ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/index.ts000066400000000000000000000000001313536451300234410ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/extensions/package.json000066400000000000000000000000321313536451300242550ustar00rootroot00000000000000{ "main": "./index.js" }enhanced-resolve-3.4.1/test/fixtures/file.load1000066400000000000000000000000001313536451300214240ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/file.load2000066400000000000000000000000001313536451300214250ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/lib/000077500000000000000000000000001313536451300203435ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/lib/complex1.js000066400000000000000000000000411313536451300224240ustar00rootroot00000000000000module.exports = "lib complex1"; enhanced-resolve-3.4.1/test/fixtures/main1.js000066400000000000000000000002231313536451300211350ustar00rootroot00000000000000var a = require("./a"); if(x) { for(var i = 0; i < 100; i++) { while(true) require("./b"); do { i++; } while(require("m1/a")()); } } enhanced-resolve-3.4.1/test/fixtures/main2.js000066400000000000000000000002741313536451300211440ustar00rootroot00000000000000var a = require("./a"); with(x) { switch(a) { case 1: require("./b"); default: require.ensure(["m1/a"], function() { var a = require("m1/a"), b = require("m1/b"); }); } } enhanced-resolve-3.4.1/test/fixtures/main3.js000066400000000000000000000001271313536451300211420ustar00rootroot00000000000000var a = require("./a"); require.ensure([], function(require) { require("./c.js"); }); enhanced-resolve-3.4.1/test/fixtures/multiple_modules/000077500000000000000000000000001313536451300231605ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/multiple_modules/node_modules/000077500000000000000000000000001313536451300256355ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/multiple_modules/node_modules/m1/000077500000000000000000000000001313536451300261525ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/multiple_modules/node_modules/m1/a.js000066400000000000000000000001021313536451300267210ustar00rootroot00000000000000module.exports = function a() { return "This is nested m1/a"; }; enhanced-resolve-3.4.1/test/fixtures/node_modules/000077500000000000000000000000001313536451300222525ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/complexm/000077500000000000000000000000001313536451300240765ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/complexm/node_modules/000077500000000000000000000000001313536451300265535ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/complexm/node_modules/m1/000077500000000000000000000000001313536451300270705ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/complexm/node_modules/m1/a.js000066400000000000000000000000451313536451300276450ustar00rootroot00000000000000module.exports = "the correct a.js"; enhanced-resolve-3.4.1/test/fixtures/node_modules/complexm/node_modules/m1/index.js000066400000000000000000000000561313536451300305360ustar00rootroot00000000000000module.exports = " :) " + require("m2/b.js"); enhanced-resolve-3.4.1/test/fixtures/node_modules/complexm/step1.js000066400000000000000000000000621313536451300254660ustar00rootroot00000000000000module.exports = require("m1/a") + require("m1"); enhanced-resolve-3.4.1/test/fixtures/node_modules/complexm/step2.js000066400000000000000000000000321313536451300254640ustar00rootroot00000000000000module.exports = "Step2"; enhanced-resolve-3.4.1/test/fixtures/node_modules/invalidPackageJson/000077500000000000000000000000001313536451300260065ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/invalidPackageJson/package.json000066400000000000000000000000001313536451300302620ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/l-loader.js000066400000000000000000000000001313536451300242750ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/m1/000077500000000000000000000000001313536451300225675ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/m1/a.js000066400000000000000000000000731313536451300233450ustar00rootroot00000000000000module.exports = function a() { return "This is m1/a"; }; enhanced-resolve-3.4.1/test/fixtures/node_modules/m1/b.js000066400000000000000000000000731313536451300233460ustar00rootroot00000000000000module.exports = function a() { return "This is m1/b"; }; enhanced-resolve-3.4.1/test/fixtures/node_modules/m2-loader/000077500000000000000000000000001313536451300240345ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/m2-loader/b.js000066400000000000000000000001141313536451300246070ustar00rootroot00000000000000module.exports = function() { "module.exports = 'This is m2-loader/b';"; } enhanced-resolve-3.4.1/test/fixtures/node_modules/m2-loader/c.js000066400000000000000000000000001313536451300246020ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/m2/000077500000000000000000000000001313536451300225705ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/m2/b.js000066400000000000000000000000411313536451300233420ustar00rootroot00000000000000module.exports = "This is m2/b"; enhanced-resolve-3.4.1/test/fixtures/node_modules/recursive-module/000077500000000000000000000000001313536451300255445ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/recursive-module/file.js000066400000000000000000000000001313536451300270070ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/node_modules/recursive-module/index.js000066400000000000000000000000001313536451300271770ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/shortcutdir.js/000077500000000000000000000000001313536451300225625ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/fixtures/shortcutdir.js/a.js000066400000000000000000000000001313536451300233260ustar00rootroot00000000000000enhanced-resolve-3.4.1/test/missing.js000066400000000000000000000075711313536451300177450ustar00rootroot00000000000000var resolve = require("../"); var path = require("path"); var should = require("should"); describe("missing", function() { var testCases = [ [path.join(__dirname, "fixtures"), "./missing-file", [ path.join(__dirname, "fixtures", "missing-file"), path.join(__dirname, "fixtures", "missing-file.js"), path.join(__dirname, "fixtures", "missing-file.node"), ]], [path.join(__dirname, "fixtures"), "missing-module", [ path.join(__dirname, "fixtures", "node_modules", "missing-module"), path.join(__dirname, "..", "node_modules", "missing-module"), ]], [path.join(__dirname, "fixtures"), "missing-module/missing-file", [ path.join(__dirname, "fixtures", "node_modules", "missing-module", "missing-file.js"), path.join(__dirname, "..", "node_modules", "missing-module", "missing-file"), ]], [path.join(__dirname, "fixtures"), "m1/missing-file", [ path.join(__dirname, "fixtures", "node_modules", "m1", "missing-file"), path.join(__dirname, "fixtures", "node_modules", "m1", "missing-file.js"), path.join(__dirname, "fixtures", "node_modules", "m1", "missing-file.node"), path.join(__dirname, "..", "node_modules", "m1", "missing-file"), ]], [path.join(__dirname, "fixtures"), "m1/", [ path.join(__dirname, "fixtures", "node_modules", "m1", "index"), path.join(__dirname, "fixtures", "node_modules", "m1", "index.js"), path.join(__dirname, "fixtures", "node_modules", "m1", "index.json"), path.join(__dirname, "fixtures", "node_modules", "m1", "index.node"), ]], [path.join(__dirname, "fixtures"), "m1/a", [ path.join(__dirname, "fixtures", "node_modules", "m1", "a") ]], ]; testCases.forEach(function(testCase) { it("should tell about missing file when trying to resolve " + testCase[1], function(done) { var callback = function(err, filename) { if(err) { err.missing.sort().should.containDeep(testCase[2].sort()); callback.missing.sort().should.containDeep(testCase[2].sort()); resolve(testCase[0], testCase[1], function(err) { err.missing.sort().should.containDeep(testCase[2].sort()); done(); }); return; } callback.missing.sort().should.containDeep(testCase[2].sort()); done(); }; callback.missing = []; resolve(testCase[0], testCase[1], callback); }); it("should tell about missing file in the callback's error object when trying to resolve " + testCase[1], function(done) { var callback = function(err, filename) { if(err) { err.missing.sort().should.containDeep(testCase[2].sort()); resolve(testCase[0], testCase[1], function(err) { err.missing.sort().should.containDeep(testCase[2].sort()); done(); }); return; } done(); }; resolve(testCase[0], testCase[1], callback); }); it("should report error details exactly once when trying to resolve " + testCase[1], function(done) { var callback = function(err, filename) { if(err) { var details = err.details.split("\n"); var firstDetail = details.shift(); should.notEqual(firstDetail.indexOf(testCase[1]), -1); details.should.not.containDeep([firstDetail]); } done(); }; resolve(testCase[0], testCase[1], callback); }); it("should report missing files exactly once when trying to resolve " + testCase[1], function(done) { var callback = function(err, filename) { if(err) { var missing = err.missing.sort(); var isSame = true; for(var i = 0; i < missing.length - 1; i += 2) { isSame = isSame && (missing[i] === missing[i + 1]); } isSame.should.not.be.true("missing file names should not be repeated"); } done(); }; resolve(testCase[0], testCase[1], callback); }); it("should tell about missing file when trying to resolve sync " + testCase[1], function() { try { resolve.sync(testCase[0], testCase[1]); } catch(err) { err.missing.sort().should.containDeep(testCase[2].sort()); } }); }); }); enhanced-resolve-3.4.1/test/plugins.js000066400000000000000000000012511313536451300177420ustar00rootroot00000000000000var ResolverFactory = require("../").ResolverFactory; var CloneBasenamePlugin = require("../lib/CloneBasenamePlugin"); var path = require("path"); describe("plugins", function() { it("should resolve with the CloneBasenamePlugin", function(done) { var resolver = ResolverFactory.createResolver({ fileSystem: require("fs"), plugins: [ new CloneBasenamePlugin("after-existing-directory", "undescribed-raw-file") ] }); resolver.resolve({}, __dirname, "./fixtures/directory-default", function(err, result) { if(err) return done(err); result.should.be.eql(path.resolve(__dirname, "fixtures/directory-default/directory-default.js")); done(); }); }); }); enhanced-resolve-3.4.1/test/pr-53.js000066400000000000000000000005571313536451300171370ustar00rootroot00000000000000var CachedInputFileSystem = require("../lib/CachedInputFileSystem"); describe("pr-53", function() { it("should allow to readJsonSync in CachedInputFileSystem", function() { var cfs = new CachedInputFileSystem({ readFileSync: function(path) { return JSON.stringify("abc" + path); } }, 1000); cfs.readJsonSync("xyz").should.be.eql("abcxyz"); }); }); enhanced-resolve-3.4.1/test/resolve.js000066400000000000000000000112221313536451300177370ustar00rootroot00000000000000/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ var should = require("should"); var path = require("path"); var resolve = require("../"); var fixtures = path.join(__dirname, "fixtures"); function testResolve(name, context, moduleName, result) { describe(name, function() { it("should resolve sync correctly", function() { var filename = resolve.sync(context, moduleName); should.exist(filename); filename.should.equal(result); }); it("should resolve async correctly", function(done) { resolve(context, moduleName, function(err, filename) { if(err) return done(err); should.exist(filename); filename.should.equal(result); done(); }); }); }); } function testResolveLoader(name, context, moduleName, result) { describe(name, function() { it("should resolve sync correctly", function() { var filename = resolve.loader.sync(context, moduleName); should.exist(filename); filename.should.equal(result); }); it("should resolve async correctly", function(done) { resolve.loader(context, moduleName, function(err, filename) { if(err) return done(err); should.exist(filename); filename.should.equal(result); done(); }); }); }); } function testResolveContext(name, context, moduleName, result) { describe(name, function() { it("should resolve async correctly", function(done) { resolve.context(context, moduleName, function(err, filename) { if(err) done(err); should.exist(filename); filename.should.equal(result); done(); }); }); it("should resolve sync correctly", function() { var filename = resolve.context.sync(context, moduleName); should.exist(filename); filename.should.equal(result); }); }); } describe("resolve", function() { testResolve("absolute path", fixtures, path.join(fixtures, "main1.js"), path.join(fixtures, "main1.js")); testResolve("file with .js", fixtures, "./main1.js", path.join(fixtures, "main1.js")); testResolve("file without extension", fixtures, "./main1", path.join(fixtures, "main1.js")); testResolve("another file with .js", fixtures, "./a.js", path.join(fixtures, "a.js")); testResolve("another file without extension", fixtures, "./a", path.join(fixtures, "a.js")); testResolve("file in module with .js", fixtures, "m1/a.js", path.join(fixtures, "node_modules", "m1", "a.js")); testResolve("file in module without extension", fixtures, "m1/a", path.join(fixtures, "node_modules", "m1", "a.js")); testResolve("another file in module without extension", fixtures, "complexm/step1", path.join(fixtures, "node_modules", "complexm", "step1.js")); testResolve("from submodule to file in sibling module", path.join(fixtures, "node_modules", "complexm"), "m2/b.js", path.join(fixtures, "node_modules", "m2", "b.js")); testResolve("from submodule to file in sibling of parent module", path.join(fixtures, "node_modules", "complexm", "web_modules", "m1"), "m2/b.js", path.join(fixtures, "node_modules", "m2", "b.js")); testResolve("from nested directory to overwritten file in module", path.join(fixtures, "multiple_modules"), "m1/a.js", path.join(fixtures, "multiple_modules", "node_modules", "m1", "a.js")); testResolve("from nested directory to not overwritten file in module", path.join(fixtures, "multiple_modules"), "m1/b.js", path.join(fixtures, "node_modules", "m1", "b.js")); testResolve("file with query", fixtures, "./main1.js?query", path.join(fixtures, "main1.js") + "?query"); testResolve("file in module with query", fixtures, "m1/a?query", path.join(fixtures, "node_modules", "m1", "a.js") + "?query"); testResolveContext("context for fixtures", fixtures, "./", fixtures); testResolveContext("context for fixtures/lib", fixtures, "./lib", path.join(fixtures, "lib")); testResolveContext("context for fixtures with ..", fixtures, "./lib/../../fixtures/./lib/..", fixtures); testResolveContext("context for fixtures with query", fixtures, "./?query", fixtures + "?query"); testResolve("differ between directory and file, resolve file", fixtures, "./dirOrFile", path.join(fixtures, "dirOrFile.js")); testResolve("differ between directory and file, resolve directory", fixtures, "./dirOrFile/", path.join(fixtures, "dirOrFile", "index.js")); testResolveLoader("loader with template without extension", fixtures, "m2/b", path.join(fixtures, "node_modules", "m2-loader", "b.js")); testResolveLoader("loader with template as file", fixtures, "l", path.join(fixtures, "node_modules", "l-loader.js")); testResolve("find node_modules outside of node_modules", path.join(fixtures, "browser-module", "node_modules"), "m1/a", path.join(fixtures, "node_modules", "m1", "a.js")); }); enhanced-resolve-3.4.1/test/simple.js000066400000000000000000000020621313536451300175530ustar00rootroot00000000000000var resolve = require("../"); var should = require("should"); var path = require("path"); describe("simple", function() { var pathsToIt = [ [__dirname, "../lib/node", "direct"], [__dirname, "../", "as directory"], [path.join(__dirname, "..", ".."), "./enhanced-resolve", "as module"], [path.join(__dirname, "..", ".."), "./enhanced-resolve/lib/node", "in module"] ]; pathsToIt.forEach(function(pathToIt) { it("should resolve itself " + pathToIt[2], function(done) { resolve(pathToIt[0], pathToIt[1], function(err, filename) { if(err) return done(new Error([err.message, err.stack, err.details].join("\n"))); should.exist(filename); filename.should.have.type("string"); filename.should.be.eql(path.join(__dirname, "..", "lib", "node.js")); done(); }); }); it("should resolve itself sync " + pathToIt[2], function() { var filename = resolve.sync(pathToIt[0], pathToIt[1]); should.exist(filename); filename.should.have.type("string"); filename.should.be.eql(path.join(__dirname, "..", "lib", "node.js")); }); }); }); enhanced-resolve-3.4.1/test/symlink.js000066400000000000000000000124071313536451300177540ustar00rootroot00000000000000var resolve = require("../"); var should = require("should"); var path = require("path"); var fs = require("fs"); var tempPath = path.join(__dirname, "temp"); describe("symlink", function() { var isAdmin = true; try { fs.mkdirSync(tempPath); fs.symlinkSync(path.join(__dirname, "..", "lib", "node.js"), path.join(tempPath, "test"), "file"); fs.symlinkSync(path.join(__dirname, "..", "lib"), path.join(tempPath, "test2"), "dir"); } catch(e) { isAdmin = false; } try { fs.unlinkSync(path.join(tempPath, "test")); } catch(e) { isAdmin = false; } try { fs.unlinkSync(path.join(tempPath, "test2")); } catch(e) { isAdmin = false; } try { fs.rmdirSync(tempPath); } catch(e) { isAdmin = false; } if(isAdmin) { before(function() { // Create some cool symlinks try { fs.mkdirSync(tempPath); fs.symlinkSync(path.join(__dirname, "..", "lib", "node.js"), path.join(tempPath, "node.js"), "file"); fs.symlinkSync(path.join(__dirname, "..", "lib"), path.join(tempPath, "lib"), "dir"); fs.symlinkSync(path.join(__dirname, ".."), path.join(tempPath, "this"), "dir"); fs.symlinkSync(path.join(tempPath, "this"), path.join(tempPath, "that"), "dir"); fs.symlinkSync(path.join("..", "..", "lib", "node.js"), path.join(tempPath, "node.relative.js"), "file"); fs.symlinkSync(path.join(".", "node.relative.js"), path.join(tempPath, "node.relative.sym.js"), "file"); } catch(e) {} }); after(function() { fs.unlinkSync(path.join(tempPath, "node.js")); fs.unlinkSync(path.join(tempPath, "node.relative.js")); fs.unlinkSync(path.join(tempPath, "node.relative.sym.js")); fs.unlinkSync(path.join(tempPath, "lib")); fs.unlinkSync(path.join(tempPath, "this")); fs.unlinkSync(path.join(tempPath, "that")); fs.rmdirSync(tempPath); }); var resolveWithoutSymlinks = resolve.create({ symlinks: false }); var resolveSyncWithoutSymlinks = resolve.create.sync({ symlinks: false }); [ [tempPath, "./node.js", "with a symlink to a file"], [tempPath, "./node.relative.js", "with a relative symlink to a file"], [tempPath, "./node.relative.sym.js", "with a relative symlink to a symlink to a file"], [tempPath, "./lib/node.js", "with a symlink to a directory 1"], [tempPath, "./this/lib/node.js", "with a symlink to a directory 2"], [tempPath, "./this/test/temp/node.js", "with multiple symlinks in the path 1"], [tempPath, "./this/test/temp/lib/node.js", "with multiple symlinks in the path 2"], [tempPath, "./this/test/temp/this/lib/node.js", "with multiple symlinks in the path 3"], [tempPath, "./that/lib/node.js", "with a symlink to a directory 2 (chained)"], [tempPath, "./that/test/temp/node.js", "with multiple symlinks in the path 1 (chained)"], [tempPath, "./that/test/temp/lib/node.js", "with multiple symlinks in the path 2 (chained)"], [tempPath, "./that/test/temp/that/lib/node.js", "with multiple symlinks in the path 3 (chained)"], [path.join(tempPath, "lib"), "./node.js", "with symlinked directory as context 1"], [path.join(tempPath, "this"), "./lib/node.js", "with symlinked directory as context 2"], [path.join(tempPath, "this"), "./test/temp/lib/node.js", "with symlinked directory as context and in path"], [path.join(tempPath, "this", "lib"), "./node.js", "with symlinked directory in context path"], [path.join(tempPath, "this", "test"), "./temp/node.js", "with symlinked directory in context path and symlinked file"], [path.join(tempPath, "this", "test"), "./temp/lib/node.js", "with symlinked directory in context path and symlinked directory"], [path.join(tempPath, "that"), "./lib/node.js", "with symlinked directory as context 2 (chained)"], [path.join(tempPath, "that"), "./test/temp/lib/node.js", "with symlinked directory as context and in path (chained)"], [path.join(tempPath, "that", "lib"), "./node.js", "with symlinked directory in context path (chained)"], [path.join(tempPath, "that", "test"), "./temp/node.js", "with symlinked directory in context path and symlinked file (chained)"], [path.join(tempPath, "that", "test"), "./temp/lib/node.js", "with symlinked directory in context path and symlinked directory (chained)"], ].forEach(function(pathToIt) { it("should resolve symlink to itself " + pathToIt[2], function(done) { resolve(pathToIt[0], pathToIt[1], function(err, filename) { if(err) return done(err); should.exist(filename); filename.should.have.type("string"); filename.should.be.eql(path.join(__dirname, "..", "lib", "node.js")); resolveWithoutSymlinks(pathToIt[0], pathToIt[1], function(err, filename) { if(err) return done(err); filename.should.have.type("string"); filename.should.be.eql(path.resolve(pathToIt[0], pathToIt[1])); done(); }); }); }); it("should resolve symlink to itself sync " + pathToIt[2], function() { var filename = resolve.sync(pathToIt[0], pathToIt[1]); should.exist(filename); filename.should.have.type("string"); filename.should.be.eql(path.join(__dirname, "..", "lib", "node.js")); filename = resolveSyncWithoutSymlinks(pathToIt[0], pathToIt[1]); filename.should.have.type("string"); filename.should.be.eql(path.resolve(pathToIt[0], pathToIt[1])); }); }); } else { it("cannot test symlinks because we have no permission to create them"); } }); enhanced-resolve-3.4.1/test/unsafe-cache.js000066400000000000000000000063231313536451300206100ustar00rootroot00000000000000var resolve = require("../"); var path = require("path"); describe("unsafe-cache", function() { var cache; var cachedResolve; var context; var otherContext; beforeEach(function() { context = { some: "context" }; otherContext = { someOther: "context" }; }); describe("with no other options", function() { beforeEach(function() { cache = {}; cachedResolve = resolve.create({ unsafeCache: cache }); }); it("should cache request", function(done) { cachedResolve(path.join(__dirname, "fixtures"), "m2/b", function(err, result) { if(err) return done(err); Object.keys(cache).should.have.length(2); Object.keys(cache).forEach(function(key) { cache[key] = { path: "yep" }; }); cachedResolve(path.join(__dirname, "fixtures"), "m2/b", function(err, result) { if(err) return done(err); result.should.be.eql("yep"); done(); }); }); }); it("should not return from cache if context does not match", function(done) { cachedResolve(context, path.join(__dirname, "fixtures"), "m2/b", function(err, result) { if(err) return done(err); Object.keys(cache).should.have.length(2); Object.keys(cache).forEach(function(key) { cache[key] = { path: "yep" }; }); cachedResolve(otherContext, path.join(__dirname, "fixtures"), "m2/b", function(err, result) { if(err) return done(err); result.should.not.be.eql("yep"); done(); }); }); }); it("should not return from cache if query does not match", function(done) { cachedResolve(path.join(__dirname, "fixtures"), "m2/b?query", function(err, result) { if(err) return done(err); Object.keys(cache).should.have.length(2); Object.keys(cache).forEach(function(key) { cache[key] = { path: "yep" }; }); cachedResolve(path.join(__dirname, "fixtures"), "m2/b?query2", function(err, result) { if(err) return done(err); result.should.not.be.eql("yep"); done(); }); }); }); }); describe("with cacheWithContext false", function() { beforeEach(function() { cache = {}; cachedResolve = resolve.create({ unsafeCache: cache, cacheWithContext: false }); }); it("should cache request", function(done) { cachedResolve(context, path.join(__dirname, "fixtures"), "m2/b", function(err, result) { if(err) return done(err); Object.keys(cache).should.have.length(2); Object.keys(cache).forEach(function(key) { cache[key] = { path: "yep" }; }); cachedResolve(context, path.join(__dirname, "fixtures"), "m2/b", function(err, result) { if(err) return done(err); result.should.be.eql("yep"); done(); }); }); }); it("should return from cache even if context does not match", function(done) { cachedResolve(context, path.join(__dirname, "fixtures"), "m2/b", function(err, result) { if(err) return done(err); Object.keys(cache).should.have.length(2); Object.keys(cache).forEach(function(key) { cache[key] = { path: "yep" }; }); cachedResolve(otherContext, path.join(__dirname, "fixtures"), "m2/b", function(err, result) { if(err) return done(err); result.should.be.eql("yep"); done(); }); }); }); }); });