@astrojs/compiler 0.11.1 → 0.11.4
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 +20 -0
- package/astro.wasm +0 -0
- package/browser/index.js +15 -14
- package/node/index.js +14 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @astrojs/compiler
|
|
2
2
|
|
|
3
|
+
## 0.11.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 99b5de2: Reset tokenizer state when a raw element that is self-closing is encountered.
|
|
8
|
+
|
|
9
|
+
This fixes the handling of self-closing elements like `<title />` and `<script />` when used with `set:html`.
|
|
10
|
+
|
|
11
|
+
## 0.11.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- dcf15bf: Fixes bug causing a crash when using Astro.resolve on a hoisted script
|
|
16
|
+
|
|
17
|
+
## 0.11.2
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 41cc6ef: Fix memory issue caused by duplicate WASM instantiations
|
|
22
|
+
|
|
3
23
|
## 0.11.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/astro.wasm
CHANGED
|
Binary file
|
package/browser/index.js
CHANGED
|
@@ -4,26 +4,27 @@ export const transform = (input, options) => {
|
|
|
4
4
|
};
|
|
5
5
|
let initializePromise;
|
|
6
6
|
let longLivedService;
|
|
7
|
-
export const initialize = (options) => {
|
|
7
|
+
export const initialize = async (options) => {
|
|
8
8
|
let wasmURL = options.wasmURL;
|
|
9
9
|
if (!wasmURL)
|
|
10
10
|
throw new Error('Must provide the "wasmURL" option');
|
|
11
11
|
wasmURL += '';
|
|
12
|
-
if (initializePromise)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
if (!initializePromise) {
|
|
13
|
+
initializePromise = startRunningService(wasmURL).catch((err) => {
|
|
14
|
+
// Let the caller try again if this fails.
|
|
15
|
+
initializePromise = void 0;
|
|
16
|
+
// But still, throw the error back up the caller.
|
|
17
|
+
throw err;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
longLivedService = longLivedService || (await initializePromise);
|
|
20
21
|
};
|
|
21
22
|
let ensureServiceIsRunning = () => {
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
if (
|
|
23
|
+
if (!initializePromise)
|
|
24
|
+
throw new Error('You need to call "initialize" before calling this');
|
|
25
|
+
if (!longLivedService)
|
|
25
26
|
throw new Error('You need to wait for the promise returned from "initialize" to be resolved before calling this');
|
|
26
|
-
|
|
27
|
+
return longLivedService;
|
|
27
28
|
};
|
|
28
29
|
const instantiateWASM = async (wasmURL, importObject) => {
|
|
29
30
|
let response = undefined;
|
|
@@ -44,7 +45,7 @@ const startRunningService = async (wasmURL) => {
|
|
|
44
45
|
const wasm = await instantiateWASM(wasmURL, go.importObject);
|
|
45
46
|
go.run(wasm.instance);
|
|
46
47
|
const service = globalThis['@astrojs/compiler'];
|
|
47
|
-
|
|
48
|
+
return {
|
|
48
49
|
transform: (input, options) => new Promise((resolve) => resolve(service.transform(input, options || {}))),
|
|
49
50
|
};
|
|
50
51
|
};
|
package/node/index.js
CHANGED
|
@@ -2,17 +2,23 @@ import { promises as fs } from 'fs';
|
|
|
2
2
|
import Go from './wasm_exec.js';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
export const transform = async (input, options) => {
|
|
5
|
-
return
|
|
5
|
+
return getService().then((service) => service.transform(input, options));
|
|
6
6
|
};
|
|
7
7
|
export const compile = async (template) => {
|
|
8
8
|
const { default: mod } = await import(`data:text/javascript;charset=utf-8;base64,${Buffer.from(template).toString('base64')}`);
|
|
9
9
|
return mod;
|
|
10
10
|
};
|
|
11
11
|
let longLivedService;
|
|
12
|
-
let
|
|
13
|
-
if (longLivedService)
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
let getService = () => {
|
|
13
|
+
if (!longLivedService) {
|
|
14
|
+
longLivedService = startRunningService().catch((err) => {
|
|
15
|
+
// Let the caller try again if this fails.
|
|
16
|
+
longLivedService = void 0;
|
|
17
|
+
// But still, throw the error back up the caller.
|
|
18
|
+
throw err;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return longLivedService;
|
|
16
22
|
};
|
|
17
23
|
const instantiateWASM = async (wasmURL, importObject) => {
|
|
18
24
|
let response = undefined;
|
|
@@ -27,9 +33,8 @@ const startRunningService = async () => {
|
|
|
27
33
|
const go = new Go();
|
|
28
34
|
const wasm = await instantiateWASM(fileURLToPath(new URL('../astro.wasm', import.meta.url)), go.importObject);
|
|
29
35
|
go.run(wasm.instance);
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
transform: (input, options) => new Promise((resolve) => resolve(
|
|
36
|
+
const _service = globalThis['@astrojs/compiler'];
|
|
37
|
+
return {
|
|
38
|
+
transform: (input, options) => new Promise((resolve) => resolve(_service.transform(input, options || {}))),
|
|
33
39
|
};
|
|
34
|
-
return longLivedService;
|
|
35
40
|
};
|