JezK
Edit File: generate-pnp-map-api.tpl.js
#!$$SHEBANG /* eslint-disable max-len, flowtype/require-valid-file-annotation, flowtype/require-return-type */ /* global packageInformationStores, $$BLACKLIST, $$SETUP_STATIC_TABLES */ // Used for the resolveUnqualified part of the resolution (ie resolving folder/index.js & file extensions) // Deconstructed so that they aren't affected by any fs monkeypatching occuring later during the execution "use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); function _slicedToArray2() { var data = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); _slicedToArray2 = function _slicedToArray2() { return data; }; return data; } function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } var _require = require('fs'), statSync = _require.statSync, lstatSync = _require.lstatSync, readlinkSync = _require.readlinkSync, readFileSync = _require.readFileSync, existsSync = _require.existsSync, realpathSync = _require.realpathSync; var Module = require('module'); var path = require('path'); var StringDecoder = require('string_decoder'); var ignorePattern = $$BLACKLIST ? new RegExp($$BLACKLIST) : null; var pnpFile = path.resolve(__dirname, __filename); var builtinModules = new Set(Module.builtinModules || Object.keys(process.binding('natives'))); var topLevelLocator = { name: null, reference: null }; var blacklistedLocator = { name: NaN, reference: NaN }; // Used for compatibility purposes - cf setupCompatibilityLayer var patchedModules = []; var fallbackLocators = [topLevelLocator]; // Matches backslashes of Windows paths var backwardSlashRegExp = /\\/g; // Matches if the path must point to a directory (ie ends with /) var isDirRegExp = /\/$/; // Matches if the path starts with a valid path qualifier (./, ../, /) // eslint-disable-next-line no-unused-vars var isStrictRegExp = /^\.{0,2}\//; // Splits a require request into its components, or return null if the request is a file path var pathRegExp = /^(?![a-zA-Z]:[\\\/]|\\\\|\.{0,2}(?:\/|$))((?:@[^\/]+\/)?[^\/]+)\/?(.*|)$/; // Keep a reference around ("module" is a common name in this context, so better rename it to something more significant) var pnpModule = module; /** * Used to disable the resolution hooks (for when we want to fallback to the previous resolution - we then need * a way to "reset" the environment temporarily) */ var enableNativeHooks = true; /** * Simple helper function that assign an error code to an error, so that it can more easily be caught and used * by third-parties. */ function makeError(code, message) { var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var error = new Error(message); return Object.assign(error, { code: code, data: data }); } /** * Ensures that the returned locator isn't a blacklisted one. * * Blacklisted packages are packages that cannot be used because their dependencies cannot be deduced. This only * happens with peer dependencies, which effectively have different sets of dependencies depending on their parents. * * In order to deambiguate those different sets of dependencies, the Yarn implementation of PnP will generate a * symlink for each combination of <package name>/<package version>/<dependent package> it will find, and will * blacklist the target of those symlinks. By doing this, we ensure that files loaded through a specific path * will always have the same set of dependencies, provided the symlinks are correctly preserved. * * Unfortunately, some tools do not preserve them, and when it happens PnP isn't able anymore to deduce the set of * dependencies based on the path of the file that makes the require calls. But since we've blacklisted those paths, * we're able to print a more helpful error message that points out that a third-party package is doing something * incompatible! */ // eslint-disable-next-line no-unused-vars function blacklistCheck(locator) { if (locator === blacklistedLocator) { throw makeError("BLACKLISTED", ["A package has been resolved through a blacklisted path - this is usually caused by one of your tools calling", "\"realpath\" on the return value of \"require.resolve\". Since the returned values use symlinks to disambiguate", "peer dependencies, they must be passed untransformed to \"require\"."].join(" ")); } return locator; } $$SETUP_STATIC_TABLES(); /** * Returns the module that should be used to resolve require calls. It's usually the direct parent, except if we're * inside an eval expression. */ function getIssuerModule(parent) { var issuer = parent; while (issuer && (issuer.id === '[eval]' || issuer.id === '<repl>' || !issuer.filename)) { issuer = issuer.parent; } return issuer; } /** * Returns information about a package in a safe way (will throw if they cannot be retrieved) */ function getPackageInformationSafe(packageLocator) { var packageInformation = exports.getPackageInformation(packageLocator); if (!packageInformation) { throw makeError("INTERNAL", "Couldn't find a matching entry in the dependency tree for the specified parent (this is probably an internal error)"); } return packageInformation; } /** * Implements the node resolution for folder access and extension selection */ function applyNodeExtensionResolution(unqualifiedPath, _ref) { var extensions = _ref.extensions; // We use this "infinite while" so that we can restart the process as long as we hit package folders while (true) { var stat = void 0; try { stat = statSync(unqualifiedPath); } catch (error) {} // If the file exists and is a file, we can stop right there if (stat && !stat.isDirectory()) { // If the very last component of the resolved path is a symlink to a file, we then resolve it to a file. We only // do this first the last component, and not the rest of the path! This allows us to support the case of bin // symlinks, where a symlink in "/xyz/pkg-name/.bin/bin-name" will point somewhere else (like "/xyz/pkg-name/index.js"). // In such a case, we want relative requires to be resolved relative to "/xyz/pkg-name/" rather than "/xyz/pkg-name/.bin/". // // Also note that the reason we must use readlink on the last component (instead of realpath on the whole path) // is that we must preserve the other symlinks, in particular those used by pnp to deambiguate packages using // peer dependencies. For example, "/xyz/.pnp/local/pnp-01234569/.bin/bin-name" should see its relative requires // be resolved relative to "/xyz/.pnp/local/pnp-0123456789/" rather than "/xyz/pkg-with-peers/", because otherwise // we would lose the information that would tell us what are the dependencies of pkg-with-peers relative to its // ancestors. if (lstatSync(unqualifiedPath).isSymbolicLink()) { unqualifiedPath = path.normalize(path.resolve(path.dirname(unqualifiedPath), readlinkSync(unqualifiedPath))); } return unqualifiedPath; } // If the file is a directory, we must check if it contains a package.json with a "main" entry if (stat && stat.isDirectory()) { var pkgJson = void 0; try { pkgJson = JSON.parse(readFileSync("".concat(unqualifiedPath, "/package.json"), 'utf-8')); } catch (error) {} var nextUnqualifiedPath = void 0; if (pkgJson && pkgJson.main) { nextUnqualifiedPath = path.resolve(unqualifiedPath, pkgJson.main); } // If the "main" field changed the path, we start again from this new location if (nextUnqualifiedPath && nextUnqualifiedPath !== unqualifiedPath) { var resolution = applyNodeExtensionResolution(nextUnqualifiedPath, { extensions: extensions }); if (resolution !== null) { return resolution; } } } // Otherwise we check if we find a file that match one of the supported extensions var qualifiedPath = extensions.map(function (extension) { return "".concat(unqualifiedPath).concat(extension); }).find(function (candidateFile) { return existsSync(candidateFile); }); if (qualifiedPath) { return qualifiedPath; } // Otherwise, we check if the path is a folder - in such a case, we try to use its index if (stat && stat.isDirectory()) { var indexPath = extensions.map(function (extension) { return "".concat(unqualifiedPath, "/index").concat(extension); }).find(function (candidateFile) { return existsSync(candidateFile); }); if (indexPath) { return indexPath; } } // Otherwise there's nothing else we can do :( return null; } } /** * This function creates fake modules that can be used with the _resolveFilename function. * Ideally it would be nice to be able to avoid this, since it causes useless allocations * and cannot be cached efficiently (we recompute the nodeModulePaths every time). * * Fortunately, this should only affect the fallback, and there hopefully shouldn't be a * lot of them. */ function makeFakeModule(path) { var fakeModule = new Module(path, false); fakeModule.filename = path; fakeModule.paths = Module._nodeModulePaths(path); return fakeModule; } /** * Normalize path to posix format. */ function normalizePath(fsPath) { fsPath = path.normalize(fsPath); if (process.platform === 'win32') { fsPath = fsPath.replace(backwardSlashRegExp, '/'); } return fsPath; } /** * Forward the resolution to the next resolver (usually the native one) */ function callNativeResolution(request, issuer) { if (issuer.endsWith('/')) { issuer += 'internal.js'; } try { enableNativeHooks = false; // Since we would need to create a fake module anyway (to call _resolveLookupPath that // would give us the paths to give to _resolveFilename), we can as well not use // the {paths} option at all, since it internally makes _resolveFilename create another // fake module anyway. return Module._resolveFilename(request, makeFakeModule(issuer), false); } finally { enableNativeHooks = true; } } /** * This key indicates which version of the standard is implemented by this resolver. The `std` key is the * Plug'n'Play standard, and any other key are third-party extensions. Third-party extensions are not allowed * to override the standard, and can only offer new methods. * * If an new version of the Plug'n'Play standard is released and some extensions conflict with newly added * functions, they'll just have to fix the conflicts and bump their own version number. */ exports.VERSIONS = { std: 1 }; /** * Useful when used together with getPackageInformation to fetch information about the top-level package. */ exports.topLevel = { name: null, reference: null }; /** * Gets the package information for a given locator. Returns null if they cannot be retrieved. */ exports.getPackageInformation = function getPackageInformation(_ref2) { var name = _ref2.name, reference = _ref2.reference; var packageInformationStore = packageInformationStores.get(name); if (!packageInformationStore) { return null; } var packageInformation = packageInformationStore.get(reference); if (!packageInformation) { return null; } return packageInformation; }; /** * Transforms a request (what's typically passed as argument to the require function) into an unqualified path. * This path is called "unqualified" because it only changes the package name to the package location on the disk, * which means that the end result still cannot be directly accessed (for example, it doesn't try to resolve the * file extension, or to resolve directories to their "index.js" content). Use the "resolveUnqualified" function * to convert them to fully-qualified paths, or just use "resolveRequest" that do both operations in one go. * * Note that it is extremely important that the `issuer` path ends with a forward slash if the issuer is to be * treated as a folder (ie. "/tmp/foo/" rather than "/tmp/foo" if "foo" is a directory). Otherwise relative * imports won't be computed correctly (they'll get resolved relative to "/tmp/" instead of "/tmp/foo/"). */ exports.resolveToUnqualified = function resolveToUnqualified(request, issuer) { var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, _ref3$considerBuiltin = _ref3.considerBuiltins, considerBuiltins = _ref3$considerBuiltin === void 0 ? true : _ref3$considerBuiltin; // The 'pnpapi' request is reserved and will always return the path to the PnP file, from everywhere if (request === "pnpapi") { return pnpFile; } // Bailout if the request is a native module if (considerBuiltins && builtinModules.has(request)) { return null; } // We allow disabling the pnp resolution for some subpaths. This is because some projects, often legacy, // contain multiple levels of dependencies (ie. a yarn.lock inside a subfolder of a yarn.lock). This is // typically solved using workspaces, but not all of them have been converted already. if (ignorePattern && ignorePattern.test(normalizePath(issuer))) { var result = callNativeResolution(request, issuer); if (result === false) { throw makeError("BUILTIN_NODE_RESOLUTION_FAIL", "The builtin node resolution algorithm was unable to resolve the module referenced by \"".concat(request, "\" and requested from \"").concat(issuer, "\" (it didn't go through the pnp resolver because the issuer was explicitely ignored by the regexp \"$$BLACKLIST\")"), { request: request, issuer: issuer }); } return result; } var unqualifiedPath; // If the request is a relative or absolute path, we just return it normalized var dependencyNameMatch = request.match(pathRegExp); if (!dependencyNameMatch) { if (path.isAbsolute(request)) { unqualifiedPath = path.normalize(request); } else if (issuer.match(isDirRegExp)) { unqualifiedPath = path.normalize(path.resolve(issuer, request)); } else { unqualifiedPath = path.normalize(path.resolve(path.dirname(issuer), request)); } } // Things are more hairy if it's a package require - we then need to figure out which package is needed, and in // particular the exact version for the given location on the dependency tree if (dependencyNameMatch) { var _dependencyNameMatch = (0, _slicedToArray2()["default"])(dependencyNameMatch, 3), dependencyName = _dependencyNameMatch[1], subPath = _dependencyNameMatch[2]; var issuerLocator = exports.findPackageLocator(issuer); // If the issuer file doesn't seem to be owned by a package managed through pnp, then we resort to using the next // resolution algorithm in the chain, usually the native Node resolution one if (!issuerLocator) { var _result = callNativeResolution(request, issuer); if (_result === false) { throw makeError("BUILTIN_NODE_RESOLUTION_FAIL", "The builtin node resolution algorithm was unable to resolve the module referenced by \"".concat(request, "\" and requested from \"").concat(issuer, "\" (it didn't go through the pnp resolver because the issuer doesn't seem to be part of the Yarn-managed dependency tree)"), { request: request, issuer: issuer }); } return _result; } var issuerInformation = getPackageInformationSafe(issuerLocator); // We obtain the dependency reference in regard to the package that request it var dependencyReference = issuerInformation.packageDependencies.get(dependencyName); // If we can't find it, we check if we can potentially load it from the packages that have been defined as potential fallbacks. // It's a bit of a hack, but it improves compatibility with the existing Node ecosystem. Hopefully we should eventually be able // to kill this logic and become stricter once pnp gets enough traction and the affected packages fix themselves. if (issuerLocator !== topLevelLocator) { for (var t = 0, T = fallbackLocators.length; dependencyReference === undefined && t < T; ++t) { var fallbackInformation = getPackageInformationSafe(fallbackLocators[t]); dependencyReference = fallbackInformation.packageDependencies.get(dependencyName); } } // If we can't find the path, and if the package making the request is the top-level, we can offer nicer error messages if (!dependencyReference) { if (dependencyReference === null) { if (issuerLocator === topLevelLocator) { throw makeError("MISSING_PEER_DEPENDENCY", "You seem to be requiring a peer dependency (\"".concat(dependencyName, "\"), but it is not installed (which might be because you're the top-level package)"), { request: request, issuer: issuer, dependencyName: dependencyName }); } else { throw makeError("MISSING_PEER_DEPENDENCY", "Package \"".concat(issuerLocator.name, "@").concat(issuerLocator.reference, "\" is trying to access a peer dependency (\"").concat(dependencyName, "\") that should be provided by its direct ancestor but isn't"), { request: request, issuer: issuer, issuerLocator: Object.assign({}, issuerLocator), dependencyName: dependencyName }); } } else { if (issuerLocator === topLevelLocator) { throw makeError("UNDECLARED_DEPENDENCY", "You cannot require a package (\"".concat(dependencyName, "\") that is not declared in your dependencies (via \"").concat(issuer, "\")"), { request: request, issuer: issuer, dependencyName: dependencyName }); } else { var candidates = Array.from(issuerInformation.packageDependencies.keys()); throw makeError("UNDECLARED_DEPENDENCY", "Package \"".concat(issuerLocator.name, "@").concat(issuerLocator.reference, "\" (via \"").concat(issuer, "\") is trying to require the package \"").concat(dependencyName, "\" (via \"").concat(request, "\") without it being listed in its dependencies (").concat(candidates.join(", "), ")"), { request: request, issuer: issuer, issuerLocator: Object.assign({}, issuerLocator), dependencyName: dependencyName, candidates: candidates }); } } } // We need to check that the package exists on the filesystem, because it might not have been installed var dependencyLocator = { name: dependencyName, reference: dependencyReference }; var dependencyInformation = exports.getPackageInformation(dependencyLocator); var dependencyLocation = path.resolve(__dirname, dependencyInformation.packageLocation); if (!dependencyLocation) { throw makeError("MISSING_DEPENDENCY", "Package \"".concat(dependencyLocator.name, "@").concat(dependencyLocator.reference, "\" is a valid dependency, but hasn't been installed and thus cannot be required (it might be caused if you install a partial tree, such as on production environments)"), { request: request, issuer: issuer, dependencyLocator: Object.assign({}, dependencyLocator) }); } // Now that we know which package we should resolve to, we only have to find out the file location if (subPath) { unqualifiedPath = path.resolve(dependencyLocation, subPath); } else { unqualifiedPath = dependencyLocation; } } return path.normalize(unqualifiedPath); }; /** * Transforms an unqualified path into a qualified path by using the Node resolution algorithm (which automatically * appends ".js" / ".json", and transforms directory accesses into "index.js"). */ exports.resolveUnqualified = function resolveUnqualified(unqualifiedPath) { var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref4$extensions = _ref4.extensions, extensions = _ref4$extensions === void 0 ? Object.keys(Module._extensions) : _ref4$extensions; var qualifiedPath = applyNodeExtensionResolution(unqualifiedPath, { extensions: extensions }); if (qualifiedPath) { return path.normalize(qualifiedPath); } else { throw makeError("QUALIFIED_PATH_RESOLUTION_FAILED", "Couldn't find a suitable Node resolution for unqualified path \"".concat(unqualifiedPath, "\""), { unqualifiedPath: unqualifiedPath }); } }; /** * Transforms a request into a fully qualified path. * * Note that it is extremely important that the `issuer` path ends with a forward slash if the issuer is to be * treated as a folder (ie. "/tmp/foo/" rather than "/tmp/foo" if "foo" is a directory). Otherwise relative * imports won't be computed correctly (they'll get resolved relative to "/tmp/" instead of "/tmp/foo/"). */ exports.resolveRequest = function resolveRequest(request, issuer) { var _ref5 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, considerBuiltins = _ref5.considerBuiltins, extensions = _ref5.extensions; var unqualifiedPath; try { unqualifiedPath = exports.resolveToUnqualified(request, issuer, { considerBuiltins: considerBuiltins }); } catch (originalError) { // If we get a BUILTIN_NODE_RESOLUTION_FAIL error there, it means that we've had to use the builtin node // resolution, which usually shouldn't happen. It might be because the user is trying to require something // from a path loaded through a symlink (which is not possible, because we need something normalized to // figure out which package is making the require call), so we try to make the same request using a fully // resolved issuer and throws a better and more actionable error if it works. if (originalError.code === "BUILTIN_NODE_RESOLUTION_FAIL") { var realIssuer; try { realIssuer = realpathSync(issuer); } catch (error) {} if (realIssuer) { if (issuer.endsWith("/")) { realIssuer = realIssuer.replace(/\/?$/, "/"); } try { exports.resolveToUnqualified(request, realIssuer, { considerBuiltins: considerBuiltins }); } catch (error) { // If an error was thrown, the problem doesn't seem to come from a path not being normalized, so we // can just throw the original error which was legit. throw originalError; } // If we reach this stage, it means that resolveToUnqualified didn't fail when using the fully resolved // file path, which is very likely caused by a module being invoked through Node with a path not being // correctly normalized (ie you should use "node $(realpath script.js)" instead of "node script.js"). throw makeError("SYMLINKED_PATH_DETECTED", "A pnp module (\"".concat(request, "\") has been required from what seems to be a symlinked path (\"").concat(issuer, "\"). This is not possible, you must ensure that your modules are invoked through their fully resolved path on the filesystem (in this case \"").concat(realIssuer, "\")."), { request: request, issuer: issuer, realIssuer: realIssuer }); } } throw originalError; } if (unqualifiedPath === null) { return null; } try { return exports.resolveUnqualified(unqualifiedPath, { extensions: extensions }); } catch (resolutionError) { if (resolutionError.code === 'QUALIFIED_PATH_RESOLUTION_FAILED') { Object.assign(resolutionError.data, { request: request, issuer: issuer }); } throw resolutionError; } }; /** * Setups the hook into the Node environment. * * From this point on, any call to `require()` will go through the "resolveRequest" function, and the result will * be used as path of the file to load. */ exports.setup = function setup() { // A small note: we don't replace the cache here (and instead use the native one). This is an effort to not // break code similar to "delete require.cache[require.resolve(FOO)]", where FOO is a package located outside // of the Yarn dependency tree. In this case, we defer the load to the native loader. If we were to replace the // cache by our own, the native loader would populate its own cache, which wouldn't be exposed anymore, so the // delete call would be broken. var originalModuleLoad = Module._load; Module._load = function (request, parent, isMain) { if (!enableNativeHooks) { return originalModuleLoad.call(Module, request, parent, isMain); } // Builtins are managed by the regular Node loader if (builtinModules.has(request)) { try { enableNativeHooks = false; return originalModuleLoad.call(Module, request, parent, isMain); } finally { enableNativeHooks = true; } } // The 'pnpapi' name is reserved to return the PnP api currently in use by the program if (request === "pnpapi") { return pnpModule.exports; } // Request `Module._resolveFilename` (ie. `resolveRequest`) to tell us which file we should load var modulePath = Module._resolveFilename(request, parent, isMain); // Check if the module has already been created for the given file var cacheEntry = Module._cache[modulePath]; if (cacheEntry) { return cacheEntry.exports; } // Create a new module and store it into the cache var module = new Module(modulePath, parent); Module._cache[modulePath] = module; // The main module is exposed as global variable if (isMain) { process.mainModule = module; module.id = '.'; } // Try to load the module, and remove it from the cache if it fails var hasThrown = true; try { module.load(modulePath); hasThrown = false; } finally { if (hasThrown) { delete Module._cache[modulePath]; } } // Some modules might have to be patched for compatibility purposes for (var _i = 0, _patchedModules = patchedModules; _i < _patchedModules.length; _i++) { var _patchedModules$_i = (0, _slicedToArray2()["default"])(_patchedModules[_i], 2), filter = _patchedModules$_i[0], patchFn = _patchedModules$_i[1]; if (filter.test(request)) { module.exports = patchFn(exports.findPackageLocator(parent.filename), module.exports); } } return module.exports; }; var originalModuleResolveFilename = Module._resolveFilename; Module._resolveFilename = function (request, parent, isMain, options) { if (!enableNativeHooks) { return originalModuleResolveFilename.call(Module, request, parent, isMain, options); } var issuers; if (options) { var optionNames = new Set(Object.keys(options)); optionNames["delete"]('paths'); if (optionNames.size > 0) { throw makeError("UNSUPPORTED", "Some options passed to require() aren't supported by PnP yet (".concat(Array.from(optionNames).join(', '), ")")); } if (options.paths) { issuers = options.paths.map(function (entry) { return "".concat(path.normalize(entry), "/"); }); } } if (!issuers) { var issuerModule = getIssuerModule(parent); var issuer = issuerModule ? issuerModule.filename : "".concat(process.cwd(), "/"); issuers = [issuer]; } var firstError; var _iterator = _createForOfIteratorHelper(issuers), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var _issuer = _step.value; var resolution = void 0; try { resolution = exports.resolveRequest(request, _issuer); } catch (error) { firstError = firstError || error; continue; } return resolution !== null ? resolution : request; } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } throw firstError; }; var originalFindPath = Module._findPath; Module._findPath = function (request, paths, isMain) { if (!enableNativeHooks) { return originalFindPath.call(Module, request, paths, isMain); } var _iterator2 = _createForOfIteratorHelper(paths || []), _step2; try { for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { var _path = _step2.value; var resolution = void 0; try { resolution = exports.resolveRequest(request, _path); } catch (error) { continue; } if (resolution) { return resolution; } } } catch (err) { _iterator2.e(err); } finally { _iterator2.f(); } return false; }; process.versions.pnp = String(exports.VERSIONS.std); }; exports.setupCompatibilityLayer = function () { // ESLint currently doesn't have any portable way for shared configs to specify their own // plugins that should be used (https://github.com/eslint/eslint/issues/10125). This will // likely get fixed at some point, but it'll take time and in the meantime we'll just add // additional fallback entries for common shared configs. for (var _i2 = 0, _arr = ["react-scripts"]; _i2 < _arr.length; _i2++) { var name = _arr[_i2]; var packageInformationStore = packageInformationStores.get(name); if (packageInformationStore) { var _iterator3 = _createForOfIteratorHelper(packageInformationStore.keys()), _step3; try { for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { var reference = _step3.value; fallbackLocators.push({ name: name, reference: reference }); } } catch (err) { _iterator3.e(err); } finally { _iterator3.f(); } } } // Modern versions of `resolve` support a specific entry point that custom resolvers can use // to inject a specific resolution logic without having to patch the whole package. // // Cf: https://github.com/browserify/resolve/pull/174 patchedModules.push([/^\.\/normalize-options\.js$/, function (issuer, normalizeOptions) { if (!issuer || issuer.name !== 'resolve') { return normalizeOptions; } return function (request, opts) { opts = opts || {}; if (opts.forceNodeResolution) { return opts; } opts.preserveSymlinks = true; opts.paths = function (request, basedir, getNodeModulesDir, opts) { // Extract the name of the package being requested (1=full name, 2=scope name, 3=local name) var parts = request.match(/^((?:(@[^\/]+)\/)?([^\/]+))/); // make sure that basedir ends with a slash if (basedir.charAt(basedir.length - 1) !== '/') { basedir = path.join(basedir, '/'); } // This is guaranteed to return the path to the "package.json" file from the given package var manifestPath = exports.resolveToUnqualified("".concat(parts[1], "/package.json"), basedir); // The first dirname strips the package.json, the second strips the local named folder var nodeModules = path.dirname(path.dirname(manifestPath)); // Strips the scope named folder if needed if (parts[2]) { nodeModules = path.dirname(nodeModules); } return [nodeModules]; }; return opts; }; }]); }; if (module.parent && module.parent.id === 'internal/preload') { exports.setupCompatibilityLayer(); exports.setup(); } if (process.mainModule === module) { exports.setupCompatibilityLayer(); var reportError = function reportError(code, message, data) { process.stdout.write("".concat(JSON.stringify([{ code: code, message: message, data: data }, null]), "\n")); }; var reportSuccess = function reportSuccess(resolution) { process.stdout.write("".concat(JSON.stringify([null, resolution]), "\n")); }; var processResolution = function processResolution(request, issuer) { try { reportSuccess(exports.resolveRequest(request, issuer)); } catch (error) { reportError(error.code, error.message, error.data); } }; var processRequest = function processRequest(data) { try { var _JSON$parse = JSON.parse(data), _JSON$parse2 = (0, _slicedToArray2()["default"])(_JSON$parse, 2), request = _JSON$parse2[0], issuer = _JSON$parse2[1]; processResolution(request, issuer); } catch (error) { reportError("INVALID_JSON", error.message, error.data); } }; if (process.argv.length > 2) { if (process.argv.length !== 4) { process.stderr.write("Usage: ".concat(process.argv[0], " ").concat(process.argv[1], " <request> <issuer>\n")); process.exitCode = 64; /* EX_USAGE */ } else { processResolution(process.argv[2], process.argv[3]); } } else { var buffer = ''; var decoder = new StringDecoder.StringDecoder(); process.stdin.on('data', function (chunk) { buffer += decoder.write(chunk); do { var index = buffer.indexOf('\n'); if (index === -1) { break; } var line = buffer.slice(0, index); buffer = buffer.slice(index + 1); processRequest(line); } while (true); }); } } //# sourceMappingURL=generate-pnp-map-api.tpl.js.map