@tamagui/metro-plugin 3.0.9 → 3.0.11

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.
@@ -156,7 +156,11 @@ function createMetroCompilerResolver(config) {
156
156
  originModulePath: importer,
157
157
  preferNativePlatform: true,
158
158
  projectRoot: config.projectRoot,
159
- resolveAsset: () => null,
159
+ resolveAsset: (dirPath, assetName, extension) => {
160
+ const basePath = (0, import_node_path.join)(dirPath, assetName);
161
+ const assets = [basePath + extension, ...(resolver.assetResolutions ?? []).map((resolution) => `${basePath}@${resolution}x${extension}`)].map((assetPath) => fileSystemLookup(assetPath).realPath).filter((assetPath) => !!assetPath);
162
+ return assets.length ? assets : null;
163
+ },
160
164
  resolveHasteModule: () => null,
161
165
  resolveHastePackage: () => null,
162
166
  resolveRequest: resolver.resolveRequest ?? null,
@@ -130,7 +130,11 @@ function createMetroCompilerResolver(config) {
130
130
  originModulePath: importer,
131
131
  preferNativePlatform: true,
132
132
  projectRoot: config.projectRoot,
133
- resolveAsset: () => null,
133
+ resolveAsset: (dirPath, assetName, extension) => {
134
+ const basePath = join(dirPath, assetName);
135
+ const assets = [basePath + extension, ...(resolver.assetResolutions ?? []).map((resolution) => `${basePath}@${resolution}x${extension}`)].map((assetPath) => fileSystemLookup(assetPath).realPath).filter((assetPath) => !!assetPath);
136
+ return assets.length ? assets : null;
137
+ },
134
138
  resolveHasteModule: () => null,
135
139
  resolveHastePackage: () => null,
136
140
  resolveRequest: resolver.resolveRequest ?? null,
@@ -1 +1 @@
1
- {"version":3,"file":"metroResolver.js","names":[],"sources":["esm/metroResolver.js"],"sourcesContent":["import { existsSync, lstatSync, readFileSync, realpathSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, extname, isAbsolute, join, parse, relative, resolve } from \"node:path\";\nfunction compareCodeUnits(left, right) {\n return left < right ? -1 : left > right ? 1 : 0;\n}\nfunction findClosestPackage(path) {\n let directory = existsSync(path) && statSync(path).isDirectory() ? path : dirname(path);\n const root = parse(directory).root;\n while (true) {\n const packagePath = join(directory, \"package.json\");\n if (existsSync(packagePath)) {\n try {\n return {\n rootPath: directory,\n packageJson: JSON.parse(readFileSync(packagePath, \"utf8\")),\n packageRelativePath: relative(directory, path)\n };\n } catch {\n return null;\n }\n }\n if (directory === root || directory.endsWith(`${join(\"node_modules\")}`)) {\n return null;\n }\n directory = dirname(directory);\n }\n}\nfunction lookup(projectRoot, path) {\n const absolutePath = isAbsolute(path) ? path : resolve(projectRoot, path);\n try {\n const stat = lstatSync(absolutePath);\n const realPath = realpathSync(absolutePath);\n return {\n exists: true,\n type: stat.isDirectory() ? \"d\" : \"f\",\n realPath\n };\n } catch {\n return { exists: false };\n }\n}\nfunction moduleSpecifiersFromAst(ast) {\n const specifiers = /* @__PURE__ */ new Map();\n const seen = /* @__PURE__ */ new Set();\n function add(value, isESMImport) {\n if (typeof value !== \"string\") return;\n specifiers.set(value, (specifiers.get(value) ?? false) || isESMImport);\n }\n function visit(value) {\n if (!value || typeof value !== \"object\") return;\n if (seen.has(value)) return;\n seen.add(value);\n if (Array.isArray(value)) {\n for (const child of value) visit(child);\n return;\n }\n const node = value;\n if (node.type === \"ImportDeclaration\" || node.type === \"ExportAllDeclaration\" || node.type === \"ExportNamedDeclaration\") {\n add(node.source?.value, true);\n } else if (node.type === \"CallExpression\") {\n const first = node.arguments?.[0];\n if (node.callee?.type === \"Import\") {\n add(first?.value, true);\n } else if (node.callee?.type === \"Identifier\" && node.callee.name === \"require\") {\n add(first?.value, false);\n }\n }\n for (const [key, child] of Object.entries(node)) {\n if (key === \"loc\" || key === \"comments\" || key === \"tokens\") continue;\n visit(child);\n }\n }\n visit(ast);\n return [...specifiers].sort(([left], [right]) => compareCodeUnits(left, right)).map(([specifier, isESMImport]) => ({ specifier, isESMImport }));\n}\nfunction createMetroCompilerResolver(config) {\n const requireFromProject = createRequire(join(config.projectRoot, \"package.json\"));\n const resolverPackage = requireFromProject(\"metro-resolver/package.json\");\n if (!resolverPackage.version.startsWith(\"0.84.\")) {\n throw new Error(\n `@tamagui/metro-plugin requires the Metro 0.84 resolver contract, found ${resolverPackage.version}`\n );\n }\n const resolverModule = requireFromProject(\"metro-resolver\");\n const metroResolve = resolverModule.resolve;\n const createDefaultContextModule = requireFromProject(\n \"metro-resolver/private/createDefaultContext\"\n );\n const createDefaultContext = createDefaultContextModule.default ?? createDefaultContextModule;\n const resolver = config.resolver ?? {};\n const fileSystemLookup = (path) => lookup(config.projectRoot, path);\n const getPackage = (packagePath) => {\n try {\n return JSON.parse(readFileSync(packagePath, \"utf8\"));\n } catch {\n return null;\n }\n };\n return {\n version: resolverPackage.version,\n resolve(importer, dependency, platform) {\n const dependencyDescriptor = {\n name: dependency.specifier,\n data: {\n asyncType: null,\n isESMImport: dependency.isESMImport,\n key: dependency.specifier,\n locs: []\n }\n };\n const context = createDefaultContext(\n {\n allowHaste: false,\n assetExts: new Set(resolver.assetExts ?? []),\n customResolverOptions: {},\n dev: true,\n disableHierarchicalLookup: resolver.disableHierarchicalLookup ?? false,\n doesFileExist: (path) => fileSystemLookup(path).type === \"f\",\n extraNodeModules: resolver.extraNodeModules ?? null,\n fileSystemLookup,\n getPackage,\n getPackageForModule: findClosestPackage,\n isESMImport: dependency.isESMImport,\n mainFields: resolver.resolverMainFields ?? [\"react-native\", \"browser\", \"main\"],\n nodeModulesPaths: resolver.nodeModulesPaths ?? [],\n originModulePath: importer,\n preferNativePlatform: true,\n projectRoot: config.projectRoot,\n resolveAsset: () => null,\n resolveHasteModule: () => null,\n resolveHastePackage: () => null,\n resolveRequest: resolver.resolveRequest ?? null,\n sourceExts: resolver.sourceExts ?? [\"js\", \"jsx\", \"json\", \"ts\", \"tsx\"],\n unstable_conditionNames: resolver.unstable_conditionNames ?? [],\n unstable_conditionsByPlatform: resolver.unstable_conditionsByPlatform ?? {},\n unstable_enablePackageExports: resolver.unstable_enablePackageExports ?? true,\n unstable_logWarning: (message) => config.resolver?.unstable_logWarning?.(message)\n },\n dependencyDescriptor\n );\n const result = metroResolve(context, dependency.specifier, platform);\n if (result.type === \"empty\") return null;\n if (result.type !== \"sourceFile\" || !result.filePath) return null;\n const resolvedId = realpathSync(result.filePath);\n return {\n specifier: dependency.specifier,\n resolvedId,\n external: resolvedId.includes(`${join(\"node_modules\")}`)\n };\n }\n };\n}\nfunction isCompilerSourceFile(path) {\n return [\".js\", \".jsx\", \".mjs\", \".cjs\", \".ts\", \".tsx\"].includes(extname(path));\n}\nexport {\n createMetroCompilerResolver,\n isCompilerSourceFile,\n moduleSpecifiersFromAst\n};\n//# sourceMappingURL=metroResolver.js.map\n"],"mappings":";;;;;AAGA,SAAS,iBAAiB,MAAM,OAAO;CACrC,OAAO,OAAO,QAAQ,CAAC,IAAI,OAAO,QAAQ,IAAI;AAChD;AACA,SAAS,mBAAmB,MAAM;CAChC,IAAI,YAAY,WAAW,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,YAAY,IAAI,OAAO,QAAQ,IAAI;CACtF,MAAM,OAAO,MAAM,SAAS,CAAC,CAAC;CAC9B,OAAO,MAAM;EACX,MAAM,cAAc,KAAK,WAAW,cAAc;EAClD,IAAI,WAAW,WAAW,GAAG;GAC3B,IAAI;IACF,OAAO;KACL,UAAU;KACV,aAAa,KAAK,MAAM,aAAa,aAAa,MAAM,CAAC;KACzD,qBAAqB,SAAS,WAAW,IAAI;IAC/C;GACF,QAAQ;IACN,OAAO;GACT;EACF;EACA,IAAI,cAAc,QAAQ,UAAU,SAAS,GAAG,KAAK,cAAc,GAAG,GAAG;GACvE,OAAO;EACT;EACA,YAAY,QAAQ,SAAS;CAC/B;AACF;AACA,SAAS,OAAO,aAAa,MAAM;CACjC,MAAM,eAAe,WAAW,IAAI,IAAI,OAAO,QAAQ,aAAa,IAAI;CACxE,IAAI;EACF,MAAM,OAAO,UAAU,YAAY;EACnC,MAAM,WAAW,aAAa,YAAY;EAC1C,OAAO;GACL,QAAQ;GACR,MAAM,KAAK,YAAY,IA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AAC;KAAM;KAAO;KAAQ;KAAM;IAAK;IACpE,yBAAyB,SAAS,2BAA2B,CAAC;IAC9D,+BAA+B,SAAS,iCAAiC,CAAC;IAC1E,+BAA+B,SAAS,iCAAiC;IACzE,sBAAsB,YAAY,OAAO,UAAU,sBAAsB,OAAO;GAClF,GACA,oBACF;GACA,MAAM,SAAS,aAAa,SAAS,WAAW,WAAW,QAAQ;GACnE,IAAI,OAAO,SAAS,SAAS,OAAO;GACpC,IAAI,OAAO,SAAS,gBAAgB,CAAC,OAAO,UAAU,OAAO;GAC7D,MAAM,aAAa,aAAa,OAAO,QAAQ;GAC/C,OAAO;IACL,WAAW,WAAW;IACtB;IACA,UAAU,WAAW,SAAS,GAAG,KAAK,cAAc,GAAG;GACzD;EACF;CACF;AACF;AACA,SAAS,qBAAqB,MAAM;CAClC,OAAO;EAAC;EAAO;EAAQ;EAAQ;EAAQ;EAAO;CAAM,CAAC,CAAC,SAAS,QAAQ,IAAI,CAAC;AAC9E"}
1
+ {"version":3,"file":"metroResolver.js","names":[],"sources":["esm/metroResolver.js"],"sourcesContent":["import { existsSync, lstatSync, readFileSync, realpathSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, extname, isAbsolute, join, parse, relative, resolve } from \"node:path\";\nfunction compareCodeUnits(left, right) {\n return left < right ? -1 : left > right ? 1 : 0;\n}\nfunction findClosestPackage(path) {\n let directory = existsSync(path) && statSync(path).isDirectory() ? path : dirname(path);\n const root = parse(directory).root;\n while (true) {\n const packagePath = join(directory, \"package.json\");\n if (existsSync(packagePath)) {\n try {\n return {\n rootPath: directory,\n packageJson: JSON.parse(readFileSync(packagePath, \"utf8\")),\n packageRelativePath: relative(directory, path)\n };\n } catch {\n return null;\n }\n }\n if (directory === root || directory.endsWith(`${join(\"node_modules\")}`)) {\n return null;\n }\n directory = dirname(directory);\n }\n}\nfunction lookup(projectRoot, path) {\n const absolutePath = isAbsolute(path) ? path : resolve(projectRoot, path);\n try {\n const stat = lstatSync(absolutePath);\n const realPath = realpathSync(absolutePath);\n return {\n exists: true,\n type: stat.isDirectory() ? \"d\" : \"f\",\n realPath\n };\n } catch {\n return { exists: false };\n }\n}\nfunction moduleSpecifiersFromAst(ast) {\n const specifiers = /* @__PURE__ */ new Map();\n const seen = /* @__PURE__ */ new Set();\n function add(value, isESMImport) {\n if (typeof value !== \"string\") return;\n specifiers.set(value, (specifiers.get(value) ?? false) || isESMImport);\n }\n function visit(value) {\n if (!value || typeof value !== \"object\") return;\n if (seen.has(value)) return;\n seen.add(value);\n if (Array.isArray(value)) {\n for (const child of value) visit(child);\n return;\n }\n const node = value;\n if (node.type === \"ImportDeclaration\" || node.type === \"ExportAllDeclaration\" || node.type === \"ExportNamedDeclaration\") {\n add(node.source?.value, true);\n } else if (node.type === \"CallExpression\") {\n const first = node.arguments?.[0];\n if (node.callee?.type === \"Import\") {\n add(first?.value, true);\n } else if (node.callee?.type === \"Identifier\" && node.callee.name === \"require\") {\n add(first?.value, false);\n }\n }\n for (const [key, child] of Object.entries(node)) {\n if (key === \"loc\" || key === \"comments\" || key === \"tokens\") continue;\n visit(child);\n }\n }\n visit(ast);\n return [...specifiers].sort(([left], [right]) => compareCodeUnits(left, right)).map(([specifier, isESMImport]) => ({ specifier, isESMImport }));\n}\nfunction createMetroCompilerResolver(config) {\n const requireFromProject = createRequire(join(config.projectRoot, \"package.json\"));\n const resolverPackage = requireFromProject(\"metro-resolver/package.json\");\n if (!resolverPackage.version.startsWith(\"0.84.\")) {\n throw new Error(\n `@tamagui/metro-plugin requires the Metro 0.84 resolver contract, found ${resolverPackage.version}`\n );\n }\n const resolverModule = requireFromProject(\"metro-resolver\");\n const metroResolve = resolverModule.resolve;\n const createDefaultContextModule = requireFromProject(\n \"metro-resolver/private/createDefaultContext\"\n );\n const createDefaultContext = createDefaultContextModule.default ?? createDefaultContextModule;\n const resolver = config.resolver ?? {};\n const fileSystemLookup = (path) => lookup(config.projectRoot, path);\n const getPackage = (packagePath) => {\n try {\n return JSON.parse(readFileSync(packagePath, \"utf8\"));\n } catch {\n return null;\n }\n };\n return {\n version: resolverPackage.version,\n resolve(importer, dependency, platform) {\n const dependencyDescriptor = {\n name: dependency.specifier,\n data: {\n asyncType: null,\n isESMImport: dependency.isESMImport,\n key: dependency.specifier,\n locs: []\n }\n };\n const context = createDefaultContext(\n {\n allowHaste: false,\n assetExts: new Set(resolver.assetExts ?? []),\n customResolverOptions: {},\n dev: true,\n disableHierarchicalLookup: resolver.disableHierarchicalLookup ?? false,\n doesFileExist: (path) => fileSystemLookup(path).type === \"f\",\n extraNodeModules: resolver.extraNodeModules ?? null,\n fileSystemLookup,\n getPackage,\n getPackageForModule: findClosestPackage,\n isESMImport: dependency.isESMImport,\n mainFields: resolver.resolverMainFields ?? [\"react-native\", \"browser\", \"main\"],\n nodeModulesPaths: resolver.nodeModulesPaths ?? [],\n originModulePath: importer,\n preferNativePlatform: true,\n projectRoot: config.projectRoot,\n // as metro's DependencyGraph does, so an existing asset is not a failure\n resolveAsset: (dirPath, assetName, extension) => {\n const basePath = join(dirPath, assetName);\n const assets = [\n basePath + extension,\n ...(resolver.assetResolutions ?? []).map(\n (resolution) => `${basePath}@${resolution}x${extension}`\n )\n ].map((assetPath) => fileSystemLookup(assetPath).realPath).filter((assetPath) => !!assetPath);\n return assets.length ? assets : null;\n },\n resolveHasteModule: () => null,\n resolveHastePackage: () => null,\n resolveRequest: resolver.resolveRequest ?? null,\n sourceExts: resolver.sourceExts ?? [\"js\", \"jsx\", \"json\", \"ts\", \"tsx\"],\n unstable_conditionNames: resolver.unstable_conditionNames ?? [],\n unstable_conditionsByPlatform: resolver.unstable_conditionsByPlatform ?? {},\n unstable_enablePackageExports: resolver.unstable_enablePackageExports ?? true,\n unstable_logWarning: (message) => config.resolver?.unstable_logWarning?.(message)\n },\n dependencyDescriptor\n );\n const result = metroResolve(context, dependency.specifier, platform);\n if (result.type === \"empty\") return null;\n if (result.type !== \"sourceFile\" || !result.filePath) return null;\n const resolvedId = realpathSync(result.filePath);\n return {\n specifier: dependency.specifier,\n resolvedId,\n external: resolvedId.includes(`${join(\"node_modules\")}`)\n };\n }\n };\n}\nfunction isCompilerSourceFile(path) {\n return [\".js\", \".jsx\", \".mjs\", \".cjs\", \".ts\", \".tsx\"].includes(extname(path));\n}\nexport {\n createMetroCompilerResolver,\n isCompilerSourceFile,\n moduleSpecifiersFromAst\n};\n//# sourceMappingURL=metroResolver.js.map\n"],"mappings":";;;;;AAGA,SAAS,iBAAiB,MAAM,OAAO;CACrC,OAAO,OAAO,QAAQ,CAAC,IAAI,OAAO,QAAQ,IAAI;AAChD;AACA,SAAS,mBAAmB,MAAM;CAChC,IAAI,YAAY,WAAW,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,YAAY,IAAI,OAAO,QAAQ,IAAI;CACtF,MAAM,OAAO,MAAM,SAAS,CAAC,CAAC;CAC9B,OAAO,MAAM;EACX,MAAM,cAAc,KAAK,WAAW,cAAc;EAClD,IAAI,WAAW,WAAW,GAAG;GAC3B,IAAI;IACF,OAAO;KACL,UAAU;KACV,aAAa,KAAK,MAAM,aAAa,aAAa,MAAM,CAAC;KACzD,qBAAqB,SAAS,WAAW,IAAI;IAC/C;GACF,QAAQ;IACN,OAAO;GACT;EACF;EACA,IAAI,cAAc,QAAQ,UAAU,SAAS,GAAG,KAAK,cAAc,GAAG,GAAG;GACvE,OAAO;EACT;EACA,YAAY,QAAQ,SAAS;CAC/B;AACF;AACA,SAAS,OAAO,aAAa,MAAM;CACjC,MAAM,eAAe,WAAW,IAAI,IAAI,OAAO,QAAQ,aAAa,IAAI;CACxE,IAAI;EACF,MAAM,OAAO,UAAU,YAAY;EACnC,MAAM,WAAW,aAAa,YAAY;EAC1C,OAAO;GACL,QAAQ;GACR,MAAM,KAAK,YAAY,IAAI,MAAM;GACjC;EACF;CACF,QAAQ;EACN,OAAO,EAAE,QAAQ,MAAM;CACzB;AACF;AACA,SAAS,wBAAwB,KAAK;CACpC,MAAM,6BAA6B,IAAI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B,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,cAAc,CAAC,CAAC,SAAS;KAC5F,OAAO,OAAO,SAAS,SAAS;IAClC;IACA,0BAA0B;IAC1B,2BAA2B;IAC3B,gBAAgB,SAAS,kBAAkB;IAC3C,YAAY,SAAS,cAAc;KAAC;KAAM;KAAO;KAAQ;KAAM;IAAK;IACpE,yBAAyB,SAAS,2BAA2B,CAAC;IAC9D,+BAA+B,SAAS,iCAAiC,CAAC;IAC1E,+BAA+B,SAAS,iCAAiC;IACzE,sBAAsB,YAAY,OAAO,UAAU,sBAAsB,OAAO;GAClF,GACA,oBACF;GACA,MAAM,SAAS,aAAa,SAAS,WAAW,WAAW,QAAQ;GACnE,IAAI,OAAO,SAAS,SAAS,OAAO;GACpC,IAAI,OAAO,SAAS,gBAAgB,CAAC,OAAO,UAAU,OAAO;GAC7D,MAAM,aAAa,aAAa,OAAO,QAAQ;GAC/C,OAAO;IACL,WAAW,WAAW;IACtB;IACA,UAAU,WAAW,SAAS,GAAG,KAAK,cAAc,GAAG;GACzD;EACF;CACF;AACF;AACA,SAAS,qBAAqB,MAAM;CAClC,OAAO;EAAC;EAAO;EAAQ;EAAQ;EAAQ;EAAO;CAAM,CAAC,CAAC,SAAS,QAAQ,IAAI,CAAC;AAC9E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/metro-plugin",
3
- "version": "3.0.9",
3
+ "version": "3.0.11",
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.9",
45
- "@tamagui/static": "3.0.9",
44
+ "@tamagui/compiler-core": "3.0.11",
45
+ "@tamagui/static": "3.0.11",
46
46
  "ignore": "^5.3.2"
47
47
  },
48
48
  "devDependencies": {
49
- "@tamagui/build": "3.0.9",
49
+ "@tamagui/build": "3.0.11",
50
50
  "metro": "0.84.4",
51
51
  "metro-resolver": "0.84.4"
52
52
  },
@@ -59,5 +59,5 @@
59
59
  "url": "git+https://github.com/tamagui/tamagui.git",
60
60
  "directory": "code/compiler/metro-plugin"
61
61
  },
62
- "releaseSourceCommit": "1971272fa9915450004c84ea48188100fdf278ff"
62
+ "releaseSourceCommit": "2126db6e1f5389c724e21f06ce7d7e7d9f49f4aa"
63
63
  }
