unplugin-typegpu 0.9.0 → 0.10.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.
- package/_virtual/_rolldown/runtime.cjs +29 -0
- package/babel.cjs +163 -2
- package/babel.d.cts +7 -7
- package/babel.d.mts +11 -0
- package/babel.mjs +159 -0
- package/bun.cjs +40 -2
- package/bun.d.cts +5 -3
- package/bun.d.mts +6 -0
- package/bun.mjs +36 -0
- package/common.cjs +183 -0
- package/common.d.cts +25 -0
- package/common.d.mts +25 -0
- package/common.mjs +174 -0
- package/esbuild.cjs +8 -2
- package/esbuild.d.cts +2 -14
- package/esbuild.d.mts +2 -0
- package/esbuild.mjs +7 -0
- package/farm.cjs +8 -2
- package/farm.d.cts +2 -14
- package/farm.d.mts +2 -0
- package/farm.mjs +7 -0
- package/filter.cjs +63 -0
- package/filter.mjs +61 -0
- package/index.cjs +30 -2
- package/index.d.cts +12 -48
- package/index.d.mts +19 -0
- package/index.mjs +18 -0
- package/package.json +110 -66
- package/rolldown-browser.cjs +7 -0
- package/rolldown-browser.d.mts +1 -0
- package/rolldown-browser.mjs +7 -0
- package/rolldown.cjs +8 -2
- package/rolldown.d.cts +2 -14
- package/rolldown.d.mts +2 -0
- package/rolldown.mjs +7 -0
- package/rollup-impl.cjs +127 -0
- package/rollup-impl.d.cts +38 -0
- package/rollup-impl.d.mts +39 -0
- package/rollup-impl.mjs +125 -0
- package/rollup.cjs +8 -2
- package/rollup.d.cts +2 -14
- package/rollup.d.mts +2 -0
- package/rollup.mjs +7 -0
- package/rspack.cjs +8 -2
- package/rspack.d.cts +2 -14
- package/rspack.d.mts +2 -0
- package/rspack.mjs +7 -0
- package/vite.cjs +8 -2
- package/vite.d.cts +2 -14
- package/vite.d.mts +2 -0
- package/vite.mjs +7 -0
- package/webpack.cjs +8 -2
- package/webpack.d.cts +2 -14
- package/webpack.d.mts +2 -0
- package/webpack.mjs +7 -0
- package/babel.cjs.map +0 -1
- package/babel.d.ts +0 -10
- package/babel.js +0 -2
- package/babel.js.map +0 -1
- package/bun-Dq3TUCfa.d.cts +0 -27
- package/bun-Dq3TUCfa.d.ts +0 -27
- package/bun.cjs.map +0 -1
- package/bun.d.ts +0 -3
- package/bun.js +0 -2
- package/bun.js.map +0 -1
- package/chunk-DEVVEJF4.cjs +0 -2
- package/chunk-DEVVEJF4.cjs.map +0 -1
- package/chunk-EESBB3Y4.js +0 -2
- package/chunk-EESBB3Y4.js.map +0 -1
- package/chunk-LJXNN2RM.cjs +0 -7
- package/chunk-LJXNN2RM.cjs.map +0 -1
- package/chunk-NQODVO3L.cjs +0 -2
- package/chunk-NQODVO3L.cjs.map +0 -1
- package/chunk-RIZD7OMC.js +0 -7
- package/chunk-RIZD7OMC.js.map +0 -1
- package/chunk-V4Q4PLLO.js +0 -2
- package/chunk-V4Q4PLLO.js.map +0 -1
- package/esbuild.cjs.map +0 -1
- package/esbuild.d.ts +0 -14
- package/esbuild.js +0 -2
- package/esbuild.js.map +0 -1
- package/farm.cjs.map +0 -1
- package/farm.d.ts +0 -14
- package/farm.js +0 -2
- package/farm.js.map +0 -1
- package/index.cjs.map +0 -1
- package/index.d.ts +0 -54
- package/index.js +0 -2
- package/index.js.map +0 -1
- package/rolldown.cjs.map +0 -1
- package/rolldown.d.ts +0 -14
- package/rolldown.js +0 -2
- package/rolldown.js.map +0 -1
- package/rollup.cjs.map +0 -1
- package/rollup.d.ts +0 -14
- package/rollup.js +0 -2
- package/rollup.js.map +0 -1
- package/rspack.cjs.map +0 -1
- package/rspack.d.ts +0 -14
- package/rspack.js +0 -2
- package/rspack.js.map +0 -1
- package/vite.cjs.map +0 -1
- package/vite.d.ts +0 -14
- package/vite.js +0 -2
- package/vite.js.map +0 -1
- package/webpack.cjs.map +0 -1
- package/webpack.d.ts +0 -14
- package/webpack.js +0 -2
- package/webpack.js.map +0 -1
package/common.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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 };
|
package/common.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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 };
|
package/common.mjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
//#region src/common.ts
|
|
2
|
+
const defaultOptions = {
|
|
3
|
+
include: /\.m?[jt]sx?(?:\?.*)?$/,
|
|
4
|
+
autoNamingEnabled: true,
|
|
5
|
+
earlyPruning: true
|
|
6
|
+
};
|
|
7
|
+
function embedJSON(jsValue) {
|
|
8
|
+
return JSON.stringify(jsValue).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Checks if `node` is an alias for the 'tgpu' object, traditionally
|
|
12
|
+
* available via `import tgpu from 'typegpu'`.
|
|
13
|
+
*/
|
|
14
|
+
function isTgpu(ctx, node) {
|
|
15
|
+
let path = "";
|
|
16
|
+
let tail = node;
|
|
17
|
+
while (true) if (tail.type === "MemberExpression") {
|
|
18
|
+
if ((tail.property.type === "Literal" || tail.property.type === "StringLiteral") && tail.property.value === "~unstable") {
|
|
19
|
+
tail = tail.object;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (tail.property.type !== "Identifier") break;
|
|
23
|
+
path = path ? `${tail.property.name}.${path}` : tail.property.name;
|
|
24
|
+
tail = tail.object;
|
|
25
|
+
} else if (tail.type === "Identifier") {
|
|
26
|
+
path = path ? `${tail.name}.${path}` : tail.name;
|
|
27
|
+
break;
|
|
28
|
+
} else break;
|
|
29
|
+
return ctx.tgpuAliases.has(path);
|
|
30
|
+
}
|
|
31
|
+
function gatherTgpuAliases(node, ctx) {
|
|
32
|
+
if (node.source.value === "typegpu") {
|
|
33
|
+
for (const spec of node.specifiers) if (spec.type === "ImportDefaultSpecifier" || spec.type === "ImportSpecifier" && spec.imported.type === "Identifier" && spec.imported.name === "tgpu") ctx.tgpuAliases.add(spec.local.name);
|
|
34
|
+
else if (spec.type === "ImportNamespaceSpecifier") ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const fnShellFunctionNames = [
|
|
38
|
+
"fn",
|
|
39
|
+
"vertexFn",
|
|
40
|
+
"fragmentFn",
|
|
41
|
+
"computeFn"
|
|
42
|
+
];
|
|
43
|
+
function isShellImplementationCall(node, ctx) {
|
|
44
|
+
return node.callee.type === "CallExpression" && node.callee.callee.type === "MemberExpression" && node.callee.callee.property.type === "Identifier" && fnShellFunctionNames.includes(node.callee.callee.property.name) && node.arguments.length === 1 && isTgpu(ctx, node.callee.callee.object);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Extracts a name and expression from nodes that contain a label and an expression,
|
|
48
|
+
* such as VariableDeclarator or PropertyDefinition.
|
|
49
|
+
* Returns a tuple of [name, expression] if found, otherwise undefined.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* extractLabelledExpression(node`let name = tgpu.bindGroupLayout({});`)
|
|
53
|
+
* // ["name", node`tgpu.bindGroupLayout({})`]
|
|
54
|
+
*/
|
|
55
|
+
function extractLabelledExpression(node) {
|
|
56
|
+
if (node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.init) return [node.id.name, node.init];
|
|
57
|
+
else if (node.type === "AssignmentExpression") {
|
|
58
|
+
const maybeName = tryFindIdentifier(node.left);
|
|
59
|
+
if (maybeName) return [maybeName, node.right];
|
|
60
|
+
} else if ((node.type === "Property" || node.type === "ObjectProperty") && node.key.type === "Identifier") return [node.key.name, node.value];
|
|
61
|
+
else if ((node.type === "ClassProperty" || node.type === "PropertyDefinition") && node.value && node.key.type === "Identifier") return [node.key.name, node.value];
|
|
62
|
+
}
|
|
63
|
+
function getFunctionName(node, parent) {
|
|
64
|
+
var _extractLabelledExpre, _node$id;
|
|
65
|
+
const maybeName = parent ? (_extractLabelledExpre = extractLabelledExpression(parent)) === null || _extractLabelledExpre === void 0 ? void 0 : _extractLabelledExpre[0] : void 0;
|
|
66
|
+
return maybeName !== null && maybeName !== void 0 ? maybeName : node.type === "FunctionDeclaration" || node.type === "FunctionExpression" ? (_node$id = node.id) === null || _node$id === void 0 ? void 0 : _node$id.name : void 0;
|
|
67
|
+
}
|
|
68
|
+
const resourceConstructors = [
|
|
69
|
+
"bindGroupLayout",
|
|
70
|
+
"vertexLayout",
|
|
71
|
+
"privateVar",
|
|
72
|
+
"workgroupVar",
|
|
73
|
+
"const",
|
|
74
|
+
"slot",
|
|
75
|
+
"accessor",
|
|
76
|
+
"comptime",
|
|
77
|
+
...fnShellFunctionNames,
|
|
78
|
+
"createBuffer",
|
|
79
|
+
"createMutable",
|
|
80
|
+
"createReadonly",
|
|
81
|
+
"createUniform",
|
|
82
|
+
"createQuerySet",
|
|
83
|
+
"createPipeline",
|
|
84
|
+
"createComputePipeline",
|
|
85
|
+
"createGuardedComputePipeline",
|
|
86
|
+
"createRenderPipeline",
|
|
87
|
+
"createTexture",
|
|
88
|
+
"createSampler",
|
|
89
|
+
"createComparisonSampler",
|
|
90
|
+
"struct",
|
|
91
|
+
"unstruct",
|
|
92
|
+
"createView"
|
|
93
|
+
];
|
|
94
|
+
/**
|
|
95
|
+
* Checks if `node` should be wrapped in an autoname function.
|
|
96
|
+
* Since it is mostly for debugging and clean WGSL generation,
|
|
97
|
+
* some false positives and false negatives are admissible.
|
|
98
|
+
*/
|
|
99
|
+
function containsResourceConstructorCall(node, ctx) {
|
|
100
|
+
if (node.type === "CallExpression") {
|
|
101
|
+
if (isShellImplementationCall(node, ctx)) return true;
|
|
102
|
+
if (node.callee.type === "Identifier" && resourceConstructors.includes(node.callee.name)) return true;
|
|
103
|
+
if (node.callee.type === "MemberExpression") {
|
|
104
|
+
if (node.callee.property.type === "Identifier") {
|
|
105
|
+
if (resourceConstructors.includes(node.callee.property.name)) return true;
|
|
106
|
+
if (node.callee.property.name === "$name") return false;
|
|
107
|
+
}
|
|
108
|
+
return containsResourceConstructorCall(node.callee.object, ctx);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (node.type === "TaggedTemplateExpression") return containsResourceConstructorCall(node.tag, ctx);
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Tries to find an identifier in a node.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* // syntax is simplified, imagine the arguments are appropriate nodes instead
|
|
119
|
+
* tryFindIdentifier('myBuffer'); // 'myBuffer'
|
|
120
|
+
* tryFindIdentifier('buffers.myBuffer'); // 'myBuffer'
|
|
121
|
+
* tryFindIdentifier('this.myBuffer'); // 'myBuffer'
|
|
122
|
+
* tryFindIdentifier('[a, b]'); // undefined
|
|
123
|
+
*/
|
|
124
|
+
function tryFindIdentifier(node) {
|
|
125
|
+
if (node.type === "Identifier") return node.name;
|
|
126
|
+
if (node.type === "PrivateName") return tryFindIdentifier(node.id);
|
|
127
|
+
if (node.type === "PrivateIdentifier") return node.name;
|
|
128
|
+
if (node.type === "MemberExpression") return tryFindIdentifier(node.property);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Checks if `node` contains a label and a tgpu expression that could be named.
|
|
132
|
+
* If so, it calls the provided callback. Nodes selected for naming include:
|
|
133
|
+
*
|
|
134
|
+
* `let name = tgpu.bindGroupLayout({});` (VariableDeclarator)
|
|
135
|
+
*
|
|
136
|
+
* `name = tgpu.bindGroupLayout({});` (AssignmentExpression)
|
|
137
|
+
*
|
|
138
|
+
* `property: tgpu.bindGroupLayout({})` (Property/ObjectProperty)
|
|
139
|
+
*
|
|
140
|
+
* Since it is mostly for debugging and clean WGSL generation,
|
|
141
|
+
* some false positives and false negatives are admissible.
|
|
142
|
+
*
|
|
143
|
+
* This function is NOT used for auto-naming shell-less functions.
|
|
144
|
+
* Those are handled separately.
|
|
145
|
+
*
|
|
146
|
+
* @privateRemarks
|
|
147
|
+
* When adding new checks, you need to call this method in the corresponding node in Babel.
|
|
148
|
+
*/
|
|
149
|
+
function performExpressionNaming(ctx, node, namingCallback) {
|
|
150
|
+
if (!ctx.autoNamingEnabled) return;
|
|
151
|
+
const labelledExpression = extractLabelledExpression(node);
|
|
152
|
+
if (labelledExpression) {
|
|
153
|
+
const [label, expression] = labelledExpression;
|
|
154
|
+
if (containsResourceConstructorCall(expression, ctx)) namingCallback(expression, label);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const useGpuDirective = "use gpu";
|
|
158
|
+
/** Regular expressions used for early pruning (to avoid unnecessary parsing, which is expensive) */
|
|
159
|
+
const earlyPruneRegex = [/["']use gpu["']/, /t(ype)?gpu/];
|
|
160
|
+
const operators = {
|
|
161
|
+
"+": "__tsover_add",
|
|
162
|
+
"-": "__tsover_sub",
|
|
163
|
+
"*": "__tsover_mul",
|
|
164
|
+
"/": "__tsover_div",
|
|
165
|
+
"%": "__tsover_mod",
|
|
166
|
+
"+=": "__tsover_add",
|
|
167
|
+
"-=": "__tsover_sub",
|
|
168
|
+
"*=": "__tsover_mul",
|
|
169
|
+
"/=": "__tsover_div",
|
|
170
|
+
"%=": "__tsover_mod"
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
export { defaultOptions, earlyPruneRegex, embedJSON, gatherTgpuAliases, getFunctionName, isShellImplementationCall, operators, performExpressionNaming, useGpuDirective };
|
package/esbuild.cjs
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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,2 @@
|
|
|
1
|
-
import { esbuildPlugin } from
|
|
2
|
-
|
|
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 { esbuildPlugin } from "./index.cjs";
|
|
2
|
+
export = esbuildPlugin;
|
package/esbuild.d.mts
ADDED
package/esbuild.mjs
ADDED
package/farm.cjs
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
package/farm.d.cts
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
import { farmPlugin } from
|
|
2
|
-
|
|
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 { farmPlugin as default };
|
|
1
|
+
import { farmPlugin } from "./index.cjs";
|
|
2
|
+
export = farmPlugin;
|
package/farm.d.mts
ADDED
package/farm.mjs
ADDED
package/filter.cjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let pathe = require("pathe");
|
|
3
|
+
let picomatch = require("picomatch");
|
|
4
|
+
picomatch = require_runtime.__toESM(picomatch);
|
|
5
|
+
|
|
6
|
+
//#region src/filter.ts
|
|
7
|
+
function toArray(array) {
|
|
8
|
+
const result = array || [];
|
|
9
|
+
if (Array.isArray(result)) return result;
|
|
10
|
+
return [result];
|
|
11
|
+
}
|
|
12
|
+
const BACKSLASH_REGEX = /\\/g;
|
|
13
|
+
function normalize(path) {
|
|
14
|
+
return path.replace(BACKSLASH_REGEX, "/");
|
|
15
|
+
}
|
|
16
|
+
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
|
17
|
+
function isAbsolute(path) {
|
|
18
|
+
return ABSOLUTE_PATH_REGEX.test(path);
|
|
19
|
+
}
|
|
20
|
+
function getMatcherString(glob, cwd) {
|
|
21
|
+
if (glob.startsWith("**") || isAbsolute(glob)) return normalize(glob);
|
|
22
|
+
return normalize((0, pathe.resolve)(cwd, glob));
|
|
23
|
+
}
|
|
24
|
+
function patternToIdFilter(pattern) {
|
|
25
|
+
if (pattern instanceof RegExp) return (id) => {
|
|
26
|
+
const normalizedId = normalize(id);
|
|
27
|
+
const result = pattern.test(normalizedId);
|
|
28
|
+
pattern.lastIndex = 0;
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
31
|
+
const matcher = (0, picomatch.default)(getMatcherString(pattern, process.cwd()), { dot: true });
|
|
32
|
+
return (id) => {
|
|
33
|
+
return matcher(normalize(id));
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createFilter(exclude, include) {
|
|
37
|
+
if (!exclude && !include) return;
|
|
38
|
+
return (input) => {
|
|
39
|
+
if (exclude === null || exclude === void 0 ? void 0 : exclude.some((filter) => filter(input))) return false;
|
|
40
|
+
if (include === null || include === void 0 ? void 0 : include.some((filter) => filter(input))) return true;
|
|
41
|
+
return !(include && include.length > 0);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function normalizeFilter(filter) {
|
|
45
|
+
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
|
46
|
+
if (Array.isArray(filter)) return { include: filter };
|
|
47
|
+
return {
|
|
48
|
+
exclude: filter.exclude ? toArray(filter.exclude) : void 0,
|
|
49
|
+
include: filter.include ? toArray(filter.include) : void 0
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function createIdFilter(filter) {
|
|
53
|
+
if (!filter) return;
|
|
54
|
+
const { exclude, include } = normalizeFilter(filter);
|
|
55
|
+
return createFilter(exclude === null || exclude === void 0 ? void 0 : exclude.map(patternToIdFilter), include === null || include === void 0 ? void 0 : include.map(patternToIdFilter));
|
|
56
|
+
}
|
|
57
|
+
function createFilterForId(filter) {
|
|
58
|
+
const filterFunction = createIdFilter(filter);
|
|
59
|
+
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
exports.createFilterForId = createFilterForId;
|
package/filter.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { resolve } from "pathe";
|
|
2
|
+
import picomatch from "picomatch";
|
|
3
|
+
|
|
4
|
+
//#region src/filter.ts
|
|
5
|
+
function toArray(array) {
|
|
6
|
+
const result = array || [];
|
|
7
|
+
if (Array.isArray(result)) return result;
|
|
8
|
+
return [result];
|
|
9
|
+
}
|
|
10
|
+
const BACKSLASH_REGEX = /\\/g;
|
|
11
|
+
function normalize(path) {
|
|
12
|
+
return path.replace(BACKSLASH_REGEX, "/");
|
|
13
|
+
}
|
|
14
|
+
const ABSOLUTE_PATH_REGEX = /^(?:\/|(?:[A-Z]:)?[/\\|])/i;
|
|
15
|
+
function isAbsolute(path) {
|
|
16
|
+
return ABSOLUTE_PATH_REGEX.test(path);
|
|
17
|
+
}
|
|
18
|
+
function getMatcherString(glob, cwd) {
|
|
19
|
+
if (glob.startsWith("**") || isAbsolute(glob)) return normalize(glob);
|
|
20
|
+
return normalize(resolve(cwd, glob));
|
|
21
|
+
}
|
|
22
|
+
function patternToIdFilter(pattern) {
|
|
23
|
+
if (pattern instanceof RegExp) return (id) => {
|
|
24
|
+
const normalizedId = normalize(id);
|
|
25
|
+
const result = pattern.test(normalizedId);
|
|
26
|
+
pattern.lastIndex = 0;
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
const matcher = picomatch(getMatcherString(pattern, process.cwd()), { dot: true });
|
|
30
|
+
return (id) => {
|
|
31
|
+
return matcher(normalize(id));
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createFilter(exclude, include) {
|
|
35
|
+
if (!exclude && !include) return;
|
|
36
|
+
return (input) => {
|
|
37
|
+
if (exclude === null || exclude === void 0 ? void 0 : exclude.some((filter) => filter(input))) return false;
|
|
38
|
+
if (include === null || include === void 0 ? void 0 : include.some((filter) => filter(input))) return true;
|
|
39
|
+
return !(include && include.length > 0);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function normalizeFilter(filter) {
|
|
43
|
+
if (typeof filter === "string" || filter instanceof RegExp) return { include: [filter] };
|
|
44
|
+
if (Array.isArray(filter)) return { include: filter };
|
|
45
|
+
return {
|
|
46
|
+
exclude: filter.exclude ? toArray(filter.exclude) : void 0,
|
|
47
|
+
include: filter.include ? toArray(filter.include) : void 0
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function createIdFilter(filter) {
|
|
51
|
+
if (!filter) return;
|
|
52
|
+
const { exclude, include } = normalizeFilter(filter);
|
|
53
|
+
return createFilter(exclude === null || exclude === void 0 ? void 0 : exclude.map(patternToIdFilter), include === null || include === void 0 ? void 0 : include.map(patternToIdFilter));
|
|
54
|
+
}
|
|
55
|
+
function createFilterForId(filter) {
|
|
56
|
+
const filterFunction = createIdFilter(filter);
|
|
57
|
+
return filterFunction ? (id) => !!filterFunction(id) : void 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { createFilterForId };
|
package/index.cjs
CHANGED
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_rollup_impl = require('./rollup-impl.cjs');
|
|
4
|
+
const require_babel = require('./babel.cjs');
|
|
5
|
+
const require_bun = require('./bun.cjs');
|
|
6
|
+
const require_rolldown_browser = require('./rolldown-browser.cjs');
|
|
7
|
+
let unplugin = require("unplugin");
|
|
8
|
+
|
|
9
|
+
//#region src/index.ts
|
|
10
|
+
const typegpu = (0, unplugin.createUnplugin)(require_rollup_impl.rollUpImpl);
|
|
11
|
+
const vitePlugin = typegpu.vite;
|
|
12
|
+
const rollupPlugin = typegpu.rollup;
|
|
13
|
+
const rolldownPlugin = typegpu.rolldown;
|
|
14
|
+
const webpackPlugin = typegpu.webpack;
|
|
15
|
+
const rspackPlugin = typegpu.rspack;
|
|
16
|
+
const esbuildPlugin = typegpu.esbuild;
|
|
17
|
+
const farmPlugin = typegpu.farm;
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.babelPlugin = require_babel.default;
|
|
21
|
+
exports.bunPlugin = require_bun.default;
|
|
22
|
+
exports.default = typegpu;
|
|
23
|
+
exports.esbuildPlugin = esbuildPlugin;
|
|
24
|
+
exports.farmPlugin = farmPlugin;
|
|
25
|
+
exports.rolldownBrowserPlugin = require_rolldown_browser.default;
|
|
26
|
+
exports.rolldownPlugin = rolldownPlugin;
|
|
27
|
+
exports.rollupPlugin = rollupPlugin;
|
|
28
|
+
exports.rspackPlugin = rspackPlugin;
|
|
29
|
+
exports.vitePlugin = vitePlugin;
|
|
30
|
+
exports.webpackPlugin = webpackPlugin;
|
package/index.d.cts
CHANGED
|
@@ -1,54 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
export { default as babelPlugin } from './babel.cjs';
|
|
8
|
-
import * as magic_string_ast from 'magic-string-ast';
|
|
9
|
-
import 'bun';
|
|
10
|
-
import '@babel/traverse';
|
|
11
|
-
import '@babel/types';
|
|
12
|
-
|
|
13
|
-
declare const rollUpImpl: (rawOptions: Options) => {
|
|
14
|
-
name: "unplugin-typegpu";
|
|
15
|
-
enforce: "post" | "pre" | undefined;
|
|
16
|
-
transform: {
|
|
17
|
-
filter: {
|
|
18
|
-
id: Omit<Options, "include" | "autoNamingEnabled" | "earlyPruning"> & Omit<{
|
|
19
|
-
include: RegExp;
|
|
20
|
-
autoNamingEnabled: boolean;
|
|
21
|
-
earlyPruning: boolean;
|
|
22
|
-
}, "include" | "autoNamingEnabled" | "earlyPruning"> & {
|
|
23
|
-
include: string | RegExp | unplugin.StringOrRegExp[];
|
|
24
|
-
autoNamingEnabled: boolean;
|
|
25
|
-
earlyPruning: boolean;
|
|
26
|
-
};
|
|
27
|
-
code: RegExp[];
|
|
28
|
-
} | {
|
|
29
|
-
id: Omit<Options, "include" | "autoNamingEnabled" | "earlyPruning"> & Omit<{
|
|
30
|
-
include: RegExp;
|
|
31
|
-
autoNamingEnabled: boolean;
|
|
32
|
-
earlyPruning: boolean;
|
|
33
|
-
}, "include" | "autoNamingEnabled" | "earlyPruning"> & {
|
|
34
|
-
include: string | RegExp | unplugin.StringOrRegExp[];
|
|
35
|
-
autoNamingEnabled: boolean;
|
|
36
|
-
earlyPruning: boolean;
|
|
37
|
-
};
|
|
38
|
-
code?: never;
|
|
39
|
-
};
|
|
40
|
-
handler(this: UnpluginBuildContext & UnpluginContext, code: string, id: string): magic_string_ast.CodeTransform | undefined;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
1
|
+
import export_default from "./babel.cjs";
|
|
2
|
+
import { Options } from "./common.cjs";
|
|
3
|
+
import _default from "./bun.cjs";
|
|
4
|
+
import { Plugin } from "./node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/rollup.cjs";
|
|
5
|
+
import { rollUpImpl } from "./rollup-impl.cjs";
|
|
6
|
+
import * as unplugin from "unplugin";
|
|
43
7
|
|
|
8
|
+
//#region src/index.d.ts
|
|
44
9
|
declare const typegpu: unplugin.UnpluginInstance<Options, boolean>;
|
|
45
|
-
|
|
46
|
-
declare const
|
|
47
|
-
declare const rollupPlugin: (options: Options) => rollup.Plugin<any> | rollup.Plugin<any>[];
|
|
10
|
+
declare const vitePlugin: (options: Options) => unplugin.VitePlugin<any> | unplugin.VitePlugin<any>[];
|
|
11
|
+
declare const rollupPlugin: (options: Options) => Plugin<any> | Plugin<any>[];
|
|
48
12
|
declare const rolldownPlugin: (options: Options) => unplugin.RolldownPlugin<any> | unplugin.RolldownPlugin<any>[];
|
|
49
|
-
declare const webpackPlugin: (options: Options) => WebpackPluginInstance;
|
|
13
|
+
declare const webpackPlugin: (options: Options) => unplugin.WebpackPluginInstance;
|
|
50
14
|
declare const rspackPlugin: (options: Options) => RspackPluginInstance;
|
|
51
15
|
declare const esbuildPlugin: (options: Options) => unplugin.EsbuildPlugin;
|
|
52
16
|
declare const farmPlugin: (options: Options) => JsPlugin;
|
|
53
|
-
|
|
54
|
-
export { Options, typegpu as default, esbuildPlugin, farmPlugin, rollUpImpl as rolldownBrowserPlugin, rolldownPlugin, rollupPlugin, rspackPlugin, vitePlugin, webpackPlugin };
|
|
17
|
+
//#endregion
|
|
18
|
+
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.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import export_default from "./babel.mjs";
|
|
2
|
+
import { Options } from "./common.mjs";
|
|
3
|
+
import _default from "./bun.mjs";
|
|
4
|
+
import { Plugin } from "./node_modules/.pnpm/rollup@4.34.8/node_modules/rollup/dist/rollup.mjs";
|
|
5
|
+
import { rollUpImpl } from "./rollup-impl.mjs";
|
|
6
|
+
import "./rolldown-browser.mjs";
|
|
7
|
+
import * as unplugin from "unplugin";
|
|
8
|
+
|
|
9
|
+
//#region src/index.d.ts
|
|
10
|
+
declare const typegpu: unplugin.UnpluginInstance<Options, boolean>;
|
|
11
|
+
declare const vitePlugin: (options: Options) => unplugin.VitePlugin<any> | unplugin.VitePlugin<any>[];
|
|
12
|
+
declare const rollupPlugin: (options: Options) => Plugin<any> | Plugin<any>[];
|
|
13
|
+
declare const rolldownPlugin: (options: Options) => unplugin.RolldownPlugin<any> | unplugin.RolldownPlugin<any>[];
|
|
14
|
+
declare const webpackPlugin: (options: Options) => unplugin.WebpackPluginInstance;
|
|
15
|
+
declare const rspackPlugin: (options: Options) => RspackPluginInstance;
|
|
16
|
+
declare const esbuildPlugin: (options: Options) => unplugin.EsbuildPlugin;
|
|
17
|
+
declare const farmPlugin: (options: Options) => JsPlugin;
|
|
18
|
+
//#endregion
|
|
19
|
+
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { rollUpImpl } from "./rollup-impl.mjs";
|
|
2
|
+
import babel_default from "./babel.mjs";
|
|
3
|
+
import bun_default from "./bun.mjs";
|
|
4
|
+
import rolldown_browser_default from "./rolldown-browser.mjs";
|
|
5
|
+
import { createUnplugin } from "unplugin";
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const typegpu = createUnplugin(rollUpImpl);
|
|
9
|
+
const vitePlugin = typegpu.vite;
|
|
10
|
+
const rollupPlugin = typegpu.rollup;
|
|
11
|
+
const rolldownPlugin = typegpu.rolldown;
|
|
12
|
+
const webpackPlugin = typegpu.webpack;
|
|
13
|
+
const rspackPlugin = typegpu.rspack;
|
|
14
|
+
const esbuildPlugin = typegpu.esbuild;
|
|
15
|
+
const farmPlugin = typegpu.farm;
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { babel_default as babelPlugin, bun_default as bunPlugin, typegpu as default, esbuildPlugin, farmPlugin, rolldown_browser_default as rolldownBrowserPlugin, rolldownPlugin, rollupPlugin, rspackPlugin, vitePlugin, webpackPlugin };
|