@tamagui/vite-plugin 2.7.7 → 3.0.0-0.canary.1791056644527
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/compilerStats.cjs +126 -0
- package/dist/cjs/extensions.cjs +25 -18
- package/dist/cjs/index.cjs +9 -11
- package/dist/cjs/internal.cjs +24 -0
- package/dist/cjs/loadTamagui.cjs +250 -85
- package/dist/cjs/plugin.cjs +1164 -439
- package/dist/cjs/zeroRuntime.cjs +152 -0
- package/dist/esm/compilerStats.mjs +98 -0
- package/dist/esm/compilerStats.mjs.map +1 -0
- package/dist/esm/extensions.mjs +13 -1
- package/dist/esm/extensions.mjs.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/internal.mjs +3 -0
- package/dist/esm/loadTamagui.mjs +234 -59
- package/dist/esm/loadTamagui.mjs.map +1 -1
- package/dist/esm/plugin.mjs +1147 -417
- package/dist/esm/plugin.mjs.map +1 -1
- package/dist/esm/zeroRuntime.mjs +119 -0
- package/dist/esm/zeroRuntime.mjs.map +1 -0
- package/package.json +27 -11
- package/src/compilerStats.ts +168 -0
- package/src/internal.ts +9 -0
- package/src/loadTamagui.ts +347 -77
- package/src/plugin.ts +1579 -254
- package/src/zeroRuntime.ts +205 -0
- package/types/compilerStats.d.ts +44 -0
- package/types/compilerStats.d.ts.map +1 -0
- package/types/internal.d.ts +10 -0
- package/types/internal.d.ts.map +1 -0
- package/types/loadTamagui.d.ts +53 -11
- package/types/loadTamagui.d.ts.map +1 -1
- package/types/plugin.d.ts +33 -5
- package/types/plugin.d.ts.map +1 -1
- package/types/zeroRuntime.d.ts +60 -0
- package/types/zeroRuntime.d.ts.map +1 -0
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var compilerStats_exports = {};
|
|
28
|
+
__export(compilerStats_exports, {
|
|
29
|
+
createCompilerStatsReport: () => createCompilerStatsReport,
|
|
30
|
+
formatCompilerStatsReport: () => formatCompilerStatsReport
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(compilerStats_exports);
|
|
33
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
34
|
+
const normalizePath = (value) => value.replace(/\\/g, "/");
|
|
35
|
+
function normalizeDiagnostic(diagnostic) {
|
|
36
|
+
const unsupportedComponentSuffix = diagnostic.component && `#${diagnostic.component} does not accept className`;
|
|
37
|
+
const message = unsupportedComponentSuffix && diagnostic.message.endsWith(unsupportedComponentSuffix) ? `${diagnostic.component} does not accept className` : diagnostic.message;
|
|
38
|
+
return {
|
|
39
|
+
code: diagnostic.code,
|
|
40
|
+
message,
|
|
41
|
+
...diagnostic.component && { component: diagnostic.component }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function createCompilerStatsReport(root, reports) {
|
|
45
|
+
const totals = {
|
|
46
|
+
modules: 0,
|
|
47
|
+
found: 0,
|
|
48
|
+
lowered: 0,
|
|
49
|
+
flattened: 0,
|
|
50
|
+
partial: 0,
|
|
51
|
+
styled: 0,
|
|
52
|
+
bailed: 0,
|
|
53
|
+
notFlattened: 0,
|
|
54
|
+
flattenRate: 0
|
|
55
|
+
};
|
|
56
|
+
const bailoutCodes = /* @__PURE__ */ new Map();
|
|
57
|
+
const bailoutReasons = /* @__PURE__ */ new Map();
|
|
58
|
+
const modules = [];
|
|
59
|
+
for (const [id, report] of [...reports].sort(([left], [right]) => left.localeCompare(right))) {
|
|
60
|
+
if (report.stats.found === 0) continue;
|
|
61
|
+
const partial = report.stats.lowered - report.stats.flattened;
|
|
62
|
+
const notFlattened = report.stats.found - report.stats.flattened;
|
|
63
|
+
totals.modules++;
|
|
64
|
+
totals.found += report.stats.found;
|
|
65
|
+
totals.lowered += report.stats.lowered;
|
|
66
|
+
totals.flattened += report.stats.flattened;
|
|
67
|
+
totals.partial += partial;
|
|
68
|
+
totals.styled += report.stats.styled;
|
|
69
|
+
totals.bailed += report.stats.bailed;
|
|
70
|
+
totals.notFlattened += notFlattened;
|
|
71
|
+
const diagnostics = report.diagnostics.map(normalizeDiagnostic);
|
|
72
|
+
for (const diagnostic of diagnostics) {
|
|
73
|
+
bailoutCodes.set(diagnostic.code, (bailoutCodes.get(diagnostic.code) ?? 0) + 1);
|
|
74
|
+
const key = JSON.stringify([
|
|
75
|
+
diagnostic.code,
|
|
76
|
+
diagnostic.message,
|
|
77
|
+
diagnostic.component
|
|
78
|
+
]);
|
|
79
|
+
const reason = bailoutReasons.get(key);
|
|
80
|
+
if (reason) {
|
|
81
|
+
reason.count++;
|
|
82
|
+
} else {
|
|
83
|
+
bailoutReasons.set(key, {
|
|
84
|
+
...diagnostic,
|
|
85
|
+
count: 1
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
modules.push({
|
|
90
|
+
id: normalizePath(import_node_path.default.relative(root, id)),
|
|
91
|
+
stats: {
|
|
92
|
+
...report.stats,
|
|
93
|
+
partial,
|
|
94
|
+
notFlattened
|
|
95
|
+
},
|
|
96
|
+
diagnostics
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
totals.flattenRate = totals.found ? totals.flattened / totals.found : 0;
|
|
100
|
+
return {
|
|
101
|
+
schemaVersion: 1,
|
|
102
|
+
selector: {
|
|
103
|
+
id: "all",
|
|
104
|
+
include: ["**"]
|
|
105
|
+
},
|
|
106
|
+
totals,
|
|
107
|
+
bailoutCodes: Object.fromEntries([...bailoutCodes].sort(([leftCode, leftCount], [rightCode, rightCount]) => rightCount - leftCount || leftCode.localeCompare(rightCode))),
|
|
108
|
+
bailoutReasons: [...bailoutReasons.values()].sort((left, right) => right.count - left.count || left.code.localeCompare(right.code) || left.message.localeCompare(right.message) || (left.component ?? "").localeCompare(right.component ?? "")),
|
|
109
|
+
modules
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function formatCompilerStatsReport(report, verbose) {
|
|
113
|
+
const moduleLines = report.modules.map(({ id, stats, diagnostics }) => {
|
|
114
|
+
const codes = [...new Set(diagnostics.map(({ code }) => code))];
|
|
115
|
+
return ` ${id}: found ${stats.found} lowered ${stats.lowered} flattened ${stats.flattened} bailed ${stats.bailed}` + (codes.length ? ` (${codes.join(", ")})` : "");
|
|
116
|
+
});
|
|
117
|
+
const summary = `
|
|
118
|
+
[tamagui] compiler stats: ${report.totals.modules} modules with candidates
|
|
119
|
+
found ${report.totals.found} \xB7 lowered ${report.totals.lowered} (flattened ${report.totals.flattened}, partial ${report.totals.partial}, styled ${report.totals.styled}) \xB7 bailed ${report.totals.bailed}`;
|
|
120
|
+
const bailouts = Object.entries(report.bailoutCodes).map(([code, count]) => ` bailout ${code}: ${count}`).join("\n");
|
|
121
|
+
return [
|
|
122
|
+
summary,
|
|
123
|
+
bailouts,
|
|
124
|
+
verbose ? moduleLines.join("\n") : ""
|
|
125
|
+
].filter(Boolean).join("\n");
|
|
126
|
+
}
|
package/dist/cjs/extensions.cjs
CHANGED
|
@@ -3,26 +3,33 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
10
|
};
|
|
11
11
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
21
|
var extensions_exports = {};
|
|
24
|
-
__export(extensions_exports, {
|
|
25
|
-
extensions: () => extensions
|
|
26
|
-
});
|
|
22
|
+
__export(extensions_exports, { extensions: () => extensions });
|
|
27
23
|
module.exports = __toCommonJS(extensions_exports);
|
|
28
|
-
const extensions = [
|
|
24
|
+
const extensions = [
|
|
25
|
+
".ios.js",
|
|
26
|
+
".native.js",
|
|
27
|
+
".native.ts",
|
|
28
|
+
".native.tsx",
|
|
29
|
+
".js",
|
|
30
|
+
".jsx",
|
|
31
|
+
".json",
|
|
32
|
+
".ts",
|
|
33
|
+
".tsx",
|
|
34
|
+
".mjs"
|
|
35
|
+
];
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,18 +3,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
8
|
+
get: () => from[key],
|
|
9
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
13
|
};
|
|
14
14
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
-
value: true
|
|
17
|
-
}), mod);
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
16
|
var index_exports = {};
|
|
19
17
|
module.exports = __toCommonJS(index_exports);
|
|
20
|
-
__reExport(index_exports, require("./plugin.cjs"), module.exports);
|
|
18
|
+
__reExport(index_exports, require("./plugin.cjs"), module.exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var internal_exports = {};
|
|
22
|
+
__export(internal_exports, { createTamaguiPlugins: () => import_plugin.createTamaguiPlugins });
|
|
23
|
+
module.exports = __toCommonJS(internal_exports);
|
|
24
|
+
var import_plugin = require("./plugin.cjs");
|
package/dist/cjs/loadTamagui.cjs
CHANGED
|
@@ -5,97 +5,262 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
12
|
};
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
21
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
30
25
|
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
27
|
var loadTamagui_exports = {};
|
|
35
28
|
__export(loadTamagui_exports, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
getTamaguiOptions: () => getTamaguiOptions,
|
|
40
|
-
loadTamaguiBuildConfig: () => loadTamaguiBuildConfig
|
|
29
|
+
TAMAGUI_EVALUATION_ENVIRONMENT: () => TAMAGUI_EVALUATION_ENVIRONMENT,
|
|
30
|
+
createViteTamaguiLoader: () => createViteTamaguiLoader,
|
|
31
|
+
viteBuildConfigLoader: () => viteBuildConfigLoader
|
|
41
32
|
});
|
|
42
33
|
module.exports = __toCommonJS(loadTamagui_exports);
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
34
|
+
var import_static = __toESM(require("@tamagui/static"), 1);
|
|
35
|
+
var import_node_module = require("node:module");
|
|
36
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
var import_vite = require("vite");
|
|
38
|
+
const import_meta = {};
|
|
39
|
+
const TAMAGUI_EVALUATION_ENVIRONMENT = "tamagui";
|
|
40
|
+
const viteBuildConfigLoader = async (absolutePath, root) => {
|
|
41
|
+
const { module: module2, dependencies } = await (0, import_vite.runnerImport)(absolutePath, { root });
|
|
42
|
+
return {
|
|
43
|
+
exports: module2,
|
|
44
|
+
dependencies: [absolutePath, ...dependencies]
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const requireFromLoader = (0, import_node_module.createRequire)(typeof __filename === "string" ? __filename : import_meta.url);
|
|
48
|
+
const vitePluginVersions = [`@tamagui/vite-plugin@${requireFromLoader("@tamagui/vite-plugin/package.json").version}`];
|
|
49
|
+
function createViteTamaguiLoader(optionsIn = {}) {
|
|
50
|
+
let environment = null;
|
|
51
|
+
let ownsEnvironment = false;
|
|
52
|
+
let loadPromise = null;
|
|
53
|
+
let loadedOptions = null;
|
|
54
|
+
let projectPromise = null;
|
|
55
|
+
let loadingProject = null;
|
|
56
|
+
const invalidatedFiles = /* @__PURE__ */ new Set();
|
|
57
|
+
const evaluationDependencies = /* @__PURE__ */ new Set();
|
|
58
|
+
const stampSources = /* @__PURE__ */ new Set();
|
|
59
|
+
let generation = 0;
|
|
60
|
+
const normalizeDependency = (id) => id.split("?")[0];
|
|
61
|
+
const captureEvaluationDependencies = (modules) => {
|
|
62
|
+
evaluationDependencies.clear();
|
|
63
|
+
stampSources.clear();
|
|
64
|
+
for (const { id } of modules) {
|
|
65
|
+
const dependency = normalizeDependency(id);
|
|
66
|
+
if (import_node_path.default.isAbsolute(dependency)) {
|
|
67
|
+
evaluationDependencies.add(dependency);
|
|
68
|
+
stampSources.add(dependency);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (environment) {
|
|
72
|
+
for (const module2 of environment.runner.evaluatedModules.urlToIdModuleMap.values()) {
|
|
73
|
+
const dependency = normalizeDependency(module2.file);
|
|
74
|
+
if (!import_node_path.default.isAbsolute(dependency)) continue;
|
|
75
|
+
stampSources.add(dependency);
|
|
76
|
+
if (!dependency.includes("/node_modules/")) {
|
|
77
|
+
evaluationDependencies.add(dependency);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const loadTamaguiBuildConfig = async () => {
|
|
83
|
+
if (loadedOptions) return loadedOptions;
|
|
84
|
+
if (loadPromise) return loadPromise;
|
|
85
|
+
const pending = import_static.default.loadTamaguiBuildConfigAsync({
|
|
86
|
+
...optionsIn,
|
|
87
|
+
platform: "web"
|
|
88
|
+
}, viteBuildConfigLoader).then((options) => {
|
|
89
|
+
loadedOptions = options;
|
|
90
|
+
return options;
|
|
91
|
+
}, (error) => {
|
|
92
|
+
if (loadPromise === pending) loadPromise = null;
|
|
93
|
+
throw error;
|
|
94
|
+
});
|
|
95
|
+
loadPromise = pending;
|
|
96
|
+
return pending;
|
|
97
|
+
};
|
|
98
|
+
const resolveAndImport = async (moduleName, root, kind) => {
|
|
99
|
+
if (!environment) {
|
|
100
|
+
throw new Error(`The Tamagui Vite evaluation environment is not ready. Config and component evaluation requires Vite's ModuleRunner.`);
|
|
101
|
+
}
|
|
102
|
+
const source = import_node_path.default.isAbsolute(moduleName) ? moduleName : kind === "config" || moduleName.startsWith(".") ? import_node_path.default.resolve(root, moduleName) : moduleName;
|
|
103
|
+
let environmentResolution = await environment.pluginContainer.resolveId(source);
|
|
104
|
+
if (!environmentResolution && kind === "config" && source !== moduleName) {
|
|
105
|
+
environmentResolution = await environment.pluginContainer.resolveId(moduleName);
|
|
106
|
+
}
|
|
107
|
+
const resolvedId = environmentResolution?.id;
|
|
108
|
+
if (!resolvedId) {
|
|
109
|
+
throw new Error(`Unable to resolve ${moduleName} in the Tamagui Vite environment (plugins: ${environment.plugins.map((plugin) => plugin.name).join(", ")})`);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
moduleName,
|
|
113
|
+
id: resolvedId,
|
|
114
|
+
module: await environment.runner.import(resolvedId)
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
const evaluateProjectModules = async (options) => {
|
|
118
|
+
if (!environment) {
|
|
119
|
+
throw new Error(`Cannot evaluate Tamagui without the ${TAMAGUI_EVALUATION_ENVIRONMENT} Vite environment`);
|
|
120
|
+
}
|
|
121
|
+
const root = environment.config.root;
|
|
122
|
+
const config = await resolveAndImport(options.config || "tamagui.config.ts", root, "config");
|
|
123
|
+
const components = await Promise.all((options.components || []).map((name) => resolveAndImport(name, root, "component")));
|
|
124
|
+
captureEvaluationDependencies([config, ...components]);
|
|
125
|
+
return {
|
|
126
|
+
config,
|
|
127
|
+
components
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const loadProject = async (options) => {
|
|
131
|
+
if (projectPromise) return projectPromise;
|
|
132
|
+
const previous = loadingProject;
|
|
133
|
+
const projectGeneration = generation;
|
|
134
|
+
const changedFiles = [...invalidatedFiles];
|
|
135
|
+
invalidatedFiles.clear();
|
|
136
|
+
projectPromise = (async () => {
|
|
137
|
+
try {
|
|
138
|
+
await previous;
|
|
139
|
+
} catch {}
|
|
140
|
+
if (!environment) {
|
|
141
|
+
throw new Error(`Cannot load Tamagui without the ${TAMAGUI_EVALUATION_ENVIRONMENT} Vite environment`);
|
|
142
|
+
}
|
|
143
|
+
for (const file of changedFiles) {
|
|
144
|
+
const evaluated2 = environment.runner.evaluatedModules;
|
|
145
|
+
const affected = new Set(evaluated2.getModulesByFile(file));
|
|
146
|
+
for (const module2 of affected) {
|
|
147
|
+
for (const importer of module2.importers) {
|
|
148
|
+
const parent = evaluated2.getModuleById(importer);
|
|
149
|
+
if (parent) affected.add(parent);
|
|
150
|
+
}
|
|
151
|
+
evaluated2.invalidateModule(module2);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
let evaluated = null;
|
|
155
|
+
return import_static.default.loadCompilerProject({
|
|
156
|
+
root: environment.config.root,
|
|
157
|
+
target: "web",
|
|
158
|
+
options,
|
|
159
|
+
generation: `vite:${projectGeneration}`,
|
|
160
|
+
hostVersions: vitePluginVersions,
|
|
161
|
+
async load(normalizedOptions) {
|
|
162
|
+
evaluated = await evaluateProjectModules(normalizedOptions);
|
|
163
|
+
return import_static.default.loadTamaguiFromModules(normalizedOptions, {
|
|
164
|
+
config: evaluated.config.module,
|
|
165
|
+
components: evaluated.components.map(({ moduleName, module: module2 }) => ({
|
|
166
|
+
moduleName,
|
|
167
|
+
module: module2
|
|
168
|
+
})),
|
|
169
|
+
stampSources: [...stampSources]
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
async resolveComponents(moduleNames) {
|
|
173
|
+
if (!evaluated) {
|
|
174
|
+
throw new Error("The Tamagui compiler project modules were not evaluated");
|
|
175
|
+
}
|
|
176
|
+
const byName = new Map(evaluated.components.map(({ moduleName, id }) => [moduleName, id]));
|
|
177
|
+
return moduleNames.map((moduleName) => {
|
|
178
|
+
const id = byName.get(moduleName);
|
|
179
|
+
if (!id) throw new Error(`Unable to resolve compiler component ${moduleName}`);
|
|
180
|
+
return {
|
|
181
|
+
moduleName,
|
|
182
|
+
id
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
})();
|
|
188
|
+
loadingProject = projectPromise;
|
|
189
|
+
const pending = projectPromise;
|
|
190
|
+
try {
|
|
191
|
+
return await pending;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
if (projectPromise === pending) projectPromise = null;
|
|
194
|
+
throw error;
|
|
195
|
+
} finally {
|
|
196
|
+
if (loadingProject === pending) loadingProject = null;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
getEnvironment: () => environment,
|
|
201
|
+
getGeneration: () => generation,
|
|
202
|
+
getLoadPromise: () => loadPromise,
|
|
203
|
+
getTamaguiOptions: () => loadedOptions,
|
|
204
|
+
async getTamaguiConfig() {
|
|
205
|
+
const options = await loadTamaguiBuildConfig();
|
|
206
|
+
if (options.disable) return null;
|
|
207
|
+
return (await loadProject(options)).projectInfo.tamaguiConfig;
|
|
208
|
+
},
|
|
209
|
+
async getCompilerProject() {
|
|
210
|
+
const options = await loadTamaguiBuildConfig();
|
|
211
|
+
return loadProject(options);
|
|
212
|
+
},
|
|
213
|
+
getEvaluationDependencies: () => [...evaluationDependencies],
|
|
214
|
+
isEvaluationDependency: (id) => evaluationDependencies.has(normalizeDependency(id)),
|
|
215
|
+
evaluateProjectModules,
|
|
216
|
+
async evaluateModule(id) {
|
|
217
|
+
if (!environment) return null;
|
|
218
|
+
try {
|
|
219
|
+
return await environment.runner.import(id);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (process.env.DEBUG === "tamagui") {
|
|
222
|
+
console.info(`[tamagui] component discovery skipped ${id}:`, error);
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
loadTamaguiBuildConfig,
|
|
228
|
+
setEnvironment(next, options) {
|
|
229
|
+
if (environment === next) return;
|
|
230
|
+
environment = next;
|
|
231
|
+
ownsEnvironment = options?.owned === true;
|
|
232
|
+
generation++;
|
|
233
|
+
projectPromise = null;
|
|
234
|
+
},
|
|
235
|
+
invalidate(file) {
|
|
236
|
+
if (file) invalidatedFiles.add(normalizeDependency(file));
|
|
237
|
+
generation++;
|
|
238
|
+
projectPromise = null;
|
|
239
|
+
},
|
|
240
|
+
async ensureFullConfigLoaded() {
|
|
241
|
+
const options = await loadTamaguiBuildConfig();
|
|
242
|
+
if (!options.disable) {
|
|
243
|
+
await loadProject(options);
|
|
244
|
+
}
|
|
245
|
+
return [...evaluationDependencies];
|
|
246
|
+
},
|
|
247
|
+
async cleanup() {
|
|
248
|
+
try {
|
|
249
|
+
await loadingProject?.catch(() => {});
|
|
250
|
+
if (ownsEnvironment && environment) {
|
|
251
|
+
await environment.close();
|
|
252
|
+
}
|
|
253
|
+
} finally {
|
|
254
|
+
environment = null;
|
|
255
|
+
ownsEnvironment = false;
|
|
256
|
+
loadPromise = null;
|
|
257
|
+
loadedOptions = null;
|
|
258
|
+
projectPromise = null;
|
|
259
|
+
loadingProject = null;
|
|
260
|
+
invalidatedFiles.clear();
|
|
261
|
+
evaluationDependencies.clear();
|
|
262
|
+
stampSources.clear();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
93
266
|
}
|
|
94
|
-
async function cleanup() {
|
|
95
|
-
await StaticWorker.destroyPool();
|
|
96
|
-
const state = getLoadState();
|
|
97
|
-
state.loadPromise = null;
|
|
98
|
-
state.loadedOptions = null;
|
|
99
|
-
state.fullConfigLoaded = false;
|
|
100
|
-
state.fullConfigLoadPromise = null;
|
|
101
|
-
}
|