Options
All
  • Public
  • Public/Protected
  • All
Menu

Package plugin-compat

@yarnpkg/plugin-compat

This plugin contains various builtin patches that will be applied to packages that aren't compatible with the Plug'n'Play resolution out-of-the-box.

Install

This plugin is included by default in Yarn.

Compatibility Features

Variables

Object literals

Variables

Const packageExtensions

packageExtensions: Array<[string, any]> = [// https://github.com/SamVerschueren/stream-to-observable/pull/5[`@samverschueren/stream-to-observable@*`, {peerDependenciesMeta: {[`rxjs`]: {optional: true,},[`zenObservable`]: {optional: true,},},}],// https://github.com/sindresorhus/any-observable/pull/25[`any-observable@*`, {peerDependenciesMeta: {[`rxjs`]: {optional: true,},[`zenObservable`]: {optional: true,},},}],// https://github.com/keymetrics/pm2-io-agent/pull/125[`@pm2/agent@*`, {dependencies: {[`debug`]: `*`,},}],// https://github.com/visionmedia/debug/pull/727[`debug@*`, {peerDependenciesMeta: {[`supports-color`]: {optional: true,},},}],// https://github.com/sindresorhus/got/pull/1125[`got@*`, {dependencies: {[`@types/responselike`]: `^1.0.0`,[`@types/keyv`]: `^3.1.1`,},}],// https://github.com/szmarczak/cacheable-lookup/pull/12[`cacheable-lookup@*`, {dependencies: {[`@types/keyv`]: `^3.1.1`,},}],]

Const patch

patch: "diff --git a/fsevents.js b/fsevents.jssemver exclusivity ^1--- a/fsevents.js+++ b/fsevents.js@@ -36,11 +36,15 @@ module.exports.Constants = Native.Constants;var defer = global.setImmediate || process.nextTick;function watch(path) {- var fse = new FSEvents(String(path || ''), handler);+ var VFS = require('./vfs');+ var vfs = new VFS(String(path || ''));++ var fse = new FSEvents(vfs.resolvedPath, handler);EventEmitter.call(fse);return fse;function handler(path, flags, id) {+ path = vfs.transpose(path);defer(function() {fse.emit('fsevent', path, flags, id);var info = getInfo(path, flags);diff --git a/fsevents.js b/fsevents.jssemver exclusivity ^2.1--- a/fsevents.js+++ b/fsevents.js@@ -21,5 +21,7 @@ function watch(path, handler) {throw new TypeError(`fsevents argument 2 must be a function and not a ${typeof handler}`);}- let instance = Native.start(path, handler);+ let VFS = require('./vfs');+ let vfs = new VFS(path);+ let instance = Native.start(vfs.resolvedPath, vfs.wrap(handler));if (!instance) throw new Error(`could not watch: ${path}`);diff --git a/vfs.js b/vfs.jsnew file mode 100644--- /dev/null+++ b/vfs.js@@ -0,0 +1,41 @@+const path = require(`path`);++const NUMBER_REGEXP = /^[0-9]+$/;+const VIRTUAL_REGEXP = /^(\/(?:[^\/]+\/)*?\$\$virtual)((?:\/([^\/]+)(?:\/([^\/]+))?)?((?:\/.*)?))$/;++function resolveVirtual(p) {+ const match = p.match(VIRTUAL_REGEXP);+ if (!match)+ return p;++ const target = path.dirname(match[1]);+ if (!match[3] || !match[4])+ return target;++ const isnum = NUMBER_REGEXP.test(match[4]);+ if (!isnum)+ return p;++ const depth = Number(match[4]);+ const backstep = `../`.repeat(depth);+ const subpath = (match[5] || `.`);++ return resolveVirtual(path.join(target, backstep, subpath));+}++module.exports = class FsePnp {+ constructor(p) {+ this.normalizedPath = path.resolve(p);+ this.resolvedPath = resolveVirtual(this.normalizedPath);+ }++ transpose(p) {+ return this.normalizedPath + p.substr(this.resolvedPath.length);+ }++ wrap(fn) {+ return (path, ...args) => {+ return fn(this.transpose(path), ...args);+ };+ }+};" = "diff --git a/fsevents.js b/fsevents.jssemver exclusivity ^1--- a/fsevents.js+++ b/fsevents.js@@ -36,11 +36,15 @@ module.exports.Constants = Native.Constants;var defer = global.setImmediate || process.nextTick;function watch(path) {- var fse = new FSEvents(String(path || ''), handler);+ var VFS = require('./vfs');+ var vfs = new VFS(String(path || ''));++ var fse = new FSEvents(vfs.resolvedPath, handler);EventEmitter.call(fse);return fse;function handler(path, flags, id) {+ path = vfs.transpose(path);defer(function() {fse.emit('fsevent', path, flags, id);var info = getInfo(path, flags);diff --git a/fsevents.js b/fsevents.jssemver exclusivity ^2.1--- a/fsevents.js+++ b/fsevents.js@@ -21,5 +21,7 @@ function watch(path, handler) {throw new TypeError(`fsevents argument 2 must be a function and not a ${typeof handler}`);}- let instance = Native.start(path, handler);+ let VFS = require('./vfs');+ let vfs = new VFS(path);+ let instance = Native.start(vfs.resolvedPath, vfs.wrap(handler));if (!instance) throw new Error(`could not watch: ${path}`);diff --git a/vfs.js b/vfs.jsnew file mode 100644--- /dev/null+++ b/vfs.js@@ -0,0 +1,41 @@+const path = require(`path`);++const NUMBER_REGEXP = /^[0-9]+$/;+const VIRTUAL_REGEXP = /^(\/(?:[^\/]+\/)*?\$\$virtual)((?:\/([^\/]+)(?:\/([^\/]+))?)?((?:\/.*)?))$/;++function resolveVirtual(p) {+ const match = p.match(VIRTUAL_REGEXP);+ if (!match)+ return p;++ const target = path.dirname(match[1]);+ if (!match[3] || !match[4])+ return target;++ const isnum = NUMBER_REGEXP.test(match[4]);+ if (!isnum)+ return p;++ const depth = Number(match[4]);+ const backstep = `../`.repeat(depth);+ const subpath = (match[5] || `.`);++ return resolveVirtual(path.join(target, backstep, subpath));+}++module.exports = class FsePnp {+ constructor(p) {+ this.normalizedPath = path.resolve(p);+ this.resolvedPath = resolveVirtual(this.normalizedPath);+ }++ transpose(p) {+ return this.normalizedPath + p.substr(this.resolvedPath.length);+ }++ wrap(fn) {+ return (path, ...args) => {+ return fn(this.transpose(path), ...args);+ };+ }+};"

Const patch

patch: "diff --git a/lib/normalize-options.js b/lib/normalize-options.jsindex 4b56904..53a3219 100644semver exclusivity >=1.9--- a/lib/normalize-options.js+++ b/lib/normalize-options.js@@ -1,10 +1,108 @@-module.exports = function (x, opts) {- /**- * This file is purposefully a passthrough. It's expected that third-party- * environments will override it at runtime in order to inject special logic- * into `resolve` (by manipulating the options). One such example is the PnP- * code path in Yarn.- */-- return opts || {};+// Info: this file has been generated by Yarn with the approval of the+// `resolve` maintainers. Bugs caused by a code located here should be+// opened against the Yarn repository.++const path = require(`path`);++module.exports = function (_, opts) {+ opts = opts || {};++ if (opts.forceNodeResolution || !process.versions.pnp)+ return opts;++ // It would be nice if we could throw, but that would break the transparent+ // compatibility with packages that use `resolve` today (such as Gulp). Since+ // it's the whole point of this patch, we don't.+ //+ // if (opts.packageIterator || opts.paths)+ // throw new Error(`The "packageIterator" and "paths" options cannot be used in PnP environments. Set "forceNodeResolution: true" if absolutely needed, or branch on process.versions.pnp otherwise.`);++ const {findPnpApi} = require(`module`);++ const runPnpResolution = (request, basedir) => {+ // Extract the name of the package being requested (1=package name, 2=internal path)+ const parts = request.match(/^((?:@[^\/]+\/)?[^\/]+)(\/.*)?/);+ if (!parts)+ throw new Error(`Assertion failed: Expected the "resolve" package to call the "paths" callback with package names only (got "${request}")`);++ // Make sure that basedir ends with a slash+ if (basedir.charAt(basedir.length - 1) !== `/`)+ basedir = path.join(basedir, `/`);++ const api = findPnpApi(basedir);+ if (api === null)+ return undefined;++ // This is guaranteed to return the path to the "package.json" file from the given package+ let manifestPath;+ try {+ manifestPath = api.resolveToUnqualified(`${parts[1]}/package.json`, basedir, {considerBuiltins: false});+ } catch (err) {+ return null;+ }++ if (manifestPath === null)+ throw new Error(`Assertion failed: The resolution thinks that "${parts[1]}" is a Node builtin`);++ // Strip the package.json to get the package folder+ const packagePath = path.dirname(manifestPath);++ // Attach the internal path to the resolved package directory+ const unqualifiedPath = typeof parts[2] !== `undefined`+ ? path.join(packagePath, parts[2])+ : packagePath;++ return {packagePath, unqualifiedPath};+ };++ const packageIterator = (request, basedir, getCandidates, opts) => {+ const resolution = runPnpResolution(request, basedir);+ if (typeof resolution === `undefined`)+ return getCandidates();++ if (resolution === null)+ return [];++ return [resolution.unqualifiedPath];+ };++ const paths = (request, basedir, getNodeModulePaths, opts) => {+ const resolution = runPnpResolution(request, basedir);+ if (typeof resolution === `undefined`)+ return getNodeModulePaths();++ if (resolution === null)+ return [];++ // Stip the local named folder+ let nodeModules = path.dirname(resolution.packagePath);++ // Strip the scope named folder if needed+ if (request.match(/^@[^\/]+\//))+ nodeModules = path.dirname(nodeModules);++ return [nodeModules];+ };++ // We need to keep track whether we're in `packageIterator` or not so that+ // the code is compatible with both `resolve` 1.9+ and `resolve` 1.15++ let isInsideIterator = false;++ opts.packageIterator = function (request, basedir, getCandidates, opts) {+ isInsideIterator = true;+ try {+ return packageIterator(request, basedir, getCandidates, opts);+ } finally {+ isInsideIterator = false;+ }+ };++ opts.paths = function (request, basedir, getNodeModulePaths, opts) {+ if (isInsideIterator)+ return getNodeModulePaths();++ return paths(request, basedir, getNodeModulePaths, opts);+ };++ return opts;};" = "diff --git a/lib/normalize-options.js b/lib/normalize-options.jsindex 4b56904..53a3219 100644semver exclusivity >=1.9--- a/lib/normalize-options.js+++ b/lib/normalize-options.js@@ -1,10 +1,108 @@-module.exports = function (x, opts) {- /**- * This file is purposefully a passthrough. It's expected that third-party- * environments will override it at runtime in order to inject special logic- * into `resolve` (by manipulating the options). One such example is the PnP- * code path in Yarn.- */-- return opts || {};+// Info: this file has been generated by Yarn with the approval of the+// `resolve` maintainers. Bugs caused by a code located here should be+// opened against the Yarn repository.++const path = require(`path`);++module.exports = function (_, opts) {+ opts = opts || {};++ if (opts.forceNodeResolution || !process.versions.pnp)+ return opts;++ // It would be nice if we could throw, but that would break the transparent+ // compatibility with packages that use `resolve` today (such as Gulp). Since+ // it's the whole point of this patch, we don't.+ //+ // if (opts.packageIterator || opts.paths)+ // throw new Error(`The "packageIterator" and "paths" options cannot be used in PnP environments. Set "forceNodeResolution: true" if absolutely needed, or branch on process.versions.pnp otherwise.`);++ const {findPnpApi} = require(`module`);++ const runPnpResolution = (request, basedir) => {+ // Extract the name of the package being requested (1=package name, 2=internal path)+ const parts = request.match(/^((?:@[^\/]+\/)?[^\/]+)(\/.*)?/);+ if (!parts)+ throw new Error(`Assertion failed: Expected the "resolve" package to call the "paths" callback with package names only (got "${request}")`);++ // Make sure that basedir ends with a slash+ if (basedir.charAt(basedir.length - 1) !== `/`)+ basedir = path.join(basedir, `/`);++ const api = findPnpApi(basedir);+ if (api === null)+ return undefined;++ // This is guaranteed to return the path to the "package.json" file from the given package+ let manifestPath;+ try {+ manifestPath = api.resolveToUnqualified(`${parts[1]}/package.json`, basedir, {considerBuiltins: false});+ } catch (err) {+ return null;+ }++ if (manifestPath === null)+ throw new Error(`Assertion failed: The resolution thinks that "${parts[1]}" is a Node builtin`);++ // Strip the package.json to get the package folder+ const packagePath = path.dirname(manifestPath);++ // Attach the internal path to the resolved package directory+ const unqualifiedPath = typeof parts[2] !== `undefined`+ ? path.join(packagePath, parts[2])+ : packagePath;++ return {packagePath, unqualifiedPath};+ };++ const packageIterator = (request, basedir, getCandidates, opts) => {+ const resolution = runPnpResolution(request, basedir);+ if (typeof resolution === `undefined`)+ return getCandidates();++ if (resolution === null)+ return [];++ return [resolution.unqualifiedPath];+ };++ const paths = (request, basedir, getNodeModulePaths, opts) => {+ const resolution = runPnpResolution(request, basedir);+ if (typeof resolution === `undefined`)+ return getNodeModulePaths();++ if (resolution === null)+ return [];++ // Stip the local named folder+ let nodeModules = path.dirname(resolution.packagePath);++ // Strip the scope named folder if needed+ if (request.match(/^@[^\/]+\//))+ nodeModules = path.dirname(nodeModules);++ return [nodeModules];+ };++ // We need to keep track whether we're in `packageIterator` or not so that+ // the code is compatible with both `resolve` 1.9+ and `resolve` 1.15++ let isInsideIterator = false;++ opts.packageIterator = function (request, basedir, getCandidates, opts) {+ isInsideIterator = true;+ try {+ return packageIterator(request, basedir, getCandidates, opts);+ } finally {+ isInsideIterator = false;+ }+ };++ opts.paths = function (request, basedir, getNodeModulePaths, opts) {+ if (isInsideIterator)+ return getNodeModulePaths();++ return paths(request, basedir, getNodeModulePaths, opts);+ };++ return opts;};"

Const patch

patch: "diff --git a/lib/tsc.js b/lib/tsc.jsindex d7f749f633..c4a080b2c8 100644semver exclusivity >=3 <3.6--- a/lib/tsc.js+++ b/lib/tsc.js@@ -22576,21 +22576,48 @@ var ts;}}ts.getEffectiveTypeRoots = getEffectiveTypeRoots;- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {var traceEnabled = isTraceEnabled(options, host);if (redirectedReference) {@@ -22670,7 +22697,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, undefined, undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, undefined, undefined);result = searchResult && searchResult.value;}else {@@ -23043,9 +23072,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -23487,6 +23519,45 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ function isPnpAvailable() {+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), false, state, true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), false, state, true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));var ts;(function (ts) {diff --git a/lib/tsserver.js b/lib/tsserver.jsindex 4ea67ecd85..057ea079ad 100644semver exclusivity >=3 <3.6--- a/lib/tsserver.js+++ b/lib/tsserver.js@@ -27790,24 +27790,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -27894,7 +27922,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28378,9 +28408,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -28876,6 +28909,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.jsindex 2897a22620..cf3e054327 100644semver exclusivity >=3 <3.6--- a/lib/tsserverlibrary.js+++ b/lib/tsserverlibrary.js@@ -27940,24 +27940,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28044,7 +28072,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28528,9 +28558,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29026,6 +29059,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/typescript.js b/lib/typescript.jsindex 548ceea966..92c195a616 100644semver exclusivity >=3 <3.6--- a/lib/typescript.js+++ b/lib/typescript.js@@ -27929,24 +27929,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28033,7 +28061,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28517,9 +28547,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29015,6 +29048,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/typescriptServices.js b/lib/typescriptServices.jsindex 9046c6f907..0f0db98cbb 100644semver exclusivity >=3 <3.6--- a/lib/typescriptServices.js+++ b/lib/typescriptServices.js@@ -27929,24 +27929,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28033,7 +28061,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28517,9 +28547,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29015,6 +29048,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.jsindex 776a2e0a9b..cfa1e84496 100644semver exclusivity >=3 <3.6--- a/lib/typingsInstaller.js+++ b/lib/typingsInstaller.js@@ -27779,24 +27779,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -27883,7 +27911,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28367,9 +28397,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -28865,6 +28898,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/tsc.js b/lib/tsc.jsindex d7f749f633..543543807b 100644semver exclusivity >3.6--- a/lib/tsc.js+++ b/lib/tsc.js@@ -22576,21 +22576,48 @@ var ts;}}ts.getEffectiveTypeRoots = getEffectiveTypeRoots;- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {var traceEnabled = isTraceEnabled(options, host);if (redirectedReference) {@@ -22670,7 +22697,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, undefined, undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, undefined, undefined);result = searchResult && searchResult.value;}else {@@ -23043,9 +23072,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -23487,6 +23519,45 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ function isPnpAvailable() {+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), false, state, true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), false, state, true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));var ts;(function (ts) {@@ -81887,6 +81958,9 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -81917,7 +81991,7 @@ var ts;var moduleSpecifier = packageNameOnly ? moduleFileName : getDirectoryOrExtensionlessFileName(moduleFileName);var globalTypingsCacheLocation = host.getGlobalTypingsCacheLocation && host.getGlobalTypingsCacheLocation();var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}var nodeModulesDirectoryName = moduleSpecifier.substring(parts.topLevelPackageNameIndex + 1);diff --git a/lib/tsserver.js b/lib/tsserver.jsindex 4ea67ecd85..83510127ae 100644semver exclusivity >3.6--- a/lib/tsserver.js+++ b/lib/tsserver.js@@ -27790,24 +27790,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -27894,7 +27922,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28378,9 +28408,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -28876,6 +28909,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99548,6 +99632,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99582,7 +99670,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name@@ -123974,11 +124064,28 @@ var ts;}}}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ // @ts-ignore+ return require("pnpapi");+ }/*** Don't include something from a `node_modules` that isn't actually reachable by a global import.* A relative import to node_modules is usually a bad idea.*/- function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ function isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath) {// If it's in a `node_modules` but is not reachable from here via a global import, don't bother.var toNodeModules = ts.forEachAncestorDirectory(toPath, function (ancestor) { return ts.getBaseFileName(ancestor) === "node_modules" ? ancestor : undefined; });var toNodeModulesParent = toNodeModules && ts.getDirectoryPath(getCanonicalFileName(toNodeModules));@@ -123986,6 +124093,26 @@ var ts;|| ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)|| (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));}+ function isImportablePathPnp(fromPath, toPath) {+ var pnpApi = getPnpApi();+ var fromLocator = pnpApi.findPackageLocator(fromPath);+ var toLocator = pnpApi.findPackageLocator(toPath);+ // eslint-disable-next-line no-null/no-null+ if (toLocator === null) {+ return false;+ }+ var fromInfo = pnpApi.getPackageInformation(fromLocator);+ var toReference = fromInfo.packageDependencies.get(toLocator.name);+ return toReference === toLocator.reference;+ }+ function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ if (isPnpAvailable()) {+ return isImportablePathPnp(fromPath, toPath);+ }+ else {+ return isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath);+ }+ }function moduleSymbolToValidIdentifier(moduleSymbol, target) {return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);}diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.jsindex 2897a22620..4738788997 100644semver exclusivity >3.6--- a/lib/tsserverlibrary.js+++ b/lib/tsserverlibrary.js@@ -27940,24 +27940,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28044,7 +28072,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28528,9 +28558,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29026,6 +29059,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99698,6 +99782,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99732,7 +99820,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name@@ -124487,11 +124577,28 @@ var ts;}}}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ // @ts-ignore+ return require("pnpapi");+ }/*** Don't include something from a `node_modules` that isn't actually reachable by a global import.* A relative import to node_modules is usually a bad idea.*/- function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ function isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath) {// If it's in a `node_modules` but is not reachable from here via a global import, don't bother.var toNodeModules = ts.forEachAncestorDirectory(toPath, function (ancestor) { return ts.getBaseFileName(ancestor) === "node_modules" ? ancestor : undefined; });var toNodeModulesParent = toNodeModules && ts.getDirectoryPath(getCanonicalFileName(toNodeModules));@@ -124499,6 +124606,26 @@ var ts;|| ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)|| (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));}+ function isImportablePathPnp(fromPath, toPath) {+ var pnpApi = getPnpApi();+ var fromLocator = pnpApi.findPackageLocator(fromPath);+ var toLocator = pnpApi.findPackageLocator(toPath);+ // eslint-disable-next-line no-null/no-null+ if (toLocator === null) {+ return false;+ }+ var fromInfo = pnpApi.getPackageInformation(fromLocator);+ var toReference = fromInfo.packageDependencies.get(toLocator.name);+ return toReference === toLocator.reference;+ }+ function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ if (isPnpAvailable()) {+ return isImportablePathPnp(fromPath, toPath);+ }+ else {+ return isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath);+ }+ }function moduleSymbolToValidIdentifier(moduleSymbol, target) {return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);}diff --git a/lib/typescript.js b/lib/typescript.jsindex 548ceea966..1e5b232e75 100644semver exclusivity >3.6--- a/lib/typescript.js+++ b/lib/typescript.js@@ -27929,24 +27929,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28033,7 +28061,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28517,9 +28547,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29015,6 +29048,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99687,6 +99771,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99721,7 +99809,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name@@ -124476,11 +124566,28 @@ var ts;}}}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ // @ts-ignore+ return require("pnpapi");+ }/*** Don't include something from a `node_modules` that isn't actually reachable by a global import.* A relative import to node_modules is usually a bad idea.*/- function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ function isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath) {// If it's in a `node_modules` but is not reachable from here via a global import, don't bother.var toNodeModules = ts.forEachAncestorDirectory(toPath, function (ancestor) { return ts.getBaseFileName(ancestor) === "node_modules" ? ancestor : undefined; });var toNodeModulesParent = toNodeModules && ts.getDirectoryPath(getCanonicalFileName(toNodeModules));@@ -124488,6 +124595,26 @@ var ts;|| ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)|| (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));}+ function isImportablePathPnp(fromPath, toPath) {+ var pnpApi = getPnpApi();+ var fromLocator = pnpApi.findPackageLocator(fromPath);+ var toLocator = pnpApi.findPackageLocator(toPath);+ // eslint-disable-next-line no-null/no-null+ if (toLocator === null) {+ return false;+ }+ var fromInfo = pnpApi.getPackageInformation(fromLocator);+ var toReference = fromInfo.packageDependencies.get(toLocator.name);+ return toReference === toLocator.reference;+ }+ function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ if (isPnpAvailable()) {+ return isImportablePathPnp(fromPath, toPath);+ }+ else {+ return isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath);+ }+ }function moduleSymbolToValidIdentifier(moduleSymbol, target) {return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);}diff --git a/lib/typescriptServices.js b/lib/typescriptServices.jsindex 9046c6f907..f3a9af2320 100644semver exclusivity >3.6--- a/lib/typescriptServices.js+++ b/lib/typescriptServices.js@@ -27929,24 +27929,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28033,7 +28061,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28517,9 +28547,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29015,6 +29048,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99687,6 +99771,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99721,7 +99809,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name@@ -124476,11 +124566,28 @@ var ts;}}}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ // @ts-ignore+ return require("pnpapi");+ }/*** Don't include something from a `node_modules` that isn't actually reachable by a global import.* A relative import to node_modules is usually a bad idea.*/- function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ function isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath) {// If it's in a `node_modules` but is not reachable from here via a global import, don't bother.var toNodeModules = ts.forEachAncestorDirectory(toPath, function (ancestor) { return ts.getBaseFileName(ancestor) === "node_modules" ? ancestor : undefined; });var toNodeModulesParent = toNodeModules && ts.getDirectoryPath(getCanonicalFileName(toNodeModules));@@ -124488,6 +124595,26 @@ var ts;|| ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)|| (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));}+ function isImportablePathPnp(fromPath, toPath) {+ var pnpApi = getPnpApi();+ var fromLocator = pnpApi.findPackageLocator(fromPath);+ var toLocator = pnpApi.findPackageLocator(toPath);+ // eslint-disable-next-line no-null/no-null+ if (toLocator === null) {+ return false;+ }+ var fromInfo = pnpApi.getPackageInformation(fromLocator);+ var toReference = fromInfo.packageDependencies.get(toLocator.name);+ return toReference === toLocator.reference;+ }+ function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ if (isPnpAvailable()) {+ return isImportablePathPnp(fromPath, toPath);+ }+ else {+ return isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath);+ }+ }function moduleSymbolToValidIdentifier(moduleSymbol, target) {return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);}diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.jsindex 776a2e0a9b..a96c74bf24 100644semver exclusivity >3.6--- a/lib/typingsInstaller.js+++ b/lib/typingsInstaller.js@@ -27779,24 +27779,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -27883,7 +27911,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28367,9 +28397,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -28865,6 +28898,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99537,6 +99621,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99571,7 +99659,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name" = "diff --git a/lib/tsc.js b/lib/tsc.jsindex d7f749f633..c4a080b2c8 100644semver exclusivity >=3 <3.6--- a/lib/tsc.js+++ b/lib/tsc.js@@ -22576,21 +22576,48 @@ var ts;}}ts.getEffectiveTypeRoots = getEffectiveTypeRoots;- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {var traceEnabled = isTraceEnabled(options, host);if (redirectedReference) {@@ -22670,7 +22697,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, undefined, undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, undefined, undefined);result = searchResult && searchResult.value;}else {@@ -23043,9 +23072,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -23487,6 +23519,45 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ function isPnpAvailable() {+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), false, state, true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), false, state, true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));var ts;(function (ts) {diff --git a/lib/tsserver.js b/lib/tsserver.jsindex 4ea67ecd85..057ea079ad 100644semver exclusivity >=3 <3.6--- a/lib/tsserver.js+++ b/lib/tsserver.js@@ -27790,24 +27790,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -27894,7 +27922,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28378,9 +28408,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -28876,6 +28909,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.jsindex 2897a22620..cf3e054327 100644semver exclusivity >=3 <3.6--- a/lib/tsserverlibrary.js+++ b/lib/tsserverlibrary.js@@ -27940,24 +27940,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28044,7 +28072,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28528,9 +28558,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29026,6 +29059,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/typescript.js b/lib/typescript.jsindex 548ceea966..92c195a616 100644semver exclusivity >=3 <3.6--- a/lib/typescript.js+++ b/lib/typescript.js@@ -27929,24 +27929,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28033,7 +28061,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28517,9 +28547,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29015,6 +29048,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/typescriptServices.js b/lib/typescriptServices.jsindex 9046c6f907..0f0db98cbb 100644semver exclusivity >=3 <3.6--- a/lib/typescriptServices.js+++ b/lib/typescriptServices.js@@ -27929,24 +27929,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28033,7 +28061,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28517,9 +28547,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29015,6 +29048,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.jsindex 776a2e0a9b..cfa1e84496 100644semver exclusivity >=3 <3.6--- a/lib/typingsInstaller.js+++ b/lib/typingsInstaller.js@@ -27779,24 +27779,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -27883,7 +27911,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28367,9 +28397,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -28865,6 +28898,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;diff --git a/lib/tsc.js b/lib/tsc.jsindex d7f749f633..543543807b 100644semver exclusivity >3.6--- a/lib/tsc.js+++ b/lib/tsc.js@@ -22576,21 +22576,48 @@ var ts;}}ts.getEffectiveTypeRoots = getEffectiveTypeRoots;- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }function resolveTypeReferenceDirective(typeReferenceDirectiveName, containingFile, options, host, redirectedReference) {var traceEnabled = isTraceEnabled(options, host);if (redirectedReference) {@@ -22670,7 +22697,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, undefined, undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, undefined, undefined);result = searchResult && searchResult.value;}else {@@ -23043,9 +23072,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -23487,6 +23519,45 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ function isPnpAvailable() {+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), false, state, true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), false, state, true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));var ts;(function (ts) {@@ -81887,6 +81958,9 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -81917,7 +81991,7 @@ var ts;var moduleSpecifier = packageNameOnly ? moduleFileName : getDirectoryOrExtensionlessFileName(moduleFileName);var globalTypingsCacheLocation = host.getGlobalTypingsCacheLocation && host.getGlobalTypingsCacheLocation();var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}var nodeModulesDirectoryName = moduleSpecifier.substring(parts.topLevelPackageNameIndex + 1);diff --git a/lib/tsserver.js b/lib/tsserver.jsindex 4ea67ecd85..83510127ae 100644semver exclusivity >3.6--- a/lib/tsserver.js+++ b/lib/tsserver.js@@ -27790,24 +27790,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -27894,7 +27922,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28378,9 +28408,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -28876,6 +28909,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99548,6 +99632,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99582,7 +99670,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name@@ -123974,11 +124064,28 @@ var ts;}}}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ // @ts-ignore+ return require("pnpapi");+ }/*** Don't include something from a `node_modules` that isn't actually reachable by a global import.* A relative import to node_modules is usually a bad idea.*/- function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ function isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath) {// If it's in a `node_modules` but is not reachable from here via a global import, don't bother.var toNodeModules = ts.forEachAncestorDirectory(toPath, function (ancestor) { return ts.getBaseFileName(ancestor) === "node_modules" ? ancestor : undefined; });var toNodeModulesParent = toNodeModules && ts.getDirectoryPath(getCanonicalFileName(toNodeModules));@@ -123986,6 +124093,26 @@ var ts;|| ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)|| (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));}+ function isImportablePathPnp(fromPath, toPath) {+ var pnpApi = getPnpApi();+ var fromLocator = pnpApi.findPackageLocator(fromPath);+ var toLocator = pnpApi.findPackageLocator(toPath);+ // eslint-disable-next-line no-null/no-null+ if (toLocator === null) {+ return false;+ }+ var fromInfo = pnpApi.getPackageInformation(fromLocator);+ var toReference = fromInfo.packageDependencies.get(toLocator.name);+ return toReference === toLocator.reference;+ }+ function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ if (isPnpAvailable()) {+ return isImportablePathPnp(fromPath, toPath);+ }+ else {+ return isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath);+ }+ }function moduleSymbolToValidIdentifier(moduleSymbol, target) {return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);}diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.jsindex 2897a22620..4738788997 100644semver exclusivity >3.6--- a/lib/tsserverlibrary.js+++ b/lib/tsserverlibrary.js@@ -27940,24 +27940,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28044,7 +28072,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28528,9 +28558,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29026,6 +29059,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99698,6 +99782,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99732,7 +99820,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name@@ -124487,11 +124577,28 @@ var ts;}}}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ // @ts-ignore+ return require("pnpapi");+ }/*** Don't include something from a `node_modules` that isn't actually reachable by a global import.* A relative import to node_modules is usually a bad idea.*/- function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ function isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath) {// If it's in a `node_modules` but is not reachable from here via a global import, don't bother.var toNodeModules = ts.forEachAncestorDirectory(toPath, function (ancestor) { return ts.getBaseFileName(ancestor) === "node_modules" ? ancestor : undefined; });var toNodeModulesParent = toNodeModules && ts.getDirectoryPath(getCanonicalFileName(toNodeModules));@@ -124499,6 +124606,26 @@ var ts;|| ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)|| (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));}+ function isImportablePathPnp(fromPath, toPath) {+ var pnpApi = getPnpApi();+ var fromLocator = pnpApi.findPackageLocator(fromPath);+ var toLocator = pnpApi.findPackageLocator(toPath);+ // eslint-disable-next-line no-null/no-null+ if (toLocator === null) {+ return false;+ }+ var fromInfo = pnpApi.getPackageInformation(fromLocator);+ var toReference = fromInfo.packageDependencies.get(toLocator.name);+ return toReference === toLocator.reference;+ }+ function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ if (isPnpAvailable()) {+ return isImportablePathPnp(fromPath, toPath);+ }+ else {+ return isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath);+ }+ }function moduleSymbolToValidIdentifier(moduleSymbol, target) {return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);}diff --git a/lib/typescript.js b/lib/typescript.jsindex 548ceea966..1e5b232e75 100644semver exclusivity >3.6--- a/lib/typescript.js+++ b/lib/typescript.js@@ -27929,24 +27929,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28033,7 +28061,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28517,9 +28547,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29015,6 +29048,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99687,6 +99771,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99721,7 +99809,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name@@ -124476,11 +124566,28 @@ var ts;}}}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ // @ts-ignore+ return require("pnpapi");+ }/*** Don't include something from a `node_modules` that isn't actually reachable by a global import.* A relative import to node_modules is usually a bad idea.*/- function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ function isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath) {// If it's in a `node_modules` but is not reachable from here via a global import, don't bother.var toNodeModules = ts.forEachAncestorDirectory(toPath, function (ancestor) { return ts.getBaseFileName(ancestor) === "node_modules" ? ancestor : undefined; });var toNodeModulesParent = toNodeModules && ts.getDirectoryPath(getCanonicalFileName(toNodeModules));@@ -124488,6 +124595,26 @@ var ts;|| ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)|| (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));}+ function isImportablePathPnp(fromPath, toPath) {+ var pnpApi = getPnpApi();+ var fromLocator = pnpApi.findPackageLocator(fromPath);+ var toLocator = pnpApi.findPackageLocator(toPath);+ // eslint-disable-next-line no-null/no-null+ if (toLocator === null) {+ return false;+ }+ var fromInfo = pnpApi.getPackageInformation(fromLocator);+ var toReference = fromInfo.packageDependencies.get(toLocator.name);+ return toReference === toLocator.reference;+ }+ function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ if (isPnpAvailable()) {+ return isImportablePathPnp(fromPath, toPath);+ }+ else {+ return isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath);+ }+ }function moduleSymbolToValidIdentifier(moduleSymbol, target) {return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);}diff --git a/lib/typescriptServices.js b/lib/typescriptServices.jsindex 9046c6f907..f3a9af2320 100644semver exclusivity >3.6--- a/lib/typescriptServices.js+++ b/lib/typescriptServices.js@@ -27929,24 +27929,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -28033,7 +28061,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28517,9 +28547,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -29015,6 +29048,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99687,6 +99771,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99721,7 +99809,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name@@ -124476,11 +124566,28 @@ var ts;}}}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ // @ts-ignore+ return require("pnpapi");+ }/*** Don't include something from a `node_modules` that isn't actually reachable by a global import.* A relative import to node_modules is usually a bad idea.*/- function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ function isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath) {// If it's in a `node_modules` but is not reachable from here via a global import, don't bother.var toNodeModules = ts.forEachAncestorDirectory(toPath, function (ancestor) { return ts.getBaseFileName(ancestor) === "node_modules" ? ancestor : undefined; });var toNodeModulesParent = toNodeModules && ts.getDirectoryPath(getCanonicalFileName(toNodeModules));@@ -124488,6 +124595,26 @@ var ts;|| ts.startsWith(getCanonicalFileName(fromPath), toNodeModulesParent)|| (!!globalCachePath && ts.startsWith(getCanonicalFileName(globalCachePath), toNodeModulesParent));}+ function isImportablePathPnp(fromPath, toPath) {+ var pnpApi = getPnpApi();+ var fromLocator = pnpApi.findPackageLocator(fromPath);+ var toLocator = pnpApi.findPackageLocator(toPath);+ // eslint-disable-next-line no-null/no-null+ if (toLocator === null) {+ return false;+ }+ var fromInfo = pnpApi.getPackageInformation(fromLocator);+ var toReference = fromInfo.packageDependencies.get(toLocator.name);+ return toReference === toLocator.reference;+ }+ function isImportablePath(fromPath, toPath, getCanonicalFileName, globalCachePath) {+ if (isPnpAvailable()) {+ return isImportablePathPnp(fromPath, toPath);+ }+ else {+ return isImportablePathNode(fromPath, toPath, getCanonicalFileName, globalCachePath);+ }+ }function moduleSymbolToValidIdentifier(moduleSymbol, target) {return moduleSpecifierToValidIdentifier(ts.removeFileExtension(ts.stripQuotes(moduleSymbol.name)), target);}diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.jsindex 776a2e0a9b..a96c74bf24 100644semver exclusivity >3.6--- a/lib/typingsInstaller.js+++ b/lib/typingsInstaller.js@@ -27779,24 +27779,52 @@ var ts;ts.getEffectiveTypeRoots = getEffectiveTypeRoots;/*** Returns the path to every node_modules/@types directory from some ancestor directory.- * Returns undefined if there are none.*/- function getDefaultTypeRoots(currentDirectory, host) {+ function getNodeModulesTypeRoots(currentDirectory, host) {if (!host.directoryExists) {return [ts.combinePaths(currentDirectory, nodeModulesAtTypes)];// And if it doesn't exist, tough.}- var typeRoots;+ var typeRoots = [];ts.forEachAncestorDirectory(ts.normalizePath(currentDirectory), function (directory) {var atTypes = ts.combinePaths(directory, nodeModulesAtTypes);if (host.directoryExists(atTypes)) {- (typeRoots || (typeRoots = [])).push(atTypes);+ typeRoots.push(atTypes);}return undefined;});return typeRoots;}var nodeModulesAtTypes = ts.combinePaths("node_modules", "@types");+ function getPnpTypeRoots(currentDirectory) {+ if (!isPnpAvailable()) {+ return [];+ }+ // Some TS consumers pass relative paths that aren't normalized+ currentDirectory = ts.sys.resolvePath(currentDirectory);+ var pnpapi = getPnpApi();+ var locator = pnpapi.findPackageLocator(currentDirectory + "/");+ var packageDependencies = pnpapi.getPackageInformation(locator).packageDependencies;+ var typeRoots = [];+ for (var _i = 0, _a = Array.from(packageDependencies.entries()); _i < _a.length; _i++) {+ var _b = _a[_i], name = _b[0], referencish = _b[1];+ // eslint-disable-next-line no-null/no-null+ if (name.startsWith(typesPackagePrefix) && referencish !== null) {+ var dependencyLocator = pnpapi.getLocator(name, referencish);+ var packageLocation = pnpapi.getPackageInformation(dependencyLocator).packageLocation;+ typeRoots.push(ts.getDirectoryPath(packageLocation));+ }+ }+ return typeRoots;+ }+ var typesPackagePrefix = "@types/";+ function getDefaultTypeRoots(currentDirectory, host) {+ var nmTypes = getNodeModulesTypeRoots(currentDirectory, host);+ var pnpTypes = getPnpTypeRoots(currentDirectory);+ if (nmTypes.length > 0 || pnpTypes.length > 0) {+ return [].concat(nmTypes, pnpTypes);+ }+ }/*** @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.* This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups@@ -27883,7 +27911,9 @@ var ts;}var result = void 0;if (!ts.isExternalModuleNameRelative(typeReferenceDirectiveName)) {- var searchResult = loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);+ var searchResult = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState)+ : loadModuleFromNearestNodeModulesDirectory(Extensions.DtsOnly, typeReferenceDirectiveName, initialLocationForSecondaryLookup, moduleResolutionState, /*cache*/ undefined, /*redirectedReference*/ undefined);result = searchResult && searchResult.value;}else {@@ -28367,9 +28397,12 @@ var ts;if (traceEnabled) {trace(host, ts.Diagnostics.Loading_module_0_from_node_modules_folder_target_file_type_1, moduleName, Extensions[extensions]);}- var resolved_1 = loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);- if (!resolved_1)+ var resolved_1 = isPnpAvailable()+ ? tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state)+ : loadModuleFromNearestNodeModulesDirectory(extensions, moduleName, containingDirectory, state, cache, redirectedReference);+ if (!resolved_1) {return undefined;+ }var resolvedValue = resolved_1.value;if (!compilerOptions.preserveSymlinks && resolvedValue && !resolvedValue.originalPath) {var path = realPath(resolvedValue.path, host, traceEnabled);@@ -28865,6 +28898,57 @@ var ts;function toSearchResult(value) {return value !== undefined ? { value: value } : undefined;}+ /**+ * We only allow PnP to be used as a resolution strategy if TypeScript+ * itself is executed under a PnP runtime (and we only allow it to access+ * the current PnP runtime, not any on the disk). This ensures that we+ * don't execute potentially malicious code that didn't already have a+ * chance to be executed (if we're running within the runtime, it means+ * that the runtime has already been executed).+ * @internal+ */+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }+ function getPnpApi() {+ return require("pnpapi");+ }+ function loadPnpPackageResolution(packageName, containingDirectory) {+ try {+ return getPnpApi().resolveToUnqualified(packageName, containingDirectory + "/", { considerBuiltins: false });+ }+ catch (_a) {+ // Nothing to do+ }+ }+ function loadPnpTypePackageResolution(packageName, containingDirectory) {+ return loadPnpPackageResolution(getTypesPackageName(packageName), containingDirectory);+ }+ /* @internal */+ function tryLoadModuleUsingPnpResolution(extensions, moduleName, containingDirectory, state) {+ var _a = parsePackageName(moduleName), packageName = _a.packageName, rest = _a.rest;+ var packageResolution = loadPnpPackageResolution(packageName, containingDirectory);+ var packageFullResolution = packageResolution+ ? nodeLoadModuleByRelativeName(extensions, ts.combinePaths(packageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ var resolved;+ if (packageFullResolution) {+ resolved = packageFullResolution;+ }+ else if (extensions === Extensions.TypeScript || extensions === Extensions.DtsOnly) {+ var typePackageResolution = loadPnpTypePackageResolution(packageName, containingDirectory);+ var typePackageFullResolution = typePackageResolution+ ? nodeLoadModuleByRelativeName(Extensions.DtsOnly, ts.combinePaths(typePackageResolution, rest), /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true)+ : undefined;+ if (typePackageFullResolution) {+ resolved = typePackageFullResolution;+ }+ }+ if (resolved) {+ return toSearchResult(resolved);+ }+ }})(ts || (ts = {}));/* @internal */var ts;@@ -99537,6 +99621,10 @@ var ts;? removeExtensionAndIndexPostFix(relativePath, ending, compilerOptions): ts.removeFileExtension(relativePath);}+ function isPnpAvailable() {+ // @ts-ignore+ return process.versions.pnp;+ }function tryGetModuleNameAsNodeModule(moduleFileName, _a, host, options, packageNameOnly) {var getCanonicalFileName = _a.getCanonicalFileName, sourceDirectory = _a.sourceDirectory;if (!host.fileExists || !host.readFile) {@@ -99571,7 +99659,9 @@ var ts;// Get a path that's relative to node_modules or the importing file's path// if node_modules folder is in this folder or any of its parent folders, no need to keep it.var pathToTopLevelNodeModules = getCanonicalFileName(moduleSpecifier.substring(0, parts.topLevelNodeModulesIndex));- if (!(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {+ // If PnP is enabled the node_modules entries we'll get will always be relevant even if they+ // are located in a weird path apparently outside of the source directory+ if (!isPnpAvailable() && !(ts.startsWith(sourceDirectory, pathToTopLevelNodeModules) || globalTypingsCacheLocation && ts.startsWith(getCanonicalFileName(globalTypingsCacheLocation), pathToTopLevelNodeModules))) {return undefined;}// If the module was found in @types, get the actual Node package name"

Object literals

Const plugin

plugin: object

hooks

hooks: object

getBuiltinPatch

  • getBuiltinPatch(project: Project, name: string): Promise<undefined | null | string>

reduceDependency

registerPackageExtensions

  • registerPackageExtensions(configuration: Configuration, registerPackageExtension: function): Promise<void>

Generated using TypeDoc