@tamagui/vite-plugin-cjs 2.0.0-rc.9 → 2.0.0

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 (56) hide show
  1. package/dist/cjs/extensions.cjs +12 -10
  2. package/dist/cjs/index.cjs +7 -5
  3. package/dist/cjs/index.js +11 -8
  4. package/dist/cjs/loadTamagui.cjs +58 -39
  5. package/dist/cjs/plugin.cjs +280 -123
  6. package/dist/esm/index.js +1 -1
  7. package/dist/esm/index.js.map +1 -6
  8. package/dist/esm/loadTamagui.mjs +34 -17
  9. package/dist/esm/loadTamagui.mjs.map +1 -1
  10. package/dist/esm/plugin.mjs +249 -94
  11. package/dist/esm/plugin.mjs.map +1 -1
  12. package/package.json +2 -2
  13. package/dist/cjs/cache.cjs +0 -70
  14. package/dist/cjs/cache.js +0 -63
  15. package/dist/cjs/cache.js.map +0 -6
  16. package/dist/cjs/extensions.mjs +0 -47
  17. package/dist/cjs/extensions.mjs.map +0 -1
  18. package/dist/cjs/extensions.native.js +0 -47
  19. package/dist/cjs/extensions.native.js.map +0 -1
  20. package/dist/cjs/extract.cjs +0 -160
  21. package/dist/cjs/extract.js +0 -148
  22. package/dist/cjs/extract.js.map +0 -6
  23. package/dist/cjs/extract.mjs +0 -226
  24. package/dist/cjs/extract.mjs.map +0 -1
  25. package/dist/cjs/extract.native.js +0 -274
  26. package/dist/cjs/extract.native.js.map +0 -1
  27. package/dist/cjs/index.mjs +0 -31
  28. package/dist/cjs/index.mjs.map +0 -1
  29. package/dist/cjs/index.native.js +0 -31
  30. package/dist/cjs/index.native.js.map +0 -1
  31. package/dist/cjs/loadTamagui.mjs +0 -89
  32. package/dist/cjs/loadTamagui.mjs.map +0 -1
  33. package/dist/cjs/loadTamagui.native.js +0 -90
  34. package/dist/cjs/loadTamagui.native.js.map +0 -1
  35. package/dist/cjs/plugin.mjs +0 -228
  36. package/dist/cjs/plugin.mjs.map +0 -1
  37. package/dist/cjs/plugin.native.js +0 -244
  38. package/dist/cjs/plugin.native.js.map +0 -1
  39. package/dist/esm/cache.js +0 -47
  40. package/dist/esm/cache.js.map +0 -6
  41. package/dist/esm/cache.mjs +0 -40
  42. package/dist/esm/cache.mjs.map +0 -1
  43. package/dist/esm/extensions.native.js +0 -14
  44. package/dist/esm/extensions.native.js.map +0 -1
  45. package/dist/esm/extract.js +0 -129
  46. package/dist/esm/extract.js.map +0 -6
  47. package/dist/esm/extract.mjs +0 -126
  48. package/dist/esm/extract.mjs.map +0 -1
  49. package/dist/esm/extract.native.js +0 -216
  50. package/dist/esm/extract.native.js.map +0 -1
  51. package/dist/esm/index.native.js +0 -3
  52. package/dist/esm/index.native.js.map +0 -1
  53. package/dist/esm/loadTamagui.native.js +0 -36
  54. package/dist/esm/loadTamagui.native.js.map +0 -1
  55. package/dist/esm/plugin.native.js +0 -184
  56. package/dist/esm/plugin.native.js.map +0 -1
@@ -2,79 +2,116 @@ 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_module = require("node:module");
44
+ var import_node_path = __toESM(require("node:path"), 1);
45
+ var import_node_url = require("node:url");
46
+ var import_loadTamagui = require("./loadTamagui.cjs");
47
+ const import_meta = {};
48
+ const _pluginRequire = (0, import_node_module.createRequire)(typeof __filename === "string" ? __filename : (0, import_node_url.fileURLToPath)(import_meta.url));
49
+ const resolve = name => _pluginRequire.resolve(name);
50
+ const normalizePath = value => value.replace(/\\/g, "/");
51
+ const CACHE_KEY = "__tamagui_vite_cache__";
52
+ const CACHE_SIZE_KEY = "__tamagui_vite_cache_size__";
53
+ const PENDING_KEY = "__tamagui_vite_pending__";
50
54
  function getSharedCache() {
51
- return globalThis[CACHE_KEY] || (globalThis[CACHE_KEY] = {}), globalThis[CACHE_KEY];
55
+ if (!globalThis[CACHE_KEY]) {
56
+ ;
57
+ globalThis[CACHE_KEY] = {};
58
+ }
59
+ return globalThis[CACHE_KEY];
52
60
  }
