11#!/usr/bin/env node
22
33const { existsSync} = require ( `fs` ) ;
4- const { createRequire, createRequireFromPath } = require ( `module` ) ;
4+ const { createRequire} = require ( `module` ) ;
55const { resolve} = require ( `path` ) ;
66
77const relPnpApiPath = "../../../../.pnp.cjs" ;
88
99const absPnpApiPath = resolve ( __dirname , relPnpApiPath ) ;
10- const absRequire = ( createRequire || createRequireFromPath ) ( absPnpApiPath ) ;
10+ const absRequire = createRequire ( absPnpApiPath ) ;
1111
1212const moduleWrapper = tsserver => {
1313 if ( ! process . versions . pnp ) {
@@ -61,14 +61,30 @@ const moduleWrapper = tsserver => {
6161 //
6262 // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
6363 //
64- // Update Oct 8 2021: VSCode changed their format in 1.61.
64+ // 2021-10-08 : VSCode changed the format in 1.61.
6565 // Before | ^zip:/c:/foo/bar.zip/package.json
6666 // After | ^/zip//c:/foo/bar.zip/package.json
6767 //
68+ // 2022-04-06: VSCode changed the format in 1.66.
69+ // Before | ^/zip//c:/foo/bar.zip/package.json
70+ // After | ^/zip/c:/foo/bar.zip/package.json
71+ //
72+ // 2022-05-06: VSCode changed the format in 1.68
73+ // Before | ^/zip/c:/foo/bar.zip/package.json
74+ // After | ^/zip//c:/foo/bar.zip/package.json
75+ //
6876 case `vscode <1.61` : {
6977 str = `^zip:${ str } ` ;
7078 } break ;
7179
80+ case `vscode <1.66` : {
81+ str = `^/zip/${ str } ` ;
82+ } break ;
83+
84+ case `vscode <1.68` : {
85+ str = `^/zip${ str } ` ;
86+ } break ;
87+
7288 case `vscode` : {
7389 str = `^/zip/${ str } ` ;
7490 } break ;
@@ -93,6 +109,8 @@ const moduleWrapper = tsserver => {
93109 str = `zip:${ str } ` ;
94110 } break ;
95111 }
112+ } else {
113+ str = str . replace ( / ^ \/ ? / , process . platform === `win32` ? `` : `/` ) ;
96114 }
97115 }
98116
@@ -119,9 +137,7 @@ const moduleWrapper = tsserver => {
119137
120138 case `vscode` :
121139 default : {
122- return process . platform === `win32`
123- ? str . replace ( / ^ \^ ? ( z i p : | \/ z i p ) \/ + / , `` )
124- : str . replace ( / ^ \^ ? ( z i p : | \/ z i p ) \/ + / , `/` ) ;
140+ return str . replace ( / ^ \^ ? ( z i p : | \/ z i p ( \/ t s - n u l - a u t h o r i t y ) ? ) \/ + / , process . platform === `win32` ? `` : `/` )
125141 } break ;
126142 }
127143 }
@@ -160,8 +176,21 @@ const moduleWrapper = tsserver => {
160176 typeof parsedMessage . arguments . hostInfo === `string`
161177 ) {
162178 hostInfo = parsedMessage . arguments . hostInfo ;
163- if ( hostInfo === `vscode` && process . env . VSCODE_IPC_HOOK && process . env . VSCODE_IPC_HOOK . match ( / C o d e \/ 1 \. ( [ 1 - 5 ] [ 0 - 9 ] | 6 0 ) \. / ) ) {
164- hostInfo += ` <1.61` ;
179+ if ( hostInfo === `vscode` && process . env . VSCODE_IPC_HOOK ) {
180+ const [ , major , minor ] = ( process . env . VSCODE_IPC_HOOK . match (
181+ // The RegExp from https://semver.org/ but without the caret at the start
182+ / ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) (?: - ( (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z A - Z - ] [ 0 - 9 a - z A - Z - ] * ) (?: \. (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z A - Z - ] [ 0 - 9 a - z A - Z - ] * ) ) * ) ) ? (?: \+ ( [ 0 - 9 a - z A - Z - ] + (?: \. [ 0 - 9 a - z A - Z - ] + ) * ) ) ? $ /
183+ ) ?? [ ] ) . map ( Number )
184+
185+ if ( major === 1 ) {
186+ if ( minor < 61 ) {
187+ hostInfo += ` <1.61` ;
188+ } else if ( minor < 66 ) {
189+ hostInfo += ` <1.66` ;
190+ } else if ( minor < 68 ) {
191+ hostInfo += ` <1.68` ;
192+ }
193+ }
165194 }
166195 }
167196
0 commit comments