@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,27 +1,47 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
1
+ var __defProp = Object.defineProperty
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor
3
+ var __getOwnPropNames = Object.getOwnPropertyNames
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
6
+ for (var name in all)
7
+ __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: !0,
10
+ })
10
11
  },
11
12
  __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
- get: () => from[key],
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- return to;
17
- };
18
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
20
- }), mod);
21
- var extensions_exports = {};
13
+ if ((from && typeof from == 'object') || typeof from == 'function')
14
+ for (let key of __getOwnPropNames(from))
15
+ !__hasOwnProp.call(to, key) &&
16
+ key !== except &&
17
+ __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
20
+ })
21
+ return to
22
+ }
23
+ var __toCommonJS = (mod) =>
24
+ __copyProps(
25
+ __defProp({}, '__esModule', {
26
+ value: !0,
27
+ }),
28
+ mod
29
+ )
30
+ var extensions_exports = {}
22
31
  __export(extensions_exports, {
23
- extensions: () => extensions
24
- });
25
- module.exports = __toCommonJS(extensions_exports);
26
- const extensions = [".ios.js", ".native.js", ".native.ts", ".native.tsx", ".js", ".jsx", ".json", ".ts", ".tsx", ".mjs"];
32
+ extensions: () => extensions,
33
+ })
34
+ module.exports = __toCommonJS(extensions_exports)
35
+ const extensions = [
36
+ '.ios.js',
37
+ '.native.js',
38
+ '.native.ts',
39
+ '.native.tsx',
40
+ '.js',
41
+ '.jsx',
42
+ '.json',
43
+ '.ts',
44
+ '.tsx',
45
+ '.mjs',
46
+ ]
27
47
  //# sourceMappingURL=extensions.mjs.map
@@ -1,29 +1,47 @@
1
- "use strict";
2
-
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
1
+ var __defProp = Object.defineProperty
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor
3
+ var __getOwnPropNames = Object.getOwnPropertyNames
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty
7
5
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
6
+ for (var name in all)
7
+ __defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: !0,
10
+ })
12
11
  },
13
12
  __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, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- return to;
19
- };
20
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: !0
22
- }), mod);
23
- var extensions_exports = {};
13
+ if ((from && typeof from == 'object') || typeof from == 'function')
14
+ for (let key of __getOwnPropNames(from))
15
+ !__hasOwnProp.call(to, key) &&
16
+ key !== except &&
17
+ __defProp(to, key, {
18
+ get: () => from[key],
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
20
+ })
21
+ return to
22
+ }
23
+ var __toCommonJS = (mod) =>
24
+ __copyProps(
25
+ __defProp({}, '__esModule', {
26
+ value: !0,
27
+ }),
28
+ mod
29
+ )
30
+ var extensions_exports = {}
24
31
  __export(extensions_exports, {
25
- extensions: () => extensions
26
- });
27
- module.exports = __toCommonJS(extensions_exports);
28
- var extensions = [".ios.js", ".native.js", ".native.ts", ".native.tsx", ".js", ".jsx", ".json", ".ts", ".tsx", ".mjs"];
32
+ extensions: () => extensions,
33
+ })
34
+ module.exports = __toCommonJS(extensions_exports)
35
+ var extensions = [
36
+ '.ios.js',
37
+ '.native.js',
38
+ '.native.ts',
39
+ '.native.tsx',
40
+ '.js',
41
+ '.jsx',
42
+ '.json',
43
+ '.ts',
44
+ '.tsx',
45
+ '.mjs',
46
+ ]
29
47
  //# sourceMappingURL=extensions.native.js.map
@@ -1,97 +1,132 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
1
+ var __create = Object.create
2
+ var __defProp = Object.defineProperty
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor
4
+ var __getOwnPropNames = Object.getOwnPropertyNames
5
5
  var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ __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
- });
8
+ for (var name in all)
9
+ __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: !0,
12
+ })
12
13
  },
13
14
  __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, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- return to;
