@tamagui/vite-plugin 2.0.0-rc.4 → 2.0.0-rc.40

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.
Files changed (45) hide show
  1. package/dist/cjs/extensions.cjs +12 -10
  2. package/dist/cjs/index.cjs +7 -5
  3. package/dist/cjs/loadTamagui.cjs +58 -39
  4. package/dist/cjs/plugin.cjs +252 -130
  5. package/dist/esm/index.js +1 -1
  6. package/dist/esm/index.js.map +1 -6
  7. package/dist/esm/loadTamagui.mjs +34 -17
  8. package/dist/esm/loadTamagui.mjs.map +1 -1
  9. package/dist/esm/plugin.mjs +221 -101
  10. package/dist/esm/plugin.mjs.map +1 -1
  11. package/package.json +12 -11
  12. package/src/plugin.ts +18 -15
  13. package/types/plugin.d.ts +2 -2
  14. package/types/plugin.d.ts.map +1 -1
  15. package/dist/cjs/cache.cjs +0 -70
  16. package/dist/cjs/cache.js +0 -63
  17. package/dist/cjs/cache.js.map +0 -6
  18. package/dist/cjs/extensions.js +0 -32
  19. package/dist/cjs/extensions.js.map +0 -6
  20. package/dist/cjs/extract.cjs +0 -159
  21. package/dist/cjs/extract.js +0 -148
  22. package/dist/cjs/extract.js.map +0 -6
  23. package/dist/cjs/index.js +0 -15
  24. package/dist/cjs/index.js.map +0 -6
  25. package/dist/cjs/loadTamagui.js +0 -75
  26. package/dist/cjs/loadTamagui.js.map +0 -6
  27. package/dist/cjs/plugin.js +0 -307
  28. package/dist/cjs/plugin.js.map +0 -6
  29. package/dist/esm/cache.js +0 -47
  30. package/dist/esm/cache.js.map +0 -6
  31. package/dist/esm/cache.mjs +0 -40
  32. package/dist/esm/cache.mjs.map +0 -1
  33. package/dist/esm/extensions.js +0 -16
  34. package/dist/esm/extensions.js.map +0 -6
  35. package/dist/esm/extract.js +0 -129
  36. package/dist/esm/extract.js.map +0 -6
  37. package/dist/esm/extract.mjs +0 -125
  38. package/dist/esm/extract.mjs.map +0 -1
  39. package/dist/esm/loadTamagui.js +0 -51
  40. package/dist/esm/loadTamagui.js.map +0 -6
  41. package/dist/esm/plugin.js +0 -294
  42. package/dist/esm/plugin.js.map +0 -6
  43. package/types/cache.d.ts +0 -50
  44. package/types/cache.d.ts.map +0 -1
  45. package/types/extract.d.ts.map +0 -1
@@ -2,74 +2,90 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
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
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
32
34
  var plugin_exports = {};
33
35
  __export(plugin_exports, {
34
36
  tamaguiAliases: () => tamaguiAliases,
35
37
  tamaguiPlugin: () => tamaguiPlugin
36
38
  });
37
39
  module.exports = __toCommonJS(plugin_exports);
38
- var Static = __toESM(require("@tamagui/static-worker"), 1),
39
- import_static_worker = require("@tamagui/static-worker"),
40
- import_node_crypto = require("node:crypto"),
41
- import_node_path = __toESM(require("node:path"), 1),
42
- import_node_url = require("node:url"),
43
- import_vite = require("vite"),
44
- import_loadTamagui = require("./loadTamagui.cjs");
45
- const import_meta = {},
46
- resolve = name => (0, import_node_url.fileURLToPath)(import_meta.resolve(name)),
47
- CACHE_KEY = "__tamagui_vite_cache__",
48
- CACHE_SIZE_KEY = "__tamagui_vite_cache_size__",
49
- PENDING_KEY = "__tamagui_vite_pending__";
40
+ var Static = __toESM(require("@tamagui/static-worker"), 1);
41
+ var import_static_worker = require("@tamagui/static-worker");
42
+ var import_node_crypto = require("node:crypto");
43
+ var import_node_path = __toESM(require("node:path"), 1);
44
+ var import_node_url = require("node:url");
45
+ var import_vite = require("vite");
46
+ var import_loadTamagui = require("./loadTamagui.cjs");
47
+ const import_meta = {};
48
+ const resolve = name => (0, import_node_url.fileURLToPath)(import_meta.resolve(name));
49
+ const CACHE_KEY = "__tamagui_vite_cache__";
50
+ const CACHE_SIZE_KEY = "__tamagui_vite_cache_size__";
51
+ const PENDING_KEY = "__tamagui_vite_pending__";
50
52
  function getSharedCache() {
51
- return globalThis[CACHE_KEY] || (globalThis[CACHE_KEY] = {}), globalThis[CACHE_KEY];
53
+ if (!globalThis[CACHE_KEY]) {
54
+ ;
55
+ globalThis[CACHE_KEY] = {};
56
+ }
57
+ return globalThis[CACHE_KEY];
52
58
  }
