@griffel/transform 2.0.1 → 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 +7 -4
- package/evaluation/module.d.mts +1 -1
- package/package.json +2 -2
- package/transform.js +50 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
# Change Log - @griffel/transform
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
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.
|
|
7
|
+
## 2.0.2
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Fri, 13 Mar 2026 16:59:28 GMT
|
|
10
10
|
|
|
11
11
|
### Patches
|
|
12
12
|
|
|
13
|
-
-
|
|
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
|
|
14
17
|
|
|
15
18
|
## 2.0.0
|
|
16
19
|
|
package/evaluation/module.d.mts
CHANGED
|
@@ -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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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(
|
|
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(
|
|
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,
|