53
61
  function getSharedCacheSize() {
54
62
  return globalThis[CACHE_SIZE_KEY] || 0;
55
63
  }
56
64
  function setSharedCacheSize(size) {
65
+ ;
57
66
  globalThis[CACHE_SIZE_KEY] = size;
58
67
  }
59
68
  function clearSharedCache() {
60
- globalThis[CACHE_KEY] = {}, globalThis[CACHE_SIZE_KEY] = 0;
69
+ ;
70
+ globalThis[CACHE_KEY] = {};
71
+ globalThis[CACHE_SIZE_KEY] = 0;
72
+ }
73
+ function isInstalled(projectRoot, id) {
74
+ try {
75
+ const req = (0, import_node_module.createRequire)(import_node_path.default.join(projectRoot, "package.json"));
76
+ req.resolve(id);
77
+ return true;
78
+ } catch {
79
+ return false;
80
+ }
81
+ }
82
+ function addIfInstalled(userConf, projectRoot, ids) {
83
+ const root = projectRoot || process.cwd();
84
+ userConf.optimizeDeps ||= {};
85
+ userConf.optimizeDeps.include ||= [];
86
+ for (const id of ids) {
87
+ if (!userConf.optimizeDeps.include.includes(id) && isInstalled(root, id)) {
88
+ userConf.optimizeDeps.include.push(id);
89
+ }
90
+ }
61
91
  }
62
92
  function getPendingExtractions() {
63
- return globalThis[PENDING_KEY] || (globalThis[PENDING_KEY] = /* @__PURE__ */new Map()), globalThis[PENDING_KEY];
93
+ if (!globalThis[PENDING_KEY]) {
94
+ ;
95
+ globalThis[PENDING_KEY] = /* @__PURE__ */new Map();
96
+ }
97
+ return globalThis[PENDING_KEY];
64
98
  }
