Skip to content

Commit 17c7289

Browse files
Make it work
1 parent 7a6941c commit 17c7289

File tree

15 files changed

+158
-34
lines changed

15 files changed

+158
-34
lines changed

Diff for: .github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ jobs:
5050
node-version: ${{ matrix.node-version }}
5151
cache: 'pnpm'
5252

53+
- name: Setup WASM target
54+
run: rustup target add wasm32-wasip1-threads
55+
5356
# Cargo already skips downloading dependencies if they already exist
5457
- name: Cache cargo
5558
uses: actions/cache@v4

Diff for: .github/workflows/integration-tests.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- vite
3131
- cli
3232
- postcss
33-
- workers
33+
- oxide
3434
- webpack
3535

3636
# Exclude windows and macos from being built on feature branches
@@ -59,6 +59,9 @@ jobs:
5959
node-version: ${{ matrix.node-version }}
6060
cache: 'pnpm'
6161

62+
- name: Setup WASM target
63+
run: rustup target add wasm32-wasip1-threads
64+
6265
# Cargo already skips downloading dependencies if they already exist
6366
- name: Cache cargo
6467
uses: actions/cache@v4

Diff for: Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: crates/node/.gitignore

+5-7
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,9 @@ Cargo.lock
199199
# Generated
200200
index.d.ts
201201
index.js
202-
203-
# wasm stuff
204202
*.wasm
205-
/browser.js
206-
/tailwindcss-oxide.wasi-browser.js
207-
/tailwindcss-oxide.wasi.cjs
208-
/wasi-worker-browser.mjs
209-
/wasi-worker.mjs
203+
browser.js
204+
tailwindcss-oxide.wasi-browser.js
205+
tailwindcss-oxide.wasi.cjs
206+
wasi-worker-browser.mjs
207+
wasi-worker.mjs

Diff for: crates/node/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ crate-type = ["cdylib"]
88

99
[dependencies]
1010
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
11-
napi = { version = "2.16.16", default-features = false, features = ["napi4"] }
11+
napi = { version = "2.16.17", default-features = false, features = ["napi4"] }
1212
napi-derive = "2.16.13"
1313
tailwindcss-oxide = { path = "../oxide" }
1414
rayon = "1.10.0"
1515

1616
[build-dependencies]
17-
napi-build = "2.1.4"
17+
napi-build = "2.1.6"

Diff for: crates/node/npm/wasm32-wasi/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Diff for: crates/node/npm/wasm32-wasi/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node-linker=hoisted

Diff for: crates/node/npm/wasm32-wasi/package.json

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tailwindcss/oxide-wasm32-wasi",
3-
"version": "4.1.2",
3+
"version": "4.1.3",
44
"cpu": [
55
"wasm32"
66
],
@@ -27,6 +27,19 @@
2727
},
2828
"browser": "tailwindcss-oxide.wasi-browser.js",
2929
"dependencies": {
30-
"@napi-rs/wasm-runtime": "^0.2.8"
31-
}
30+
"@napi-rs/wasm-runtime": "^0.2.8",
31+
"@emnapi/core": "^1.4.0",
32+
"@emnapi/runtime": "^1.4.0",
33+
"@tybys/wasm-util": "^0.9.0",
34+
"@emnapi/wasi-threads": "^1.0.1",
35+
"tslib": "^2.8.0"
36+
},
37+
"bundledDependencies": [
38+
"@napi-rs/wasm-runtime",
39+
"@emnapi/core",
40+
"@emnapi/runtime",
41+
"@tybys/wasm-util",
42+
"@emnapi/wasi-threads",
43+
"tslib"
44+
]
3245
}

