@griffel/transform 2.0.0 → 2.0.2

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/CHANGELOG.md CHANGED
@@ -1,12 +1,23 @@
1
1
  # Change Log - @griffel/transform
2
2
 
3
- This log was last generated on Wed, 11 Mar 2026 13:31:20 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 13 Mar 2026 16:59:28 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 2.0.2
8
+
9
+ Fri, 13 Mar 2026 16:59:28 GMT
10
+
11
+ ### Patches
12
+
13
+ - fix: wrap VM errors as host Error with filename context (olfedias@microsoft.com)
14
+ - perf: skip eval cache for __mkPreval entry-point evaluations (olfedias@microsoft.com)
15
+ - fix: wrap VM errors as host Error with filename context, defer CJS export assignments for IIFE patterns (olfedias@microsoft.com)
16
+ - Bump @griffel/transform-shaker to v1.0.2
17
+
7
18
  ## 2.0.0
8
19
 
9
- Wed, 11 Mar 2026 13:31:20 GMT
20
+ Wed, 11 Mar 2026 13:33:34 GMT
10
21
 
11
22
  ### Major changes
12
23
 
@@ -25,7 +25,7 @@ export declare class Module {
25
25
  cache: Record<string, Module>;
26
26
  resolve: (id: string) => string;
27
27
  };
28
- evaluate(text: string, only?: string[] | null): void;
28
+ evaluate(text: string, only?: string[] | null, useEvalCache?: boolean): void;
29
29
  static invalidate: () => void;
30
30
  static invalidateEvalCache: () => void;
31
31
  static _nodeModulePaths: (filename: string) => string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@griffel/transform",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "A package that performs build time transforms for Griffel",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@griffel/core": "^1.20.1",
20
- "@griffel/transform-shaker": "^1.0.0",
20
+ "@griffel/transform-shaker": "^1.0.2",
21
21
  "debug": "^4.3.0",
22
22
  "magic-string": "^0.30.19",
23
23
  "oxc-parser": "^0.116.0",
package/transform.js CHANGED
@@ -51,6 +51,7 @@ function convertESMtoCJS(code, filename) {
51
51
  return code;
52
52
  }
53
53
  const ms = new MagicString(code);
