Skip to content

Commit

Permalink
refactor: split node exports
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Jan 18, 2024
1 parent de357e1 commit 973f96f
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 67 deletions.
1 change: 0 additions & 1 deletion crates/ruff_fmt/extra/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.bak
*.tgz
10 changes: 10 additions & 0 deletions crates/ruff_fmt/extra/ruff_fmt_node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fs from "node:fs/promises";
import initAsync from "./ruff_fmt.js";

const wasm = new URL("./ruff_fmt_bg.wasm", import.meta.url);

export default function __wbg_init(init = fs.readFile(wasm)) {
return initAsync(init);
}

export * from "./ruff_fmt.js";
8 changes: 8 additions & 0 deletions crates/ruff_fmt/extra/ruff_fmt_vite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import initAsync from "./ruff_fmt.js";
import wasm from "./ruff_fmt_bg.wasm?url";

export default function __wbg_init(input = wasm) {
return initAsync(input);
}

export * from "./ruff_fmt.js";
8 changes: 0 additions & 8 deletions crates/ruff_fmt/extra/vite.js

This file was deleted.

24 changes: 0 additions & 24 deletions crates/ruff_fmt/patch/ruff_fmt.patch

This file was deleted.

2 changes: 0 additions & 2 deletions crates/ruff_fmt/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ cd $crates_dir
# backup ruff_fmt.js
cp ./pkg/ruff_fmt.js ./pkg/ruff_fmt.js.bak

git apply ./patch/ruff_fmt.patch

cp -R ./extra/. ./pkg/

./scripts/package.mjs ./pkg/package.json
29 changes: 0 additions & 29 deletions crates/ruff_fmt/scripts/gen_patch.sh

This file was deleted.

3 changes: 2 additions & 1 deletion crates/ruff_fmt/scripts/package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ pkg_json.publishConfig = {
pkg_json.exports = {
".": {
types: "./ruff_fmt.d.ts",
node: "./ruff_fmt_node.js",
default: "./ruff_fmt.js",
},
"./vite": {
types: "./ruff_fmt.d.ts",
default: "./vite.js",
default: "./ruff_fmt_vite.js",
},
"./package.json": "./package.json",
"./*": "./*",
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/test_bun/bun.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from "bun:test";
import fs from "node:fs/promises";
import path from "node:path";
import init, { format } from "../pkg/ruff_fmt.js";
import init, { format } from "../pkg";

await init();

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_fmt/test_node/test-node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "node:fs/promises";
import path from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
import init, { format } from "../pkg/ruff_fmt.js";
import init, { format } from "../pkg/ruff_fmt_node.js";

await init();

Expand Down

0 comments on commit 973f96f

Please sign in to comment.