@tamagui/vite-plugin-cjs 2.0.0-1768530912818 → 2.0.0-1768636514428

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.
@@ -1,166 +1,216 @@
1
- import * as Static from "@tamagui/static-worker";
2
- import { getPragmaOptions } from "@tamagui/static-worker";
3
- import path from "path";
4
- import { normalizePath } from "vite";
5
- import { disableStatic, loadTamaguiBuildConfig, tamaguiOptions } from "./loadTamagui.native.js";
6
- import { createHash } from "crypto";
1
+ import * as Static from '@tamagui/static-worker'
2
+ import { getPragmaOptions } from '@tamagui/static-worker'
3
+ import path from 'path'
4
+ import { normalizePath } from 'vite'
5
+ import {
6
+ disableStatic,
7
+ loadTamaguiBuildConfig,
8
+ tamaguiOptions,
9
+ } from './loadTamagui.native.js'
10
+ import { createHash } from 'crypto'
7
11
  function _instanceof(left, right) {
8
- return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
12
+ return right != null && typeof Symbol < 'u' && right[Symbol.hasInstance]
13
+ ? !!right[Symbol.hasInstance](left)
14
+ : left instanceof right
9
15
  }
10
16
  function tamaguiExtractPlugin(optionsIn) {
11
- if (optionsIn?.disable) return {
12
- name: "tamagui-extract"
13
- };
14
- var getHash = function (input) {
15
- return createHash("sha1").update(input).digest("base64");
16
- },
17
- clearCompilerCache = function () {
18
- memoryCache = {}, cacheSize = 0;
17
+ if (optionsIn?.disable)
18
+ return {
19
+ name: 'tamagui-extract',
20
+ }
21
+ var getHash = (input) => createHash('sha1').update(input).digest('base64'),
22
+ clearCompilerCache = () => {
23
+ ;(memoryCache = {}), (cacheSize = 0)
19
24
  },
20
25
  memoryCache = {},
21
26
  cacheSize = 0,
22
- cssMap = /* @__PURE__ */new Map(),
27
+ cssMap = /* @__PURE__ */ new Map(),
23
28
  config,
24
29
  server,
25
- virtualExt = ".tamagui.css",
26
- getAbsoluteVirtualFileId = function (filePath) {
27
- return filePath.startsWith(config.root) ? filePath : normalizePath(path.join(config.root, filePath));
28
- };
30
+ virtualExt = '.tamagui.css',
31
+ getAbsoluteVirtualFileId = (filePath) =>
32
+ filePath.startsWith(config.root)
33
+ ? filePath
34
+ : normalizePath(path.join(config.root, filePath))
29
35
  function isVite6AndNotClient(environment) {
30
- return environment?.name && environment.name !== "client";
36
+ return environment?.name && environment.name !== 'client'
31
37
  }
32
38
  function isVite6Native(environment) {
33
- return environment?.name && (environment.name === "ios" || environment.name === "android");
39
+ return (
40
+ environment?.name && (environment.name === 'ios' || environment.name === 'android')
41
+ )
34
42
  }
35
43
  function invalidateModule(absoluteId) {
36
44
  if (server) {
37
- var {
38
- moduleGraph
39
- } = server,
40
- modules = moduleGraph.getModulesByFile(absoluteId);
45
+ var { moduleGraph } = server,
46
+ modules = moduleGraph.getModulesByFile(absoluteId)
41
47
  if (modules) {
42
48
  var _iteratorNormalCompletion = !0,
43
49
  _didIteratorError = !1,
44
- _iteratorError = void 0;
50
+ _iteratorError = void 0
45
51
  try {
46
- for (var _iterator = modules[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
47
- var module = _step.value;
48
- moduleGraph.invalidateModule(module), module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now();
52
+ for (
53
+ var _iterator = modules[Symbol.iterator](), _step;
54
+ !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
55
+ _iteratorNormalCompletion = !0
56
+ ) {
57
+ var module = _step.value
58
+ moduleGraph.invalidateModule(module),
59
+ (module.lastHMRTimestamp = module.lastInvalidationTimestamp || Date.now())
49
60
  }
50
61
  } catch (err) {
51
- _didIteratorError = !0, _iteratorError = err;
62
+ ;(_didIteratorError = !0), (_iteratorError = err)
52
63
  } finally {
53
64
  try {
54
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
65
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return()
55
66
  } finally {
56
- if (_didIteratorError) throw _iteratorError;
67
+ if (_didIteratorError) throw _iteratorError
57
68
  }
58
69
  }
59
70
  }
60
71
  }
61
72
  }
62
73
  return {
63
- name: "tamagui-extract",
64
- enforce: "pre",
74
+ name: 'tamagui-extract',
75
+ enforce: 'pre',
65
76
  configureServer(_server) {
66
- server = _server;
77
+ server = _server
67
78
  },
68
79
  async buildStart() {
69
- await loadTamaguiBuildConfig(optionsIn);
80
+ await loadTamaguiBuildConfig(optionsIn)
70
81
  },
71
82
  async closeBundle() {
72
- await Static?.destroyPool();
83
+ await Static?.destroyPool()
73
84
  },
74
85
  config(userConf) {
75
- var _userConf, _userConf_optimizeDeps;
76
- (_userConf = userConf).optimizeDeps || (_userConf.optimizeDeps = {}), (_userConf_optimizeDeps = userConf.optimizeDeps).include || (_userConf_optimizeDeps.include = []), userConf.optimizeDeps.include.push("@tamagui/core/inject-styles");
86
+ var _userConf, _userConf_optimizeDeps
87
+ ;(_userConf = userConf).optimizeDeps || (_userConf.optimizeDeps = {}),
88
+ (_userConf_optimizeDeps = userConf.optimizeDeps).include ||
89
+ (_userConf_optimizeDeps.include = []),
90
+ userConf.optimizeDeps.include.push('@tamagui/core/inject-styles')
77
91
  },
78
92
  async configResolved(resolvedConfig) {
79
- config = resolvedConfig;
93
+ config = resolvedConfig
80
94
  },
81
95
  async resolveId(source) {
82
- if (!isVite6Native(this.environment) && !(!(tamaguiOptions === null || tamaguiOptions === void 0) && tamaguiOptions.disableServerOptimization && isVite6AndNotClient(this.environment))) {
83
- var [validId, query] = source.split("?");
96
+ if (
97
+ !isVite6Native(this.environment) &&
98
+ !(
99
+ !(tamaguiOptions === null || tamaguiOptions === void 0) &&
100
+ tamaguiOptions.disableServerOptimization &&
101
+ isVite6AndNotClient(this.environment)
102
+ )
103
+ ) {
104
+ var [validId, query] = source.split('?')
84
105
  if (validId.endsWith(virtualExt)) {
85
- var absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
86
- if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : "");
106
+ var absoluteId = source.startsWith(config.root)
107
+ ? source
108
+ : getAbsoluteVirtualFileId(validId)
109
+ if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : '')
87
110
  }
88
111
  }
89
112
  },
90
113
  /**
91
- * TODO
92
- *
93
- * mainFields module:jsx breaks, so lets just have a mapping here
94
- * where we load() and map it to the jsx path before transform
95
- *
96
- */
114
+ * TODO
115
+ *
116
+ * mainFields module:jsx breaks, so lets just have a mapping here
117
+ * where we load() and map it to the jsx path before transform
118
+ *
119
+ */
97
120
  async load(id) {
98
- if (!disableStatic && !isVite6Native(this.environment) && !(!(tamaguiOptions === null || tamaguiOptions === void 0) && tamaguiOptions.disableServerOptimization && isVite6AndNotClient(this.environment))) {
99
- var [validId] = id.split("?");
100
- return cssMap.get(validId);
121
+ if (
122
+ !disableStatic &&
123
+ !isVite6Native(this.environment) &&
124
+ !(
125
+ !(tamaguiOptions === null || tamaguiOptions === void 0) &&
126
+ tamaguiOptions.disableServerOptimization &&
127
+ isVite6AndNotClient(this.environment)
128
+ )
129
+ ) {
130
+ var [validId] = id.split('?')
131
+ return cssMap.get(validId)
101
132
  }
102
133
  },
103
134
  transform: {
104
- order: "pre",
135
+ order: 'pre',
105
136
  async handler(code, id) {
106
- if (!disableStatic && !isVite6Native(this.environment) && !(!(tamaguiOptions === null || tamaguiOptions === void 0) && tamaguiOptions.disableServerOptimization && isVite6AndNotClient(this.environment))) {
107
- var [validId] = id.split("?");
108
- if (validId.endsWith(".tsx")) {
109
- var firstCommentIndex = code.indexOf("// "),
110
- {
111
- shouldDisable,
112
- shouldPrintDebug
113
- } = await getPragmaOptions({
114
- source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : "",
115
- path: validId
116
- });
137
+ if (
138
+ !disableStatic &&
139
+ !isVite6Native(this.environment) &&
140
+ !(
141
+ !(tamaguiOptions === null || tamaguiOptions === void 0) &&
142
+ tamaguiOptions.disableServerOptimization &&
143
+ isVite6AndNotClient(this.environment)
144
+ )
145
+ ) {
146
+ var [validId] = id.split('?')
147
+ if (validId.endsWith('.tsx')) {
148
+ var firstCommentIndex = code.indexOf('// '),
149
+ { shouldDisable, shouldPrintDebug } = await getPragmaOptions({
150
+ source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : '',
151
+ path: validId,
152
+ })
117
153
  if (shouldPrintDebug) {
118
- var _this_environment;
119
- console.trace(`Current file: ${id} in environment: ${(_this_environment = this.environment) === null || _this_environment === void 0 ? void 0 : _this_environment.name}, shouldDisable: ${shouldDisable}`), console.info(`
154
+ var _this_environment
155
+ console.trace(
156
+ `Current file: ${id} in environment: ${(_this_environment = this.environment) === null || _this_environment === void 0 ? void 0 : _this_environment.name}, shouldDisable: ${shouldDisable}`
157
+ ),
158
+ console.info(`
120
159
 
121
160
  Original source:
122
161
  ${code}
123
162
 
124
- `);
163
+ `)
125
164
  }
126
165
  if (!shouldDisable) {
127
- var cacheEnv = this.environment.name === "client" || this.environment.name === "ssr" ?
128
- // same cache key for ssr and web since they are the same
129
- "web" : this.environment.name,
166
+ var cacheEnv =
167
+ this.environment.name === 'client' || this.environment.name === 'ssr'
168
+ ? // same cache key for ssr and web since they are the same
169
+ 'web'
170
+ : this.environment.name,
130
171
  cacheKey = getHash(`${cacheEnv}${code}${id}`),
131
- cached = memoryCache[cacheKey];
132
- if (cached) return cached;
133
- var extracted;
172
+ cached = memoryCache[cacheKey]
173
+ if (cached) return cached
174
+ var extracted
134
175
  try {
135
176
  extracted = await Static.extractToClassNames({
136
177
  source: code,
137
178
  sourcePath: validId,
138
179
  options: tamaguiOptions,
139
- shouldPrintDebug
140
- });
180
+ shouldPrintDebug,
181
+ })
141
182
  } catch (err) {
142
- console.error(_instanceof(err, Error) ? err.message : String(err));
143
- return;
183
+ console.error(_instanceof(err, Error) ? err.message : String(err))
184
+ return
144
185
  }
145
186
  if (extracted) {
146
187
  var rootRelativeId = `${validId}${virtualExt}`,
147
188
  absoluteId = getAbsoluteVirtualFileId(rootRelativeId),
148
- source = extracted.js;
149
- extracted.styles && (this.addWatchFile(rootRelativeId), server && cssMap.has(absoluteId) && invalidateModule(rootRelativeId), source = `${source}
150
- import "${rootRelativeId}";`, cssMap.set(absoluteId, extracted.styles));
189
+ source = extracted.js
190
+ extracted.styles &&
191
+ (this.addWatchFile(rootRelativeId),
192
+ server && cssMap.has(absoluteId) && invalidateModule(rootRelativeId),
193
+ (source = `${source}
194
+ import "${rootRelativeId}";`),
195
+ cssMap.set(absoluteId, extracted.styles))
151
196
  var codeOut = source.toString(),
152
197
  out = {
153
198
  code: codeOut,
154
- map: extracted.map
155
- };
156
- return cacheSize += codeOut.length, cacheSize > 26214400 && clearCompilerCache(), memoryCache[cacheKey] = out, out;
199
+ map: extracted.map,
200
+ }
201
+ return (
202
+ (cacheSize += codeOut.length),
203
+ cacheSize > 26214400 && clearCompilerCache(),
204
+ (memoryCache[cacheKey] = out),
205
+ out
206
+ )
157
207
  }
158
208
  }
159
209
  }
160
210
  }
161
- }
162
- }
163
- };
211
+ },
212
+ },
213
+ }
164
214
  }