19
- };
20
- 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);
32
- var extract_exports = {};
15
+ if ((from && typeof from == 'object') || typeof from == 'function')
16
+ for (let key of __getOwnPropNames(from))
17
+ !__hasOwnProp.call(to, key) &&
18
+ key !== except &&
19
+ __defProp(to, key, {
20
+ get: () => from[key],
21
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
22
+ })
23
+ return to
24
+ }
25
+ var __toESM = (mod, isNodeMode, target) => (
26
+ (target = mod != null ? __create(__getProtoOf(mod)) : {}),
27
+ __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule
33
+ ? __defProp(target, 'default', {
34
+ value: mod,
35
+ enumerable: !0,
36
+ })
37
+ : target,
38
+ mod
39
+ )
40
+ ),
41
+ __toCommonJS = (mod) =>
42
+ __copyProps(
43
+ __defProp({}, '__esModule', {
44
+ value: !0,
45
+ }),
46
+ mod
47
+ )
48
+ var extract_exports = {}
33
49
  __export(extract_exports, {
34
- tamaguiExtractPlugin: () => tamaguiExtractPlugin
35
- });
36
- module.exports = __toCommonJS(extract_exports);
37
- var Static = __toESM(require("@tamagui/static-worker"), 1),
38
- import_static_worker = require("@tamagui/static-worker"),
39
- import_node_path = __toESM(require("node:path"), 1),
40
- import_vite = require("vite"),
41
- import_loadTamagui = require("./loadTamagui.mjs"),
42
- import_node_crypto = require("node:crypto");
50
+ tamaguiExtractPlugin: () => tamaguiExtractPlugin,
51
+ })
52
+ module.exports = __toCommonJS(extract_exports)
53
+ var Static = __toESM(require('@tamagui/static-worker'), 1),
54
+ import_static_worker = require('@tamagui/static-worker'),
55
+ import_node_path = __toESM(require('node:path'), 1),
56
+ import_vite = require('vite'),
57
+ import_loadTamagui = require('./loadTamagui.mjs'),
58
+ import_node_crypto = require('node:crypto')
43
59
  function tamaguiExtractPlugin(optionsIn) {
44
- if (optionsIn?.disable) return {
45
- name: "tamagui-extract"
46
- };
47
- const getHash = input => (0, import_node_crypto.createHash)("sha1").update(input).digest("base64"),
60
+ if (optionsIn?.disable)
61
+ return {
62
+ name: 'tamagui-extract',
63
+ }
64
+ const getHash = (input) =>
65
+ (0, import_node_crypto.createHash)('sha1').update(input).digest('base64'),
48
66
  clearCompilerCache = () => {
49
- memoryCache = {}, cacheSize = 0;
50
- };
67
+ ;(memoryCache = {}), (cacheSize = 0)
68
+ }
51
69
  let memoryCache = {},
52
- cacheSize = 0;
53
- const cssMap = /* @__PURE__ */new Map();
54
- let config, server;
55
- const virtualExt = ".tamagui.css",
56
- getAbsoluteVirtualFileId = filePath => filePath.startsWith(config.root) ? filePath : (0, import_vite.normalizePath)(import_node_path.default.join(config.root, filePath));
70
+ cacheSize = 0
71
+ const cssMap = /* @__PURE__ */ new Map()
72
+ let config, server
73
+ const virtualExt = '.tamagui.css',
74
+ getAbsoluteVirtualFileId = (filePath) =>
75
+ filePath.startsWith(config.root)
76
+ ? filePath
77
+ : (0, import_vite.normalizePath)(
78
+ import_node_path.default.join(config.root, filePath)
79
+ )
57
80
  function isVite6AndNotClient(environment) {
58
- return environment?.name && environment.name !== "client";
81
+ return environment?.name && environment.name !== 'client'
59
82
  }
60
83
  function isVite6Native(environment) {
61
- return environment?.name && (environment.name === "ios" || environment.name === "android");
84
+ return (
85
+ environment?.name && (environment.name === 'ios' || environment.name === 'android')
86
+ )
62
87
  }
