@griffel/transform 3.0.3 → 3.0.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.
Files changed (188) hide show
  1. package/CHANGELOG.json +404 -0
  2. package/CHANGELOG.md +130 -0
  3. package/__fixtures__/assets/blank.jpg +0 -0
  4. package/__fixtures__/assets/code.ts +12 -0
  5. package/__fixtures__/assets/empty.jpg +0 -0
  6. package/__fixtures__/assets/output.meta.json +12 -0
  7. package/__fixtures__/assets/output.ts +12 -0
  8. package/__fixtures__/assets-multiple-declarations/blank.jpg +0 -0
  9. package/__fixtures__/assets-multiple-declarations/code.ts +8 -0
  10. package/__fixtures__/assets-multiple-declarations/empty.jpg +0 -0
  11. package/__fixtures__/assets-multiple-declarations/output.meta.json +9 -0
  12. package/__fixtures__/assets-multiple-declarations/output.ts +6 -0
  13. package/__fixtures__/assets-reset-styles/blank.jpg +0 -0
  14. package/__fixtures__/assets-reset-styles/code.ts +11 -0
  15. package/__fixtures__/assets-reset-styles/empty.jpg +0 -0
  16. package/__fixtures__/assets-reset-styles/output.meta.json +11 -0
  17. package/__fixtures__/assets-reset-styles/output.ts +7 -0
  18. package/__fixtures__/assets-urls/code.ts +13 -0
  19. package/__fixtures__/assets-urls/output.meta.json +14 -0
  20. package/__fixtures__/assets-urls/output.ts +10 -0
  21. package/__fixtures__/at-rules/code.ts +14 -0
  22. package/__fixtures__/at-rules/output.meta.json +15 -0
  23. package/__fixtures__/at-rules/output.ts +10 -0
  24. package/__fixtures__/config-classname-hash-salt/code.ts +5 -0
  25. package/__fixtures__/config-classname-hash-salt/output.meta.json +7 -0
  26. package/__fixtures__/config-classname-hash-salt/output.ts +3 -0
  27. package/__fixtures__/config-evaluation-rules/code.ts +8 -0
  28. package/__fixtures__/config-evaluation-rules/consts.ts +1 -0
  29. package/__fixtures__/config-evaluation-rules/output.meta.json +7 -0
  30. package/__fixtures__/config-evaluation-rules/output.ts +4 -0
  31. package/__fixtures__/config-evaluation-rules/sampleEvaluator.cjs +12 -0
  32. package/__fixtures__/error-argument-count/fixture.js +4 -0
  33. package/__fixtures__/error-cjs/fixture.js +4 -0
  34. package/__fixtures__/error-on-undefined/fixture.ts +7 -0
  35. package/__fixtures__/error-on-undefined/tokens.ts +1 -0
  36. package/__fixtures__/export-default/code.ts +6 -0
  37. package/__fixtures__/export-default/output.meta.json +14 -0
  38. package/__fixtures__/export-default/output.ts +6 -0
  39. package/__fixtures__/function-mixin/code.ts +6 -0
  40. package/__fixtures__/function-mixin/mixins.ts +7 -0
  41. package/__fixtures__/function-mixin/output.meta.json +7 -0
  42. package/__fixtures__/function-mixin/output.ts +4 -0
  43. package/__fixtures__/function-mixin/tokens.ts +3 -0
  44. package/__fixtures__/import-alias/code.ts +5 -0
  45. package/__fixtures__/import-alias/output.meta.json +7 -0
  46. package/__fixtures__/import-alias/output.ts +3 -0
  47. package/__fixtures__/import-custom-module/code.ts +6 -0
  48. package/__fixtures__/import-custom-module/output.meta.json +7 -0
  49. package/__fixtures__/import-custom-module/output.ts +4 -0
  50. package/__fixtures__/keyframes/code.ts +22 -0
  51. package/__fixtures__/keyframes/output.meta.json +17 -0
  52. package/__fixtures__/keyframes/output.ts +6 -0
  53. package/__fixtures__/multiple-declarations/code.ts +8 -0
  54. package/__fixtures__/multiple-declarations/output.meta.json +7 -0
  55. package/__fixtures__/multiple-declarations/output.ts +4 -0
  56. package/__fixtures__/non-existing-module-call/code.ts +10 -0
  57. package/__fixtures__/non-existing-module-call/module.ts +13 -0
  58. package/__fixtures__/non-existing-module-call/output.meta.json +7 -0
  59. package/__fixtures__/non-existing-module-call/output.ts +6 -0
  60. package/__fixtures__/object/code.ts +6 -0
  61. package/__fixtures__/object/output.meta.json +14 -0
  62. package/__fixtures__/object/output.ts +6 -0
  63. package/__fixtures__/object-computed-keys/code.ts +8 -0
  64. package/__fixtures__/object-computed-keys/output.meta.json +14 -0
  65. package/__fixtures__/object-computed-keys/output.ts +8 -0
  66. package/__fixtures__/object-imported-keys/code.ts +9 -0
  67. package/__fixtures__/object-imported-keys/consts.ts +2 -0
  68. package/__fixtures__/object-imported-keys/output.meta.json +7 -0
  69. package/__fixtures__/object-imported-keys/output.ts +4 -0
  70. package/__fixtures__/object-mixins/code.ts +11 -0
  71. package/__fixtures__/object-mixins/mixins.ts +17 -0
  72. package/__fixtures__/object-mixins/output.meta.json +16 -0
  73. package/__fixtures__/object-mixins/output.ts +10 -0
  74. package/__fixtures__/object-mixins/tokens.ts +3 -0
  75. package/__fixtures__/object-nesting/code.ts +13 -0
  76. package/__fixtures__/object-nesting/consts.ts +1 -0
  77. package/__fixtures__/object-nesting/output.meta.json +9 -0
  78. package/__fixtures__/object-nesting/output.ts +6 -0
  79. package/__fixtures__/object-reset/code.ts +8 -0
  80. package/__fixtures__/object-reset/output.meta.json +7 -0
  81. package/__fixtures__/object-reset/output.ts +5 -0
  82. package/__fixtures__/object-sequence-expr/code.ts +16 -0
  83. package/__fixtures__/object-sequence-expr/output.meta.json +7 -0
  84. package/__fixtures__/object-sequence-expr/output.ts +7 -0
  85. package/__fixtures__/object-shorthands/code.ts +8 -0
  86. package/__fixtures__/object-shorthands/output.meta.json +20 -0
  87. package/__fixtures__/object-shorthands/output.ts +5 -0
  88. package/__fixtures__/object-variables/code.ts +9 -0
  89. package/__fixtures__/object-variables/output.meta.json +15 -0
  90. package/__fixtures__/object-variables/output.ts +9 -0
  91. package/__fixtures__/object-variables/vars.ts +5 -0
  92. package/__fixtures__/reset-styles/code.ts +6 -0
  93. package/__fixtures__/reset-styles/output.meta.json +7 -0
  94. package/__fixtures__/reset-styles/output.ts +3 -0
  95. package/__fixtures__/reset-styles-at-rules/code.ts +7 -0
  96. package/__fixtures__/reset-styles-at-rules/output.meta.json +8 -0
  97. package/__fixtures__/reset-styles-at-rules/output.ts +3 -0
  98. package/__fixtures__/rules-with-metadata/code.ts +9 -0
  99. package/__fixtures__/rules-with-metadata/output.meta.json +14 -0
  100. package/__fixtures__/rules-with-metadata/output.ts +3 -0
  101. package/__fixtures__/shared-mixins/code.ts +7 -0
  102. package/__fixtures__/shared-mixins/mixins.ts +6 -0
  103. package/__fixtures__/shared-mixins/output.meta.json +7 -0
  104. package/__fixtures__/shared-mixins/output.ts +8 -0
  105. package/__fixtures__/static-styles/code.ts +7 -0
  106. package/__fixtures__/static-styles/output.meta.json +7 -0
  107. package/__fixtures__/static-styles/output.ts +3 -0
  108. package/__fixtures__/static-styles-array/code.ts +10 -0
  109. package/__fixtures__/static-styles-array/output.meta.json +7 -0
  110. package/__fixtures__/static-styles-array/output.ts +3 -0
  111. package/__fixtures__/static-styles-string/code.ts +3 -0
  112. package/__fixtures__/static-styles-string/output.meta.json +7 -0
  113. package/__fixtures__/static-styles-string/output.ts +3 -0
  114. package/__fixtures__/tokens/code.ts +11 -0
  115. package/__fixtures__/tokens/output.meta.json +12 -0
  116. package/__fixtures__/tokens/output.ts +7 -0
  117. package/__fixtures__/tokens/tokens.ts +4 -0
  118. package/__fixtures__/unsupported-css-properties/fixture.ts +16 -0
  119. package/__fixtures__/unsupported-css-properties/output.meta.json +5 -0
  120. package/__fixtures__/unsupported-css-properties/output.ts +3 -0
  121. package/eslint.config.mjs +31 -0
  122. package/package.json +7 -8
  123. package/project.json +51 -0
  124. package/src/{constants.mjs → constants.mts} +0 -1
  125. package/src/evaluation/astEvaluator.mts +109 -0
  126. package/src/evaluation/astEvaluator.test.mts +126 -0
  127. package/src/evaluation/batchEvaluator.mts +79 -0
  128. package/src/evaluation/evalCache.mts +84 -0
  129. package/src/evaluation/fluentTokensPlugin.mts +82 -0
  130. package/src/evaluation/fluentTokensPlugin.test.mts +130 -0
  131. package/src/evaluation/module.mts +271 -0
  132. package/src/evaluation/module.test.mts +133 -0
  133. package/src/evaluation/{process.mjs → process.mts} +12 -7
  134. package/src/evaluation/types.mts +49 -0
  135. package/src/evaluation/vmEvaluator.mts +45 -0
  136. package/src/evaluation/vmEvaluator.test.mts +30 -0
  137. package/src/{index.d.mts → index.mts} +4 -0
  138. package/src/transformSync.mts +425 -0
  139. package/src/transformSync.test.mts +429 -0
  140. package/src/types.mts +13 -0
  141. package/src/utils/convertESMtoCJS.mts +226 -0
  142. package/src/utils/convertESMtoCJS.test.mts +159 -0
  143. package/src/utils/dedupeCSSRules.mts +25 -0
  144. package/src/utils/dedupeCSSRules.test.mts +39 -0
  145. package/tsconfig.json +19 -0
  146. package/tsconfig.lib.json +30 -0
  147. package/tsconfig.spec.json +24 -0
  148. package/vitest.config.mts +18 -0
  149. package/LICENSE.md +0 -21
  150. package/src/constants.d.mts +0 -2
  151. package/src/constants.mjs.map +0 -1
  152. package/src/evaluation/astEvaluator.d.mts +0 -20
  153. package/src/evaluation/astEvaluator.mjs +0 -90
  154. package/src/evaluation/astEvaluator.mjs.map +0 -1
  155. package/src/evaluation/batchEvaluator.d.mts +0 -13
  156. package/src/evaluation/batchEvaluator.mjs +0 -54
  157. package/src/evaluation/batchEvaluator.mjs.map +0 -1
  158. package/src/evaluation/evalCache.d.mts +0 -9
  159. package/src/evaluation/evalCache.mjs +0 -65
  160. package/src/evaluation/evalCache.mjs.map +0 -1
  161. package/src/evaluation/fluentTokensPlugin.d.mts +0 -2
  162. package/src/evaluation/fluentTokensPlugin.mjs +0 -70
  163. package/src/evaluation/fluentTokensPlugin.mjs.map +0 -1
  164. package/src/evaluation/module.d.mts +0 -44
  165. package/src/evaluation/module.mjs +0 -207
  166. package/src/evaluation/module.mjs.map +0 -1
  167. package/src/evaluation/process.d.mts +0 -24
  168. package/src/evaluation/process.mjs.map +0 -1
  169. package/src/evaluation/types.d.mts +0 -34
  170. package/src/evaluation/types.mjs +0 -2
  171. package/src/evaluation/types.mjs.map +0 -1
  172. package/src/evaluation/vmEvaluator.d.mts +0 -3
  173. package/src/evaluation/vmEvaluator.mjs +0 -33
  174. package/src/evaluation/vmEvaluator.mjs.map +0 -1
  175. package/src/index.mjs +0 -9
  176. package/src/index.mjs.map +0 -1
  177. package/src/transformSync.d.mts +0 -41
  178. package/src/transformSync.mjs +0 -252
  179. package/src/transformSync.mjs.map +0 -1
  180. package/src/types.d.mts +0 -12
  181. package/src/types.mjs +0 -2
  182. package/src/types.mjs.map +0 -1
  183. package/src/utils/convertESMtoCJS.d.mts +0 -6
  184. package/src/utils/convertESMtoCJS.mjs +0 -203
  185. package/src/utils/convertESMtoCJS.mjs.map +0 -1
  186. package/src/utils/dedupeCSSRules.d.mts +0 -6
  187. package/src/utils/dedupeCSSRules.mjs +0 -19
  188. package/src/utils/dedupeCSSRules.mjs.map +0 -1
