@tamagui/static-worker 1.136.1-1762552971784
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/index.js +119 -0
- package/dist/index.js.map +6 -0
- package/dist/index.mjs +129 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -0
- package/src/index.ts +229 -0
- package/types/index.d.ts +69 -0
- package/types/index.d.ts.map +1 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import Piscina from "piscina";
|
|
4
|
+
const getPragmaOptions = async (props) => {
|
|
5
|
+
const { default: Static } = await import("@tamagui/static");
|
|
6
|
+
return Static.getPragmaOptions(props);
|
|
7
|
+
}, getWorkerPath = () => {
|
|
8
|
+
if (typeof import.meta < "u" && import.meta.url) {
|
|
9
|
+
const staticPackagePath = fileURLToPath(import.meta.resolve("@tamagui/static"));
|
|
10
|
+
return resolve(dirname(staticPackagePath), "worker.js");
|
|
11
|
+
}
|
|
12
|
+
return resolve(process.cwd(), "node_modules/@tamagui/static/dist/worker.js");
|
|
13
|
+
};
|
|
14
|
+
let piscinaPool = null;
|
|
15
|
+
function getPool() {
|
|
16
|
+
return piscinaPool || (piscinaPool = new Piscina({
|
|
17
|
+
filename: getWorkerPath(),
|
|
18
|
+
// Single worker for state consistency and simpler caching
|
|
19
|
+
minThreads: 1,
|
|
20
|
+
maxThreads: 1,
|
|
21
|
+
idleTimeout: 6e4
|
|
22
|
+
// 60s - keep alive for config watching
|
|
23
|
+
})), piscinaPool;
|
|
24
|
+
}
|
|
25
|
+
async function loadTamagui(options) {
|
|
26
|
+
const pool = getPool(), task = {
|
|
27
|
+
type: "extractToClassNames",
|
|
28
|
+
source: "// dummy",
|
|
29
|
+
sourcePath: "__dummy__.tsx",
|
|
30
|
+
options: {
|
|
31
|
+
components: ["tamagui"],
|
|
32
|
+
...options
|
|
33
|
+
},
|
|
34
|
+
shouldPrintDebug: !1
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
return await pool.run(task, { name: "runTask" }), { success: !0 };
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw console.error("[static-worker] Error loading Tamagui config:", error), error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function extractToClassNames(params) {
|
|
43
|
+
const { source, sourcePath = "", options, shouldPrintDebug = !1 } = params;
|
|
44
|
+
if (typeof source != "string")
|
|
45
|
+
throw new Error("`source` must be a string of javascript");
|
|
46
|
+
const task = {
|
|
47
|
+
type: "extractToClassNames",
|
|
48
|
+
source,
|
|
49
|
+
sourcePath,
|
|
50
|
+
options,
|
|
51
|
+
shouldPrintDebug
|
|
52
|
+
}, result = await getPool().run(task, { name: "runTask" });
|
|
53
|
+
if (!result.success)
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Worker error: ${result.error}${result.stack ? `
|
|
56
|
+
${result.stack}` : ""}`
|
|
57
|
+
);
|
|
58
|
+
return result.data;
|
|
59
|
+
}
|
|
60
|
+
async function extractToNative(sourceFileName, sourceCode, options) {
|
|
61
|
+
const task = {
|
|
62
|
+
type: "extractToNative",
|
|
63
|
+
sourceFileName,
|
|
64
|
+
sourceCode,
|
|
65
|
+
options
|
|
66
|
+
}, result = await getPool().run(task, { name: "runTask" });
|
|
67
|
+
if (!result.success)
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Worker error: ${result.error}${result.stack ? `
|
|
70
|
+
${result.stack}` : ""}`
|
|
71
|
+
);
|
|
72
|
+
return result.data;
|
|
73
|
+
}
|
|
74
|
+
async function watchTamaguiConfig(options) {
|
|
75
|
+
const { default: Static } = await import("@tamagui/static"), watcher = await Static.watchTamaguiConfig(options);
|
|
76
|
+
if (!watcher)
|
|
77
|
+
return;
|
|
78
|
+
const originalDispose = watcher.dispose;
|
|
79
|
+
return {
|
|
80
|
+
dispose: () => {
|
|
81
|
+
originalDispose(), clearWorkerCache().catch((err) => {
|
|
82
|
+
console.error("[static-worker] Error clearing cache:", err);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async function loadTamaguiBuildConfig(tamaguiOptions) {
|
|
88
|
+
const { default: Static } = await import("@tamagui/static");
|
|
89
|
+
return Static.loadTamaguiBuildConfigSync(tamaguiOptions);
|
|
90
|
+
}
|
|
91
|
+
async function clearWorkerCache() {
|
|
92
|
+
if (!piscinaPool) return;
|
|
93
|
+
const task = { type: "clearCache" };
|
|
94
|
+
await piscinaPool.run(task, { name: "runTask" });
|
|
95
|
+
}
|
|
96
|
+
async function destroyPool() {
|
|
97
|
+
piscinaPool && (await piscinaPool.destroy(), piscinaPool = null);
|
|
98
|
+
}
|
|
99
|
+
function getPoolStats() {
|
|
100
|
+
return piscinaPool ? {
|
|
101
|
+
threads: piscinaPool.threads.length,
|
|
102
|
+
queueSize: piscinaPool.queueSize,
|
|
103
|
+
completed: piscinaPool.completed,
|
|
104
|
+
duration: piscinaPool.duration,
|
|
105
|
+
utilization: piscinaPool.utilization
|
|
106
|
+
} : null;
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
clearWorkerCache,
|
|
110
|
+
destroyPool,
|
|
111
|
+
extractToClassNames,
|
|
112
|
+
extractToNative,
|
|
113
|
+
getPoolStats,
|
|
114
|
+
getPragmaOptions,
|
|
115
|
+
loadTamagui,
|
|
116
|
+
loadTamaguiBuildConfig,
|
|
117
|
+
watchTamaguiConfig
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"mappings": "AAWA,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;AAC9B,OAAO,aAAa;AAQb,MAAM,mBAAmB,OAAO,UAGjC;AACJ,QAAM,EAAE,SAAS,OAAO,IAAI,M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AAW,YAAY;AAAA,IACvB,WAAW,YAAY;AAAA,IACvB,UAAU,YAAY;AAAA,IACtB,aAAa,YAAY;AAAA,EAC3B,IARS;AASX;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import Piscina from "piscina";
|
|
4
|
+
const getPragmaOptions = async props => {
|
|
5
|
+
const {
|
|
6
|
+
default: Static
|
|
7
|
+
} = await import("@tamagui/static");
|
|
8
|
+
return Static.getPragmaOptions(props);
|
|
9
|
+
},
|
|
10
|
+
getWorkerPath = () => {
|
|
11
|
+
if (typeof import.meta < "u" && import.meta.url) {
|
|
12
|
+
const staticPackagePath = fileURLToPath(import.meta.resolve("@tamagui/static"));
|
|
13
|
+
return resolve(dirname(staticPackagePath), "worker.js");
|
|
14
|
+
}
|
|
15
|
+
return resolve(process.cwd(), "node_modules/@tamagui/static/dist/worker.js");
|
|
16
|
+
};
|
|
17
|
+
let piscinaPool = null;
|
|
18
|
+
function getPool() {
|
|
19
|
+
return piscinaPool || (piscinaPool = new Piscina({
|
|
20
|
+
filename: getWorkerPath(),
|
|
21
|
+
// Single worker for state consistency and simpler caching
|
|
22
|
+
minThreads: 1,
|
|
23
|
+
maxThreads: 1,
|
|
24
|
+
idleTimeout: 6e4
|
|
25
|
+
// 60s - keep alive for config watching
|
|
26
|
+
})), piscinaPool;
|
|
27
|
+
}
|
|
28
|
+
async function loadTamagui(options) {
|
|
29
|
+
const pool = getPool(),
|
|
30
|
+
task = {
|
|
31
|
+
type: "extractToClassNames",
|
|
32
|
+
source: "// dummy",
|
|
33
|
+
sourcePath: "__dummy__.tsx",
|
|
34
|
+
options: {
|
|
35
|
+
components: ["tamagui"],
|
|
36
|
+
...options
|
|
37
|
+
},
|
|
38
|
+
shouldPrintDebug: !1
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
return await pool.run(task, {
|
|
42
|
+
name: "runTask"
|
|
43
|
+
}), {
|
|
44
|
+
success: !0
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
throw console.error("[static-worker] Error loading Tamagui config:", error), error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function extractToClassNames(params) {
|
|
51
|
+
const {
|
|
52
|
+
source,
|
|
53
|
+
sourcePath = "",
|
|
54
|
+
options,
|
|
55
|
+
shouldPrintDebug = !1
|
|
56
|
+
} = params;
|
|
57
|
+
if (typeof source != "string") throw new Error("`source` must be a string of javascript");
|
|
58
|
+
const task = {
|
|
59
|
+
type: "extractToClassNames",
|
|
60
|
+
source,
|
|
61
|
+
sourcePath,
|
|
62
|
+
options,
|
|
63
|
+
shouldPrintDebug
|
|
64
|
+
},
|
|
65
|
+
result = await getPool().run(task, {
|
|
66
|
+
name: "runTask"
|
|
67
|
+
});
|
|
68
|
+
if (!result.success) throw new Error(`Worker error: ${result.error}${result.stack ? `
|
|
69
|
+
${result.stack}` : ""}`);
|
|
70
|
+
return result.data;
|
|
71
|
+
}
|
|
72
|
+
async function extractToNative(sourceFileName, sourceCode, options) {
|
|
73
|
+
const task = {
|
|
74
|
+
type: "extractToNative",
|
|
75
|
+
sourceFileName,
|
|
76
|
+
sourceCode,
|
|
77
|
+
options
|
|
78
|
+
},
|
|
79
|
+
result = await getPool().run(task, {
|
|
80
|
+
name: "runTask"
|
|
81
|
+
});
|
|
82
|
+
if (!result.success) throw new Error(`Worker error: ${result.error}${result.stack ? `
|
|
83
|
+
${result.stack}` : ""}`);
|
|
84
|
+
return result.data;
|
|
85
|
+
}
|
|
86
|
+
async function watchTamaguiConfig(options) {
|
|
87
|
+
const {
|
|
88
|
+
default: Static
|
|
89
|
+
} = await import("@tamagui/static"),
|
|
90
|
+
watcher = await Static.watchTamaguiConfig(options);
|
|
91
|
+
if (!watcher) return;
|
|
92
|
+
const originalDispose = watcher.dispose;
|
|
93
|
+
return {
|
|
94
|
+
dispose: () => {
|
|
95
|
+
originalDispose(), clearWorkerCache().catch(err => {
|
|
96
|
+
console.error("[static-worker] Error clearing cache:", err);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function loadTamaguiBuildConfig(tamaguiOptions) {
|
|
102
|
+
const {
|
|
103
|
+
default: Static
|
|
104
|
+
} = await import("@tamagui/static");
|
|
105
|
+
return Static.loadTamaguiBuildConfigSync(tamaguiOptions);
|
|
106
|
+
}
|
|
107
|
+
async function clearWorkerCache() {
|
|
108
|
+
if (!piscinaPool) return;
|
|
109
|
+
const task = {
|
|
110
|
+
type: "clearCache"
|
|
111
|
+
};
|
|
112
|
+
await piscinaPool.run(task, {
|
|
113
|
+
name: "runTask"
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async function destroyPool() {
|
|
117
|
+
piscinaPool && (await piscinaPool.destroy(), piscinaPool = null);
|
|
118
|
+
}
|
|
119
|
+
function getPoolStats() {
|
|
120
|
+
return piscinaPool ? {
|
|
121
|
+
threads: piscinaPool.threads.length,
|
|
122
|
+
queueSize: piscinaPool.queueSize,
|
|
123
|
+
completed: piscinaPool.completed,
|
|
124
|
+
duration: piscinaPool.duration,
|
|
125
|
+
utilization: piscinaPool.utilization
|
|
126
|
+
} : null;
|
|
127
|
+
}
|
|
128
|
+
export { clearWorkerCache, destroyPool, extractToClassNames, extractToNative, getPoolStats, getPragmaOptions, loadTamagui, loadTamaguiBuildConfig, watchTamaguiConfig };
|
|
129
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["dirname","resolve","fileURLToPath","Piscina","getPragmaOptions","props","default","Static","getWorkerPath","import","meta","url","staticPackagePath","process","cwd","piscinaPool","getPool","filename","minThreads","maxThreads","idleTimeout","loadTamagui","options","pool","task","type","source","sourcePath","components","shouldPrintDebug","run","name","success","error","console","extractToClassNames","params","Error","result","stack","data","extractToNative","sourceFileName","sourceCode","watchTamaguiConfig","watcher","originalDispose","dispose","clearWorkerCache","catch","err","loadTamaguiBuildConfig","tamaguiOptions","loadTamaguiBuildConfigSync","destroyPool","destroy","getPoolStats","threads","length","queueSize","completed","duration","utilization"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAWA,SAASA,OAAA,EAASC,OAAA,QAAe;AACjC,SAASC,aAAA,QAAqB;AAC9B,OAAOC,OAAA,MAAa;AAQb,MAAMC,gBAAA,GAAmB,MAAOC,KAAA,IAGjC;IACJ,MAAM;MAAEC,OAAA,EAASC;IAAO,IAAI,MAAM,OAAO,iBAAiB;IAC1D,OAAOA,MAAA,CAAOH,gBAAA,CAAiBC,KAAK;EACtC;EAGMG,aAAA,GAAgBA,CAAA,KAAM;IAE1B,IAAI,OAAOC,MAAA,CAAAC,IAAA,GAAgB,OAAeD,MAAA,CAAAC,IAAA,CAAYC,GAAA,EAAK;MAEzD,MAAMC,iBAAA,GAAoBV,aAAA,CAAcO,MAAA,CAAAC,IAAA,CAAYT,OAAA,CAAQ,iBAAiB,CAAC;MAC9E,OAAOA,OAAA,CAAQD,OAAA,CAAQY,iBAAiB,GAAG,WAAW;IACxD;IAGA,OAAOX,OAAA,CAAQY,OAAA,CAAQC,GAAA,CAAI,GAAG,6CAA6C;EAC7E;AAEA,IAAIC,WAAA,GAA8B;AAKlC,SAASC,QAAA,EAAmB;EAC1B,OAAKD,WAAA,KACHA,WAAA,GAAc,IAAIZ,OAAA,CAAQ;IACxBc,QAAA,EAAUT,aAAA,CAAc;IAAA;IAExBU,UAAA,EAAY;IACZC,UAAA,EAAY;IACZC,WAAA,EAAa;IAAA;EACf,CAAC,IAEIL,WAAA;AACT;AAMA,eAAsBM,YAAYC,OAAA,EAAgD;EAChF,MAAMC,IAAA,GAAOP,OAAA,CAAQ;IAIfQ,IAAA,GAAO;MACXC,IAAA,EAAM;MACNC,MAAA,EAAQ;MACRC,UAAA,EAAY;MACZL,OAAA,EAAS;Q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AAY6C,SAAA;IACvBC,QAAA,EAAU9C,WAAA,CAAY8C,QAAA;IACtBC,WAAA,EAAa/C,WAAA,CAAY+C;EAC3B,IARS;AASX","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/static-worker",
|
|
3
|
+
"version": "1.136.1-1762552971784",
|
|
4
|
+
"source": "src/index.ts",
|
|
5
|
+
"types": "./types/index.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"module": "dist",
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"types",
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tamagui-build --skip-native",
|
|
15
|
+
"watch": "tamagui-build --skip-native --watch",
|
|
16
|
+
"clean": "tamagui-build clean",
|
|
17
|
+
"clean:build": "tamagui-build clean:build",
|
|
18
|
+
"lint": "biome check src",
|
|
19
|
+
"lint:fix": "biome check --write src"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./types/index.d.ts",
|
|
25
|
+
"require": "./dist/index.js",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@tamagui/static": "1.136.1-1762552971784",
|
|
35
|
+
"@tamagui/types": "1.136.1-1762552971784",
|
|
36
|
+
"piscina": "^4.7.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@tamagui/build": "1.136.1-1762552971784"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamagui/static-worker
|
|
3
|
+
*
|
|
4
|
+
* Pure worker-based API for Tamagui static extraction.
|
|
5
|
+
* All operations run in a worker thread for better performance and isolation.
|
|
6
|
+
*
|
|
7
|
+
* This package provides a clean async API that wraps @tamagui/static's worker
|
|
8
|
+
* implementation without exposing any sync/legacy APIs.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { TamaguiOptions } from '@tamagui/types'
|
|
12
|
+
import { dirname, resolve } from 'node:path'
|
|
13
|
+
import { fileURLToPath } from 'node:url'
|
|
14
|
+
import Piscina from 'piscina'
|
|
15
|
+
|
|
16
|
+
export type {
|
|
17
|
+
ExtractedResponse,
|
|
18
|
+
TamaguiProjectInfo,
|
|
19
|
+
} from '@tamagui/static'
|
|
20
|
+
export type { TamaguiOptions } from '@tamagui/types'
|
|
21
|
+
|
|
22
|
+
export const getPragmaOptions = async (props: {
|
|
23
|
+
source: string
|
|
24
|
+
path: string
|
|
25
|
+
}) => {
|
|
26
|
+
const { default: Static } = await import('@tamagui/static')
|
|
27
|
+
return Static.getPragmaOptions(props)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Resolve worker path - works for both CJS and ESM
|
|
31
|
+
const getWorkerPath = () => {
|
|
32
|
+
// In ESM
|
|
33
|
+
if (typeof import.meta !== 'undefined' && import.meta.url) {
|
|
34
|
+
// This will need to resolve to the actual worker from static package
|
|
35
|
+
const staticPackagePath = fileURLToPath(import.meta.resolve('@tamagui/static'))
|
|
36
|
+
return resolve(dirname(staticPackagePath), 'worker.js')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Fallback - assume static is installed
|
|
40
|
+
return resolve(process.cwd(), 'node_modules/@tamagui/static/dist/worker.js')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let piscinaPool: Piscina | null = null
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get or create the Piscina worker pool
|
|
47
|
+
*/
|
|
48
|
+
function getPool(): Piscina {
|
|
49
|
+
if (!piscinaPool) {
|
|
50
|
+
piscinaPool = new Piscina({
|
|
51
|
+
filename: getWorkerPath(),
|
|
52
|
+
// Single worker for state consistency and simpler caching
|
|
53
|
+
minThreads: 1,
|
|
54
|
+
maxThreads: 1,
|
|
55
|
+
idleTimeout: 60000, // 60s - keep alive for config watching
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
return piscinaPool
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Load Tamagui configuration in the worker thread
|
|
63
|
+
* This is cached in the worker, so subsequent calls are fast
|
|
64
|
+
*/
|
|
65
|
+
export async function loadTamagui(options: Partial<TamaguiOptions>): Promise<any> {
|
|
66
|
+
const pool = getPool()
|
|
67
|
+
|
|
68
|
+
// Use extractToClassNames with a dummy request to trigger config loading
|
|
69
|
+
// The worker will cache the config for subsequent requests
|
|
70
|
+
const task = {
|
|
71
|
+
type: 'extractToClassNames',
|
|
72
|
+
source: '// dummy',
|
|
73
|
+
sourcePath: '__dummy__.tsx',
|
|
74
|
+
options: {
|
|
75
|
+
components: ['tamagui'],
|
|
76
|
+
...options,
|
|
77
|
+
},
|
|
78
|
+
shouldPrintDebug: false,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
await pool.run(task, { name: 'runTask' })
|
|
83
|
+
return { success: true }
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.error('[static-worker] Error loading Tamagui config:', error)
|
|
86
|
+
throw error
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Extract Tamagui components to className-based CSS for web
|
|
92
|
+
*/
|
|
93
|
+
export async function extractToClassNames(params: {
|
|
94
|
+
source: string | Buffer
|
|
95
|
+
sourcePath?: string
|
|
96
|
+
options: TamaguiOptions
|
|
97
|
+
shouldPrintDebug?: boolean | 'verbose'
|
|
98
|
+
}): Promise<any> {
|
|
99
|
+
const { source, sourcePath = '', options, shouldPrintDebug = false } = params
|
|
100
|
+
|
|
101
|
+
if (typeof source !== 'string') {
|
|
102
|
+
throw new Error('`source` must be a string of javascript')
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const task = {
|
|
106
|
+
type: 'extractToClassNames',
|
|
107
|
+
source,
|
|
108
|
+
sourcePath,
|
|
109
|
+
options,
|
|
110
|
+
shouldPrintDebug,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const pool = getPool()
|
|
114
|
+
const result = (await pool.run(task, { name: 'runTask' })) as any
|
|
115
|
+
|
|
116
|
+
if (!result.success) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`Worker error: ${result.error}${result.stack ? `\n${result.stack}` : ''}`
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return result.data
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Extract Tamagui components to React Native StyleSheet format
|
|
127
|
+
*/
|
|
128
|
+
export async function extractToNative(
|
|
129
|
+
sourceFileName: string,
|
|
130
|
+
sourceCode: string,
|
|
131
|
+
options: TamaguiOptions
|
|
132
|
+
): Promise<any> {
|
|
133
|
+
const task = {
|
|
134
|
+
type: 'extractToNative',
|
|
135
|
+
sourceFileName,
|
|
136
|
+
sourceCode,
|
|
137
|
+
options,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const pool = getPool()
|
|
141
|
+
const result = (await pool.run(task, { name: 'runTask' })) as any
|
|
142
|
+
|
|
143
|
+
if (!result.success) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`Worker error: ${result.error}${result.stack ? `\n${result.stack}` : ''}`
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return result.data
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Watch Tamagui config for changes and reload when it changes
|
|
154
|
+
*/
|
|
155
|
+
export async function watchTamaguiConfig(
|
|
156
|
+
options: TamaguiOptions
|
|
157
|
+
): Promise<{ dispose: () => void } | undefined> {
|
|
158
|
+
// For now, we'll use the static package's watcher directly
|
|
159
|
+
// This could be improved to use worker-based watching
|
|
160
|
+
const { default: Static } = await import('@tamagui/static')
|
|
161
|
+
const watcher = await Static.watchTamaguiConfig(options)
|
|
162
|
+
|
|
163
|
+
if (!watcher) {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Wrap the dispose to also clear worker cache
|
|
168
|
+
const originalDispose = watcher.dispose
|
|
169
|
+
return {
|
|
170
|
+
dispose: () => {
|
|
171
|
+
originalDispose()
|
|
172
|
+
// Clear worker cache when config changes
|
|
173
|
+
clearWorkerCache().catch((err) => {
|
|
174
|
+
console.error('[static-worker] Error clearing cache:', err)
|
|
175
|
+
})
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Load Tamagui build configuration synchronously
|
|
182
|
+
* This is only used for loading tamagui.build.ts config, not the full tamagui config
|
|
183
|
+
*/
|
|
184
|
+
export async function loadTamaguiBuildConfig(
|
|
185
|
+
tamaguiOptions: Partial<TamaguiOptions> | undefined
|
|
186
|
+
): Promise<TamaguiOptions> {
|
|
187
|
+
// Import from static package for this sync operation
|
|
188
|
+
const { default: Static } = await import('@tamagui/static')
|
|
189
|
+
|
|
190
|
+
return Static.loadTamaguiBuildConfigSync(tamaguiOptions)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Clear the worker's config cache
|
|
195
|
+
* Call this when config files change
|
|
196
|
+
*/
|
|
197
|
+
export async function clearWorkerCache(): Promise<void> {
|
|
198
|
+
if (!piscinaPool) return
|
|
199
|
+
|
|
200
|
+
const task = { type: 'clearCache' }
|
|
201
|
+
await piscinaPool.run(task, { name: 'runTask' })
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Clean up the worker pool on exit
|
|
206
|
+
* Should be called when the build process completes
|
|
207
|
+
*/
|
|
208
|
+
export async function destroyPool(): Promise<void> {
|
|
209
|
+
if (piscinaPool) {
|
|
210
|
+
await piscinaPool.destroy()
|
|
211
|
+
piscinaPool = null
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get pool statistics for debugging
|
|
217
|
+
*/
|
|
218
|
+
export function getPoolStats() {
|
|
219
|
+
if (!piscinaPool) {
|
|
220
|
+
return null
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
threads: piscinaPool.threads.length,
|
|
224
|
+
queueSize: piscinaPool.queueSize,
|
|
225
|
+
completed: piscinaPool.completed,
|
|
226
|
+
duration: piscinaPool.duration,
|
|
227
|
+
utilization: piscinaPool.utilization,
|
|
228
|
+
}
|
|
229
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tamagui/static-worker
|
|
3
|
+
*
|
|
4
|
+
* Pure worker-based API for Tamagui static extraction.
|
|
5
|
+
* All operations run in a worker thread for better performance and isolation.
|
|
6
|
+
*
|
|
7
|
+
* This package provides a clean async API that wraps @tamagui/static's worker
|
|
8
|
+
* implementation without exposing any sync/legacy APIs.
|
|
9
|
+
*/
|
|
10
|
+
import type { TamaguiOptions } from '@tamagui/types';
|
|
11
|
+
export type { ExtractedResponse, TamaguiProjectInfo, } from '@tamagui/static';
|
|
12
|
+
export type { TamaguiOptions } from '@tamagui/types';
|
|
13
|
+
export declare const getPragmaOptions: (props: {
|
|
14
|
+
source: string;
|
|
15
|
+
path: string;
|
|
16
|
+
}) => Promise<{
|
|
17
|
+
shouldPrintDebug: boolean | "verbose";
|
|
18
|
+
shouldDisable: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
/**
|
|
21
|
+
* Load Tamagui configuration in the worker thread
|
|
22
|
+
* This is cached in the worker, so subsequent calls are fast
|
|
23
|
+
*/
|
|
24
|
+
export declare function loadTamagui(options: Partial<TamaguiOptions>): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Extract Tamagui components to className-based CSS for web
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractToClassNames(params: {
|
|
29
|
+
source: string | Buffer;
|
|
30
|
+
sourcePath?: string;
|
|
31
|
+
options: TamaguiOptions;
|
|
32
|
+
shouldPrintDebug?: boolean | 'verbose';
|
|
33
|
+
}): Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Extract Tamagui components to React Native StyleSheet format
|
|
36
|
+
*/
|
|
37
|
+
export declare function extractToNative(sourceFileName: string, sourceCode: string, options: TamaguiOptions): Promise<any>;
|
|
38
|
+
/**
|
|
39
|
+
* Watch Tamagui config for changes and reload when it changes
|
|
40
|
+
*/
|
|
41
|
+
export declare function watchTamaguiConfig(options: TamaguiOptions): Promise<{
|
|
42
|
+
dispose: () => void;
|
|
43
|
+
} | undefined>;
|
|
44
|
+
/**
|
|
45
|
+
* Load Tamagui build configuration synchronously
|
|
46
|
+
* This is only used for loading tamagui.build.ts config, not the full tamagui config
|
|
47
|
+
*/
|
|
48
|
+
export declare function loadTamaguiBuildConfig(tamaguiOptions: Partial<TamaguiOptions> | undefined): Promise<TamaguiOptions>;
|
|
49
|
+
/**
|
|
50
|
+
* Clear the worker's config cache
|
|
51
|
+
* Call this when config files change
|
|
52
|
+
*/
|
|
53
|
+
export declare function clearWorkerCache(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Clean up the worker pool on exit
|
|
56
|
+
* Should be called when the build process completes
|
|
57
|
+
*/
|
|
58
|
+
export declare function destroyPool(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Get pool statistics for debugging
|
|
61
|
+
*/
|
|
62
|
+
export declare function getPoolStats(): {
|
|
63
|
+
threads: number;
|
|
64
|
+
queueSize: number;
|
|
65
|
+
completed: number;
|
|
66
|
+
duration: number;
|
|
67
|
+
utilization: number;
|
|
68
|
+
} | null;
|
|
69
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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