54
+ const deferredExports = [];
54
55
  for (const node of program.body) {
55
56
  switch (node.type) {
56
57
  case "ImportDeclaration": {
@@ -105,14 +106,11 @@ function convertESMtoCJS(code, filename) {
105
106
  const names = prop(decl, "declarations").flatMap(
106
107
  (d) => extractDeclaredNames(prop(d, "id"))
107
108
  );
108
- const exportsCode = names.map((name) => `exports.${name} = ${name};`).join(" ");
109
- ms.appendLeft(node.end, "\n" + exportsCode);
109
+ deferredExports.push(...names);
110
110
  } else if (decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") {
111
111
  const id = prop(decl, "id");
112
112
  if (id) {
113
- const name = prop(id, "name");
114
- ms.appendLeft(node.end, `
115
- exports.${name} = ${name};`);
113
+ deferredExports.push(prop(id, "name"));
116
114
  }
117
115
  }
118
116
  } else if (prop(node, "source")) {
@@ -173,6 +171,9 @@ exports.default = ${prop(id, "name")};`);
173
171
  }
174
172
  }
175
173
  }
174
+ if (deferredExports.length > 0) {
175
+ ms.append("\n" + deferredExports.map((name) => `exports.${name} = ${name};`).join("\n"));
176
+ }
176
177
  ms.prepend('Object.defineProperty(exports, "__esModule", { value: true });\n');
177
178
  return ms.toString();
178
179
  }
@@ -293,6 +294,9 @@ const debug = createDebug("griffel:module");
293
294
  let cache = {};
294
295
  const NOOP = () => {
295
296
  };
297
+ function isError$1(e) {
298
+ return e != null && typeof e === "object" && "message" in e && "stack" in e;
299
+ }
296
300
  const createCustomDebug = (depth) => (namespaces, arg1, ...args) => {
297
301
  const modulePrefix = depth === 0 ? "module" : `sub-module-${depth}`;
298
302
  debug(`${modulePrefix}:${namespaces}`, arg1, ...args);
@@ -383,7 +387,7 @@ class Module {
383
387
  resolve: (id) => this.resolveFilename(id, this).path
384
388
  }
385
389
  );
386
- evaluate(text, only = null) {
390
+ evaluate(text, only = null, useEvalCache = true) {
387
391
  const { filename } = this;
388
392
  let action = "ignore";
389
393
  for (let i = this.rules.length - 1; i >= 0; i--) {
@@ -394,7 +398,7 @@ class Module {
394
398
  }
395
399
  }
396
400
  const cacheKey = [this.filename, ...only ?? []];
397
- if (has(cacheKey, text)) {
401
+ if (useEvalCache && has(cacheKey, text)) {
398
402
  this.exports = get(cacheKey, text);
399
403
  return;
400
404
  }
@@ -417,25 +421,36 @@ ${code}`);
417
421
  })(exports);`, {
418
422
  filename: this.filename
419
423
  });
420
- script.runInContext(
421
- vm.createContext({
422
- clearImmediate: NOOP,
423
- clearInterval: NOOP,
424
- clearTimeout: NOOP,
425
- setImmediate: NOOP,
426
- setInterval: NOOP,
427
- setTimeout: NOOP,
428
- fetch: NOOP,
429
- global,
430
- process: mockProcess,
431
- module: this,
432
- exports: this.exports,
433
- require: this.require,
434
- __filename: this.filename,
435
- __dirname: path.dirname(this.filename)
436
- })
437
- );
438
- set(cacheKey, text, this.exports);
424
+ try {
425
+ script.runInContext(
426
+ vm.createContext({
427
+ clearImmediate: NOOP,
428
+ clearInterval: NOOP,
429
+ clearTimeout: NOOP,
430
+ setImmediate: NOOP,
431
+ setInterval: NOOP,
432
+ setTimeout: NOOP,
433
+ fetch: NOOP,
434
+ global,
435
+ process: mockProcess,
436
+ module: this,
437
+ exports: this.exports,
438
+ require: this.require,
439
+ __filename: this.filename,
440
+ __dirname: path.dirname(this.filename)
441
+ })
442
+ );
443
+ } catch (vmError) {
444
+ const message = isError$1(vmError) ? vmError.message : String(vmError);
445
+ const hostError = new Error(message);
446
+ if (isError$1(vmError)) {
447
+ hostError.stack = vmError.stack;
448
+ }
449
+ throw hostError;
450
+ }
451
+ if (useEvalCache) {
452
+ set(cacheKey, text, this.exports);
453
+ }
439
454
  }
440
455
  static invalidate = () => {
441
456
  cache = {};
@@ -529,7 +544,12 @@ export const __mkPreval = (() => {
529
544
  `;
530
545
  try {
531
546
  const mod = new Module(filename, evaluationRules, resolveFilename);
532
- mod.evaluate(codeForEvaluation, ["__mkPreval"]);
547
+ mod.evaluate(
548
+ codeForEvaluation,
549
+ ["__mkPreval"],
550
+ /* useEvalCache */
551
+ false
552
+ );
533
553
  const result = mod.exports.__mkPreval;
534
554
  if (isError(result)) {
535
555
  return { confident: false, error: result };
@@ -765,7 +785,9 @@ function transformSync(sourceCode, options) {
765
785
  }
766
786
  const functionKind = importedName;
767
787
  if (node.arguments.length !== 1) {
768
- throw new Error(`${functionKind}() function accepts only a single param`);
788
+ throw new Error(
789
+ `${functionKind}() function accepts only a single param, got ${node.arguments.length} in ${filename}`
790
+ );
769
791
  }
770
792
  matchedSpecifiers.set(declaration.node.start, {
771
793
  start: declaration.node.start,