@tamagui/metro-plugin 3.0.13 → 3.0.14
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.
|
@@ -107,8 +107,8 @@ function moduleSpecifiersFromAst(ast) {
|
|
|
107
107
|
function createMetroCompilerResolver(config) {
|
|
108
108
|
const requireFromProject = (0, import_node_module.createRequire)((0, import_node_path.join)(config.projectRoot, "package.json"));
|
|
109
109
|
const resolverPackage = requireFromProject("metro-resolver/package.json");
|
|
110
|
-
if (
|
|
111
|
-
throw new Error(`@tamagui/metro-plugin requires the Metro 0.84 resolver contract, found ${resolverPackage.version}`);
|
|
110
|
+
if (!/^0\.8[4-7]\./.test(resolverPackage.version)) {
|
|
111
|
+
throw new Error(`@tamagui/metro-plugin requires the Metro 0.84 to 0.87 resolver contract, found ${resolverPackage.version}`);
|
|
112
112
|
}
|
|
113
113
|
const resolverModule = requireFromProject("metro-resolver");
|
|
114
114
|
const metroResolve = resolverModule.resolve;
|
|
@@ -81,8 +81,8 @@ function moduleSpecifiersFromAst(ast) {
|
|
|
81
81
|
function createMetroCompilerResolver(config) {
|
|
82
82
|
const requireFromProject = createRequire(join(config.projectRoot, "package.json"));
|
|
83
83
|
const resolverPackage = requireFromProject("metro-resolver/package.json");
|
|
84
|
-
if (
|
|
85
|
-
throw new Error(`@tamagui/metro-plugin requires the Metro 0.84 resolver contract, found ${resolverPackage.version}`);
|
|
84
|
+
if (!/^0\.8[4-7]\./.test(resolverPackage.version)) {
|
|
85
|
+
throw new Error(`@tamagui/metro-plugin requires the Metro 0.84 to 0.87 resolver contract, found ${resolverPackage.version}`);
|
|
86
86
|
}
|
|
87
87
|
const resolverModule = requireFromProject("metro-resolver");
|
|
88
88
|
const metroResolve = resolverModule.resolve;
|
|
@@ -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 // 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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C;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 (!/^0\\.8[4-7]\\./.test(resolverPackage.version)) {\n throw new Error(\n `@tamagui/metro-plugin requires the Metro 0.84 to 0.87 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,M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AgB,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.
|
|
3
|
+
"version": "3.0.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -41,23 +41,23 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@jridgewell/trace-mapping": "0.3.31",
|
|
44
|
-
"@tamagui/compiler-core": "3.0.
|
|
45
|
-
"@tamagui/static": "3.0.
|
|
44
|
+
"@tamagui/compiler-core": "3.0.14",
|
|
45
|
+
"@tamagui/static": "3.0.14",
|
|
46
46
|
"ignore": "^5.3.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@tamagui/build": "3.0.
|
|
49
|
+
"@tamagui/build": "3.0.14",
|
|
50
50
|
"metro": "0.84.4",
|
|
51
51
|
"metro-resolver": "0.84.4"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"metro": "
|
|
55
|
-
"metro-resolver": "
|
|
54
|
+
"metro": ">=0.84.4 <0.88.0",
|
|
55
|
+
"metro-resolver": ">=0.84.4 <0.88.0"
|
|
56
56
|
},
|
|
57
57
|
"repository": {
|
|
58
58
|
"type": "git",
|
|
59
59
|
"url": "git+https://github.com/tamagui/tamagui.git",
|
|
60
60
|
"directory": "code/compiler/metro-plugin"
|
|
61
61
|
},
|
|
62
|
-
"releaseSourceCommit": "
|
|
62
|
+
"releaseSourceCommit": "61a8bd09550319d14c141581a8e4bb286a9795a6"
|
|
63
63
|
}
|
package/src/metroResolver.ts
CHANGED
|
@@ -126,9 +126,9 @@ export function createMetroCompilerResolver(config: MetroResolverConfig): {
|
|
|
126
126
|
const resolverPackage = requireFromProject('metro-resolver/package.json') as {
|
|
127
127
|
version: string
|
|
128
128
|
}
|
|
129
|
-
if (
|
|
129
|
+
if (!/^0\.8[4-7]\./.test(resolverPackage.version)) {
|
|
130
130
|
throw new Error(
|
|
131
|
-
`@tamagui/metro-plugin requires the Metro 0.84 resolver contract, found ${resolverPackage.version}`
|
|
131
|
+
`@tamagui/metro-plugin requires the Metro 0.84 to 0.87 resolver contract, found ${resolverPackage.version}`
|
|
132
132
|
)
|
|
133
133
|
}
|
|
134
134
|
const resolverModule = requireFromProject('metro-resolver')
|
|
@@ -6,6 +6,6 @@
|
|
|
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 (
|
|
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 (!/^0\\.8[4-7]\\./.test(resolverPackage.version)) {\n throw new Error(\n `@tamagui/metro-plugin requires the Metro 0.84 to 0.87 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
|
}
|