@tamagui/metro-plugin 3.0.0-beta.765.1 → 3.0.0-beta.804.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 +13 -1
- package/dist/cjs/transformer.cjs +11 -6
- package/dist/esm/index.mjs +13 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/transformer.mjs +11 -6
- package/dist/esm/transformer.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +26 -0
- package/src/transformer.ts +16 -6
- package/types/index.d.ts.map +2 -2
- package/types/transformer.d.ts +2 -0
- package/types/transformer.d.ts.map +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -67,6 +67,17 @@ function withTamagui(metroConfig, optionsIn) {
|
|
|
67
67
|
const zero = (0, import_zeroRuntime.createMetroZeroController)(options, zeroProjectRoot, zeroIslandBuild ?? null, zeroPublicDir);
|
|
68
68
|
if (zero?.isEnforcing) {
|
|
69
69
|
(0, import_zeroSerializer.applyMetroZeroRuntime)(metroConfig, zero);
|
|
70
|
+
const resolveRequest = metroConfig.resolver.resolveRequest;
|
|
71
|
+
metroConfig.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
72
|
+
const resolved = resolveRequest ? resolveRequest(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
73
|
+
if (resolved?.type === "sourceFile" && /(^|\/)(?:directStyleCSS|getCSSStylesAtomic)\.(?:c?js|mjs)$/.test(resolved.filePath)) {
|
|
74
|
+
return {
|
|
75
|
+
...resolved,
|
|
76
|
+
filePath: resolved.filePath.replace(/(?:directStyleCSS|getCSSStylesAtomic)(?=\.)/, (name) => `${name}Compiled`)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return resolved;
|
|
80
|
+
};
|
|
70
81
|
}
|
|
71
82
|
if (!options.disable) {
|
|
72
83
|
const projectRoot = metroConfig.projectRoot ?? process.cwd();
|
|
@@ -91,7 +102,8 @@ function withTamagui(metroConfig, optionsIn) {
|
|
|
91
102
|
cacheBaseRoot,
|
|
92
103
|
originalBabelTransformerPath,
|
|
93
104
|
projectRoot,
|
|
94
|
-
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full"
|
|
105
|
+
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full",
|
|
106
|
+
didOutputCSSLiteral: zero?.isEnforcing ? "1" : void 0
|
|
95
107
|
});
|
|
96
108
|
const userGetTransformOptions = metroConfig.transformer.getTransformOptions;
|
|
97
109
|
metroConfig.transformer.getTransformOptions = (0, import_transformOptions.composeMetroGetTransformOptions)(frontend, userGetTransformOptions);
|
package/dist/cjs/transformer.cjs
CHANGED
|
@@ -49,21 +49,26 @@ function createMetroCompilerTransformer(config) {
|
|
|
49
49
|
return id;
|
|
50
50
|
}
|
|
51
51
|
function planEligible(moduleId) {
|
|
52
|
-
return (0, import_metroResolver.isCompilerSourceFile)(moduleId) && !moduleId.includes(`${(0, import_node_path.join)("node_modules")}`) && (0, import_node_fs.existsSync)(moduleId);
|
|
52
|
+
return (0, import_metroResolver.isCompilerSourceFile)(moduleId) && !moduleId.includes(`${(0, import_node_path.join)("node_modules")}`) && !/(?:directStyleCSS|getCSSStylesAtomic)Compiled\.(?:c?js|mjs)$/.test(moduleId) && (0, import_node_fs.existsSync)(moduleId);
|
|
53
53
|
}
|
|
54
54
|
const runtimeLiteral = config.runtimeLiteral ?? "full";
|
|
55
|
-
const
|
|
55
|
+
const envLiterals = /* @__PURE__ */ new Map([["TAMAGUI_RUNTIME", runtimeLiteral]]);
|
|
56
|
+
if (config.didOutputCSSLiteral) {
|
|
57
|
+
envLiterals.set("TAMAGUI_DID_OUTPUT_CSS", config.didOutputCSSLiteral);
|
|
58
|
+
}
|
|
59
|
+
const inlineBuildLiterals = ({ types }) => ({ visitor: { MemberExpression(nodePath) {
|
|
56
60
|
const node = nodePath.node;
|
|
57
|
-
if (node.computed || !types.isIdentifier(node.property
|
|
61
|
+
if (node.computed || !types.isIdentifier(node.property) || !types.isMemberExpression(node.object) || node.object.computed || !types.isIdentifier(node.object.object, { name: "process" }) || !types.isIdentifier(node.object.property, { name: "env" })) {
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
|
-
|
|
64
|
+
const literal = envLiterals.get(node.property.name);
|
|
65
|
+
if (literal) nodePath.replaceWith(types.stringLiteral(literal));
|
|
61
66
|
} } });
|
|
62
67
|
return {
|
|
63
68
|
async transform(argsIn) {
|
|
64
69
|
const args = {
|
|
65
70
|
...argsIn,
|
|
66
|
-
plugins: [...argsIn.plugins ?? [],
|
|
71
|
+
plugins: [...argsIn.plugins ?? [], inlineBuildLiterals]
|
|
67
72
|
};
|
|
68
73
|
const platform = typeof args.options.platform === "string" ? args.options.platform : "default";
|
|
69
74
|
const cache = new import_compilerCache.MetroCompilerCache((0, import_node_path.join)(config.cacheBaseRoot, platform));
|
|
@@ -121,7 +126,7 @@ function createMetroCompilerTransformer(config) {
|
|
|
121
126
|
};
|
|
122
127
|
},
|
|
123
128
|
getCacheKey() {
|
|
124
|
-
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");
|
|
129
|
+
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(config.didOutputCSSLiteral ?? "").update("\0").update((0, import_babel.userBabelCacheKey)(config.originalBabelTransformerPath)).digest("hex");
|
|
125
130
|
}
|
|
126
131
|
};
|
|
127
132
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -30,6 +30,17 @@ function withTamagui(metroConfig, optionsIn) {
|
|
|
30
30
|
const zero = createMetroZeroController(options, zeroProjectRoot, zeroIslandBuild ?? null, zeroPublicDir);
|
|
31
31
|
if (zero?.isEnforcing) {
|
|
32
32
|
applyMetroZeroRuntime(metroConfig, zero);
|
|
33
|
+
const resolveRequest = metroConfig.resolver.resolveRequest;
|
|
34
|
+
metroConfig.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
35
|
+
const resolved = resolveRequest ? resolveRequest(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);
|
|
36
|
+
if (resolved?.type === "sourceFile" && /(^|\/)(?:directStyleCSS|getCSSStylesAtomic)\.(?:c?js|mjs)$/.test(resolved.filePath)) {
|
|
37
|
+
return {
|
|
38
|
+
...resolved,
|
|
39
|
+
filePath: resolved.filePath.replace(/(?:directStyleCSS|getCSSStylesAtomic)(?=\.)/, (name) => `${name}Compiled`)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return resolved;
|
|
43
|
+
};
|
|
33
44
|
}
|
|
34
45
|
if (!options.disable) {
|
|
35
46
|
const projectRoot = metroConfig.projectRoot ?? process.cwd();
|
|
@@ -54,7 +65,8 @@ function withTamagui(metroConfig, optionsIn) {
|
|
|
54
65
|
cacheBaseRoot,
|
|
55
66
|
originalBabelTransformerPath,
|
|
56
67
|
projectRoot,
|
|
57
|
-
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full"
|
|
68
|
+
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full",
|
|
69
|
+
didOutputCSSLiteral: zero?.isEnforcing ? "1" : void 0
|
|
58
70
|
});
|
|
59
71
|
const userGetTransformOptions = metroConfig.transformer.getTransformOptions;
|
|
60
72
|
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,YAAY,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;
|
|
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 const resolveRequest = metroConfig.resolver.resolveRequest;\n metroConfig.resolver.resolveRequest = (context, moduleName, platform) => {\n const resolved = resolveRequest ? resolveRequest(context, moduleName, platform) : context.resolveRequest(context, moduleName, platform);\n if (resolved?.type === \"sourceFile\" && /(^|\\/)(?:directStyleCSS|getCSSStylesAtomic)\\.(?:c?js|mjs)$/.test(\n resolved.filePath\n )) {\n return {\n ...resolved,\n filePath: resolved.filePath.replace(\n /(?:directStyleCSS|getCSSStylesAtomic)(?=\\.)/,\n (name) => `${name}Compiled`\n )\n };\n }\n return resolved;\n };\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 didOutputCSSLiteral: zero?.isEnforcing ? \"1\" : void 0\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,YAAY,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;EACvC,MAAM,iBAAiB,YAAY,SAAS;EAC5C,YAAY,SAAS,kBAAkB,SAAS,YAAY,aAAa;GACvE,MAAM,WAAW,iBAAiB,eAAe,SAAS,YAAY,QAAQ,IAAI,QAAQ,eAAe,SAAS,YAAY,QAAQ;GACtI,IAAI,UAAU,SAAS,gBAAgB,6DAA6D,KAClG,SAAS,QACX,GAAG;IACD,OAAO;KACL,GAAG;KACH,UAAU,SAAS,SAAS,QAC1B,gDACC,SAAS,GAAG,KAAK,SACpB;IACF;GACF;GACA,OAAO;EACT;CACF;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,qBAAqB,MAAM,cAAc,MAAM,KAAK;EACtD,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
|
@@ -24,21 +24,26 @@ function createMetroCompilerTransformer(config) {
|
|
|
24
24
|
return id;
|
|
25
25
|
}
|
|
26
26
|
function planEligible(moduleId) {
|
|
27
|
-
return isCompilerSourceFile(moduleId) && !moduleId.includes(`${join("node_modules")}`) && existsSync(moduleId);
|
|
27
|
+
return isCompilerSourceFile(moduleId) && !moduleId.includes(`${join("node_modules")}`) && !/(?:directStyleCSS|getCSSStylesAtomic)Compiled\.(?:c?js|mjs)$/.test(moduleId) && existsSync(moduleId);
|
|
28
28
|
}
|
|
29
29
|
const runtimeLiteral = config.runtimeLiteral ?? "full";
|
|
30
|
-
const
|
|
30
|
+
const envLiterals = /* @__PURE__ */ new Map([["TAMAGUI_RUNTIME", runtimeLiteral]]);
|
|
31
|
+
if (config.didOutputCSSLiteral) {
|
|
32
|
+
envLiterals.set("TAMAGUI_DID_OUTPUT_CSS", config.didOutputCSSLiteral);
|
|
33
|
+
}
|
|
34
|
+
const inlineBuildLiterals = ({ types }) => ({ visitor: { MemberExpression(nodePath) {
|
|
31
35
|
const node = nodePath.node;
|
|
32
|
-
if (node.computed || !types.isIdentifier(node.property
|
|
36
|
+
if (node.computed || !types.isIdentifier(node.property) || !types.isMemberExpression(node.object) || node.object.computed || !types.isIdentifier(node.object.object, { name: "process" }) || !types.isIdentifier(node.object.property, { name: "env" })) {
|
|
33
37
|
return;
|
|
34
38
|
}
|
|
35
|
-
|
|
39
|
+
const literal = envLiterals.get(node.property.name);
|
|
40
|
+
if (literal) nodePath.replaceWith(types.stringLiteral(literal));
|
|
36
41
|
} } });
|
|
37
42
|
return {
|
|
38
43
|
async transform(argsIn) {
|
|
39
44
|
const args = {
|
|
40
45
|
...argsIn,
|
|
41
|
-
plugins: [...argsIn.plugins ?? [],
|
|
46
|
+
plugins: [...argsIn.plugins ?? [], inlineBuildLiterals]
|
|
42
47
|
};
|
|
43
48
|
const platform = typeof args.options.platform === "string" ? args.options.platform : "default";
|
|
44
49
|
const cache = new MetroCompilerCache(join(config.cacheBaseRoot, platform));
|
|
@@ -96,7 +101,7 @@ function createMetroCompilerTransformer(config) {
|
|
|
96
101
|
};
|
|
97
102
|
},
|
|
98
103
|
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");
|
|
104
|
+
return createHash("sha256").update(`tamagui-metro-compiler-v${METRO_COMPILER_CACHE_VERSION}`).update("\0").update(runtimeLiteral).update("\0").update(config.didOutputCSSLiteral ?? "").update("\0").update(userBabelCacheKey(config.originalBabelTransformerPath)).digest("hex");
|
|
100
105
|
}
|
|
101
106
|
};
|
|
102
107
|
}
|
|
@@ -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
|
|
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\")}`) && !/(?:directStyleCSS|getCSSStylesAtomic)Compiled\\.(?:c?js|mjs)$/.test(moduleId) && existsSync(moduleId);\n }\n const runtimeLiteral = config.runtimeLiteral ?? \"full\";\n const envLiterals = /* @__PURE__ */ new Map([[\"TAMAGUI_RUNTIME\", runtimeLiteral]]);\n if (config.didOutputCSSLiteral) {\n envLiterals.set(\"TAMAGUI_DID_OUTPUT_CSS\", config.didOutputCSSLiteral);\n }\n const inlineBuildLiterals = ({ types }) => ({\n visitor: {\n MemberExpression(nodePath) {\n const node = nodePath.node;\n if (node.computed || !types.isIdentifier(node.property) || !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 literal = envLiterals.get(node.property.name);\n if (literal) nodePath.replaceWith(types.stringLiteral(literal));\n }\n }\n });\n return {\n async transform(argsIn) {\n const args = {\n ...argsIn,\n plugins: [...argsIn.plugins ?? [], inlineBuildLiterals]\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(config.didOutputCSSLiteral ?? \"\").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":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/metro-plugin",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.804.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.804.1",
|
|
45
|
+
"@tamagui/static": "3.0.0-beta.804.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.804.1",
|
|
50
50
|
"metro": "0.84.4",
|
|
51
51
|
"metro-resolver": "0.84.4"
|
|
52
52
|
},
|
package/src/index.ts
CHANGED
|
@@ -111,6 +111,31 @@ export function withTamagui(
|
|
|
111
111
|
// so it never installs the serializer that owns the artifact and the gate.
|
|
112
112
|
if (zero?.isEnforcing) {
|
|
113
113
|
applyMetroZeroRuntime(metroConfig, zero)
|
|
114
|
+
const resolveRequest = metroConfig.resolver.resolveRequest
|
|
115
|
+
metroConfig.resolver.resolveRequest = (
|
|
116
|
+
context: any,
|
|
117
|
+
moduleName: string,
|
|
118
|
+
platform: string
|
|
119
|
+
) => {
|
|
120
|
+
const resolved = resolveRequest
|
|
121
|
+
? resolveRequest(context, moduleName, platform)
|
|
122
|
+
: context.resolveRequest(context, moduleName, platform)
|
|
123
|
+
if (
|
|
124
|
+
resolved?.type === 'sourceFile' &&
|
|
125
|
+
/(^|\/)(?:directStyleCSS|getCSSStylesAtomic)\.(?:c?js|mjs)$/.test(
|
|
126
|
+
resolved.filePath
|
|
127
|
+
)
|
|
128
|
+
) {
|
|
129
|
+
return {
|
|
130
|
+
...resolved,
|
|
131
|
+
filePath: resolved.filePath.replace(
|
|
132
|
+
/(?:directStyleCSS|getCSSStylesAtomic)(?=\.)/,
|
|
133
|
+
(name: string) => `${name}Compiled`
|
|
134
|
+
),
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return resolved
|
|
138
|
+
}
|
|
114
139
|
}
|
|
115
140
|
|
|
116
141
|
if (!options.disable) {
|
|
@@ -147,6 +172,7 @@ export function withTamagui(
|
|
|
147
172
|
projectRoot,
|
|
148
173
|
// an integration-owned literal, never an ambient shell value
|
|
149
174
|
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? 'zero' : 'full',
|
|
175
|
+
didOutputCSSLiteral: zero?.isEnforcing ? '1' : undefined,
|
|
150
176
|
}
|
|
151
177
|
)
|
|
152
178
|
const userGetTransformOptions = metroConfig.transformer.getTransformOptions
|
package/src/transformer.ts
CHANGED
|
@@ -31,6 +31,8 @@ export interface MetroCompilerTransformerOptions {
|
|
|
31
31
|
* inlined here so every guard is a constant.
|
|
32
32
|
*/
|
|
33
33
|
runtimeLiteral?: 'full' | 'zero'
|
|
34
|
+
/** The integration-owned compiled CSS marker for this bundle request. */
|
|
35
|
+
didOutputCSSLiteral?: '1'
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export interface MetroCompilerTransformMetadata {
|
|
@@ -72,19 +74,24 @@ export function createMetroCompilerTransformer(config: MetroCompilerTransformerO
|
|
|
72
74
|
return (
|
|
73
75
|
isCompilerSourceFile(moduleId) &&
|
|
74
76
|
!moduleId.includes(`${join('node_modules')}`) &&
|
|
77
|
+
!/(?:directStyleCSS|getCSSStylesAtomic)Compiled\.(?:c?js|mjs)$/.test(moduleId) &&
|
|
75
78
|
existsSync(moduleId)
|
|
76
79
|
)
|
|
77
80
|
}
|
|
78
|
-
//
|
|
79
|
-
//
|
|
81
|
+
// Metro has no define mechanism, so inline the integration-owned build
|
|
82
|
+
// literals at the transform level.
|
|
80
83
|
const runtimeLiteral = config.runtimeLiteral ?? 'full'
|
|
81
|
-
const
|
|
84
|
+
const envLiterals = new Map<string, string>([['TAMAGUI_RUNTIME', runtimeLiteral]])
|
|
85
|
+
if (config.didOutputCSSLiteral) {
|
|
86
|
+
envLiterals.set('TAMAGUI_DID_OUTPUT_CSS', config.didOutputCSSLiteral)
|
|
87
|
+
}
|
|
88
|
+
const inlineBuildLiterals = ({ types }: { types: any }) => ({
|
|
82
89
|
visitor: {
|
|
83
90
|
MemberExpression(nodePath: any) {
|
|
84
91
|
const node = nodePath.node
|
|
85
92
|
if (
|
|
86
93
|
node.computed ||
|
|
87
|
-
!types.isIdentifier(node.property
|
|
94
|
+
!types.isIdentifier(node.property) ||
|
|
88
95
|
!types.isMemberExpression(node.object) ||
|
|
89
96
|
node.object.computed ||
|
|
90
97
|
!types.isIdentifier(node.object.object, { name: 'process' }) ||
|
|
@@ -92,7 +99,8 @@ export function createMetroCompilerTransformer(config: MetroCompilerTransformerO
|
|
|
92
99
|
) {
|
|
93
100
|
return
|
|
94
101
|
}
|
|
95
|
-
|
|
102
|
+
const literal = envLiterals.get(node.property.name)
|
|
103
|
+
if (literal) nodePath.replaceWith(types.stringLiteral(literal))
|
|
96
104
|
},
|
|
97
105
|
},
|
|
98
106
|
})
|
|
@@ -101,7 +109,7 @@ export function createMetroCompilerTransformer(config: MetroCompilerTransformerO
|
|
|
101
109
|
async transform(argsIn) {
|
|
102
110
|
const args = {
|
|
103
111
|
...argsIn,
|
|
104
|
-
plugins: [...(argsIn.plugins ?? []),
|
|
112
|
+
plugins: [...(argsIn.plugins ?? []), inlineBuildLiterals],
|
|
105
113
|
}
|
|
106
114
|
const platform =
|
|
107
115
|
typeof args.options.platform === 'string' ? args.options.platform : 'default'
|
|
@@ -181,6 +189,8 @@ export function createMetroCompilerTransformer(config: MetroCompilerTransformerO
|
|
|
181
189
|
.update('\0')
|
|
182
190
|
.update(runtimeLiteral)
|
|
183
191
|
.update('\0')
|
|
192
|
+
.update(config.didOutputCSSLiteral ?? '')
|
|
193
|
+
.update('\0')
|
|
184
194
|
.update(userBabelCacheKey(config.originalBabelTransformerPath))
|
|
185
195
|
.digest('hex')
|
|
186
196
|
},
|
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;AA6GH,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\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 const resolveRequest = metroConfig.resolver.resolveRequest\n metroConfig.resolver.resolveRequest = (\n context: any,\n moduleName: string,\n platform: string\n ) => {\n const resolved = resolveRequest\n ? resolveRequest(context, moduleName, platform)\n : context.resolveRequest(context, moduleName, platform)\n if (\n resolved?.type === 'sourceFile' &&\n /(^|\\/)(?:directStyleCSS|getCSSStylesAtomic)\\.(?:c?js|mjs)$/.test(\n resolved.filePath\n )\n ) {\n return {\n ...resolved,\n filePath: resolved.filePath.replace(\n /(?:directStyleCSS|getCSSStylesAtomic)(?=\\.)/,\n (name: string) => `${name}Compiled`\n ),\n }\n }\n return resolved\n }\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 didOutputCSSLiteral: zero?.isEnforcing ? '1' : undefined,\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,8 @@ export interface MetroCompilerTransformerOptions {
|
|
|
11
11
|
* inlined here so every guard is a constant.
|
|
12
12
|
*/
|
|
13
13
|
runtimeLiteral?: "full" | "zero";
|
|
14
|
+
/** The integration-owned compiled CSS marker for this bundle request. */
|
|
15
|
+
didOutputCSSLiteral?: "1";
|
|
14
16
|
}
|
|
15
17
|
export interface MetroCompilerTransformMetadata {
|
|
16
18
|
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;;CAE1B,sBAAsB;;AAGxB,iBAAiB,+BAA+B;CAC9C;CACA,aAAa;CACb,WAAW;;AAGb,OAAO,iBAAS,+BAA+B,QAAQ,kCAAkC;CACvF,UAAU,MAAM,0BAA0B,QAAQ;CAClD;;AA0JF,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 //
|
|
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 /** The integration-owned compiled CSS marker for this bundle request. */\n didOutputCSSLiteral?: '1'\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 !/(?:directStyleCSS|getCSSStylesAtomic)Compiled\\.(?:c?js|mjs)$/.test(moduleId) &&\n existsSync(moduleId)\n )\n }\n // Metro has no define mechanism, so inline the integration-owned build\n // literals at the transform level.\n const runtimeLiteral = config.runtimeLiteral ?? 'full'\n const envLiterals = new Map<string, string>([['TAMAGUI_RUNTIME', runtimeLiteral]])\n if (config.didOutputCSSLiteral) {\n envLiterals.set('TAMAGUI_DID_OUTPUT_CSS', config.didOutputCSSLiteral)\n }\n const inlineBuildLiterals = ({ types }: { types: any }) => ({\n visitor: {\n MemberExpression(nodePath: any) {\n const node = nodePath.node\n if (\n node.computed ||\n !types.isIdentifier(node.property) ||\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 literal = envLiterals.get(node.property.name)\n if (literal) nodePath.replaceWith(types.stringLiteral(literal))\n },\n },\n })\n\n return {\n async transform(argsIn) {\n const args = {\n ...argsIn,\n plugins: [...(argsIn.plugins ?? []), inlineBuildLiterals],\n }\n const platform =\n typeof args.options.platform === 'string' ? args.options.platform : 'default'\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(config.didOutputCSSLiteral ?? '')\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
|
}
|