unplugin-typegpu 0.10.2 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +14 -4
  2. package/babel-C8UzthFd.d.cts +13 -0
  3. package/babel-CbManzjz.js +128 -0
  4. package/babel-CmCnq-43.d.ts +13 -0
  5. package/babel-Dis-Pwfu.cjs +140 -0
  6. package/babel.cjs +4 -160
  7. package/babel.d.cts +3 -10
  8. package/babel.d.ts +3 -0
  9. package/babel.js +4 -0
  10. package/bun-CDECNeIU.js +134 -0
  11. package/bun-DCACcaN2.cjs +154 -0
  12. package/bun-cwXs2EDP.d.cts +6 -0
  13. package/bun-ovScJ4Es.d.ts +6 -0
  14. package/bun.cjs +4 -38
  15. package/bun.d.cts +2 -4
  16. package/bun.d.ts +3 -0
  17. package/bun.js +4 -0
  18. package/common-BlvLUwEz.d.ts +85 -0
  19. package/common-BoeQmwpt.cjs +340 -0
  20. package/common-CElmMmuq.js +279 -0
  21. package/common-DZ2cLtbe.d.cts +84 -0
  22. package/esbuild.cjs +6 -3
  23. package/esbuild.d.cts +4 -1
  24. package/esbuild.d.ts +5 -0
  25. package/esbuild.js +10 -0
  26. package/farm.cjs +6 -3
  27. package/farm.d.cts +4 -1
  28. package/farm.d.ts +5 -0
  29. package/farm.js +10 -0
  30. package/index-COIv1oYx.d.cts +48 -0
  31. package/index-PPreQbn5.d.ts +48 -0
  32. package/index.cjs +17 -28
  33. package/index.d.cts +5 -17
  34. package/index.d.ts +5 -0
  35. package/index.js +6 -0
  36. package/package.json +11 -9
  37. package/rolldown.cjs +6 -3
  38. package/rolldown.d.cts +4 -1
  39. package/rolldown.d.ts +5 -0
  40. package/rolldown.js +10 -0
  41. package/rollup.cjs +6 -3
  42. package/rollup.d.cts +4 -1
  43. package/rollup.d.ts +5 -0
  44. package/rollup.js +10 -0
  45. package/rspack.cjs +6 -3
  46. package/rspack.d.cts +4 -1
  47. package/rspack.d.ts +5 -0
  48. package/rspack.js +10 -0
  49. package/src-D84rmPxv.js +21 -0
  50. package/src-bIj7OBnd.cjs +82 -0
  51. package/vite.cjs +6 -3
  52. package/vite.d.cts +4 -1
  53. package/vite.d.ts +5 -0
  54. package/vite.js +10 -0
  55. package/webpack.cjs +6 -3
  56. package/webpack.d.cts +4 -1
  57. package/webpack.d.ts +5 -0
  58. package/webpack.js +10 -0
  59. package/babel.d.mts +0 -11
  60. package/babel.mjs +0 -158
  61. package/bun.d.mts +0 -6
  62. package/bun.mjs +0 -36
  63. package/common-CRPQ2KE6.d.mts +0 -25
  64. package/common-Dpl8jppn.d.cts +0 -25
  65. package/esbuild.d.mts +0 -2
  66. package/esbuild.mjs +0 -7
  67. package/farm.d.mts +0 -2
  68. package/farm.mjs +0 -7
  69. package/filter-6T-5w4kG.mjs +0 -234
  70. package/filter-CKmD4HRk.cjs +0 -327
  71. package/index-legacy-DRI9LQiG.d.mts +0 -1488
  72. package/index-legacy-xKi5C2ga.d.cts +0 -1488
  73. package/index.d.mts +0 -17
  74. package/index.mjs +0 -17
  75. package/rolldown-browser-DKeiFM_e.mjs +0 -129
  76. package/rolldown-browser-DUanNY-R.cjs +0 -141
  77. package/rolldown-browser-JYqfNLQ8.d.mts +0 -1247
  78. package/rolldown.d.mts +0 -2
  79. package/rolldown.mjs +0 -7
  80. package/rollup-impl-DqC_d-_W.d.cts +0 -1246
  81. package/rollup.d.mts +0 -2
  82. package/rollup.mjs +0 -7
  83. package/rspack.d.mts +0 -2
  84. package/rspack.mjs +0 -7
  85. package/vite.d.mts +0 -2
  86. package/vite.mjs +0 -7
  87. package/webpack.d.mts +0 -2
  88. package/webpack.mjs +0 -7
