Skip to content

Commit 8721a18

Browse files
committed
Handle lock file 3
1 parent 245bfc2 commit 8721a18

3 files changed

Lines changed: 64 additions & 119 deletions

File tree

src/typingsInstallerCore/typingsInstaller.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ interface NpmConfig {
4646
}
4747

4848
interface NpmLock {
49-
dependencies: { [packageName: string]: { version: string; }; };
49+
dependencies?: { [packageName: string]: { version: string; }; };
50+
packages?: {
51+
[nodeModulesAtTypesPackage: string]: { version: string; };
52+
};
5053
}
5154

5255
export interface Log {
@@ -304,9 +307,12 @@ export abstract class TypingsInstaller {
304307
this.log.writeLine(`Loaded content of '${packageJson}':${stringifyIndented(npmConfig)}`);
305308
this.log.writeLine(`Loaded content of '${packageLockJson}':${stringifyIndented(npmLock)}`);
306309
}
307-
if (npmConfig.devDependencies && npmLock.dependencies) {
310+
if (npmConfig.devDependencies && (npmLock.packages || npmLock.dependencies)) {
308311
for (const key in npmConfig.devDependencies) {
309-
if (!hasProperty(npmLock.dependencies, key)) {
312+
if (
313+
(npmLock.packages && !hasProperty(npmLock.packages, `node_modules/${key}`)) ||
314+
(npmLock.dependencies && !hasProperty(npmLock.dependencies, key))
315+
) {
310316
// if package in package.json but not package-lock.json, skip adding to cache so it is reinstalled on next use
311317
continue;
312318
}
@@ -333,7 +339,8 @@ export abstract class TypingsInstaller {
333339
if (this.log.isEnabled()) {
334340
this.log.writeLine(`Adding entry into typings cache: '${packageName}' => '${typingFile}'`);
335341
}
336-
const info = getProperty(npmLock.dependencies, key);
342+
const info = npmLock.packages && getProperty(npmLock.packages, `node_modules/${key}`) ||
343+
getProperty(npmLock.dependencies!, key);
337344
const version = info && info.version;
338345
if (!version) {
339346
continue;

tests/baselines/reference/tsserver/typingsInstaller/expired-cache-entry-lockFile3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ TI:: [hh:mm:ss:mss] Loaded content of '/home/src/Library/Caches/typescript/packa
156156
}
157157
}
158158
}
159+
TI:: [hh:mm:ss:mss] Adding entry into typings cache: 'jquery' => '/home/src/Library/Caches/typescript/node_modules/@types/jquery/index.d.ts'
159160
TI:: [hh:mm:ss:mss] Finished processing cache location '/home/src/Library/Caches/typescript'
160161
TI:: [hh:mm:ss:mss] Npm config file: /home/src/Library/Caches/typescript/package.json
161162
TI:: [hh:mm:ss:mss] Updating types-registry npm package...

tests/baselines/reference/tsserver/typingsInstaller/non-expired-cache-entry-lockFile3.js

Lines changed: 52 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ TI:: [hh:mm:ss:mss] Loaded content of '/home/src/Library/Caches/typescript/packa
156156
}
157157
}
158158
}
159+
TI:: [hh:mm:ss:mss] Adding entry into typings cache: 'jquery' => '/home/src/Library/Caches/typescript/node_modules/@types/jquery/index.d.ts'
159160
TI:: [hh:mm:ss:mss] Finished processing cache location '/home/src/Library/Caches/typescript'
160161
TI:: [hh:mm:ss:mss] Npm config file: /home/src/Library/Caches/typescript/package.json
161162
TI:: [hh:mm:ss:mss] Updating types-registry npm package...
@@ -193,10 +194,10 @@ TI:: [hh:mm:ss:mss] Typing names in '/home/src/projects/project/package.json' de
193194
TI:: [hh:mm:ss:mss] Inferred typings from unresolved imports: []
194195
TI:: [hh:mm:ss:mss] Finished typings discovery:
195196
{
196-
"cachedTypingPaths": [],
197-
"newTypingNames": [
198-
"jquery"
197+
"cachedTypingPaths": [
198+
"/home/src/Library/Caches/typescript/node_modules/@types/jquery/index.d.ts"
199199
],
200+
"newTypingNames": [],
200201
"filesToWatch": [
201202
"/home/src/projects/project/bower_components",
202203
"/home/src/projects/project/package.json",
@@ -226,95 +227,6 @@ Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/
226227
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/Projects/bin/bower_components 1 undefined Project: /dev/null/inferredProject1* WatchType: Directory location for typing installer
227228
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/Projects/bin/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Directory location for typing installer
228229
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /home/src/Vscode/Projects/bin/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Directory location for typing installer
229-
TI:: [hh:mm:ss:mss] Installing typings ["jquery"]
230-
TI:: [hh:mm:ss:mss] Npm config file: /home/src/Library/Caches/typescript/package.json
231-
TI:: [hh:mm:ss:mss] Sending response:
232-
{
233-
"kind": "event::beginInstallTypes",
234-
"eventId": 1,
235-
"typingsInstallerVersion": "FakeVersion",
236-
"projectName": "/dev/null/inferredProject1*"
237-
}
238-
Info seq [hh:mm:ss:mss] event:
239-
{
240-
"seq": 0,
241-
"type": "event",
242-
"event": "beginInstallTypes",
243-
"body": {
244-
"eventId": 1
245-
}
246-
}
247-
TI:: [hh:mm:ss:mss] #1 with cwd: /home/src/Library/Caches/typescript arguments: [
248-
"@types/jquery@tsFakeMajor.Minor"
249-
]
250-
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
251-
Info seq [hh:mm:ss:mss] Files (2)
252-
253-
Info seq [hh:mm:ss:mss] -----------------------------------------------
254-
Info seq [hh:mm:ss:mss] Open files:
255-
Info seq [hh:mm:ss:mss] FileName: /home/src/projects/project/app.js ProjectRootPath: undefined
256-
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1*
257-
Info seq [hh:mm:ss:mss] response:
258-
{
259-
"seq": 0,
260-
"type": "response",
261-
"command": "open",
262-
"request_seq": 1,
263-
"success": true,
264-
"performanceData": {
265-
"updateGraphDurationMs": *
266-
}
267-
}
268-
After request
269-
270-
PolledWatches::
271-
/home/src/Vscode/Projects/bin/bower_components: *new*
272-
{"pollingInterval":500}
273-
/home/src/Vscode/Projects/bin/node_modules: *new*
274-
{"pollingInterval":500}
275-
/home/src/Vscode/Projects/bin/node_modules/@types:
276-
{"pollingInterval":500}
277-
/home/src/Vscode/Projects/node_modules/@types:
278-
{"pollingInterval":500}
279-
/home/src/Vscode/node_modules/@types:
280-
{"pollingInterval":500}
281-
/home/src/projects/project/bower_components: *new*
282-
{"pollingInterval":500}
283-
/home/src/projects/project/jsconfig.json:
284-
{"pollingInterval":2000}
285-
/home/src/projects/project/node_modules: *new*
286-
{"pollingInterval":500}
287-
/home/src/projects/project/tsconfig.json:
288-
{"pollingInterval":2000}
289-
290-
FsWatches::
291-
/home/src/projects/project/package.json: *new*
292-
{}
293-
/home/src/tslibs/TS/Lib/lib.d.ts:
294-
{}
295-
296-
PendingInstalls callback:: count: 1
297-
1: #1 with arguments:: [
298-
"@types/jquery@tsFakeMajor.Minor"
299-
] *new*
300-
301-
Projects::
302-
/dev/null/inferredProject1* (Inferred) *changed*
303-
projectStateVersion: 1
304-
projectProgramVersion: 1 *changed*
305-
autoImportProviderHost: false *changed*
306-
307-
Before running PendingInstalls callback:: count: 1
308-
1: #1 with arguments:: [
309-
"@types/jquery@tsFakeMajor.Minor"
310-
]
311-
312-
TI:: Installation #1 with arguments:: [
313-
"@types/jquery@tsFakeMajor.Minor"
314-
] complete with success::true
315-
316-
TI:: [hh:mm:ss:mss] Installed typings ["@types/jquery@tsFakeMajor.Minor"]
317-
TI:: [hh:mm:ss:mss] Installed typing files ["/home/src/Library/Caches/typescript/node_modules/@types/jquery/index.d.ts"]
318230
TI:: [hh:mm:ss:mss] Sending response:
319231
{
320232
"projectName": "/dev/null/inferredProject1*",
@@ -366,31 +278,52 @@ Info seq [hh:mm:ss:mss] event:
366278
"kind": "action::set"
367279
}
368280
}
369-
TI:: [hh:mm:ss:mss] Sending response:
370-
{
371-
"kind": "event::endInstallTypes",
372-
"eventId": 1,
373-
"projectName": "/dev/null/inferredProject1*",
374-
"packagesToInstall": [
375-
"@types/jquery@tsFakeMajor.Minor"
376-
],
377-
"installSuccess": true,
378-
"typingsInstallerVersion": "FakeVersion"
379-
}
380-
Info seq [hh:mm:ss:mss] event:
281+
TI:: [hh:mm:ss:mss] No new typings were requested as a result of typings discovery
282+
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
283+
Info seq [hh:mm:ss:mss] Files (2)
284+
285+
Info seq [hh:mm:ss:mss] -----------------------------------------------
286+
Info seq [hh:mm:ss:mss] Open files:
287+
Info seq [hh:mm:ss:mss] FileName: /home/src/projects/project/app.js ProjectRootPath: undefined
288+
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1*
289+
Info seq [hh:mm:ss:mss] response:
381290
{
382291
"seq": 0,
383-
"type": "event",
384-
"event": "endInstallTypes",
385-
"body": {
386-
"eventId": 1,
387-
"packages": [
388-
"@types/jquery@tsFakeMajor.Minor"
389-
],
390-
"success": true
292+
"type": "response",
293+
"command": "open",
294+
"request_seq": 1,
295+
"success": true,
296+
"performanceData": {
297+
"updateGraphDurationMs": *
391298
}
392299
}
393-
After running PendingInstalls callback:: count: 0
300+
After request
301+
302+
PolledWatches::
303+
/home/src/Vscode/Projects/bin/bower_components: *new*
304+
{"pollingInterval":500}
305+
/home/src/Vscode/Projects/bin/node_modules: *new*
306+
{"pollingInterval":500}
307+
/home/src/Vscode/Projects/bin/node_modules/@types:
308+
{"pollingInterval":500}
309+
/home/src/Vscode/Projects/node_modules/@types:
310+
{"pollingInterval":500}
311+
/home/src/Vscode/node_modules/@types:
312+
{"pollingInterval":500}
313+
/home/src/projects/project/bower_components: *new*
314+
{"pollingInterval":500}
315+
/home/src/projects/project/jsconfig.json:
316+
{"pollingInterval":2000}
317+
/home/src/projects/project/node_modules: *new*
318+
{"pollingInterval":500}
319+
/home/src/projects/project/tsconfig.json:
320+
{"pollingInterval":2000}
321+
322+
FsWatches::
323+
/home/src/projects/project/package.json: *new*
324+
{}
325+
/home/src/tslibs/TS/Lib/lib.d.ts:
326+
{}
394327

395328
Timeout callback:: count: 2
396329
1: /dev/null/inferredProject1* *new*
@@ -399,6 +332,10 @@ Timeout callback:: count: 2
399332
Projects::
400333
/dev/null/inferredProject1* (Inferred) *changed*
401334
projectStateVersion: 2 *changed*
402-
projectProgramVersion: 1
335+
projectProgramVersion: 1 *changed*
403336
dirty: true *changed*
404-
autoImportProviderHost: false
337+
autoImportProviderHost: false *changed*
338+
339+
Before running PendingInstalls callback:: count: 0
340+
341+
After running PendingInstalls callback:: count: 0

0 commit comments

Comments
 (0)