@@ -1,70 +0,0 @@
1
- import { DEOPT } from './astEvaluator.mjs';
2
- // zIndex tokens are not part of the theme and include default fallback values.
3
- // See: https://github.com/microsoft/fluentui/blob/master/packages/tokens/src/global/zIndexes.ts
4
- const Z_INDEX_DEFAULTS = {
5
- zIndexBackground: 0,
6
- zIndexContent: 1,
7
- zIndexOverlay: 1000,
8
- zIndexPopup: 2000,
9
- zIndexMessages: 3000,
10
- zIndexFloating: 4000,
11
- zIndexPriority: 5000,
12
- zIndexDebug: 6000,
13
- };
14
- /**
15
- * Evaluates template literals that contain Fluent UI design tokens.
16
- * Transforms `${tokens.propertyName}` expressions into CSS custom properties: `var(--propertyName)`
17
- */
18
- function evaluateTemplateLiteralWithTokens(node) {
19
- let result = '';
20
- for (let i = 0; i < node.quasis.length; i++) {
21
- result += node.quasis[i].value.cooked;
22
- if (i < node.expressions.length) {
23
- const expression = node.expressions[i];
24
- if (expression.type === 'MemberExpression' &&
25
- expression.object.type === 'Identifier' &&
26
- expression.object.name === 'tokens' &&
27
- expression.property.type === 'Identifier' &&
28
- !expression.computed) {
29
- const name = expression.property.name;
30
- const fallback = Z_INDEX_DEFAULTS[name];
31
- result += fallback !== undefined ? `var(--${name}, ${fallback})` : `var(--${name})`;
32
- }
33
- else {
34
- return DEOPT;
35
- }
36
- }
37
- }
38
- return result;
39
- }
40
- /**
41
- * Evaluates member expressions that reference Fluent UI design tokens.
42
- * Transforms `tokens.propertyName` expressions into CSS custom properties: `var(--propertyName)`
43
- */
44
- function evaluateTokensMemberExpression(node) {
45
- if (node.object.type === 'Identifier' &&
46
- node.object.name === 'tokens' &&
47
- node.property.type === 'Identifier' &&
48
- !node.computed) {
49
- const name = node.property.name;
50
- const fallback = Z_INDEX_DEFAULTS[name];
51
- return fallback !== undefined ? `var(--${name}, ${fallback})` : `var(--${name})`;
52
- }
53
- else {
54
- return DEOPT;
55
- }
56
- }
57
- export const fluentTokensPlugin = {
58
- name: 'fluentTokensPlugin',
59
- evaluateNode(node) {
60
- switch (node.type) {
61
- case 'TemplateLiteral':
62
- return evaluateTemplateLiteralWithTokens(node);
63
- case 'MemberExpression':
64
- return evaluateTokensMemberExpression(node);
65
- default:
66
- return DEOPT;
67
- }
68
- },
69
- };
70
- //# sourceMappingURL=fluentTokensPlugin.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fluentTokensPlugin.mjs","sourceRoot":"","sources":["../../../../../packages/transform/src/evaluation/fluentTokensPlugin.mts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAc,MAAM,oBAAoB,CAAC;AAGvD,+EAA+E;AAC/E,gGAAgG;AAChG,MAAM,gBAAgB,GAA2B;IAC/C,gBAAgB,EAAE,CAAC;IACnB,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,IAAI;IACnB,WAAW,EAAE,IAAI;IACjB,cAAc,EAAE,IAAI;IACpB,cAAc,EAAE,IAAI;IACpB,cAAc,EAAE,IAAI;IACpB,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;GAGG;AACH,SAAS,iCAAiC,CAAC,IAAqB;IAC9D,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;QAEtC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M,CAAC;QACN,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAuB;IACpD,IAAI,EAAE,oBAAoB;IAC1B,YAAY,CAAC,IAAI;QACf,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,iBAAiB;gBACpB,OAAO,iCAAiC,CAAC,IAAI,CAAC,CAAC;YACjD,KAAK,kBAAkB;gBACrB,OAAO,8BAA8B,CAAC,IAAI,CAAC,CAAC;YAC9C;gBACE,OAAO,KAAK,CAAC;QACjB,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -1,44 +0,0 @@
1
- /**
2
- * Custom module system for evaluating code in a sandboxed VM context.
3
- * Copied from @linaria/babel-preset v3.0.0-beta.19, adapted to use `debug` package
4
- * and local imports instead of @linaria/* packages.
5
- *
6
- * This serves 2 purposes:
7
- * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`
8
- * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds
9
- *
10
- * We also use it to transpile the code with Babel by default.
11
- * We also store source maps for it to provide correct error stacktraces.
12
- */
13
- import type { EvalRule } from './types.mjs';
14
- export type TransformResolver = (id: string, options: {
15
- filename: string;
16
- paths: readonly string[];
17
- }) => {
18
- path: string;
19
- builtin: boolean;
20
- };
21
- export declare class Module {
22
- readonly id: string;
23
- readonly filename: string;
24
- readonly paths: readonly string[];
25
- rules: EvalRule[];
26
- imports: Map<string, string[]> | null;
27
- dependencies: string[] | null;
28
- transform: ((code: string, filename: string) => string) | null;
29
- static readonly extensions: Set<string>;
30
- exports: unknown;
31
- private readonly resolveFilename;
32
- private debug;
33
- private debuggerDepth;
34
- constructor(filename: string, rules: EvalRule[], resolveFilename: TransformResolver, debuggerDepth?: number);
35
- require: ((id: string) => unknown) & {
36
- ensure: () => void;
37
- cache: Record<string, Module>;
38
- resolve: (id: string) => string;
39
- };
40
- evaluate(text: string, only?: string[] | null, useEvalCache?: boolean): void;
41
- static invalidate: () => void;
42
- static invalidateEvalCache: () => void;
43
- static _nodeModulePaths: (filename: string) => string[];
44
- }
@@ -1,207 +0,0 @@
1
- /**
2
- * Custom module system for evaluating code in a sandboxed VM context.
3
- * Copied from @linaria/babel-preset v3.0.0-beta.19, adapted to use `debug` package
4
- * and local imports instead of @linaria/* packages.
5
- *
6
- * This serves 2 purposes:
7
- * - Avoid leakage from evaluated code to module cache in current context, e.g. `babel-register`
8
- * - Allow us to invalidate the module cache without affecting other stuff, necessary for rebuilds
9
- *
10
- * We also use it to transpile the code with Babel by default.
11
- * We also store source maps for it to provide correct error stacktraces.
12
- */
13
- import fs from 'node:fs';
14
- import NativeModule from 'node:module';
15
- import path from 'node:path';
16
- import vm from 'node:vm';
17
- import createDebug from 'debug';
18
- import { ASSET_TAG_OPEN, ASSET_TAG_CLOSE } from '../constants.mjs';
19
- import { convertESMtoCJS } from '../utils/convertESMtoCJS.mjs';
20
- import * as EvalCache from './evalCache.mjs';
21
- import * as mockProcess from './process.mjs';
22
- const debug = createDebug('griffel:module');
23
- // Separate cache for evaluated modules
24
- let cache = {};
25
- const NOOP = () => { };
26
- /** Checks if a value is an Error-like object (works across VM contexts where `instanceof Error` fails). */
27
- function isError(e) {
28
- return e != null && typeof e === 'object' && 'message' in e && 'stack' in e;
29
- }
30
- const createCustomDebug = (depth) => (namespaces, arg1, ...args) => {
31
- const modulePrefix = depth === 0 ? 'module' : `sub-module-${depth}`;
32
- debug(`${modulePrefix}:${namespaces}`, arg1, ...args);
33
- };
34
- export class Module {
35
- id;
36
- filename;
37
- rules;
38
- imports = null;
39
- dependencies = null;
40
- transform = null;
41
- static extensions = new Set(['.json', '.js', '.jsx', '.ts', '.tsx', '.cjs', '.mjs', '.mts', '.cts']);
42
- exports = {};
43
- resolveFilename;
44
- debug;
45
- debuggerDepth;
46
- constructor(filename, rules, resolveFilename, debuggerDepth = 0) {
47
- this.id = filename;
48
- this.filename = filename;
49
- this.rules = rules;
50
- this.resolveFilename = resolveFilename;
51
- this.debuggerDepth = debuggerDepth;
52
- this.debug = createCustomDebug(debuggerDepth);
53
- Object.defineProperties(this, {
54
- id: {
55
- value: filename,
56
- writable: false,
57
- },
58
- filename: {
59
- value: filename,
60
- writable: false,
61
- },
62
- paths: {
63
- value: Object.freeze(NativeModule._nodeModulePaths(path.dirname(filename))),
64
- writable: false,
65
- },
66
- });
67
- this.exports = {};
68
- this.debug('prepare', filename);
69
- }
70
- require = Object.assign((id) => {
71
- this.debug('require', id);
72
- // Resolve module id (and filename) relatively to parent module
73
- const resolved = this.resolveFilename(id, this);
74
- if (resolved.builtin) {
75
- throw new Error(`Unable to import "${id}". Importing Node builtins is not supported in the sandbox.`);
76
- }
77
- const filename = resolved.path;
78
- this.dependencies?.push(id);
79
- let cacheKey = filename;
80
- let only = [];
81
- if (this.imports?.has(id)) {
82
- // We know what exactly we need from this module. Let's shake it!
83
- only = this.imports.get(id).sort();
84
- if (only.length === 0) {
85
- // Probably the module is used as a value itself
86
- // like `'The answer is ' + require('./module')`
87
- only = ['default'];
88
- }
89
- cacheKey += `:${only.join(',')}`;
90
- }
91
- let m = cache[cacheKey];
92
- if (!m) {
93
- this.debug('cached:not-exist', id);
94
- // Create the module if cached module is not available
95
- m = new Module(filename, this.rules, this.resolveFilename, this.debuggerDepth + 1);
96
- m.transform = this.transform;
97
- // Store it in cache at this point, otherwise
98
- // we would end up in infinite loop with cyclic dependencies
99
- cache[cacheKey] = m;
100
- const ext = path.extname(filename).toLowerCase();
101
- if (Module.extensions.has(ext)) {
102
- // To evaluate the file, we need to read it first
103
- const code = fs.readFileSync(filename, 'utf-8');
104
- if (ext === '.json') {
105
- // For JSON files, parse it to a JS object similar to Node
106
- m.exports = JSON.parse(code);
107
- }
108
- else {
109
- // For JS/TS files, evaluate the module
110
- // The module will be transpiled using provided transform
111
- m.evaluate(code, only.includes('*') ? ['*'] : only);
112
- }
113
- }
114
- else {
115
- // For non JS/JSON requires, export the resolved absolute path wrapped in asset tags.
116
- // This allows downstream tools (e.g. webpack plugin) to resolve the path correctly
117
- // when CSS is extracted to a different location.
118
- m.exports = ASSET_TAG_OPEN + filename + ASSET_TAG_CLOSE;
119
- }
120
- }
121
- else {
122
- this.debug('cached:exist', id);
123
- }
124
- return m.exports;
125
- }, {
126
- ensure: NOOP,
127
- cache,
128
- resolve: (id) => this.resolveFilename(id, this).path,
129
- });
130
- evaluate(text, only = null, useEvalCache = true) {
131
- const { filename } = this;
132
- // Find last matching rule (iterate backwards, break on first match)
133
- let action = 'ignore';
134
- for (let i = this.rules.length - 1; i >= 0; i--) {
135
- const { test } = this.rules[i];
136
- if (!test || (typeof test === 'function' ? test(filename) : test.test(filename))) {
137
- action = this.rules[i].action;
138
- break;
139
- }
140
- }
141
- const cacheKey = [this.filename, ...(only ?? [])];
142
- if (useEvalCache && EvalCache.has(cacheKey, text)) {
143
- this.exports = EvalCache.get(cacheKey, text);
144
- return;
145
- }
146
- let code;
147
- if (action === 'ignore') {
148
- this.debug('ignore', `${filename}`);
149
- code = text;
150
- }
151
- else {
152
- // For JavaScript files, we need to transpile it and to get the exports of the module
153
- this.debug('prepare-evaluation', this.filename, 'using', action.name);
154
- const result = action(this.filename, text, only);
155
- code = result.code;
156
- this.imports = result.imports;
157
- // Convert ESM syntax to CJS so it can run inside a function wrapper in vm.Script
158
- if (result.moduleKind === 'esm') {
159
- code = convertESMtoCJS(code, this.filename);
160
- }
161
- this.debug('evaluate', `${this.filename} (only ${(only || []).join(', ')}):\n${code}`);
162
- }
163
- const script = new vm.Script(`(function (exports) { ${code}\n})(exports);`, {
164
- filename: this.filename,
165
- });
166
- try {
167
- script.runInContext(vm.createContext({
168
- clearImmediate: NOOP,
169
- clearInterval: NOOP,
170
- clearTimeout: NOOP,
171
- setImmediate: NOOP,
172
- setInterval: NOOP,
173
- setTimeout: NOOP,
174
- fetch: NOOP,
175
- global,
176
- process: mockProcess,
177
- module: this,
178
- exports: this.exports,
179
- require: this.require,
180
- __filename: this.filename,
181
- __dirname: path.dirname(this.filename),
182
- }));
183
- }
184
- catch (vmError) {
185
- // Errors thrown inside vm.runInContext() use the VM context's Error constructor,
186
- // so they fail `instanceof Error` in the host context (e.g. webpack wraps them as NonErrorEmittedError).
187
- // Re-create as a host Error with filename context.
188
- const message = isError(vmError) ? vmError.message : String(vmError);
189
- const hostError = new Error(message);
190
- if (isError(vmError)) {
191
- hostError.stack = vmError.stack;
192
- }
193
- throw hostError;
194
- }
195
- if (useEvalCache) {
196
- EvalCache.set(cacheKey, text, this.exports);
197
- }
198
- }
199
- static invalidate = () => {
200
- cache = {};
201
- };
202
- static invalidateEvalCache = () => {
203
- EvalCache.clear();
204
- };
205
- static _nodeModulePaths = (filename) => NativeModule._nodeModulePaths(filename);
206
- }
207
- //# sourceMappingURL=module.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"module.mjs","sourceRoot":"","sources":["../../../../../packages/transform/src/evaluation/module.mts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,YAAY,MAAM,aAAa,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,WAAW,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,WAAW,MAAM,eAAe,CAAC;AAQ7C,MAAM,KAAK,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC;AAE5C,uCAAuC;AACvC,IAAI,KAAK,GAA2B,EAAE,CAAC;AAEvC,MAAM,IAAI,GAAG,GAAG,EAAE,GAAc,CAAC,CAAC;AAElC,2GAA2G;AAC3G,SAAS,OAAO,CAAC,CAAU;IACzB,OAAO,CAAC,IAAI,IAAI,IAAI,O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GAAG,CAAC,QAAgB,EAAY,EAAE,CACtD,YAA2E,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC"}
@@ -1,24 +0,0 @@
1
- /**
2
- * Mocked `process` variable for the VM sandbox used in module evaluation.
3
- * Copied from @linaria/babel-preset v3.0.0-beta.19.
4
- */
5
- export declare const nextTick: (fn: (...args: unknown[]) => void) => ReturnType<typeof setTimeout>;
6
- export declare const platform = "browser";
7
- export declare const arch = "browser";
8
- export declare const execPath = "browser";
9
- export declare const title = "browser";
10
- export declare const pid = 1;
11
- export declare const browser = true;
12
- export declare const argv: string[];
13
- export declare const binding: () => never;
14
- export declare const cwd: () => string;
15
- export declare const exit: () => void;
16
- export declare const kill: () => void;
17
- export declare const chdir: () => void;
18
- export declare const umask: () => void;
19
- export declare const dlopen: () => void;
20
- export declare const uptime: () => void;
21
- export declare const memoryUsage: () => void;
22
- export declare const uvCounters: () => void;
23
- export declare const features: {};
24
- export declare const env: NodeJS.ProcessEnv;
@@ -1 +0,0 @@
1
- {"version":3,"file":"process.mjs","sourceRoot":"","sources":["../../../../../packages/transform/src/evaluation/process.mts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAgC,EAAiC,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAE/G,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC;AAClC,MAAM,CAAC,MAAM,IAAI,GAAG,SAAS,CAAC;AAC9B,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAC;AAClC,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAC;AAC/B,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;AACrB,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;AAC5B,MAAM,CAAC,MAAM,IAAI,GAAa,EAAE,CAAC;AAEjC,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,OAAO;IACrC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAW,EAAE,CAAC,GAAG,CAAC;AAErC,MAAM,IAAI,GAAG,GAAS,EAAE,GAAc,CAAC,CAAC;AAExC,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC;AACzB,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC;AACzB,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC;AAC1B,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC;AAC1B,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC;AAC/B,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAC3B,MAAM,CAAC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC"}
@@ -1,34 +0,0 @@
1
- import type { Node, Program } from 'oxc-parser';
2
- export type EvaluatorResult = {
3
- code: string;
4
- imports: Map<string, string[]> | null;
5
- moduleKind: 'esm' | 'cjs';
6
- };
7
- export type EvalRule = {
8
- test?: RegExp | ((path: string) => boolean);
9
- action: Evaluator | 'ignore';
10
- };
11
- export type Evaluator = (filename: string, text: string, only: string[] | null) => EvaluatorResult;
12
- export interface TransformPerfIssue {
13
- type: 'cjs-module' | 'barrel-export-star';
14
- /** The dependency file that caused the issue */
15
- dependencyFilename: string;
16
- }
17
- export interface EvaluationResult {
18
- confident: boolean;
19
- value?: unknown;
20
- error?: Error;
21
- }
22
- export interface AstEvaluatorContext {
23
- /** Full program AST */
24
- programAst: Program;
25
- /** Recursive evaluator callback (goes through base + all plugins) */
26
- evaluateNode: (node: Node) => unknown;
27
- }
28
- export interface AstEvaluatorPlugin {
29
- name: string;
30
- /**
31
- * Evaluate an AST node. Return DEOPT symbol to signal "can't handle this".
32
- */
33
- evaluateNode: (node: Node, context: AstEvaluatorContext) => unknown;
34
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../../../../packages/transform/src/evaluation/types.mts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- import type { TransformResolver } from './module.mjs';
2
- import type { EvalRule, EvaluationResult } from './types.mjs';
3
- export declare function vmEvaluator(sourceCode: string, filename: string, expressionCode: string, evaluationRules: EvalRule[], resolveFilename: TransformResolver): EvaluationResult;
@@ -1,33 +0,0 @@
1
- import { Module } from './module.mjs';
2
- function isError(e) {
3
- return Object.prototype.toString.call(e) === '[object Error]';
4
- }
5
- export function vmEvaluator(sourceCode, filename, expressionCode, evaluationRules, resolveFilename) {
6
- // Create a simple wrapper program for evaluation
7
- const codeForEvaluation = `
8
- ${sourceCode}
9
-
10
- export const __mkPreval = (() => {
11
- try {
12
- return ([${expressionCode}]);
13
- } catch (e) {
14
- return e;
15
- }
16
- })();
17
- `;
18
- try {
19
- const mod = new Module(filename, evaluationRules, resolveFilename);
20
- // useEvalCache=false: each source file produces unique codeForEvaluation (different sourceCode +
21
- // expressionCode), so the eval cache would never hit — skip the unnecessary hashing and map storage.
22
- mod.evaluate(codeForEvaluation, ['__mkPreval'], /* useEvalCache */ false);
23
- const result = mod.exports.__mkPreval;
24
- if (isError(result)) {
25
- return { confident: false, error: result };
26
- }
27
- return { confident: true, value: result };
28
- }
29
- catch (err) {
30
- return { confident: false, error: err };
31
- }
32
- }
33
- //# sourceMappingURL=vmEvaluator.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vmEvaluator.mjs","sourceRoot":"","sources":["../../../../../packages/transform/src/evaluation/vmEvaluator.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,SAAS,OAAO,CAAC,CAAU;IACzB,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,UAAkB,EAClB,QAAgB,EAChB,cAAsB,EACtB,eAA2B,EAC3B,eAAkC;IAElC,iDAAiD;IACjD,MAAM,iBAAiB,GAAG;EAC1B,UAAU;;;;eAIG,cAAc;;;;;CAK5B,CAAC;IAEA,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,eAAe,EAAE,eAAe,CAAC,CAAC;QACnE,iGAAiG;QACjG,qGAAqG;QACrG,GAAG,CAAC,QAAQ,CAAC,iBAAiB,EAAE,CAAC,YAAY,CAAC,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAE1E,MAAM,MAAM,GAAI,GAAG,CAAC,OAAmC,CAAC,UAAU,CAAC;QAEnE,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACpB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAC7C,CAAC;QAED,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC5C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,GAAY,EAAE,CAAC;IACnD,CAAC;AACH,CAAC"}
package/src/index.mjs DELETED
@@ -1,9 +0,0 @@
1
- export { default as shakerEvaluator } from '@griffel/transform-shaker';
2
- export { Module } from './evaluation/module.mjs';
3
- export * as EvalCache from './evaluation/evalCache.mjs';
4
- export { ASSET_TAG_OPEN, ASSET_TAG_CLOSE } from './constants.mjs';
5
- // Our APIs
6
- export { transformSync } from './transformSync.mjs';
7
- export { DEOPT } from './evaluation/astEvaluator.mjs';
8
- export { fluentTokensPlugin } from './evaluation/fluentTokensPlugin.mjs';
9
- //# sourceMappingURL=index.mjs.map
package/src/index.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../packages/transform/src/index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,MAAM,EAA0B,MAAM,yBAAyB,CAAC;AACzE,OAAO,KAAK,SAAS,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAIlE,WAAW;AAEX,OAAO,EAAE,aAAa,EAA+C,MAAM,qBAAqB,CAAC;AACjG,OAAO,EAAE,KAAK,EAAc,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC"}
@@ -1,41 +0,0 @@
1
- import type { TransformResolver } from './evaluation/module.mjs';
2
- import type { EvalRule, TransformPerfIssue } from './evaluation/types.mjs';
3
- import { type CSSRulesByBucket } from '@griffel/core';
4
- import type { AstEvaluatorPlugin } from './evaluation/types.mjs';
5
- export type TransformOptions = {
6
- filename: string;
7
- /** Custom module resolver used to resolve imports inside evaluated modules. */
8
- resolveModule: TransformResolver;
9
- classNameHashSalt?: string;
10
- /**
11
- * Returns the evaluated CSS rules in the file result metadata
12
- * @default false
13
- */
14
- generateMetadata?: boolean;
15
- /** Defines set of modules and imports handled by a transformPlugin. */
16
- importsToTransform?: string[];
17
- /** Defines the set of function names that should be treated as Griffel style calls. */
18
- functionsToTransform?: FunctionKinds[];
19
- /** The set of rules that defines how the matched files will be transformed during the evaluation. */
20
- evaluationRules?: EvalRule[];
21
- /** Plugins for extending AST evaluation with custom node handling. */
22
- astEvaluationPlugins?: AstEvaluatorPlugin[];
23
- /**
24
- * Collects performance issues (CJS modules, barrel re-exports) during evaluation.
25
- * @default false
26
- */
27
- collectPerfIssues?: boolean;
28
- };
29
- export type TransformResult = {
30
- code: string;
31
- cssRulesByBucket?: CSSRulesByBucket;
32
- usedProcessing: boolean;
33
- usedVMForEvaluation: boolean;
34
- perfIssues?: TransformPerfIssue[];
35
- };
36
- type FunctionKinds = 'makeStyles' | 'makeResetStyles' | 'makeStaticStyles';
37
- /**
38
- * Transforms passed source code with oxc-parser and oxc-walker instead of Babel.
39
- */
40
- export declare function transformSync(sourceCode: string, options: TransformOptions): TransformResult;
41
- export {};