@tamagui/static 3.0.0-beta.755.1 → 3.0.0-beta.804.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.
@@ -107,6 +107,9 @@ function cleanId(id) {
107
107
  function externalId(specifier) {
108
108
  return (0, import_compiler_core.resolvedModuleId)(`external://${encodeURIComponent(specifier)}`);
109
109
  }
110
+ function compilerContext(input) {
111
+ return `${input.root}\0${input.target}\0${input.environment ?? ""}\0${input.project.generation}`;
112
+ }
110
113
  function sourceCanBeLinked(root, id) {
111
114
  const clean = cleanId(id);
112
115
  const normalized = clean.replace(/\\/g, "/");
@@ -118,6 +121,8 @@ var CompilerFrontend = class {
118
121
  session = new import_compiler_core.CompilerSession();
119
122
  queue = Promise.resolve();
120
123
  planCaches = /* @__PURE__ */ new Map();
124
+ moduleRecords = /* @__PURE__ */ new Map();
125
+ moduleContext = null;
121
126
  /**
122
127
  * One cache per project root and platform. Absent when the project produced
123
128
  * no content stamp, in which case plans are never persisted rather than
@@ -152,7 +157,18 @@ var CompilerFrontend = class {
152
157
  return total;
153
158
  }
154
159
  compile(input) {
155
- const operation = this.queue.then(() => this.compileNow(input));
160
+ const operation = this.queue.then(async () => {
161
+ const previousTarget = process.env.TAMAGUI_TARGET;
162
+ const previousStatic = process.env.IS_STATIC;
163
+ try {
164
+ return await this.compileNow(input);
165
+ } finally {
166
+ if (previousTarget === void 0) delete process.env.TAMAGUI_TARGET;
167
+ else process.env.TAMAGUI_TARGET = previousTarget;
168
+ if (previousStatic === void 0) delete process.env.IS_STATIC;
169
+ else process.env.IS_STATIC = previousStatic;
170
+ }
171
+ });
156
172
  this.queue = operation.catch(() => void 0);
157
173
  return operation;
158
174
  }
@@ -162,6 +178,7 @@ var CompilerFrontend = class {
162
178
  const invalidated = /* @__PURE__ */ new Set();
163
179
  for (const module2 of modules.values()) {
164
180
  for (const id of await this.session.update(module2)) invalidated.add(id);
181
+ this.moduleRecords.set(module2.id, module2);
165
182
  }
166
183
  return [...invalidated].sort();
167
184
  });
@@ -175,7 +192,13 @@ var CompilerFrontend = class {
175
192
  return this.session.dependentsOf((0, import_compiler_core.resolvedModuleId)(cleanId(id)));
176
193
  }
177
194
  remove(id) {
178
- const operation = this.queue.then(() => this.session.remove((0, import_compiler_core.resolvedModuleId)(cleanId(id))));
195
+ const operation = this.queue.then(async () => {
196
+ const result = await this.session.remove((0, import_compiler_core.resolvedModuleId)(cleanId(id)));
197
+ for (const invalidatedId of result.invalidatedIds) {
198
+ this.moduleRecords.delete(invalidatedId);
199
+ }
200
+ return result;
201
+ });
179
202
  this.queue = operation.catch(() => void 0);
180
203
  return operation;
181
204
  }
@@ -187,6 +210,7 @@ var CompilerFrontend = class {
187
210
  const invalidated = /* @__PURE__ */ new Set();
188
211
  for (const module2 of modules.values()) {
189
212
  for (const id of await this.session.update(module2)) invalidated.add(id);
213
+ this.moduleRecords.set(module2.id, module2);
190
214
  }
191
215
  const projectInfo = input.project.projectInfo;
192
216
  if (!projectInfo.tamaguiConfig || !projectInfo.components) {
@@ -225,13 +249,36 @@ var CompilerFrontend = class {
225
249
  };
226
250
  }
227
251
  async buildTree(input) {
252
+ const moduleContext = compilerContext(input);
253
+ if (this.moduleContext !== moduleContext) {
254
+ this.moduleRecords.clear();
255
+ this.moduleContext = moduleContext;
256
+ }
228
257
  const componentBySpecifier = new Map(input.project.componentModules.map((component) => [component.moduleName, (0, import_compiler_core.resolvedModuleId)(cleanId(component.id))]));
229
258
  const modules = /* @__PURE__ */ new Map();
230
259
  const loading = /* @__PURE__ */ new Set();
260
+ const addInstalledClosure = (module2) => {
261
+ if (modules.has(module2.id) || loading.has(module2.id)) return;
262
+ loading.add(module2.id);
263
+ for (const dependency of module2.imports) {
264
+ if (dependency.external) continue;
265
+ const installedDependency = this.moduleRecords.get(dependency.resolvedId);
266
+ if (installedDependency && this.session.has(dependency.resolvedId)) {
267
+ addInstalledClosure(installedDependency);
268
+ }
269
+ }
270
+ modules.set(module2.id, module2);
271
+ loading.delete(module2.id);
272
+ };
231
273
  const loadModule = async (rawId, source) => {
232
274
  const id = (0, import_compiler_core.resolvedModuleId)(cleanId(rawId));
233
275
  const existing = modules.get(id);
234
276
  if (existing) return existing;
277
+ const installed = this.moduleRecords.get(id);
278
+ if (installed?.source === source && this.session.has(id)) {
279
+ addInstalledClosure(installed);
280
+ return installed;
281
+ }
235
282
  if (loading.has(id)) {
236
283
  return {
237
284
  id,
@@ -261,9 +308,14 @@ var CompilerFrontend = class {
261
308
  external: !canLink
262
309
  });
263
310
  if (canLink && !modules.has(resolvedId) && !loading.has(resolvedId)) {
264
- const dependencySource = await input.load(resolution.id);
265
- if (dependencySource !== null) {
266
- await loadModule(resolution.id, dependencySource);
311
+ const installedDependency = this.moduleRecords.get(resolvedId);
312
+ if (installedDependency && this.session.has(resolvedId)) {
313
+ addInstalledClosure(installedDependency);
314
+ } else {
315
+ const dependencySource = await input.load(resolution.id);
316
+ if (dependencySource !== null) {
317
+ await loadModule(resolution.id, dependencySource);
318
+ }
267
319
  }
268
320
  }
269
321
  }