@tamagui/metro-plugin 3.0.0-beta.1153.1 → 3.0.0-beta.1161.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 +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +7 -3
- package/src/transformer.ts +1 -1
- package/types/index.d.ts +2 -2
- package/types/index.d.ts.map +2 -2
- package/types/transformer.d.ts +1 -1
- package/types/transformer.d.ts.map +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -102,7 +102,7 @@ function withTamagui(metroConfig, optionsIn) {
|
|
|
102
102
|
cacheBaseRoot,
|
|
103
103
|
originalBabelTransformerPath,
|
|
104
104
|
projectRoot,
|
|
105
|
-
runtimeLiteral: zero?.isEnforcing
|
|
105
|
+
runtimeLiteral: !zero?.isEnforcing ? "full" : zero.islandBuild ? "island" : "zero",
|
|
106
106
|
didOutputCSSLiteral: zero?.isEnforcing ? "1" : void 0
|
|
107
107
|
});
|
|
108
108
|
const userGetTransformOptions = metroConfig.transformer.getTransformOptions;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -65,7 +65,7 @@ function withTamagui(metroConfig, optionsIn) {
|
|
|
65
65
|
cacheBaseRoot,
|
|
66
66
|
originalBabelTransformerPath,
|
|
67
67
|
projectRoot,
|
|
68
|
-
runtimeLiteral: zero?.isEnforcing
|
|
68
|
+
runtimeLiteral: !zero?.isEnforcing ? "full" : zero.islandBuild ? "island" : "zero",
|
|
69
69
|
didOutputCSSLiteral: zero?.isEnforcing ? "1" : void 0
|
|
70
70
|
});
|
|
71
71
|
const userGetTransformOptions = metroConfig.transformer.getTransformOptions;
|
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 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
|
|
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 ? \"full\" : zero.islandBuild ? \"island\" : \"zero\",\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,CAAC,MAAM,cAAc,SAAS,KAAK,cAAc,WAAW;GAC5E,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/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.1161.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.1161.1",
|
|
45
|
+
"@tamagui/static": "3.0.0-beta.1161.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.1161.1",
|
|
50
50
|
"metro": "0.84.4",
|
|
51
51
|
"metro-resolver": "0.84.4"
|
|
52
52
|
},
|
package/src/index.ts
CHANGED
|
@@ -17,8 +17,8 @@ export type MetroTamaguiOptions = TamaguiOptions & {
|
|
|
17
17
|
compilerCacheRoot?: string
|
|
18
18
|
/**
|
|
19
19
|
* Set by the zero-runtime island bundle request. An island is a second Metro
|
|
20
|
-
* bundle with `TAMAGUI_RUNTIME='
|
|
21
|
-
* keeps the
|
|
20
|
+
* bundle with `TAMAGUI_RUNTIME='island'` and its own entry, so this invocation
|
|
21
|
+
* keeps the component runtime and only contributes its CSS fragment.
|
|
22
22
|
*/
|
|
23
23
|
zeroIslandBuild?: string
|
|
24
24
|
/**
|
|
@@ -171,7 +171,11 @@ export function withTamagui(
|
|
|
171
171
|
originalBabelTransformerPath,
|
|
172
172
|
projectRoot,
|
|
173
173
|
// an integration-owned literal, never an ambient shell value
|
|
174
|
-
runtimeLiteral: zero?.isEnforcing
|
|
174
|
+
runtimeLiteral: !zero?.isEnforcing
|
|
175
|
+
? 'full'
|
|
176
|
+
: zero.islandBuild
|
|
177
|
+
? 'island'
|
|
178
|
+
: 'zero',
|
|
175
179
|
didOutputCSSLiteral: zero?.isEnforcing ? '1' : undefined,
|
|
176
180
|
}
|
|
177
181
|
)
|
package/src/transformer.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface MetroCompilerTransformerOptions {
|
|
|
30
30
|
* Metro never reads an ambient value: the literal is decided by the build and
|
|
31
31
|
* inlined here so every guard is a constant.
|
|
32
32
|
*/
|
|
33
|
-
runtimeLiteral?: 'full' | 'zero'
|
|
33
|
+
runtimeLiteral?: 'full' | 'zero' | 'island'
|
|
34
34
|
/** The integration-owned compiled CSS marker for this bundle request. */
|
|
35
35
|
didOutputCSSLiteral?: '1'
|
|
36
36
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export type MetroTamaguiOptions = TamaguiOptions & {
|
|
|
5
5
|
compilerCacheRoot?: string;
|
|
6
6
|
/**
|
|
7
7
|
* Set by the zero-runtime island bundle request. An island is a second Metro
|
|
8
|
-
* bundle with `TAMAGUI_RUNTIME='
|
|
9
|
-
* keeps the
|
|
8
|
+
* bundle with `TAMAGUI_RUNTIME='island'` and its own entry, so this invocation
|
|
9
|
+
* keeps the component runtime and only contributes its CSS fragment.
|
|
10
10
|
*/
|
|
11
11
|
zeroIslandBuild?: string;
|
|
12
12
|
/**
|
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;AAiHH,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='
|
|
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='island'` and its own entry, so this invocation\n * keeps the component 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\n ? 'full'\n : zero.islandBuild\n ? 'island'\n : 'zero',\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
|
@@ -10,7 +10,7 @@ export interface MetroCompilerTransformerOptions {
|
|
|
10
10
|
* Metro never reads an ambient value: the literal is decided by the build and
|
|
11
11
|
* inlined here so every guard is a constant.
|
|
12
12
|
*/
|
|
13
|
-
runtimeLiteral?: "full" | "zero";
|
|
13
|
+
runtimeLiteral?: "full" | "zero" | "island";
|
|
14
14
|
/** The integration-owned compiled CSS marker for this bundle request. */
|
|
15
15
|
didOutputCSSLiteral?: "1";
|
|
16
16
|
}
|
|
@@ -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,SAAS;;CAEnC,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 /** 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"
|
|
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' | 'island'\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
|
}
|