File: /var/www/design.system/node_modules/@rushstack/node-core-library/lib/RealNodeModulePath.js.map
{"version":3,"file":"RealNodeModulePath.js","sourceRoot":"","sources":["../src/RealNodeModulePath.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,+CAAiC;AAWjC;;;;;;;;;;;;;GAaG;AACH,MAAa,0BAA0B;IAcrC,YAAmB,UAA8C,EAAE;QACjE,MAAM,EACJ,EAAE,EAAE,EAAE,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE,YAAY,GAAG,MAAM,CAAC,YAAY,EAAE,GAAG,MAAM,EACjF,IAAI,EAAE,EACJ,UAAU,GAAG,QAAQ,CAAC,UAAU,EAChC,IAAI,GAAG,QAAQ,CAAC,IAAI,EACpB,OAAO,GAAG,QAAQ,CAAC,OAAO,EAC1B,GAAG,GAAG,QAAQ,CAAC,GAAG,EACnB,GAAG,QAAQ,EACb,GAAG,OAAO,CAAC;QACZ,MAAM,KAAK,GAAwB,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,GAAG,GAAG;YACT,SAAS;YACT,YAAY;SACb,CAAC;QACF,IAAI,CAAC,KAAK,GAAG;YACX,UAAU;YACV,IAAI;YACJ,OAAO;YACP,GAAG;SACJ,CAAC;QAEF,MAAM,gBAAgB,GAAW,GAAG,GAAG,eAAe,GAAG,EAAE,CAAC;QAC5D,MAAM,IAAI,GAAS,IAAI,CAAC;QAExB,SAAS,0BAA0B,CAAC,KAAa;YAC/C,0CAA0C;YAC1C,MAAM,gBAAgB,GAAW,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;YACrE,IAAI,gBAAgB,GAAG,CAAC,EAAE,CAAC;gBACzB,oEAAoE;gBACpE,OAAO,KAAK,CAAC;YACf,CAAC;YAED,0EAA0E;YAC1E,IAAI,SAAS,GAAW,gBAAgB,GAAG,g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,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,oGAAoG;QACpG,oBAAoB;QACpB,MAAM,IAAI,GAA6B,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAChE,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;YAC1B,8DAA8D;YAC9D,MAAM,MAAM,GAAW,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC;YACjF,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;CACF;AAhJD,gEAgJC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as nodeFs from 'fs';\nimport * as nodePath from 'path';\n\n/**\n * Arguments used to create a function that resolves symlinked node_modules in a path\n * @public\n */\nexport interface IRealNodeModulePathResolverOptions {\n fs?: Partial<Pick<typeof nodeFs, 'lstatSync' | 'readlinkSync'>>;\n path?: Partial<Pick<typeof nodePath, 'isAbsolute' | 'join' | 'resolve' | 'sep'>>;\n}\n\n/**\n * This class encapsulates a caching resolver for symlinks in node_modules directories.\n * It assumes that the only symlinks that exist in input paths are those that correspond to\n * npm packages.\n *\n * @remarks\n * In a repository with a symlinked node_modules installation, some symbolic links need to be mapped for\n * node module resolution to produce correct results. However, calling `fs.realpathSync.native` on every path,\n * as is commonly done by most resolvers, involves an enormous number of file system operations (for reference,\n * each invocation of `fs.realpathSync.native` involves a series of `fs.readlinkSync` calls, up to one for each\n * path segment in the input).\n *\n * @public\n */\nexport class RealNodeModulePathResolver {\n /**\n * Similar in function to `fs.realpathSync.native`, but assumes the only symlinks present are npm packages.\n *\n * @param input - A path to a file or directory, where the path separator is `${require('node:path').sep}`\n * @returns The real path to the input, resolving the node_modules symlinks in the path\n * @public\n */\n public readonly realNodeModulePath: (input: string) => string;\n\n private readonly _cache: Map<string, string>;\n private readonly _fs: Required<NonNullable<IRealNodeModulePathResolverOptions['fs']>>;\n private readonly _path: Required<NonNullable<IRealNodeModulePathResolverOptions['path']>>;\n\n public constructor(options: IRealNodeModulePathResolverOptions = {}) {\n const {\n fs: { lstatSync = nodeFs.lstatSync, readlinkSync = nodeFs.readlinkSync } = nodeFs,\n path: {\n isAbsolute = nodePath.isAbsolute,\n join = nodePath.join,\n resolve = nodePath.resolve,\n sep = nodePath.sep\n } = nodePath\n } = options;\n const cache: Map<string, string> = (this._cache = new Map());\n this._fs = {\n lstatSync,\n readlinkSync\n };\n this._path = {\n isAbsolute,\n join,\n resolve,\n sep\n };\n\n const nodeModulesToken: string = `${sep}node_modules${sep}`;\n const self: this = this;\n\n function realNodeModulePathInternal(input: string): string {\n // Find the last node_modules path segment\n const nodeModulesIndex: number = input.lastIndexOf(nodeModulesToken);\n if (nodeModulesIndex < 0) {\n // No node_modules in path, so we assume it is already the real path\n return input;\n }\n\n // First assume that the next path segment after node_modules is a symlink\n let linkStart: number = nodeModulesIndex + nodeModulesToken.length - 1;\n let linkEnd: number = input.indexOf(sep, linkStart + 1);\n // If the path segment starts with a '@', then it is a scoped package\n const isScoped: boolean = input.charAt(linkStart + 1) === '@';\n if (isScoped) {\n // For a scoped package, the scope is an ordinary directory, so we need to find the next path segment\n if (linkEnd < 0) {\n // Symlink missing, so see if anything before the last node_modules needs resolving,\n // and preserve the rest of the path\n return join(\n realNodeModulePathInternal(input.slice(0, nodeModulesIndex)),\n input.slice(nodeModulesIndex + 1),\n // Joining to `.` will clean up any extraneous trailing slashes\n '.'\n );\n }\n\n linkStart = linkEnd;\n linkEnd = input.indexOf(sep, linkStart + 1);\n }\n\n // No trailing separator, so the link is the last path segment\n if (linkEnd < 0) {\n linkEnd = input.length;\n }\n\n const linkCandidate: string = input.slice(0, linkEnd);\n // Check if the link is a symlink\n const linkTarget: string | undefined = self._tryReadLink(linkCandidate);\n if (linkTarget && isAbsolute(linkTarget)) {\n // Absolute path, combine the link target with any remaining path segments\n // Cache the resolution to avoid the readlink call in subsequent calls\n cache.set(linkCandidate, linkTarget);\n cache.set(linkTarget, linkTarget);\n // Joining to `.` will clean up any extraneous trailing slashes\n return join(linkTarget, input.slice(linkEnd + 1), '.');\n }\n\n // Relative path or does not exist\n // Either way, the path before the last node_modules could itself be in a node_modules folder\n // So resolve the base path to find out what paths are relative to\n const realpathBeforeNodeModules: string = realNodeModulePathInternal(input.slice(0, nodeModulesIndex));\n if (linkTarget) {\n // Relative path in symbolic link. Should be resolved relative to real path of base path.\n const resolvedTarget: string = resolve(\n realpathBeforeNodeModules,\n input.slice(nodeModulesIndex + 1, linkStart),\n linkTarget\n );\n // Cache the result of the combined resolution to avoid the readlink call in subsequent calls\n cache.set(linkCandidate, resolvedTarget);\n cache.set(resolvedTarget, resolvedTarget);\n // Joining to `.` will clean up any extraneous trailing slashes\n return join(resolvedTarget, input.slice(linkEnd + 1), '.');\n }\n\n // No symlink, so just return the real path before the last node_modules combined with the\n // subsequent path segments\n // Joining to `.` will clean up any extraneous trailing slashes\n return join(realpathBeforeNodeModules, input.slice(nodeModulesIndex + 1), '.');\n }\n\n this.realNodeModulePath = (input: string) => {\n return realNodeModulePathInternal(resolve(input));\n };\n }\n\n /**\n * Clears the cache of resolved symlinks.\n * @public\n */\n public clearCache(): void {\n this._cache.clear();\n }\n\n /**\n * Tries to read a symbolic link at the specified path.\n * If the input is not a symbolic link, returns undefined.\n * @param link - The link to try to read\n * @returns The target of the symbolic link, or undefined if the input is not a symbolic link\n */\n private _tryReadLink(link: string): string | undefined {\n const cached: string | undefined = this._cache.get(link);\n if (cached) {\n return cached;\n }\n\n // On Windows, calling `readlink` on a directory throws an EUNKOWN, not EINVAL, so just pay the cost\n // of an lstat call.\n const stat: nodeFs.Stats | undefined = this._fs.lstatSync(link);\n if (stat.isSymbolicLink()) {\n // path.join(x, '.') will trim trailing slashes, if applicable\n const result: string = this._path.join(this._fs.readlinkSync(link, 'utf8'), '.');\n return result;\n }\n }\n}\n"]}