mirror of
https://github.com/swc-project/swc.git
synced 2024-12-27 07:34:20 +03:00
feat(es/typescript): Add esm build for fast ts strip (#9286)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/9283
This commit is contained in:
parent
76fe139334
commit
d10cb9ffa2
26
.github/workflows/publish-npm-package.yml
vendored
26
.github/workflows/publish-npm-package.yml
vendored
@ -588,12 +588,18 @@ jobs:
|
||||
- crate: "binding_core_wasm"
|
||||
npm: "@swc\\/wasm"
|
||||
target: nodejs
|
||||
out: "pkg"
|
||||
- crate: "binding_core_wasm"
|
||||
npm: "@swc\\/wasm-web"
|
||||
target: web
|
||||
out: "pkg"
|
||||
- crate: "binding_typescript_wasm"
|
||||
npm: "@swc\\/wasm-typescript"
|
||||
target: nodejs
|
||||
build: "./scripts/build.sh"
|
||||
out: "pkg"
|
||||
- crate: "binding_typescript_wasm"
|
||||
build: "./scripts/esm.sh"
|
||||
out: "esm"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
@ -631,21 +637,23 @@ jobs:
|
||||
|
||||
- name: Build
|
||||
working-directory: bindings/${{ matrix.settings.crate }}
|
||||
if: ${{ !matrix.settings.build }}
|
||||
run: |
|
||||
# If ./scripts/build.sh exists, apply it
|
||||
if [ -f ./scripts/build.sh ]; then
|
||||
./scripts/build.sh
|
||||
else
|
||||
wasm-pack build --out-name wasm --release --scope=swc --target ${{ matrix.settings.target }}
|
||||
fi
|
||||
wasm-pack build --out-name wasm --release --scope=swc --target ${{ matrix.settings.target }}
|
||||
sed -i -e 's/"name": "@swc\/${{ matrix.settings.crate }}"/"name": "${{ matrix.settings.npm }}"/g' pkg/package.json
|
||||
|
||||
- name: Build
|
||||
working-directory: bindings/${{ matrix.settings.crate }}
|
||||
if: ${{ matrix.settings.build }}
|
||||
run: |
|
||||
${{ matrix.settings.build }}
|
||||
|
||||
- name: Publish
|
||||
if: ${{ !inputs.skipBuild }}
|
||||
run: |
|
||||
npm config set provenance true
|
||||
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
|
||||
(cd bindings/${{ matrix.settings.crate }}/pkg && npm publish --access public --tag $NPM_TAG)
|
||||
(cd bindings/${{ matrix.settings.crate }}/${{ matrix.settings.out }} && npm publish --access public --tag $NPM_TAG)
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
15
bindings/binding_typescript_wasm/scripts/esm.mjs
Executable file
15
bindings/binding_typescript_wasm/scripts/esm.mjs
Executable file
@ -0,0 +1,15 @@
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
const pkgJsonFile = await fs.readFile("esm/package.json", "utf8");
|
||||
const pkgJson = JSON.parse(pkgJsonFile);
|
||||
pkgJson.name = '@swc/wasm-typescript-esm';
|
||||
pkgJson.exports = {
|
||||
types: "./wasm.d.ts",
|
||||
node: "./wasm-node.js",
|
||||
default: "./wasm.js",
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
fs.cp("src/wasm-node.js", "esm/wasm-node.js"),
|
||||
fs.writeFile("esm/package.json", JSON.stringify(pkgJson, null, 2)),
|
||||
]);
|
2
bindings/binding_typescript_wasm/scripts/esm.sh
Executable file
2
bindings/binding_typescript_wasm/scripts/esm.sh
Executable file
@ -0,0 +1,2 @@
|
||||
wasm-pack build --out-name wasm --out-dir esm --release --scope=swc --target web
|
||||
node ./scripts/esm.mjs
|
@ -37,5 +37,6 @@ await fs.unlink('pkg/wasm_bg.wasm');
|
||||
// Remove wasm from .files section of package.json
|
||||
const pkgJsonFile = await fs.readFile('pkg/package.json', 'utf8');
|
||||
const pkgJson = JSON.parse(pkgJsonFile);
|
||||
pkgJson.name = '@swc/wasm-typescript';
|
||||
pkgJson.files = pkgJson.files.filter(file => file !== 'wasm_bg.wasm');
|
||||
await fs.writeFile('pkg/package.json', JSON.stringify(pkgJson, null, 2));
|
10
bindings/binding_typescript_wasm/src/wasm-node.js
Normal file
10
bindings/binding_typescript_wasm/src/wasm-node.js
Normal file
@ -0,0 +1,10 @@
|
||||
import fs from "node:fs/promises";
|
||||
import initAsync from "./wasm.js";
|
||||
|
||||
const wasm = new URL("./wasm_bg.wasm", import.meta.url);
|
||||
|
||||
export default function (init = fs.readFile(wasm)) {
|
||||
return initAsync(init);
|
||||
}
|
||||
|
||||
export * from "./wasm.js";
|
Loading…
Reference in New Issue
Block a user