unplugin-typegpu 0.9.0 → 0.10.0

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 (129) hide show
  1. package/babel.cjs +161 -2
  2. package/babel.d.cts +8 -7
  3. package/babel.d.cts.map +1 -0
  4. package/babel.d.mts +12 -0
  5. package/babel.d.mts.map +1 -0
  6. package/babel.mjs +159 -0
  7. package/babel.mjs.map +1 -0
  8. package/bun.cjs +39 -2
  9. package/bun.d.cts +6 -3
  10. package/bun.d.cts.map +1 -0
  11. package/bun.d.mts +7 -0
  12. package/bun.d.mts.map +1 -0
  13. package/bun.mjs +37 -0
  14. package/bun.mjs.map +1 -0
  15. package/common-CRPQ2KE6.d.mts +26 -0
  16. package/common-CRPQ2KE6.d.mts.map +1 -0
  17. package/common-Dpl8jppn.d.cts +26 -0
  18. package/common-Dpl8jppn.d.cts.map +1 -0
  19. package/esbuild.cjs +8 -2
  20. package/esbuild.d.cts +3 -14
  21. package/esbuild.d.mts +4 -0
  22. package/esbuild.mjs +8 -0
  23. package/esbuild.mjs.map +1 -0
  24. package/farm.cjs +8 -2
  25. package/farm.d.cts +3 -14
  26. package/farm.d.mts +4 -0
  27. package/farm.mjs +8 -0
  28. package/farm.mjs.map +1 -0
  29. package/filter-6T-5w4kG.mjs +235 -0
  30. package/filter-6T-5w4kG.mjs.map +1 -0
  31. package/filter-CKmD4HRk.cjs +327 -0
  32. package/index-legacy-DRI9LQiG.d.mts +1489 -0
  33. package/index-legacy-DRI9LQiG.d.mts.map +1 -0
  34. package/index-legacy-xKi5C2ga.d.cts +1489 -0
  35. package/index-legacy-xKi5C2ga.d.cts.map +1 -0
  36. package/index.cjs +29 -2
  37. package/index.d.cts +12 -48
  38. package/index.d.cts.map +1 -0
  39. package/index.d.mts +18 -0
  40. package/index.d.mts.map +1 -0
  41. package/index.mjs +18 -0
  42. package/index.mjs.map +1 -0
  43. package/package.json +95 -51
  44. package/rolldown-browser-DKeiFM_e.mjs +130 -0
  45. package/rolldown-browser-DKeiFM_e.mjs.map +1 -0
  46. package/rolldown-browser-DUanNY-R.cjs +141 -0
  47. package/rolldown-browser-JYqfNLQ8.d.mts +1248 -0
  48. package/rolldown-browser-JYqfNLQ8.d.mts.map +1 -0
  49. package/rolldown.cjs +8 -2
  50. package/rolldown.d.cts +3 -14
  51. package/rolldown.d.mts +4 -0
  52. package/rolldown.mjs +8 -0
  53. package/rolldown.mjs.map +1 -0
  54. package/rollup-impl-DqC_d-_W.d.cts +1247 -0
  55. package/rollup-impl-DqC_d-_W.d.cts.map +1 -0
  56. package/rollup.cjs +8 -2
  57. package/rollup.d.cts +3 -14
  58. package/rollup.d.mts +4 -0
  59. package/rollup.mjs +8 -0
  60. package/rollup.mjs.map +1 -0
  61. package/rspack.cjs +8 -2
  62. package/rspack.d.cts +3 -14
  63. package/rspack.d.mts +4 -0
  64. package/rspack.mjs +8 -0
  65. package/rspack.mjs.map +1 -0
  66. package/vite.cjs +8 -2
  67. package/vite.d.cts +3 -14
  68. package/vite.d.mts +4 -0
  69. package/vite.mjs +8 -0
  70. package/vite.mjs.map +1 -0
  71. package/webpack.cjs +8 -2
  72. package/webpack.d.cts +3 -14
  73. package/webpack.d.mts +4 -0
  74. package/webpack.mjs +8 -0
  75. package/webpack.mjs.map +1 -0
  76. package/babel.cjs.map +0 -1
  77. package/babel.d.ts +0 -10
  78. package/babel.js +0 -2
  79. package/babel.js.map +0 -1
  80. package/bun-Dq3TUCfa.d.cts +0 -27
  81. package/bun-Dq3TUCfa.d.ts +0 -27
  82. package/bun.cjs.map +0 -1
  83. package/bun.d.ts +0 -3
  84. package/bun.js +0 -2
  85. package/bun.js.map +0 -1
  86. package/chunk-DEVVEJF4.cjs +0 -2
  87. package/chunk-DEVVEJF4.cjs.map +0 -1
  88. package/chunk-EESBB3Y4.js +0 -2
  89. package/chunk-EESBB3Y4.js.map +0 -1
  90. package/chunk-LJXNN2RM.cjs +0 -7
  91. package/chunk-LJXNN2RM.cjs.map +0 -1
  92. package/chunk-NQODVO3L.cjs +0 -2
  93. package/chunk-NQODVO3L.cjs.map +0 -1
  94. package/chunk-RIZD7OMC.js +0 -7
  95. package/chunk-RIZD7OMC.js.map +0 -1
  96. package/chunk-V4Q4PLLO.js +0 -2
  97. package/chunk-V4Q4PLLO.js.map +0 -1
  98. package/esbuild.cjs.map +0 -1
  99. package/esbuild.d.ts +0 -14
  100. package/esbuild.js +0 -2
  101. package/esbuild.js.map +0 -1
  102. package/farm.cjs.map +0 -1
  103. package/farm.d.ts +0 -14
  104. package/farm.js +0 -2
  105. package/farm.js.map +0 -1
  106. package/index.cjs.map +0 -1
  107. package/index.d.ts +0 -54
  108. package/index.js +0 -2
  109. package/index.js.map +0 -1
  110. package/rolldown.cjs.map +0 -1
  111. package/rolldown.d.ts +0 -14
  112. package/rolldown.js +0 -2
  113. package/rolldown.js.map +0 -1
  114. package/rollup.cjs.map +0 -1
  115. package/rollup.d.ts +0 -14
  116. package/rollup.js +0 -2
  117. package/rollup.js.map +0 -1
  118. package/rspack.cjs.map +0 -1
  119. package/rspack.d.ts +0 -14
  120. package/rspack.js +0 -2
  121. package/rspack.js.map +0 -1
  122. package/vite.cjs.map +0 -1
  123. package/vite.d.ts +0 -14
  124. package/vite.js +0 -2
  125. package/vite.js.map +0 -1
  126. package/webpack.cjs.map +0 -1
  127. package/webpack.d.ts +0 -14
  128. package/webpack.js +0 -2
  129. package/webpack.js.map +0 -1
