@astrojs/compiler 0.0.0-sync-20230409173822 → 0.0.0-sync-20230418114635
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/CHANGELOG.md +1 -1
- package/astro.wasm +0 -0
- package/node/{sync.js → sync.cjs} +10 -15
- package/node/sync.cts +62 -0
- package/node/{sync.d.ts → sync.d.cts} +8 -1
- package/package.json +3 -3
- package/sync.d.ts +1 -1
package/CHANGELOG.md
CHANGED
package/astro.wasm
CHANGED
|
Binary file
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
2
|
import Go from './wasm_exec';
|
|
3
|
+
import { join } from 'node:path';
|
|
3
4
|
function getService() {
|
|
4
5
|
if (!longLivedService) {
|
|
5
|
-
|
|
6
|
+
longLivedService = startRunningService();
|
|
6
7
|
}
|
|
7
8
|
return longLivedService;
|
|
8
9
|
}
|
|
@@ -14,12 +15,12 @@ export const parse = ((input, options) => {
|
|
|
14
15
|
export const convertToTSX = ((input, options) => {
|
|
15
16
|
return getService().convertToTSX(input, options);
|
|
16
17
|
});
|
|
17
|
-
export
|
|
18
|
+
export function startRunningService() {
|
|
18
19
|
const go = new Go();
|
|
19
|
-
const wasm =
|
|
20
|
-
go.run(wasm
|
|
20
|
+
const wasm = instantiateWASM(join(__dirname, '../astro.wasm'), go.importObject);
|
|
21
|
+
go.run(wasm);
|
|
21
22
|
const _service = globalThis['@astrojs/compiler'];
|
|
22
|
-
|
|
23
|
+
return {
|
|
23
24
|
transform: (input, options) => {
|
|
24
25
|
try {
|
|
25
26
|
return _service.transform(input, options || {});
|
|
@@ -39,14 +40,8 @@ export async function startRunningService(wasmPath) {
|
|
|
39
40
|
return { ...result, map: JSON.parse(result.map) };
|
|
40
41
|
},
|
|
41
42
|
};
|
|
42
|
-
return 'hey';
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const wasmArrayBuffer = await fs.readFile(wasmURL).then((res) => res.buffer);
|
|
48
|
-
return WebAssembly.instantiate(new Uint8Array(wasmArrayBuffer), importObject);
|
|
49
|
-
};
|
|
50
|
-
response = await fetchAndInstantiateTask();
|
|
51
|
-
return response;
|
|
44
|
+
function instantiateWASM(wasmURL, importObject) {
|
|
45
|
+
const wasmArrayBuffer = readFileSync(wasmURL);
|
|
46
|
+
return new WebAssembly.Instance(new WebAssembly.Module(wasmArrayBuffer), importObject);
|
|
52
47
|
}
|
package/node/sync.cts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import type * as types from '../shared/types';
|
|
3
|
+
import Go from './wasm_exec';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
type UnwrappedPromise<T> = T extends (...params: any) => Promise<infer Return> ? (...params: Parameters<T>) => Return : T;
|
|
7
|
+
|
|
8
|
+
interface Service {
|
|
9
|
+
transform: UnwrappedPromise<typeof types.transform>;
|
|
10
|
+
parse: UnwrappedPromise<typeof types.parse>;
|
|
11
|
+
convertToTSX: UnwrappedPromise<typeof types.convertToTSX>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getService(): Service {
|
|
15
|
+
if (!longLivedService) {
|
|
16
|
+
longLivedService = startRunningService();
|
|
17
|
+
}
|
|
18
|
+
return longLivedService;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let longLivedService: Service | undefined;
|
|
22
|
+
|
|
23
|
+
export const transform = ((input, options) => getService().transform(input, options)) satisfies Service['transform'];
|
|
24
|
+
|
|
25
|
+
export const parse = ((input, options) => {
|
|
26
|
+
return getService().parse(input, options);
|
|
27
|
+
}) satisfies Service['parse'];
|
|
28
|
+
|
|
29
|
+
export const convertToTSX = ((input, options) => {
|
|
30
|
+
return getService().convertToTSX(input, options);
|
|
31
|
+
}) satisfies Service['convertToTSX'];
|
|
32
|
+
|
|
33
|
+
export function startRunningService(): Service {
|
|
34
|
+
const go = new Go();
|
|
35
|
+
const wasm = instantiateWASM(join(__dirname, '../astro.wasm'), go.importObject);
|
|
36
|
+
go.run(wasm);
|
|
37
|
+
const _service: any = (globalThis as any)['@astrojs/compiler'];
|
|
38
|
+
return {
|
|
39
|
+
transform: (input, options) => {
|
|
40
|
+
try {
|
|
41
|
+
return _service.transform(input, options || {});
|
|
42
|
+
} catch (err) {
|
|
43
|
+
// Recreate the service next time on panic
|
|
44
|
+
longLivedService = void 0;
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
parse: (input, options) => {
|
|
49
|
+
const result = _service.parse(input, options || {});
|
|
50
|
+
return { ...result, ast: JSON.parse(result.ast) };
|
|
51
|
+
},
|
|
52
|
+
convertToTSX: (input, options) => {
|
|
53
|
+
const result = _service.convertToTSX(input, options || {});
|
|
54
|
+
return { ...result, map: JSON.parse(result.map) };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function instantiateWASM(wasmURL: string, importObject: Record<string, any>): WebAssembly.Instance {
|
|
60
|
+
const wasmArrayBuffer = readFileSync(wasmURL);
|
|
61
|
+
return new WebAssembly.Instance(new WebAssembly.Module(wasmArrayBuffer), importObject);
|
|
62
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type * as types from '../shared/types';
|
|
2
|
+
type UnwrappedPromise<T> = T extends (...params: any) => Promise<infer Return> ? (...params: Parameters<T>) => Return : T;
|
|
3
|
+
interface Service {
|
|
4
|
+
transform: UnwrappedPromise<typeof types.transform>;
|
|
5
|
+
parse: UnwrappedPromise<typeof types.parse>;
|
|
6
|
+
convertToTSX: UnwrappedPromise<typeof types.convertToTSX>;
|
|
7
|
+
}
|
|
2
8
|
export declare const transform: (input: string, options: types.TransformOptions | undefined) => types.TransformResult;
|
|
3
9
|
export declare const parse: (input: string, options: types.ParseOptions | undefined) => types.ParseResult;
|
|
4
10
|
export declare const convertToTSX: (input: string, options: types.ConvertToTSXOptions | undefined) => types.TSXResult;
|
|
5
|
-
export declare function startRunningService(
|
|
11
|
+
export declare function startRunningService(): Service;
|
|
12
|
+
export {};
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bugs": "https://github.com/withastro/compiler/issues",
|
|
7
7
|
"homepage": "https://astro.build",
|
|
8
|
-
"version": "0.0.0-sync-
|
|
8
|
+
"version": "0.0.0-sync-20230418114635",
|
|
9
9
|
"main": "./node/index.js",
|
|
10
10
|
"types": "./node",
|
|
11
11
|
"repository": {
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"default": "./browser/index.js"
|
|
20
20
|
},
|
|
21
21
|
"./sync": {
|
|
22
|
-
"import": "./node/sync.
|
|
23
|
-
"default": "./node/sync.
|
|
22
|
+
"import": "./node/sync.cjs",
|
|
23
|
+
"default": "./node/sync.cjs"
|
|
24
24
|
},
|
|
25
25
|
"./utils": {
|
|
26
26
|
"browser": "./browser/utils.js",
|
package/sync.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './node/sync';
|
|
1
|
+
export * from './node/sync.cjs';
|