Skip to content

Commit 91f7155

Browse files
authored
fix: Polyfill process in unplugin-typegpu (#2394)
1 parent 9700d5c commit 91f7155

6 files changed

Lines changed: 16 additions & 4 deletions

File tree

packages/unplugin-typegpu/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"directory": "packages/unplugin-typegpu"
2727
},
2828
"type": "module",
29-
"sideEffects": false,
3029
"exports": {
3130
"./package.json": "./package.json",
3231
".": "./src/index.ts",

packages/unplugin-typegpu/src/babel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as t from '@babel/types';
21
import type { NodePath, TraverseOptions } from '@babel/traverse';
32
import defu from 'defu';
43
import { transpileFn } from 'tinyest-for-wgsl';
54
import { FORMAT_VERSION } from 'tinyest';
5+
import { t } from './core/babel-types.ts';
66
import {
77
type PluginState,
88
defaultOptions,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// oxlint-disable-next-line import/no-unassigned-import -- imported for side effects
2+
import './polyfill-process.ts';
3+
4+
import * as t from '@babel/types';
5+
export { t };

packages/unplugin-typegpu/src/core/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { t } from './babel-types.ts';
12
import type { NodePath, TraverseOptions } from '@babel/traverse';
2-
import * as t from '@babel/types';
33
import type { FilterPattern } from 'unplugin';
44
import { MagicStringAST } from 'magic-string-ast';
55
import { transpileFn } from 'tinyest-for-wgsl';

packages/unplugin-typegpu/src/core/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import _traverse, { type NodePath } from '@babel/traverse';
66
import { FORMAT_VERSION } from 'tinyest';
77
import { transpileFn } from 'tinyest-for-wgsl';
88
import * as parser from '@babel/parser';
9-
import * as t from '@babel/types';
9+
import { t } from './babel-types.ts';
1010
import {
1111
defaultOptions,
1212
earlyPruneRegex,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// The babel plugin can be imported in a browser, which doesn't have `process` defined
2+
if (typeof globalThis.process === 'undefined') {
3+
// oxlint-disable-next-line typescript/no-explicit-any
4+
(globalThis.process as any) = {};
5+
}
6+
if (typeof globalThis.process.env === 'undefined') {
7+
globalThis.process.env = {};
8+
}

0 commit comments

Comments
 (0)