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/errors.js +17 -0
- package/dist/index.js +241 -249
- package/dist/package.json +1 -1
- package/dist/strip-loader.js +23 -15
- package/dist/transform-loader.js +27 -19
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/strip-loader.js
CHANGED
|
@@ -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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
}
|
package/dist/transform-loader.js
CHANGED
|
@@ -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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
}
|