@@ -35,9 +35,10 @@ async function mergeCache(cache, key, value) {
35
35
/**
36
36
* @param {import('.').ExtensionDemand } extensionDemand
37
37
* @param {* } cache
38
+ * @param {string } extensionDir
38
39
*/
39
- async function syncExtensionData ( { identifier } , cache ) {
40
- const packageJsonPath = path . join ( getExtensionPath ( identifier ) , 'package.json' ) ;
40
+ async function syncExtensionData ( { identifier } , cache , extensionDir ) {
41
+ const packageJsonPath = path . join ( getExtensionPath ( identifier , extensionDir ) , 'package.json' ) ;
41
42
const { grammars, themes } = await processExtension ( packageJsonPath ) ;
42
43
Object . keys ( grammars ) . forEach ( scopeName => ( grammars [ scopeName ] . languageId = languageId ++ ) ) ;
43
44
await mergeCache ( cache , 'grammars' , grammars ) ;
@@ -47,8 +48,9 @@ async function syncExtensionData({ identifier }, cache) {
47
48
/**
48
49
* @param {import('.').ExtensionDemand } extensionDemand
49
50
* @param {* } cache
51
+ * @param {string } extensionDir
50
52
*/
51
- async function downloadExtension ( extensionDemand , cache ) {
53
+ async function downloadExtension ( extensionDemand , cache , extensionDir ) {
52
54
const { identifier, version } = extensionDemand ;
53
55
const { publisher, name } = parseExtensionIdentifier ( identifier ) ;
54
56
const url = `https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${ publisher } /vsextensions/${ name } /${ version } /vspackage` ;
@@ -73,37 +75,43 @@ async function downloadExtension(extensionDemand, cache) {
73
75
} ) ;
74
76
} ) ;
75
77
76
- const extensionPath = getExtensionBasePath ( identifier ) ;
78
+ const extensionPath = getExtensionBasePath ( identifier , extensionDir ) ;
77
79
await decompress ( archive , extensionPath ) ;
78
- await syncExtensionData ( extensionDemand , cache ) ;
80
+ await syncExtensionData ( extensionDemand , cache , extensionDir ) ;
79
81
return extensionPath ;
80
82
}
81
83
82
84
/**
83
- * @param {'grammar' | 'theme' } type
84
- * @param {string } name
85
- * @param {import('.').ExtensionDemand[] } extensions
86
- * @param {* } cache
87
- * @param {Record<string, string> } languageAliases
85
+ * @typedef {object } DownloadExtensionOptions
86
+ * @property {'grammar' | 'theme' } type
87
+ * @property {string } name
88
+ * @property {import('.').ExtensionDemand[] } extensions
89
+ * @property {* } cache
90
+ * @property {Record<string, string> } languageAliases
91
+ * @property {string } extensionDir
92
+ */
93
+
94
+ /**
95
+ * @param {DownloadExtensionOptions } options
88
96
*/
89
- async function downloadExtensionIfNeeded ( type , name , extensions , cache , languageAliases ) {
97
+ async function downloadExtensionIfNeeded ( { type, name, extensions, cache, languageAliases, extensionDir } ) {
90
98
extensions = extensions . slice ( ) ;
91
99
const extensionExists = type === 'grammar' ? grammarExists : themeExists ;
92
100
while ( extensions . length && ! ( await extensionExists ( name ) ) ) {
93
101
const extensionDemand = extensions . shift ( ) ;
94
102
const { identifier, version } = extensionDemand ;
95
- const extensionPath = getExtensionBasePath ( identifier ) ;
103
+ const extensionPath = getExtensionBasePath ( identifier , extensionDir ) ;
96
104
if ( ! fs . existsSync ( extensionPath ) ) {
97
- await downloadExtension ( extensionDemand , cache ) ;
105
+ await downloadExtension ( extensionDemand , cache , extensionDir ) ;
98
106
continue ;
99
107
}
100
- const packageJson = getExtensionPackageJson ( identifier ) ;
108
+ const packageJson = getExtensionPackageJson ( identifier , extensionDir ) ;
101
109
if ( packageJson . version !== version ) {
102
- await downloadExtension ( extensionDemand , cache ) ;
110
+ await downloadExtension ( extensionDemand , cache , extensionDir ) ;
103
111
continue ;
104
112
}
105
113
106
- await syncExtensionData ( extensionDemand , cache ) ;
114
+ await syncExtensionData ( extensionDemand , cache , extensionDir ) ;
107
115
}
108
116
109
117
/** @param {string } languageName */
0 commit comments