65
99
  function tamaguiAliases(options = {}) {
66
100
  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"));
101
+ if (options.svg) {
102
+ aliases.push({
103
+ find: "react-native-svg",
104
+ replacement: resolve("@tamagui/react-native-svg")
105
+ });
106
+ }
107
+ if (options.rnwLite) {
108
+ const rnwlBase = import_node_path.default.dirname(resolve("@tamagui/react-native-web-lite/package.json"));
109
+ const rnwl = normalizePath(import_node_path.default.join(rnwlBase, options.rnwLite === "without-animated" ? "dist/esm/without-animated.mjs" : "dist/esm/index.mjs"));
73
110
  aliases.push({
74
111
  // map deep RNW paths like dist/exports/StyleSheet/preprocess to rnw-lite's flat structure
75
112
  // extracts the final path segment (e.g. "preprocess" or "createReactDOMStyle")
76
113
  find: /^react-native(?:-web)?\/dist\/(?:exports|modules)\/.*\/([^/]+)$/,
77
- replacement: `${rnwlBase}/dist/esm/$1.mjs`
114
+ replacement: `${normalizePath(rnwlBase)}/dist/esm/$1.mjs`
78
115
  }, {
79
116
  find: /^react-native$/,
80
117
  replacement: rnwl
@@ -95,23 +132,32 @@ function tamaguiPlugin({
95
132
  disableResolveConfig,
96
133
  ...tamaguiOptionsIn
97
134
  } = {}) {
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"];
135
+ let shouldExtract = !tamaguiOptionsIn.disableExtraction;
136
+ let watcher;
137
+ const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv;
138
+ const extensions = [`.web.mjs`, `.web.js`, `.web.jsx`, `.web.ts`, `.web.tsx`, ".mjs", ".js", ".mts", ".ts", ".jsx", ".tsx", ".json"];
102
139
  (0, import_loadTamagui.loadTamaguiBuildConfig)(tamaguiOptionsIn);
103
140
  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));
141
+ const promise = (0, import_loadTamagui.getLoadPromise)();
142
+ if (promise) await promise;
143
+ const options = (0, import_loadTamagui.getTamaguiOptions)();
144
+ if (options) {
145
+ shouldExtract = !options.disableExtraction;
146
+ }
147
+ return options;
148
+ };
149
+ const getHash = input => (0, import_node_crypto.createHash)("sha1").update(input).digest("base64");
150
+ const memoryCache = getSharedCache();
151
+ const cssMap = /* @__PURE__ */new Map();
152
+ let config;
153
+ let server;
154
+ const virtualExt = `.tamagui.css`;
155
+ const getAbsoluteVirtualFileId = filePath => {
156
+ if (filePath.startsWith(config.root)) {
157
+ return filePath;
158
+ }
159
+ return normalizePath(import_node_path.default.join(config.root, filePath));
160
+ };
115
161
  function isNotClient(environment) {
116
162
  return environment?.name && environment.name !== "client";
117
163
  }
@@ -121,12 +167,17 @@ function tamaguiPlugin({
121
167
  function invalidateModule(absoluteId) {
122
168
  if (!server) return;
123
169
  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();
170
+ moduleGraph
171
+ } = server;
172
+ const modules = moduleGraph.getModulesByFile(absoluteId);
173
+ if (modules) {
174
+ for (const module2 of modules) {
175
+ moduleGraph.invalidateModule(module2);
176
+ module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
177
+ }
178
+ }
128
179
  }
129
- return [{
180
+ const basePlugin = {
130
181
  name: "tamagui",
131
182
  enforce: "pre",
132
183
  configureServer(_server) {
@@ -137,27 +188,26 @@ function tamaguiPlugin({
137
188
  res?.dispose();
138
189
  });
139
190
  },
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
191
  async config(_, env) {
147
192
  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
- })), {
193
+ if (!options) {
194
+ throw new Error(`No tamagui options loaded`);
195
+ }
196
+ if (!options.disableWatchTamaguiConfig) {
197
+ watcher = Static.watchTamaguiConfig({
198
+ components: ["tamagui"],
199
+ config: "./src/tamagui.config.ts",
200
+ ...options
201
+ }).catch(err => {
202
+ console.error(` [Tamagui] Error watching config: ${err}`);
203
+ });
204
+ }
205
+ return {
156
206
  envPrefix: ["TAMAGUI_"],
157
207
  environments: {
158
208
  client: {
159
209
  define: {
160
- "process.env.TAMAGUI_IS_CLIENT": JSON.stringify(!0),
210
+ "process.env.TAMAGUI_IS_CLIENT": JSON.stringify(true),
161
211
  "process.env.TAMAGUI_ENVIRONMENT": '"client"'
162
212
  }
163
213
  }
@@ -165,14 +215,14 @@ function tamaguiPlugin({
165
215
  define: {
166
216
  // reanimated support
167
217
  _frameTimestamp: void 0,
168
- _WORKLET: !1,
218
+ _WORKLET: false,
169
219
  __DEV__: `${env.mode === "development"}`,
170
220
  "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
171
221
  "process.env.ENABLE_RSC": JSON.stringify(process.env.ENABLE_RSC || ""),
172
222
  "process.env.ENABLE_STEPS": JSON.stringify(process.env.ENABLE_STEPS || ""),
173
- "process.env.IS_STATIC": JSON.stringify(!1),
223
+ "process.env.IS_STATIC": JSON.stringify(false),
174
224
  ...(env.mode === "production" && {
175
- "process.env.TAMAGUI_OPTIMIZE_THEMES": JSON.stringify(!0)
225
+ "process.env.TAMAGUI_OPTIMIZE_THEMES": JSON.stringify(true)
176
226
  })
177
227
  },
178
228
  resolve: disableResolveConfig || enableNativeEnv ? {} : {
@@ -190,37 +240,86 @@ function tamaguiPlugin({
190
240
  }
191
241
  };
192
242
  }
193
- }, {
243
+ };
244
+ const rnwLitePlugin = {
194
245
  name: "tamagui-rnw-lite",
195
246
  config() {
196
- if (enableNativeEnv) return {};
247
+ if (enableNativeEnv) {
248
+ return {};
249
+ }
197
250
  const options = (0, import_loadTamagui.getTamaguiOptions)();
198
- return options?.useReactNativeWebLite ? {
251
+ if (!options?.useReactNativeWebLite) {
252
+ return {};
253
+ }
254
+ const include = [];
255
+ if (isInstalled(process.cwd(), "memoize-one")) {
256
+ include.push("memoize-one");
257
+ }
258
+ return {
199
259
  resolve: {
200
260
  alias: tamaguiAliases({
201
261
  rnwLite: options.useReactNativeWebLite
202
262
  })
263
+ },
264
+ optimizeDeps: {
265
+ // upstream react-native-web must not be pre-bundled when aliased to lite
266
+ exclude: ["react-native-web"],
267
+ include
203
268
  }
204
- } : {};
269
+ };
205
270
  }
206
- }, {
271
+ };
272
+ const extractPlugin = {
207
273
  name: "tamagui-extract",
208
274
  enforce: "pre",
209
275
  async config(userConf) {
210
- await ensureLoaded(), shouldExtract && (userConf.optimizeDeps ||= {}, userConf.optimizeDeps.include ||= [], userConf.optimizeDeps.include.push("@tamagui/core/inject-styles"));
276
+ const options = await ensureLoaded();
277
+ userConf.optimizeDeps ||= {};
278
+ userConf.optimizeDeps.include ||= [];
279
+ userConf.optimizeDeps.include.push("inline-style-prefixer");
280
+ addIfInstalled(userConf, userConf.root, ["@tamagui/toast", "@tamagui/toast/v2"]);
281
+ userConf.resolve ||= {};
282
+ userConf.resolve.dedupe ||= [];
283
+ for (const id of ["tamagui", "@tamagui/core", "@tamagui/web", "@tamagui/toast"]) {
284
+ if (!userConf.resolve.dedupe.includes(id) && isInstalled(userConf.root || process.cwd(), id)) {
285
+ userConf.resolve.dedupe.push(id);
286
+ }
287
+ }
288
+ if (!shouldExtract) return;
289
+ userConf.optimizeDeps.include.push("@tamagui/core/inject-styles");
211
290
  },
212
291
  async configResolved(resolvedConfig) {
213
292
  config = resolvedConfig;
214
293
  },
215
294
  async resolveId(source) {
216
- if (!shouldExtract || isNative(this.environment) || isNotClient(this.environment)) return;
295
+ if (!shouldExtract) return;
296
+ if (isNative(this.environment)) {
297
+ return;
298
+ }
299
+ if (isNotClient(this.environment)) {
300
+ return;
301
+ }
217
302
  const [validId, query] = source.split("?");
218
- if (!validId.endsWith(virtualExt)) return;
303
+ if (!validId.endsWith(virtualExt)) {
304
+ return;
305
+ }
219
306
  const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
220
- if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : "");
307
+ if (cssMap.has(absoluteId)) {
308
+ return absoluteId + (query ? `?${query}` : "");
309
+ }
221
310
  },
222
311
  async load(id) {
223
- if (!shouldExtract || (0, import_loadTamagui.getTamaguiOptions)()?.disable || isNative(this.environment) || isNotClient(this.environment)) return;
312
+ if (!shouldExtract) return;
313
+ const options = (0, import_loadTamagui.getTamaguiOptions)();
314
+ if (options?.disable) {
315
+ return;
316
+ }
317
+ if (isNative(this.environment)) {
318
+ return;
319
+ }
320
+ if (isNotClient(this.environment)) {
321
+ return;
322
+ }
224
323
  const [validId] = id.split("?");
225
324
  return cssMap.get(validId);
226
325
  },
@@ -228,9 +327,17 @@ function tamaguiPlugin({
228
327
  order: "pre",
229
328
  async handler(code, id) {
230
329
  const options = await ensureLoaded();
231
- if (await (0, import_loadTamagui.ensureFullConfigLoaded)(), options?.disable || isNative(this.environment)) return;
330
+ await (0, import_loadTamagui.ensureFullConfigLoaded)();
331
+ if (options?.disable) {
332
+ return;
333
+ }
334
+ if (isNative(this.environment)) {
335
+ return;
336
+ }
232
337
  const [validId] = id.split("?");
233
- if (!validId.endsWith(".tsx")) return;
338
+ if (!validId.endsWith(".tsx")) {
339
+ return;
340
+ }
234
341
  const {
235
342
  shouldDisable,
236
343
  shouldPrintDebug
@@ -238,29 +345,50 @@ function tamaguiPlugin({
238
345
  source: code,
239
346
  path: validId
240
347
  });
241
- if (shouldPrintDebug && (console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`), console.info(`
348
+ if (shouldPrintDebug) {
349
+ console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`);
350
+ console.info(`
242
351
 
243
352
  Original source:
244
353
  ${code}
245
354
 
246
- `)), shouldDisable) return;
247
- const isSSR = isNotClient(this.environment),
248
- cacheKey = getHash(`${code}${id}`),
249
- pending = getPendingExtractions(),
250
- formatResult = entry => ({
251
- code: !isSSR && entry.cssImport ? `${entry.js}
252
- ${entry.cssImport}` : entry.js,
355
+ `);
356
+ }
357
+ if (shouldDisable) {
358
+ return;
359
+ }
360
+ const isSSR = isNotClient(this.environment);
361
+ const cacheKey = getHash(`${code}${id}`);
362
+ const pending = getPendingExtractions();
363
+ const formatResult = entry => {
364
+ const finalCode = !isSSR && entry.cssImport ? `${entry.js}
365
+ ${entry.cssImport}` : entry.js;
366
+ return {
367
+ code: finalCode,
253
368
  map: entry.map
254
- }),
255
- cached = memoryCache[cacheKey];
256
- 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);
369
+ };
370
+ };
371
+ const cached = memoryCache[cacheKey];
372
+ if (cached) {
373
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
374
+ console.info(`[tamagui-cache] HIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
375
+ }
376
+ return formatResult(cached);
377
+ }
257
378
  const pendingExtraction = pending.get(cacheKey);
258
379
  if (pendingExtraction) {
259
- process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] WAIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
380
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
381
+ console.info(`[tamagui-cache] WAIT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
382
+ }
260
383
  const result = await pendingExtraction;
261
- return result ? formatResult(result) : void 0;
384
+ if (result) {
385
+ return formatResult(result);
386
+ }
387
+ return;
388
+ }
389
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
390
+ console.info(`[tamagui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
262
391
  }
263
- process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] EXTRACT ${this.environment?.name || "unknown"} ${id.split("/").pop()} key=${cacheKey.slice(0, 8)}`);
264
392
  const extractionPromise = (async () => {
265
393
  let extracted;
266
394
  try {
@@ -271,30 +399,59 @@ ${entry.cssImport}` : entry.js,
271
399
  shouldPrintDebug
272
400
  });
273
401
  } catch (err) {
274
- 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;
402
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
403
+ console.info(`[tamagui-cache] ERROR extracting ${id.split("/").pop()}:`, err);
404
+ }
405
+ console.error(err instanceof Error ? err.message : String(err));
406
+ return null;
275
407
  }
276
- if (!extracted) return process.env.DEBUG_TAMAGUI_CACHE && console.info(`[tamagui-cache] no extraction result for ${id.split("/").pop()}`), null;
277
- const rootRelativeId = `${validId}${virtualExt}`,
278
- absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
408
+ if (!extracted) {
409
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
410
+ console.info(`[tamagui-cache] no extraction result for ${id.split("/").pop()}`);
411
+ }
412
+ return null;
413
+ }
414
+ const rootRelativeId = `${validId}${virtualExt}`;
415
+ const absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
279
416
  let cssImport = null;
280
- extracted.styles && (this.addWatchFile(rootRelativeId), server && cssMap.has(absoluteId) && invalidateModule(rootRelativeId), cssImport = `import "${rootRelativeId}";`, cssMap.set(absoluteId, extracted.styles));
281
- const jsCode = extracted.js.toString(),
282
- cacheEntry = {
283
- js: jsCode,
284
- map: extracted.map,
285
- cssImport
286
- },
287
- newSize = getSharedCacheSize() + jsCode.length;
288
- 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;
417
+ if (extracted.styles) {
418
+ this.addWatchFile(rootRelativeId);
419
+ if (server && cssMap.has(absoluteId)) {
420
+ invalidateModule(rootRelativeId);
421
+ }
422
+ cssImport = `import "${rootRelativeId}";`;
423
+ cssMap.set(absoluteId, extracted.styles);
424
+ }
425
+ const jsCode = extracted.js.toString();
426
+ const cacheEntry = {
427
+ js: jsCode,
428
+ map: extracted.map,
429
+ cssImport
430
+ };
431
+ const newSize = getSharedCacheSize() + jsCode.length;
432
+ if (newSize > 67108864) {
433
+ clearSharedCache();
434
+ } else {
435
+ setSharedCacheSize(newSize);
436
+ }
437
+ memoryCache[cacheKey] = cacheEntry;
438
+ if (process.env.DEBUG_TAMAGUI_CACHE) {
439
+ console.info(`[tamagui-cache] WRITE key=${cacheKey.slice(0, 8)} cacheSize=${Object.keys(memoryCache).length}`);
440
+ }
441
+ return cacheEntry;
289
442
  })();
290
443
  pending.set(cacheKey, extractionPromise);
291
444
  try {
292
445
  const result = await extractionPromise;
293
- return result ? formatResult(result) : void 0;
446
+ if (result) {
447
+ return formatResult(result);
448
+ }
449
+ return;
294
450
  } finally {
295
451
  pending.delete(cacheKey);
296
452
  }
297
453
  }
298
454
  }
299
- }];
455
+ };
456
+ return [basePlugin, rnwLitePlugin, extractPlugin];
300
457
  }
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":[]}