@tamagui/static-worker 2.0.0-rc.4 → 2.0.0-rc.40
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/index.cjs +169 -109
- package/dist/esm/index.js +143 -73
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/index.mjs +141 -83
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +8 -6
- package/src/index.ts +11 -10
- package/types/index.d.ts +3 -2
- package/types/index.d.ts.map +1 -1
- package/dist/cjs/index.js +0 -224
- package/dist/cjs/index.js.map +0 -6
package/dist/esm/index.mjs
CHANGED
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import Piscina from "piscina";
|
|
3
3
|
const getPragmaOptions = async props => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
const {
|
|
5
|
+
default: Static
|
|
6
|
+
} = await import("@tamagui/static");
|
|
7
|
+
return Static.getPragmaOptions(props);
|
|
8
|
+
};
|
|
9
|
+
const getWorkerPath = () => {
|
|
10
|
+
if (typeof import.meta !== "undefined" && import.meta.url) {
|
|
11
|
+
const workerPath = fileURLToPath(import.meta.resolve("@tamagui/static/worker"));
|
|
12
|
+
return workerPath.replace(/\.mjs$/, ".js");
|
|
13
|
+
}
|
|
14
|
+
return require.resolve("@tamagui/static/worker").replace(/\.mjs$/, ".js");
|
|
15
|
+
};
|
|
16
|
+
const POOL_KEY = "__tamagui_piscina_pool__";
|
|
17
|
+
const CLOSING_KEY = "__tamagui_piscina_closing__";
|
|
18
|
+
const TASK_COUNT_KEY = "__tamagui_piscina_task_count__";
|
|
19
|
+
const RECYCLING_KEY = "__tamagui_piscina_recycling__";
|
|
20
|
+
const MAX_TASKS_BEFORE_RECYCLE = 1e3;
|
|
15
21
|
function getSharedPool() {
|
|
16
22
|
return globalThis[POOL_KEY] ?? null;
|
|
17
23
|
}
|
|
18
24
|
function setSharedPool(pool) {
|
|
25
|
+
;
|
|
19
26
|
globalThis[POOL_KEY] = pool;
|
|
20
27
|
}
|
|
21
28
|
function isClosing() {
|
|
22
|
-
return globalThis[CLOSING_KEY] ===
|
|
29
|
+
return globalThis[CLOSING_KEY] === true;
|
|
23
30
|
}
|
|
24
31
|
function setClosing(value) {
|
|
32
|
+
;
|
|
25
33
|
globalThis[CLOSING_KEY] = value;
|
|
26
34
|
}
|
|
27
35
|
function isRecycling() {
|
|
28
|
-
return globalThis[RECYCLING_KEY] ===
|
|
36
|
+
return globalThis[RECYCLING_KEY] === true;
|
|
29
37
|
}
|
|
30
38
|
function setRecycling(value) {
|
|
39
|
+
;
|
|
31
40
|
globalThis[RECYCLING_KEY] = value;
|
|
32
41
|
}
|
|
33
42
|
function getTaskCount() {
|
|
@@ -35,64 +44,87 @@ function getTaskCount() {
|
|
|
35
44
|
}
|
|
36
45
|
function incrementTaskCount() {
|
|
37
46
|
const count = getTaskCount() + 1;
|
|
38
|
-
|
|
47
|
+
globalThis[TASK_COUNT_KEY] = count;
|
|
48
|
+
return count;
|
|
39
49
|
}
|
|
40
50
|
function resetTaskCount() {
|
|
51
|
+
;
|
|
41
52
|
globalThis[TASK_COUNT_KEY] = 0;
|
|
42
53
|
}
|
|
43
54
|
function createPool() {
|
|
44
55
|
const pool = new Piscina({
|
|
45
56
|
filename: getWorkerPath(),
|
|
46
|
-
//
|
|
47
|
-
minThreads:
|
|
48
|
-
maxThreads:
|
|
57
|
+
// each worker loads and caches config independently
|
|
58
|
+
minThreads: 2,
|
|
59
|
+
maxThreads: 2,
|
|
49
60
|
// Never terminate due to idle - worker stays alive until close() or process exit
|
|
50
61
|
// This prevents "Terminating worker thread" errors from Piscina during idle
|
|
51
62
|
idleTimeout: Number.POSITIVE_INFINITY
|
|
52
63
|
// no resourceLimits - we rely on task-based recycling instead
|
|
53
64
|
// V8 resourceLimits cause "Terminating worker thread" messages when hit
|
|
54
65
|
});
|
|
55
|
-
|
|
56
|
-
isClosing() || isRecycling()
|
|
57
|
-
|
|
66
|
+
pool.on("error", err => {
|
|
67
|
+
if (isClosing() || isRecycling()) return;
|
|
68
|
+
const message = err && typeof err === "object" && "message" in err ? String(err.message) : "";
|
|
69
|
+
if (message.includes("Terminating worker thread")) return;
|
|
70
|
+
console.error("[tamagui] Worker pool error:", err);
|
|
71
|
+
});
|
|
72
|
+
return pool;
|
|
58
73
|
}
|
|
59
74
|
function getPool() {
|
|
60
75
|
let pool = getSharedPool();
|
|
61
|
-
|
|
76
|
+
if (!pool) {
|
|
77
|
+
pool = createPool();
|
|
78
|
+
setSharedPool(pool);
|
|
79
|
+
}
|
|
80
|
+
return pool;
|
|
62
81
|
}
|
|
63
82
|
async function loadTamagui(options) {
|
|
64
|
-
const pool = getPool()
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
const pool = getPool();
|
|
84
|
+
const task = {
|
|
85
|
+
type: "extractToClassNames",
|
|
86
|
+
source: "// dummy",
|
|
87
|
+
sourcePath: "__dummy__.tsx",
|
|
88
|
+
options: {
|
|
89
|
+
components: ["tamagui"],
|
|
90
|
+
...options
|
|
91
|
+
},
|
|
92
|
+
shouldPrintDebug: false
|
|
93
|
+
};
|
|
75
94
|
try {
|
|
76
|
-
|
|
95
|
+
await pool.run(task, {
|
|
77
96
|
name: "runTask"
|
|
78
|
-
})
|
|
79
|
-
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
success: true
|
|
80
100
|
};
|
|
81
101
|
} catch (error) {
|
|
82
|
-
|
|
102
|
+
console.error("[static-worker] Error loading Tamagui config:", error);
|
|
103
|
+
throw error;
|
|
83
104
|
}
|
|
84
105
|
}
|
|
85
106
|
async function recyclePool(options) {
|
|
86
107
|
if (isClosing() || isRecycling()) return;
|
|
87
108
|
const oldPool = getSharedPool();
|
|
88
109
|
if (!oldPool) return;
|
|
89
|
-
setRecycling(
|
|
110
|
+
setRecycling(true);
|
|
90
111
|
const start = Date.now();
|
|
91
112
|
try {
|
|
92
|
-
const originalStderr = process.stderr.write.bind(process.stderr)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
113
|
+
const originalStderr = process.stderr.write.bind(process.stderr);
|
|
114
|
+
const originalStdout = process.stdout.write.bind(process.stdout);
|
|
115
|
+
const filter = (chunk, ...args) => {
|
|
116
|
+
const str = typeof chunk === "string" ? chunk : chunk?.toString?.() || "";
|
|
117
|
+
if (str.includes("Terminating worker thread")) return true;
|
|
118
|
+
return false;
|
|
119
|
+
};
|
|
120
|
+
process.stderr.write = (chunk, ...args) => {
|
|
121
|
+
if (filter(chunk)) return true;
|
|
122
|
+
return originalStderr(chunk, ...args);
|
|
123
|
+
};
|
|
124
|
+
process.stdout.write = (chunk, ...args) => {
|
|
125
|
+
if (filter(chunk)) return true;
|
|
126
|
+
return originalStdout(chunk, ...args);
|
|
127
|
+
};
|
|
96
128
|
const newPool = createPool();
|
|
97
129
|
setSharedPool(newPool);
|
|
98
130
|
const warmupTask = {
|
|
@@ -102,17 +134,22 @@ async function recyclePool(options) {
|
|
|
102
134
|
options: {
|
|
103
135
|
...options,
|
|
104
136
|
// skip the "built config" log on warmup since it's a recycle
|
|
105
|
-
_skipBuildLog:
|
|
137
|
+
_skipBuildLog: true
|
|
106
138
|
},
|
|
107
|
-
shouldPrintDebug:
|
|
139
|
+
shouldPrintDebug: false
|
|
108
140
|
};
|
|
109
141
|
await newPool.run(warmupTask, {
|
|
110
142
|
name: "runTask"
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
|
|
143
|
+
});
|
|
144
|
+
oldPool.removeAllListeners();
|
|
145
|
+
oldPool.destroy().catch(() => {});
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
process.stderr.write = originalStderr;
|
|
148
|
+
process.stdout.write = originalStdout;
|
|
149
|
+
});
|
|
150
|
+
console.log(` \u267B\uFE0F [tamagui] recycled worker pool (${Date.now() - start}ms)`);
|
|
114
151
|
} finally {
|
|
115
|
-
setRecycling(
|
|
152
|
+
setRecycling(false);
|
|
116
153
|
}
|
|
117
154
|
}
|
|
118
155
|
async function loadTamaguiBuildConfig(tamaguiOptions) {
|
|
@@ -126,55 +163,72 @@ async function extractToClassNames(params) {
|
|
|
126
163
|
source,
|
|
127
164
|
sourcePath = "",
|
|
128
165
|
options,
|
|
129
|
-
shouldPrintDebug =
|
|
166
|
+
shouldPrintDebug = false
|
|
130
167
|
} = params;
|
|
131
|
-
if (typeof source
|
|
168
|
+
if (typeof source !== "string") {
|
|
169
|
+
throw new Error("`source` must be a string of javascript");
|
|
170
|
+
}
|
|
132
171
|
const task = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
172
|
+
type: "extractToClassNames",
|
|
173
|
+
source,
|
|
174
|
+
sourcePath,
|
|
175
|
+
options,
|
|
176
|
+
shouldPrintDebug
|
|
177
|
+
};
|
|
178
|
+
const pool = getPool();
|
|
179
|
+
const result = await pool.run(task, {
|
|
180
|
+
name: "runTask"
|
|
181
|
+
});
|
|
142
182
|
if (!result.success) {
|
|
143
|
-
const errorMessage = [`[tamagui-extract] Error processing file: ${sourcePath || "(unknown)"}`,
|
|
144
|
-
${result.stack}` : ""].filter(Boolean).join(
|
|
145
|
-
`);
|
|
183
|
+
const errorMessage = [`[tamagui-extract] Error processing file: ${sourcePath || "(unknown)"}`, ``, result.error, result.stack ? `
|
|
184
|
+
${result.stack}` : ""].filter(Boolean).join("\n");
|
|
146
185
|
throw new Error(errorMessage);
|
|
147
186
|
}
|
|
148
|
-
|
|
187
|
+
const count = incrementTaskCount();
|
|
188
|
+
if (count >= MAX_TASKS_BEFORE_RECYCLE) {
|
|
189
|
+
resetTaskCount();
|
|
190
|
+
recyclePool(options).catch(() => {});
|
|
191
|
+
}
|
|
192
|
+
return result.data;
|
|
149
193
|
}
|
|
150
194
|
async function extractToNative(sourceFileName, sourceCode, options) {
|
|
151
195
|
const task = {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
196
|
+
type: "extractToNative",
|
|
197
|
+
sourceFileName,
|
|
198
|
+
sourceCode,
|
|
199
|
+
options
|
|
200
|
+
};
|
|
201
|
+
const pool = getPool();
|
|
202
|
+
const result = await pool.run(task, {
|
|
203
|
+
name: "runTask"
|
|
204
|
+
});
|
|
160
205
|
if (!result.success) {
|
|
161
|
-
const errorMessage = [`[tamagui-extract] Error processing file: ${sourceFileName || "(unknown)"}`,
|
|
162
|
-
${result.stack}` : ""].filter(Boolean).join(
|
|
163
|
-
`);
|
|
206
|
+
const errorMessage = [`[tamagui-extract] Error processing file: ${sourceFileName || "(unknown)"}`, ``, result.error, result.stack ? `
|
|
207
|
+
${result.stack}` : ""].filter(Boolean).join("\n");
|
|
164
208
|
throw new Error(errorMessage);
|
|
165
209
|
}
|
|
166
|
-
|
|
210
|
+
const count = incrementTaskCount();
|
|
211
|
+
if (count >= MAX_TASKS_BEFORE_RECYCLE) {
|
|
212
|
+
resetTaskCount();
|
|
213
|
+
recyclePool(options).catch(() => {});
|
|
214
|
+
}
|
|
215
|
+
return result.data;
|
|
167
216
|
}
|
|
168
217
|
async function watchTamaguiConfig(options) {
|
|
169
218
|
const {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (!watcher)
|
|
219
|
+
default: Static
|
|
220
|
+
} = await import("@tamagui/static");
|
|
221
|
+
const watcher = await Static.watchTamaguiConfig(options);
|
|
222
|
+
if (!watcher) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
174
225
|
const originalDispose = watcher.dispose;
|
|
175
226
|
return {
|
|
176
227
|
dispose: () => {
|
|
177
|
-
originalDispose()
|
|
228
|
+
originalDispose();
|
|
229
|
+
if (getSharedPool()) {
|
|
230
|
+
clearWorkerCache();
|
|
231
|
+
}
|
|
178
232
|
}
|
|
179
233
|
};
|
|
180
234
|
}
|
|
@@ -191,23 +245,27 @@ async function clearWorkerCache() {
|
|
|
191
245
|
async function destroyPool() {
|
|
192
246
|
const pool = getSharedPool();
|
|
193
247
|
if (pool) {
|
|
194
|
-
setClosing(
|
|
248
|
+
setClosing(true);
|
|
195
249
|
try {
|
|
196
250
|
await pool.close();
|
|
197
251
|
} finally {
|
|
198
|
-
setSharedPool(null)
|
|
252
|
+
setSharedPool(null);
|
|
253
|
+
setClosing(false);
|
|
199
254
|
}
|
|
200
255
|
}
|
|
201
256
|
}
|
|
202
257
|
function getPoolStats() {
|
|
203
258
|
const pool = getSharedPool();
|
|
204
|
-
|
|
259
|
+
if (!pool) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
205
263
|
threads: pool.threads.length,
|
|
206
264
|
queueSize: pool.queueSize,
|
|
207
265
|
completed: pool.completed,
|
|
208
266
|
duration: pool.duration,
|
|
209
267
|
utilization: pool.utilization
|
|
210
|
-
}
|
|
268
|
+
};
|
|
211
269
|
}
|
|
212
270
|
export { clearWorkerCache, destroyPool, extractToClassNames, extractToNative, getPoolStats, getPragmaOptions, loadTamagui, loadTamaguiBuildConfig, watchTamaguiConfig };
|
|
213
271
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["fileURLToPath","Piscina","getPragmaOptions","props","default","Static","getWorkerPath","import","meta","url","resolve","replace","require","POOL_KEY","CLOSING_KEY","TASK_COUNT_KEY","RECYCLING_KEY","MAX_TASKS_BEFORE_RECYCLE","getSharedPool","globalThis","setSharedPool","pool","isClosing","setClosing","value","isRecycling","setRecycling","getTaskCount","incrementTaskCount","count","resetTaskCount","createPool","filename","minThreads","maxThreads","idleTimeout","Number","POSITIVE_INFINITY","on","err","
|
|
1
|
+
{"version":3,"names":["fileURLToPath","Piscina","getPragmaOptions","props","default","Static","getWorkerPath","import","meta","url","workerPath","resolve","replace","require","POOL_KEY","CLOSING_KEY","TASK_COUNT_KEY","RECYCLING_KEY","MAX_TASKS_BEFORE_RECYCLE","getSharedPool","globalThis","setSharedPool","pool","isClosing","setClosing","value","isRecycling","setRecycling","getTaskCount","incrementTaskCount","count","resetTaskCount","createPool","filename","minThreads","maxThreads","idleTimeout","Number","POSITIVE_INFINITY","on","err","message","String","includes","console","error","getPool","loadTamagui","options","task","type","source","sourcePath","components","shouldPrintDebug","run","name","success","recyclePool","oldPool","start","Date","now","originalStderr","process","stderr","write","bind","originalStdout","stdout","filter","chunk","args","str","toString","newPool","warmupTask","_skipBuildLog","removeAllListeners","destroy","catch","setTimeout","log","loadTamaguiBuildConfig","tamaguiOptions","loadTamaguiBuildConfigAsync","extractToClassNames","params","Error","result","errorMessage","stack","Boolean","join","data","extractToNative","sourceFileName","sourceCode","watchTamaguiConfig","watcher","originalDispose","dispose","clearWorkerCache","destroyPool","close","getPoolStats","threads","length","queueSize","completed","duration","utilization"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAWA,SAASA,aAAA,QAAqB;AAC9B,OAAOC,OAAA,MAAa;AAKb,MAAMC,gBAAA,GAAmB,MAAOC,KAAA,IAA4C;EACjF,MAAM;IAAEC,OAAA,EAASC;EAAO,IAAI,MAAM,OAAO,iBAAiB;EAC1D,OAAOA,MAAA,CAAOH,gBAAA,CAAiBC,KAAK;AACtC;AAGA,MAAMG,aAAA,GAAgBA,CAAA,KAAM;EAG1B,IAAI,OAAOC,MAAA,CAAAC,IAAA,KAAgB,eAAeD,MAAA,CAAAC,IAAA,CAAYC,GAAA,EAAK;IACzD,MAAMC,UAAA,GAAaV,aAAA,CAAcO,MAAA,CAAAC,IAAA,CAAYG,OAAA,CAAQ,wBA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|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/static-worker",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.40",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"files": [
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
"./package.json": "./package.json",
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./types/index.d.ts",
|
|
19
|
-
"
|
|
19
|
+
"browser": "./dist/esm/index.mjs",
|
|
20
20
|
"module": "./dist/esm/index.mjs",
|
|
21
|
-
"import": "./dist/esm/index.mjs"
|
|
21
|
+
"import": "./dist/esm/index.mjs",
|
|
22
|
+
"require": "./dist/cjs/index.cjs"
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
25
|
"publishConfig": {
|
|
@@ -30,15 +31,16 @@
|
|
|
30
31
|
"clean": "tamagui-build clean",
|
|
31
32
|
"clean:build": "tamagui-build clean:build",
|
|
32
33
|
"test": "vitest run",
|
|
34
|
+
"test:web": "bun run test",
|
|
33
35
|
"test:watch": "vitest"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@tamagui/static": "2.0.0-rc.
|
|
37
|
-
"@tamagui/types": "2.0.0-rc.
|
|
38
|
+
"@tamagui/static": "2.0.0-rc.40",
|
|
39
|
+
"@tamagui/types": "2.0.0-rc.40",
|
|
38
40
|
"piscina": "^4.7.0"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
|
-
"@tamagui/build": "2.0.0-rc.
|
|
43
|
+
"@tamagui/build": "2.0.0-rc.40",
|
|
42
44
|
"vitest": "4.0.4"
|
|
43
45
|
}
|
|
44
46
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { TamaguiOptions } from '@tamagui/types'
|
|
12
|
-
import { dirname, resolve } from 'node:path'
|
|
13
12
|
import { fileURLToPath } from 'node:url'
|
|
14
13
|
import Piscina from 'piscina'
|
|
15
14
|
|
|
@@ -43,8 +42,9 @@ const RECYCLING_KEY = '__tamagui_piscina_recycling__'
|
|
|
43
42
|
|
|
44
43
|
// recycle worker after this many tasks to prevent RSS bloat from V8 memory fragmentation
|
|
45
44
|
// Node.js worker threads don't release memory properly - see https://github.com/nodejs/node/issues/51868
|
|
46
|
-
//
|
|
47
|
-
|
|
45
|
+
// set high enough that builds (typically 200-400 files) never trigger a recycle,
|
|
46
|
+
// but long-running dev servers still get memory relief eventually
|
|
47
|
+
const MAX_TASKS_BEFORE_RECYCLE = 1000
|
|
48
48
|
|
|
49
49
|
function getSharedPool(): Piscina | null {
|
|
50
50
|
return (globalThis as any)[POOL_KEY] ?? null
|
|
@@ -90,9 +90,9 @@ function resetTaskCount() {
|
|
|
90
90
|
function createPool(): Piscina {
|
|
91
91
|
const pool = new Piscina({
|
|
92
92
|
filename: getWorkerPath(),
|
|
93
|
-
//
|
|
94
|
-
minThreads:
|
|
95
|
-
maxThreads:
|
|
93
|
+
// each worker loads and caches config independently
|
|
94
|
+
minThreads: 2,
|
|
95
|
+
maxThreads: 2,
|
|
96
96
|
// Never terminate due to idle - worker stays alive until close() or process exit
|
|
97
97
|
// This prevents "Terminating worker thread" errors from Piscina during idle
|
|
98
98
|
idleTimeout: Number.POSITIVE_INFINITY,
|
|
@@ -126,14 +126,15 @@ function getPool(): Piscina {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
-
* Load Tamagui configuration in
|
|
130
|
-
*
|
|
129
|
+
* Load Tamagui configuration in worker
|
|
130
|
+
* Sends a warmup task to trigger config loading
|
|
131
|
+
* bundleConfig auto-detects if files exist and skips rebuild
|
|
131
132
|
*/
|
|
132
133
|
export async function loadTamagui(options: Partial<TamaguiOptions>): Promise<any> {
|
|
133
134
|
const pool = getPool()
|
|
134
135
|
|
|
135
|
-
//
|
|
136
|
-
//
|
|
136
|
+
// use extractToClassNames with a dummy request to trigger config loading
|
|
137
|
+
// the worker will cache the config for subsequent requests
|
|
137
138
|
const task = {
|
|
138
139
|
type: 'extractToClassNames',
|
|
139
140
|
source: '// dummy',
|
package/types/index.d.ts
CHANGED
|
@@ -18,8 +18,9 @@ export declare const getPragmaOptions: (props: {
|
|
|
18
18
|
shouldDisable: boolean;
|
|
19
19
|
}>;
|
|
20
20
|
/**
|
|
21
|
-
* Load Tamagui configuration in
|
|
22
|
-
*
|
|
21
|
+
* Load Tamagui configuration in worker
|
|
22
|
+
* Sends a warmup task to trigger config loading
|
|
23
|
+
* bundleConfig auto-detects if files exist and skips rebuild
|
|
23
24
|
*/
|
|
24
25
|
export declare function loadTamagui(options: Partial<TamaguiOptions>): Promise<any>;
|
|
25
26
|
/**
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIpD,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC5E,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,eAAO,MAAM,gBAAgB,GAAU,OAAO;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;;;EAG7E,CAAA;AA2GD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAuBhF;AAsED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,cAAc,EAAE,OAAO,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