53
59
  function getSharedCacheSize() {
54
60
  return globalThis[CACHE_SIZE_KEY] || 0;
55
61
  }
56
62
  function setSharedCacheSize(size) {
63
+ ;
57
64
  globalThis[CACHE_SIZE_KEY] = size;
58
65
  }
59
66
  function clearSharedCache() {
60
- globalThis[CACHE_KEY] = {}, globalThis[CACHE_SIZE_KEY] = 0;
67
+ ;
68
+ globalThis[CACHE_KEY] = {};
69
+ globalThis[CACHE_SIZE_KEY] = 0;
61
70
  }
62
71
  function getPendingExtractions() {
63
- return globalThis[PENDING_KEY] || (globalThis[PENDING_KEY] = /* @__PURE__ */new Map()), globalThis[PENDING_KEY];
72
+ if (!globalThis[PENDING_KEY]) {
73
+ ;
74
+ globalThis[PENDING_KEY] = /* @__PURE__ */new Map();
75
+ }
76
+ return globalThis[PENDING_KEY];
64
77
  }
65
78
  function tamaguiAliases(options = {}) {
66
79
  const aliases = [];
67
- if (options.svg && aliases.push({
68
- find: "react-native-svg",
69
- replacement: resolve("@tamagui/react-native-svg")
70
- }), options.rnwLite) {
71
- const rnwl = resolve(options.rnwLite === "without-animated" ? "@tamagui/react-native-web-lite/without-animated" : "@tamagui/react-native-web-lite"),
72
- rnwlBase = import_node_path.default.dirname(resolve("@tamagui/react-native-web-lite/package.json"));
80
+ if (options.svg) {
81
+ aliases.push({
82
+ find: "react-native-svg",
83
+ replacement: resolve("@tamagui/react-native-svg")
84
+ });
85
+ }
86
+ if (options.rnwLite) {
87
+ const rnwl = resolve(options.rnwLite === "without-animated" ? "@tamagui/react-native-web-lite/without-animated" : "@tamagui/react-native-web-lite");
88
+ const rnwlBase = import_node_path.default.dirname(resolve("@tamagui/react-native-web-lite/package.json"));
73
89
  aliases.push({
74
90
  // map deep RNW paths like dist/exports/StyleSheet/preprocess to rnw-lite's flat structure
75
91
  // extracts the final path segment (e.g. "preprocess" or "createReactDOMStyle")
@@ -95,23 +111,32 @@ function tamaguiPlugin({
95
111
  disableResolveConfig,
96
112
  ...tamaguiOptionsIn
97
113
  } = {}) {
98
- let shouldExtract = !tamaguiOptionsIn.disableExtraction,
99
- watcher;
100
- const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv,
101
- extensions = [".web.mjs", ".web.js", ".web.jsx", ".web.ts", ".web.tsx", ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
114
+ let shouldExtract = !tamaguiOptionsIn.disableExtraction;
115
+ let watcher;
116
+ const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv;
117
+ const extensions = [`.web.mjs`, `.web.js`, `.web.jsx`, `.web.ts`, `.web.tsx`, ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
102
118
  (0, import_loadTamagui.loadTamaguiBuildConfig)(tamaguiOptionsIn);
103
119
  const ensureLoaded = async () => {
104
- const promise = (0, import_loadTamagui.getLoadPromise)();
105
- promise && (await promise);
106
- const options = (0, import_loadTamagui.getTamaguiOptions)();
107
- return options && (shouldExtract = !options.disableExtraction), options;
108
- },
109
- getHash = input => (0, import_node_crypto.createHash)("sha1").update(input).digest("base64"),
110
- memoryCache = getSharedCache(),
111
- cssMap = /* @__PURE__ */new Map();
112
- let config, server;
113
- const virtualExt = ".tamagui.css",
114
- getAbsoluteVirtualFileId = filePath => filePath.startsWith(config.root) ? filePath : (0, import_vite.normalizePath)(import_node_path.default.join(config.root, filePath));
120
+ const promise = (0, import_loadTamagui.getLoadPromise)();
121
+ if (promise) await promise;
122
+ const options = (0, import_loadTamagui.getTamaguiOptions)();
123
+ if (options) {
124
+ shouldExtract = !options.disableExtraction;
125
+ }
126
+ return options;
127
+ };
128
+ const getHash = input => (0, import_node_crypto.createHash)("sha1").update(input).digest("base64");
129
+ const memoryCache = getSharedCache();
130
+ const cssMap = /* @__PURE__ */new Map();
131
+ let config;
132
+ let server;
133
+ const virtualExt = `.tamagui.css`;
134
+ const getAbsoluteVirtualFileId = filePath => {
135
+ if (filePath.startsWith(config.root)) {
136
+ return filePath;
137
+ }
138
+ return (0, import_vite.normalizePath)(import_node_path.default.join(config.root, filePath));
139
+ };
115
140
  function isNotClient(environment) {
116
141
  return environment?.name && environment.name !== "client";
117
142
  }
@@ -121,12 +146,17 @@ function tamaguiPlugin({
121
146
  function invalidateModule(absoluteId) {
122
147
  if (!server) return;
123
148
  const {
124
- moduleGraph
125
- } = server,
126
- modules = moduleGraph.getModulesByFile(absoluteId);
127
- if (modules) for (const module2 of modules) moduleGraph.invalidateModule(module2), module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
149
+ moduleGraph
150
+ } = server;
151
+ const modules = moduleGraph.getModulesByFile(absoluteId);
152
+ if (modules) {
153
+ for (const module2 of modules) {
154
+ moduleGraph.invalidateModule(module2);
155
+ module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
156
+ }
157
+ }
128
158
  }
129
- return [{
159
+ const basePlugin = {
130
160
  name: "tamagui",
131
161
  enforce: "pre",
132
162
  configureServer(_server) {
@@ -137,27 +167,26 @@ function tamaguiPlugin({
137
167
  res?.dispose();
138
168
  });
139
169
  },
140
- async transform(code, id) {
141
- if (id.includes("expo-linear-gradient")) return (0, import_vite.transformWithEsbuild)(code, id, {
142
- loader: "jsx",
143
- jsx: "automatic"
144
- });
145
- },
146
170
  async config(_, env) {
147
171
  const options = await ensureLoaded();
148
- if (!options) throw new Error("No tamagui options loaded");
149
- return options.disableWatchTamaguiConfig || (watcher = Static.watchTamaguiConfig({
150
- components: ["tamagui"],
151
- config: "./src/tamagui.config.ts",
152
- ...options
153
- }).catch(err => {
154
- console.error(` [Tamagui] Error watching config: ${err}`);
155
- })), {
172
+ if (!options) {
173
+ throw new Error(`No tamagui options loaded`);
174
+ }
175
+ if (!options.disableWatchTamaguiConfig) {
176
+ watcher = Static.watchTamaguiConfig({
177
+ components: ["tamagui"],
178
+ config: "./src/tamagui.config.ts",
179
+ ...options
180
+ }).catch(err => {
181
+ console.error(` [Tamagui] Error watching config: ${err}`);
182
+ });
183
+ }
184
+ return {
156
185
  envPrefix: ["TAMAGUI_"],
157
186
  environments: {
158
187
  client: {
159
188
  define: {
160
- "process.env.TAMAGUI_IS_CLIENT": JSON.stringify(!0),
189
+ "process.env.TAMAGUI_IS_CLIENT": JSON.stringify(true),
161
190
  "process.env.TAMAGUI_ENVIRONMENT": '"client"'
162
191
  }
163
192
  }
@@ -165,14 +194,14 @@ function tamaguiPlugin({
165
194
  define: {
166
195
  // reanimated support
167
196
  _frameTimestamp: void 0,
168
- _WORKLET: !1,
197
+ _WORKLET: false,
169
198
  __DEV__: `${env.mode === "development"}`,
170
199
  "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
171
200
  "process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
172
201
  "process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
173
- "process.env.IS_STATIC": JSON.stringify(!1),
202
+ "process.env.IS_STATIC": JSON.stringify(false),
174
203
  ...(env.mode === "production" && {
175
- "process.env.TAMAGUI_OPTIMIZE_THEMES": JSON.stringify(!0)
204
+ "process.env.TAMAGUI_OPTIMIZE_THEMES": JSON.stringify(true)
176
205
  })
177
206
  },
178
207
  resolve: disableResolveConfig || enableNativeEnv ? {} : {
@@ -190,37 +219,73 @@ function tamaguiPlugin({
190
219
  }
191
220
  };
192
221
  }
193
- }, {
222
+ };
223
+ const rnwLitePlugin = {
194
224
  name: "tamagui-rnw-lite",
195
225
  config() {
196
- if (enableNativeEnv) return {};
226
+ if (enableNativeEnv) {
227
+ return {};
228
+ }
197
229
  const options = (0, import_loadTamagui.getTamaguiOptions)();
198
- return options?.useReactNativeWebLite ? {
230
+ if (!options?.useReactNativeWebLite) {
231
+ return {};
232
+ }
233
+ return {
199
234
  resolve: {
200
235
  alias: tamaguiAliases({
201
236
  rnwLite: options.useReactNativeWebLite
202
237
  })
238
+ },
239
+ optimizeDeps: {
240
+ // upstream react-native-web must not be pre-bundled when aliased to lite
241
+ exclude: ["react-native-web"]
203
242
  }
204
- } : {};
243
+ };
205
244
  }
206
- }, {
245
+ };
246
+ const extractPlugin = {
207
247
  name: "tamagui-extract",
208
248
  enforce: "pre",
209
249
  async config(userConf) {
210
- await ensureLoaded(), shouldExtract && (userConf.optimizeDeps ||= {}, userConf.optimizeDeps.include ||= [], userConf.optimizeDeps.include.push("@tamagui/core/inject-styles"));
250
+ const options = await ensureLoaded();
251
+ userConf.optimizeDeps ||= {};
252
+ userConf.optimizeDeps.include ||= [];
253
+ userConf.optimizeDeps.include.push("inline-style-prefixer");
254
+ if (!shouldExtract) return;
255
+ userConf.optimizeDeps.include.push("@tamagui/core/inject-styles");
211
256
  },
212
257
  async configResolved(resolvedConfig) {
213
258
  config = resolvedConfig;
214
259
  },
215
260
  async resolveId(source) {
216
- if (!shouldExtract || isNative(this.environment) || isNotClient(this.environment)) return;
261
+ if (!shouldExtract) return;
262
+ if (isNative(this.environment)) {
263
+ return;
264
+ }
265
+ if (isNotClient(this.environment)) {
266
+ return;
267
+ }
217
268
  const [validId, query] = source.split("?");
218
- if (!validId.endsWith(virtualExt)) return;
269
+ if (!validId.endsWith(virtualExt)) {
270
+ return;
271
+ }
219
272
  const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
220
- if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : "");
273
+ if (cssMap.has(absoluteId)) {
274
+ return absoluteId + (query ? `?${query}` : "");
275
+ }
221
276
  },
222
277
  async load(id) {
223
- if (!shouldExtract || (0, import_loadTamagui.getTamaguiOptions)()?.disable || isNative(this.environment) || isNotClient(this.environment)) return;
278
+ if (!shouldExtract) return;
279
+ const options = (0, import_loadTamagui.getTamaguiOptions)();
280
+ if (options?.disable) {
281
+ return;
282
+ }
283
+ if (isNative(this.environment)) {
284
+ return;
285
+ }
286
+ if (isNotClient(this.environment)) {
287
+ return;
288
+ }
224
289
  const [validId] = id.split("?");
225
290
  return cssMap.get(validId);
226
291
  },
@@ -228,40 +293,68 @@ function tamaguiPlugin({
228
293
  order: "pre",
229
294
  async handler(code, id) {
230
295
  const options = await ensureLoaded();
231
- if (await (0, import_loadTamagui.ensureFullConfigLoaded)(), options?.disable || isNative(this.environment)) return;
296
+ await (0, import_loadTamagui.ensureFullConfigLoaded)();
297
+ if (options?.disable) {
298
+ return;
299
+ }
300
+ if (isNative(this.environment)) {
301
+ return;
302
+ }
232
303
  const [validId] = id.split("?");
233
- if (!validId.endsWith(".tsx")) return;
234
- const firstCommentIndex = code.indexOf("// "),
235
- {
236
- shouldDisable,
237
- shouldPrintDebug
238
- } = await (0, import_static_worker.getPragmaOptions)({
239
- source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : "",
240
- path: validId
241
- });
242
- if (shouldPrintDebug && (console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`), console.info(`
304
+ if (!validId.endsWith(".tsx")) {
305
+ return;
306
+ }
307
+ const {
308
+ shouldDisable,
309
+ shouldPrintDebug
310
+ } = await (0, import_static_worker.getPragmaOptions)({
311
+ source: code,
312
+ path: validId
313
+ });
314
+ if (shouldPrintDebug) {
315
+ console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`);
316
+ console.info(`
243
317
 
244
318
  Original source:
245
319
  ${code}
246
320
 
247
- `)), shouldDisable) return;
248
- const isSSR = isNotClient(this.environment),
249
- cacheKey = getHash(`${code}${id}`),
250
- pending = getPendingExtractions(),
251
- formatResult = entry => ({
252
- code: !isSSR && entry.cssImport ? `${entry.js}
253
- ${entry.cssImport}` : entry.js,
321
+ `);
322
+ }
323
+ if (shouldDisable) {
324
+ return;
325
+ }
326
+ const isSSR = isNotClient(this.environment);
327
+ const cacheKey = getHash(`${code}${id}`);
328
+ const pending = getPendingExtractions();
329
+ const formatResult = entry => {
330
+ const finalCode = !isSSR && entry.cssImport ? `${entry.js}
331
+ ${entry.cssImport}` : entry.js;
332
+ return {
333
+ code: finalCode,
254
334
  map: entry.map
255
- }),
256
- cached = memoryCache[cacheKey];
257
- if (cached) return process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] HIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`), formatResult(cached);
335
+ };
336
+ };
337
+ const cached = memoryCache[cacheKey];
338
+ if (cached) {
339
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
340
+ console.info(`[tamagui-cache] HIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
341
+ }
342
+ return formatResult(cached);
343
+ }
258
344
  const pendingExtraction = pending.get(cacheKey);
259
345
  if (pendingExtraction) {
260
- process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] WAIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
346
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
347
+ console.info(`[tamagui-cache] WAIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
348
+ }
261
349
  const result = await pendingExtraction;
262
- return result ? formatResult(result) : void 0;
350
+ if (result) {
351
+ return formatResult(result);
352
+ }
353
+ return;
354
+ }
355
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
356
+ console.info(`[tamagui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
263
357
  }
264
- process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
265
358
  const extractionPromise = (async () => {
266
359
  let extracted;
267
360
  try {
@@ -272,30 +365,59 @@ ${entry.cssImport}` : entry.js,
272
365
  shouldPrintDebug
273
366
  });
274
367
  } catch (err) {
275
- return process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] ERROR extracting ${id.split("/").pop()}:`, err), console.error(err instanceof Error ? err.message : String(err)), null;
368
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
369
+ console.info(`[tamagui-cache] ERROR extracting ${id.split("/").pop()}:`, err);
370
+ }
371
+ console.error(err instanceof Error ? err.message : String(err));
372
+ return null;
373
+ }
374
+ if (!extracted) {
375
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
376
+ console.info(`[tamagui-cache] no extraction result for ${id.split("/").pop()}`);
377
+ }
378
+ return null;
276
379
  }
277
- if (!extracted) return process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] no extraction result for ${id.split("/").pop()}`), null;
278
- const rootRelativeId = `${validId}${virtualExt}`,
279
- absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
380
+ const rootRelativeId = `${validId}${virtualExt}`;
381
+ const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
280
382
  let cssImport = null;
281
- extracted.styles && (this.addWatchFile(rootRelativeId), server && cssMap.has(absoluteId) && invalidateModule(rootRelativeId), cssImport = `import "${rootRelativeId}";`, cssMap.set(absoluteId, extracted.styles));
282
- const jsCode = extracted.js.toString(),
283
- cacheEntry = {
284
- js: jsCode,
285
- map: extracted.map,
286
- cssImport
287
- },
288
- newSize = getSharedCacheSize() + jsCode.length;
289
- return newSize > 67108864 ? clearSharedCache() : setSharedCacheSize(newSize), memoryCache[cacheKey] = cacheEntry, process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] WRITE key=${cacheKey.slice(0, 8)} cacheSize=${Object.keys(memoryCache).length}`), cacheEntry;
383
+ if (extracted.styles) {
384
+ this.addWatchFile(rootRelativeId);
385
+ if (server && cssMap.has(absoluteId)) {
386
+ invalidateModule(rootRelativeId);
387
+ }
388
+ cssImport = `import "${rootRelativeId}";`;
389
+ cssMap.set(absoluteId, extracted.styles);
390
+ }
391
+ const jsCode = extracted.js.toString();
392
+ const cacheEntry = {
393
+ js: jsCode,
394
+ map: extracted.map,
395
+ cssImport
396
+ };
397
+ const newSize = getSharedCacheSize() + jsCode.length;
398
+ if (newSize > 67108864) {
399
+ clearSharedCache();
400
+ } else {
401
+ setSharedCacheSize(newSize);
402
+ }
403
+ memoryCache[cacheKey] = cacheEntry;
404
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
405
+ console.info(`[tamagui-cache] WRITE key=${cacheKey.slice(0, 8)} cacheSize=${Object.keys(memoryCache).length}`);
406
+ }
407
+ return cacheEntry;
290
408
  })();
291
409
  pending.set(cacheKey, extractionPromise);
292
410
  try {
293
411
  const result = await extractionPromise;
294
- return result ? formatResult(result) : void 0;
412
+ if (result) {
413
+ return formatResult(result);
414
+ }
415
+ return;
295
416
  } finally {
296
417
  pending.delete(cacheKey);
297
418
  }
298
419
  }
299
420
  }
300
- }];
421
+ };
422
+ return [basePlugin, rnwLitePlugin, extractPlugin];
301
423
  }
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./plugin";
1
+ export * from "./plugin.mjs";
2
2
  //# sourceMappingURL=index.js.map
@@ -1,6 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "mappings": "AAAA,cAAc;",
5
- "names": []
6
- }
1
+ {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
@@ -1,12 +1,16 @@
1
1
  import * as StaticWorker from "@tamagui/static-worker";
2
2
  const LOAD_STATE_KEY = "__tamagui_load_state__";
3
3
  function getLoadState() {
4
- return globalThis[LOAD_STATE_KEY] || (globalThis[LOAD_STATE_KEY] = {
5
- loadPromise: null,
6
- loadedOptions: null,
7
- fullConfigLoaded: !1,
8
- fullConfigLoadPromise: null
9
- }), globalThis[LOAD_STATE_KEY];
4
+ if (!globalThis[LOAD_STATE_KEY]) {
5
+ ;
6
+ globalThis[LOAD_STATE_KEY] = {
7
+ loadPromise: null,
8
+ loadedOptions: null,
9
+ fullConfigLoaded: false,
10
+ fullConfigLoadPromise: null
11
+ };
12
+ }
13
+ return globalThis[LOAD_STATE_KEY];
10
14
  }
11
15
  function getTamaguiOptions() {
12
16
  return getLoadState().loadedOptions;
@@ -16,29 +20,42 @@ function getLoadPromise() {
16
20
  }
17
21
  async function loadTamaguiBuildConfig(optionsIn) {
18
22
  const state = getLoadState();
19
- return state.loadedOptions ? state.loadedOptions : (state.loadPromise || (state.loadPromise = (async () => {
23
+ if (state.loadedOptions) return state.loadedOptions;
24
+ if (state.loadPromise) return state.loadPromise;
25
+ state.loadPromise = (async () => {
20
26
  const options = await StaticWorker.loadTamaguiBuildConfig({
21
27
  ...optionsIn,
22
28
  platform: "web"
23
29
  });
24
- return state.loadedOptions = options, options;
25
- })()), state.loadPromise);
30
+ state.loadedOptions = options;
31
+ return options;
32
+ })();
33
+ return state.loadPromise;
26
34
  }
27
35
  async function ensureFullConfigLoaded() {
28
36
  const state = getLoadState();
29
- if (!state.fullConfigLoaded) return state.fullConfigLoadPromise || (state.fullConfigLoadPromise = (async () => {
37
+ if (state.fullConfigLoaded) return;
38
+ if (state.fullConfigLoadPromise) return state.fullConfigLoadPromise;
39
+ state.fullConfigLoadPromise = (async () => {
30
40
  const options = await loadTamaguiBuildConfig();
31
- !options.disableWatchTamaguiConfig && !options.disable && (await StaticWorker.loadTamagui({
32
- components: ["tamagui"],
33
- platform: "web",
34
- ...options
35
- })), state.fullConfigLoaded = !0;
36
- })()), state.fullConfigLoadPromise;
41
+ if (!options.disableWatchTamaguiConfig && !options.disable) {
42
+ await StaticWorker.loadTamagui({
43
+ components: ["tamagui"],
44
+ platform: "web",
45
+ ...options
46
+ });
47
+ }
48
+ state.fullConfigLoaded = true;
49
+ })();
50
+ return state.fullConfigLoadPromise;
37
51
  }
38
52
  async function cleanup() {
39
53
  await StaticWorker.destroyPool();
40
54
  const state = getLoadState();
41
- state.loadPromise = null, state.loadedOptions = null, state.fullConfigLoaded = !1, state.fullConfigLoadPromise = null;
55
+ state.loadPromise = null;
56
+ state.loadedOptions = null;
57
+ state.fullConfigLoaded = false;
58
+ state.fullConfigLoadPromise = null;
42
59
  }
43
60
  export { cleanup, ensureFullConfigLoaded, getLoadPromise, getTamaguiOptions, loadTamaguiBuildConfig };
44
61
  //# sourceMappingURL=loadTamagui.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["StaticWorker","LOAD_STATE_KEY","getLoadState","globalThis","loadPromise","loadedOptions","fullConfigLoaded","fullConfigLoadPromise","getTamaguiOptions","getLoadPromise","loadTamaguiBuildConfig","optionsIn","state","options","platform","ensureFullConfigLoaded","disableWatchTamaguiConfig","disable","loadTamagui","components","cleanup","destroyPool"],"sources":["../../src/loadTamagui.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,YAAA,MAAkB;AAI9B,MAAMC,cAAA,GAAiB;AASvB,SAASC,aAAA,EAA0B;EACjC,OAAMC,UAAA,CAAmBF,cAAc,MACnCE,UAAA,CAAmBF,cAAc,IAAI;IACrCG,WAAA,EAAa;IACbC,aAAA,EAAe;IACfC,gBAAA,EAAkB;IAClBC,qBAAA,EAAuB;EACzB,IAEMJ,UAAA,CAAmBF,cAAc;AAC3C;AAEO,SAASO,kBAAA,EAA2C;EACzD,OAAON,YAAA,CAAa,EAAEG,aAAA;AACxB;AAEO,SAASI,eAAA,EAAiD;EAC/D,OAAOP,YAAA,CAAa,EAAEE,WAAA;AACxB;AAMA,eAAsBM,uBACpBC,SAAA,EACyB;EACzB,MAAMC,KAAA,GAAQV,YAAA,CAAa;EAC3B,OAAIU,KAAA,CAAMP,aAAA,GAAsBO,KAAA,CAAMP,aAAA,IAClCO,KAAA,CAAMR,WAAA,KAEVQ,KAAA,CAAMR,WAAA,IAAe,YAAY;IAC/B,MAAMS,OAAA,GAAU,MAAMb,YAAA,CAAaU,sBAAA,CAAuB;MACxD,GAAGC,SAAA;MACHG,QAAA,EAAU;IACZ,CAAC;IAED,OAAAF,KAAA,CAAMP,aAAA,GAAgBQ,OAAA,EACfA,OAAA;EACT,GAAG,IAEID,KAAA,CAAMR,WAAA;AACf;AAMA,eAAsBW,uBAAA,EAAwC;EAC5D,MAAMH,KAAA,GAAQV,YAAA,CAAa;EAE3B,IAAI,CAAAU,KAAA,CAAMN,gBAAA,EACV,OAAIM,KAAA,CAAML,qBAAA,KAIVK,KAAA,CAAML,qBAAA,IAAyB,YAAY;IACzC,MAAMM,OAAA,GAAU,MAAMH,sBAAA,CAAuB;IAGzC,CAACG,OAAA,CAAQG,yBAAA,IAA6B,CAACH,OAAA,CAAQI,OAAA,KACjD,MAAMjB,YAAA,CAAakB,WAAA,CAAY;MAC7BC,UAAA,EAAY,CAAC,SAAS;MACtBL,QAAA,EAAU;MACV,GAAGD;IACL,CAAC,IAEHD,KAAA,CAAMN,gBAAA,GAAmB;EAC3B,GAAG,IAEIM,KAAA,CAAML,qBAAA;AACf;AAEA,eAAsBa,QAAA,EAAU;EAC9B,MAAMpB,YAAA,CAAaqB,WAAA,CAAY;EAC/B,MAAMT,KAAA,GAAQV,YAAA,CAAa;EAC3BU,KAAA,CAAMR,WAAA,GAAc,MACpBQ,KAAA,CAAMP,aAAA,GAAgB,MACtBO,KAAA,CAAMN,gBAAA,GAAmB,IACzBM,KAAA,CAAML,qBAAA,GAAwB;AAChC","ignoreList":[]}
1
+ {"version":3,"names":["StaticWorker","LOAD_STATE_KEY","getLoadState","globalThis","loadPromise","loadedOptions","fullConfigLoaded","fullConfigLoadPromise","getTamaguiOptions","getLoadPromise","loadTamaguiBuildConfig","optionsIn","state","options","platform","ensureFullConfigLoaded","disableWatchTamaguiConfig","disable","loadTamagui","components","cleanup","destroyPool"],"sources":["../../src/loadTamagui.ts"],"sourcesContent":[null],"mappings":"AAAA,YAAYA,YAAA,MAAkB;AAI9B,MAAMC,cAAA,GAAiB;AASvB,SAASC,aAAA,EAA0B;EACjC,IAAI,CAAEC,UAAA,CAAmBF,cAAc,GAAG;IACxC;IAAEE,UAAA,CAAmBF,cAAc,IAAI;MACrCG,WAAA,EAAa;MACbC,aAAA,EAAe;MACfC,gBAAA,EAAkB;MAClBC,qBAAA,EAAuB;IACzB;EACF;EACA,OAAQJ,UAAA,CAAmBF,cAAc;AAC3C;AAEO,SAASO,kBAAA,EAA2C;EACzD,OAAON,YAAA,CAAa,EAAEG,aAAA;AACxB;AAEO,SAASI,eAAA,EAAiD;EAC/D,OAAOP,YAAA,CAAa,EAAEE,WAAA;AACxB;AAMA,eAAsBM,uBACpBC,SAAA,EACyB;EACzB,MAAMC,KAAA,GAAQV,YAAA,CAAa;EAC3B,IAAIU,KAAA,CAAMP,aAAA,EAAe,OAAOO,KAAA,CAAMP,aAAA;EACtC,IAAIO,KAAA,CAAMR,WAAA,EAAa,OAAOQ,KAAA,CAAMR,WAAA;EAEpCQ,KAAA,CAAMR,WAAA,IAAe,YAAY;IAC/B,MAAMS,OAAA,GAAU,MAAMb,YAAA,CAAaU,sBAAA,CAAuB;MACxD,GAAGC,SAAA;MACHG,QAAA,EAAU;IACZ,CAAC;IAEDF,KAAA,CAAMP,aAAA,GAAgBQ,OAAA;IACtB,OAAOA,OAAA;EACT,GAAG;EAEH,OAAOD,KAAA,CAAMR,WAAA;AACf;AAMA,eAAsBW,uBAAA,EAAwC;EAC5D,MAAMH,KAAA,GAAQV,YAAA,CAAa;EAE3B,IAAIU,KAAA,CAAMN,gBAAA,EAAkB;EAC5B,IAAIM,KAAA,CAAML,qBAAA,EAAuB,OAAOK,KAAA,CAAML,qBAAA;EAI9CK,KAAA,CAAML,qBAAA,IAAyB,YAAY;IACzC,MAAMM,OAAA,GAAU,MAAMH,sBAAA,CAAuB;IAG7C,IAAI,CAACG,OAAA,CAAQG,yBAAA,IAA6B,CAACH,OAAA,CAAQI,OAAA,EAAS;MAC1D,MAAMjB,YAAA,CAAakB,WAAA,CAAY;QAC7BC,UAAA,EAAY,CAAC,SAAS;QACtBL,QAAA,EAAU;QACV,GAAGD;MACL,CAAC;IACH;IACAD,KAAA,CAAMN,gBAAA,GAAmB;EAC3B,GAAG;EAEH,OAAOM,KAAA,CAAML,qBAAA;AACf;AAEA,eAAsBa,QAAA,EAAU;EAC9B,MAAMpB,YAAA,CAAaqB,WAAA,CAAY;EAC/B,MAAMT,KAAA,GAAQV,YAAA,CAAa;EAC3BU,KAAA,CAAMR,WAAA,GAAc;EACpBQ,KAAA,CAAMP,aAAA,GAAgB;EACtBO,KAAA,CAAMN,gBAAA,GAAmB;EACzBM,KAAA,CAAML,qBAAA,GAAwB;AAChC","ignoreList":[]}