package/babel.cjs CHANGED
@@ -1,2 +1,161 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkDEVVEJF4cjs = require('./chunk-DEVVEJF4.cjs');exports.default = _chunkDEVVEJF4cjs.i;
2
- //# sourceMappingURL=babel.cjs.map
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_filter = require('./filter-CKmD4HRk.cjs');
3
+ let defu = require("defu");
4
+ defu = require_filter.__toESM(defu);
5
+ let tinyest_for_wgsl = require("tinyest-for-wgsl");
6
+ let tinyest = require("tinyest");
7
+ let _babel_standalone = require("@babel/standalone");
8
+ _babel_standalone = require_filter.__toESM(_babel_standalone);
9
+
10
+ //#region src/babel.ts
11
+ const template = _babel_standalone.packages.template;
12
+ const types = _babel_standalone.packages.types;
13
+ function containsUseGpuDirective(node) {
14
+ var _node$body$directives, _node$body;
15
+ return ("directives" in node.body ? (_node$body$directives = (_node$body = node.body) === null || _node$body === void 0 ? void 0 : _node$body.directives) !== null && _node$body$directives !== void 0 ? _node$body$directives : [] : []).map((directive) => directive.value.value).includes(require_filter.useGpuDirective);
16
+ }
17
+ function i(identifier) {
18
+ return types.identifier(identifier);
19
+ }
20
+ const fnNodeToOriginalMap = /* @__PURE__ */ new WeakMap();
21
+ function functionToTranspiled(node, parent) {
22
+ var _fnNodeToOriginalMap$;
23
+ const { params, body, externalNames } = (0, tinyest_for_wgsl.transpileFn)((_fnNodeToOriginalMap$ = fnNodeToOriginalMap.get(node)) !== null && _fnNodeToOriginalMap$ !== void 0 ? _fnNodeToOriginalMap$ : node);
24
+ const maybeName = require_filter.getFunctionName(node, parent);
25
+ const metadata = types.objectExpression([
26
+ types.objectProperty(i("v"), types.numericLiteral(tinyest.FORMAT_VERSION)),
27
+ types.objectProperty(i("name"), maybeName ? types.stringLiteral(maybeName) : types.buildUndefinedNode()),
28
+ types.objectProperty(i("ast"), template.expression`${require_filter.embedJSON({
29
+ params,
30
+ body,
31
+ externalNames
32
+ })}`()),
33
+ types.objectProperty(i("externals"), types.arrowFunctionExpression([], types.blockStatement([types.returnStatement(types.objectExpression(externalNames.map((name) => types.objectProperty(i(name), i(name), false, name !== "this"))))])))
34
+ ]);
35
+ return types.callExpression(types.arrowFunctionExpression([i("$")], types.logicalExpression("&&", types.callExpression(types.memberExpression(types.assignmentExpression("??=", types.memberExpression(i("globalThis"), i("__TYPEGPU_META__")), types.newExpression(i("WeakMap"), [])), i("set")), [types.assignmentExpression("=", types.memberExpression(i("$"), i("f")), node), metadata]), types.memberExpression(i("$"), i("f")))), [types.objectExpression([])]);
36
+ }
37
+ function wrapInAutoName(node, name) {
38
+ return types.callExpression(template.expression("globalThis.__TYPEGPU_AUTONAME__ ?? (a => a)", { placeholderPattern: false })(), [node, types.stringLiteral(name)]);
39
+ }
40
+ function functionVisitor(ctx) {
41
+ let inUseGpuScope = false;
42
+ return {
43
+ VariableDeclarator(path) {
44
+ require_filter.performExpressionNaming(ctx, path.node, (node, name) => {
45
+ path.get("init").replaceWith(wrapInAutoName(node, name));
46
+ });
47
+ },
48
+ AssignmentExpression(path) {
49
+ if (inUseGpuScope) {
50
+ const runtimeFn = require_filter.operators[path.node.operator];
51
+ if (runtimeFn) path.replaceWith(types.assignmentExpression("=", path.node.left, types.callExpression(types.identifier(runtimeFn), [path.node.left, path.node.right])));
52
+ }
53
+ require_filter.performExpressionNaming(ctx, path.node, (node, name) => {
54
+ path.get("right").replaceWith(wrapInAutoName(node, name));
55
+ });
56
+ },
57
+ ObjectProperty(path) {
58
+ require_filter.performExpressionNaming(ctx, path.node, (node, name) => {
59
+ path.get("value").replaceWith(wrapInAutoName(node, name));
60
+ });
61
+ },
62
+ ClassProperty(path) {
63
+ require_filter.performExpressionNaming(ctx, path.node, (node, name) => {
64
+ path.get("value").replaceWith(wrapInAutoName(node, name));
65
+ });
66
+ },
67
+ ImportDeclaration(path) {
68
+ require_filter.gatherTgpuAliases(path.node, ctx);
69
+ },
70
+ BinaryExpression: { exit(path) {
71
+ if (!inUseGpuScope) return;
72
+ const runtimeFn = require_filter.operators[path.node.operator];
73
+ if (runtimeFn) path.replaceWith(types.callExpression(types.identifier(runtimeFn), [path.node.left, path.node.right]));
74
+ } },
75
+ ArrowFunctionExpression: {
76
+ enter(path) {
77
+ if (containsUseGpuDirective(path.node)) {
78
+ fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
79
+ if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
80
+ inUseGpuScope = true;
81
+ }
82
+ },
83
+ exit(path) {
84
+ const node = path.node;
85
+ if (containsUseGpuDirective(node)) {
86
+ inUseGpuScope = false;
87
+ const parent = path.parentPath.node;
88
+ path.replaceWith(functionToTranspiled(node, parent));
89
+ path.skip();
90
+ }
91
+ }
92
+ },
93
+ FunctionExpression: {
94
+ enter(path) {
95
+ if (containsUseGpuDirective(path.node)) {
96
+ fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
97
+ if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
98
+ inUseGpuScope = true;
99
+ }
100
+ },
101
+ exit(path) {
102
+ const node = path.node;
103
+ if (containsUseGpuDirective(node)) {
104
+ inUseGpuScope = false;
105
+ const parent = path.parentPath.node;
106
+ path.replaceWith(functionToTranspiled(node, parent));
107
+ path.skip();
108
+ }
109
+ }
110
+ },
111
+ FunctionDeclaration: {
112
+ enter(path) {
113
+ if (containsUseGpuDirective(path.node)) {
114
+ fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
115
+ if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
116
+ inUseGpuScope = true;
117
+ }
118
+ },
119
+ exit(path) {
120
+ var _fnNodeToOriginalMap$2;
121
+ const node = (_fnNodeToOriginalMap$2 = fnNodeToOriginalMap.get(path.node)) !== null && _fnNodeToOriginalMap$2 !== void 0 ? _fnNodeToOriginalMap$2 : path.node;
122
+ if (containsUseGpuDirective(node)) {
123
+ inUseGpuScope = false;
124
+ if (!node.id) return;
125
+ const parent = path.parentPath.node;
126
+ const expression = types.functionExpression(node.id, node.params, node.body);
127
+ path.replaceWith(types.variableDeclaration("const", [types.variableDeclarator(node.id, functionToTranspiled(expression, parent))]));
128
+ path.skip();
129
+ }
130
+ }
131
+ },
132
+ CallExpression: { exit(path) {
133
+ const node = path.node;
134
+ if (require_filter.isShellImplementationCall(node, ctx)) {
135
+ const implementation = node.arguments[0];
136
+ if (implementation && (implementation.type === "FunctionExpression" || implementation.type === "ArrowFunctionExpression")) {
137
+ const transpiled = functionToTranspiled(implementation, null);
138
+ path.replaceWith(types.callExpression(node.callee, [transpiled]));
139
+ path.skip();
140
+ }
141
+ }
142
+ } }
143
+ };
144
+ }
145
+ function babel_default() {
146
+ return { visitor: { Program(path, state) {
147
+ const options = (0, defu.default)(state.opts, require_filter.defaultOptions);
148
+ const id = state.filename;
149
+ const filter = require_filter.createFilterForId(options);
150
+ if (id && filter && !(filter === null || filter === void 0 ? void 0 : filter(id))) return;
151
+ const ctx = {
152
+ tgpuAliases: new Set(options.forceTgpuAlias ? [options.forceTgpuAlias] : []),
153
+ fileId: id,
154
+ autoNamingEnabled: options.autoNamingEnabled
155
+ };
156
+ path.traverse(functionVisitor(ctx));
157
+ } } };
158
+ }
159
+
160
+ //#endregion
161
+ exports.default = babel_default;
package/babel.d.cts CHANGED
@@ -1,10 +1,11 @@
1
- import * as _babel_traverse from '@babel/traverse';
2
- import * as babel from '@babel/types';
1
+ import { n as Program, t as Node } from "./index-legacy-xKi5C2ga.cjs";
2
+ import * as _babel_traverse0 from "@babel/traverse";
3
3
 
