Skip to content

Commit 4e637d6

Browse files
layershifterclaude
andauthored
feat: switch from @linaria/shaker to @griffel/transform-shaker (#795)
* feat(transform): replace @linaria/shaker with @griffel/transform-shaker Replace the external @linaria/shaker dependency with the internal @griffel/transform-shaker package. Since the new shaker produces ESM output (vs Babel-compiled CJS from the old shaker), add an ESM→CJS converter in Module.evaluate so code can run inside vm.Script's function wrapper. Also fix several shaker graph-builder bugs uncovered during integration: - ImportDeclaration not kept alive when its bindings are referenced - ExportNamedDeclaration declarators removed from shaken output - Missing TemplateLiteral:expressions and SpreadElement:argument handlers - Computed Property:key not treated as a variable reference Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: remove StrictOptions, babelOptions, and simplify Evaluator signature - Remove StrictOptions type (was just { rules: EvalRule[] }) - Remove babelOptions from TransformOptions and all call sites - Simplify Evaluator to (filename, text, only) => [string, Map | null] - Module class now takes rules: EvalRule[] directly - Remove config-babel-options fixture and test - Remove private: true from transform-shaker - Add @griffel/transform-shaker dependency, remove oxc-transform Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Change files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: revert snapshot changes, rename _shakerEvaluator Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d5bcd3b commit 4e637d6

24 files changed

Lines changed: 79 additions & 167 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Initial release of @griffel/transform-shaker",
4+
"packageName": "@griffel/transform-shaker",
5+
"email": "olfedias@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "BREAKING: Replace @linaria/shaker with @griffel/transform-shaker. Remove babelOptions from TransformOptions. Remove StrictOptions type.",
4+
"packageName": "@griffel/transform",
5+
"email": "olfedias@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "BREAKING: Remove babelOptions from WebpackLoaderOptions. Uses @griffel/transform-shaker instead of @linaria/shaker.",
4+
"packageName": "@griffel/webpack-plugin",
5+
"email": "olfedias@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/transform-shaker/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "@griffel/transform-shaker",
3-
"private": true,
43
"version": "1.0.0",
54
"description": "Tree-shaking evaluator for Griffel transform, based on @linaria/shaker",
65
"license": "MIT",

packages/transform-shaker/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function prepareForShake(filename: string, code: string): { program: Program; co
3737
return { program: parsed.program, code: sourceCode };
3838
}
3939

40-
const shaker: Evaluator = (filename, options, text, only = null) => {
40+
const shaker: Evaluator = (filename, text, only = null) => {
4141
const { program, code } = prepareForShake(filename, text);
4242
const [shakenCode, imports] = shake(program, code, only);
4343
return [shakenCode, imports];

packages/transform-shaker/src/shaker.test.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,7 @@ function getFileName() {
1717
function _shake(only: string[] = ['__linariaPreval']) {
1818
return (literal: TemplateStringsArray, ...placeholders: string[]): [string, Map<string, string[]>] => {
1919
const code = dedent(literal, ...placeholders);
20-
const [shaken, deps] = shaker(
21-
getFileName(),
22-
{
23-
displayName: true,
24-
evaluate: true,
25-
rules: [
26-
{
27-
action: shaker,
28-
},
29-
{
30-
test: /\/node_modules\//,
31-
action: 'ignore',
32-
},
33-
],
34-
},
35-
code,
36-
only,
37-
);
20+
const [shaken, deps] = shaker(getFileName(), code, only);
3821

3922
return [shaken, deps!];
4023
};

packages/transform-shaker/src/utils.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,16 @@ export const warn = log.bind(null, 'warn');
5959

6060
// --- From @linaria/babel-preset types ---
6161

62-
export type Evaluator = (
63-
filename: string,
64-
options: StrictOptions,
65-
text: string,
66-
only: string[] | null,
67-
) => [string, Map<string, string[]> | null];
68-
6962
export type EvalRule = {
7063
test?: RegExp | ((path: string) => boolean);
7164
action: Evaluator | 'ignore' | string;
7265
};
7366

74-
export type StrictOptions = {
75-
classNameSlug?: string | ((...args: unknown[]) => string);
76-
displayName: boolean;
77-
evaluate: boolean;
78-
ignore?: RegExp;
79-
rules: EvalRule[];
80-
};
67+
export type Evaluator = (
68+
filename: string,
69+
text: string,
70+
only: string[] | null,
71+
) => [string, Map<string, string[]> | null];
8172

8273
// --- Invariant utility (replaces ts-invariant) ---
8374

packages/transform/__fixtures__/config-babel-options/code.ts

Whitespace-only changes.

packages/transform/__fixtures__/config-babel-options/colorRenamePlugin.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/transform/__fixtures__/config-babel-options/output.meta.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)