@tamagui/vite-plugin-cjs 2.0.0-1768586279389 → 2.0.0-1768696252732
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.
- package/dist/cjs/extensions.mjs +42 -22
- package/dist/cjs/extensions.native.js +42 -24
- package/dist/cjs/extract.mjs +170 -106
- package/dist/cjs/extract.native.js +192 -121
- package/dist/cjs/index.mjs +28 -17
- package/dist/cjs/index.native.js +28 -19
- package/dist/cjs/loadTamagui.mjs +69 -48
- package/dist/cjs/loadTamagui.native.js +68 -49
- package/dist/cjs/plugin.mjs +211 -157
- package/dist/cjs/plugin.native.js +225 -160
- package/dist/esm/extensions.native.js +13 -2
- package/dist/esm/extract.native.js +139 -89
- package/dist/esm/index.native.js +2 -2
- package/dist/esm/loadTamagui.native.js +22 -17
- package/dist/esm/plugin.native.js +170 -127
- package/package.json +2 -2
|
@@ -1,166 +1,216 @@
|
|
|
1
|
-
import * as Static from
|
|
2
|
-
import { getPragmaOptions } from
|
|
3
|
-
import path from
|
|
4
|
-
import { normalizePath } from
|
|
5
|
-
import {
|
|
6
|
-
|
|
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 <
|
|
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)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 =
|
|
26
|
-
getAbsoluteVirtualFileId =
|
|
27
|
-
|
|
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 !==
|
|
36
|
+
return environment?.name && environment.name !== 'client'
|
|
31
37
|
}
|
|
32
38
|
function isVite6Native(environment) {
|
|
33
|
-
return
|
|
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
|
-
|
|
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 (
|
|
47
|
-
var
|
|
48
|
-
|
|
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:
|
|
64
|
-
enforce:
|
|
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 = {}),
|
|
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 (
|
|
83
|
-
|
|
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)
|
|
86
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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 (
|
|
99
|
-
|
|
100
|
-
|
|
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:
|
|
135
|
+
order: 'pre',
|
|
105
136
|
async handler(code, id) {
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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(
|
|
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 =
|
|
128
|
-
|
|
129
|
-
|
|
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 &&
|
|
150
|
-
|
|
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
|
|
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
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
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
|
|
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(
|
|
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:
|
|
17
|
-
}),
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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),
|
|
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
|