@delance/runtime 2024.12.1 → 2024.12.100-patch1

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.
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('./v2024.12.1-2e91db5ed8551efad5675c6a0530df175463ce01229505551dfcb4b65ba6fc15/server.bundle.js');
3
+ require('./v2024.12.100-patch1-a040b24fa18f6de20de211e78d8a6467a3f88fb34493439e74909b437292ec98/server.bundle.js');
package/install.mjs CHANGED
@@ -1,24 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import assert, {AssertionError} from 'node:assert';
4
- import {subtle} from 'node:crypto';
3
+ // @ts-check
4
+ import assert from 'node:assert';
5
5
  import fs from 'node:fs/promises';
6
6
  import path from 'node:path';
7
7
  import process from 'node:process';
8
8
  import delance from '@delance/builder';
9
9
  import {BlobReader, BlobWriter, TextWriter, ZipReader} from '@zip.js/zip.js';
10
- import pMap from 'p-map';
11
- import pRetry, {AbortError} from 'p-retry';
10
+ import map from 'p-map';
12
11
 
13
- import pkg from './package.json' with {type: 'json'};
12
+ import {getPkg, pkg} from './utils.mjs';
14
13
 
15
- /**
16
- * @param {string} string
17
- */
18
- function reverse(string) {
19
- return [...string].reverse().join('');
20
- }
14
+ async function writeEntry() {
15
+ return fs.writeFile(
16
+ 'dist/langserver.cjs',
17
+ `#!/usr/bin/env node
21
18
 
19
+ require('./v${pkg.version}-${pkg.delance.sha256}/server.bundle.js');`,
20
+ );
21
+ }
22
22
  const output = path.resolve(`dist/v${pkg.version}-${pkg.delance.sha256}`);
23
23
 
24
24
  await fs.mkdir(output, {recursive: true});
@@ -31,107 +31,17 @@ try {
31
31
  }
32
32
 
33
33
  if (processed) {
34
+ await writeEntry();
34
35
  process.exit();
35
36
  }
36
37
 
37
- /** @type {Blob?} */
38
- let vsix = null;
39
-
40
- if (process.env.DELANCE_VSIX) {
41
- try {
42
- vsix = new Blob([await fs.readFile(process.env.DELANCE_VSIX)]);
43
- const hash = Array.from(
44
- new Uint8Array(
45
- await subtle.digest('SHA-256', await vsix.arrayBuffer()),
46
- ),
47
- )
48
- .map((b) => b.toString(16).padStart(2, '0'))
49
- .join('');
50
-
51
- assert.equal(hash, pkg.delance.sha256, 'sha256 mismatch');
52
- } catch (e) {
53
- if (/** @type {Error & {syscall: string}} */ (e)?.syscall === 'open') {
54
- console.error(e);
55
- } else {
56
- throw e;
57
- }
58
- }
59
- }
60
-
61
- if (!vsix) {
62
- const baseURL = new URL(reverse('/moc.oidutslausiv.ecalptekram//:sptth'));
63
- const publisher = reverse('nohtyp-sm');
64
- const extension = reverse('ecnalyp-edocsv');
65
-
66
- const items = new URL(`/items?itemName=${publisher}.${extension}`, baseURL);
67
- const download = new URL(
68
- `/_apis/public/gallery/publishers/${publisher}/vsextensions/${extension}/${pkg.version}/vspackage`,
69
- baseURL,
70
- );
71
-
72
- /** @type {RequestInit} */
73
- const init = {
74
- headers: {
75
- 'user-agent': 'Mozilla/5.0 (Delance) Gecko/20100101 Firefox/120.0',
76
- },
77
- credentials: 'include',
78
- };
79
-
80
- const {headers} = await fetch(items, init);
81
- const cookie = headers
82
- .getSetCookie()
83
- .map((c) => c.split(';', 2)[0])
84
- .join('; ');
85
-
86
- vsix = await pRetry(async () => {
87
- const response = await fetch(download, {
88
- headers: {
89
- cookie,
90
- },
91
- redirect: 'follow',
92
- referrer: items.href,
93
- });
94
-
95
- if (response.status === 429) {
96
- const delay = response.headers.get('retry-after');
97
- if (delay) {
98
- throw new Error('Rate limited');
99
- }
100
- }
101
-
102
- if (!response.ok) {
103
- throw new AbortError(response.statusText);
104
- }
105
-
106
- const vsix = await response.blob();
107
-
108
- const hash = Array.from(
109
- new Uint8Array(
110
- await subtle.digest('SHA-256', await vsix.arrayBuffer()),
111
- ),
112
- )
113
- .map((b) => b.toString(16).padStart(2, '0'))
114
- .join('');
115
-
116
- try {
117
- assert.equal(hash, pkg.delance.sha256, 'sha256 mismatch');
118
- } catch (error) {
119
- if (error instanceof AssertionError) {
120
- throw new AbortError(error);
121
- }
122
- throw error;
123
- }
124
-
125
- return vsix;
126
- });
127
- }
128
-
129
- const zip = new ZipReader(new BlobReader(vsix));
38
+ /** @type {ZipReader<BlobReader>} */
39
+ const zip = new ZipReader(new BlobReader(await getPkg()));
130
40
 