package/index.d.mts DELETED
@@ -1,17 +0,0 @@
1
- import export_default from "./babel.mjs";
2
- import { t as Options } from "./common-CRPQ2KE6.mjs";
3
- import _default from "./bun.mjs";
4
- import { n as Plugin, t as rollUpImpl } from "./rolldown-browser-JYqfNLQ8.mjs";
5
- import * as unplugin from "unplugin";
6
-
7
- //#region src/index.d.ts
8
- declare const typegpu: unplugin.UnpluginInstance<Options, boolean>;
9
- declare const vitePlugin: (options: Options) => unplugin.VitePlugin<any> | unplugin.VitePlugin<any>[];
10
- declare const rollupPlugin: (options: Options) => Plugin<any> | Plugin<any>[];
11
- declare const rolldownPlugin: (options: Options) => unplugin.RolldownPlugin<any> | unplugin.RolldownPlugin<any>[];
12
- declare const webpackPlugin: (options: Options) => unplugin.WebpackPluginInstance;
13
- declare const rspackPlugin: (options: Options) => RspackPluginInstance;
14
- declare const esbuildPlugin: (options: Options) => unplugin.EsbuildPlugin;
15
- declare const farmPlugin: (options: Options) => JsPlugin;
16
- //#endregion
17
- export { type Options, export_default as babelPlugin, _default as bunPlugin, typegpu as default, esbuildPlugin, farmPlugin, rollUpImpl as rolldownBrowserPlugin, rolldownPlugin, rollupPlugin, rspackPlugin, vitePlugin, webpackPlugin };
package/index.mjs DELETED
@@ -1,17 +0,0 @@
1
- import { n as rollUpImpl, t as rolldown_browser_default } from "./rolldown-browser-DKeiFM_e.mjs";
2
- import babel_default from "./babel.mjs";
3
- import bun_default from "./bun.mjs";
4
- import { createUnplugin } from "unplugin";
5
-
6
- //#region src/index.ts
7
- const typegpu = createUnplugin(rollUpImpl);
8
- const vitePlugin = typegpu.vite;
9
- const rollupPlugin = typegpu.rollup;
10
- const rolldownPlugin = typegpu.rolldown;
11
- const webpackPlugin = typegpu.webpack;
12
- const rspackPlugin = typegpu.rspack;
13
- const esbuildPlugin = typegpu.esbuild;
14
- const farmPlugin = typegpu.farm;
15
-
16
- //#endregion
17
- export { babel_default as babelPlugin, bun_default as bunPlugin, typegpu as default, esbuildPlugin, farmPlugin, rolldown_browser_default as rolldownBrowserPlugin, rolldownPlugin, rollupPlugin, rspackPlugin, vitePlugin, webpackPlugin };
@@ -1,129 +0,0 @@
1
- import { a as gatherTgpuAliases, c as operators, i as embedJSON, l as performExpressionNaming, n as defaultOptions, o as getFunctionName, r as earlyPruneRegex, s as isShellImplementationCall, u as useGpuDirective } from "./filter-6T-5w4kG.mjs";
2
- import defu from "defu";
3
- import { MagicStringAST, generateTransform } from "magic-string-ast";
4
- import { walk } from "estree-walker";
5
- import { transpileFn } from "tinyest-for-wgsl";
6
- import { FORMAT_VERSION } from "tinyest";
7
-
8
- //#region src/rollup-impl.ts
9
- function containsUseGpuDirective(node) {
10
- if (node.body.type === "BlockStatement") {
11
- for (const statement of node.body.body) if (statement.type === "ExpressionStatement" && statement.directive === useGpuDirective) return true;
12
- }
13
- return false;
14
- }
15
- function removeUseGpuDirective(node) {
16
- const cloned = structuredClone(node);
17
- if (cloned.body.type === "BlockStatement") cloned.body.body = cloned.body.body.filter((statement) => !(statement.type === "ExpressionStatement" && statement.directive === useGpuDirective));
18
- return cloned;
19
- }
20
- function assignMetadata(magicString, node, metadata) {
21
- magicString.prependLeft(node.start, "(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(node.end, `), ${metadata}) && $.f)({}))`);
22
- }
23
- function wrapInAutoName(magicString, node, name) {
24
- magicString.prependLeft(node.start, "((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(node.end, `, "${name}"))`);
25
- }
26
- const rollUpImpl = (rawOptions) => {
27
- const options = defu(rawOptions, defaultOptions);
28
- return {
29
- name: "unplugin-typegpu",
30
- enforce: options.enforce,
31
- transform: {
32
- filter: options.earlyPruning ? {
33
- id: options,
34
- code: earlyPruneRegex
35
- } : { id: options },
36
- handler(code, id) {
37
- const ctx = {
38
- tgpuAliases: new Set(options.forceTgpuAlias ? [options.forceTgpuAlias] : []),
39
- fileId: id,
40
- autoNamingEnabled: options.autoNamingEnabled
41
- };
42
- let ast;
43
- try {
44
- ast = this.parse(code, {
45
- lang: "ts",
46
- allowReturnOutsideFunction: true
47
- });
48
- } catch (cause) {
49
- console.warn(`[unplugin-typegpu] Failed to parse ${id}. Cause: ${typeof cause === "object" && cause && "message" in cause ? cause.message : cause}`);
50
- return;
51
- }
52
- const tgslFunctionDefs = [];
53
- const magicString = new MagicStringAST(code);
54
- walk(ast, { enter(_node, _parent) {
55
- const node = _node;
56
- const parent = _parent;
57
- performExpressionNaming(ctx, node, (node, name) => {
58
- wrapInAutoName(magicString, node, name);
59
- });
60
- if (node.type === "ImportDeclaration") gatherTgpuAliases(node, ctx);
61
- if (node.type === "CallExpression") {
62
- if (isShellImplementationCall(node, ctx)) {
63
- const implementation = node.arguments[0];
64
- if (implementation && (implementation.type === "FunctionExpression" || implementation.type === "ArrowFunctionExpression")) {
65
- tgslFunctionDefs.push({ def: removeUseGpuDirective(implementation) });
66
- this.skip();
67
- }
68
- }
69
- }
70
- if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
71
- if (containsUseGpuDirective(node)) {
72
- tgslFunctionDefs.push({
73
- def: removeUseGpuDirective(node),
74
- name: getFunctionName(node, parent)
75
- });
76
- this.skip();
77
- }
78
- }
79
- } });
80
- for (const { def, name } of tgslFunctionDefs) {
81
- const { params, body, externalNames } = transpileFn(def);
82
- const isFunctionStatement = def.type === "FunctionDeclaration";
83
- walk(def, { leave(_node) {
84
- const node = _node;
85
- if (node.type === "AssignmentExpression") {
86
- const runtimeFn = operators[node.operator];
87
- if (runtimeFn) {
88
- const left = node.left;
89
- const right = node.right;
90
- const lhs = magicString.sliceNode(left);
91
- const rhs = magicString.sliceNode(right);
92
- magicString.overwriteNode(node, `${lhs} = ${runtimeFn}(${lhs}, ${rhs})`);
93
- }
94
- } else if (node.type === "BinaryExpression") {
95
- const runtimeFn = operators[node.operator];
96
- if (runtimeFn) {
97
- const left = node.left;
98
- const right = node.right;
99
- const lhs = magicString.sliceNode(left);
100
- const rhs = magicString.sliceNode(right);
101
- magicString.overwriteNode(node, `${runtimeFn}(${lhs}, ${rhs})`);
102
- }
103
- }
104
- } });
105
- if (isFunctionStatement && name && code.slice(0, def.start).search(new RegExp(`(?<![\\w_.])${name}(?![\\w_])`)) !== -1) console.warn(`File ${id}: function "${name}" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);
106
- assignMetadata(magicString, def, `{
107
- v: ${FORMAT_VERSION},
108
- name: ${name ? `"${name}"` : "undefined"},
109
- ast: ${embedJSON({
110
- params,
111
- body,
112
- externalNames
113
- })},
114
- externals: () => ({${externalNames.map((e) => e === "this" ? "\"this\": this" : e).join(", ")}}),
115
- }`);
116
- if (isFunctionStatement && name) magicString.prependLeft(def.start, `const ${name} = `);
117
- }
118
- return generateTransform(magicString, id);
119
- }
120
- }
121
- };
122
- };
123
-
124
- //#endregion
125
- //#region src/rolldown-browser.ts
126
- var rolldown_browser_default = rollUpImpl;
127
-
128
- //#endregion
129
- export { rollUpImpl as n, rolldown_browser_default as t };
@@ -1,141 +0,0 @@
1
- const require_filter = require('./filter-CKmD4HRk.cjs');
2
- let defu = require("defu");
3
- defu = require_filter.__toESM(defu);
4
- let magic_string_ast = require("magic-string-ast");
5
- let estree_walker = require("estree-walker");
6
- let tinyest_for_wgsl = require("tinyest-for-wgsl");
7
- let tinyest = require("tinyest");
8
-
9
- //#region src/rollup-impl.ts
10
- function containsUseGpuDirective(node) {
11
- if (node.body.type === "BlockStatement") {
12
- for (const statement of node.body.body) if (statement.type === "ExpressionStatement" && statement.directive === require_filter.useGpuDirective) return true;
13
- }
14
- return false;
15
- }
16
- function removeUseGpuDirective(node) {
17
- const cloned = structuredClone(node);
18
- if (cloned.body.type === "BlockStatement") cloned.body.body = cloned.body.body.filter((statement) => !(statement.type === "ExpressionStatement" && statement.directive === require_filter.useGpuDirective));
19
- return cloned;
20
- }
21
- function assignMetadata(magicString, node, metadata) {
22
- magicString.prependLeft(node.start, "(($ => (globalThis.__TYPEGPU_META__ ??= new WeakMap()).set($.f = (").appendRight(node.end, `), ${metadata}) && $.f)({}))`);
23
- }
24
- function wrapInAutoName(magicString, node, name) {
25
- magicString.prependLeft(node.start, "((globalThis.__TYPEGPU_AUTONAME__ ?? (a => a))(").appendRight(node.end, `, "${name}"))`);
26
- }
27
- const rollUpImpl = (rawOptions) => {
28
- const options = (0, defu.default)(rawOptions, require_filter.defaultOptions);
29
- return {
30
- name: "unplugin-typegpu",
31
- enforce: options.enforce,
32
- transform: {
33
- filter: options.earlyPruning ? {
34
- id: options,
35
- code: require_filter.earlyPruneRegex
36
- } : { id: options },
37
- handler(code, id) {
38
- const ctx = {
39
- tgpuAliases: new Set(options.forceTgpuAlias ? [options.forceTgpuAlias] : []),
40
- fileId: id,
41
- autoNamingEnabled: options.autoNamingEnabled
42
- };
43
- let ast;
44
- try {
45
- ast = this.parse(code, {
46
- lang: "ts",
47
- allowReturnOutsideFunction: true
48
- });
49
- } catch (cause) {
50
- console.warn(`[unplugin-typegpu] Failed to parse ${id}. Cause: ${typeof cause === "object" && cause && "message" in cause ? cause.message : cause}`);
51
- return;
52
- }
53
- const tgslFunctionDefs = [];
54
- const magicString = new magic_string_ast.MagicStringAST(code);
55
- (0, estree_walker.walk)(ast, { enter(_node, _parent) {
56
- const node = _node;
57
- const parent = _parent;
58
- require_filter.performExpressionNaming(ctx, node, (node, name) => {
59
- wrapInAutoName(magicString, node, name);
60
- });
61
- if (node.type === "ImportDeclaration") require_filter.gatherTgpuAliases(node, ctx);
62
- if (node.type === "CallExpression") {
63
- if (require_filter.isShellImplementationCall(node, ctx)) {
64
- const implementation = node.arguments[0];
65
- if (implementation && (implementation.type === "FunctionExpression" || implementation.type === "ArrowFunctionExpression")) {
66
- tgslFunctionDefs.push({ def: removeUseGpuDirective(implementation) });
67
- this.skip();
68
- }
69
- }
70
- }
71
- if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration") {
72
- if (containsUseGpuDirective(node)) {
73
- tgslFunctionDefs.push({
74
- def: removeUseGpuDirective(node),
75
- name: require_filter.getFunctionName(node, parent)
76
- });
77
- this.skip();
78
- }
79
- }
80
- } });
81
- for (const { def, name } of tgslFunctionDefs) {
82
- const { params, body, externalNames } = (0, tinyest_for_wgsl.transpileFn)(def);
83
- const isFunctionStatement = def.type === "FunctionDeclaration";
84
- (0, estree_walker.walk)(def, { leave(_node) {
85
- const node = _node;
86
- if (node.type === "AssignmentExpression") {
87
- const runtimeFn = require_filter.operators[node.operator];
88
- if (runtimeFn) {
89
- const left = node.left;
90
- const right = node.right;
91
- const lhs = magicString.sliceNode(left);
92
- const rhs = magicString.sliceNode(right);
93
- magicString.overwriteNode(node, `${lhs} = ${runtimeFn}(${lhs}, ${rhs})`);
94
- }
95
- } else if (node.type === "BinaryExpression") {
96
- const runtimeFn = require_filter.operators[node.operator];
97
- if (runtimeFn) {
98
- const left = node.left;
99
- const right = node.right;
100
- const lhs = magicString.sliceNode(left);
101
- const rhs = magicString.sliceNode(right);
102
- magicString.overwriteNode(node, `${runtimeFn}(${lhs}, ${rhs})`);
103
- }
104
- }
105
- } });
106
- if (isFunctionStatement && name && code.slice(0, def.start).search(new RegExp(`(?<![\\w_.])${name}(?![\\w_])`)) !== -1) console.warn(`File ${id}: function "${name}" might have been referenced before its usage. Function statements are no longer hoisted after being transformed by the plugin.`);
107
- assignMetadata(magicString, def, `{
108
- v: ${tinyest.FORMAT_VERSION},
109
- name: ${name ? `"${name}"` : "undefined"},
110
- ast: ${require_filter.embedJSON({
111
- params,
112
- body,
113
- externalNames
114
- })},
115
- externals: () => ({${externalNames.map((e) => e === "this" ? "\"this\": this" : e).join(", ")}}),
116
- }`);
117
- if (isFunctionStatement && name) magicString.prependLeft(def.start, `const ${name} = `);
118
- }
119
- return (0, magic_string_ast.generateTransform)(magicString, id);
120
- }
121
- }
122
- };
123
- };
124
-
125
- //#endregion
126
- //#region src/rolldown-browser.ts
127
- var rolldown_browser_default = rollUpImpl;
128
-
129
- //#endregion
130
- Object.defineProperty(exports, 'rollUpImpl', {
131
- enumerable: true,
132
- get: function () {
133
- return rollUpImpl;
134
- }
135
- });
136
- Object.defineProperty(exports, 'rolldown_browser_default', {
137
- enumerable: true,
138
- get: function () {
139
- return rolldown_browser_default;
140
- }
141
- });