165
- export { tamaguiExtractPlugin };
215
+ export { tamaguiExtractPlugin }
166
216
  //# sourceMappingURL=extract.native.js.map
@@ -1,3 +1,3 @@
1
- export * from "./plugin.native.js";
2
- export * from "./extract.native.js";
1
+ export * from './plugin.native.js'
2
+ export * from './extract.native.js'
3
3
  //# sourceMappingURL=index.native.js.map
@@ -1,31 +1,36 @@
1
- import * as StaticWorker from "@tamagui/static-worker";
1
+ import * as StaticWorker from '@tamagui/static-worker'
2
2
  var tamaguiOptions = null,
3
3
  disableStatic = !1,
4
4
  watcherDispose = null,
5
- isLoading = null;
5
+ isLoading = null
6
6
  async function loadTamaguiBuildConfig(optionsIn) {
7
7
  if (!tamaguiOptions) {
8
- if (isLoading) return await isLoading;
9
- var resolve;
10
- isLoading = new Promise(function (res) {
11
- resolve = res;
12
- });
8
+ if (isLoading) return await isLoading
9
+ var resolve
10
+ isLoading = new Promise((res) => {
11
+ resolve = res
12
+ })
13
13
  try {
14
- tamaguiOptions = await StaticWorker.loadTamaguiBuildConfig({
14
+ ;(tamaguiOptions = await StaticWorker.loadTamaguiBuildConfig({
15
15
  ...optionsIn,
16
- platform: "web"
17
- }), disableStatic = !!tamaguiOptions.disable, !optionsIn?.disableWatchTamaguiConfig && !disableStatic && (await StaticWorker.loadTamagui({
18
- components: ["tamagui"],
19
- platform: "web",
20
- ...tamaguiOptions
21
- }));
16
+ platform: 'web',
17
+ })),
18
+ (disableStatic = !!tamaguiOptions.disable),
19
+ !optionsIn?.disableWatchTamaguiConfig &&
20
+ !disableStatic &&
21
+ (await StaticWorker.loadTamagui({
22
+ components: ['tamagui'],
23
+ platform: 'web',
24
+ ...tamaguiOptions,
25
+ }))
22
26
  } finally {
23
- resolve(), isLoading = null;
27
+ resolve(), (isLoading = null)
24
28
  }
25
29
  }
26
30
  }
27
31
  async function cleanup() {
28
- watcherDispose && (watcherDispose(), watcherDispose = null), await StaticWorker.destroyPool();
32
+ watcherDispose && (watcherDispose(), (watcherDispose = null)),
33
+ await StaticWorker.destroyPool()
29
34
  }
30
- export { cleanup, disableStatic, loadTamaguiBuildConfig, tamaguiOptions };
35
+ export { cleanup, disableStatic, loadTamaguiBuildConfig, tamaguiOptions }
31
36
  //# sourceMappingURL=loadTamagui.native.js.map