63
88
  function invalidateModule(absoluteId) {
64
- if (!server) return;
65
- const {
66
- moduleGraph
67
- } = server,
68
- modules = moduleGraph.getModulesByFile(absoluteId);
69
- if (modules) for (const module2 of modules) moduleGraph.invalidateModule(module2), module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now();
89
+ if (!server) return
90
+ const { moduleGraph } = server,
91
+ modules = moduleGraph.getModulesByFile(absoluteId)
92
+ if (modules)
93
+ for (const module2 of modules)
94
+ moduleGraph.invalidateModule(module2),
95
+ (module2.lastHMRTimestamp = module2.lastInvalidationTimestamp || Date.now())
70
96
  }
71
97
  return {
72
- name: "tamagui-extract",
73
- enforce: "pre",
98
+ name: 'tamagui-extract',
99
+ enforce: 'pre',
74
100
  configureServer(_server) {
75
- server = _server;
101
+ server = _server
76
102
  },
77
103
  async buildStart() {
78
- await (0, import_loadTamagui.loadTamaguiBuildConfig)(optionsIn);
104
+ await (0, import_loadTamagui.loadTamaguiBuildConfig)(optionsIn)
79
105
  },
80
106
  async closeBundle() {
81
- await Static?.destroyPool();
107
+ await Static?.destroyPool()
82
108
  },
83
109
  config(userConf) {
84
- userConf.optimizeDeps ||= {}, userConf.optimizeDeps.include ||= [], userConf.optimizeDeps.include.push("@tamagui/core/inject-styles");
110
+ ;(userConf.optimizeDeps ||= {}),
111
+ (userConf.optimizeDeps.include ||= []),
112
+ userConf.optimizeDeps.include.push('@tamagui/core/inject-styles')
85
113
  },
86
114
  async configResolved(resolvedConfig) {
87
- config = resolvedConfig;
115
+ config = resolvedConfig
88
116
  },
89
117
  async resolveId(source) {
90
- if (isVite6Native(this.environment) || import_loadTamagui.tamaguiOptions?.disableServerOptimization && isVite6AndNotClient(this.environment)) return;
91
- const [validId, query] = source.split("?");
92
- if (!validId.endsWith(virtualExt)) return;
93
- const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
94
- if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : "");
118
+ if (
119
+ isVite6Native(this.environment) ||
120
+ (import_loadTamagui.tamaguiOptions?.disableServerOptimization &&
121
+ isVite6AndNotClient(this.environment))
122
+ )
123
+ return
124
+ const [validId, query] = source.split('?')
125
+ if (!validId.endsWith(virtualExt)) return
126
+ const absoluteId = source.startsWith(config.root)
127
+ ? source
128
+ : getAbsoluteVirtualFileId(validId)
129
+ if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : '')
95
130
  },
96
131
  /**
97
132
  * TODO
@@ -101,62 +136,91 @@ function tamaguiExtractPlugin(optionsIn) {
101
136
  *
102
137
  */
103
138
  async load(id) {
104
- if (import_loadTamagui.disableStatic || isVite6Native(this.environment) || import_loadTamagui.tamaguiOptions?.disableServerOptimization && isVite6AndNotClient(this.environment)) return;
105
- const [validId] = id.split("?");
106
- return cssMap.get(validId);
139
+ if (
140
+ import_loadTamagui.disableStatic ||
141
+ isVite6Native(this.environment) ||
142
+ (import_loadTamagui.tamaguiOptions?.disableServerOptimization &&
143
+ isVite6AndNotClient(this.environment))
144
+ )
145
+ return
146
+ const [validId] = id.split('?')
147
+ return cssMap.get(validId)
107
148
  },
