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