@@ -178,7 +178,19 @@ export function createMetroCompilerResolver(config: MetroResolverConfig): {
178
178
  originModulePath: importer,
179
179
  preferNativePlatform: true,
180
180
  projectRoot: config.projectRoot,
181
- resolveAsset: () => null,
181
+ // as metro's DependencyGraph does, so an existing asset is not a failure
182
+ resolveAsset: (dirPath: string, assetName: string, extension: string) => {
183
+ const basePath = join(dirPath, assetName)
184
+ const assets = [
185
+ basePath + extension,
186
+ ...(resolver.assetResolutions ?? []).map(
187
+ (resolution: string) => `${basePath}@${resolution}x${extension}`
188
+ ),
189
+ ]
190
+ .map((assetPath) => fileSystemLookup(assetPath).realPath)
191
+ .filter((assetPath): assetPath is string => !!assetPath)
192
+ return assets.length ? assets : null
193
+ },
182
194
  resolveHasteModule: () => null,
183
195
  resolveHastePackage: () => null,
184
196
  resolveRequest: resolver.resolveRequest ?? null,
@@ -1,11 +1,11 @@
1
1
  {
2
- "mappings": "AAIA,iBAAiB,oBAAoB;CACnC;CACA,WAAW;;AAGb,iBAAiB,wBAAwB;CACvC;CACA;CACA;;AAGF,iBAAiB,qBAAqB;CACpC;CACA;;AAuDF,OAAO,iBAAS,wBAAwB,eAAe;AA4CvD,OAAO,iBAAS,4BAA4B,QAAQ,sBAAsB;CACxE;CACA,QACE,kBACA,YAAY,sBACZ,0BACC;;AAoFL,OAAO,iBAAS,qBAAqB",
2
+ "mappings": "AAIA,iBAAiB,oBAAoB;CACnC;CACA,WAAW;;AAGb,iBAAiB,wBAAwB;CACvC;CACA;CACA;;AAGF,iBAAiB,qBAAqB;CACpC;CACA;;AAuDF,OAAO,iBAAS,wBAAwB,eAAe;AA4CvD,OAAO,iBAAS,4BAA4B,QAAQ,sBAAsB;CACxE;CACA,QACE,kBACA,YAAY,sBACZ,0BACC;;AAgGL,OAAO,iBAAS,qBAAqB",
3
3
  "names": [],
4
4
  "sources": [
5
5
  "src/metroResolver.ts"
6
6
  ],
7
7
  "version": 3,
8
8
  "sourcesContent": [
9
- "import { existsSync, lstatSync, readFileSync, realpathSync, statSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, extname, isAbsolute, join, parse, relative, resolve } from 'node:path'\n\nexport interface MetroResolverConfig {\n projectRoot: string\n resolver?: Record<string, any>\n}\n\nexport interface MetroResolvedDependency {\n specifier: string\n resolvedId: string\n external: boolean\n}\n\nexport interface MetroModuleSpecifier {\n specifier: string\n isESMImport: boolean\n}\n\ntype MetroResolve = (\n context: Record<string, any>,\n specifier: string,\n platform: string | null\n) => { type: string; filePath?: string }\n\nfunction compareCodeUnits(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0\n}\n\nfunction findClosestPackage(path: string): {\n rootPath: string\n packageJson: Record<string, any>\n packageRelativePath: string\n} | null {\n let directory = existsSync(path) && statSync(path).isDirectory() ? path : dirname(path)\n const root = parse(directory).root\n while (true) {\n const packagePath = join(directory, 'package.json')\n if (existsSync(packagePath)) {\n try {\n return {\n rootPath: directory,\n packageJson: JSON.parse(readFileSync(packagePath, 'utf8')),\n packageRelativePath: relative(directory, path),\n }\n } catch {\n return null\n }\n }\n if (directory === root || directory.endsWith(`${join('node_modules')}`)) {\n return null\n }\n directory = dirname(directory)\n }\n}\n\nfunction lookup(projectRoot: string, path: string) {\n const absolutePath = isAbsolute(path) ? path : resolve(projectRoot, path)\n try {\n const stat = lstatSync(absolutePath)\n const realPath = realpathSync(absolutePath)\n return {\n exists: true as const,\n type: (stat.isDirectory() ? 'd' : 'f') as 'd' | 'f',\n realPath,\n }\n } catch {\n return { exists: false as const }\n }\n}\n\nexport function moduleSpecifiersFromAst(ast: unknown): MetroModuleSpecifier[] {\n const specifiers = new Map<string, boolean>()\n const seen = new Set<object>()\n\n function add(value: unknown, isESMImport: boolean): void {\n if (typeof value !== 'string') return\n specifiers.set(value, (specifiers.get(value) ?? false) || isESMImport)\n }\n\n function visit(value: unknown): void {\n if (!value || typeof value !== 'object') return\n if (seen.has(value)) return\n seen.add(value)\n if (Array.isArray(value)) {\n for (const child of value) visit(child)\n return\n }\n const node = value as Record<string, any>\n if (\n node.type === 'ImportDeclaration' ||\n node.type === 'ExportAllDeclaration' ||\n node.type === 'ExportNamedDeclaration'\n ) {\n add(node.source?.value, true)\n } else if (node.type === 'CallExpression') {\n const first = node.arguments?.[0]\n if (node.callee?.type === 'Import') {\n add(first?.value, true)\n } else if (node.callee?.type === 'Identifier' && node.callee.name === 'require') {\n add(first?.value, false)\n }\n }\n for (const [key, child] of Object.entries(node)) {\n if (key === 'loc' || key === 'comments' || key === 'tokens') continue\n visit(child)\n }\n }\n\n visit(ast)\n return [...specifiers]\n .sort(([left], [right]) => compareCodeUnits(left, right))\n .map(([specifier, isESMImport]) => ({ specifier, isESMImport }))\n}\n\nexport function createMetroCompilerResolver(config: MetroResolverConfig): {\n version: string\n resolve(\n importer: string,\n dependency: MetroModuleSpecifier,\n platform: string | null\n ): MetroResolvedDependency | null\n} {\n const requireFromProject = createRequire(join(config.projectRoot, 'package.json'))\n const resolverPackage = requireFromProject('metro-resolver/package.json') as {\n version: string\n }\n if (!resolverPackage.version.startsWith('0.84.')) {\n throw new Error(\n `@tamagui/metro-plugin requires the Metro 0.84 resolver contract, found ${resolverPackage.version}`\n )\n }\n const resolverModule = requireFromProject('metro-resolver')\n const metroResolve: MetroResolve = resolverModule.resolve\n const createDefaultContextModule = requireFromProject(\n 'metro-resolver/private/createDefaultContext'\n )\n const createDefaultContext =\n createDefaultContextModule.default ?? createDefaultContextModule\n const resolver = config.resolver ?? {}\n const fileSystemLookup = (path: string) => lookup(config.projectRoot, path)\n const getPackage = (packagePath: string) => {\n try {\n return JSON.parse(readFileSync(packagePath, 'utf8'))\n } catch {\n return null\n }\n }\n\n return {\n version: resolverPackage.version,\n resolve(importer, dependency, platform) {\n const dependencyDescriptor = {\n name: dependency.specifier,\n data: {\n asyncType: null,\n isESMImport: dependency.isESMImport,\n key: dependency.specifier,\n locs: [],\n },\n }\n const context = createDefaultContext(\n {\n allowHaste: false,\n assetExts: new Set(resolver.assetExts ?? []),\n customResolverOptions: {},\n dev: true,\n disableHierarchicalLookup: resolver.disableHierarchicalLookup ?? false,\n doesFileExist: (path: string) => fileSystemLookup(path).type === 'f',\n extraNodeModules: resolver.extraNodeModules ?? null,\n fileSystemLookup,\n getPackage,\n getPackageForModule: findClosestPackage,\n isESMImport: dependency.isESMImport,\n mainFields: resolver.resolverMainFields ?? ['react-native', 'browser', 'main'],\n nodeModulesPaths: resolver.nodeModulesPaths ?? [],\n originModulePath: importer,\n preferNativePlatform: true,\n projectRoot: config.projectRoot,\n resolveAsset: () => null,\n resolveHasteModule: () => null,\n resolveHastePackage: () => null,\n resolveRequest: resolver.resolveRequest ?? null,\n sourceExts: resolver.sourceExts ?? ['js', 'jsx', 'json', 'ts', 'tsx'],\n unstable_conditionNames: resolver.unstable_conditionNames ?? [],\n unstable_conditionsByPlatform: resolver.unstable_conditionsByPlatform ?? {},\n unstable_enablePackageExports: resolver.unstable_enablePackageExports ?? true,\n unstable_logWarning: (message: string) =>\n config.resolver?.unstable_logWarning?.(message),\n },\n dependencyDescriptor\n )\n const result = metroResolve(context, dependency.specifier, platform)\n if (result.type === 'empty') return null\n if (result.type !== 'sourceFile' || !result.filePath) return null\n const resolvedId = realpathSync(result.filePath)\n return {\n specifier: dependency.specifier,\n resolvedId,\n external: resolvedId.includes(`${join('node_modules')}`),\n }\n },\n }\n}\n\nexport function isCompilerSourceFile(path: string): boolean {\n return ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'].includes(extname(path))\n}\n"
9
+ "import { existsSync, lstatSync, readFileSync, realpathSync, statSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, extname, isAbsolute, join, parse, relative, resolve } from 'node:path'\n\nexport interface MetroResolverConfig {\n projectRoot: string\n resolver?: Record<string, any>\n}\n\nexport interface MetroResolvedDependency {\n specifier: string\n resolvedId: string\n external: boolean\n}\n\nexport interface MetroModuleSpecifier {\n specifier: string\n isESMImport: boolean\n}\n\ntype MetroResolve = (\n context: Record<string, any>,\n specifier: string,\n platform: string | null\n) => { type: string; filePath?: string }\n\nfunction compareCodeUnits(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0\n}\n\nfunction findClosestPackage(path: string): {\n rootPath: string\n packageJson: Record<string, any>\n packageRelativePath: string\n} | null {\n let directory = existsSync(path) && statSync(path).isDirectory() ? path : dirname(path)\n const root = parse(directory).root\n while (true) {\n const packagePath = join(directory, 'package.json')\n if (existsSync(packagePath)) {\n try {\n return {\n rootPath: directory,\n packageJson: JSON.parse(readFileSync(packagePath, 'utf8')),\n packageRelativePath: relative(directory, path),\n }\n } catch {\n return null\n }\n }\n if (directory === root || directory.endsWith(`${join('node_modules')}`)) {\n return null\n }\n directory = dirname(directory)\n }\n}\n\nfunction lookup(projectRoot: string, path: string) {\n const absolutePath = isAbsolute(path) ? path : resolve(projectRoot, path)\n try {\n const stat = lstatSync(absolutePath)\n const realPath = realpathSync(absolutePath)\n return {\n exists: true as const,\n type: (stat.isDirectory() ? 'd' : 'f') as 'd' | 'f',\n realPath,\n }\n } catch {\n return { exists: false as const }\n }\n}\n\nexport function moduleSpecifiersFromAst(ast: unknown): MetroModuleSpecifier[] {\n const specifiers = new Map<string, boolean>()\n const seen = new Set<object>()\n\n function add(value: unknown, isESMImport: boolean): void {\n if (typeof value !== 'string') return\n specifiers.set(value, (specifiers.get(value) ?? false) || isESMImport)\n }\n\n function visit(value: unknown): void {\n if (!value || typeof value !== 'object') return\n if (seen.has(value)) return\n seen.add(value)\n if (Array.isArray(value)) {\n for (const child of value) visit(child)\n return\n }\n const node = value as Record<string, any>\n if (\n node.type === 'ImportDeclaration' ||\n node.type === 'ExportAllDeclaration' ||\n node.type === 'ExportNamedDeclaration'\n ) {\n add(node.source?.value, true)\n } else if (node.type === 'CallExpression') {\n const first = node.arguments?.[0]\n if (node.callee?.type === 'Import') {\n add(first?.value, true)\n } else if (node.callee?.type === 'Identifier' && node.callee.name === 'require') {\n add(first?.value, false)\n }\n }\n for (const [key, child] of Object.entries(node)) {\n if (key === 'loc' || key === 'comments' || key === 'tokens') continue\n visit(child)\n }\n }\n\n visit(ast)\n return [...specifiers]\n .sort(([left], [right]) => compareCodeUnits(left, right))\n .map(([specifier, isESMImport]) => ({ specifier, isESMImport }))\n}\n\nexport function createMetroCompilerResolver(config: MetroResolverConfig): {\n version: string\n resolve(\n importer: string,\n dependency: MetroModuleSpecifier,\n platform: string | null\n ): MetroResolvedDependency | null\n} {\n const requireFromProject = createRequire(join(config.projectRoot, 'package.json'))\n const resolverPackage = requireFromProject('metro-resolver/package.json') as {\n version: string\n }\n if (!resolverPackage.version.startsWith('0.84.')) {\n throw new Error(\n `@tamagui/metro-plugin requires the Metro 0.84 resolver contract, found ${resolverPackage.version}`\n )\n }\n const resolverModule = requireFromProject('metro-resolver')\n const metroResolve: MetroResolve = resolverModule.resolve\n const createDefaultContextModule = requireFromProject(\n 'metro-resolver/private/createDefaultContext'\n )\n const createDefaultContext =\n createDefaultContextModule.default ?? createDefaultContextModule\n const resolver = config.resolver ?? {}\n const fileSystemLookup = (path: string) => lookup(config.projectRoot, path)\n const getPackage = (packagePath: string) => {\n try {\n return JSON.parse(readFileSync(packagePath, 'utf8'))\n } catch {\n return null\n }\n }\n\n return {\n version: resolverPackage.version,\n resolve(importer, dependency, platform) {\n const dependencyDescriptor = {\n name: dependency.specifier,\n data: {\n asyncType: null,\n isESMImport: dependency.isESMImport,\n key: dependency.specifier,\n locs: [],\n },\n }\n const context = createDefaultContext(\n {\n allowHaste: false,\n assetExts: new Set(resolver.assetExts ?? []),\n customResolverOptions: {},\n dev: true,\n disableHierarchicalLookup: resolver.disableHierarchicalLookup ?? false,\n doesFileExist: (path: string) => fileSystemLookup(path).type === 'f',\n extraNodeModules: resolver.extraNodeModules ?? null,\n fileSystemLookup,\n getPackage,\n getPackageForModule: findClosestPackage,\n isESMImport: dependency.isESMImport,\n mainFields: resolver.resolverMainFields ?? ['react-native', 'browser', 'main'],\n nodeModulesPaths: resolver.nodeModulesPaths ?? [],\n originModulePath: importer,\n preferNativePlatform: true,\n projectRoot: config.projectRoot,\n // as metro's DependencyGraph does, so an existing asset is not a failure\n resolveAsset: (dirPath: string, assetName: string, extension: string) => {\n const basePath = join(dirPath, assetName)\n const assets = [\n basePath + extension,\n ...(resolver.assetResolutions ?? []).map(\n (resolution: string) => `${basePath}@${resolution}x${extension}`\n ),\n ]\n .map((assetPath) => fileSystemLookup(assetPath).realPath)\n .filter((assetPath): assetPath is string => !!assetPath)\n return assets.length ? assets : null\n },\n resolveHasteModule: () => null,\n resolveHastePackage: () => null,\n resolveRequest: resolver.resolveRequest ?? null,\n sourceExts: resolver.sourceExts ?? ['js', 'jsx', 'json', 'ts', 'tsx'],\n unstable_conditionNames: resolver.unstable_conditionNames ?? [],\n unstable_conditionsByPlatform: resolver.unstable_conditionsByPlatform ?? {},\n unstable_enablePackageExports: resolver.unstable_enablePackageExports ?? true,\n unstable_logWarning: (message: string) =>\n config.resolver?.unstable_logWarning?.(message),\n },\n dependencyDescriptor\n )\n const result = metroResolve(context, dependency.specifier, platform)\n if (result.type === 'empty') return null\n if (result.type !== 'sourceFile' || !result.filePath) return null\n const resolvedId = realpathSync(result.filePath)\n return {\n specifier: dependency.specifier,\n resolvedId,\n external: resolvedId.includes(`${join('node_modules')}`),\n }\n },\n }\n}\n\nexport function isCompilerSourceFile(path: string): boolean {\n return ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx'].includes(extname(path))\n}\n"
10
10
  ]
11
11
  }