Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
81c9518
Fix getResolvePackageJsonImports utility (#61707)
andrewbranch May 16, 2025
b504a1e
Handle lock file 3 version when caching the typings ensuring we can r…
sheetalkamat May 21, 2025
44d4671
Update pr_owners.txt (#61798)
jakebailey Jun 3, 2025
3dd0a35
Initialize the map for dts to reference and source to reference when …
sheetalkamat Jun 4, 2025
2b88aeb
LEGO: Pull request from lego/hb_5378966c-b857-470a-8675-daebef4a6da1_…
csigs Jun 4, 2025
a591ca3
fix(61747): for (using of = is incorrectly parsed (#61764)
a-tarasyuk Jun 5, 2025
ac03ba4
fix(checker): report error when using bigint as enum key (#61777)
magic-akari Jun 5, 2025
cd34199
tsc --init update (#61813)
RyanCavanaugh Jun 6, 2025
a69c6d0
Add support for `import defer` proposal (#60757)
nicolo-ribaudo Jun 6, 2025
ffd98c1
feat: add Error.isError() to ESNext lib (#60788)
dirkluijk Jun 6, 2025
51dcd90
Cache mapper instantiations (#61505)
Andarist Jun 6, 2025
652ed7f
Add lib.esnext.sharedmemory (#61646)
Renegade334 Jun 6, 2025
1e24945
explicitly disallow `using` in ambient contexts (#61781)
Renegade334 Jun 6, 2025
fa2a0fc
Issue "'{0}' declarations can only be declared inside a block." for b…
Andarist Jun 6, 2025
7715955
Fix helpers emit for .cjs files in ESM module mode (#61814)
andrewbranch Jun 6, 2025
355b9e0
Avoid resolving source prop type when the target is `unknown`/`any` (…
Andarist Jun 6, 2025
97cfa26
optimization, reduce memory usage (#61822)
VincentBailly Jun 9, 2025
cb38d99
Add `--module node20` (#61805)
andrewbranch Jun 9, 2025
34d1ea6
Fix type variable leaks and cache inconsistencies (#61668)
ahejlsberg Jun 9, 2025
0dfd0c2
Restore `import defer =` parsing (#61837)
nicolo-ribaudo Jun 9, 2025
12e09f4
Port "Improve type discrimination algorithm" from tsgo (#61828)
jakebailey Jun 9, 2025
529ed09
fix link to "Help Wanted" issues (#61843)
AllenSH12 Jun 11, 2025
dd1e258
LEGO: Pull request from lego/hb_5378966c-b857-470a-8675-daebef4a6da1_…
csigs Jun 11, 2025
f1d2494
LEGO: Pull request from lego/hb_5378966c-b857-470a-8675-daebef4a6da1_…
csigs Jun 17, 2025
5a3271b
LEGO: Pull request from lego/hb_5378966c-b857-470a-8675-daebef4a6da1_…
csigs Jun 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle lock file 3 version when caching the typings ensuring we can r…
…euse already installed packages (microsoft#61730)
  • Loading branch information
sheetalkamat authored May 21, 2025
commit b504a1eed45e35b5f54694a1e0a09f35d0a5663c
107 changes: 107 additions & 0 deletions src/testRunner/unittests/tsserver/typingsInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,113 @@ describe("unittests:: tsserver:: typingsInstaller:: General functionality", () =
host.runPendingInstalls();
baselineTsserverLogs("typingsInstaller", "non expired cache entry", session);
});

it("expired cache entry (inferred project, should install typings) lockFile3", () => {
const file1 = {
path: "/home/src/projects/project/app.js",
content: "",
};
const packageJson = {
path: "/home/src/projects/project/package.json",
content: jsonToReadableText({
name: "test",
dependencies: {
jquery: "^3.1.0",
},
}),
};
const jquery = {
path: getPathForTypeScriptTypingInstallerCacheTest("node_modules/@types/jquery/index.d.ts"),
content: "declare const $: { x: number }",
};
const cacheConfig = {
path: getPathForTypeScriptTypingInstallerCacheTest("package.json"),
content: jsonToReadableText({
dependencies: {
"types-registry": "^0.1.317",
},
devDependencies: {
"@types/jquery": "^1.0.0",
},
}),
};
const cacheLockConfig = {
path: getPathForTypeScriptTypingInstallerCacheTest("package-lock.json"),
content: jsonToReadableText({
packages: {
"node_modules/@types/jquery": {
version: "1.0.0",
},
},
}),
};
const host = TestServerHost.createServerHost(
[file1, packageJson, jquery, cacheConfig, cacheLockConfig],
{ typingsInstallerTypesRegistry: "jquery" },
);
const session = new TestSession({
host,
useSingleInferredProject: true,
installAction: [jquery],
});
openFilesForSession([file1], session);
host.runPendingInstalls();
host.runQueuedTimeoutCallbacks();
baselineTsserverLogs("typingsInstaller", "expired cache entry lockFile3", session);
});

it("non-expired cache entry (inferred project, should not install typings) lockFile3", () => {
const file1 = {
path: "/home/src/projects/project/app.js",
content: "",
};
const packageJson = {
path: "/home/src/projects/project/package.json",
content: jsonToReadableText({
name: "test",
dependencies: {
jquery: "^3.1.0",
},
}),
};
const cacheConfig = {
path: getPathForTypeScriptTypingInstallerCacheTest("package.json"),
content: jsonToReadableText({
dependencies: {
"types-registry": "^0.1.317",
},
devDependencies: {
"@types/jquery": "^1.3.0",
},
}),
};
const cacheLockConfig = {
path: getPathForTypeScriptTypingInstallerCacheTest("package-lock.json"),
content: jsonToReadableText({
packages: {
"node_modules/@types/jquery": {
version: "1.3.0",
},
},
}),
};
const jquery = {
path: getPathForTypeScriptTypingInstallerCacheTest("node_modules/@types/jquery/index.d.ts"),
content: "declare const $: { x: number }",
};
const host = TestServerHost.createServerHost(
[file1, packageJson, cacheConfig, cacheLockConfig, jquery],
{ typingsInstallerTypesRegistry: "jquery" },
);
const session = new TestSession({
host,
useSingleInferredProject: true,
installAction: true,
});
openFilesForSession([file1], session);
host.runPendingInstalls();
baselineTsserverLogs("typingsInstaller", "non expired cache entry lockFile3", session);
});
});

describe("unittests:: tsserver:: typingsInstaller:: Validate package name:", () => {
Expand Down
16 changes: 12 additions & 4 deletions src/typingsInstallerCore/typingsInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ interface NpmConfig {
}

interface NpmLock {
dependencies: { [packageName: string]: { version: string; }; };
dependencies?: { [packageName: string]: { version: string; }; };
packages?: {
[nodeModulesAtTypesPackage: string]: { version: string; };
};
}

export interface Log {
Expand Down Expand Up @@ -304,9 +307,13 @@ export abstract class TypingsInstaller {
this.log.writeLine(`Loaded content of '${packageJson}':${stringifyIndented(npmConfig)}`);
this.log.writeLine(`Loaded content of '${packageLockJson}':${stringifyIndented(npmLock)}`);
}
if (npmConfig.devDependencies && npmLock.dependencies) {
// Packages is present in lock file 3 vs lockfile 2 has dependencies field for already installed types package
if (npmConfig.devDependencies && (npmLock.packages || npmLock.dependencies)) {
for (const key in npmConfig.devDependencies) {
if (!hasProperty(npmLock.dependencies, key)) {
if (
(npmLock.packages && !hasProperty(npmLock.packages, `node_modules/${key}`)) ||
(npmLock.dependencies && !hasProperty(npmLock.dependencies, key))
) {
// if package in package.json but not package-lock.json, skip adding to cache so it is reinstalled on next use
continue;
}
Expand All @@ -333,7 +340,8 @@ export abstract class TypingsInstaller {
if (this.log.isEnabled()) {
this.log.writeLine(`Adding entry into typings cache: '${packageName}' => '${typingFile}'`);
}
const info = getProperty(npmLock.dependencies, key);
const info = npmLock.packages && getProperty(npmLock.packages, `node_modules/${key}`) ||
getProperty(npmLock.dependencies!, key);
const version = info && info.version;
if (!version) {
continue;
Expand Down
Loading