Diff for: crates/node/package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"main": "index.js",
1010
"types": "index.d.ts",
1111
"napi": {
12-
"name": "tailwindcss-oxide",
1312
"binaryName": "tailwindcss-oxide",
1413
"packageName": "@tailwindcss/oxide",
1514
"targets": [
@@ -35,6 +34,7 @@
3534
"license": "MIT",
3635
"devDependencies": {
3736
"@napi-rs/cli": "^3.0.0-alpha.77",
37+
"@napi-rs/wasm-runtime": "^0.2.8",
3838
"emnapi": "1.3.1"
3939
},
4040
"engines": {
@@ -50,7 +50,9 @@
5050
},
5151
"scripts": {
5252
"artifacts": "napi artifacts",
53-
"build": "napi build --platform --release --no-const-enum",
53+
"build": "pnpm run build:platform && pnpm run build:wasm",
54+
"postbuild": "node ./scripts/move-artifacts.mjs",
55+
"build:platform": "napi build --platform --release --no-const-enum",
5456
"build:wasm": "napi build --release --target wasm32-wasip1-threads",
5557
"dev": "cargo watch --quiet --shell 'npm run build'",
5658
"build:debug": "napi build --platform --no-const-enum",
@@ -66,8 +68,8 @@
6668
"@tailwindcss/oxide-linux-arm64-musl": "workspace:*",
6769
"@tailwindcss/oxide-linux-x64-gnu": "workspace:*",
6870
"@tailwindcss/oxide-linux-x64-musl": "workspace:*",
71+
"@tailwindcss/oxide-wasm32-wasi": "workspace:*",
6972
"@tailwindcss/oxide-win32-arm64-msvc": "workspace:*",
70-
"@tailwindcss/oxide-win32-x64-msvc": "workspace:*",
71-
"@tailwindcss/oxide-wasm32-wasi": "workspace:*"
73+
"@tailwindcss/oxide-win32-x64-msvc": "workspace:*"
7274
}
7375
}

Diff for: crates/node/scripts/move-artifacts.mjs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import url from 'node:url'
4+
5+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
6+
let root = path.resolve(__dirname, '..')
7+
const tailwindcssOxideRoot = path.join(root)
8+
9+
// Move napi artifacts into sub packages
10+
for (let file of await fs.readdir(tailwindcssOxideRoot)) {
11+
if (file.startsWith('tailwindcss-oxide.') && file.endsWith('.node')) {
12+
let target = file.split('.')[1]
13+
await fs.cp(
14+
path.join(tailwindcssOxideRoot, file),
15+
path.join(tailwindcssOxideRoot, 'npm', target, file),
16+
)
17+
}
18+
}
19+
20+
// Move napi wasm artifacts into sub package
21+
let wasmArtifacts = {
22+
'tailwindcss-oxide.debug.wasm': 'tailwindcss-oxide.wasm32-wasi.debug.wasm',
23+
'tailwindcss-oxide.wasm': 'tailwindcss-oxide.wasm32-wasi.wasm',
24+
'tailwindcss-oxide.wasi-browser.js': 'tailwindcss-oxide.wasi-browser.js',
25+
'tailwindcss-oxide.wasi.cjs': 'tailwindcss-oxide.wasi.cjs',
26+
'wasi-worker-browser.mjs': 'wasi-worker-browser.mjs',
27+
'wasi-worker.mjs': 'wasi-worker.mjs',
28+
}
29+
for (let file of await fs.readdir(tailwindcssOxideRoot)) {
30+
if (!wasmArtifacts[file]) continue
31+
await fs.cp(
32+
path.join(tailwindcssOxideRoot, file),
33+
path.join(tailwindcssOxideRoot, 'npm', 'wasm32-wasi', wasmArtifacts[file]),
34+
)
35+
}

Diff for: integrations/oxide/wasm.test.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { css, js, json, test } from '../utils'
2+
3+
test(
4+
'@tailwindcss/oxide-wasm32-wasi can be loaded into a Node.js process',
5+
{
6+
fs: {
7+
'package.json': json`
8+
{
9+
"dependencies": {
10+
"@tailwindcss/oxide-wasm32-wasi": "workspace:^"
11+
}
12+
}
13+
`,
14+
'src/index.css': css`@import 'tailwindcss/utilities';`,
15+
'src/index.js': js`
16+
const className = "content-['src/index.js']"
17+
module.exports = { className }
18+
`,
19+
'index.mjs': js`
20+
import { Scanner } from '@tailwindcss/oxide-wasm32-wasi'
21+
import { join } from 'node:path'
22+
23+
let scanner = new Scanner({
24+
sources: [
25+
{
26+
// Note: There is currently a known-problem that the Node WASI preview implementation
27+
// does not properly handle FS reads on macOS. This forces us to scan a folder that
28+
// does not contain files required to load the WASM module.
29+
//
30+
// https://github.com/nodejs/node/issues/47193
31+
base: join(process.cwd(), 'src'),
32+
pattern: '**/*',
33+
negated: false,
34+
},
35+
],
36+
})
37+
console.log(JSON.stringify(scanner.scan()))
38+
process.exit()
39+
`,
40+
},
41+
},
42+
async ({ expect, exec }) => {
43+
let output = await exec(`node index.mjs`)
44+
expect(JSON.parse(output)).toMatchInlineSnapshot(`
45+
[
46+
"className",
47+
"const",
48+
"content-['src/index.js']",
49+
"exports",
50+
]
51+
`)
52+
},
53+
)
File renamed without changes.

Diff for: pnpm-lock.yaml

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: scripts/pack-packages.mjs

-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ for (let path of paths) {
2424
workspaces.set(pkg.name, { version: pkg.version ?? '', dir: dirname(path) })
2525
}
2626

27-
// Move napi artifacts into sub packages
28-
const tailwindcssOxideRoot = path.join(root, 'crates', 'node')
29-
for (let file of await fs.readdir(tailwindcssOxideRoot)) {
30-
if (file.startsWith('tailwindcss-oxide.') && file.endsWith('.node')) {
31-
let target = file.split('.')[1]
32-
await fs.cp(
33-
path.join(tailwindcssOxideRoot, file),
34-
path.join(tailwindcssOxideRoot, 'npm', target, file),
35-
)
36-
}
37-
}
38-
3927
// Clean dist folder
4028
await fs.rm(path.join(root, 'dist'), { recursive: true, force: true })
4129

Diff for: scripts/version-packages.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ const syncedWorkspaces = new Map([
2828
'crates/node/npm/linux-arm64-musl',
2929
'crates/node/npm/linux-x64-gnu',
3030
'crates/node/npm/linux-x64-musl',
31-
'crates/node/npm/win32-x64-msvc',
31+
'crates/node/npm/wasm32-wasi',
3232
'crates/node/npm/win32-arm64-msvc',
33+
'crates/node/npm/win32-x64-msvc',
3334
],
3435
],
3536
['@tailwindcss/cli', ['packages/@tailwindcss-standalone']],

0 commit comments

Comments
 (0)