4
+ //#region src/babel.d.ts
4
5
  declare function export_default(): {
5
- visitor: {
6
- Program(this: babel.Node, path: _babel_traverse.NodePath<babel.Program>, state: babel.Node): void;
7
- };
6
+ visitor: {
7
+ Program(this: Node, path: _babel_traverse0.NodePath<Program>, state: Node): void;
8
+ };
8
9
  };
9
-
10
- export { export_default as default };
10
+ export = export_default;
11
+ //# sourceMappingURL=babel.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.d.cts","names":[],"sources":["../src/babel.ts"],"mappings":";;;;iBAG2C,cAAA,CAAA"}
package/babel.d.mts ADDED
@@ -0,0 +1,12 @@
1
+ import { n as Program, t as Node } from "./index-legacy-DRI9LQiG.mjs";
2
+ import * as _babel_traverse0 from "@babel/traverse";
3
+
4
+ //#region src/babel.d.ts
5
+ declare function export_default(): {
6
+ visitor: {
7
+ Program(this: Node, path: _babel_traverse0.NodePath<Program>, state: Node): void;
8
+ };
9
+ };
10
+ //#endregion
11
+ export { export_default as default };
12
+ //# sourceMappingURL=babel.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.d.mts","names":[],"sources":["../src/babel.ts"],"mappings":";;;;iBAG2C,cAAA,CAAA"}
package/babel.mjs ADDED
@@ -0,0 +1,159 @@
1
+ import { a as gatherTgpuAliases, c as operators, i as embedJSON, l as performExpressionNaming, n as defaultOptions, o as getFunctionName, s as isShellImplementationCall, t as createFilterForId, u as useGpuDirective } from "./filter-6T-5w4kG.mjs";
2
+ import defu from "defu";
3
+ import { transpileFn } from "tinyest-for-wgsl";
4
+ import { FORMAT_VERSION } from "tinyest";
5
+ import * as Babel from "@babel/standalone";
6
+
7
+ //#region src/babel.ts
8
+ const template = Babel.packages.template;
9
+ const types = Babel.packages.types;
10
+ function containsUseGpuDirective(node) {
11
+ var _node$body$directives, _node$body;
12
+ return ("directives" in node.body ? (_node$body$directives = (_node$body = node.body) === null || _node$body === void 0 ? void 0 : _node$body.directives) !== null && _node$body$directives !== void 0 ? _node$body$directives : [] : []).map((directive) => directive.value.value).includes(useGpuDirective);
13
+ }
14
+ function i(identifier) {
15
+ return types.identifier(identifier);
16
+ }
17
+ const fnNodeToOriginalMap = /* @__PURE__ */ new WeakMap();
18
+ function functionToTranspiled(node, parent) {
19
+ var _fnNodeToOriginalMap$;
20
+ const { params, body, externalNames } = transpileFn((_fnNodeToOriginalMap$ = fnNodeToOriginalMap.get(node)) !== null && _fnNodeToOriginalMap$ !== void 0 ? _fnNodeToOriginalMap$ : node);
21
+ const maybeName = getFunctionName(node, parent);
22
+ const metadata = types.objectExpression([
23
+ types.objectProperty(i("v"), types.numericLiteral(FORMAT_VERSION)),
24
+ types.objectProperty(i("name"), maybeName ? types.stringLiteral(maybeName) : types.buildUndefinedNode()),
25
+ types.objectProperty(i("ast"), template.expression`${embedJSON({
26
+ params,
27
+ body,
28
+ externalNames
29
+ })}`()),
30
+ types.objectProperty(i("externals"), types.arrowFunctionExpression([], types.blockStatement([types.returnStatement(types.objectExpression(externalNames.map((name) => types.objectProperty(i(name), i(name), false, name !== "this"))))])))
31
+ ]);
32
+ return types.callExpression(types.arrowFunctionExpression([i("$")], types.logicalExpression("&&", types.callExpression(types.memberExpression(types.assignmentExpression("??=", types.memberExpression(i("globalThis"), i("__TYPEGPU_META__")), types.newExpression(i("WeakMap"), [])), i("set")), [types.assignmentExpression("=", types.memberExpression(i("$"), i("f")), node), metadata]), types.memberExpression(i("$"), i("f")))), [types.objectExpression([])]);
33
+ }
34
+ function wrapInAutoName(node, name) {
35
+ return types.callExpression(template.expression("globalThis.__TYPEGPU_AUTONAME__ ?? (a => a)", { placeholderPattern: false })(), [node, types.stringLiteral(name)]);
36
+ }
37
+ function functionVisitor(ctx) {
38
+ let inUseGpuScope = false;
39
+ return {
40
+ VariableDeclarator(path) {
41
+ performExpressionNaming(ctx, path.node, (node, name) => {
42
+ path.get("init").replaceWith(wrapInAutoName(node, name));
43
+ });
44
+ },
45
+ AssignmentExpression(path) {
46
+ if (inUseGpuScope) {
47
+ const runtimeFn = operators[path.node.operator];
48
+ if (runtimeFn) path.replaceWith(types.assignmentExpression("=", path.node.left, types.callExpression(types.identifier(runtimeFn), [path.node.left, path.node.right])));
49
+ }
50
+ performExpressionNaming(ctx, path.node, (node, name) => {
51
+ path.get("right").replaceWith(wrapInAutoName(node, name));
52
+ });
53
+ },
54
+ ObjectProperty(path) {
55
+ performExpressionNaming(ctx, path.node, (node, name) => {
56
+ path.get("value").replaceWith(wrapInAutoName(node, name));
57
+ });
58
+ },
59
+ ClassProperty(path) {
60
+ performExpressionNaming(ctx, path.node, (node, name) => {
61
+ path.get("value").replaceWith(wrapInAutoName(node, name));
62
+ });
63
+ },
64
+ ImportDeclaration(path) {
65
+ gatherTgpuAliases(path.node, ctx);
66
+ },
67
+ BinaryExpression: { exit(path) {
68
+ if (!inUseGpuScope) return;
69
+ const runtimeFn = operators[path.node.operator];
70
+ if (runtimeFn) path.replaceWith(types.callExpression(types.identifier(runtimeFn), [path.node.left, path.node.right]));
71
+ } },
72
+ ArrowFunctionExpression: {
73
+ enter(path) {
74
+ if (containsUseGpuDirective(path.node)) {
75
+ fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
76
+ if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
77
+ inUseGpuScope = true;
78
+ }
79
+ },
80
+ exit(path) {
81
+ const node = path.node;
82
+ if (containsUseGpuDirective(node)) {
83
+ inUseGpuScope = false;
84
+ const parent = path.parentPath.node;
85
+ path.replaceWith(functionToTranspiled(node, parent));
86
+ path.skip();
87
+ }
88
+ }
89
+ },
90
+ FunctionExpression: {
91
+ enter(path) {
92
+ if (containsUseGpuDirective(path.node)) {
93
+ fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
94
+ if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
95
+ inUseGpuScope = true;
96
+ }
97
+ },
98
+ exit(path) {
99
+ const node = path.node;
100
+ if (containsUseGpuDirective(node)) {
101
+ inUseGpuScope = false;
102
+ const parent = path.parentPath.node;
103
+ path.replaceWith(functionToTranspiled(node, parent));
104
+ path.skip();
105
+ }
106
+ }
107
+ },
108
+ FunctionDeclaration: {
109
+ enter(path) {
110
+ if (containsUseGpuDirective(path.node)) {
111
+ fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));
112
+ if (inUseGpuScope) throw new Error(`Nesting 'use gpu' functions is not allowed`);
113
+ inUseGpuScope = true;
114
+ }
115
+ },
116
+ exit(path) {
117
+ var _fnNodeToOriginalMap$2;
118
+ const node = (_fnNodeToOriginalMap$2 = fnNodeToOriginalMap.get(path.node)) !== null && _fnNodeToOriginalMap$2 !== void 0 ? _fnNodeToOriginalMap$2 : path.node;
119
+ if (containsUseGpuDirective(node)) {
120
+ inUseGpuScope = false;
121
+ if (!node.id) return;
122
+ const parent = path.parentPath.node;
123
+ const expression = types.functionExpression(node.id, node.params, node.body);
124
+ path.replaceWith(types.variableDeclaration("const", [types.variableDeclarator(node.id, functionToTranspiled(expression, parent))]));
125
+ path.skip();
126
+ }
127
+ }
128
+ },
129
+ CallExpression: { exit(path) {
130
+ const node = path.node;
131
+ if (isShellImplementationCall(node, ctx)) {
132
+ const implementation = node.arguments[0];
133
+ if (implementation && (implementation.type === "FunctionExpression" || implementation.type === "ArrowFunctionExpression")) {
134
+ const transpiled = functionToTranspiled(implementation, null);
135
+ path.replaceWith(types.callExpression(node.callee, [transpiled]));
136
+ path.skip();
137
+ }
138
+ }
139
+ } }
140
+ };
141
+ }
142
+ function babel_default() {
143
+ return { visitor: { Program(path, state) {
144
+ const options = defu(state.opts, defaultOptions);
145
+ const id = state.filename;
146
+ const filter = createFilterForId(options);
147
+ if (id && filter && !(filter === null || filter === void 0 ? void 0 : filter(id))) return;
148
+ const ctx = {
149
+ tgpuAliases: new Set(options.forceTgpuAlias ? [options.forceTgpuAlias] : []),
150
+ fileId: id,
151
+ autoNamingEnabled: options.autoNamingEnabled
152
+ };
153
+ path.traverse(functionVisitor(ctx));
154
+ } } };
155
+ }
156
+
157
+ //#endregion
158
+ export { babel_default as default };
159
+ //# sourceMappingURL=babel.mjs.map
package/babel.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel.mjs","names":[],"sources":["../src/babel.ts"],"sourcesContent":["import * as Babel from '@babel/standalone';\nimport type TemplateGenerator from '@babel/template';\nimport type { TraverseOptions } from '@babel/traverse';\nimport type * as babel from '@babel/types';\nimport defu from 'defu';\nimport { FORMAT_VERSION } from 'tinyest';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n defaultOptions,\n embedJSON,\n gatherTgpuAliases,\n getFunctionName,\n isShellImplementationCall,\n operators,\n type Options,\n performExpressionNaming,\n useGpuDirective,\n} from './common.ts';\nimport { createFilterForId } from './filter.ts';\n\n// NOTE: @babel/standalone does expose internal packages, as specified in the docs, but the\n// typing for @babel/standalone does not expose them.\nconst template = (\n Babel as unknown as { packages: { template: typeof TemplateGenerator } }\n).packages.template;\nconst types = (Babel as unknown as { packages: { types: typeof babel } })\n .packages.types;\n\nfunction containsUseGpuDirective(\n node:\n | babel.FunctionDeclaration\n | babel.FunctionExpression\n | babel.ArrowFunctionExpression,\n): boolean {\n return ((\n 'directives' in node.body ? (node.body?.directives ?? []) : []\n )\n .map((directive) => directive.value.value))\n .includes(useGpuDirective);\n}\n\nfunction i(identifier: string): babel.Identifier {\n return types.identifier(identifier);\n}\n\nconst fnNodeToOriginalMap = new WeakMap<\n | babel.FunctionDeclaration\n | babel.FunctionExpression\n | babel.ArrowFunctionExpression,\n | babel.FunctionDeclaration\n | babel.FunctionExpression\n | babel.ArrowFunctionExpression\n>();\n\nfunction functionToTranspiled(\n node: babel.ArrowFunctionExpression | babel.FunctionExpression,\n parent: babel.Node | null,\n): babel.CallExpression {\n const { params, body, externalNames } = transpileFn(\n fnNodeToOriginalMap.get(node) ?? node,\n );\n const maybeName = getFunctionName(node, parent);\n\n const metadata = types.objectExpression([\n types.objectProperty(\n i('v'),\n types.numericLiteral(FORMAT_VERSION),\n ),\n types.objectProperty(\n i('name'),\n maybeName ? types.stringLiteral(maybeName) : types.buildUndefinedNode(),\n ),\n types.objectProperty(\n i('ast'),\n template.expression`${embedJSON({ params, body, externalNames })}`(),\n ),\n types.objectProperty(\n i('externals'),\n types.arrowFunctionExpression(\n [],\n types.blockStatement([\n types.returnStatement(\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(\n i(name),\n i(name),\n false,\n /* shorthand */ name !== 'this',\n )\n ),\n ),\n ),\n ]),\n ),\n ),\n ]);\n\n return types.callExpression(\n types.arrowFunctionExpression(\n [i('$')],\n types.logicalExpression(\n '&&',\n types.callExpression(\n types.memberExpression(\n types.assignmentExpression(\n '??=',\n types.memberExpression(i('globalThis'), i('__TYPEGPU_META__')),\n types.newExpression(i('WeakMap'), []),\n ),\n i('set'),\n ),\n [\n types.assignmentExpression(\n '=',\n types.memberExpression(i('$'), i('f')),\n node,\n ),\n metadata,\n ],\n ),\n types.memberExpression(i('$'), i('f')),\n ),\n ),\n [types.objectExpression([])],\n );\n}\n\nfunction wrapInAutoName(\n node: babel.Expression,\n name: string,\n) {\n return types.callExpression(\n template.expression('globalThis.__TYPEGPU_AUTONAME__ ?? (a => a)', {\n placeholderPattern: false,\n })(),\n [node, types.stringLiteral(name)],\n );\n}\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n let inUseGpuScope = false;\n\n return {\n VariableDeclarator(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('init').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n AssignmentExpression(path) {\n if (inUseGpuScope) {\n const runtimeFn =\n operators[path.node.operator as keyof typeof operators];\n\n if (runtimeFn) {\n path.replaceWith(\n types.assignmentExpression(\n '=',\n path.node.left,\n types.callExpression(types.identifier(runtimeFn), [\n path.node.left as babel.Expression,\n path.node.right,\n ]),\n ),\n );\n }\n }\n\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('right').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n ObjectProperty(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('value').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n ClassProperty(path) {\n performExpressionNaming(ctx, path.node, (node, name) => {\n path.get('value').replaceWith(wrapInAutoName(node, name));\n });\n },\n\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n BinaryExpression: {\n exit(path) {\n if (!inUseGpuScope) {\n return;\n }\n\n const runtimeFn =\n operators[path.node.operator as keyof typeof operators];\n\n if (runtimeFn) {\n path.replaceWith(\n types.callExpression(types.identifier(runtimeFn), [\n path.node.left as babel.Expression,\n path.node.right,\n ]),\n );\n }\n },\n },\n\n ArrowFunctionExpression: {\n enter(path) {\n if (containsUseGpuDirective(path.node)) {\n fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));\n if (inUseGpuScope) {\n throw new Error(`Nesting 'use gpu' functions is not allowed`);\n }\n inUseGpuScope = true;\n }\n },\n exit(path) {\n const node = path.node;\n if (containsUseGpuDirective(node)) {\n inUseGpuScope = false;\n const parent = path.parentPath.node;\n path.replaceWith(functionToTranspiled(node, parent));\n path.skip();\n }\n },\n },\n\n FunctionExpression: {\n enter(path) {\n if (containsUseGpuDirective(path.node)) {\n fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));\n if (inUseGpuScope) {\n throw new Error(`Nesting 'use gpu' functions is not allowed`);\n }\n inUseGpuScope = true;\n }\n },\n exit(path) {\n const node = path.node;\n if (containsUseGpuDirective(node)) {\n inUseGpuScope = false;\n const parent = path.parentPath.node;\n path.replaceWith(functionToTranspiled(node, parent));\n path.skip();\n }\n },\n },\n\n FunctionDeclaration: {\n enter(path) {\n if (containsUseGpuDirective(path.node)) {\n fnNodeToOriginalMap.set(path.node, types.cloneNode(path.node, true));\n if (inUseGpuScope) {\n throw new Error(`Nesting 'use gpu' functions is not allowed`);\n }\n inUseGpuScope = true;\n }\n },\n exit(path) {\n const node = (fnNodeToOriginalMap.get(path.node) ??\n path.node) as babel.FunctionDeclaration;\n if (containsUseGpuDirective(node)) {\n inUseGpuScope = false;\n\n if (!node.id) {\n return;\n }\n\n const parent = path.parentPath.node;\n const expression = types.functionExpression(\n node.id,\n node.params,\n node.body,\n );\n\n path.replaceWith(\n types.variableDeclaration('const', [\n types.variableDeclarator(\n node.id,\n functionToTranspiled(expression, parent),\n ),\n ]),\n );\n path.skip();\n }\n },\n },\n\n CallExpression: {\n exit(path) {\n const node = path.node;\n\n if (isShellImplementationCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const transpiled = functionToTranspiled(\n implementation,\n null,\n );\n\n path.replaceWith(\n types.callExpression(node.callee, [\n transpiled,\n ]),\n );\n\n path.skip();\n }\n }\n },\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // oxlint-disable-next-line typescript/no-explicit-any <oh babel babel...>\n const options = defu((state as any).opts as Options, defaultOptions);\n // oxlint-disable-next-line typescript/no-explicit-any <oh babel babel...>\n const id: string | undefined = (state as any).filename;\n\n const filter = createFilterForId(options);\n if (id && filter && !filter?.(id)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set<string>(\n options.forceTgpuAlias ? [options.forceTgpuAlias] : [],\n ),\n fileId: id,\n autoNamingEnabled: options.autoNamingEnabled,\n };\n\n path.traverse(functionVisitor(ctx));\n },\n } satisfies TraverseOptions,\n };\n}\n"],"mappings":";;;;;;;AAuBA,MAAM,WACJ,MACA,SAAS;AACX,MAAM,QAAS,MACZ,SAAS;AAEZ,SAAS,wBACP,MAIS;;AACT,SACE,gBAAgB,KAAK,8CAAQ,KAAK,8DAAM,mFAAc,EAAE,GAAI,EAAE,EAE7D,KAAK,cAAc,UAAU,MAAM,MAAM,CACzC,SAAS,gBAAgB;;AAG9B,SAAS,EAAE,YAAsC;AAC/C,QAAO,MAAM,WAAW,WAAW;;AAGrC,MAAM,sCAAsB,IAAI,SAO7B;AAEH,SAAS,qBACP,MACA,QACsB;;CACtB,MAAM,EAAE,QAAQ,MAAM,kBAAkB,qCACtC,oBAAoB,IAAI,KAAK,yEAAI,KAClC;CACD,MAAM,YAAY,gBAAgB,MAAM,OAAO;CAE/C,MAAM,WAAW,MAAM,iBAAiB;EACtC,MAAM,eACJ,EAAE,IAAI,EACN,MAAM,eAAe,eAAe,CACrC;EACD,MAAM,eACJ,EAAE,OAAO,EACT,YAAY,MAAM,cAAc,UAAU,GAAG,MAAM,oBAAoB,CACxE;EACD,MAAM,eACJ,EAAE,MAAM,EACR,SAAS,UAAU,GAAG,UAAU;GAAE;GAAQ;GAAM;GAAe,CAAC,IAAI,CACrE;EACD,MAAM,eACJ,EAAE,YAAY,EACd,MAAM,wBACJ,EAAE,EACF,MAAM,eAAe,CACnB,MAAM,gBACJ,MAAM,iBACJ,cAAc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AC,OAAS,GAAG,EAC/B;EAGF,MAAM,MAAe;GACnB,aAAa,IAAI,IACf,QAAQ,iBAAiB,CAAC,QAAQ,eAAe,GAAG,EAAE,CACvD;GACD,QAAQ;GACR,mBAAmB,QAAQ;GAC5B;AAED,OAAK,SAAS,gBAAgB,IAAI,CAAC;IAEtC,EACF"}
package/bun.cjs CHANGED
@@ -1,2 +1,39 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkNQODVO3Lcjs = require('./chunk-NQODVO3L.cjs');require('./chunk-DEVVEJF4.cjs');exports.default = _chunkNQODVO3Lcjs.a;
2
- //# sourceMappingURL=bun.cjs.map
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_filter = require('./filter-CKmD4HRk.cjs');
3
+ const require_babel = require('./babel.cjs');
4
+ let defu = require("defu");
5
+ defu = require_filter.__toESM(defu);
6
+ let _babel_standalone = require("@babel/standalone");
7
+ _babel_standalone = require_filter.__toESM(_babel_standalone);
8
+
9
+ //#region src/bun.ts
10
+ var bun_default = (rawOptions) => {
11
+ const options = (0, defu.default)(rawOptions, require_filter.defaultOptions);
12
+ const include = options.include;
13
+ if (!(include instanceof RegExp)) throw new Error(`Unsupported 'include' options in Bun plugin. Please provide a single regular expression`);
14
+ if (options.exclude) throw new Error(`Unsupported 'exclude' option in Bun plugin`);
15
+ return {
16
+ name: "unplugin-typegpu",
17
+ setup(build) {
18
+ build.onLoad({ filter: include }, async (args) => {
19
+ const text = await Bun.file(args.path).text();
20
+ if (require_filter.earlyPruneRegex.every((pattern) => !pattern.test(text))) return {
21
+ contents: text,
22
+ loader: args.loader
23
+ };
24
+ const result = _babel_standalone.transform(text, {
25
+ presets: [["typescript", { allowDeclareFields: true }]],
26
+ filename: args.path,
27
+ plugins: [require_babel.default]
28
+ }).code;
29
+ return {
30
+ contents: result !== null && result !== void 0 ? result : text,
31
+ loader: args.loader
32
+ };
33
+ });
34
+ }
35
+ };
36
+ };
37
+
38
+ //#endregion
39
+ exports.default = bun_default;
package/bun.d.cts CHANGED
@@ -1,3 +1,6 @@
1
- import 'bun';
2
- export { _ as default } from './bun-Dq3TUCfa.cjs';
3
- import 'unplugin';
1
+ import { t as Options } from "./common-Dpl8jppn.cjs";
2
+
3
+ //#region src/bun.d.ts
4
+ declare const _default: (rawOptions: Options) => BunPlugin;
5
+ export = _default;
6
+ //# sourceMappingURL=bun.d.cts.map
package/bun.d.cts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.d.cts","names":[],"sources":["../src/bun.ts"],"mappings":";;;cAG4E,QAAA,GAG5D,UAAA,EAAY,OAAA,KAAU,SAAA;AAAA"}
package/bun.d.mts ADDED
@@ -0,0 +1,7 @@
1
+ import { t as Options } from "./common-CRPQ2KE6.mjs";
2
+
3
+ //#region src/bun.d.ts
4
+ declare const _default: (rawOptions: Options) => BunPlugin;
5
+ //#endregion
6
+ export { _default as default };
7
+ //# sourceMappingURL=bun.d.mts.map
package/bun.d.mts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.d.mts","names":[],"sources":["../src/bun.ts"],"mappings":";;;cAG4E,QAAA,GAG5D,UAAA,EAAY,OAAA,KAAU,SAAA"}
package/bun.mjs ADDED
@@ -0,0 +1,37 @@
1
+ import { n as defaultOptions, r as earlyPruneRegex } from "./filter-6T-5w4kG.mjs";
2
+ import babel_default from "./babel.mjs";
3
+ import defu from "defu";
4
+ import * as Babel from "@babel/standalone";
5
+
6
+ //#region src/bun.ts
7
+ var bun_default = (rawOptions) => {
8
+ const options = defu(rawOptions, defaultOptions);
9
+ const include = options.include;
10
+ if (!(include instanceof RegExp)) throw new Error(`Unsupported 'include' options in Bun plugin. Please provide a single regular expression`);
11
+ if (options.exclude) throw new Error(`Unsupported 'exclude' option in Bun plugin`);
12
+ return {
13
+ name: "unplugin-typegpu",
14
+ setup(build) {
15
+ build.onLoad({ filter: include }, async (args) => {
16
+ const text = await Bun.file(args.path).text();
17
+ if (earlyPruneRegex.every((pattern) => !pattern.test(text))) return {
18
+ contents: text,
19
+ loader: args.loader
20
+ };
21
+ const result = Babel.transform(text, {
22
+ presets: [["typescript", { allowDeclareFields: true }]],
23
+ filename: args.path,
24
+ plugins: [babel_default]
25
+ }).code;
26
+ return {
27
+ contents: result !== null && result !== void 0 ? result : text,
28
+ loader: args.loader
29
+ };
30
+ });
31
+ }
32
+ };
33
+ };
34
+
35
+ //#endregion
36
+ export { bun_default as default };
37
+ //# sourceMappingURL=bun.mjs.map
package/bun.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.mjs","names":["babelPlugin"],"sources":["../src/bun.ts"],"sourcesContent":["import type { BunPlugin } from 'bun';\nimport * as Babel from '@babel/standalone';\nimport defu from 'defu';\nimport { defaultOptions, earlyPruneRegex, type Options } from './common.ts';\nimport babelPlugin from './babel.ts';\n\nexport default (rawOptions: Options): BunPlugin => {\n const options = defu(rawOptions, defaultOptions);\n const include = options.include;\n if (!(include instanceof RegExp)) {\n throw new Error(\n `Unsupported 'include' options in Bun plugin. Please provide a single regular expression`,\n );\n }\n if (options.exclude) {\n throw new Error(`Unsupported 'exclude' option in Bun plugin`);\n }\n\n return {\n name: 'unplugin-typegpu',\n setup(build) {\n build.onLoad({ filter: include }, async (args) => {\n const text = await Bun.file(args.path).text();\n\n // Pruning early before more expensive operations\n if (earlyPruneRegex.every((pattern) => !pattern.test(text))) {\n return {\n contents: text,\n loader: args.loader,\n };\n }\n\n const result = Babel.transform(text, {\n presets: [['typescript', { allowDeclareFields: true }]],\n filename: args.path,\n plugins: [babelPlugin],\n }).code;\n\n return {\n contents: result ?? text,\n loader: args.loader,\n };\n });\n },\n };\n};\n"],"mappings":";;;;;;AAMA,mBAAgB,eAAmC;CACjD,MAAM,UAAU,KAAK,YAAY,eAAe;CAChD,MAAM,UAAU,QAAQ;AACxB,KAAI,EAAE,mBAAmB,QACvB,OAAM,IAAI,MACR,0FACD;AAEH,KAAI,QAAQ,QACV,OAAM,IAAI,MAAM,6CAA6C;AAG/D,QAAO;EACL,MAAM;EACN,MAAM,OAAO;AACX,SAAM,OAAO,EAAE,QAAQ,SAAS,EAAE,OAAO,SAAS;IAChD,MAAM,OAAO,MAAM,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM;AAG7C,QAAI,gBAAgB,OAAO,YAAY,CAAC,QAAQ,KAAK,KAAK,CAAC,CACzD,QAAO;KACL,UAAU;KACV,QAAQ,KAAK;KACd;IAGH,MAAM,SAAS,MAAM,UAAU,MAAM;KACnC,SAAS,CAAC,CAAC,cAAc,EAAE,oBAAoB,MAAM,CAAC,CAAC;KACvD,UAAU,KAAK;KACf,SAAS,CAACA,cAAY;KACvB,CAAC,CAAC;AAEH,WAAO;KACL,UAAU,gDAAU;KACpB,QAAQ,KAAK;KACd;KACD;;EAEL"}
@@ -0,0 +1,26 @@
1
+ import { FilterPattern } from "unplugin";
2
+
3
+ //#region src/common.d.ts
4
+ interface Options {
5
+ /** @default [/\.m?[jt]sx?$/] */
6
+ include?: FilterPattern;
7
+ /** @default undefined */
8
+ exclude?: FilterPattern;
9
+ /** @default undefined */
10
+ enforce?: 'post' | 'pre' | undefined;
11
+ /** @default undefined */
12
+ forceTgpuAlias?: string | undefined;
13
+ /** @default true */
14
+ autoNamingEnabled?: boolean | undefined;
15
+ /**
16
+ * Skipping files that don't contain "typegpu", "tgpu" or "use gpu".
17
+ * In case this early pruning hinders transformation, you
18
+ * can disable it.
19
+ *
20
+ * @default true
21
+ */
22
+ earlyPruning?: boolean | undefined;
23
+ }
24
+ //#endregion
25
+ export { Options as t };
26
+ //# sourceMappingURL=common-CRPQ2KE6.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-CRPQ2KE6.d.mts","names":[],"sources":["../src/common.ts"],"mappings":";;;UAciB,OAAA;EAcf;EAZA,OAAA,GAAU,aAAA;EAqBE;EAlBZ,OAAA,GAAU,aAAA;;EAGV,OAAA;;EAGA,cAAA;;EAGA,iBAAA;;;;;;;;EASA,YAAA;AAAA"}
@@ -0,0 +1,26 @@
1
+ import { FilterPattern } from "unplugin";
2
+
3
+ //#region src/common.d.ts
4
+ interface Options {
5
+ /** @default [/\.m?[jt]sx?$/] */
6
+ include?: FilterPattern;
7
+ /** @default undefined */
8
+ exclude?: FilterPattern;
9
+ /** @default undefined */
10
+ enforce?: 'post' | 'pre' | undefined;
11
+ /** @default undefined */
12
+ forceTgpuAlias?: string | undefined;
13
+ /** @default true */
14
+ autoNamingEnabled?: boolean | undefined;
15
+ /**
16
+ * Skipping files that don't contain "typegpu", "tgpu" or "use gpu".
17
+ * In case this early pruning hinders transformation, you
18
+ * can disable it.
19
+ *
20
+ * @default true
21
+ */
22
+ earlyPruning?: boolean | undefined;
23
+ }
24
+ //#endregion
25
+ export { Options as t };
26
+ //# sourceMappingURL=common-Dpl8jppn.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-Dpl8jppn.d.cts","names":[],"sources":["../src/common.ts"],"mappings":";;;UAciB,OAAA;EAcf;EAZA,OAAA,GAAU,aAAA;EAqBE;EAlBZ,OAAA,GAAU,aAAA;;EAGV,OAAA;;EAGA,cAAA;;EAGA,iBAAA;;;;;;;;EASA,YAAA;AAAA"}
package/esbuild.cjs CHANGED
@@ -1,2 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkLJXNN2RMcjs = require('./chunk-LJXNN2RM.cjs');require('./chunk-NQODVO3L.cjs');require('./chunk-DEVVEJF4.cjs');var l=_chunkLJXNN2RMcjs.h;exports.default = l;
2
- //# sourceMappingURL=esbuild.cjs.map
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_index = require('./index.cjs');
3
+
4
+ //#region src/esbuild.ts
5
+ var esbuild_default = require_index.esbuildPlugin;
6
+
7
+ //#endregion
8
+ exports.default = esbuild_default;
package/esbuild.d.cts CHANGED
@@ -1,14 +1,3 @@
1
- import { esbuildPlugin } from './index.cjs';
2
- import 'rollup';
3
- import 'vite';
4
- import 'unplugin';
5
- import './bun-Dq3TUCfa.cjs';
6
- import 'bun';
7
- import './babel.cjs';
8
- import '@babel/traverse';
9
- import '@babel/types';
10
- import 'magic-string-ast';
11
-
12
-
13
-
14
- export { esbuildPlugin as default };
1
+ import "./rollup-impl-DqC_d-_W.cjs";
2
+ import { esbuildPlugin } from "./index.cjs";
3
+ export = esbuildPlugin;
package/esbuild.d.mts ADDED
@@ -0,0 +1,4 @@
1
+ import "./common-CRPQ2KE6.mjs";
2
+ import "./rolldown-browser-JYqfNLQ8.mjs";
3
+ import { esbuildPlugin } from "./index.mjs";
4
+ export { esbuildPlugin as default };
package/esbuild.mjs ADDED
@@ -0,0 +1,8 @@
1
+ import { esbuildPlugin } from "./index.mjs";
2
+
3
+ //#region src/esbuild.ts
4
+ var esbuild_default = esbuildPlugin;
5
+
6
+ //#endregion
7
+ export { esbuild_default as default };
8
+ //# sourceMappingURL=esbuild.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild.mjs","names":[],"sources":["../src/esbuild.ts"],"sourcesContent":["import { esbuildPlugin } from './index.ts';\n\nexport default esbuildPlugin;\n"],"mappings":";;;AAEA,sBAAe"}
package/farm.cjs CHANGED
@@ -1,2 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkLJXNN2RMcjs = require('./chunk-LJXNN2RM.cjs');require('./chunk-NQODVO3L.cjs');require('./chunk-DEVVEJF4.cjs');var m=_chunkLJXNN2RMcjs.i;exports.default = m;
2
- //# sourceMappingURL=farm.cjs.map
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_index = require('./index.cjs');
3
+
4
+ //#region src/farm.ts
5
+ var farm_default = require_index.farmPlugin;
6
+
7
+ //#endregion
8
+ exports.default = farm_default;