unplugin-typegpu 0.1.0-alpha.4 → 0.1.0-alpha.5
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/babel.cjs.map +1 -1
- package/chunk-4LM3AL5S.cjs.map +1 -1
- package/chunk-EDH7U5CG.cjs.map +1 -1
- package/esbuild.cjs.map +1 -1
- package/farm.cjs.map +1 -1
- package/index.cjs.map +1 -1
- package/package.json +2 -2
- package/rolldown.cjs.map +1 -1
- package/rollup.cjs.map +1 -1
- package/rspack.cjs.map +1 -1
- package/vite.cjs.map +1 -1
- package/webpack.cjs.map +1 -1
package/babel.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/babel.cjs"],"names":[],"mappings":"AAAA,iIAAwC,sCAAqB","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/babel.cjs"}
|
package/chunk-4LM3AL5S.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/babel.ts","../src/common.ts"],"names":["embedJSON","jsValue","isTgpu","ctx","node","path","tail"],"mappings":"AAAA,wbAAuB,kDAIK,SCWZA,CAAAA,CAAUC,CAAAA,CAAkB,CAC1C,OAAO,IAAA,CAAK,SAAA,CAAUA,CAAO,CAAA,CAC1B,OAAA,CAAQ,SAAA,CAAW,SAAS,CAAA,CAC5B,OAAA,CAAQ,SAAA,CAAW,SAAS,CACjC,CAMA,SAASC,CAAAA,CAAOC,CAAAA,CAAcC,CAAAA,CAA2C,CACvE,IAAIC,CAAAA,CAAO,EAAA,CAEPC,CAAAA,CAAOF,CAAAA,CACX,GAAA,CAAA,CAAA,CAAA,CACE,EAAA,CAAIE,CAAAA,CAAK,IAAA,GAAS,kBAAA,CAAoB,CACpC,EAAA,CAAIA,CAAAA,CAAK,QAAA,CAAS,IAAA,GAAS,YAAA,CAEzB,KAAA,CAGFD,CAAAA,CAAOA,CAAAA,CAAO,CAAA,EAAA","file":"/Users/
|
|
1
|
+
{"version":3,"sources":["../src/babel.ts","../src/common.ts"],"names":["embedJSON","jsValue","isTgpu","ctx","node","path","tail"],"mappings":"AAAA,wbAAuB,kDAIK,SCWZA,CAAAA,CAAUC,CAAAA,CAAkB,CAC1C,OAAO,IAAA,CAAK,SAAA,CAAUA,CAAO,CAAA,CAC1B,OAAA,CAAQ,SAAA,CAAW,SAAS,CAAA,CAC5B,OAAA,CAAQ,SAAA,CAAW,SAAS,CACjC,CAMA,SAASC,CAAAA,CAAOC,CAAAA,CAAcC,CAAAA,CAA2C,CACvE,IAAIC,CAAAA,CAAO,EAAA,CAEPC,CAAAA,CAAOF,CAAAA,CACX,GAAA,CAAA,CAAA,CAAA,CACE,EAAA,CAAIE,CAAAA,CAAK,IAAA,GAAS,kBAAA,CAAoB,CACpC,EAAA,CAAIA,CAAAA,CAAK,QAAA,CAAS,IAAA,GAAS,YAAA,CAEzB,KAAA,CAGFD,CAAAA,CAAOA,CAAAA,CAAO,CAAA,EAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/chunk-4LM3AL5S.cjs","sourcesContent":["import * as Babel from '@babel/standalone';\nimport type TemplateGenerator from '@babel/template';\nimport type { TraverseOptions } from '@babel/traverse';\nimport type * as t from '@babel/types';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\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 t } }).packages\n .types;\n\nfunction functionVisitor(ctx: Context): TraverseOptions {\n return {\n ImportDeclaration(path) {\n gatherTgpuAliases(path.node, ctx);\n },\n\n CallExpression(path) {\n const node = path.node;\n\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n (implementation.type === 'FunctionExpression' ||\n implementation.type === 'ArrowFunctionExpression')\n ) {\n const { argNames, body, externalNames } = transpileFn(implementation);\n\n path.replaceWith(\n types.callExpression(node.callee, [\n types.callExpression(template.expression('tgpu.__assignAst')(), [\n implementation,\n template.expression`${embedJSON({ argNames, body, externalNames })}`(),\n types.objectExpression(\n externalNames.map((name) =>\n types.objectProperty(\n types.identifier(name),\n types.identifier(name),\n ),\n ),\n ),\n ]),\n ]),\n );\n\n path.skip();\n }\n }\n },\n };\n}\n\nexport default function () {\n return {\n visitor: {\n Program(path, state) {\n // @ts-ignore\n const code: string | undefined = state.file?.code;\n // @ts-ignore\n const options: TypegpuPluginOptions | undefined = state.opts;\n // @ts-ignore\n const id: string | undefined = state.filename;\n\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set(['tgpu']),\n };\n\n path.traverse(functionVisitor(ctx));\n },\n } satisfies TraverseOptions,\n };\n}\n","import type * as babel from '@babel/types';\nimport type * as acorn from 'acorn';\n\nexport type Context = {\n /**\n * How the `tgpu` object is used in code. Since it can be aliased, we\n * need to catch that and act accordingly.\n */\n tgpuAliases: Set<string>;\n};\n\nexport interface TypegpuPluginOptions {\n include?: 'all' | RegExp[];\n}\n\nexport function embedJSON(jsValue: unknown) {\n return JSON.stringify(jsValue)\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029');\n}\n\n/**\n * Checks if `node` is an alias for the 'tgpu' object, traditionally\n * available via `import tgpu from 'typegpu'`.\n */\nfunction isTgpu(ctx: Context, node: babel.Node | acorn.AnyNode): boolean {\n let path = '';\n\n let tail = node;\n while (true) {\n if (tail.type === 'MemberExpression') {\n if (tail.property.type !== 'Identifier') {\n // Not handling computed expressions.\n break;\n }\n\n path = path ? `${tail.property.name}.${path}` : tail.property.name;\n tail = tail.object;\n } else if (tail.type === 'Identifier') {\n path = path ? `${tail.name}.${path}` : tail.name;\n break;\n } else {\n break;\n }\n }\n\n return ctx.tgpuAliases.has(path);\n}\n\nconst typegpuImportRegex = /import.*from\\s*['\"]typegpu.*['\"]/g;\nconst typegpuDynamicImportRegex = /import\\s*\\(\\s*['\"]\\s*typegpu.*['\"]/g;\nconst typegpuRequireRegex = /require\\s*\\(\\s*['\"]\\s*typegpu.*['\"]\\s*\\)/g;\n\nexport function shouldSkipFile(\n options: TypegpuPluginOptions | undefined,\n id: string | undefined,\n code: string | undefined,\n) {\n if (code && !options?.include) {\n if (\n !typegpuImportRegex.test(code) &&\n !typegpuRequireRegex.test(code) &&\n !typegpuDynamicImportRegex.test(code)\n ) {\n // No imports to `typegpu` or its sub modules, exiting early.\n return true;\n }\n } else if (\n options?.include &&\n options.include !== 'all' &&\n (!id || !options.include.some((pattern) => pattern.test(id)))\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function gatherTgpuAliases(\n node: acorn.ImportDeclaration | babel.ImportDeclaration,\n ctx: Context,\n) {\n if (node.source.value === 'typegpu') {\n for (const spec of node.specifiers) {\n if (\n // The default export of 'typegpu' is the `tgpu` object.\n spec.type === 'ImportDefaultSpecifier' ||\n // Aliasing 'tgpu' while importing, e.g. import { tgpu as t } from 'typegpu';\n (spec.type === 'ImportSpecifier' &&\n spec.imported.type === 'Identifier' &&\n spec.imported.name === 'tgpu')\n ) {\n ctx.tgpuAliases.add(spec.local.name);\n } else if (spec.type === 'ImportNamespaceSpecifier') {\n // Importing everything, e.g. import * as t from 'typegpu';\n ctx.tgpuAliases.add(`${spec.local.name}.tgpu`);\n }\n }\n }\n}\n\nexport function isDoesCall(\n node: acorn.CallExpression | babel.CallExpression,\n ctx: Context,\n) {\n return (\n node.callee.type === 'MemberExpression' &&\n node.arguments.length === 1 &&\n node.callee.property.type === 'Identifier' &&\n ((node.callee.property.name === 'procedure' &&\n isTgpu(ctx, node.callee.object)) ||\n // Assuming that every call to `.does` is related to TypeGPU\n // because shells can be created separately from calls to `tgpu`,\n // making it hard to detect.\n node.callee.property.name === 'does')\n );\n}\n"]}
|
package/chunk-EDH7U5CG.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/chunk-EDH7U5CG.cjs","../src/index.ts"],"names":["typegpu","options","code","id","shouldSkipFile","ctx","ast","tgslFunctionDefs","walk","_node","_parent","prop","index","node","gatherTgpuAliases","isDoesCall","implementation","magicString","MagicString","expr","argNames","body","externalNames","transpileFn","embedJSON"],"mappings":"AAAA,iOAA+D,6CCC/B,qGACR,kDACI,oCACyB,IAgB/CA,CAAAA,CACJC,CAAAA,EAAAA,CACI,CACJ,IAAA,CAAM,kBAAA,CACN,SAAA,CAAUC,CAAAA,CAAMC,CAAAA,CAAI,CAClB,EAAA,CAAIC,iCAAAA,CAAeH,CAASE,CAAAA,CAAID,CAAI,CAAA,CAClC,MAAA,CAGF,IAAMG,CAAAA,CAAe,CACnB,WAAA,CAAa,IAAI,GAAA,CAAI,CAAC,MAAM,CAAC,CAC/B,CAAA,CAEMC,CAAAA,CAAM,IAAA,CAAK,KAAA,CAAMJ,CAAAA,CAAM,CAC3B,0BAAA,CAA4B,CAAA,CAC9B,CAAC,CAAA,CAEKK,CAAAA,CAAsC,CAAC,CAAA,CAE7CC,gCAAAA,CAAKF,CAAK,CACR,KAAA,CAAMG,CAAAA,CAAOC,CAAAA,CAASC,CAAAA,CAAMC,CAAAA,CAAO,CACjC,IAAMC,CAAAA,CAAOJ,CAAAA,CAMb,EAAA,CAJII,CAAAA,CAAK,IAAA,GAAS,mBAAA,EAChBC,iCAAAA,CAAkBD,CAAMR,CAAG,CAAA,CAGzBQ,CAAAA,CAAK,IAAA,GAAS,gBAAA,EACZE,iCAAAA,CAAWF,CAAMR,CAAG,CAAA,CAAG,CACzB,IAAMW,CAAAA,CAAiBH,CAAAA,CAAK,SAAA,CAAU,CAAC,CAAA,CAGrCG,CAAAA,EACEA,CAAAA,CAAe,IAAA,GAAS,iBAAA,EACxBA,CAAAA,CAAe,IAAA,GAAS,SAAA,EAE1BT,CAAAA,CAAiB,IAAA,CAAK,CACpB,OAAA,CAASM,CAAAA,CACT,cAAA,CAAAG,CACF,CAAC,CAEL,CAEJ,CACF,CAAC,CAAA,CAED,IAAMC,CAAAA,CAAc,IAAIC,0BAAAA,CAAYhB,CAAI,CAAA,CAExC,GAAA,CAAA,IAAWiB,EAAAA,GAAQZ,CAAAA,CAAkB,CACnC,GAAM,CAAE,QAAA,CAAAa,CAAAA,CAAU,IAAA,CAAAC,CAAAA,CAAM,aAAA,CAAAC,CAAc,CAAA,CAAIC,yCAAAA,CACxCJ,CAAK,cACP,CAAA,CAGAF,CAAAA,CAAY,UAAA,CAAWE,CAAAA,CAAK,cAAA,CAAe,KAAA,CAAO,mBAAmB,CAAA,CACrEF,CAAAA,CAAY,WAAA,CACVE,CAAAA,CAAK,cAAA,CAAe,GAAA,CACpB,CAAA,EAAA,EAAKK,iCAAAA,CAAY,QAAA,CAAAJ,CAAAA,CAAU,IAAA,CAAAC,CAAAA,CAAM,aAAA,CAAAC,CAAc,CAAC,CAAC,CAAA,CAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/chunk-EDH7U5CG.cjs","sourcesContent":[null,"import type { AnyNode, CallExpression } from 'acorn';\nimport { type Node, walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport { transpileFn } from 'tinyest-for-wgsl';\nimport { type UnpluginFactory, createUnplugin } from 'unplugin';\nimport babel from './babel';\nimport {\n type Context,\n type TypegpuPluginOptions,\n embedJSON,\n gatherTgpuAliases,\n isDoesCall,\n shouldSkipFile,\n} from './common';\n\ntype TgslFunctionDef = {\n varDecl: CallExpression;\n implementation: AnyNode;\n};\n\nconst typegpu: UnpluginFactory<TypegpuPluginOptions> = (\n options: TypegpuPluginOptions,\n) => ({\n name: 'unplugin-typegpu' as const,\n transform(code, id) {\n if (shouldSkipFile(options, id, code)) {\n return;\n }\n\n const ctx: Context = {\n tgpuAliases: new Set(['tgpu']),\n };\n\n const ast = this.parse(code, {\n allowReturnOutsideFunction: true,\n }) as Node;\n\n const tgslFunctionDefs: TgslFunctionDef[] = [];\n\n walk(ast, {\n enter(_node, _parent, prop, index) {\n const node = _node as AnyNode;\n\n if (node.type === 'ImportDeclaration') {\n gatherTgpuAliases(node, ctx);\n }\n\n if (node.type === 'CallExpression') {\n if (isDoesCall(node, ctx)) {\n const implementation = node.arguments[0];\n\n if (\n implementation &&\n !(implementation.type === 'TemplateLiteral') &&\n !(implementation.type === 'Literal')\n ) {\n tgslFunctionDefs.push({\n varDecl: node,\n implementation,\n });\n }\n }\n }\n },\n });\n\n const magicString = new MagicString(code);\n\n for (const expr of tgslFunctionDefs) {\n const { argNames, body, externalNames } = transpileFn(\n expr.implementation,\n );\n\n // Wrap the implementation in a call to `tgpu.__assignAst` to associate the AST with the implementation.\n magicString.appendLeft(expr.implementation.start, 'tgpu.__assignAst(');\n magicString.appendRight(\n expr.implementation.end,\n `, ${embedJSON({ argNames, body, externalNames })}`,\n );\n\n if (externalNames.length > 0) {\n magicString.appendRight(\n expr.implementation.end,\n `, {${externalNames.join(', ')}})`,\n );\n } else {\n magicString.appendRight(expr.implementation.end, ', undefined)');\n }\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap(),\n };\n },\n});\n\nconst unplugin = createUnplugin(typegpu);\n\nexport type { TypegpuPluginOptions } from './common';\n\nexport default unplugin;\n\nexport const vitePlugin = unplugin.vite;\nexport const rollupPlugin = unplugin.rollup;\nexport const rolldownPlugin = unplugin.rolldown;\nexport const webpackPlugin = unplugin.webpack;\nexport const rspackPlugin = unplugin.rspack;\nexport const esbuildPlugin = unplugin.esbuild;\nexport const farmPlugin = unplugin.farm;\nexport const babelPlugin = babel;\n"]}
|
package/esbuild.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/esbuild.cjs","../src/esbuild.ts"],"names":["esbuild_default","esbuildPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/esbuild.cjs","sourcesContent":[null,"import { esbuildPlugin } from './index';\n\nexport default esbuildPlugin;\n"]}
|
package/farm.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/farm.cjs","../src/farm.ts"],"names":["farm_default","farmPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/farm.cjs","sourcesContent":[null,"import { farmPlugin } from './index';\n\nexport default farmPlugin;\n"]}
|
package/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/index.cjs"],"names":[],"mappings":"AAAA,iIAAmD,gCAA6B,qYAAoK","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/index.cjs"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-typegpu",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
4
|
"description": "Build plugins for TypeGPU, enabling seamless JavaScript -> WGSL transpilation and improved debugging.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rollup-plugin",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"homepage": "https://typegpu.com",
|
|
85
85
|
"dependencies": {
|
|
86
86
|
"@babel/standalone": "^7.26.6",
|
|
87
|
-
"tinyest-for-wgsl": "~0.1.0-alpha.
|
|
87
|
+
"tinyest-for-wgsl": "~0.1.0-alpha.5",
|
|
88
88
|
"estree-walker": "^3.0.3",
|
|
89
89
|
"magic-string": "^0.30.11",
|
|
90
90
|
"unplugin": "^2.2.0"
|
package/rolldown.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rolldown.cjs","../src/rolldown.ts"],"names":["rolldown_default","rolldownPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rolldown.cjs","sourcesContent":[null,"import { rolldownPlugin } from './index';\n\nexport default rolldownPlugin;\n"]}
|
package/rollup.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rollup.cjs","../src/rollup.ts"],"names":["rollup_default","rollupPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rollup.cjs","sourcesContent":[null,"import { rollupPlugin } from './index';\n\nexport default rollupPlugin;\n"]}
|
package/rspack.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rspack.cjs","../src/rspack.ts"],"names":["rspack_default","rspackPlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/rspack.cjs","sourcesContent":[null,"import { rspackPlugin } from './index';\n\nexport default rspackPlugin;\n"]}
|
package/vite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/vite.cjs","../src/vite.ts"],"names":["vite_default","vitePlugin"],"mappings":"AAAA,iIAAwC,gCAA6B,ICE9DA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/vite.cjs","sourcesContent":[null,"import { vitePlugin } from './index';\n\nexport default vitePlugin;\n"]}
|
package/webpack.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/webpack.cjs","../src/webpack.ts"],"names":["webpack_default","webpackPlugin"],"mappings":"AAAA,iIAAmC,gCAA6B,ICEzDA,CAAAA,CAAQC,mBAAAA,CAAAA,oBAAAA","file":"/Users/marcinhawryluk/Documents/wigsill/packages/unplugin-typegpu/dist/webpack.cjs","sourcesContent":[null,"import { webpackPlugin } from './index';\n\nexport default webpackPlugin;\n"]}
|