131
41
  const prefix = path.normalize('extension/dist/');
132
42
 
133
- await pMap(
134
- await zip.getEntries(),
43
+ await map(
44
+ zip.getEntriesGenerator(),
135
45
  async (entry) => {
136
46
  const filename = path.normalize(entry.filename);
137
47
  if (!filename.startsWith(prefix)) {
@@ -176,9 +86,4 @@ await pMap(
176
86
  {concurrency: 4},
177
87
  );
178
88
 
179
- await fs.writeFile(
180
- 'dist/langserver.cjs',
181
- `#!/usr/bin/env node
182
-
183
- require('./v${pkg.version}-${pkg.delance.sha256}/server.bundle.js');`,
184
- );
89
+ await writeEntry();
package/package.json CHANGED
@@ -1,29 +1,36 @@
1
1
  {
2
2
  "name": "@delance/runtime",
3
- "version": "2024.12.1",
3
+ "version": "2024.12.100-patch1",
4
4
  "description": "Runtime and entrypoint for the lance",
5
5
  "license": "0BSD",
6
6
  "bin": {
7
7
  "delance-langserver": "dist/langserver.cjs"
8
8
  },
9
9
  "delance": {
10
- "sha256": "2e91db5ed8551efad5675c6a0530df175463ce01229505551dfcb4b65ba6fc15"
10
+ "sha256": "a040b24fa18f6de20de211e78d8a6467a3f88fb34493439e74909b437292ec98"
11
11
  },
12
- "files": ["langserver.cjs", "install.mjs"],
12
+ "files": [
13
+ "langserver.cjs",
14
+ "install.mjs",
15
+ "utils.mjs"
16
+ ],
13
17
  "scripts": {
14
18
  "postinstall": "node install.mjs",
19
+ "prepublishOnly": "node install.mjs",
15
20
  "lint": "biome lint ."
16
21
  },
17
22
  "dependencies": {
18
- "@delance/builder": "^0.2.16",
19
- "@zip.js/zip.js": "^2.7.53",
20
- "p-map": "^7.0.2",
21
- "p-retry": "^6.2.0"
23
+ "@delance/builder": "^0.3.1",
24
+ "@zip.js/zip.js": "^2.7.54",
25
+ "p-map": "^7.0.3",
26
+ "p-retry": "^6.2.1"
22
27
  },
23
28
  "devDependencies": {
24
29
  "@biomejs/biome": "^1.9.4",
25
- "@types/node": "^20.17.6",
26
- "typescript": "^5.6.3"
30
+ "@types/node": "^22.10.5",
31
+ "typescript": "^5.7.3"
27
32
  },
28
- "trustedDependencies": ["@biomejs/biome"]
33
+ "trustedDependencies": [
34
+ "@biomejs/biome"
35
+ ]
29
36
  }
package/utils.mjs ADDED
@@ -0,0 +1,122 @@
1
+ // @ts-check
2
+ import assert, {AssertionError} from 'node:assert';
3
+ import {subtle} from 'node:crypto';
4
+ import fs from 'node:fs/promises';
5
+ import process from 'node:process';
6
+ import retry, {AbortError} from 'p-retry';
7
+
8
+ import pkg from './package.json' with {type: 'json'};
9
+
10
+ /**
11
+ * @param {string} string
12
+ */
13
+ const reverse = (string) => [...string].reverse().join('');
14
+
15
+ const BASE_URL = new URL(reverse('/moc.oidutslausiv.ecalptekram//:sptth'));
16
+ const PUBLISHER = reverse('nohtyp-sm');
17
+ const EXTENSION = reverse('ecnalyp-edocsv');
18
+
19
+ const ITEMS = new URL(`/items?itemName=${PUBLISHER}.${EXTENSION}`, BASE_URL);
20
+
21
+ /** @type {RequestInit} */
22
+ const INIT = {
23
+ headers: {
24
+ 'user-agent': 'Mozilla/5.0 (Delance) Gecko/20100101 Firefox/120.0',
25
+ },
26
+ credentials: 'include',
27
+ };
28
+
29
+ /**
30
+ * @param {Blob} blob
31
+ */
32
+ export const sha256 = async (blob) =>
33
+ Array.from(
34
+ new Uint8Array(
35
+ await subtle.digest('SHA-256', await blob.arrayBuffer()),
36
+ ),
37
+ )
38
+ .map((b) => b.toString(16).padStart(2, '0'))
39
+ .join('');
40
+
41
+ const pkgVersion = pkg.version.split('-')[0];
42
+
43
+ export async function getPkg({check = true, version = pkgVersion} = {}) {
44
+ const PACKAGE = new URL(
45
+ `/_apis/public/gallery/publishers/${PUBLISHER}/vsextensions/${EXTENSION}/${version}/vspackage`,
46
+ BASE_URL,
47
+ );
48
+
49
+ /** @type {Blob?} */
50
+ let vsix = null;
51
+
52
+ if (process.env.DELANCE_VSIX) {
53
+ try {
54
+ vsix = new Blob([await fs.readFile(process.env.DELANCE_VSIX)]);
55
+ if (check)
56
+ assert.equal(
57
+ await sha256(vsix),
58
+ pkg.delance.sha256,
59
+ 'sha256 mismatch',
60
+ );
61
+ } catch (e) {
62
+ if (
63
+ /** @type {Error & {syscall: string}} */ (e)?.syscall === 'open'
64
+ ) {
65
+ console.error(e);
66
+ } else {
67
+ throw e;
68
+ }
69
+ }
70
+ }
71
+
72
+ if (!vsix) {
73
+ const {headers} = await fetch(ITEMS, INIT);
74
+ const cookie = headers
75
+ .getSetCookie()
76
+ .map((c) => c.split(';', 2)[0])
77
+ .join('; ');
78
+
79
+ vsix = await retry(async () => {
80
+ const response = await fetch(PACKAGE, {
81
+ headers: {
82
+ cookie,
83
+ },
84
+ redirect: 'follow',
85
+ referrer: ITEMS.href,
86
+ });
87
+
88
+ if (response.status === 429) {
89
+ const delay = response.headers.get('retry-after');
90
+ if (delay) {
91
+ throw new Error('Rate limited');
92
+ }
93
+ }
94
+
95
+ if (!response.ok) {
96
+ throw new AbortError(response.statusText);
97
+ }
98
+
99
+ const blob = await response.blob();
100
+
101
+ if (check)
102
+ try {
103
+ assert.equal(
104
+ await sha256(blob),
105
+ pkg.delance.sha256,
106
+ 'sha256 mismatch',
107
+ );
108
+ } catch (error) {
109
+ if (error instanceof AssertionError) {
110
+ throw new AbortError(error);
111
+ }
112
+ throw error;
113
+ }
114
+
115
+ return blob;
116
+ });
117
+ }
118
+
119
+ return vsix;
120
+ }
121
+
122
+ export {pkg};