Skip to content

Commit 755b173

Browse files
committed
feat: add @swc/wasm fallback for platforms w/o node addons
1 parent ad2be47 commit 755b173

File tree

12 files changed

+100
-78
lines changed

12 files changed

+100
-78
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
},
4343
"dependencies": {
4444
"@rollup/plugin-virtual": "^3.0.2",
45-
"@swc/core": "^1.10.16",
45+
"@swc/core": "^1.12.14",
46+
"@swc/wasm": "^1.12.14",
4647
"uuid": "^10.0.0"
4748
},
4849
"peerDependencies": {

src/bundle-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as SWC from "@swc/core";
1+
import * as SWC from "./swc";
22
import { CodePattern, findHighestPattern } from "./find";
33

44
import { resolveImport } from "./utils/resolve-import";

src/find.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="jest-extended" />
22

3-
import * as SWC from "@swc/core";
3+
import * as SWC from "./swc";
44

55
import { CodePattern, findHighestPattern } from "./find";
66

src/find.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as SWC from "@swc/core";
1+
import * as SWC from "./swc";
22
import { Visitor } from "@swc/core/Visitor";
33

44
// Throw an exception when found top-level await to exit earlier from AST traversal

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from "path";
22
import { Plugin, ResolvedConfig } from "vite";
33
import { rollup, OutputChunk } from "rollup";
44
import virtual from "@rollup/plugin-virtual";
5-
import * as SWC from "@swc/core";
5+
import * as SWC from "./swc";
66
import esbuild from "./esbuild";
77

88
import { DEFAULT_OPTIONS, Options } from "./options";

src/swc.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "@swc/core";

src/swc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* istanbul ignore file */
2+
let SWC;
3+
try {
4+
if (process.env.VITE_TLA_FORCE_WASM === "true") {
5+
throw new Error("Force using @swc/wasm");
6+
}
7+
SWC = require("@swc/core");
8+
} catch (e) {
9+
if (process.env.VITE_TLA_FORCE_NATIVE === "true") {
10+
throw e;
11+
}
12+
SWC = require("@swc/wasm");
13+
}
14+
15+
module.exports = SWC;

src/transform.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="jest-extended" />
22

3-
import * as SWC from "@swc/core";
3+
import * as SWC from "./swc";
44

55
import { BundleInfo } from "./bundle-info";
66
import { DEFAULT_OPTIONS } from "./options";

src/transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as SWC from "@swc/core";
1+
import * as SWC from "./swc";
22

33
import { BundleInfo } from "./bundle-info";
44
import { Options } from "./options";

src/utils/make-node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as SWC from "@swc/core";
1+
import * as SWC from "../swc";
22

33
function span(): SWC.Span {
44
return { start: 0, end: 0, ctxt: 0 };

0 commit comments

Comments
 (0)