@tamagui/metro-plugin 3.0.0-beta.655.1 → 3.0.0-beta.669.1
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/dist/cjs/index.cjs +3 -1
- package/dist/cjs/transformer.cjs +32 -10
- package/dist/esm/index.mjs +3 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/transformer.mjs +32 -10
- package/dist/esm/transformer.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +2 -0
- package/src/transformer.ts +52 -21
- package/types/index.d.ts.map +2 -2
- package/types/transformer.d.ts +5 -0
- package/types/transformer.d.ts.map +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -56,6 +56,7 @@ function getMetroCompilerFrontend(metroConfig) {
|
|
|
56
56
|
function withTamagui(metroConfig, optionsIn) {
|
|
57
57
|
const { compilerCacheRoot, zeroIslandBuild, zeroPublicDir = "public", ...tamaguiOptionsIn } = optionsIn || {};
|
|
58
58
|
const options = loadTamaguiBuildConfigSync(tamaguiOptionsIn);
|
|
59
|
+
const webRuntimeFeatures = import_static.default.resolveWebRuntimeFeatureLiterals(options);
|
|
59
60
|
metroConfig.resolver = {
|
|
60
61
|
...metroConfig.resolver,
|
|
61
62
|
sourceExts: [.../* @__PURE__ */ new Set([...metroConfig.resolver?.sourceExts || [], "css"])]
|
|
@@ -92,7 +93,8 @@ function withTamagui(metroConfig, optionsIn) {
|
|
|
92
93
|
cacheBaseRoot,
|
|
93
94
|
originalBabelTransformerPath,
|
|
94
95
|
projectRoot,
|
|
95
|
-
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full"
|
|
96
|
+
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full",
|
|
97
|
+
webRuntimeFeatures
|
|
96
98
|
});
|
|
97
99
|
const userGetTransformOptions = metroConfig.transformer.getTransformOptions;
|
|
98
100
|
metroConfig.transformer.getTransformOptions = (0, import_transformOptions.composeMetroGetTransformOptions)(frontend, userGetTransformOptions);
|
package/dist/cjs/transformer.cjs
CHANGED
|
@@ -53,20 +53,42 @@ function createMetroCompilerTransformer(config) {
|
|
|
53
53
|
return (0, import_metroResolver.isCompilerSourceFile)(moduleId) && !moduleId.includes(`${(0, import_node_path.join)("node_modules")}`) && (0, import_node_fs.existsSync)(moduleId);
|
|
54
54
|
}
|
|
55
55
|
const runtimeLiteral = config.runtimeLiteral ?? "full";
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
const inlineRuntimeLiterals = (platform, { types }) => {
|
|
57
|
+
const enabledFeatures = {
|
|
58
|
+
inlineThemeValues: "enabled",
|
|
59
|
+
styleValueGrammar: "enabled",
|
|
60
|
+
safeArea: "enabled"
|
|
61
|
+
};
|
|
62
|
+
const features = platform === "web" ? {
|
|
63
|
+
...enabledFeatures,
|
|
64
|
+
...config.webRuntimeFeatures
|
|
65
|
+
} : enabledFeatures;
|
|
66
|
+
const featureByName = {
|
|
67
|
+
TAMAGUI_RUNTIME_INLINE_THEME_VALUES: features.inlineThemeValues,
|
|
68
|
+
TAMAGUI_RUNTIME_STYLE_VALUE_GRAMMAR: features.styleValueGrammar,
|
|
69
|
+
TAMAGUI_RUNTIME_SAFE_AREA: features.safeArea
|
|
70
|
+
};
|
|
71
|
+
return { visitor: { MemberExpression(nodePath) {
|
|
72
|
+
const node = nodePath.node;
|
|
73
|
+
if (node.computed || !types.isMemberExpression(node.object) || node.object.computed || !types.isIdentifier(node.object.object, { name: "process" }) || !types.isIdentifier(node.object.property, { name: "env" })) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const name = types.isIdentifier(node.property) ? node.property.name : "";
|
|
77
|
+
if (name === "TAMAGUI_RUNTIME") {
|
|
78
|
+
nodePath.replaceWith(types.stringLiteral(runtimeLiteral));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const literal = featureByName[name];
|
|
82
|
+
if (literal) nodePath.replaceWith(types.stringLiteral(literal));
|
|
83
|
+
} } };
|
|
84
|
+
};
|
|
63
85
|
return {
|
|
64
86
|
async transform(argsIn) {
|
|
87
|
+
const platform = typeof argsIn.options.platform === "string" ? argsIn.options.platform : "default";
|
|
65
88
|
const args = {
|
|
66
89
|
...argsIn,
|
|
67
|
-
plugins: [...argsIn.plugins ?? [],
|
|
90
|
+
plugins: [...argsIn.plugins ?? [], (babel) => inlineRuntimeLiterals(platform, babel)]
|
|
68
91
|
};
|
|
69
|
-
const platform = typeof args.options.platform === "string" ? args.options.platform : "default";
|
|
70
92
|
const cache = new import_compilerCache.MetroCompilerCache((0, import_node_path.join)(config.cacheBaseRoot, platform));
|
|
71
93
|
let tamagui = {
|
|
72
94
|
cacheHit: false,
|
|
@@ -122,7 +144,7 @@ function createMetroCompilerTransformer(config) {
|
|
|
122
144
|
};
|
|
123
145
|
},
|
|
124
146
|
getCacheKey() {
|
|
125
|
-
return (0, import_node_crypto.createHash)("sha256").update(`tamagui-metro-compiler-v${import_compilerCache.METRO_COMPILER_CACHE_VERSION}`).update("\0").update(runtimeLiteral).update("\0").update((0, import_babel.userBabelCacheKey)(config.originalBabelTransformerPath)).digest("hex");
|
|
147
|
+
return (0, import_node_crypto.createHash)("sha256").update(`tamagui-metro-compiler-v${import_compilerCache.METRO_COMPILER_CACHE_VERSION}`).update("\0").update(runtimeLiteral).update("\0").update(JSON.stringify(config.webRuntimeFeatures ?? {})).update("\0").update((0, import_babel.userBabelCacheKey)(config.originalBabelTransformerPath)).digest("hex");
|
|
126
148
|
}
|
|
127
149
|
};
|
|
128
150
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -18,6 +18,7 @@ function getMetroCompilerFrontend(metroConfig) {
|
|
|
18
18
|
function withTamagui(metroConfig, optionsIn) {
|
|
19
19
|
const { compilerCacheRoot, zeroIslandBuild, zeroPublicDir = "public", ...tamaguiOptionsIn } = optionsIn || {};
|
|
20
20
|
const options = loadTamaguiBuildConfigSync(tamaguiOptionsIn);
|
|
21
|
+
const webRuntimeFeatures = Static.resolveWebRuntimeFeatureLiterals(options);
|
|
21
22
|
metroConfig.resolver = {
|
|
22
23
|
...metroConfig.resolver,
|
|
23
24
|
sourceExts: [.../* @__PURE__ */ new Set([...metroConfig.resolver?.sourceExts || [], "css"])]
|
|
@@ -54,7 +55,8 @@ function withTamagui(metroConfig, optionsIn) {
|
|
|
54
55
|
cacheBaseRoot,
|
|
55
56
|
originalBabelTransformerPath,
|
|
56
57
|
projectRoot,
|
|
57
|
-
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full"
|
|
58
|
+
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full",
|
|
59
|
+
webRuntimeFeatures
|
|
58
60
|
});
|
|
59
61
|
const userGetTransformOptions = metroConfig.transformer.getTransformOptions;
|
|
60
62
|
metroConfig.transformer.getTransformOptions = composeMetroGetTransformOptions(frontend, userGetTransformOptions);
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { isAbsolute, join } from \"node:path\";\nimport Static from \"@tamagui/static\";\nimport { defaultMetroCompilerCacheRoot } from \"./compilerCache\";\nimport { applyMetroZeroRuntime } from \"./zeroSerializer\";\nimport { createMetroZeroController } from \"./zeroRuntime\";\nimport { formatMetroCompilerDiagnostic } from \"./diagnostics\";\nimport { MetroCompilerFrontend } from \"./frontend\";\nimport { writeMetroCompilerTransformerBridge } from \"./transformer\";\nimport { composeMetroGetTransformOptions } from \"./transformOptions\";\nimport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError,\n defaultMetroCompilerCacheRoot as defaultMetroCompilerCacheRoot2\n} from \"./compilerCache\";\nconst frontends = /* @__PURE__ */ new WeakMap();\nconst { loadTamaguiBuildConfigSync } = Static;\nconst requireFromPlugin = createRequire(\n typeof __filename === \"string\" ? __filename : import.meta.url\n);\nfunction getMetroCompilerFrontend(metroConfig) {\n return frontends.get(metroConfig) ?? null;\n}\nfunction withTamagui(metroConfig, optionsIn) {\n const {\n compilerCacheRoot,\n zeroIslandBuild,\n zeroPublicDir = \"public\",\n ...tamaguiOptionsIn\n } = optionsIn || {};\n const options = loadTamaguiBuildConfigSync(tamaguiOptionsIn);\n metroConfig.resolver = {\n ...metroConfig.resolver,\n sourceExts: [.../* @__PURE__ */ new Set([...metroConfig.resolver?.sourceExts || [], \"css\"])]\n };\n metroConfig.transformer = {\n ...metroConfig.transformer,\n tamagui: options\n };\n const zeroProjectRoot = metroConfig.projectRoot ?? process.cwd();\n const zero = createMetroZeroController(\n options,\n zeroProjectRoot,\n zeroIslandBuild ?? null,\n zeroPublicDir\n );\n if (zero?.isEnforcing) {\n applyMetroZeroRuntime(metroConfig, zero);\n }\n if (!options.disable) {\n const projectRoot = metroConfig.projectRoot ?? process.cwd();\n const requireFromProject = createRequire(join(projectRoot, \"package.json\"));\n const configuredBabelTransformerPath = metroConfig.transformer.babelTransformerPath ?? \"metro-babel-transformer\";\n const originalBabelTransformerPath = isAbsolute(configuredBabelTransformerPath) ? configuredBabelTransformerPath : requireFromProject.resolve(configuredBabelTransformerPath);\n const cacheBaseRoot = compilerCacheRoot ?? defaultMetroCompilerCacheRoot(projectRoot);\n const frontend = new MetroCompilerFrontend({\n projectRoot,\n resolver: metroConfig.resolver,\n transformer: metroConfig.transformer,\n tamaguiOptions: options,\n originalBabelTransformerPath,\n cacheRoot: cacheBaseRoot,\n zero,\n reportDiagnostic(diagnostic) {\n console.warn(formatMetroCompilerDiagnostic(diagnostic, projectRoot));\n }\n });\n const transformerFactoryPath = requireFromPlugin.resolve(\n \"@tamagui/metro-plugin/transformer\"\n );\n metroConfig.transformer.babelTransformerPath = writeMetroCompilerTransformerBridge(\n transformerFactoryPath,\n {\n cacheBaseRoot,\n originalBabelTransformerPath,\n projectRoot,\n // an integration-owned literal, never an ambient shell value\n runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? \"zero\" : \"full\"\n }\n );\n const userGetTransformOptions = metroConfig.transformer.getTransformOptions;\n metroConfig.transformer.getTransformOptions = composeMetroGetTransformOptions(\n frontend,\n userGetTransformOptions\n );\n frontends.set(metroConfig, frontend);\n }\n return metroConfig;\n}\nexport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError,\n defaultMetroCompilerCacheRoot2 as defaultMetroCompilerCacheRoot,\n getMetroCompilerFrontend,\n withTamagui\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAM,4BAA4B,IAAI,QAAQ;AAC9C,MAAM,EAAE,+BAA+B;AACvC,MAAM,oBAAoB,cACxB,OAAO,eAAe,WAAW,aAAa,OAAO,KAAK,GAC5D;AACA,SAAS,yBAAyB,aAAa;CAC7C,OAAO,UAAU,IAAI,WAAW,KAAK;AACvC;AACA,SAAS,YAAY,aAAa,WAAW;CAC3C,MAAM,EACJ,mBACA,iBACA,gBAAgB,UAChB,GAAG,qBACD,aAAa,CAAC;CAClB,MAAM,UAAU,2BAA2B,gBAAgB;CAC3D,YAAY,WAAW;EACrB,GAAG,YAAY;EACf,YAAY,CAAC,mBAAmB,IAAI,IAAI,CAAC,GAAG,YAAY,UAAU,cAAc,CAAC,GAAG,KAAK,CAAC,CAAC;CAC7F;CACA,YAAY,cAAc;EACxB,GAAG,YAAY;EACf,SAAS;CACX;CACA,MAAM,kBAAkB,YAAY,eAAe,QAAQ,IAAI;CAC/D,MAAM,OAAO,0BACX,SACA,iBACA,mBAAmB,MACnB,aACF;CACA,IAAI,MAAM,aAAa;EACrB,sBAAsB,aAAa,IAAI;CACzC;CACA,IAAI,CAAC,QAAQ,SAAS;EACpB,MAAM,cAAc,YAAY,eAAe,QAAQ,IAAI;EAC3D,MAAM,qBAAqB,cAAc,KAAK,aAAa,cAAc,CAAC;EAC1E,MAAM,iCAAiC,YAAY,YAAY,wBAAwB;EACvF,MAAM,+BAA+B,WAAW,8BAA8B,IAAI,iCAAiC,mBAAmB,QAAQ,8BAA8B;EAC5K,MAAM,gBAAgB,qBAAqB,8BAA8B,WAAW;EACpF,MAAM,WAAW,IAAI,sBAAsB;GACzC;GACA,UAAU,YAAY;GACtB,aAAa,YAAY;GACzB,gBAAgB;GAChB;GACA,WAAW;GACX;GACA,iBAAiB,YAAY;IAC3B,QAAQ,KAAK,8BAA8B,YAAY,WAAW,CAAC;GACrE;EACF,CAAC;EACD,MAAM,yBAAyB,kBAAkB,QAC/C,mCACF;EACA,YAAY,YAAY,uBAAuB,oCAC7C,wBACA;GACE;GACA;GACA;GAEA,gBAAgB,MAAM,eAAe,CAAC,KAAK,cAAc,SAAS;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { isAbsolute, join } from \"node:path\";\nimport Static from \"@tamagui/static\";\nimport { defaultMetroCompilerCacheRoot } from \"./compilerCache\";\nimport { applyMetroZeroRuntime } from \"./zeroSerializer\";\nimport { createMetroZeroController } from \"./zeroRuntime\";\nimport { formatMetroCompilerDiagnostic } from \"./diagnostics\";\nimport { MetroCompilerFrontend } from \"./frontend\";\nimport { writeMetroCompilerTransformerBridge } from \"./transformer\";\nimport { composeMetroGetTransformOptions } from \"./transformOptions\";\nimport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError,\n defaultMetroCompilerCacheRoot as defaultMetroCompilerCacheRoot2\n} from \"./compilerCache\";\nconst frontends = /* @__PURE__ */ new WeakMap();\nconst { loadTamaguiBuildConfigSync } = Static;\nconst requireFromPlugin = createRequire(\n typeof __filename === \"string\" ? __filename : import.meta.url\n);\nfunction getMetroCompilerFrontend(metroConfig) {\n return frontends.get(metroConfig) ?? null;\n}\nfunction withTamagui(metroConfig, optionsIn) {\n const {\n compilerCacheRoot,\n zeroIslandBuild,\n zeroPublicDir = \"public\",\n ...tamaguiOptionsIn\n } = optionsIn || {};\n const options = loadTamaguiBuildConfigSync(tamaguiOptionsIn);\n const webRuntimeFeatures = Static.resolveWebRuntimeFeatureLiterals(options);\n metroConfig.resolver = {\n ...metroConfig.resolver,\n sourceExts: [.../* @__PURE__ */ new Set([...metroConfig.resolver?.sourceExts || [], \"css\"])]\n };\n metroConfig.transformer = {\n ...metroConfig.transformer,\n tamagui: options\n };\n const zeroProjectRoot = metroConfig.projectRoot ?? process.cwd();\n const zero = createMetroZeroController(\n options,\n zeroProjectRoot,\n zeroIslandBuild ?? null,\n zeroPublicDir\n );\n if (zero?.isEnforcing) {\n applyMetroZeroRuntime(metroConfig, zero);\n }\n if (!options.disable) {\n const projectRoot = metroConfig.projectRoot ?? process.cwd();\n const requireFromProject = createRequire(join(projectRoot, \"package.json\"));\n const configuredBabelTransformerPath = metroConfig.transformer.babelTransformerPath ?? \"metro-babel-transformer\";\n const originalBabelTransformerPath = isAbsolute(configuredBabelTransformerPath) ? configuredBabelTransformerPath : requireFromProject.resolve(configuredBabelTransformerPath);\n const cacheBaseRoot = compilerCacheRoot ?? defaultMetroCompilerCacheRoot(projectRoot);\n const frontend = new MetroCompilerFrontend({\n projectRoot,\n resolver: metroConfig.resolver,\n transformer: metroConfig.transformer,\n tamaguiOptions: options,\n originalBabelTransformerPath,\n cacheRoot: cacheBaseRoot,\n zero,\n reportDiagnostic(diagnostic) {\n console.warn(formatMetroCompilerDiagnostic(diagnostic, projectRoot));\n }\n });\n const transformerFactoryPath = requireFromPlugin.resolve(\n \"@tamagui/metro-plugin/transformer\"\n );\n metroConfig.transformer.babelTransformerPath = writeMetroCompilerTransformerBridge(\n transformerFactoryPath,\n {\n cacheBaseRoot,\n originalBabelTransformerPath,\n projectRoot,\n // an integration-owned literal, never an ambient shell value\n runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? \"zero\" : \"full\",\n webRuntimeFeatures\n }\n );\n const userGetTransformOptions = metroConfig.transformer.getTransformOptions;\n metroConfig.transformer.getTransformOptions = composeMetroGetTransformOptions(\n frontend,\n userGetTransformOptions\n );\n frontends.set(metroConfig, frontend);\n }\n return metroConfig;\n}\nexport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError,\n defaultMetroCompilerCacheRoot2 as defaultMetroCompilerCacheRoot,\n getMetroCompilerFrontend,\n withTamagui\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAM,4BAA4B,IAAI,QAAQ;AAC9C,MAAM,EAAE,+BAA+B;AACvC,MAAM,oBAAoB,cACxB,OAAO,eAAe,WAAW,aAAa,OAAO,KAAK,GAC5D;AACA,SAAS,yBAAyB,aAAa;CAC7C,OAAO,UAAU,IAAI,WAAW,KAAK;AACvC;AACA,SAAS,YAAY,aAAa,WAAW;CAC3C,MAAM,EACJ,mBACA,iBACA,gBAAgB,UAChB,GAAG,qBACD,aAAa,CAAC;CAClB,MAAM,UAAU,2BAA2B,gBAAgB;CAC3D,MAAM,qBAAqB,OAAO,iCAAiC,OAAO;CAC1E,YAAY,WAAW;EACrB,GAAG,YAAY;EACf,YAAY,CAAC,mBAAmB,IAAI,IAAI,CAAC,GAAG,YAAY,UAAU,cAAc,CAAC,GAAG,KAAK,CAAC,CAAC;CAC7F;CACA,YAAY,cAAc;EACxB,GAAG,YAAY;EACf,SAAS;CACX;CACA,MAAM,kBAAkB,YAAY,eAAe,QAAQ,IAAI;CAC/D,MAAM,OAAO,0BACX,SACA,iBACA,mBAAmB,MACnB,aACF;CACA,IAAI,MAAM,aAAa;EACrB,sBAAsB,aAAa,IAAI;CACzC;CACA,IAAI,CAAC,QAAQ,SAAS;EACpB,MAAM,cAAc,YAAY,eAAe,QAAQ,IAAI;EAC3D,MAAM,qBAAqB,cAAc,KAAK,aAAa,cAAc,CAAC;EAC1E,MAAM,iCAAiC,YAAY,YAAY,wBAAwB;EACvF,MAAM,+BAA+B,WAAW,8BAA8B,IAAI,iCAAiC,mBAAmB,QAAQ,8BAA8B;EAC5K,MAAM,gBAAgB,qBAAqB,8BAA8B,WAAW;EACpF,MAAM,WAAW,IAAI,sBAAsB;GACzC;GACA,UAAU,YAAY;GACtB,aAAa,YAAY;GACzB,gBAAgB;GAChB;GACA,WAAW;GACX;GACA,iBAAiB,YAAY;IAC3B,QAAQ,KAAK,8BAA8B,YAAY,WAAW,CAAC;GACrE;EACF,CAAC;EACD,MAAM,yBAAyB,kBAAkB,QAC/C,mCACF;EACA,YAAY,YAAY,uBAAuB,oCAC7C,wBACA;GACE;GACA;GACA;GAEA,gBAAgB,MAAM,eAAe,CAAC,KAAK,cAAc,SAAS;GAClE;EACF,CACF;EACA,MAAM,0BAA0B,YAAY,YAAY;EACxD,YAAY,YAAY,sBAAsB,gCAC5C,UACA,uBACF;EACA,UAAU,IAAI,aAAa,QAAQ;CACrC;CACA,OAAO;AACT"}
|
package/dist/esm/transformer.mjs
CHANGED
|
@@ -27,20 +27,42 @@ function createMetroCompilerTransformer(config) {
|
|
|
27
27
|
return isCompilerSourceFile(moduleId) && !moduleId.includes(`${join("node_modules")}`) && existsSync(moduleId);
|
|
28
28
|
}
|
|
29
29
|
const runtimeLiteral = config.runtimeLiteral ?? "full";
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const inlineRuntimeLiterals = (platform, { types }) => {
|
|
31
|
+
const enabledFeatures = {
|
|
32
|
+
inlineThemeValues: "enabled",
|
|
33
|
+
styleValueGrammar: "enabled",
|
|
34
|
+
safeArea: "enabled"
|
|
35
|
+
};
|
|
36
|
+
const features = platform === "web" ? {
|
|
37
|
+
...enabledFeatures,
|
|
38
|
+
...config.webRuntimeFeatures
|
|
39
|
+
} : enabledFeatures;
|
|
40
|
+
const featureByName = {
|
|
41
|
+
TAMAGUI_RUNTIME_INLINE_THEME_VALUES: features.inlineThemeValues,
|
|
42
|
+
TAMAGUI_RUNTIME_STYLE_VALUE_GRAMMAR: features.styleValueGrammar,
|
|
43
|
+
TAMAGUI_RUNTIME_SAFE_AREA: features.safeArea
|
|
44
|
+
};
|
|
45
|
+
return { visitor: { MemberExpression(nodePath) {
|
|
46
|
+
const node = nodePath.node;
|
|
47
|
+
if (node.computed || !types.isMemberExpression(node.object) || node.object.computed || !types.isIdentifier(node.object.object, { name: "process" }) || !types.isIdentifier(node.object.property, { name: "env" })) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const name = types.isIdentifier(node.property) ? node.property.name : "";
|
|
51
|
+
if (name === "TAMAGUI_RUNTIME") {
|
|
52
|
+
nodePath.replaceWith(types.stringLiteral(runtimeLiteral));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const literal = featureByName[name];
|
|
56
|
+
if (literal) nodePath.replaceWith(types.stringLiteral(literal));
|
|
57
|
+
} } };
|
|
58
|
+
};
|
|
37
59
|
return {
|
|
38
60
|
async transform(argsIn) {
|
|
61
|
+
const platform = typeof argsIn.options.platform === "string" ? argsIn.options.platform : "default";
|
|
39
62
|
const args = {
|
|
40
63
|
...argsIn,
|
|
41
|
-
plugins: [...argsIn.plugins ?? [],
|
|
64
|
+
plugins: [...argsIn.plugins ?? [], (babel) => inlineRuntimeLiterals(platform, babel)]
|
|
42
65
|
};
|
|
43
|
-
const platform = typeof args.options.platform === "string" ? args.options.platform : "default";
|
|
44
66
|
const cache = new MetroCompilerCache(join(config.cacheBaseRoot, platform));
|
|
45
67
|
let tamagui = {
|
|
46
68
|
cacheHit: false,
|
|
@@ -96,7 +118,7 @@ function createMetroCompilerTransformer(config) {
|
|
|
96
118
|
};
|
|
97
119
|
},
|
|
98
120
|
getCacheKey() {
|
|
99
|
-
return createHash("sha256").update(`tamagui-metro-compiler-v${METRO_COMPILER_CACHE_VERSION}`).update("\0").update(runtimeLiteral).update("\0").update(userBabelCacheKey(config.originalBabelTransformerPath)).digest("hex");
|
|
121
|
+
return createHash("sha256").update(`tamagui-metro-compiler-v${METRO_COMPILER_CACHE_VERSION}`).update("\0").update(runtimeLiteral).update("\0").update(JSON.stringify(config.webRuntimeFeatures ?? {})).update("\0").update(userBabelCacheKey(config.originalBabelTransformerPath)).digest("hex");
|
|
100
122
|
}
|
|
101
123
|
};
|
|
102
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.js","names":[],"sources":["esm/transformer.js"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, realpathSync, renameSync, writeFileSync } from \"node:fs\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport {\n compileWithUserBabel,\n userBabelCacheKey\n} from \"./babel\";\nimport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError\n} from \"./compilerCache\";\nimport {\n formatMetroCompilerDiagnostic,\n metroDiagnostic\n} from \"./diagnostics\";\nimport { isCompilerSourceFile } from \"./metroResolver\";\nimport { applyMetroCompilerPlan } from \"./lowering\";\nfunction createMetroCompilerTransformer(config) {\n const moduleIdCache = /* @__PURE__ */ new Map();\n const missWarned = /* @__PURE__ */ new Set();\n function cacheModuleId(filename) {\n let id = moduleIdCache.get(filename);\n if (!id) {\n const absolute = isAbsolute(filename) ? filename : resolve(config.projectRoot, filename);\n try {\n id = realpathSync(absolute);\n } catch {\n id = absolute;\n }\n moduleIdCache.set(filename, id);\n }\n return id;\n }\n function planEligible(moduleId) {\n return isCompilerSourceFile(moduleId) && !moduleId.includes(`${join(\"node_modules\")}`) && existsSync(moduleId);\n }\n const runtimeLiteral = config.runtimeLiteral ?? \"full\";\n const inlineRuntimeLiteral = ({ types }) => ({\n visitor: {\n MemberExpression(nodePath) {\n const node = nodePath.node;\n if (node.computed || !types.isIdentifier(node.property, { name: \"TAMAGUI_RUNTIME\" }) || !types.isMemberExpression(node.object) || node.object.computed || !types.isIdentifier(node.object.object, { name: \"process\" }) || !types.isIdentifier(node.object.property, { name: \"env\" })) {\n return;\n }\n nodePath.replaceWith(types.stringLiteral(runtimeLiteral));\n }\n }\n });\n return {\n async transform(argsIn) {\n const args = {\n ...argsIn,\n plugins: [...argsIn.plugins ?? [], inlineRuntimeLiteral]\n };\n const platform = typeof args.options.platform === \"string\" ? args.options.platform : \"default\";\n const cache = new MetroCompilerCache(join(config.cacheBaseRoot, platform));\n let tamagui = {\n cacheHit: false,\n diagnostics: []\n };\n const moduleId = cacheModuleId(args.filename);\n try {\n const entry = await cache.read(moduleId, args.src, (reason, detail) => {\n if (missWarned.has(moduleId) || !planEligible(moduleId)) return;\n missWarned.add(moduleId);\n const diagnostic = metroDiagnostic(\n \"metro/plan-miss\",\n `Lowering plan lookup missed for ${moduleId} (${reason}${detail ? `: ${detail}` : \"\"}); module ships unlowered`,\n { moduleId }\n );\n tamagui.diagnostics.push(diagnostic);\n console.warn(formatMetroCompilerDiagnostic(diagnostic, config.projectRoot));\n });\n if (entry) {\n try {\n const lowered = await applyMetroCompilerPlan(\n { ...args, filename: moduleId },\n entry.plan,\n config.originalBabelTransformerPath\n );\n return {\n ...lowered.compiled.result,\n metadata: {\n ...lowered.compiled.result.metadata,\n tamagui: {\n cacheHit: true,\n diagnostics: entry.diagnostics,\n lowering: lowered.lowering\n }\n }\n };\n } catch (error) {\n const diagnostic = metroDiagnostic(\n \"metro/cache-corrupt\",\n `Cached lowering plan for ${args.filename} could not be applied: ${error instanceof Error ? error.message : String(error)}`,\n { moduleId }\n );\n tamagui = {\n cacheHit: true,\n diagnostics: [...entry.diagnostics, diagnostic]\n };\n console.warn(formatMetroCompilerDiagnostic(diagnostic, config.projectRoot));\n }\n }\n } catch (error) {\n if (!(error instanceof MetroCompilerCacheError)) throw error;\n tamagui.diagnostics.push(error.diagnostic);\n console.warn(formatMetroCompilerDiagnostic(error.diagnostic, config.projectRoot));\n }\n const compiled = await compileWithUserBabel(\n config.originalBabelTransformerPath,\n args\n );\n return {\n ...compiled.result,\n metadata: {\n ...compiled.result.metadata,\n tamagui\n }\n };\n },\n getCacheKey() {\n return createHash(\"sha256\").update(`tamagui-metro-compiler-v${METRO_COMPILER_CACHE_VERSION}`).update(\"\\0\").update(runtimeLiteral).update(\"\\0\").update(userBabelCacheKey(config.originalBabelTransformerPath)).digest(\"hex\");\n }\n };\n}\nfunction writeMetroCompilerTransformerBridge(transformerFactoryPath, config) {\n const serializedConfig = JSON.stringify(config);\n const bridgeHash = createHash(\"sha256\").update(transformerFactoryPath).update(\"\\0\").update(serializedConfig).digest(\"hex\");\n const directory = join(config.cacheBaseRoot, \"bridge\");\n const bridgePath = join(directory, `${bridgeHash}.cjs`);\n const temporaryPath = `${bridgePath}.${process.pid}.tmp`;\n const source = `'use strict'\nmodule.exports = require(${JSON.stringify(\n transformerFactoryPath\n )}).createMetroCompilerTransformer(${serializedConfig})\n`;\n mkdirSync(directory, { recursive: true });\n writeFileSync(temporaryPath, source, \"utf8\");\n renameSync(temporaryPath, bridgePath);\n return bridgePath;\n}\nexport {\n createMetroCompilerTransformer,\n writeMetroCompilerTransformerBridge\n};\n//# sourceMappingURL=transformer.js.map\n"],"mappings":";;;;;;;;;;AAkBA,SAAS,+BAA+B,QAAQ;CAC9C,MAAM,gCAAgC,IAAI,IAAI;CAC9C,MAAM,6BAA6B,IAAI,IAAI;CAC3C,SAAS,cAAc,UAAU;EAC/B,IAAI,KAAK,cAAc,IAAI,QAAQ;EACnC,IAAI,CAAC,IAAI;GACP,MAAM,WAAW,WAAW,QAAQ,IAAI,WAAW,QAAQ,OAAO,aAAa,QAAQ;GACvF,IAAI;IACF,KAAK,aAAa,QAAQ;GAC5B,QAAQ;IACN,KAAK;GACP;GACA,cAAc,IAAI,UAAU,EAAE;EAChC;EACA,OAAO;CACT;CACA,SAAS,aAAa,UAAU;EAC9B,OAAO,qBAAqB,QAAQ,KAAK,CAAC,SAAS,SAAS,GAAG,KAAK,cAAc,GAAG,KAAK,WAAW,QAAQ;CAC/G;CACA,MAAM,iBAAiB,OAAO,kBAAk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BAAgB,GAAG,WAAW,GAAG,QAAQ,IAAI;CACnD,MAAM,SAAS;2BACU,KAAK,UAC5B,sBACF,EAAE,mCAAmC,iBAAiB;;CAEtD,UAAU,WAAW,EAAE,WAAW,KAAK,CAAC;CACxC,cAAc,eAAe,QAAQ,MAAM;CAC3C,WAAW,eAAe,UAAU;CACpC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"transformer.js","names":[],"sources":["esm/transformer.js"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, realpathSync, renameSync, writeFileSync } from \"node:fs\";\nimport { isAbsolute, join, resolve } from \"node:path\";\nimport {\n compileWithUserBabel,\n userBabelCacheKey\n} from \"./babel\";\nimport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError\n} from \"./compilerCache\";\nimport {\n formatMetroCompilerDiagnostic,\n metroDiagnostic\n} from \"./diagnostics\";\nimport { isCompilerSourceFile } from \"./metroResolver\";\nimport { applyMetroCompilerPlan } from \"./lowering\";\nfunction createMetroCompilerTransformer(config) {\n const moduleIdCache = /* @__PURE__ */ new Map();\n const missWarned = /* @__PURE__ */ new Set();\n function cacheModuleId(filename) {\n let id = moduleIdCache.get(filename);\n if (!id) {\n const absolute = isAbsolute(filename) ? filename : resolve(config.projectRoot, filename);\n try {\n id = realpathSync(absolute);\n } catch {\n id = absolute;\n }\n moduleIdCache.set(filename, id);\n }\n return id;\n }\n function planEligible(moduleId) {\n return isCompilerSourceFile(moduleId) && !moduleId.includes(`${join(\"node_modules\")}`) && existsSync(moduleId);\n }\n const runtimeLiteral = config.runtimeLiteral ?? \"full\";\n const inlineRuntimeLiterals = (platform, { types }) => {\n const enabledFeatures = {\n inlineThemeValues: \"enabled\",\n styleValueGrammar: \"enabled\",\n safeArea: \"enabled\"\n };\n const features = platform === \"web\" ? { ...enabledFeatures, ...config.webRuntimeFeatures } : enabledFeatures;\n const featureByName = {\n TAMAGUI_RUNTIME_INLINE_THEME_VALUES: features.inlineThemeValues,\n TAMAGUI_RUNTIME_STYLE_VALUE_GRAMMAR: features.styleValueGrammar,\n TAMAGUI_RUNTIME_SAFE_AREA: features.safeArea\n };\n return {\n visitor: {\n MemberExpression(nodePath) {\n const node = nodePath.node;\n if (node.computed || !types.isMemberExpression(node.object) || node.object.computed || !types.isIdentifier(node.object.object, { name: \"process\" }) || !types.isIdentifier(node.object.property, { name: \"env\" })) {\n return;\n }\n const name = types.isIdentifier(node.property) ? node.property.name : \"\";\n if (name === \"TAMAGUI_RUNTIME\") {\n nodePath.replaceWith(types.stringLiteral(runtimeLiteral));\n return;\n }\n const literal = featureByName[name];\n if (literal) nodePath.replaceWith(types.stringLiteral(literal));\n }\n }\n };\n };\n return {\n async transform(argsIn) {\n const platform = typeof argsIn.options.platform === \"string\" ? argsIn.options.platform : \"default\";\n const args = {\n ...argsIn,\n plugins: [\n ...argsIn.plugins ?? [],\n (babel) => inlineRuntimeLiterals(platform, babel)\n ]\n };\n const cache = new MetroCompilerCache(join(config.cacheBaseRoot, platform));\n let tamagui = {\n cacheHit: false,\n diagnostics: []\n };\n const moduleId = cacheModuleId(args.filename);\n try {\n const entry = await cache.read(moduleId, args.src, (reason, detail) => {\n if (missWarned.has(moduleId) || !planEligible(moduleId)) return;\n missWarned.add(moduleId);\n const diagnostic = metroDiagnostic(\n \"metro/plan-miss\",\n `Lowering plan lookup missed for ${moduleId} (${reason}${detail ? `: ${detail}` : \"\"}); module ships unlowered`,\n { moduleId }\n );\n tamagui.diagnostics.push(diagnostic);\n console.warn(formatMetroCompilerDiagnostic(diagnostic, config.projectRoot));\n });\n if (entry) {\n try {\n const lowered = await applyMetroCompilerPlan(\n { ...args, filename: moduleId },\n entry.plan,\n config.originalBabelTransformerPath\n );\n return {\n ...lowered.compiled.result,\n metadata: {\n ...lowered.compiled.result.metadata,\n tamagui: {\n cacheHit: true,\n diagnostics: entry.diagnostics,\n lowering: lowered.lowering\n }\n }\n };\n } catch (error) {\n const diagnostic = metroDiagnostic(\n \"metro/cache-corrupt\",\n `Cached lowering plan for ${args.filename} could not be applied: ${error instanceof Error ? error.message : String(error)}`,\n { moduleId }\n );\n tamagui = {\n cacheHit: true,\n diagnostics: [...entry.diagnostics, diagnostic]\n };\n console.warn(formatMetroCompilerDiagnostic(diagnostic, config.projectRoot));\n }\n }\n } catch (error) {\n if (!(error instanceof MetroCompilerCacheError)) throw error;\n tamagui.diagnostics.push(error.diagnostic);\n console.warn(formatMetroCompilerDiagnostic(error.diagnostic, config.projectRoot));\n }\n const compiled = await compileWithUserBabel(\n config.originalBabelTransformerPath,\n args\n );\n return {\n ...compiled.result,\n metadata: {\n ...compiled.result.metadata,\n tamagui\n }\n };\n },\n getCacheKey() {\n return createHash(\"sha256\").update(`tamagui-metro-compiler-v${METRO_COMPILER_CACHE_VERSION}`).update(\"\\0\").update(runtimeLiteral).update(\"\\0\").update(JSON.stringify(config.webRuntimeFeatures ?? {})).update(\"\\0\").update(userBabelCacheKey(config.originalBabelTransformerPath)).digest(\"hex\");\n }\n };\n}\nfunction writeMetroCompilerTransformerBridge(transformerFactoryPath, config) {\n const serializedConfig = JSON.stringify(config);\n const bridgeHash = createHash(\"sha256\").update(transformerFactoryPath).update(\"\\0\").update(serializedConfig).digest(\"hex\");\n const directory = join(config.cacheBaseRoot, \"bridge\");\n const bridgePath = join(directory, `${bridgeHash}.cjs`);\n const temporaryPath = `${bridgePath}.${process.pid}.tmp`;\n const source = `'use strict'\nmodule.exports = require(${JSON.stringify(\n transformerFactoryPath\n )}).createMetroCompilerTransformer(${serializedConfig})\n`;\n mkdirSync(directory, { recursive: true });\n writeFileSync(temporaryPath, source, \"utf8\");\n renameSync(temporaryPath, bridgePath);\n return bridgePath;\n}\nexport {\n createMetroCompilerTransformer,\n writeMetroCompilerTransformerBridge\n};\n//# sourceMappingURL=transformer.js.map\n"],"mappings":";;;;;;;;;;AAkBA,SAAS,+BAA+B,QAAQ;CAC9C,MAAM,gCAAgC,IAAI,IAAI;CAC9C,MA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ugin",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.669.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
44
|
-
"@tamagui/compiler-core": "3.0.0-beta.
|
|
45
|
-
"@tamagui/static": "3.0.0-beta.
|
|
44
|
+
"@tamagui/compiler-core": "3.0.0-beta.669.1",
|
|
45
|
+
"@tamagui/static": "3.0.0-beta.669.1",
|
|
46
46
|
"ignore": "^5.3.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tamagui/build": "3.0.0-beta.
|
|
49
|
+
"@tamagui/build": "3.0.0-beta.669.1",
|
|
50
50
|
"metro": "0.84.4",
|
|
51
51
|
"metro-resolver": "0.84.4"
|
|
52
52
|
},
|
package/src/index.ts
CHANGED
|
@@ -86,6 +86,7 @@ export function withTamagui(
|
|
|
86
86
|
} = optionsIn || {}
|
|
87
87
|
|
|
88
88
|
const options = loadTamaguiBuildConfigSync(tamaguiOptionsIn)
|
|
89
|
+
const webRuntimeFeatures = Static.resolveWebRuntimeFeatureLiterals(options)
|
|
89
90
|
|
|
90
91
|
// Ensure CSS files can be resolved
|
|
91
92
|
metroConfig.resolver = {
|
|
@@ -147,6 +148,7 @@ export function withTamagui(
|
|
|
147
148
|
projectRoot,
|
|
148
149
|
// an integration-owned literal, never an ambient shell value
|
|
149
150
|
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? 'zero' : 'full',
|
|
151
|
+
webRuntimeFeatures,
|
|
150
152
|
}
|
|
151
153
|
)
|
|
152
154
|
const userGetTransformOptions = metroConfig.transformer.getTransformOptions
|
package/src/transformer.ts
CHANGED
|
@@ -31,6 +31,11 @@ export interface MetroCompilerTransformerOptions {
|
|
|
31
31
|
* inlined here so every guard is a constant.
|
|
32
32
|
*/
|
|
33
33
|
runtimeLiteral?: 'full' | 'zero'
|
|
34
|
+
webRuntimeFeatures?: {
|
|
35
|
+
inlineThemeValues: 'enabled' | 'disabled'
|
|
36
|
+
styleValueGrammar: 'enabled' | 'disabled'
|
|
37
|
+
safeArea: 'enabled' | 'disabled'
|
|
38
|
+
}
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export interface MetroCompilerTransformMetadata {
|
|
@@ -75,36 +80,60 @@ export function createMetroCompilerTransformer(config: MetroCompilerTransformerO
|
|
|
75
80
|
existsSync(moduleId)
|
|
76
81
|
)
|
|
77
82
|
}
|
|
78
|
-
// Replaces only the exact
|
|
83
|
+
// Replaces only the integration-owned exact process.env member expressions.
|
|
79
84
|
// Metro has no define mechanism, so this is the transform-level equivalent.
|
|
80
85
|
const runtimeLiteral = config.runtimeLiteral ?? 'full'
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
const inlineRuntimeLiterals = (platform: string, { types }: { types: any }) => {
|
|
87
|
+
const enabledFeatures = {
|
|
88
|
+
inlineThemeValues: 'enabled',
|
|
89
|
+
styleValueGrammar: 'enabled',
|
|
90
|
+
safeArea: 'enabled',
|
|
91
|
+
} as const
|
|
92
|
+
const features =
|
|
93
|
+
platform === 'web'
|
|
94
|
+
? { ...enabledFeatures, ...config.webRuntimeFeatures }
|
|
95
|
+
: enabledFeatures
|
|
96
|
+
const featureByName: Record<string, string> = {
|
|
97
|
+
TAMAGUI_RUNTIME_INLINE_THEME_VALUES: features.inlineThemeValues,
|
|
98
|
+
TAMAGUI_RUNTIME_STYLE_VALUE_GRAMMAR: features.styleValueGrammar,
|
|
99
|
+
TAMAGUI_RUNTIME_SAFE_AREA: features.safeArea,
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
visitor: {
|
|
103
|
+
MemberExpression(nodePath: any) {
|
|
104
|
+
const node = nodePath.node
|
|
105
|
+
if (
|
|
106
|
+
node.computed ||
|
|
107
|
+
!types.isMemberExpression(node.object) ||
|
|
108
|
+
node.object.computed ||
|
|
109
|
+
!types.isIdentifier(node.object.object, { name: 'process' }) ||
|
|
110
|
+
!types.isIdentifier(node.object.property, { name: 'env' })
|
|
111
|
+
) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
const name = types.isIdentifier(node.property) ? node.property.name : ''
|
|
115
|
+
if (name === 'TAMAGUI_RUNTIME') {
|
|
116
|
+
nodePath.replaceWith(types.stringLiteral(runtimeLiteral))
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
const literal = featureByName[name]
|
|
120
|
+
if (literal) nodePath.replaceWith(types.stringLiteral(literal))
|
|
121
|
+
},
|
|
96
122
|
},
|
|
97
|
-
}
|
|
98
|
-
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
99
125
|
|
|
100
126
|
return {
|
|
101
127
|
async transform(argsIn) {
|
|
128
|
+
const platform =
|
|
129
|
+
typeof argsIn.options.platform === 'string' ? argsIn.options.platform : 'default'
|
|
102
130
|
const args = {
|
|
103
131
|
...argsIn,
|
|
104
|
-
plugins: [
|
|
132
|
+
plugins: [
|
|
133
|
+
...(argsIn.plugins ?? []),
|
|
134
|
+
(babel: { types: any }) => inlineRuntimeLiterals(platform, babel),
|
|
135
|
+
],
|
|
105
136
|
}
|
|
106
|
-
const platform =
|
|
107
|
-
typeof args.options.platform === 'string' ? args.options.platform : 'default'
|
|
108
137
|
const cache = new MetroCompilerCache(join(config.cacheBaseRoot, platform))
|
|
109
138
|
let tamagui: MetroCompilerTransformMetadata = {
|
|
110
139
|
cacheHit: false,
|
|
@@ -181,6 +210,8 @@ export function createMetroCompilerTransformer(config: MetroCompilerTransformerO
|
|
|
181
210
|
.update('\0')
|
|
182
211
|
.update(runtimeLiteral)
|
|
183
212
|
.update('\0')
|
|
213
|
+
.update(JSON.stringify(config.webRuntimeFeatures ?? {}))
|
|
214
|
+
.update('\0')
|
|
184
215
|
.update(userBabelCacheKey(config.originalBabelTransformerPath))
|
|
185
216
|
.digest('hex')
|
|
186
217
|
},
|
package/types/index.d.ts.map
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAIA,cAAc,sBAAsB;AAMpC,SAAS,6BAA6B;AAItC,YAAY,sBAAsB,iBAAiB;;CAEjD;;;;;;CAMA;;;;;;;CAOA;;KAIG,mBAAmB;CACtB;CACA;CACA;CACA;;;AAUF,OAAO,iBAAS,yBACd,aAAa,mBACZ;;;;;;;;;;;;;;;;;;;;;;;;AA2BH,OAAO,iBAAS,YACd,aAAa,kBACb,YAAY,sBACX;
|
|
2
|
+
"mappings": "AAIA,cAAc,sBAAsB;AAMpC,SAAS,6BAA6B;AAItC,YAAY,sBAAsB,iBAAiB;;CAEjD;;;;;;CAMA;;;;;;;CAOA;;KAIG,mBAAmB;CACtB;CACA;CACA;CACA;;;AAUF,OAAO,iBAAS,yBACd,aAAa,mBACZ;;;;;;;;;;;;;;;;;;;;;;;;AA2BH,OAAO,iBAAS,YACd,aAAa,kBACb,YAAY,sBACX;AAqFH,SACE,8BACA,oBACA,yBACA,qCACK;AACP,cAAc,+BAA+B;AAC7C,cACE,yBACA,0BACA,2BACK",
|
|
3
3
|
"names": [],
|
|
4
4
|
"sources": [
|
|
5
5
|
"src/index.ts"
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"import { createRequire } from 'node:module'\nimport { isAbsolute, join } from 'node:path'\n\nimport Static from '@tamagui/static'\nimport type { TamaguiOptions } from '@tamagui/static'\n\nimport { defaultMetroCompilerCacheRoot } from './compilerCache'\nimport { applyMetroZeroRuntime } from './zeroSerializer'\nimport { createMetroZeroController } from './zeroRuntime'\nimport { formatMetroCompilerDiagnostic } from './diagnostics'\nimport { MetroCompilerFrontend } from './frontend'\nimport { writeMetroCompilerTransformerBridge } from './transformer'\nimport { composeMetroGetTransformOptions } from './transformOptions'\n\nexport type MetroTamaguiOptions = TamaguiOptions & {\n /** Override the ignored on-disk handoff used by Metro transform workers. */\n compilerCacheRoot?: string\n /**\n * Set by the zero-runtime island bundle request. An island is a second Metro\n * bundle with `TAMAGUI_RUNTIME='full'` and its own entry, so this invocation\n * keeps the full runtime and only contributes its CSS fragment.\n */\n zeroIslandBuild?: string\n /**\n * Directory the zero CSS artifact and island bundles are published from,\n * relative to the project root.\n *\n * @default 'public'\n */\n zeroPublicDir?: string\n}\n\n// Use a loose type for metro config to avoid version-specific type incompatibilities\ntype MetroConfigInput = {\n projectRoot?: string\n resolver?: any\n transformer?: any\n transformerPath?: string\n [key: string]: any\n}\n\nconst frontends = new WeakMap<object, MetroCompilerFrontend>()\nconst { loadTamaguiBuildConfigSync } = Static\nconst requireFromPlugin = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url\n)\n\nexport function getMetroCompilerFrontend(\n metroConfig: MetroConfigInput\n): MetroCompilerFrontend | null {\n return frontends.get(metroConfig) ?? null\n}\n\n/**\n * Configure Metro for Tamagui.\n *\n * This is now a simplified wrapper that just ensures CSS is enabled and\n * loads your Tamagui config. For CSS generation, use the CLI:\n *\n * 1. Create a `tamagui.build.ts` with `outputCSS` option\n * 2. Run `tamagui generate` before your build\n * 3. Import the generated CSS in your app's layout\n *\n * @example\n * ```js\n * // metro.config.js\n * const { getDefaultConfig } = require('expo/metro-config')\n * const { withTamagui } = require('@tamagui/metro-plugin')\n *\n * const config = getDefaultConfig(__dirname, { isCSSEnabled: true })\n * module.exports = withTamagui(config, {\n * components: ['tamagui'],\n * config: './tamagui.config.ts',\n * })\n * ```\n */\nexport function withTamagui(\n metroConfig: MetroConfigInput,\n optionsIn?: MetroTamaguiOptions\n): MetroConfigInput {\n const {\n compilerCacheRoot,\n zeroIslandBuild,\n zeroPublicDir = 'public',\n ...tamaguiOptionsIn\n } = optionsIn || {}\n\n const options = loadTamaguiBuildConfigSync(tamaguiOptionsIn)\n\n // Ensure CSS files can be resolved\n metroConfig.resolver = {\n ...(metroConfig.resolver as any),\n sourceExts: [...new Set([...(metroConfig.resolver?.sourceExts || []), 'css'])],\n }\n\n // Store tamagui options for potential use by other tools\n metroConfig.transformer = {\n ...metroConfig.transformer,\n tamagui: options,\n }\n\n const zeroProjectRoot = metroConfig.projectRoot ?? process.cwd()\n const zero = createMetroZeroController(\n options,\n zeroProjectRoot,\n zeroIslandBuild ?? null,\n zeroPublicDir\n )\n\n // `report` runs the analysis through the frontend and changes nothing else,\n // so it never installs the serializer that owns the artifact and the gate.\n if (zero?.isEnforcing) {\n applyMetroZeroRuntime(metroConfig, zero)\n }\n\n if (!options.disable) {\n const projectRoot = metroConfig.projectRoot ?? process.cwd()\n const requireFromProject = createRequire(join(projectRoot, 'package.json'))\n // getDefaultConfig sets this to the bare specifier 'metro-babel-transformer',\n // and createRequire needs an absolute path, so resolve either shape here\n const configuredBabelTransformerPath =\n metroConfig.transformer.babelTransformerPath ?? 'metro-babel-transformer'\n const originalBabelTransformerPath = isAbsolute(configuredBabelTransformerPath)\n ? configuredBabelTransformerPath\n : requireFromProject.resolve(configuredBabelTransformerPath)\n const cacheBaseRoot = compilerCacheRoot ?? defaultMetroCompilerCacheRoot(projectRoot)\n const frontend = new MetroCompilerFrontend({\n projectRoot,\n resolver: metroConfig.resolver,\n transformer: metroConfig.transformer,\n tamaguiOptions: options,\n originalBabelTransformerPath,\n cacheRoot: cacheBaseRoot,\n zero,\n reportDiagnostic(diagnostic) {\n console.warn(formatMetroCompilerDiagnostic(diagnostic, projectRoot))\n },\n })\n const transformerFactoryPath = requireFromPlugin.resolve(\n '@tamagui/metro-plugin/transformer'\n )\n metroConfig.transformer.babelTransformerPath = writeMetroCompilerTransformerBridge(\n transformerFactoryPath,\n {\n cacheBaseRoot,\n originalBabelTransformerPath,\n projectRoot,\n // an integration-owned literal, never an ambient shell value\n runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? 'zero' : 'full',\n }\n )\n const userGetTransformOptions = metroConfig.transformer.getTransformOptions\n metroConfig.transformer.getTransformOptions = composeMetroGetTransformOptions(\n frontend,\n userGetTransformOptions\n )\n frontends.set(metroConfig, frontend)\n }\n\n return metroConfig\n}\n\nexport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError,\n defaultMetroCompilerCacheRoot,\n} from './compilerCache'\nexport type { MetroCompilerDiagnostic } from './diagnostics'\nexport type {\n MetroCompilerGeneration,\n MetroCompilerScanOptions,\n MetroCompilerUpdate,\n} from './frontend'\n"
|
|
9
|
+
"import { createRequire } from 'node:module'\nimport { isAbsolute, join } from 'node:path'\n\nimport Static from '@tamagui/static'\nimport type { TamaguiOptions } from '@tamagui/static'\n\nimport { defaultMetroCompilerCacheRoot } from './compilerCache'\nimport { applyMetroZeroRuntime } from './zeroSerializer'\nimport { createMetroZeroController } from './zeroRuntime'\nimport { formatMetroCompilerDiagnostic } from './diagnostics'\nimport { MetroCompilerFrontend } from './frontend'\nimport { writeMetroCompilerTransformerBridge } from './transformer'\nimport { composeMetroGetTransformOptions } from './transformOptions'\n\nexport type MetroTamaguiOptions = TamaguiOptions & {\n /** Override the ignored on-disk handoff used by Metro transform workers. */\n compilerCacheRoot?: string\n /**\n * Set by the zero-runtime island bundle request. An island is a second Metro\n * bundle with `TAMAGUI_RUNTIME='full'` and its own entry, so this invocation\n * keeps the full runtime and only contributes its CSS fragment.\n */\n zeroIslandBuild?: string\n /**\n * Directory the zero CSS artifact and island bundles are published from,\n * relative to the project root.\n *\n * @default 'public'\n */\n zeroPublicDir?: string\n}\n\n// Use a loose type for metro config to avoid version-specific type incompatibilities\ntype MetroConfigInput = {\n projectRoot?: string\n resolver?: any\n transformer?: any\n transformerPath?: string\n [key: string]: any\n}\n\nconst frontends = new WeakMap<object, MetroCompilerFrontend>()\nconst { loadTamaguiBuildConfigSync } = Static\nconst requireFromPlugin = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url\n)\n\nexport function getMetroCompilerFrontend(\n metroConfig: MetroConfigInput\n): MetroCompilerFrontend | null {\n return frontends.get(metroConfig) ?? null\n}\n\n/**\n * Configure Metro for Tamagui.\n *\n * This is now a simplified wrapper that just ensures CSS is enabled and\n * loads your Tamagui config. For CSS generation, use the CLI:\n *\n * 1. Create a `tamagui.build.ts` with `outputCSS` option\n * 2. Run `tamagui generate` before your build\n * 3. Import the generated CSS in your app's layout\n *\n * @example\n * ```js\n * // metro.config.js\n * const { getDefaultConfig } = require('expo/metro-config')\n * const { withTamagui } = require('@tamagui/metro-plugin')\n *\n * const config = getDefaultConfig(__dirname, { isCSSEnabled: true })\n * module.exports = withTamagui(config, {\n * components: ['tamagui'],\n * config: './tamagui.config.ts',\n * })\n * ```\n */\nexport function withTamagui(\n metroConfig: MetroConfigInput,\n optionsIn?: MetroTamaguiOptions\n): MetroConfigInput {\n const {\n compilerCacheRoot,\n zeroIslandBuild,\n zeroPublicDir = 'public',\n ...tamaguiOptionsIn\n } = optionsIn || {}\n\n const options = loadTamaguiBuildConfigSync(tamaguiOptionsIn)\n const webRuntimeFeatures = Static.resolveWebRuntimeFeatureLiterals(options)\n\n // Ensure CSS files can be resolved\n metroConfig.resolver = {\n ...(metroConfig.resolver as any),\n sourceExts: [...new Set([...(metroConfig.resolver?.sourceExts || []), 'css'])],\n }\n\n // Store tamagui options for potential use by other tools\n metroConfig.transformer = {\n ...metroConfig.transformer,\n tamagui: options,\n }\n\n const zeroProjectRoot = metroConfig.projectRoot ?? process.cwd()\n const zero = createMetroZeroController(\n options,\n zeroProjectRoot,\n zeroIslandBuild ?? null,\n zeroPublicDir\n )\n\n // `report` runs the analysis through the frontend and changes nothing else,\n // so it never installs the serializer that owns the artifact and the gate.\n if (zero?.isEnforcing) {\n applyMetroZeroRuntime(metroConfig, zero)\n }\n\n if (!options.disable) {\n const projectRoot = metroConfig.projectRoot ?? process.cwd()\n const requireFromProject = createRequire(join(projectRoot, 'package.json'))\n // getDefaultConfig sets this to the bare specifier 'metro-babel-transformer',\n // and createRequire needs an absolute path, so resolve either shape here\n const configuredBabelTransformerPath =\n metroConfig.transformer.babelTransformerPath ?? 'metro-babel-transformer'\n const originalBabelTransformerPath = isAbsolute(configuredBabelTransformerPath)\n ? configuredBabelTransformerPath\n : requireFromProject.resolve(configuredBabelTransformerPath)\n const cacheBaseRoot = compilerCacheRoot ?? defaultMetroCompilerCacheRoot(projectRoot)\n const frontend = new MetroCompilerFrontend({\n projectRoot,\n resolver: metroConfig.resolver,\n transformer: metroConfig.transformer,\n tamaguiOptions: options,\n originalBabelTransformerPath,\n cacheRoot: cacheBaseRoot,\n zero,\n reportDiagnostic(diagnostic) {\n console.warn(formatMetroCompilerDiagnostic(diagnostic, projectRoot))\n },\n })\n const transformerFactoryPath = requireFromPlugin.resolve(\n '@tamagui/metro-plugin/transformer'\n )\n metroConfig.transformer.babelTransformerPath = writeMetroCompilerTransformerBridge(\n transformerFactoryPath,\n {\n cacheBaseRoot,\n originalBabelTransformerPath,\n projectRoot,\n // an integration-owned literal, never an ambient shell value\n runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? 'zero' : 'full',\n webRuntimeFeatures,\n }\n )\n const userGetTransformOptions = metroConfig.transformer.getTransformOptions\n metroConfig.transformer.getTransformOptions = composeMetroGetTransformOptions(\n frontend,\n userGetTransformOptions\n )\n frontends.set(metroConfig, frontend)\n }\n\n return metroConfig\n}\n\nexport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError,\n defaultMetroCompilerCacheRoot,\n} from './compilerCache'\nexport type { MetroCompilerDiagnostic } from './diagnostics'\nexport type {\n MetroCompilerGeneration,\n MetroCompilerScanOptions,\n MetroCompilerUpdate,\n} from './frontend'\n"
|
|
10
10
|
]
|
|
11
11
|
}
|
package/types/transformer.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export interface MetroCompilerTransformerOptions {
|
|
|
11
11
|
* inlined here so every guard is a constant.
|
|
12
12
|
*/
|
|
13
13
|
runtimeLiteral?: "full" | "zero";
|
|
14
|
+
webRuntimeFeatures?: {
|
|
15
|
+
inlineThemeValues: "enabled" | "disabled";
|
|
16
|
+
styleValueGrammar: "enabled" | "disabled";
|
|
17
|
+
safeArea: "enabled" | "disabled";
|
|
18
|
+
};
|
|
14
19
|
}
|
|
15
20
|
export interface MetroCompilerTransformMetadata {
|
|
16
21
|
cacheHit: boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAIA,cAGO,8BACA,iCACA;AAMP,cAGO,+BACA;AAEP,cAAsC,mCAAmC;AAEzE,iBAAiB,gCAAgC;CAC/C;CACA;CACA;;;;;;CAMA,iBAAiB,SAAS
|
|
2
|
+
"mappings": "AAIA,cAGO,8BACA,iCACA;AAMP,cAGO,+BACA;AAEP,cAAsC,mCAAmC;AAEzE,iBAAiB,gCAAgC;CAC/C;CACA;CACA;;;;;;CAMA,iBAAiB,SAAS;CAC1B,qBAAqB;EACnB,mBAAmB,YAAY;EAC/B,mBAAmB,YAAY;EAC/B,UAAU,YAAY;;;AAI1B,iBAAiB,+BAA+B;CAC9C;CACA,aAAa;CACb,WAAW;;AAGb,OAAO,iBAAS,+BAA+B,QAAQ,kCAAkC;CACvF,UAAU,MAAM,0BAA0B,QAAQ;CAClD;;AA4KF,OAAO,iBAAS,oCACd,gCACA,QAAQ",
|
|
3
3
|
"names": [],
|
|
4
4
|
"sources": [
|
|
5
5
|
"src/transformer.ts"
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"import { createHash } from 'node:crypto'\nimport { existsSync, mkdirSync, realpathSync, renameSync, writeFileSync } from 'node:fs'\nimport { isAbsolute, join, resolve } from 'node:path'\n\nimport {\n compileWithUserBabel,\n userBabelCacheKey,\n type MetroBabelTransformArgs,\n type MetroBabelTransformResult,\n} from './babel'\nimport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError,\n} from './compilerCache'\nimport {\n formatMetroCompilerDiagnostic,\n metroDiagnostic,\n type MetroCompilerDiagnostic,\n} from './diagnostics'\nimport { isCompilerSourceFile } from './metroResolver'\nimport { applyMetroCompilerPlan, type MetroCompilerLoweringResult } from './lowering'\n\nexport interface MetroCompilerTransformerOptions {\n cacheBaseRoot: string\n originalBabelTransformerPath: string\n projectRoot: string\n /**\n * The integration-owned `TAMAGUI_RUNTIME` literal for this bundle request.\n * Metro never reads an ambient value: the literal is decided by the build and\n * inlined here so every guard is a constant.\n */\n runtimeLiteral?: 'full' | 'zero'\n}\n\nexport interface MetroCompilerTransformMetadata {\n cacheHit: boolean\n diagnostics: MetroCompilerDiagnostic[]\n lowering?: MetroCompilerLoweringResult\n}\n\nexport function createMetroCompilerTransformer(config: MetroCompilerTransformerOptions): {\n transform(args: MetroBabelTransformArgs): Promise<MetroBabelTransformResult>\n getCacheKey(): string\n} {\n // Metro hands workers project-relative filenames while the compiler cache is\n // keyed by absolute realpaths (the frontend realpaths every module). Resolve\n // to the same form or every plan lookup silently misses and the whole build\n // ships unlowered.\n const moduleIdCache = new Map<string, string>()\n const missWarned = new Set<string>()\n function cacheModuleId(filename: string): string {\n let id = moduleIdCache.get(filename)\n if (!id) {\n const absolute = isAbsolute(filename)\n ? filename\n : resolve(config.projectRoot, filename)\n try {\n id = realpathSync(absolute)\n } catch {\n id = absolute\n }\n moduleIdCache.set(filename, id)\n }\n return id\n }\n // Metro also transforms modules the frontend can never plan: bundler-injected\n // polyfills, virtual modules, and node_modules (external by design). A miss\n // is only a lowering defect for a file the frontend's project graph would\n // have crawled.\n function planEligible(moduleId: string): boolean {\n return (\n isCompilerSourceFile(moduleId) &&\n !moduleId.includes(`${join('node_modules')}`) &&\n existsSync(moduleId)\n )\n }\n // Replaces only the exact
|
|
9
|
+
"import { createHash } from 'node:crypto'\nimport { existsSync, mkdirSync, realpathSync, renameSync, writeFileSync } from 'node:fs'\nimport { isAbsolute, join, resolve } from 'node:path'\n\nimport {\n compileWithUserBabel,\n userBabelCacheKey,\n type MetroBabelTransformArgs,\n type MetroBabelTransformResult,\n} from './babel'\nimport {\n METRO_COMPILER_CACHE_VERSION,\n MetroCompilerCache,\n MetroCompilerCacheError,\n} from './compilerCache'\nimport {\n formatMetroCompilerDiagnostic,\n metroDiagnostic,\n type MetroCompilerDiagnostic,\n} from './diagnostics'\nimport { isCompilerSourceFile } from './metroResolver'\nimport { applyMetroCompilerPlan, type MetroCompilerLoweringResult } from './lowering'\n\nexport interface MetroCompilerTransformerOptions {\n cacheBaseRoot: string\n originalBabelTransformerPath: string\n projectRoot: string\n /**\n * The integration-owned `TAMAGUI_RUNTIME` literal for this bundle request.\n * Metro never reads an ambient value: the literal is decided by the build and\n * inlined here so every guard is a constant.\n */\n runtimeLiteral?: 'full' | 'zero'\n webRuntimeFeatures?: {\n inlineThemeValues: 'enabled' | 'disabled'\n styleValueGrammar: 'enabled' | 'disabled'\n safeArea: 'enabled' | 'disabled'\n }\n}\n\nexport interface MetroCompilerTransformMetadata {\n cacheHit: boolean\n diagnostics: MetroCompilerDiagnostic[]\n lowering?: MetroCompilerLoweringResult\n}\n\nexport function createMetroCompilerTransformer(config: MetroCompilerTransformerOptions): {\n transform(args: MetroBabelTransformArgs): Promise<MetroBabelTransformResult>\n getCacheKey(): string\n} {\n // Metro hands workers project-relative filenames while the compiler cache is\n // keyed by absolute realpaths (the frontend realpaths every module). Resolve\n // to the same form or every plan lookup silently misses and the whole build\n // ships unlowered.\n const moduleIdCache = new Map<string, string>()\n const missWarned = new Set<string>()\n function cacheModuleId(filename: string): string {\n let id = moduleIdCache.get(filename)\n if (!id) {\n const absolute = isAbsolute(filename)\n ? filename\n : resolve(config.projectRoot, filename)\n try {\n id = realpathSync(absolute)\n } catch {\n id = absolute\n }\n moduleIdCache.set(filename, id)\n }\n return id\n }\n // Metro also transforms modules the frontend can never plan: bundler-injected\n // polyfills, virtual modules, and node_modules (external by design). A miss\n // is only a lowering defect for a file the frontend's project graph would\n // have crawled.\n function planEligible(moduleId: string): boolean {\n return (\n isCompilerSourceFile(moduleId) &&\n !moduleId.includes(`${join('node_modules')}`) &&\n existsSync(moduleId)\n )\n }\n // Replaces only the integration-owned exact process.env member expressions.\n // Metro has no define mechanism, so this is the transform-level equivalent.\n const runtimeLiteral = config.runtimeLiteral ?? 'full'\n const inlineRuntimeLiterals = (platform: string, { types }: { types: any }) => {\n const enabledFeatures = {\n inlineThemeValues: 'enabled',\n styleValueGrammar: 'enabled',\n safeArea: 'enabled',\n } as const\n const features =\n platform === 'web'\n ? { ...enabledFeatures, ...config.webRuntimeFeatures }\n : enabledFeatures\n const featureByName: Record<string, string> = {\n TAMAGUI_RUNTIME_INLINE_THEME_VALUES: features.inlineThemeValues,\n TAMAGUI_RUNTIME_STYLE_VALUE_GRAMMAR: features.styleValueGrammar,\n TAMAGUI_RUNTIME_SAFE_AREA: features.safeArea,\n }\n return {\n visitor: {\n MemberExpression(nodePath: any) {\n const node = nodePath.node\n if (\n node.computed ||\n !types.isMemberExpression(node.object) ||\n node.object.computed ||\n !types.isIdentifier(node.object.object, { name: 'process' }) ||\n !types.isIdentifier(node.object.property, { name: 'env' })\n ) {\n return\n }\n const name = types.isIdentifier(node.property) ? node.property.name : ''\n if (name === 'TAMAGUI_RUNTIME') {\n nodePath.replaceWith(types.stringLiteral(runtimeLiteral))\n return\n }\n const literal = featureByName[name]\n if (literal) nodePath.replaceWith(types.stringLiteral(literal))\n },\n },\n }\n }\n\n return {\n async transform(argsIn) {\n const platform =\n typeof argsIn.options.platform === 'string' ? argsIn.options.platform : 'default'\n const args = {\n ...argsIn,\n plugins: [\n ...(argsIn.plugins ?? []),\n (babel: { types: any }) => inlineRuntimeLiterals(platform, babel),\n ],\n }\n const cache = new MetroCompilerCache(join(config.cacheBaseRoot, platform))\n let tamagui: MetroCompilerTransformMetadata = {\n cacheHit: false,\n diagnostics: [],\n }\n const moduleId = cacheModuleId(args.filename)\n try {\n // a manifest exists exactly when the frontend planned this build, so a\n // lookup miss on a plannable file is a lowering defect (unlowered\n // output), never routine — surface it instead of silently shipping\n // runtime-path modules\n const entry = await cache.read(moduleId, args.src, (reason, detail) => {\n if (missWarned.has(moduleId) || !planEligible(moduleId)) return\n missWarned.add(moduleId)\n const diagnostic = metroDiagnostic(\n 'metro/plan-miss',\n `Lowering plan lookup missed for ${moduleId} (${reason}${detail ? `: ${detail}` : ''}); module ships unlowered`,\n { moduleId }\n )\n tamagui.diagnostics.push(diagnostic)\n console.warn(formatMetroCompilerDiagnostic(diagnostic, config.projectRoot))\n })\n if (entry) {\n try {\n const lowered = await applyMetroCompilerPlan(\n { ...args, filename: moduleId },\n entry.plan,\n config.originalBabelTransformerPath\n )\n return {\n ...lowered.compiled.result,\n metadata: {\n ...lowered.compiled.result.metadata,\n tamagui: {\n cacheHit: true,\n diagnostics: entry.diagnostics,\n lowering: lowered.lowering,\n },\n },\n }\n } catch (error) {\n const diagnostic = metroDiagnostic(\n 'metro/cache-corrupt',\n `Cached lowering plan for ${args.filename} could not be applied: ${error instanceof Error ? error.message : String(error)}`,\n { moduleId }\n )\n tamagui = {\n cacheHit: true,\n diagnostics: [...entry.diagnostics, diagnostic],\n }\n console.warn(formatMetroCompilerDiagnostic(diagnostic, config.projectRoot))\n }\n }\n } catch (error) {\n if (!(error instanceof MetroCompilerCacheError)) throw error\n tamagui.diagnostics.push(error.diagnostic)\n console.warn(formatMetroCompilerDiagnostic(error.diagnostic, config.projectRoot))\n }\n const compiled = await compileWithUserBabel(\n config.originalBabelTransformerPath,\n args\n )\n return {\n ...compiled.result,\n metadata: {\n ...compiled.result.metadata,\n tamagui,\n },\n }\n },\n getCacheKey() {\n return createHash('sha256')\n .update(`tamagui-metro-compiler-v${METRO_COMPILER_CACHE_VERSION}`)\n .update('\\0')\n .update(runtimeLiteral)\n .update('\\0')\n .update(JSON.stringify(config.webRuntimeFeatures ?? {}))\n .update('\\0')\n .update(userBabelCacheKey(config.originalBabelTransformerPath))\n .digest('hex')\n },\n }\n}\n\nexport function writeMetroCompilerTransformerBridge(\n transformerFactoryPath: string,\n config: MetroCompilerTransformerOptions\n): string {\n const serializedConfig = JSON.stringify(config)\n const bridgeHash = createHash('sha256')\n .update(transformerFactoryPath)\n .update('\\0')\n .update(serializedConfig)\n .digest('hex')\n const directory = join(config.cacheBaseRoot, 'bridge')\n const bridgePath = join(directory, `${bridgeHash}.cjs`)\n const temporaryPath = `${bridgePath}.${process.pid}.tmp`\n const source = `'use strict'\\nmodule.exports = require(${JSON.stringify(\n transformerFactoryPath\n )}).createMetroCompilerTransformer(${serializedConfig})\\n`\n mkdirSync(directory, { recursive: true })\n writeFileSync(temporaryPath, source, 'utf8')\n renameSync(temporaryPath, bridgePath)\n return bridgePath\n}\n"
|
|
10
10
|
]
|
|
11
11
|
}
|