@tamagui/metro-plugin 2.7.7 → 3.0.0-beta.643.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/README.md +12 -0
- package/dist/cjs/babel.cjs +77 -0
- package/dist/cjs/compilerCache.cjs +237 -0
- package/dist/cjs/diagnostics.cjs +41 -0
- package/dist/cjs/frontend.cjs +870 -0
- package/dist/cjs/index.cjs +102 -0
- package/dist/cjs/lowering.cjs +109 -0
- package/dist/cjs/metroResolver.cjs +197 -0
- package/dist/cjs/transformOptions.cjs +35 -0
- package/dist/cjs/transformer.cjs +142 -0
- package/dist/cjs/zeroRuntime.cjs +140 -0
- package/dist/cjs/zeroSerializer.cjs +150 -0
- package/dist/esm/babel.mjs +52 -0
- package/dist/esm/babel.mjs.map +1 -0
- package/dist/esm/compilerCache.mjs +212 -0
- package/dist/esm/compilerCache.mjs.map +1 -0
- package/dist/esm/diagnostics.mjs +18 -0
- package/dist/esm/diagnostics.mjs.map +1 -0
- package/dist/esm/frontend.mjs +839 -0
- package/dist/esm/frontend.mjs.map +1 -0
- package/dist/esm/index.mjs +64 -22
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lowering.mjs +89 -0
- package/dist/esm/lowering.mjs.map +1 -0
- package/dist/esm/metroResolver.mjs +173 -0
- package/dist/esm/metroResolver.mjs.map +1 -0
- package/dist/esm/transformOptions.mjs +14 -0
- package/dist/esm/transformOptions.mjs.map +1 -0
- package/dist/esm/transformer.mjs +119 -0
- package/dist/esm/transformer.mjs.map +1 -0
- package/dist/esm/zeroRuntime.mjs +105 -0
- package/dist/esm/zeroRuntime.mjs.map +1 -0
- package/dist/esm/zeroSerializer.mjs +123 -0
- package/dist/esm/zeroSerializer.mjs.map +1 -0
- package/package.json +33 -5
- package/src/babel.ts +87 -0
- package/src/compilerCache.ts +346 -0
- package/src/diagnostics.ts +47 -0
- package/src/frontend.ts +1178 -0
- package/src/index.ts +117 -14
- package/src/lowering.ts +136 -0
- package/src/metroResolver.ts +209 -0
- package/src/transformOptions.ts +36 -0
- package/src/transformer.ts +210 -0
- package/src/zeroRuntime.ts +212 -0
- package/src/zeroSerializer.ts +175 -0
- package/types/babel.d.ts +28 -0
- package/types/babel.d.ts.map +11 -0
- package/types/compilerCache.d.ts +63 -0
- package/types/compilerCache.d.ts.map +11 -0
- package/types/diagnostics.d.ts +16 -0
- package/types/diagnostics.d.ts.map +11 -0
- package/types/frontend.d.ts +73 -0
- package/types/frontend.d.ts.map +11 -0
- package/types/index.d.ts +49 -32
- package/types/index.d.ts.map +11 -1
- package/types/lowering.d.ts +20 -0
- package/types/lowering.d.ts.map +11 -0
- package/types/metroResolver.d.ts +21 -0
- package/types/metroResolver.d.ts.map +11 -0
- package/types/transformOptions.d.ts +13 -0
- package/types/transformOptions.d.ts.map +11 -0
- package/types/transformer.d.ts +26 -0
- package/types/transformer.d.ts.map +11 -0
- package/types/zeroRuntime.d.ts +75 -0
- package/types/zeroRuntime.d.ts.map +11 -0
- package/types/zeroSerializer.d.ts +6 -0
- package/types/zeroSerializer.d.ts.map +11 -0
- package/dist/cjs/index.js +0 -45
- package/dist/cjs/index.js.map +0 -6
- package/dist/esm/index.js +0 -25
- package/dist/esm/index.js.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var index_exports = {};
|
|
29
|
+
__export(index_exports, {
|
|
30
|
+
METRO_COMPILER_CACHE_VERSION: () => import_compilerCache2.METRO_COMPILER_CACHE_VERSION,
|
|
31
|
+
MetroCompilerCache: () => import_compilerCache2.MetroCompilerCache,
|
|
32
|
+
MetroCompilerCacheError: () => import_compilerCache2.MetroCompilerCacheError,
|
|
33
|
+
defaultMetroCompilerCacheRoot: () => import_compilerCache2.defaultMetroCompilerCacheRoot,
|
|
34
|
+
getMetroCompilerFrontend: () => getMetroCompilerFrontend,
|
|
35
|
+
withTamagui: () => withTamagui
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_node_module = require("node:module");
|
|
39
|
+
var import_node_path = require("node:path");
|
|
40
|
+
var import_static = __toESM(require("@tamagui/static"), 1);
|
|
41
|
+
var import_compilerCache = require("./compilerCache.cjs");
|
|
42
|
+
var import_zeroSerializer = require("./zeroSerializer.cjs");
|
|
43
|
+
var import_zeroRuntime = require("./zeroRuntime.cjs");
|
|
44
|
+
var import_diagnostics = require("./diagnostics.cjs");
|
|
45
|
+
var import_frontend = require("./frontend.cjs");
|
|
46
|
+
var import_transformer = require("./transformer.cjs");
|
|
47
|
+
var import_transformOptions = require("./transformOptions.cjs");
|
|
48
|
+
var import_compilerCache2 = require("./compilerCache.cjs");
|
|
49
|
+
const import_meta = {};
|
|
50
|
+
const frontends = /* @__PURE__ */ new WeakMap();
|
|
51
|
+
const { loadTamaguiBuildConfigSync } = import_static.default;
|
|
52
|
+
const requireFromPlugin = (0, import_node_module.createRequire)(typeof __filename === "string" ? __filename : import_meta.url);
|
|
53
|
+
function getMetroCompilerFrontend(metroConfig) {
|
|
54
|
+
return frontends.get(metroConfig) ?? null;
|
|
55
|
+
}
|
|
56
|
+
function withTamagui(metroConfig, optionsIn) {
|
|
57
|
+
const { compilerCacheRoot, zeroIslandBuild, zeroPublicDir = "public", ...tamaguiOptionsIn } = optionsIn || {};
|
|
58
|
+
const options = loadTamaguiBuildConfigSync(tamaguiOptionsIn);
|
|
59
|
+
metroConfig.resolver = {
|
|
60
|
+
...metroConfig.resolver,
|
|
61
|
+
sourceExts: [.../* @__PURE__ */ new Set([...metroConfig.resolver?.sourceExts || [], "css"])]
|
|
62
|
+
};
|
|
63
|
+
metroConfig.transformer = {
|
|
64
|
+
...metroConfig.transformer,
|
|
65
|
+
tamagui: options
|
|
66
|
+
};
|
|
67
|
+
const zeroProjectRoot = metroConfig.projectRoot ?? process.cwd();
|
|
68
|
+
const zero = (0, import_zeroRuntime.createMetroZeroController)(options, zeroProjectRoot, zeroIslandBuild ?? null, zeroPublicDir);
|
|
69
|
+
if (zero?.isEnforcing) {
|
|
70
|
+
(0, import_zeroSerializer.applyMetroZeroRuntime)(metroConfig, zero);
|
|
71
|
+
}
|
|
72
|
+
if (!options.disable) {
|
|
73
|
+
const projectRoot = metroConfig.projectRoot ?? process.cwd();
|
|
74
|
+
const requireFromProject = (0, import_node_module.createRequire)((0, import_node_path.join)(projectRoot, "package.json"));
|
|
75
|
+
const configuredBabelTransformerPath = metroConfig.transformer.babelTransformerPath ?? "metro-babel-transformer";
|
|
76
|
+
const originalBabelTransformerPath = (0, import_node_path.isAbsolute)(configuredBabelTransformerPath) ? configuredBabelTransformerPath : requireFromProject.resolve(configuredBabelTransformerPath);
|
|
77
|
+
const cacheBaseRoot = compilerCacheRoot ?? (0, import_compilerCache.defaultMetroCompilerCacheRoot)(projectRoot);
|
|
78
|
+
const frontend = new import_frontend.MetroCompilerFrontend({
|
|
79
|
+
projectRoot,
|
|
80
|
+
resolver: metroConfig.resolver,
|
|
81
|
+
transformer: metroConfig.transformer,
|
|
82
|
+
tamaguiOptions: options,
|
|
83
|
+
originalBabelTransformerPath,
|
|
84
|
+
cacheRoot: cacheBaseRoot,
|
|
85
|
+
zero,
|
|
86
|
+
reportDiagnostic(diagnostic) {
|
|
87
|
+
console.warn((0, import_diagnostics.formatMetroCompilerDiagnostic)(diagnostic, projectRoot));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const transformerFactoryPath = requireFromPlugin.resolve("@tamagui/metro-plugin/transformer");
|
|
91
|
+
metroConfig.transformer.babelTransformerPath = (0, import_transformer.writeMetroCompilerTransformerBridge)(transformerFactoryPath, {
|
|
92
|
+
cacheBaseRoot,
|
|
93
|
+
originalBabelTransformerPath,
|
|
94
|
+
projectRoot,
|
|
95
|
+
runtimeLiteral: zero?.isEnforcing && !zero.islandBuild ? "zero" : "full"
|
|
96
|
+
});
|
|
97
|
+
const userGetTransformOptions = metroConfig.transformer.getTransformOptions;
|
|
98
|
+
metroConfig.transformer.getTransformOptions = (0, import_transformOptions.composeMetroGetTransformOptions)(frontend, userGetTransformOptions);
|
|
99
|
+
frontends.set(metroConfig, frontend);
|
|
100
|
+
}
|
|
101
|
+
return metroConfig;
|
|
102
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var lowering_exports = {};
|
|
23
|
+
__export(lowering_exports, { applyMetroCompilerPlan: () => applyMetroCompilerPlan });
|
|
24
|
+
module.exports = __toCommonJS(lowering_exports);
|
|
25
|
+
var import_compiler_core = require("@tamagui/compiler-core");
|
|
26
|
+
var import_trace_mapping = require("@jridgewell/trace-mapping");
|
|
27
|
+
var import_babel = require("./babel.cjs");
|
|
28
|
+
function lineStarts(source) {
|
|
29
|
+
const starts = [0];
|
|
30
|
+
for (let index = 0; index < source.length; index++) {
|
|
31
|
+
if (source.charCodeAt(index) === 10) starts.push(index + 1);
|
|
32
|
+
}
|
|
33
|
+
return starts;
|
|
34
|
+
}
|
|
35
|
+
function sourceIndex(starts, position) {
|
|
36
|
+
return (starts[position.line - 1] ?? starts.at(-1) ?? 0) + position.column;
|
|
37
|
+
}
|
|
38
|
+
function tracePosition(loweredMap, position) {
|
|
39
|
+
const original = (0, import_trace_mapping.originalPositionFor)(loweredMap, {
|
|
40
|
+
line: position.line,
|
|
41
|
+
column: position.column,
|
|
42
|
+
bias: import_trace_mapping.GREATEST_LOWER_BOUND
|
|
43
|
+
});
|
|
44
|
+
return original.line == null || original.column == null ? null : {
|
|
45
|
+
line: original.line,
|
|
46
|
+
column: original.column
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function remapAstLocations(ast, loweredMap, source, filename) {
|
|
50
|
+
const starts = lineStarts(source);
|
|
51
|
+
const seen = /* @__PURE__ */ new Set();
|
|
52
|
+
const visit = (value) => {
|
|
53
|
+
if (!value || typeof value !== "object" || seen.has(value)) return;
|
|
54
|
+
seen.add(value);
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
for (const child of value) visit(child);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const node = value;
|
|
60
|
+
const loc = node.loc;
|
|
61
|
+
if (loc?.start && loc?.end) {
|
|
62
|
+
const start = tracePosition(loweredMap, loc.start);
|
|
63
|
+
const end = tracePosition(loweredMap, loc.end);
|
|
64
|
+
if (start && end) {
|
|
65
|
+
node.start = sourceIndex(starts, start);
|
|
66
|
+
node.end = sourceIndex(starts, end);
|
|
67
|
+
node.loc = {
|
|
68
|
+
...loc,
|
|
69
|
+
start,
|
|
70
|
+
end,
|
|
71
|
+
filename
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const [key, child] of Object.entries(node)) {
|
|
76
|
+
if (key === "loc" || key === "tokens") continue;
|
|
77
|
+
visit(child);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
visit(ast);
|
|
81
|
+
}
|
|
82
|
+
async function applyMetroCompilerPlan(args, plan, transformerPath) {
|
|
83
|
+
const output = (0, import_compiler_core.applyLoweredModule)(args.src, (0, import_compiler_core.resolvedModuleId)(args.filename), plan);
|
|
84
|
+
if (!output.changed || !output.map) {
|
|
85
|
+
return {
|
|
86
|
+
compiled: await (0, import_babel.compileWithUserBabel)(transformerPath, args),
|
|
87
|
+
lowering: {
|
|
88
|
+
applied: false,
|
|
89
|
+
diagnostics: plan.diagnostics,
|
|
90
|
+
sourceMapComposed: false,
|
|
91
|
+
stats: plan.stats
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const compiled = await (0, import_babel.compileWithUserBabel)(transformerPath, {
|
|
96
|
+
...args,
|
|
97
|
+
src: output.code
|
|
98
|
+
});
|
|
99
|
+
remapAstLocations(compiled.result.ast, new import_trace_mapping.TraceMap(output.map), args.src, args.filename);
|
|
100
|
+
return {
|
|
101
|
+
compiled,
|
|
102
|
+
lowering: {
|
|
103
|
+
applied: true,
|
|
104
|
+
diagnostics: plan.diagnostics,
|
|
105
|
+
sourceMapComposed: true,
|
|
106
|
+
stats: plan.stats
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var metroResolver_exports = {};
|
|
23
|
+
__export(metroResolver_exports, {
|
|
24
|
+
createMetroCompilerResolver: () => createMetroCompilerResolver,
|
|
25
|
+
isCompilerSourceFile: () => isCompilerSourceFile,
|
|
26
|
+
moduleSpecifiersFromAst: () => moduleSpecifiersFromAst
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(metroResolver_exports);
|
|
29
|
+
var import_node_fs = require("node:fs");
|
|
30
|
+
var import_node_module = require("node:module");
|
|
31
|
+
var import_node_path = require("node:path");
|
|
32
|
+
function compareCodeUnits(left, right) {
|
|
33
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
34
|
+
}
|
|
35
|
+
function findClosestPackage(path) {
|
|
36
|
+
let directory = (0, import_node_fs.existsSync)(path) && (0, import_node_fs.statSync)(path).isDirectory() ? path : (0, import_node_path.dirname)(path);
|
|
37
|
+
const root = (0, import_node_path.parse)(directory).root;
|
|
38
|
+
while (true) {
|
|
39
|
+
const packagePath = (0, import_node_path.join)(directory, "package.json");
|
|
40
|
+
if ((0, import_node_fs.existsSync)(packagePath)) {
|
|
41
|
+
try {
|
|
42
|
+
return {
|
|
43
|
+
rootPath: directory,
|
|
44
|
+
packageJson: JSON.parse((0, import_node_fs.readFileSync)(packagePath, "utf8")),
|
|
45
|
+
packageRelativePath: (0, import_node_path.relative)(directory, path)
|
|
46
|
+
};
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (directory === root || directory.endsWith(`${(0, import_node_path.join)("node_modules")}`)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
directory = (0, import_node_path.dirname)(directory);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function lookup(projectRoot, path) {
|
|
58
|
+
const absolutePath = (0, import_node_path.isAbsolute)(path) ? path : (0, import_node_path.resolve)(projectRoot, path);
|
|
59
|
+
try {
|
|
60
|
+
const stat = (0, import_node_fs.lstatSync)(absolutePath);
|
|
61
|
+
const realPath = (0, import_node_fs.realpathSync)(absolutePath);
|
|
62
|
+
return {
|
|
63
|
+
exists: true,
|
|
64
|
+
type: stat.isDirectory() ? "d" : "f",
|
|
65
|
+
realPath
|
|
66
|
+
};
|
|
67
|
+
} catch {
|
|
68
|
+
return { exists: false };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function moduleSpecifiersFromAst(ast) {
|
|
72
|
+
const specifiers = /* @__PURE__ */ new Map();
|
|
73
|
+
const seen = /* @__PURE__ */ new Set();
|
|
74
|
+
function add(value, isESMImport) {
|
|
75
|
+
if (typeof value !== "string") return;
|
|
76
|
+
specifiers.set(value, (specifiers.get(value) ?? false) || isESMImport);
|
|
77
|
+
}
|
|
78
|
+
function visit(value) {
|
|
79
|
+
if (!value || typeof value !== "object") return;
|
|
80
|
+
if (seen.has(value)) return;
|
|
81
|
+
seen.add(value);
|
|
82
|
+
if (Array.isArray(value)) {
|
|
83
|
+
for (const child of value) visit(child);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const node = value;
|
|
87
|
+
if (node.type === "ImportDeclaration" || node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration") {
|
|
88
|
+
add(node.source?.value, true);
|
|
89
|
+
} else if (node.type === "CallExpression") {
|
|
90
|
+
const first = node.arguments?.[0];
|
|
91
|
+
if (node.callee?.type === "Import") {
|
|
92
|
+
add(first?.value, true);
|
|
93
|
+
} else if (node.callee?.type === "Identifier" && node.callee.name === "require") {
|
|
94
|
+
add(first?.value, false);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const [key, child] of Object.entries(node)) {
|
|
98
|
+
if (key === "loc" || key === "comments" || key === "tokens") continue;
|
|
99
|
+
visit(child);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
visit(ast);
|
|
103
|
+
return [...specifiers].sort(([left], [right]) => compareCodeUnits(left, right)).map(([specifier, isESMImport]) => ({
|
|
104
|
+
specifier,
|
|
105
|
+
isESMImport
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
function createMetroCompilerResolver(config) {
|
|
109
|
+
const requireFromProject = (0, import_node_module.createRequire)((0, import_node_path.join)(config.projectRoot, "package.json"));
|
|
110
|
+
const resolverPackage = requireFromProject("metro-resolver/package.json");
|
|
111
|
+
if (!resolverPackage.version.startsWith("0.84.")) {
|
|
112
|
+
throw new Error(`@tamagui/metro-plugin requires the Metro 0.84 resolver contract, found ${resolverPackage.version}`);
|
|
113
|
+
}
|
|
114
|
+
const resolverModule = requireFromProject("metro-resolver");
|
|
115
|
+
const metroResolve = resolverModule.resolve;
|
|
116
|
+
const createDefaultContextModule = requireFromProject("metro-resolver/private/createDefaultContext");
|
|
117
|
+
const createDefaultContext = createDefaultContextModule.default ?? createDefaultContextModule;
|
|
118
|
+
const resolver = config.resolver ?? {};
|
|
119
|
+
const fileSystemLookup = (path) => lookup(config.projectRoot, path);
|
|
120
|
+
const getPackage = (packagePath) => {
|
|
121
|
+
try {
|
|
122
|
+
return JSON.parse((0, import_node_fs.readFileSync)(packagePath, "utf8"));
|
|
123
|
+
} catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
version: resolverPackage.version,
|
|
129
|
+
resolve(importer, dependency, platform) {
|
|
130
|
+
const dependencyDescriptor = {
|
|
131
|
+
name: dependency.specifier,
|
|
132
|
+
data: {
|
|
133
|
+
asyncType: null,
|
|
134
|
+
isESMImport: dependency.isESMImport,
|
|
135
|
+
key: dependency.specifier,
|
|
136
|
+
locs: []
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const context = createDefaultContext({
|
|
140
|
+
allowHaste: false,
|
|
141
|
+
assetExts: new Set(resolver.assetExts ?? []),
|
|
142
|
+
customResolverOptions: {},
|
|
143
|
+
dev: true,
|
|
144
|
+
disableHierarchicalLookup: resolver.disableHierarchicalLookup ?? false,
|
|
145
|
+
doesFileExist: (path) => fileSystemLookup(path).type === "f",
|
|
146
|
+
extraNodeModules: resolver.extraNodeModules ?? null,
|
|
147
|
+
fileSystemLookup,
|
|
148
|
+
getPackage,
|
|
149
|
+
getPackageForModule: findClosestPackage,
|
|
150
|
+
isESMImport: dependency.isESMImport,
|
|
151
|
+
mainFields: resolver.resolverMainFields ?? [
|
|
152
|
+
"react-native",
|
|
153
|
+
"browser",
|
|
154
|
+
"main"
|
|
155
|
+
],
|
|
156
|
+
nodeModulesPaths: resolver.nodeModulesPaths ?? [],
|
|
157
|
+
originModulePath: importer,
|
|
158
|
+
preferNativePlatform: true,
|
|
159
|
+
projectRoot: config.projectRoot,
|
|
160
|
+
resolveAsset: () => null,
|
|
161
|
+
resolveHasteModule: () => null,
|
|
162
|
+
resolveHastePackage: () => null,
|
|
163
|
+
resolveRequest: resolver.resolveRequest ?? null,
|
|
164
|
+
sourceExts: resolver.sourceExts ?? [
|
|
165
|
+
"js",
|
|
166
|
+
"jsx",
|
|
167
|
+
"json",
|
|
168
|
+
"ts",
|
|
169
|
+
"tsx"
|
|
170
|
+
],
|
|
171
|
+
unstable_conditionNames: resolver.unstable_conditionNames ?? [],
|
|
172
|
+
unstable_conditionsByPlatform: resolver.unstable_conditionsByPlatform ?? {},
|
|
173
|
+
unstable_enablePackageExports: resolver.unstable_enablePackageExports ?? true,
|
|
174
|
+
unstable_logWarning: (message) => config.resolver?.unstable_logWarning?.(message)
|
|
175
|
+
}, dependencyDescriptor);
|
|
176
|
+
const result = metroResolve(context, dependency.specifier, platform);
|
|
177
|
+
if (result.type === "empty") return null;
|
|
178
|
+
if (result.type !== "sourceFile" || !result.filePath) return null;
|
|
179
|
+
const resolvedId = (0, import_node_fs.realpathSync)(result.filePath);
|
|
180
|
+
return {
|
|
181
|
+
specifier: dependency.specifier,
|
|
182
|
+
resolvedId,
|
|
183
|
+
external: resolvedId.includes(`${(0, import_node_path.join)("node_modules")}`)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function isCompilerSourceFile(path) {
|
|
189
|
+
return [
|
|
190
|
+
".js",
|
|
191
|
+
".jsx",
|
|
192
|
+
".mjs",
|
|
193
|
+
".cjs",
|
|
194
|
+
".ts",
|
|
195
|
+
".tsx"
|
|
196
|
+
].includes((0, import_node_path.extname)(path));
|
|
197
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var transformOptions_exports = {};
|
|
23
|
+
__export(transformOptions_exports, { composeMetroGetTransformOptions: () => composeMetroGetTransformOptions });
|
|
24
|
+
module.exports = __toCommonJS(transformOptions_exports);
|
|
25
|
+
function composeMetroGetTransformOptions(frontend, userGetTransformOptions) {
|
|
26
|
+
return async function(entryFiles, transformOptions, getDependencies) {
|
|
27
|
+
const userOptions = userGetTransformOptions ? await userGetTransformOptions.call(this, entryFiles, transformOptions, getDependencies) : { transform: {} };
|
|
28
|
+
await frontend.ensureValidCache({
|
|
29
|
+
...transformOptions,
|
|
30
|
+
entryFiles,
|
|
31
|
+
transform: userOptions.transform ?? {}
|
|
32
|
+
});
|
|
33
|
+
return userOptions;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var transformer_exports = {};
|
|
23
|
+
__export(transformer_exports, {
|
|
24
|
+
createMetroCompilerTransformer: () => createMetroCompilerTransformer,
|
|
25
|
+
writeMetroCompilerTransformerBridge: () => writeMetroCompilerTransformerBridge
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(transformer_exports);
|
|
28
|
+
var import_node_crypto = require("node:crypto");
|
|
29
|
+
var import_node_fs = require("node:fs");
|
|
30
|
+
var import_node_path = require("node:path");
|
|
31
|
+
var import_babel = require("./babel.cjs");
|
|
32
|
+
var import_compilerCache = require("./compilerCache.cjs");
|
|
33
|
+
var import_diagnostics = require("./diagnostics.cjs");
|
|
34
|
+
var import_metroResolver = require("./metroResolver.cjs");
|
|
35
|
+
var import_lowering = require("./lowering.cjs");
|
|
36
|
+
function createMetroCompilerTransformer(config) {
|
|
37
|
+
const moduleIdCache = /* @__PURE__ */ new Map();
|
|
38
|
+
const missWarned = /* @__PURE__ */ new Set();
|
|
39
|
+
function cacheModuleId(filename) {
|
|
40
|
+
let id = moduleIdCache.get(filename);
|
|
41
|
+
if (!id) {
|
|
42
|
+
const absolute = (0, import_node_path.isAbsolute)(filename) ? filename : (0, import_node_path.resolve)(config.projectRoot, filename);
|
|
43
|
+
try {
|
|
44
|
+
id = (0, import_node_fs.realpathSync)(absolute);
|
|
45
|
+
} catch {
|
|
46
|
+
id = absolute;
|
|
47
|
+
}
|
|
48
|
+
moduleIdCache.set(filename, id);
|
|
49
|
+
}
|
|
50
|
+
return id;
|
|
51
|
+
}
|
|
52
|
+
function planEligible(moduleId) {
|
|
53
|
+
return (0, import_metroResolver.isCompilerSourceFile)(moduleId) && !moduleId.includes(`${(0, import_node_path.join)("node_modules")}`) && (0, import_node_fs.existsSync)(moduleId);
|
|
54
|
+
}
|
|
55
|
+
const runtimeLiteral = config.runtimeLiteral ?? "full";
|
|
56
|
+
const inlineRuntimeLiteral = ({ types }) => ({ visitor: { MemberExpression(nodePath) {
|
|
57
|
+
const node = nodePath.node;
|
|
58
|
+
if (node.computed || !types.isIdentifier(node.property, { name: "TAMAGUI_RUNTIME" }) || !types.isMemberExpression(node.object) || node.object.computed || !types.isIdentifier(node.object.object, { name: "process" }) || !types.isIdentifier(node.object.property, { name: "env" })) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
nodePath.replaceWith(types.stringLiteral(runtimeLiteral));
|
|
62
|
+
} } });
|
|
63
|
+
return {
|
|
64
|
+
async transform(argsIn) {
|
|
65
|
+
const args = {
|
|
66
|
+
...argsIn,
|
|
67
|
+
plugins: [...argsIn.plugins ?? [], inlineRuntimeLiteral]
|
|
68
|
+
};
|
|
69
|
+
const platform = typeof args.options.platform === "string" ? args.options.platform : "default";
|
|
70
|
+
const cache = new import_compilerCache.MetroCompilerCache((0, import_node_path.join)(config.cacheBaseRoot, platform));
|
|
71
|
+
let tamagui = {
|
|
72
|
+
cacheHit: false,
|
|
73
|
+
diagnostics: []
|
|
74
|
+
};
|
|
75
|
+
const moduleId = cacheModuleId(args.filename);
|
|
76
|
+
try {
|
|
77
|
+
const entry = await cache.read(moduleId, args.src, (reason, detail) => {
|
|
78
|
+
if (missWarned.has(moduleId) || !planEligible(moduleId)) return;
|
|
79
|
+
missWarned.add(moduleId);
|
|
80
|
+
const diagnostic = (0, import_diagnostics.metroDiagnostic)("metro/plan-miss", `Lowering plan lookup missed for ${moduleId} (${reason}${detail ? `: ${detail}` : ""}); module ships unlowered`, { moduleId });
|
|
81
|
+
tamagui.diagnostics.push(diagnostic);
|
|
82
|
+
console.warn((0, import_diagnostics.formatMetroCompilerDiagnostic)(diagnostic, config.projectRoot));
|
|
83
|
+
});
|
|
84
|
+
if (entry) {
|
|
85
|
+
try {
|
|
86
|
+
const lowered = await (0, import_lowering.applyMetroCompilerPlan)({
|
|
87
|
+
...args,
|
|
88
|
+
filename: moduleId
|
|
89
|
+
}, entry.plan, config.originalBabelTransformerPath);
|
|
90
|
+
return {
|
|
91
|
+
...lowered.compiled.result,
|
|
92
|
+
metadata: {
|
|
93
|
+
...lowered.compiled.result.metadata,
|
|
94
|
+
tamagui: {
|
|
95
|
+
cacheHit: true,
|
|
96
|
+
diagnostics: entry.diagnostics,
|
|
97
|
+
lowering: lowered.lowering
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const diagnostic = (0, import_diagnostics.metroDiagnostic)("metro/cache-corrupt", `Cached lowering plan for ${args.filename} could not be applied: ${error instanceof Error ? error.message : String(error)}`, { moduleId });
|
|
103
|
+
tamagui = {
|
|
104
|
+
cacheHit: true,
|
|
105
|
+
diagnostics: [...entry.diagnostics, diagnostic]
|
|
106
|
+
};
|
|
107
|
+
console.warn((0, import_diagnostics.formatMetroCompilerDiagnostic)(diagnostic, config.projectRoot));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (!(error instanceof import_compilerCache.MetroCompilerCacheError)) throw error;
|
|
112
|
+
tamagui.diagnostics.push(error.diagnostic);
|
|
113
|
+
console.warn((0, import_diagnostics.formatMetroCompilerDiagnostic)(error.diagnostic, config.projectRoot));
|
|
114
|
+
}
|
|
115
|
+
const compiled = await (0, import_babel.compileWithUserBabel)(config.originalBabelTransformerPath, args);
|
|
116
|
+
return {
|
|
117
|
+
...compiled.result,
|
|
118
|
+
metadata: {
|
|
119
|
+
...compiled.result.metadata,
|
|
120
|
+
tamagui
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
getCacheKey() {
|
|
125
|
+
return (0, import_node_crypto.createHash)("sha256").update(`tamagui-metro-compiler-v${import_compilerCache.METRO_COMPILER_CACHE_VERSION}`).update("\0").update(runtimeLiteral).update("\0").update((0, import_babel.userBabelCacheKey)(config.originalBabelTransformerPath)).digest("hex");
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function writeMetroCompilerTransformerBridge(transformerFactoryPath, config) {
|
|
130
|
+
const serializedConfig = JSON.stringify(config);
|
|
131
|
+
const bridgeHash = (0, import_node_crypto.createHash)("sha256").update(transformerFactoryPath).update("\0").update(serializedConfig).digest("hex");
|
|
132
|
+
const directory = (0, import_node_path.join)(config.cacheBaseRoot, "bridge");
|
|
133
|
+
const bridgePath = (0, import_node_path.join)(directory, `${bridgeHash}.cjs`);
|
|
134
|
+
const temporaryPath = `${bridgePath}.${process.pid}.tmp`;
|
|
135
|
+
const source = `'use strict'
|
|
136
|
+
module.exports = require(${JSON.stringify(transformerFactoryPath)}).createMetroCompilerTransformer(${serializedConfig})
|
|
137
|
+
`;
|
|
138
|
+
(0, import_node_fs.mkdirSync)(directory, { recursive: true });
|
|
139
|
+
(0, import_node_fs.writeFileSync)(temporaryPath, source, "utf8");
|
|
140
|
+
(0, import_node_fs.renameSync)(temporaryPath, bridgePath);
|
|
141
|
+
return bridgePath;
|
|
142
|
+
}
|