@tamagui/generate-themes 2.7.7 → 3.0.0-beta.643.1
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/generate-themes.cjs +146 -135
- package/dist/cjs/generate-themes.native.cjs +225 -0
- package/dist/cjs/generate-themes.native.js +174 -161
- package/dist/cjs/generate-themes.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +22 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/write-generate-themes.cjs +29 -39
- package/dist/cjs/write-generate-themes.native.cjs +49 -0
- package/dist/cjs/write-generate-themes.native.js +31 -40
- package/dist/cjs/write-generate-themes.native.js.map +1 -1
- package/dist/esm/generate-themes.mjs +132 -117
- package/dist/esm/generate-themes.mjs.map +1 -1
- package/dist/esm/generate-themes.native.js +160 -144
- package/dist/esm/generate-themes.native.js.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/index.native.js +3 -3
- package/dist/esm/write-generate-themes.mjs +13 -13
- package/dist/esm/write-generate-themes.mjs.map +1 -1
- package/dist/esm/write-generate-themes.native.js +15 -15
- package/dist/esm/write-generate-themes.native.js.map +1 -1
- package/package.json +6 -6
- package/src/generate-themes.ts +34 -18
- package/types/generate-themes.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
package/src/generate-themes.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Module from 'node:module'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// resolver internals used to purge caches between invocations, absent from
|
|
5
|
+
// @types/node and, in _pathCache's case, from bun. imported rather than read
|
|
6
|
+
// off the ambient `module`, which does not exist when this package is loaded
|
|
7
|
+
// as ESM.
|
|
8
|
+
const ModuleInternals = Module as unknown as {
|
|
9
|
+
_resolveFilename(request: string, ...args: any[]): string
|
|
10
|
+
_pathCache?: Record<string, string>
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
let didRegisterOnce = false
|
|
@@ -12,17 +17,33 @@ export async function generateThemes(inputFile: string) {
|
|
|
12
17
|
|
|
13
18
|
if (!didRegisterOnce) {
|
|
14
19
|
didRegisterOnce = true
|
|
20
|
+
const nodeResolve = ModuleInternals._resolveFilename
|
|
15
21
|
// the unregsiter does basically nothing and keeps a process running
|
|
16
22
|
require('esbuild-register/dist/node').register({
|
|
17
23
|
hookIgnoreNodeModules: false,
|
|
18
24
|
})
|
|
25
|
+
// esbuild-register installs a tsconfig-paths hook that rewrites bare workspace
|
|
26
|
+
// workspace specifiers can resolve to source-tree directories that node cannot load.
|
|
27
|
+
// prefer real node
|
|
28
|
+
// resolution (package exports) for bare specifiers, falling back to the
|
|
29
|
+
// tsconfig-paths chain for packages whose dist isn't built.
|
|
30
|
+
const chained = ModuleInternals._resolveFilename
|
|
31
|
+
ModuleInternals._resolveFilename = function (request: string, ...args: any[]) {
|
|
32
|
+
if (request[0] !== '.' && !request.startsWith('/')) {
|
|
33
|
+
try {
|
|
34
|
+
return nodeResolve.call(this, request, ...args)
|
|
35
|
+
} catch {
|
|
36
|
+
// fall through to the tsconfig-paths chain
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return chained.call(this, request, ...args)
|
|
40
|
+
}
|
|
19
41
|
} else {
|
|
20
42
|
purgeCache(inputFilePath)
|
|
21
43
|
}
|
|
22
44
|
|
|
23
45
|
let og = process.env.TAMAGUI_KEEP_THEMES
|
|
24
46
|
process.env.TAMAGUI_KEEP_THEMES = '1'
|
|
25
|
-
process.env.TAMAGUI_RUN_THEMEBUILDER = '1'
|
|
26
47
|
|
|
27
48
|
try {
|
|
28
49
|
const requiredThemes = require(inputFilePath)
|
|
@@ -44,12 +65,10 @@ export async function generateThemes(inputFile: string) {
|
|
|
44
65
|
}
|
|
45
66
|
}
|
|
46
67
|
|
|
47
|
-
/**
|
|
48
|
-
* value -> name of variable
|
|
49
|
-
*/
|
|
50
|
-
const dedupedTokens = new Map<string, string>()
|
|
51
|
-
|
|
52
68
|
function generatedThemesToTypescript(themes: Record<string, any>) {
|
|
69
|
+
// value -> name of variable. per invocation: a process-wide map would emit
|
|
70
|
+
// the previous run's colors into this run's `colors` array.
|
|
71
|
+
const dedupedTokens = new Map<string, string>()
|
|
53
72
|
const dedupedThemes = new Map<string, object>()
|
|
54
73
|
const dedupedThemeToNames = new Map<string, string[]>()
|
|
55
74
|
|
|
@@ -90,7 +109,7 @@ function generatedThemesToTypescript(themes: Record<string, any>) {
|
|
|
90
109
|
const baseTypeString = `export type Theme = {
|
|
91
110
|
${baseKeys
|
|
92
111
|
.map(([k]) => {
|
|
93
|
-
return ` ${k}: string;\n`
|
|
112
|
+
return ` ${JSON.stringify(k)}: string;\n`
|
|
94
113
|
})
|
|
95
114
|
.join('')}
|
|
96
115
|
}`
|
|
@@ -122,7 +141,7 @@ function t(a: [number, number][]) {
|
|
|
122
141
|
// add all keys array
|
|
123
142
|
const keys = baseKeys.map(([k]) => k)
|
|
124
143
|
out += `const ks = [\n`
|
|
125
|
-
out += keys.map((k) =>
|
|
144
|
+
out += keys.map((k) => JSON.stringify(k)).join(',\n')
|
|
126
145
|
out += `]\n\n`
|
|
127
146
|
|
|
128
147
|
// add all themes
|
|
@@ -176,19 +195,16 @@ function purgeCache(moduleName) {
|
|
|
176
195
|
delete require.cache[mod.id]
|
|
177
196
|
})
|
|
178
197
|
|
|
179
|
-
|
|
180
|
-
if (!
|
|
181
|
-
// bun doesn't have this
|
|
198
|
+
const pathCache = ModuleInternals._pathCache
|
|
199
|
+
if (!pathCache) {
|
|
182
200
|
return
|
|
183
201
|
}
|
|
184
202
|
|
|
185
203
|
// Remove cached paths to the module.
|
|
186
204
|
// Thanks to @bentael for pointing this out.
|
|
187
|
-
|
|
188
|
-
Object.keys(module.constructor._pathCache).forEach((cacheKey) => {
|
|
205
|
+
Object.keys(pathCache).forEach((cacheKey) => {
|
|
189
206
|
if (cacheKey.indexOf(moduleName) > 0) {
|
|
190
|
-
|
|
191
|
-
delete module.constructor._pathCache[cacheKey]
|
|
207
|
+
delete pathCache[cacheKey]
|
|
192
208
|
}
|
|
193
209
|
})
|
|
194
210
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-themes.d.ts","sourceRoot":"","sources":["../src/generate-themes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-themes.d.ts","sourceRoot":"","sources":["../src/generate-themes.ts"],"names":[],"mappings":"AAcA,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM;;eAmDrD"}
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
|
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc","ignoreList":[]}
|