amaro 0.2.2 → 0.3.1

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/dist/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "강동윤 <kdy1997.dev@gmail.com>"
5
5
  ],
6
6
  "description": "wasm module for swc",
7
- "version": "1.10.4",
7
+ "version": "1.10.11",
8
8
  "license": "Apache-2.0",
9
9
  "repository": {
10
10
  "type": "git",
@@ -1,24 +1,32 @@
1
1
  "use strict";
2
+ import { isSwcError, wrapAndReThrowSwcError } from "./errors.js";
2
3
  import { transformSync } from "./index.js";
3
4
  export async function load(url, context, nextLoad) {
4
5
  const { format } = context;
5
- if (format.endsWith("-typescript")) {
6
- const { source } = await nextLoad(url, {
7
- ...context,
8
- format: "module"
9
- });
10
- const { code } = transformSync(source.toString(), {
11
- mode: "strip-only"
12
- });
13
- return {
14
- format: format.replace("-typescript", ""),
15
- // Source map is not necessary in strip-only mode. However, to map the source
16
- // file in debuggers to the original TypeScript source, add a sourceURL magic
17
- // comment to hint that it is a generated source.
18
- source: `${code}
6
+ if (format?.endsWith("-typescript")) {
7
+ try {
8
+ const { source } = await nextLoad(url, {
9
+ ...context,
10
+ format: "module"
11
+ });
12
+ const { code } = transformSync(source.toString(), {
13
+ mode: "strip-only"
14
+ });
15
+ return {
16
+ format: format.replace("-typescript", ""),
17
+ // Source map is not necessary in strip-only mode. However, to map the source
18
+ // file in debuggers to the original TypeScript source, add a sourceURL magic
19
+ // comment to hint that it is a generated source.
20
+ source: `${code}
19
21
 
20
22
  //# sourceURL=${url}`
21
- };
23
+ };
24
+ } catch (error) {
25
+ if (isSwcError(error)) {
26
+ wrapAndReThrowSwcError(error);
27
+ }
28
+ throw error;
29
+ }
22
30
  }
23
31
  return nextLoad(url, context);
24
32
  }
@@ -1,30 +1,38 @@
1
1
  "use strict";
2
+ import { isSwcError, wrapAndReThrowSwcError } from "./errors.js";
2
3
  import { transformSync } from "./index.js";
3
4
  export async function load(url, context, nextLoad) {
4
5
  const { format } = context;
5
- if (format.endsWith("-typescript")) {
6
- const { source } = await nextLoad(url, {
7
- ...context,
8
- format: "module"
9
- });
10
- const { code, map } = transformSync(source.toString(), {
11
- mode: "transform",
12
- sourceMap: true,
13
- filename: url
14
- });
15
- let output = code;
16
- if (map) {
17
- const base64SourceMap = Buffer.from(map).toString("base64");
18
- output = `${code}
6
+ if (format?.endsWith("-typescript")) {
7
+ try {
8
+ const { source } = await nextLoad(url, {
9
+ ...context,
10
+ format: "module"
11
+ });
12
+ const { code, map } = transformSync(source.toString(), {
13
+ mode: "transform",
14
+ sourceMap: true,
15
+ filename: url
16
+ });
17
+ let output = code;
18
+ if (map) {
19
+ const base64SourceMap = Buffer.from(map).toString("base64");
20
+ output = `${code}
19
21
 
20
22
  //# sourceMappingURL=data:application/json;base64,${base64SourceMap}`;
21
- }
22
- return {
23
- format: format.replace("-typescript", ""),
24
- source: `${output}
23
+ }
24
+ return {
25
+ format: format.replace("-typescript", ""),
26
+ source: `${output}
25
27
 
26
28
  //# sourceURL=${url}`
27
- };
29
+ };
30
+ } catch (error) {
31
+ if (isSwcError(error)) {
32
+ wrapAndReThrowSwcError(error);
33
+ }
34
+ throw error;
35
+ }
28
36
  }
29
37
  return nextLoad(url, context);
30
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amaro",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Node.js TypeScript wrapper",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",