Skip to content

Commit b5a8145

Browse files
authored
refactor: Unplugin 3 (#2294)
1 parent bf5f903 commit b5a8145

29 files changed

+3123
-2242
lines changed

apps/bun-example/preload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { plugin } from 'bun';
22
import typegpu from 'unplugin-typegpu/bun';
33

4-
void plugin(typegpu({ include: /\.(ts)$/ }));
4+
void plugin(typegpu());

apps/treeshake-test/bundleWith.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function bundleWithEsbuild(entryUrl: URL, outDir: URL): Promise<URL
1717
const entryFileName = path.basename(entryUrl.pathname, '.ts');
1818
const outPath = new URL(`${entryFileName}.esbuild.js`, outDir);
1919
await esbuild({
20-
plugins: [esbuildPlugin({})],
20+
plugins: [esbuildPlugin()],
2121
entryPoints: [entryUrl.pathname],
2222
bundle: true,
2323
outfile: outPath.pathname,
@@ -40,7 +40,7 @@ export async function bundleWithWebpack(entryPath: URL, outDir: URL): Promise<UR
4040
path: path.dirname(outPath.pathname),
4141
filename: path.basename(outPath.pathname),
4242
},
43-
plugins: [webpackPlugin({})],
43+
plugins: [webpackPlugin()],
4444
module: {
4545
rules: [
4646
{
@@ -84,7 +84,7 @@ export async function bundleWithTsdown(entryUrl: URL, outDir: URL): Promise<URL>
8484

8585
try {
8686
await tsdown({
87-
plugins: [rolldownPlugin({})],
87+
plugins: [rolldownPlugin()],
8888
outputOptions: {
8989
name: path.basename(outPath.pathname),
9090
dir: path.dirname(outPath.pathname),

apps/typegpu-docs/src/content/docs/tooling/unplugin-typegpu.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import { defineConfig } from 'vite';
7171
import typegpuPlugin from 'unplugin-typegpu/vite';
7272

7373
export default defineConfig({
74-
plugins: [typegpuPlugin({})],
74+
plugins: [typegpuPlugin()],
7575
});
7676
```
7777

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@
6666
"sharp"
6767
],
6868
"overrides": {
69-
"rollup": "catalog:",
69+
"rollup": "catalog:build",
7070
"vite": "8.0.2",
71+
"@babel/types": "catalog:",
7172
"typescript": "catalog:types",
7273
"three": "catalog:example"
7374
}

packages/tinyest-for-wgsl/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
},
5757
"devDependencies": {
5858
"@babel/parser": "^7.27.0",
59-
"@babel/types": "7.26.5",
59+
"@babel/types": "catalog:",
6060
"@typegpu/tgpu-dev-cli": "workspace:*",
6161
"acorn": "^8.14.1",
6262
"tsdown": "catalog:build",

packages/tinyest-for-wgsl/tsdown.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { defineConfig } from 'tsdown';
33
export default defineConfig({
44
entry: ['src/index.ts'],
55
outDir: 'dist',
6-
inlineOnly: false,
6+
deps: {
7+
onlyBundle: false,
8+
},
79
format: ['cjs', 'esm'],
810
dts: true,
911
platform: 'neutral',

packages/typegpu/tests/unplugin/autoname.test.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,45 @@ describe('autonaming', () => {
175175
});
176176

177177
it('shellless name carries over to WGSL', () => {
178-
function myFun() {
179-
'use gpu';
180-
return 0;
181-
}
178+
const scope = () => {
179+
function myFun() {
180+
'use gpu';
181+
return 0;
182+
}
182183

183-
const main = tgpu.fn([])(() => {
184-
myFun();
185-
});
184+
const main = tgpu.fn([])(() => {
185+
myFun();
186+
});
187+
188+
return main;
189+
};
190+
191+
expect(scope.toString()).toMatchInlineSnapshot(`
192+
"() => {
193+
const myFun = (/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (function myFun() {
194+
"use gpu";
195+
return 0;
196+
}), {
197+
v: 1,
198+
name: "myFun",
199+
ast: {"params":[],"body":[0,[[10,[5,"0"]]]],"externalNames":[]},
200+
externals: () => ({}),
201+
}) && $.f)({}));
202+
203+
204+
const main = (/*#__PURE__*/(globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(__vite_ssr_import_2__.default.fn([])((/*#__PURE__*/($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (() => {
205+
myFun();
206+
}), {
207+
v: 1,
208+
name: undefined,
209+
ast: {"params":[],"body":[0,[[6,"myFun",[]]]],"externalNames":["myFun"]},
210+
externals: () => ({myFun}),
211+
}) && $.f)({}))), "main"));
212+
return main;
213+
}"
214+
`);
186215

187-
expect(tgpu.resolve([main])).toMatchInlineSnapshot(`
216+
expect(tgpu.resolve([scope()])).toMatchInlineSnapshot(`
188217
"fn myFun() -> i32 {
189218
return 0;
190219
}

packages/unplugin-typegpu/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
# unplugin-typegpu
44

5-
🚧 **Under Construction** 🚧 -
65
[GitHub](https://github.com/software-mansion/TypeGPU/tree/main/packages/unplugin-typegpu)
76

87
Read more about the plugin in the
98
[TypeGPU documentation](https://docs.swmansion.com/TypeGPU/tooling/unplugin-typegpu/).
109

1110
</div>
1211

13-
Build plugins for [TypeGPU](https://typegpu.com) that enable:
12+
A set of bundler plugins that enhance [TypeGPU](https://typegpu.com) with:
1413

15-
- Seamless JavaScript -> WGSL transpilation
16-
- [🚧 TODO] Improved debugging with automatic naming of resources
14+
- JavaScript/TypeScript shader support ('use gpu' directive)
15+
- Improved debugging with automatic naming of resources
1716

1817
## Getting Started
1918

@@ -48,6 +47,17 @@ export default defineConfig({
4847
});
4948
```
5049

50+
- bun
51+
52+
```ts
53+
// preload.ts
54+
55+
import { plugin } from 'bun';
56+
import typegpu from 'unplugin-typegpu/bun';
57+
58+
void plugin(typegpu());
59+
```
60+
5161
## TypeGPU is created by Software Mansion
5262

5363
[![swm](https://logo.swmansion.com/logo?color=white&variant=desktop&width=150&tag=typegpu-github 'Software Mansion')](https://swmansion.com)

packages/unplugin-typegpu/package.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"license": "MIT",
2323
"repository": {
2424
"type": "git",
25-
"url": "git+https://github.com/software-mansion/TypeGPU.git"
25+
"url": "git+https://github.com/software-mansion/TypeGPU.git",
26+
"directory": "packages/unplugin-typegpu"
2627
},
2728
"type": "module",
2829
"sideEffects": false,
@@ -165,29 +166,27 @@
165166
"prepublishOnly": "tgpu-dev-cli prepack"
166167
},
167168
"dependencies": {
168-
"@babel/standalone": "^7.28.6",
169+
"@babel/parser": "^7.29.0",
170+
"@babel/traverse": "^7.29.0",
171+
"@babel/types": "catalog:",
172+
"ast-kit": "^2.2.0",
169173
"defu": "^6.1.4",
170-
"estree-walker": "^3.0.3",
171-
"magic-string-ast": "^1.0.0",
174+
"magic-string-ast": "^1.0.3",
172175
"pathe": "^2.0.3",
173176
"picomatch": "^4.0.3",
174177
"tinyest": "workspace:~0.3.1",
175178
"tinyest-for-wgsl": "workspace:~0.3.2",
176-
"unplugin": "^2.3.5"
179+
"unplugin": "^3.0.0"
177180
},
178181
"devDependencies": {
179-
"@babel/template": "^7.27.2",
180-
"@babel/types": "^7.26.5",
182+
"@babel/standalone": "^7.28.6",
181183
"@rollup/plugin-virtual": "^3.0.2",
182184
"@typegpu/tgpu-dev-cli": "workspace:*",
183185
"@types/babel__standalone": "^7.1.9",
184-
"@types/babel__template": "^7.4.4",
185186
"@types/babel__traverse": "^7.20.7",
186-
"@types/bun": "^1.2.22",
187+
"@types/bun": "^1.3.11",
187188
"@types/picomatch": "^4.0.1",
188-
"acorn": "^8.14.1",
189-
"rolldown": "1.0.0-beta.33",
190-
"rollup": "catalog:",
189+
"rollup": "catalog:build",
191190
"tsdown": "catalog:build",
192191
"typescript": "catalog:types"
193192
},

0 commit comments

Comments
 (0)