tamagui-loader 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/dist/cjs/TamaguiPlugin.cjs +407 -186
- package/dist/cjs/css.cjs +29 -28
- package/dist/cjs/index.cjs +15 -18
- package/dist/cjs/loader.cjs +156 -91
- package/dist/cjs/polyfills.cjs +2 -1
- package/dist/cjs/requireResolve.cjs +15 -18
- package/dist/cjs/shouldExclude.cjs +23 -31
- package/dist/cjs/test.cjs +19 -22
- package/dist/cjs/zeroRuntime.cjs +207 -0
- package/dist/esm/TamaguiPlugin.mjs +393 -162
- package/dist/esm/TamaguiPlugin.mjs.map +1 -1
- package/dist/esm/css.mjs +15 -13
- package/dist/esm/css.mjs.map +1 -1
- package/dist/esm/index.js +6 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +6 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/loader.mjs +138 -65
- package/dist/esm/loader.mjs.map +1 -1
- package/dist/esm/polyfills.mjs +1 -0
- package/dist/esm/polyfills.mjs.map +1 -1
- package/dist/esm/requireResolve.mjs +8 -1
- package/dist/esm/requireResolve.mjs.map +1 -1
- package/dist/esm/shouldExclude.mjs +7 -5
- package/dist/esm/shouldExclude.mjs.map +1 -1
- package/dist/esm/test.mjs +5 -4
- package/dist/esm/test.mjs.map +1 -1
- package/dist/esm/zeroRuntime.mjs +170 -0
- package/dist/esm/zeroRuntime.mjs.map +1 -0
- package/package.json +12 -8
- package/src/TamaguiPlugin.ts +344 -62
- package/src/css.ts +5 -1
- package/src/loader.ts +143 -38
- package/src/zeroRuntime.ts +329 -0
- package/types/TamaguiPlugin.d.ts +15 -1
- package/types/TamaguiPlugin.d.ts.map +1 -1
- package/types/css.d.ts +1 -0
- package/types/css.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/loader.d.ts.map +1 -1
- package/types/shouldExclude.d.ts.map +1 -1
- package/types/zeroRuntime.d.ts +113 -0
- package/types/zeroRuntime.d.ts.map +1 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -5,199 +6,419 @@ 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 TamaguiPlugin_exports = {};
|
|
35
|
-
__export(TamaguiPlugin_exports, {
|
|
36
|
-
TamaguiPlugin: () => TamaguiPlugin
|
|
37
|
-
});
|
|
29
|
+
__export(TamaguiPlugin_exports, { TamaguiPlugin: () => TamaguiPlugin });
|
|
38
30
|
module.exports = __toCommonJS(TamaguiPlugin_exports);
|
|
39
|
-
var
|
|
31
|
+
var import_static = __toESM(require("@tamagui/static"), 1);
|
|
32
|
+
var import_node_crypto = require("node:crypto");
|
|
40
33
|
var import_node_fs = require("node:fs");
|
|
41
34
|
var import_node_path = require("node:path");
|
|
35
|
+
var import_node_zlib = require("node:zlib");
|
|
42
36
|
var import_webpack = __toESM(require("webpack"), 1);
|
|
43
37
|
var import_requireResolve = require("./requireResolve.cjs");
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
38
|
+
var import_zeroRuntime = require("./zeroRuntime.cjs");
|
|
39
|
+
const globalCSSGeneration = /* @__PURE__ */ new Map();
|
|
40
|
+
function generateGlobalCSSOnce(cssPath, generate) {
|
|
41
|
+
let pending = globalCSSGeneration.get(cssPath);
|
|
42
|
+
if (!pending) {
|
|
43
|
+
pending = generate();
|
|
44
|
+
globalCSSGeneration.set(cssPath, pending);
|
|
45
|
+
}
|
|
46
|
+
return pending;
|
|
47
|
+
}
|
|
48
|
+
var TamaguiPlugin = class {
|
|
49
|
+
constructor(options = {
|
|
50
|
+
platform: "web",
|
|
51
|
+
components: ["@tamagui/core"]
|
|
52
|
+
}) {
|
|
53
|
+
this.options = options;
|
|
54
|
+
}
|
|
55
|
+
options;
|
|
56
|
+
pluginName = "TamaguiPlugin";
|
|
57
|
+
/**
|
|
58
|
+
* The compiled-global-CSS tier: ordinary compiled Tamagui plus an owned
|
|
59
|
+
* `outputCSS` artifact. `withTamagui` already inlined
|
|
60
|
+
* `TAMAGUI_DID_OUTPUT_CSS='1'`, so this proves the artifact that replaces the
|
|
61
|
+
* stripped rules exists, matches this build's config, and is in the client
|
|
62
|
+
* graph. A build that cannot prove all three fails instead of shipping.
|
|
63
|
+
*/
|
|
64
|
+
applyGlobalCSS(compiler) {
|
|
65
|
+
const root = this.options.root || compiler.context || process.cwd();
|
|
66
|
+
if (compiler.options.mode === "development") return;
|
|
67
|
+
const globalCSS = import_static.default.resolveGlobalCSSOwnership({
|
|
68
|
+
platform: "web",
|
|
69
|
+
...this.options
|
|
70
|
+
}, root);
|
|
71
|
+
if (!globalCSS) return;
|
|
72
|
+
let expectedCSS = "";
|
|
73
|
+
compiler.hooks.beforeCompile.tapPromise(this.pluginName, async () => {
|
|
74
|
+
expectedCSS = await generateGlobalCSSOnce(globalCSS.cssPath, async () => {
|
|
75
|
+
const { projectInfo } = await import_static.default.loadCompilerProject({
|
|
76
|
+
root,
|
|
77
|
+
target: "web",
|
|
78
|
+
options: {
|
|
79
|
+
components: ["tamagui"],
|
|
80
|
+
...this.options
|
|
81
|
+
},
|
|
82
|
+
generation: "next-webpack:global-css",
|
|
83
|
+
missingProjectMessage: "[tamagui] outputCSS is set but the Tamagui config did not evaluate, so no CSS artifact can be generated"
|
|
84
|
+
});
|
|
85
|
+
return projectInfo.tamaguiConfig.getCSS();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
if (this.options.isServer) return;
|
|
89
|
+
compiler.hooks.afterEmit.tap(this.pluginName, (compilation) => {
|
|
90
|
+
const loadedModuleIds = [];
|
|
91
|
+
for (const module2 of (0, import_zeroRuntime.flattenModules)(compilation.modules)) {
|
|
92
|
+
const resource = module2?.resource;
|
|
93
|
+
if (resource) loadedModuleIds.push(resource);
|
|
94
|
+
}
|
|
95
|
+
const failure = import_static.default.checkGlobalCSSArtifact({
|
|
96
|
+
cssPath: globalCSS.cssPath,
|
|
97
|
+
expectedCSS,
|
|
98
|
+
loadedModuleIds,
|
|
99
|
+
importHint: `Import it once from your root layout or _app: import ${JSON.stringify(relativeImportSpecifier(root, globalCSS.cssPath))}`
|
|
100
|
+
});
|
|
101
|
+
if (failure) throw new Error(failure.message);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The zero-runtime half: the plugin owns the one generated CSS artifact, runs
|
|
106
|
+
* each declared island as a separate full-runtime compilation, and proves the
|
|
107
|
+
* emitted client graph carries no forbidden Tamagui module.
|
|
108
|
+
*/
|
|
109
|
+
applyZeroRuntime(compiler) {
|
|
110
|
+
const root = this.options.root || compiler.context || process.cwd();
|
|
111
|
+
const zero = (0, import_zeroRuntime.getWebpackZeroController)({
|
|
112
|
+
platform: "web",
|
|
113
|
+
...this.options
|
|
114
|
+
}, root);
|
|
115
|
+
if (!zero || zero.islandBuild) return;
|
|
116
|
+
compiler.hooks.beforeCompile.tapPromise(this.pluginName, async () => {
|
|
117
|
+
const { projectInfo } = await import_static.default.loadCompilerProject({
|
|
118
|
+
root,
|
|
119
|
+
target: "web",
|
|
120
|
+
options: {
|
|
121
|
+
components: ["tamagui"],
|
|
122
|
+
...this.options
|
|
123
|
+
},
|
|
124
|
+
generation: "next-webpack:zero-runtime",
|
|
125
|
+
missingProjectMessage: "[tamagui zero-runtime] the Tamagui config did not evaluate, so no CSS artifact can be generated"
|
|
126
|
+
});
|
|
127
|
+
if (zero.isEnforcing) import_static.default.assertZeroConfigDrivers(projectInfo.tamaguiConfig);
|
|
128
|
+
const configCSS = projectInfo.tamaguiConfig.getCSS();
|
|
129
|
+
zero.configHash = (0, import_node_crypto.createHash)("sha256").update(configCSS).digest("hex").slice(0, 16);
|
|
130
|
+
zero.artifact.setConfigCSS(configCSS);
|
|
131
|
+
});
|
|
132
|
+
if (this.options.isServer) return;
|
|
133
|
+
compiler.hooks.afterEmit.tapPromise(this.pluginName, async (compilation) => {
|
|
134
|
+
zero.artifact.clearGraphs();
|
|
135
|
+
zero.bridges.clear();
|
|
136
|
+
zero.violations.length = 0;
|
|
137
|
+
const collected = (0, import_zeroRuntime.collectZeroBuildInfo)(zero, compilation.modules);
|
|
138
|
+
import_static.default.writeZeroViolationReport(zero.resolved.outDir, "next-zero", {
|
|
139
|
+
integration: "next-webpack",
|
|
140
|
+
mode: zero.isEnforcing ? "enforce" : "report",
|
|
141
|
+
violations: zero.violations
|
|
142
|
+
});
|
|
143
|
+
if (!zero.isEnforcing) return;
|
|
144
|
+
if (zero.violations.length) {
|
|
145
|
+
throw new Error(import_static.default.formatZeroViolations(zero.violations));
|
|
146
|
+
}
|
|
147
|
+
const islandOutputHashes = {};
|
|
148
|
+
for (const island of zero.resolved.islands) {
|
|
149
|
+
const built = await (0, import_zeroRuntime.buildWebpackIsland)({
|
|
150
|
+
island,
|
|
151
|
+
controller: zero,
|
|
152
|
+
webpack: import_webpack.default,
|
|
153
|
+
mode: compiler.options.mode === "development" ? "development" : "production",
|
|
154
|
+
resolve: compiler.options.resolve,
|
|
155
|
+
defines: (0, import_zeroRuntime.collectDefinitions)(compiler),
|
|
156
|
+
moduleRules: [{
|
|
157
|
+
test: /\.tsx?$/,
|
|
158
|
+
exclude: /node_modules/,
|
|
159
|
+
use: [{
|
|
160
|
+
loader: (0, import_requireResolve.requireResolve)("esbuild-loader"),
|
|
161
|
+
options: {
|
|
162
|
+
target: "es2020",
|
|
163
|
+
jsx: "automatic",
|
|
164
|
+
loader: "tsx"
|
|
165
|
+
}
|
|
166
|
+
}, {
|
|
167
|
+
loader: (0, import_requireResolve.requireResolve)("tamagui-loader"),
|
|
168
|
+
options: {
|
|
169
|
+
...this.options,
|
|
170
|
+
isServer: false
|
|
171
|
+
}
|
|
172
|
+
}]
|
|
173
|
+
}]
|
|
174
|
+
});
|
|
175
|
+
islandOutputHashes[island.id] = built.hash;
|
|
176
|
+
}
|
|
177
|
+
const written = zero.artifact.write();
|
|
178
|
+
if (!written.complete) {
|
|
179
|
+
throw new Error(`[tamagui zero-runtime] cannot derive TAMAGUI_DID_OUTPUT_CSS: the generated CSS artifact is missing ${written.missing.join(", ")}`);
|
|
180
|
+
}
|
|
181
|
+
const css = zero.artifact.css();
|
|
182
|
+
(0, import_node_fs.mkdirSync)(zero.publicDir, { recursive: true });
|
|
183
|
+
const published = (0, import_node_path.join)(zero.publicDir, import_zeroRuntime.ZERO_CSS_FILENAME);
|
|
184
|
+
(0, import_node_fs.writeFileSync)(published, css);
|
|
185
|
+
const publishFailure = import_static.default.checkGlobalCSSArtifact({
|
|
186
|
+
cssPath: published,
|
|
187
|
+
expectedCSS: css,
|
|
188
|
+
loadedModuleIds: [published],
|
|
189
|
+
importHint: ""
|
|
190
|
+
});
|
|
191
|
+
if (publishFailure) throw new Error(publishFailure.message);
|
|
192
|
+
const moduleId = (module2) => module2?.resource ?? module2?.identifier?.();
|
|
193
|
+
const modules = [];
|
|
194
|
+
const importerEdges = /* @__PURE__ */ new Map();
|
|
195
|
+
for (const module2 of (0, import_zeroRuntime.flattenModules)(compilation.modules)) {
|
|
196
|
+
const id = moduleId(module2);
|
|
197
|
+
if (!id) continue;
|
|
198
|
+
const importers = [];
|
|
199
|
+
const issuer = moduleId(compilation.moduleGraph.getIssuer(module2));
|
|
200
|
+
if (issuer) importers.push(issuer);
|
|
201
|
+
for (const connection of compilation.moduleGraph.getIncomingConnections(module2)) {
|
|
202
|
+
const origin = moduleId(connection.originModule);
|
|
203
|
+
if (origin && !importers.includes(origin)) importers.push(origin);
|
|
204
|
+
}
|
|
205
|
+
importerEdges.set(id, importers);
|
|
206
|
+
modules.push({
|
|
207
|
+
id,
|
|
208
|
+
importers
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const entries = [];
|
|
212
|
+
for (const [, entry] of compilation.entries) {
|
|
213
|
+
for (const dependency of entry.dependencies) {
|
|
214
|
+
const id = moduleId(compilation.moduleGraph.getModule(dependency));
|
|
215
|
+
if (id) entries.push(id);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const escape = import_static.default.erasedExportEscape({
|
|
219
|
+
integration: "next-webpack",
|
|
220
|
+
transformed: collected.transformed,
|
|
221
|
+
erasedExports: collected.erasedExports,
|
|
222
|
+
importersOf: importerEdges
|
|
223
|
+
});
|
|
224
|
+
if (escape) throw new Error(escape);
|
|
225
|
+
const checked = import_static.default.checkZeroGraph({
|
|
226
|
+
entries,
|
|
227
|
+
modules,
|
|
228
|
+
importerEdges,
|
|
229
|
+
root: zero.resolved.root
|
|
230
|
+
});
|
|
231
|
+
const bridgeManifest = import_static.default.canonicalizeBridgeManifest(Object.fromEntries([...zero.bridges.entries()].sort(([left], [right]) => left < right ? -1 : 1)));
|
|
232
|
+
const identityInputs = {
|
|
233
|
+
runtimeLiteral: "zero",
|
|
234
|
+
target: "web",
|
|
235
|
+
configGeneration: zero.configHash,
|
|
236
|
+
cssHash: written.hash,
|
|
237
|
+
compilerVersion: import_static.default.ZERO_COMPILER_VERSION,
|
|
238
|
+
islandEntries: zero.resolved.islands.map((island) => island.module),
|
|
239
|
+
bridgeManifestHash: import_static.default.hashBridgeManifest(bridgeManifest),
|
|
240
|
+
islandOutputHashes
|
|
241
|
+
};
|
|
242
|
+
const receipt = {
|
|
243
|
+
integration: "next-webpack",
|
|
244
|
+
graph: "zero",
|
|
245
|
+
entries: entries.sort(),
|
|
246
|
+
moduleCount: modules.length,
|
|
247
|
+
tamaguiModules: checked.tamaguiModules,
|
|
248
|
+
forbidden: checked.forbidden,
|
|
249
|
+
cssArtifact: {
|
|
250
|
+
path: zero.cssHref,
|
|
251
|
+
hash: written.hash
|
|
252
|
+
},
|
|
253
|
+
identity: import_static.default.hashZeroIdentity(identityInputs),
|
|
254
|
+
gzip: { [import_zeroRuntime.ZERO_CSS_FILENAME]: (0, import_node_zlib.gzipSync)(Buffer.from(css), { level: 9 }).length },
|
|
255
|
+
plansRestoredFromCache: collected.restored > 0
|
|
256
|
+
};
|
|
257
|
+
import_static.default.writeZeroGraphReceipt(zero.resolved.outDir, "next-zero", receipt);
|
|
258
|
+
(0, import_node_fs.writeFileSync)((0, import_node_path.join)(zero.resolved.outDir, "next-zero.bridges.json"), `${JSON.stringify({
|
|
259
|
+
identity: receipt.identity,
|
|
260
|
+
identityInputs,
|
|
261
|
+
bridges: bridgeManifest
|
|
262
|
+
}, null, 2)}
|
|
263
|
+
`);
|
|
264
|
+
if (receipt.forbidden.length) {
|
|
265
|
+
throw new Error(import_static.default.formatZeroGraphFailure(receipt));
|
|
266
|
+
}
|
|
267
|
+
console.info(` \u27A1 [tamagui zero-runtime] ${modules.length} modules, 0 forbidden, css ${receipt.gzip[import_zeroRuntime.ZERO_CSS_FILENAME]} gzip, islands: ${zero.resolved.islands.map((island) => island.id).join(", ") || "none"}`);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
resolveModules = (resolves, purpose) => {
|
|
271
|
+
const res = [];
|
|
272
|
+
for (const [out, mod] of resolves) {
|
|
273
|
+
if (this.options.dangerouslyIgnoreStaticEvaluationModules?.includes(mod)) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (out.endsWith("$")) {
|
|
277
|
+
res.push([out, mod]);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
res.push([out, (0, import_requireResolve.requireResolve)(mod)]);
|
|
282
|
+
} catch (err) {
|
|
283
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
284
|
+
throw new Error(`[tamagui] Failed to resolve ${purpose} "${mod}" for "${out}".
|
|
285
|
+
Reason: ${reason}
|
|
286
|
+
Fix the module name or install it. If it is runtime-only and none of its exports create your Tamagui config or components, add "${mod}" to dangerouslyIgnoreStaticEvaluationModules in tamagui.build.ts.`, { cause: err });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return res;
|
|
290
|
+
};
|
|
291
|
+
get componentsFullPaths() {
|
|
292
|
+
return this.resolveModules(this.options.components?.map((moduleName) => [moduleName, moduleName]) || [], "configured component");
|
|
293
|
+
}
|
|
294
|
+
get componentsBaseDirs() {
|
|
295
|
+
return this.componentsFullPaths.map(([_, fullPath]) => {
|
|
296
|
+
let rootPath = (0, import_node_path.dirname)(fullPath);
|
|
297
|
+
while (rootPath.length > 1) {
|
|
298
|
+
const pkg = (0, import_node_path.join)(rootPath, "package.json");
|
|
299
|
+
const hasPkg = (0, import_node_fs.existsSync)(pkg);
|
|
300
|
+
if (hasPkg) {
|
|
301
|
+
return rootPath;
|
|
302
|
+
}
|
|
303
|
+
rootPath = (0, import_node_path.join)(rootPath, "..");
|
|
304
|
+
}
|
|
305
|
+
throw new Error(`Couldn't find package.json in any path above: ${fullPath}`);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
isInComponentModule = (fullPath) => {
|
|
309
|
+
return this.componentsBaseDirs.some((componentDir) => fullPath.startsWith(componentDir));
|
|
310
|
+
};
|
|
311
|
+
get defaultAliases() {
|
|
312
|
+
return Object.fromEntries(this.resolveModules([
|
|
313
|
+
["@tamagui/core/reset.css", "@tamagui/core/reset.css"],
|
|
314
|
+
["react/jsx-runtime.js", "react/jsx-runtime"],
|
|
315
|
+
["react/jsx-dev-runtime.js", "react/jsx-dev-runtime"],
|
|
316
|
+
...this.options.useTamaguiSVG ? [["react-native-svg", "@tamagui/react-native-svg"]] : [],
|
|
317
|
+
...this.options.useReactNativeWebLite ? [["react-native$", "@tamagui/react-native-web-lite"], ["react-native-web$", "@tamagui/react-native-web-lite"]] : [["react-native$", "react-native-web"], ["react-native-web$", "react-native-web"]]
|
|
318
|
+
], "webpack alias"));
|
|
319
|
+
}
|
|
320
|
+
apply(compiler) {
|
|
321
|
+
void import_static.default.loadCompilerProject({
|
|
322
|
+
root: this.options.root || compiler.context || process.cwd(),
|
|
323
|
+
target: "web",
|
|
324
|
+
options: {
|
|
325
|
+
components: ["tamagui"],
|
|
326
|
+
...this.options
|
|
327
|
+
},
|
|
328
|
+
generation: "next-webpack:warmup"
|
|
329
|
+
});
|
|
330
|
+
this.applyZeroRuntime(compiler);
|
|
331
|
+
this.applyGlobalCSS(compiler);
|
|
332
|
+
if (compiler.options.mode === "development" && !this.options.disableWatchConfig) {
|
|
333
|
+
void import_static.default.watchTamaguiConfig(this.options).then((watcher) => {
|
|
334
|
+
process.once("exit", () => {
|
|
335
|
+
watcher?.dispose();
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
compiler.hooks.normalModuleFactory.tap(this.pluginName, (nmf) => {
|
|
340
|
+
nmf.hooks.createModule.tap(this.pluginName, (createData) => {
|
|
341
|
+
if (createData.matchResource?.endsWith(".tamagui.css") && createData.settings) {
|
|
342
|
+
createData.settings.sideEffects = true;
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
if (!this.options.disableAliases) {
|
|
347
|
+
const existingAlias = compiler.options.resolve.alias;
|
|
348
|
+
if (Array.isArray(existingAlias)) {} else if (typeof existingAlias === "object") {
|
|
349
|
+
Object.assign(existingAlias, this.defaultAliases);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const excludeExports = this.options.excludeReactNativeWebExports;
|
|
353
|
+
if (excludeExports) {
|
|
354
|
+
if (Array.isArray(excludeExports)) {
|
|
355
|
+
try {
|
|
356
|
+
const regexStr = `react-native-web(-lite)?/.*(${excludeExports.join("|")}).*js`;
|
|
357
|
+
const regex = new RegExp(regexStr);
|
|
358
|
+
compiler.hooks.environment.tap("MyPlugin", () => {
|
|
359
|
+
const definePlugin = new import_webpack.default.NormalModuleReplacementPlugin(regex, (0, import_requireResolve.requireResolve)("@tamagui/proxy-worm"));
|
|
360
|
+
definePlugin.apply(compiler);
|
|
361
|
+
});
|
|
362
|
+
} catch (err) {
|
|
363
|
+
console.warn(`Invalid names provided to excludeReactNativeWebExports: ${excludeExports.join(", ")}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
compiler.options.resolve.extensions = [.../* @__PURE__ */ new Set([
|
|
368
|
+
".web.tsx",
|
|
369
|
+
".web.ts",
|
|
370
|
+
".web.js",
|
|
371
|
+
".ts",
|
|
372
|
+
".tsx",
|
|
373
|
+
".js",
|
|
374
|
+
...compiler.options.resolve.extensions || []
|
|
375
|
+
])];
|
|
376
|
+
compiler.options.resolve.fallback ||= {};
|
|
377
|
+
compiler.options.resolve.fallback["crypto"] ||= false;
|
|
378
|
+
const mainFields = compiler.options.resolve.mainFields;
|
|
379
|
+
if (mainFields) {
|
|
380
|
+
compiler.options.resolve.mainFields = Array.isArray(mainFields) ? mainFields : [mainFields];
|
|
381
|
+
if (!this.options.disableModuleJSXEntry) mainFields.unshift("module:jsx");
|
|
382
|
+
}
|
|
383
|
+
if (!compiler.options.module) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
const { jsLoader } = this.options;
|
|
387
|
+
const existing = compiler.options.module.rules;
|
|
388
|
+
const rules = existing.find((x) => typeof x === "object" && "oneOf" in x ? x : null)?.oneOf ?? existing;
|
|
389
|
+
const tamaguiLoader = {
|
|
390
|
+
loader: (0, import_requireResolve.requireResolve)("tamagui-loader"),
|
|
391
|
+
options: { ...this.options }
|
|
392
|
+
};
|
|
393
|
+
let didReplaceNextJS = false;
|
|
394
|
+
for (const [index, rule] of rules.entries()) {
|
|
395
|
+
const shouldReplaceNextJSRule = (rule?.use?.loader === "next-swc-loader" || Array.isArray(rule?.use) && rule?.use[0].loader === "next-swc-loader") && !rule.issuerLayer;
|
|
396
|
+
if (shouldReplaceNextJSRule) {
|
|
397
|
+
didReplaceNextJS = true;
|
|
398
|
+
rules[index] = {
|
|
399
|
+
...rule,
|
|
400
|
+
test: this.options.test ?? rule.test ?? /\.m?[jt]sx?$/,
|
|
401
|
+
exclude: this.options.exclude ?? rule.exclude,
|
|
402
|
+
use: [
|
|
403
|
+
...jsLoader ? [jsLoader] : [],
|
|
404
|
+
...rule.use ? [].concat(rule.use) : [],
|
|
405
|
+
tamaguiLoader
|
|
406
|
+
]
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (!didReplaceNextJS) {
|
|
411
|
+
if (compiler.options.mode === "development") {
|
|
412
|
+
existing.push({
|
|
413
|
+
test: this.options.test ?? /\.tsx$/,
|
|
414
|
+
exclude: this.options.exclude,
|
|
415
|
+
use: [tamaguiLoader]
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
function relativeImportSpecifier(from, to) {
|
|
422
|
+
const path = (0, import_node_path.relative)(from, to).replace(/\\/g, "/");
|
|
423
|
+
return path.startsWith(".") ? path : `./${path}`;
|
|
424
|
+
}
|