@volar/monaco 2.4.0-alpha.4 → 2.4.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ata.d.ts +1 -1
- package/lib/ata.js +45 -34
- package/package.json +4 -4
package/lib/ata.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { FileSystem } from '@volar/language-service';
|
|
2
2
|
import type { URI } from 'vscode-uri';
|
|
3
|
-
export declare function createJsDelivrNpmFileSystem(getCdnPath
|
|
3
|
+
export declare function createJsDelivrNpmFileSystem(getCdnPath?: (uri: URI) => string | undefined, getPackageVersion?: (pkgName: string) => string | undefined, onFetch?: (path: string, content: string) => void): FileSystem;
|
package/lib/ata.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
const textCache = new Map();
|
|
2
2
|
const jsonCache = new Map();
|
|
3
|
-
export function createJsDelivrNpmFileSystem(getCdnPath
|
|
3
|
+
export function createJsDelivrNpmFileSystem(getCdnPath = (uri) => {
|
|
4
|
+
if (uri.path === '/node_modules') {
|
|
5
|
+
return '';
|
|
6
|
+
}
|
|
7
|
+
else if (uri.path.startsWith('/node_modules/')) {
|
|
8
|
+
return uri.path.slice('/node_modules'.length);
|
|
9
|
+
}
|
|
10
|
+
}, getPackageVersion, onFetch) {
|
|
4
11
|
const fetchResults = new Map();
|
|
5
12
|
const flatResults = new Map();
|
|
6
13
|
return {
|
|
@@ -9,6 +16,14 @@ export function createJsDelivrNpmFileSystem(getCdnPath, resolvePackageName, onFe
|
|
|
9
16
|
if (path === undefined) {
|
|
10
17
|
return;
|
|
11
18
|
}
|
|
19
|
+
if (path === '') {
|
|
20
|
+
return {
|
|
21
|
+
type: 2,
|
|
22
|
+
size: -1,
|
|
23
|
+
ctime: -1,
|
|
24
|
+
mtime: -1,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
12
27
|
return await _stat(path);
|
|
13
28
|
},
|
|
14
29
|
async readFile(uri) {
|
|
@@ -27,15 +42,15 @@ export function createJsDelivrNpmFileSystem(getCdnPath, resolvePackageName, onFe
|
|
|
27
42
|
},
|
|
28
43
|
};
|
|
29
44
|
async function _stat(path) {
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
45
|
+
const resolved = resolvePackageName(path);
|
|
46
|
+
if (!resolved || !await isValidPackageName(resolved[1])) {
|
|
32
47
|
return;
|
|
33
48
|
}
|
|
34
|
-
if (!flatResults.has(
|
|
35
|
-
flatResults.set(
|
|
49
|
+
if (!flatResults.has(resolved[0])) {
|
|
50
|
+
flatResults.set(resolved[0], flat(resolved[1], resolved[2]));
|
|
36
51
|
}
|
|
37
|
-
const flatResult = await flatResults.get(
|
|
38
|
-
const filePath = path.slice(
|
|
52
|
+
const flatResult = await flatResults.get(resolved[0]);
|
|
53
|
+
const filePath = path.slice(resolved[0].length);
|
|
39
54
|
const file = flatResult.find(file => file.name === filePath);
|
|
40
55
|
if (file) {
|
|
41
56
|
return {
|
|
@@ -55,15 +70,15 @@ export function createJsDelivrNpmFileSystem(getCdnPath, resolvePackageName, onFe
|
|
|
55
70
|
}
|
|
56
71
|
}
|
|
57
72
|
async function _readDirectory(path) {
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
73
|
+
const resolved = resolvePackageName(path);
|
|
74
|
+
if (!resolved || !await isValidPackageName(resolved[1])) {
|
|
60
75
|
return [];
|
|
61
76
|
}
|
|
62
|
-
if (!flatResults.has(
|
|
63
|
-
flatResults.set(
|
|
77
|
+
if (!flatResults.has(resolved[0])) {
|
|
78
|
+
flatResults.set(resolved[0], flat(resolved[1], resolved[2]));
|
|
64
79
|
}
|
|
65
|
-
const flatResult = await flatResults.get(
|
|
66
|
-
const dirPath = path.slice(
|
|
80
|
+
const flatResult = await flatResults.get(resolved[0]);
|
|
81
|
+
const dirPath = path.slice(resolved[0].length);
|
|
67
82
|
const files = flatResult
|
|
68
83
|
.filter(f => f.name.substring(0, f.name.lastIndexOf('/')) === dirPath)
|
|
69
84
|
.map(f => f.name.slice(dirPath.length + 1));
|
|
@@ -76,8 +91,8 @@ export function createJsDelivrNpmFileSystem(getCdnPath, resolvePackageName, onFe
|
|
|
76
91
|
];
|
|
77
92
|
}
|
|
78
93
|
async function _readFile(path) {
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
94
|
+
const resolved = resolvePackageName(path);
|
|
95
|
+
if (!resolved || !await isValidPackageName(resolved[1])) {
|
|
81
96
|
return;
|
|
82
97
|
}
|
|
83
98
|
if (!fetchResults.has(path)) {
|
|
@@ -94,13 +109,7 @@ export function createJsDelivrNpmFileSystem(getCdnPath, resolvePackageName, onFe
|
|
|
94
109
|
}
|
|
95
110
|
return await fetchResults.get(path);
|
|
96
111
|
}
|
|
97
|
-
async function flat(
|
|
98
|
-
let pkgName = pkgNameWithVersion;
|
|
99
|
-
let version;
|
|
100
|
-
if (pkgNameWithVersion.substring(1).includes('@')) {
|
|
101
|
-
pkgName = pkgNameWithVersion.substring(0, pkgNameWithVersion.lastIndexOf('@'));
|
|
102
|
-
version = pkgNameWithVersion.substring(pkgNameWithVersion.lastIndexOf('@') + 1);
|
|
103
|
-
}
|
|
112
|
+
async function flat(pkgName, version) {
|
|
104
113
|
version ??= 'latest';
|
|
105
114
|
// resolve latest tag
|
|
106
115
|
if (version === 'latest') {
|
|
@@ -117,10 +126,6 @@ export function createJsDelivrNpmFileSystem(getCdnPath, resolvePackageName, onFe
|
|
|
117
126
|
return flat.files;
|
|
118
127
|
}
|
|
119
128
|
async function isValidPackageName(pkgName) {
|
|
120
|
-
// @aaa/bbb@latest -> @aaa/bbb
|
|
121
|
-
if (pkgName.lastIndexOf('@') >= 1) {
|
|
122
|
-
pkgName = pkgName.substring(0, pkgName.lastIndexOf('@'));
|
|
123
|
-
}
|
|
124
129
|
// ignore @aaa/node_modules
|
|
125
130
|
if (pkgName.endsWith('/node_modules')) {
|
|
126
131
|
return false;
|
|
@@ -155,19 +160,25 @@ export function createJsDelivrNpmFileSystem(getCdnPath, resolvePackageName, onFe
|
|
|
155
160
|
* "@a/b/c" -> "@a/b"
|
|
156
161
|
* "@a/b@1.2.3/c" -> "@a/b@1.2.3"
|
|
157
162
|
*/
|
|
158
|
-
function
|
|
163
|
+
function resolvePackageName(path) {
|
|
159
164
|
const parts = path.split('/');
|
|
160
|
-
let
|
|
161
|
-
if (
|
|
165
|
+
let modName = parts[0];
|
|
166
|
+
if (modName.startsWith('@')) {
|
|
162
167
|
if (!parts[1]) {
|
|
163
|
-
return
|
|
168
|
+
return;
|
|
164
169
|
}
|
|
165
|
-
|
|
170
|
+
modName += '/' + parts[1];
|
|
171
|
+
}
|
|
172
|
+
let pkgName = modName;
|
|
173
|
+
let version;
|
|
174
|
+
if (modName.lastIndexOf('@') >= 1) {
|
|
175
|
+
pkgName = modName.substring(0, modName.lastIndexOf('@'));
|
|
176
|
+
version = modName.substring(modName.lastIndexOf('@') + 1);
|
|
166
177
|
}
|
|
167
|
-
if (
|
|
168
|
-
|
|
178
|
+
if (!version && getPackageVersion) {
|
|
179
|
+
getPackageVersion?.(pkgName);
|
|
169
180
|
}
|
|
170
|
-
return pkgName;
|
|
181
|
+
return [modName, pkgName, version];
|
|
171
182
|
}
|
|
172
183
|
}
|
|
173
184
|
async function fetchText(url) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/monaco",
|
|
3
|
-
"version": "2.4.0-alpha.
|
|
3
|
+
"version": "2.4.0-alpha.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/monaco"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-service": "2.4.0-alpha.
|
|
17
|
-
"@volar/typescript": "2.4.0-alpha.
|
|
16
|
+
"@volar/language-service": "2.4.0-alpha.6",
|
|
17
|
+
"@volar/typescript": "2.4.0-alpha.6",
|
|
18
18
|
"monaco-languageserver-types": "^0.3.4",
|
|
19
19
|
"monaco-types": "^0.1.0",
|
|
20
20
|
"vscode-uri": "^3.0.8"
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"monaco-editor-core": "latest"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "7e6c0b8fb66d09037b3540bbac2c4d976b1110ce"
|
|
26
26
|
}
|