@tamagui/vite-plugin 2.0.0-rc.9 → 2.1.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.
- package/dist/cjs/extensions.cjs +12 -10
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/loadTamagui.cjs +58 -39
- package/dist/cjs/plugin.cjs +280 -123
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/loadTamagui.mjs +34 -17
- package/dist/esm/loadTamagui.mjs.map +1 -1
- package/dist/esm/plugin.mjs +249 -94
- package/dist/esm/plugin.mjs.map +1 -1
- package/package.json +11 -13
- package/src/plugin.ts +113 -23
- package/types/plugin.d.ts +2 -2
- package/types/plugin.d.ts.map +1 -1
- package/dist/cjs/cache.cjs +0 -70
- package/dist/cjs/cache.js +0 -63
- package/dist/cjs/cache.js.map +0 -6
- package/dist/cjs/extensions.js +0 -32
- package/dist/cjs/extensions.js.map +0 -6
- package/dist/cjs/extract.cjs +0 -159
- package/dist/cjs/extract.js +0 -148
- package/dist/cjs/extract.js.map +0 -6
- package/dist/cjs/index.js +0 -15
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/loadTamagui.js +0 -75
- package/dist/cjs/loadTamagui.js.map +0 -6
- package/dist/cjs/plugin.js +0 -307
- package/dist/cjs/plugin.js.map +0 -6
- package/dist/esm/cache.js +0 -47
- package/dist/esm/cache.js.map +0 -6
- package/dist/esm/cache.mjs +0 -40
- package/dist/esm/cache.mjs.map +0 -1
- package/dist/esm/extensions.js +0 -16
- package/dist/esm/extensions.js.map +0 -6
- package/dist/esm/extract.js +0 -129
- package/dist/esm/extract.js.map +0 -6
- package/dist/esm/extract.mjs +0 -125
- package/dist/esm/extract.mjs.map +0 -1
- package/dist/esm/loadTamagui.js +0 -51
- package/dist/esm/loadTamagui.js.map +0 -6
- package/dist/esm/plugin.js +0 -294
- package/dist/esm/plugin.js.map +0 -6
- package/types/cache.d.ts +0 -50
- package/types/cache.d.ts.map +0 -1
- package/types/extract.d.ts.map +0 -1
package/src/plugin.ts
CHANGED
|
@@ -2,10 +2,11 @@ import type { TamaguiOptions, ExtractedResponse } from '@tamagui/static-worker'
|
|
|
2
2
|
import * as Static from '@tamagui/static-worker'
|
|
3
3
|
import { getPragmaOptions } from '@tamagui/static-worker'
|
|
4
4
|
import { createHash } from 'node:crypto'
|
|
5
|
+
import { createRequire } from 'node:module'
|
|
5
6
|
import path from 'node:path'
|
|
6
7
|
import { fileURLToPath } from 'node:url'
|
|
7
|
-
import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
|
|
8
|
-
import {
|
|
8
|
+
import type { Plugin, PluginOption, ResolvedConfig, ViteDevServer } from 'vite'
|
|
9
|
+
import type { Environment } from 'vite'
|
|
9
10
|
import {
|
|
10
11
|
loadTamaguiBuildConfig,
|
|
11
12
|
getLoadPromise,
|
|
@@ -13,7 +14,12 @@ import {
|
|
|
13
14
|
ensureFullConfigLoaded,
|
|
14
15
|
} from './loadTamagui'
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
// handle ESM/CJS duality for plugin dependencies - resolve from plugin's location, not user's project
|
|
18
|
+
const _pluginRequire = createRequire(
|
|
19
|
+
typeof __filename === 'string' ? __filename : fileURLToPath(import.meta.url)
|
|
20
|
+
)
|
|
21
|
+
const resolve = (name: string) => _pluginRequire.resolve(name)
|
|
22
|
+
const normalizePath = (value: string) => value.replace(/\\/g, '/')
|
|
17
23
|
|
|
18
24
|
// shared cache across all plugin instances/environments via globalThis
|
|
19
25
|
type CacheEntry = {
|
|
@@ -46,6 +52,34 @@ function clearSharedCache() {
|
|
|
46
52
|
;(globalThis as any)[CACHE_SIZE_KEY] = 0
|
|
47
53
|
}
|
|
48
54
|
|
|
55
|
+
// resolves package ids against the user's project root (not the plugin's
|
|
56
|
+
// install location). returns true if the id is resolvable, false if the
|
|
57
|
+
// dep isn't installed, safe to call for optional deps.
|
|
58
|
+
function isInstalled(projectRoot: string, id: string): boolean {
|
|
59
|
+
try {
|
|
60
|
+
const req = createRequire(path.join(projectRoot, 'package.json'))
|
|
61
|
+
req.resolve(id)
|
|
62
|
+
return true
|
|
63
|
+
} catch {
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function addIfInstalled(
|
|
69
|
+
userConf: { optimizeDeps?: { include?: string[] } },
|
|
70
|
+
projectRoot: string | undefined,
|
|
71
|
+
ids: string[]
|
|
72
|
+
): void {
|
|
73
|
+
const root = projectRoot || process.cwd()
|
|
74
|
+
userConf.optimizeDeps ||= {}
|
|
75
|
+
userConf.optimizeDeps.include ||= []
|
|
76
|
+
for (const id of ids) {
|
|
77
|
+
if (!userConf.optimizeDeps.include.includes(id) && isInstalled(root, id)) {
|
|
78
|
+
userConf.optimizeDeps.include.push(id)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
49
83
|
// pending extractions map - dedupes concurrent requests for same file
|
|
50
84
|
function getPendingExtractions(): Map<string, Promise<CacheEntry | null>> {
|
|
51
85
|
if (!(globalThis as any)[PENDING_KEY]) {
|
|
@@ -78,20 +112,23 @@ export function tamaguiAliases(options: AliasOptions = {}): AliasEntry[] {
|
|
|
78
112
|
}
|
|
79
113
|
|
|
80
114
|
if (options.rnwLite) {
|
|
81
|
-
// entry point for main import (may be without-animated variant)
|
|
82
|
-
const rnwl = resolve(
|
|
83
|
-
options.rnwLite === 'without-animated'
|
|
84
|
-
? '@tamagui/react-native-web-lite/without-animated'
|
|
85
|
-
: '@tamagui/react-native-web-lite'
|
|
86
|
-
)
|
|
87
115
|
// base package path for subpath imports (package directory, not entry file)
|
|
88
116
|
const rnwlBase = path.dirname(resolve('@tamagui/react-native-web-lite/package.json'))
|
|
117
|
+
// vite aliases need the esm entry; require.resolve points at cjs.
|
|
118
|
+
const rnwl = normalizePath(
|
|
119
|
+
path.join(
|
|
120
|
+
rnwlBase,
|
|
121
|
+
options.rnwLite === 'without-animated'
|
|
122
|
+
? 'dist/esm/without-animated.mjs'
|
|
123
|
+
: 'dist/esm/index.mjs'
|
|
124
|
+
)
|
|
125
|
+
)
|
|
89
126
|
aliases.push(
|
|
90
127
|
{
|
|
91
128
|
// map deep RNW paths like dist/exports/StyleSheet/preprocess to rnw-lite's flat structure
|
|
92
129
|
// extracts the final path segment (e.g. "preprocess" or "createReactDOMStyle")
|
|
93
130
|
find: /^react-native(?:-web)?\/dist\/(?:exports|modules)\/.*\/([^/]+)$/,
|
|
94
|
-
replacement: `${rnwlBase}/dist/esm/$1.mjs`,
|
|
131
|
+
replacement: `${normalizePath(rnwlBase)}/dist/esm/$1.mjs`,
|
|
95
132
|
},
|
|
96
133
|
{
|
|
97
134
|
find: /^react-native$/,
|
|
@@ -118,12 +155,14 @@ export function tamaguiAliases(options: AliasOptions = {}): AliasEntry[] {
|
|
|
118
155
|
export function tamaguiPlugin({
|
|
119
156
|
disableResolveConfig,
|
|
120
157
|
...tamaguiOptionsIn
|
|
121
|
-
}: TamaguiOptions & {
|
|
158
|
+
}: TamaguiOptions & {
|
|
159
|
+
disableResolveConfig?: boolean
|
|
160
|
+
} = {}): PluginOption {
|
|
122
161
|
// extraction ON by default, set disableExtraction: true to opt out
|
|
123
162
|
let shouldExtract = !tamaguiOptionsIn.disableExtraction
|
|
124
163
|
let watcher: Promise<{ dispose: () => void } | void | undefined> | undefined
|
|
125
164
|
|
|
126
|
-
//
|
|
165
|
+
// temporary vxrn native env bridge
|
|
127
166
|
const enableNativeEnv = !!globalThis.__vxrnEnableNativeEnv
|
|
128
167
|
|
|
129
168
|
const extensions = [
|
|
@@ -212,15 +251,6 @@ export function tamaguiPlugin({
|
|
|
212
251
|
})
|
|
213
252
|
},
|
|
214
253
|
|
|
215
|
-
async transform(code, id) {
|
|
216
|
-
if (id.includes('expo-linear-gradient')) {
|
|
217
|
-
return transformWithEsbuild(code, id, {
|
|
218
|
-
loader: 'jsx',
|
|
219
|
-
jsx: 'automatic',
|
|
220
|
-
})
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
|
|
224
254
|
async config(_, env) {
|
|
225
255
|
const options = await ensureLoaded()
|
|
226
256
|
|
|
@@ -299,10 +329,26 @@ export function tamaguiPlugin({
|
|
|
299
329
|
return {}
|
|
300
330
|
}
|
|
301
331
|
|
|
332
|
+
// react-native-web-lite imports memoize-one internally. the esbuild dep
|
|
333
|
+
// scanner doesn't follow it through the react-native -> rnw-lite alias, so
|
|
334
|
+
// vite discovers it only at request time, re-optimizes mid-load, and full
|
|
335
|
+
// reloads. on slow runners (CI) the in-flight optimized-dep request 504s
|
|
336
|
+
// ("Outdated Optimize Dep") and surfaces as a console error. pre-include
|
|
337
|
+
// it so the first optimize pass is complete and no reload is triggered.
|
|
338
|
+
const include: string[] = []
|
|
339
|
+
if (isInstalled(process.cwd(), 'memoize-one')) {
|
|
340
|
+
include.push('memoize-one')
|
|
341
|
+
}
|
|
342
|
+
|
|
302
343
|
return {
|
|
303
344
|
resolve: {
|
|
304
345
|
alias: tamaguiAliases({ rnwLite: options.useReactNativeWebLite }),
|
|
305
346
|
},
|
|
347
|
+
optimizeDeps: {
|
|
348
|
+
// upstream react-native-web must not be pre-bundled when aliased to lite
|
|
349
|
+
exclude: ['react-native-web'],
|
|
350
|
+
include,
|
|
351
|
+
},
|
|
306
352
|
}
|
|
307
353
|
},
|
|
308
354
|
}
|
|
@@ -315,11 +361,55 @@ export function tamaguiPlugin({
|
|
|
315
361
|
|
|
316
362
|
async config(userConf) {
|
|
317
363
|
// wait for config to load to know if we should extract
|
|
318
|
-
await ensureLoaded()
|
|
319
|
-
if (!shouldExtract) return
|
|
364
|
+
const options = await ensureLoaded()
|
|
320
365
|
|
|
321
366
|
userConf.optimizeDeps ||= {}
|
|
322
367
|
userConf.optimizeDeps.include ||= []
|
|
368
|
+
|
|
369
|
+
// inline-style-prefixer is CJS with __esModule and breaks without pre-bundling
|
|
370
|
+
// (reference error: exports is not defined). always include it.
|
|
371
|
+
userConf.optimizeDeps.include.push('inline-style-prefixer')
|
|
372
|
+
|
|
373
|
+
// pre-bundle tamagui packages that use internal hooks (useThemeName, etc.)
|
|
374
|
+
// from sub-entries, vite's dep crawler can otherwise split them into a
|
|
375
|
+
// separate chunk with its own tamagui copy, producing two ThemeStateContext
|
|
376
|
+
// instances and "Missing theme" errors at runtime.
|
|
377
|
+
//
|
|
378
|
+
// @tamagui/sheet/controller is the lightweight controller subpath imported
|
|
379
|
+
// by popover/dialog/select; the app imports @tamagui/sheet (full). if these
|
|
380
|
+
// land in separate optimized chunks they each get their own copy of
|
|
381
|
+
// SheetControllerContext, so the SheetController provider (from /controller)
|
|
382
|
+
// and the Sheet consumer (from the full entry) never match and adapted
|
|
383
|
+
// sheets silently never open. include both so they share one context chunk.
|
|
384
|
+
addIfInstalled(userConf, userConf.root, [
|
|
385
|
+
'@tamagui/toast',
|
|
386
|
+
'@tamagui/toast/v2',
|
|
387
|
+
'@tamagui/sheet',
|
|
388
|
+
'@tamagui/sheet/controller',
|
|
389
|
+
])
|
|
390
|
+
|
|
391
|
+
// dedupe tamagui packages so nested resolutions collapse to a single
|
|
392
|
+
// instance. pairs with the include above: include pre-bundles, dedupe
|
|
393
|
+
// prevents duplicate bundling when sub-deps re-resolve them.
|
|
394
|
+
userConf.resolve ||= {}
|
|
395
|
+
userConf.resolve.dedupe ||= []
|
|
396
|
+
for (const id of [
|
|
397
|
+
'tamagui',
|
|
398
|
+
'@tamagui/core',
|
|
399
|
+
'@tamagui/web',
|
|
400
|
+
'@tamagui/toast',
|
|
401
|
+
'@tamagui/sheet',
|
|
402
|
+
]) {
|
|
403
|
+
if (
|
|
404
|
+
!userConf.resolve.dedupe.includes(id) &&
|
|
405
|
+
isInstalled(userConf.root || process.cwd(), id)
|
|
406
|
+
) {
|
|
407
|
+
userConf.resolve.dedupe.push(id)
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (!shouldExtract) return
|
|
412
|
+
|
|
323
413
|
userConf.optimizeDeps.include.push('@tamagui/core/inject-styles')
|
|
324
414
|
},
|
|
325
415
|
|
package/types/plugin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TamaguiOptions } from '@tamagui/static-worker';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PluginOption } from 'vite';
|
|
3
3
|
type AliasOptions = {
|
|
4
4
|
/** use @tamagui/react-native-web-lite, 'without-animated' for smaller bundle */
|
|
5
5
|
rnwLite?: boolean | 'without-animated';
|
|
@@ -17,6 +17,6 @@ type AliasEntry = {
|
|
|
17
17
|
export declare function tamaguiAliases(options?: AliasOptions): AliasEntry[];
|
|
18
18
|
export declare function tamaguiPlugin({ disableResolveConfig, ...tamaguiOptionsIn }?: TamaguiOptions & {
|
|
19
19
|
disableResolveConfig?: boolean;
|
|
20
|
-
}):
|
|
20
|
+
}): PluginOption;
|
|
21
21
|
export {};
|
|
22
22
|
//# sourceMappingURL=plugin.d.ts.map
|
package/types/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,wBAAwB,CAAA;AAO/E,OAAO,KAAK,EAAU,YAAY,EAAiC,MAAM,MAAM,CAAA;AAmF/E,KAAK,YAAY,GAAG;IAClB,gFAAgF;IAChF,OAAO,CAAC,EAAE,OAAO,GAAG,kBAAkB,CAAA;IACtC,0DAA0D;IAC1D,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAED,KAAK,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAA;AAEhE;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,YAAiB,GAAG,UAAU,EAAE,CAiDvE;AAED,wBAAgB,aAAa,CAAC,EAC5B,oBAAoB,EACpB,GAAG,gBAAgB,EACpB,GAAE,cAAc,GAAG;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC1B,GAAG,YAAY,CAiepB"}
|
package/dist/cjs/cache.cjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all) __defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: !0
|
|
9
|
-
});
|
|
10
|
-
},
|
|
11
|
-
__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 cache_exports = {};
|
|
22
|
-
__export(cache_exports, {
|
|
23
|
-
clearCache: () => clearCache,
|
|
24
|
-
clearPendingExtraction: () => clearPendingExtraction,
|
|
25
|
-
getCache: () => getCache,
|
|
26
|
-
getCached: () => getCached,
|
|
27
|
-
getPending: () => getPending,
|
|
28
|
-
getPendingExtraction: () => getPendingExtraction,
|
|
29
|
-
setCache: () => setCache,
|
|
30
|
-
setPendingExtraction: () => setPendingExtraction
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(cache_exports);
|
|
33
|
-
const KEYS = {
|
|
34
|
-
cache: "__tamagui_vite_cache__",
|
|
35
|
-
size: "__tamagui_vite_cache_size__",
|
|
36
|
-
pending: "__tamagui_vite_pending__"
|
|
37
|
-
},
|
|
38
|
-
MAX_CACHE_SIZE = 67108864;
|
|
39
|
-
function getGlobal(key, defaultValue) {
|
|
40
|
-
return globalThis[key] === void 0 && (globalThis[key] = defaultValue), globalThis[key];
|
|
41
|
-
}
|
|
42
|
-
function setGlobal(key, value) {
|
|
43
|
-
globalThis[key] = value;
|
|
44
|
-
}
|
|
45
|
-
function getCache() {
|
|
46
|
-
return getGlobal(KEYS.cache, {});
|
|
47
|
-
}
|
|
48
|
-
function getCached(key) {
|
|
49
|
-
return getCache()[key];
|
|
50
|
-
}
|
|
51
|
-
function setCache(key, entry) {
|
|
52
|
-
const cache = getCache(),
|
|
53
|
-
newSize = getGlobal(KEYS.size, 0) + entry.js.length;
|
|
54
|
-
newSize > MAX_CACHE_SIZE ? clearCache() : setGlobal(KEYS.size, newSize), cache[key] = entry;
|
|
55
|
-
}
|
|
56
|
-
function clearCache() {
|
|
57
|
-
setGlobal(KEYS.cache, {}), setGlobal(KEYS.size, 0);
|
|
58
|
-
}
|
|
59
|
-
function getPending() {
|
|
60
|
-
return getGlobal(KEYS.pending, /* @__PURE__ */new Map());
|
|
61
|
-
}
|
|
62
|
-
function getPendingExtraction(key) {
|
|
63
|
-
return getPending().get(key);
|
|
64
|
-
}
|
|
65
|
-
function setPendingExtraction(key, promise) {
|
|
66
|
-
getPending().set(key, promise);
|
|
67
|
-
}
|
|
68
|
-
function clearPendingExtraction(key) {
|
|
69
|
-
getPending().delete(key);
|
|
70
|
-
}
|
package/dist/cjs/cache.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var cache_exports = {};
|
|
16
|
-
__export(cache_exports, {
|
|
17
|
-
clearCache: () => clearCache,
|
|
18
|
-
clearPendingExtraction: () => clearPendingExtraction,
|
|
19
|
-
getCache: () => getCache,
|
|
20
|
-
getCached: () => getCached,
|
|
21
|
-
getPending: () => getPending,
|
|
22
|
-
getPendingExtraction: () => getPendingExtraction,
|
|
23
|
-
setCache: () => setCache,
|
|
24
|
-
setPendingExtraction: () => setPendingExtraction
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(cache_exports);
|
|
27
|
-
const KEYS = {
|
|
28
|
-
cache: "__tamagui_vite_cache__",
|
|
29
|
-
size: "__tamagui_vite_cache_size__",
|
|
30
|
-
pending: "__tamagui_vite_pending__"
|
|
31
|
-
}, MAX_CACHE_SIZE = 67108864;
|
|
32
|
-
function getGlobal(key, defaultValue) {
|
|
33
|
-
return globalThis[key] === void 0 && (globalThis[key] = defaultValue), globalThis[key];
|
|
34
|
-
}
|
|
35
|
-
function setGlobal(key, value) {
|
|
36
|
-
globalThis[key] = value;
|
|
37
|
-
}
|
|
38
|
-
function getCache() {
|
|
39
|
-
return getGlobal(KEYS.cache, {});
|
|
40
|
-
}
|
|
41
|
-
function getCached(key) {
|
|
42
|
-
return getCache()[key];
|
|
43
|
-
}
|
|
44
|
-
function setCache(key, entry) {
|
|
45
|
-
const cache = getCache(), newSize = getGlobal(KEYS.size, 0) + entry.js.length;
|
|
46
|
-
newSize > MAX_CACHE_SIZE ? clearCache() : setGlobal(KEYS.size, newSize), cache[key] = entry;
|
|
47
|
-
}
|
|
48
|
-
function clearCache() {
|
|
49
|
-
setGlobal(KEYS.cache, {}), setGlobal(KEYS.size, 0);
|
|
50
|
-
}
|
|
51
|
-
function getPending() {
|
|
52
|
-
return getGlobal(KEYS.pending, /* @__PURE__ */ new Map());
|
|
53
|
-
}
|
|
54
|
-
function getPendingExtraction(key) {
|
|
55
|
-
return getPending().get(key);
|
|
56
|
-
}
|
|
57
|
-
function setPendingExtraction(key, promise) {
|
|
58
|
-
getPending().set(key, promise);
|
|
59
|
-
}
|
|
60
|
-
function clearPendingExtraction(key) {
|
|
61
|
-
getPending().delete(key);
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=cache.js.map
|
package/dist/cjs/cache.js.map
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/cache.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBA,MAAM,OAAO;AAAA,EACX,OAAO;AAAA,EACP,MAAM;AAAA,EACN,SAAS;AACX,GAGM,iBAAiB;AAEvB,SAAS,UAAa,KAAa,cAAoB;AACrD,SAAK,WAAmB,GAAG,MAAM,WAC7B,WAAmB,GAAG,IAAI,eAEtB,WAAmB,GAAG;AAChC;AAEA,SAAS,UAAa,KAAa,OAAgB;AAChD,EAAC,WAAmB,GAAG,IAAI;AAC9B;AAKO,SAAS,WAAuC;AACrD,SAAO,UAAU,KAAK,OAAO,CAAC,CAAC;AACjC;AAKO,SAAS,UAAU,KAAqC;AAC7D,SAAO,SAAS,EAAE,GAAG;AACvB;AAMO,SAAS,SAAS,KAAa,OAAyB;AAC7D,QAAM,QAAQ,SAAS,GAEjB,UADc,UAAkB,KAAK,MAAM,CAAC,IACpB,MAAM,GAAG;AAEvC,EAAI,UAAU,iBACZ,WAAW,IAEX,UAAU,KAAK,MAAM,OAAO,GAG9B,MAAM,GAAG,IAAI;AACf;AAKO,SAAS,aAAmB;AACjC,YAAU,KAAK,OAAO,CAAC,CAAC,GACxB,UAAU,KAAK,MAAM,CAAC;AACxB;AAMO,SAAS,aAAsD;AACpE,SAAO,UAAU,KAAK,SAAS,oBAAI,IAAI,CAAC;AAC1C;AAKO,SAAS,qBACd,KACwC;AACxC,SAAO,WAAW,EAAE,IAAI,GAAG;AAC7B;AAKO,SAAS,qBACd,KACA,SACM;AACN,aAAW,EAAE,IAAI,KAAK,OAAO;AAC/B;AAKO,SAAS,uBAAuB,KAAmB;AACxD,aAAW,EAAE,OAAO,GAAG;AACzB;",
|
|
5
|
-
"names": []
|
|
6
|
-
}
|
package/dist/cjs/extensions.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var extensions_exports = {};
|
|
16
|
-
__export(extensions_exports, {
|
|
17
|
-
extensions: () => extensions
|
|
18
|
-
});
|
|
19
|
-
module.exports = __toCommonJS(extensions_exports);
|
|
20
|
-
const extensions = [
|
|
21
|
-
".ios.js",
|
|
22
|
-
".native.js",
|
|
23
|
-
".native.ts",
|
|
24
|
-
".native.tsx",
|
|
25
|
-
".js",
|
|
26
|
-
".jsx",
|
|
27
|
-
".json",
|
|
28
|
-
".ts",
|
|
29
|
-
".tsx",
|
|
30
|
-
".mjs"
|
|
31
|
-
];
|
|
32
|
-
//# sourceMappingURL=extensions.js.map
|
package/dist/cjs/extract.cjs
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
-
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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, {
|
|
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 = {};
|
|
33
|
-
__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.cjs"),
|
|
42
|
-
import_node_crypto = require("node:crypto");
|
|
43
|
-
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"),
|
|
48
|
-
clearCompilerCache = () => {
|
|
49
|
-
memoryCache = {}, cacheSize = 0;
|
|
50
|
-
};
|
|
51
|
-
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));
|
|
57
|
-
function isVite6AndNotClient(environment) {
|
|
58
|
-
return environment?.name && environment.name !== "client";
|
|
59
|
-
}
|
|
60
|
-
function isVite6Native(environment) {
|
|
61
|
-
return environment?.name && (environment.name === "ios" || environment.name === "android");
|
|
62
|
-
}
|
|
63
|
-
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();
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
name: "tamagui-extract",
|
|
73
|
-
enforce: "pre",
|
|
74
|
-
configureServer(_server) {
|
|
75
|
-
server = _server;
|
|
76
|
-
},
|
|
77
|
-
async buildStart() {
|
|
78
|
-
await (0, import_loadTamagui.loadTamaguiBuildConfig)(optionsIn);
|
|
79
|
-
},
|
|
80
|
-
async closeBundle() {},
|
|
81
|
-
config(userConf) {
|
|
82
|
-
userConf.optimizeDeps ||= {}, userConf.optimizeDeps.include ||= [], userConf.optimizeDeps.include.push("@tamagui/core/inject-styles");
|
|
83
|
-
},
|
|
84
|
-
async configResolved(resolvedConfig) {
|
|
85
|
-
config = resolvedConfig;
|
|
86
|
-
},
|
|
87
|
-
async resolveId(source) {
|
|
88
|
-
if (isVite6Native(this.environment) || import_loadTamagui.tamaguiOptions?.disableServerOptimization && isVite6AndNotClient(this.environment)) return;
|
|
89
|
-
const [validId, query] = source.split("?");
|
|
90
|
-
if (!validId.endsWith(virtualExt)) return;
|
|
91
|
-
const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(validId);
|
|
92
|
-
if (cssMap.has(absoluteId)) return absoluteId + (query ? `?${query}` : "");
|
|
93
|
-
},
|
|
94
|
-
/**
|
|
95
|
-
* TODO
|
|
96
|
-
*
|
|
97
|
-
* mainFields module:jsx breaks, so lets just have a mapping here
|
|
98
|
-
* where we load() and map it to the jsx path before transform
|
|
99
|
-
*
|
|
100
|
-
*/
|
|
101
|
-
async load(id) {
|
|
102
|
-
if (import_loadTamagui.disableStatic || isVite6Native(this.environment) || import_loadTamagui.tamaguiOptions?.disableServerOptimization && isVite6AndNotClient(this.environment)) return;
|
|
103
|
-
const [validId] = id.split("?");
|
|
104
|
-
return cssMap.get(validId);
|
|
105
|
-
},
|
|
106
|
-
transform: {
|
|
107
|
-
order: "pre",
|
|
108
|
-
async handler(code, id) {
|
|
109
|
-
if (import_loadTamagui.disableStatic || isVite6Native(this.environment) || import_loadTamagui.tamaguiOptions?.disableServerOptimization && isVite6AndNotClient(this.environment)) return;
|
|
110
|
-
const [validId] = id.split("?");
|
|
111
|
-
if (!validId.endsWith(".tsx")) return;
|
|
112
|
-
const firstCommentIndex = code.indexOf("// "),
|
|
113
|
-
{
|
|
114
|
-
shouldDisable,
|
|
115
|
-
shouldPrintDebug
|
|
116
|
-
} = await (0, import_static_worker.getPragmaOptions)({
|
|
117
|
-
source: firstCommentIndex >= 0 ? code.slice(firstCommentIndex) : "",
|
|
118
|
-
path: validId
|
|
119
|
-
});
|
|
120
|
-
if (shouldPrintDebug && (console.trace(`Current file: ${id} in environment: ${this.environment?.name}, shouldDisable: ${shouldDisable}`), console.info(`
|
|
121
|
-
|
|
122
|
-
Original source:
|
|
123
|
-
${code}
|
|
124
|
-
|
|
125
|
-
`)), shouldDisable) return;
|
|
126
|
-
const cacheEnv = this.environment.name === "client" || this.environment.name === "ssr" ?
|
|
127
|
-
// same cache key for ssr and web since they are the same
|
|
128
|
-
"web" : this.environment.name,
|
|
129
|
-
cacheKey = getHash(`${cacheEnv}${code}${id}`),
|
|
130
|
-
cached = memoryCache[cacheKey];
|
|
131
|
-
if (cached) return cached;
|
|
132
|
-
let extracted;
|
|
133
|
-
try {
|
|
134
|
-
extracted = await Static.extractToClassNames({
|
|
135
|
-
source: code,
|
|
136
|
-
sourcePath: validId,
|
|
137
|
-
options: import_loadTamagui.tamaguiOptions,
|
|
138
|
-
shouldPrintDebug
|
|
139
|
-
});
|
|
140
|
-
} catch (err) {
|
|
141
|
-
console.error(err instanceof Error ? err.message : String(err));
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (!extracted) return;
|
|
145
|
-
const rootRelativeId = `${validId}${virtualExt}`,
|
|
146
|
-
absoluteId = getAbsoluteVirtualFileId(rootRelativeId);
|
|
147
|
-
let source = extracted.js;
|
|
148
|
-
extracted.styles && (this.addWatchFile(rootRelativeId), server && cssMap.has(absoluteId) && invalidateModule(rootRelativeId), source = `${source}
|
|
149
|
-
import "${rootRelativeId}";`, cssMap.set(absoluteId, extracted.styles));
|
|
150
|
-
const codeOut = source.toString(),
|
|
151
|
-
out = {
|
|
152
|
-
code: codeOut,
|
|
153
|
-
map: extracted.map
|
|
154
|
-
};
|
|
155
|
-
return cacheSize += codeOut.length, cacheSize > 26214400 && clearCompilerCache(), memoryCache[cacheKey] = out, out;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}
|