108
149
  transform: {
109
- order: "pre",
150
+ order: 'pre',
110
151
  async handler(code, id) {
111
- if (import_loadTamagui.disableStatic || isVite6Native(this.environment) || import_loadTamagui.tamaguiOptions?.disableServerOptimization && isVite6AndNotClient(this.environment)) return;
112
- const [validId] = id.split("?");
113
- if (!validId.endsWith(".tsx")) return;
114
- const firstCommentIndex = code.indexOf("// "),
115
- {
116
- shouldDisable,
117
- shouldPrintDebug
118
- } = await (0, import_static_worker.getPragmaOptions)({
119
- source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : "",
120
- path: validId
121
- });
122
- if (shouldPrintDebug && (console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`), console.info(`
152
+ if (
153
+ import_loadTamagui.disableStatic ||
154
+ isVite6Native(this.environment) ||
155
+ (import_loadTamagui.tamaguiOptions?.disableServerOptimization &&
156
+ isVite6AndNotClient(this.environment))
157
+ )
158
+ return
159
+ const [validId] = id.split('?')
160
+ if (!validId.endsWith('.tsx')) return
161
+ const firstCommentIndex = code.indexOf('// '),
162
+ { shouldDisable, shouldPrintDebug } = await (0,
163
+ import_static_worker.getPragmaOptions)({
164
+ source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : '',
165
+ path: validId,
166
+ })
167
+ if (
168
+ (shouldPrintDebug &&
169
+ (console.trace(
170
+ `Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`
171
+ ),
172
+ console.info(`
123
173
 
124
174
  Original source:
125
175
  ${code}
126
176
 
127
- `)), shouldDisable) return;
128
- const cacheEnv = this.environment.name === "client" || this.environment.name === "ssr" ?
129
- // same cache key for ssr and web since they are the same
130
- "web" : this.environment.name,
177
+ `)),
178
+ shouldDisable)
179
+ )
180
+ return
181
+ const cacheEnv =
182
+ this.environment.name === 'client' || this.environment.name === 'ssr'
183
+ ? // same cache key for ssr and web since they are the same
184
+ 'web'
185
+ : this.environment.name,
131
186
  cacheKey = getHash(`${cacheEnv}${code}${id}`),
132
- cached = memoryCache[cacheKey];
133
- if (cached) return cached;
134
- let extracted;
187
+ cached = memoryCache[cacheKey]
188
+ if (cached) return cached
189
+ let extracted
135
190
  try {
136
191
  extracted = await Static.extractToClassNames({
137
192
  source: code,
138
193
  sourcePath: validId,
139
194
  options: import_loadTamagui.tamaguiOptions,
140
- shouldPrintDebug
141
- });
195
+ shouldPrintDebug,
196
+ })
142
197
  } catch (err) {
143
- console.error(err instanceof Error ? err.message : String(err));
144
- return;
198
+ console.error(err instanceof Error ? err.message : String(err))
199
+ return
145
200
  }
146
- if (!extracted) return;
201
+ if (!extracted) return
147
202
  const rootRelativeId = `${validId}${virtualExt}`,
148
- absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
149
- let source = extracted.js;
150
- extracted.styles && (this.addWatchFile(rootRelativeId), server && cssMap.has(absoluteId) && invalidateModule(rootRelativeId), source = `${source}
151
- import "${rootRelativeId}";`, cssMap.set(absoluteId, extracted.styles));
203
+ absoluteId = getAbsoluteVirtualFileId(rootRelativeId)
204
+ let source = extracted.js
205
+ extracted.styles &&
206
+ (this.addWatchFile(rootRelativeId),
207
+ server && cssMap.has(absoluteId) && invalidateModule(rootRelativeId),
208
+ (source = `${source}
209
+ import "${rootRelativeId}";`),
210
+ cssMap.set(absoluteId, extracted.styles))
152
211
  const codeOut = source.toString(),
153
212
  out = {
154
213
  code: codeOut,
155
- map: extracted.map
156
- };
157
- return cacheSize += codeOut.length, cacheSize > 26214400 && clearCompilerCache(), memoryCache[cacheKey] = out, out;
158
- }
159
- }
160
- };
214
+ map: extracted.map,
215
+ }
216
+ return (
217
+ (cacheSize += codeOut.length),
218
+ cacheSize > 26214400 && clearCompilerCache(),
219
+ (memoryCache[cacheKey] = out),
220
+ out
221
+ )
222
+ },
223
+ },
224
+ }
161
225
  }
162
226
  //# sourceMappingURL=extract.mjs.map