@tamagui/static 1.0.0-alpha.2 → 1.0.0-alpha.6
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/extractor/createExtractor.js +46 -29
- package/dist/extractor/createExtractor.js.map +2 -2
- package/dist/extractor/extractHelpers.js +3 -1
- package/dist/extractor/extractHelpers.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +8 -16
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/index.cjs +77 -50
- package/dist/index.cjs.map +2 -2
- package/dist/patchReactNativeWeb.js +18 -3
- package/dist/patchReactNativeWeb.js.map +2 -2
- package/package.json +7 -6
- package/src/extractor/createExtractor.ts +56 -39
- package/src/extractor/extractHelpers.ts +3 -2
- package/src/extractor/extractToClassNames.ts +4 -15
- package/src/patchReactNativeWeb.ts +21 -5
- package/src/types.ts +5 -2
- package/types.d.ts +215 -0
|
@@ -4,8 +4,24 @@ import * as fs from "fs";
|
|
|
4
4
|
import path from "path";
|
|
5
5
|
function patchReactNativeWeb() {
|
|
6
6
|
const rootDir = require.resolve("react-native-web").replace(/\/dist.*/, "");
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const modulePath = path.join(rootDir, "dist", "tamagui-exports.js");
|
|
8
|
+
const cjsPath = path.join(rootDir, "dist", "cjs", "tamagui-exports.js");
|
|
9
|
+
const isEqual = (() => {
|
|
10
|
+
let res = false;
|
|
11
|
+
try {
|
|
12
|
+
res = fs.readFileSync(modulePath, "utf-8") === moduleExports && fs.readFileSync(cjsPath, "utf-8") == cjsExports;
|
|
13
|
+
} catch {
|
|
14
|
+
res = false;
|
|
15
|
+
}
|
|
16
|
+
return res;
|
|
17
|
+
})();
|
|
18
|
+
if (!isEqual) {
|
|
19
|
+
console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
|
|
20
|
+
console.log(" > adding", modulePath);
|
|
21
|
+
console.log(" > adding", cjsPath);
|
|
22
|
+
fs.writeFileSync(modulePath, moduleExports);
|
|
23
|
+
fs.writeFileSync(cjsPath, cjsExports);
|
|
24
|
+
}
|
|
9
25
|
const moduleEntry = path.join(rootDir, "dist", "index.js");
|
|
10
26
|
const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
|
|
11
27
|
if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
|
|
@@ -26,7 +42,6 @@ export const TamaguiExports = TExports
|
|
|
26
42
|
exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
|
|
27
43
|
// tamagui-patch-end
|
|
28
44
|
`);
|
|
29
|
-
console.log(`Tamagui patched react-native-web`);
|
|
30
45
|
}
|
|
31
46
|
}
|
|
32
47
|
__name(patchReactNativeWeb, "patchReactNativeWeb");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/patchReactNativeWeb.ts"],
|
|
4
|
-
"sourcesContent": ["import * as fs from 'fs'\nimport path from 'path'\n\n// were patching react-native-web so we can use some internal methods\n// we do it this way because we need to rely on webpack or bundler config to determine cjs vs esm\n// so we can't just require it all directly\n// would be nice in the future to be able to eject from react-native-web entirely optionally\n\n// keep it sync\nexport function patchReactNativeWeb() {\n const rootDir = require.resolve('react-native-web').replace(/\\/dist.*/, '')\n
|
|
5
|
-
"mappings": ";;AAAA;AACA;AAQO,+BAA+B;AACpC,QAAM,UAAU,AAAgB,oCAAoB,QAAQ,YAAY;
|
|
4
|
+
"sourcesContent": ["import * as fs from 'fs'\nimport path from 'path'\n\n// were patching react-native-web so we can use some internal methods\n// we do it this way because we need to rely on webpack or bundler config to determine cjs vs esm\n// so we can't just require it all directly\n// would be nice in the future to be able to eject from react-native-web entirely optionally\n\n// keep it sync\nexport function patchReactNativeWeb() {\n const rootDir = require.resolve('react-native-web').replace(/\\/dist.*/, '')\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n\n const isEqual = (() => {\n let res = false\n try {\n res =\n fs.readFileSync(modulePath, 'utf-8') === moduleExports &&\n fs.readFileSync(cjsPath, 'utf-8') == cjsExports\n } catch {\n res = false\n }\n return res\n })()\n\n if (!isEqual) {\n console.log('\uD83E\uDD5A Tamagui patching react-native-web to share atomic styling primitives')\n console.log(' > adding', modulePath)\n console.log(' > adding', cjsPath)\n fs.writeFileSync(modulePath, moduleExports)\n fs.writeFileSync(cjsPath, cjsExports)\n }\n\n // if entry files not patched, patch them:\n const moduleEntry = path.join(rootDir, 'dist', 'index.js')\n const moduleEntrySrc = fs.readFileSync(moduleEntry, 'utf-8')\n if (!moduleEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n moduleEntry,\n `${removePatch(moduleEntrySrc)}\n\n// tamagui-patch-v4\nimport * as TExports from './tamagui-exports'\nexport const TamaguiExports = TExports\n// tamagui-patch-end\n`\n )\n }\n const cjsEntry = path.join(rootDir, 'dist', 'cjs', 'index.js')\n const cjsEntrySrc = fs.readFileSync(cjsEntry, 'utf-8')\n if (!cjsEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n cjsEntry,\n `${removePatch(cjsEntrySrc)}\n\n// tamagui-patch-v4\nexports.TamaguiExports = _interopRequireDefault(require(\"./tamagui-exports\"));\n// tamagui-patch-end\n`\n )\n }\n}\n\nfunction removePatch(source: string) {\n return source.replace(/\\/\\/ tamagui-patch([.\\s\\S]*)/g, '')\n}\n\n// view exports/View.ts\nconst forwardedPropsObj = `{\n ...fwdProps.defaultProps,\n ...fwdProps.accessibilityProps,\n ...fwdProps.clickProps,\n ...fwdProps.focusProps,\n ...fwdProps.keyboardProps,\n ...fwdProps.mouseProps,\n ...fwdProps.touchProps,\n ...fwdProps.styleProps,\n href: true,\n lang: true,\n onScroll: true,\n onWheel: true,\n pointerEvents: true\n}\n`\n\nconst moduleExports = `\nexport { atomic } from './exports/StyleSheet/compile'\nexport { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'\nexport { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'\nexport { default as i18Style } from './exports/StyleSheet/i18nStyle'\nexport { default as createDOMProps } from './modules/createDOMProps'\nexport { default as AccessibilityUtil } from './modules/AccessibilityUtil'\nexport { default as createElement } from './exports/createElement'\nexport { default as css } from './exports/StyleSheet/css'\nexport { default as TextAncestorContext } from './exports/Text/TextAncestorContext'\nexport { default as pick } from './modules/pick'\nexport { default as useElementLayout } from './modules/useElementLayout'\nexport { default as useMergeRefs } from './modules/useMergeRefs'\nexport { default as usePlatformMethods } from './modules/usePlatformMethods'\nexport { default as useResponderEvents } from './modules/useResponderEvents'\nimport * as fwdProps from './modules/forwardedProps'\nexport const forwardedProps = ${forwardedPropsObj}\n`\n\nconst cjsExports = `\nexports.atomic = require('./exports/StyleSheet/compile').atomic\nexports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')\nexports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')\nexports.i18Style = require('./exports/StyleSheet/i18nStyle')\nexports.createDOMProps = require('./modules/createDOMProps')\nexports.AccessibilityUtil = require('./modules/AccessibilityUtil')\nexports.createElement = require('./exports/createElement')\nexports.css = require('./exports/StyleSheet/css')\nexports.TextAncestorContext = require('./exports/Text/TextAncestorContext')\nexports.pick = require('./modules/pick')\nexports.useElementLayout = require('./modules/useElementLayout')\nexports.useMergeRefs = require('./modules/useMergeRefs')\nexports.usePlatformMethods = require('./modules/usePlatformMethods')\nexports.useResponderEvents = require('./modules/useResponderEvents')\nconst fwdProps = require('./modules/forwardedProps')\nexports.forwardedProps = ${forwardedPropsObj}\n`\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AAQO,+BAA+B;AACpC,QAAM,UAAU,AAAgB,oCAAoB,QAAQ,YAAY;AACxE,QAAM,aAAa,KAAK,KAAK,SAAS,QAAQ;AAC9C,QAAM,UAAU,KAAK,KAAK,SAAS,QAAQ,OAAO;AAElD,QAAM,UAAW,OAAM;AACrB,QAAI,MAAM;AACV,QAAI;AACF,YACE,GAAG,aAAa,YAAY,aAAa,iBACzC,GAAG,aAAa,SAAS,YAAY;AAAA,YACvC;AACA,YAAM;AAAA;AAER,WAAO;AAAA;AAGT,MAAI,CAAC,SAAS;AACZ,YAAQ,IAAI;AACZ,YAAQ,IAAI,eAAe;AAC3B,YAAQ,IAAI,eAAe;AAC3B,OAAG,cAAc,YAAY;AAC7B,OAAG,cAAc,SAAS;AAAA;AAI5B,QAAM,cAAc,KAAK,KAAK,SAAS,QAAQ;AAC/C,QAAM,iBAAiB,GAAG,aAAa,aAAa;AACpD,MAAI,CAAC,eAAe,SAAS,wBAAwB;AACnD,OAAG,cACD,aACA,GAAG,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASnB,QAAM,WAAW,KAAK,KAAK,SAAS,QAAQ,OAAO;AACnD,QAAM,cAAc,GAAG,aAAa,UAAU;AAC9C,MAAI,CAAC,YAAY,SAAS,wBAAwB;AAChD,OAAG,cACD,UACA,GAAG,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA7CL;AAuDhB,qBAAqB,QAAgB;AACnC,SAAO,OAAO,QAAQ,iCAAiC;AAAA;AADhD;AAKT,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiB1B,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAgBU;AAAA;AAGhC,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAgBQ;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/static",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"typings": "types.d.ts",
|
|
8
8
|
"files": [
|
|
9
|
+
"types.d.ts",
|
|
9
10
|
"dist",
|
|
10
11
|
"src"
|
|
11
12
|
],
|
|
@@ -52,10 +53,10 @@
|
|
|
52
53
|
"@dish/babel-preset": "^0.0.6",
|
|
53
54
|
"@expo/match-media": "^0.1.0",
|
|
54
55
|
"@tamagui/build": "^1.0.0-alpha.2",
|
|
55
|
-
"@tamagui/core": "^1.0.0-alpha.
|
|
56
|
-
"@tamagui/core-node": "^1.0.0-alpha.
|
|
56
|
+
"@tamagui/core": "^1.0.0-alpha.6",
|
|
57
|
+
"@tamagui/core-node": "^1.0.0-alpha.5",
|
|
57
58
|
"@tamagui/fake-react-native": "^1.0.0-alpha.2",
|
|
58
|
-
"@tamagui/helpers": "^1.0.0-alpha.
|
|
59
|
+
"@tamagui/helpers": "^1.0.0-alpha.5",
|
|
59
60
|
"babel-literal-to-ast": "^2.1.0",
|
|
60
61
|
"esbuild": "^0.13.12",
|
|
61
62
|
"esbuild-register": "^3.1.2",
|
|
@@ -63,10 +64,10 @@
|
|
|
63
64
|
"fs-extra": "^9.0.0",
|
|
64
65
|
"invariant": "^2.2.4",
|
|
65
66
|
"lodash": "^4.17.20",
|
|
66
|
-
"tamagui": "^1.0.0-alpha.
|
|
67
|
+
"tamagui": "^1.0.0-alpha.6"
|
|
67
68
|
},
|
|
68
69
|
"peerDependencies": {
|
|
69
70
|
"react-native-web": "*"
|
|
70
71
|
},
|
|
71
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "18a942d7a08109c8f5b8692a2adb20c69d56a7e1"
|
|
72
73
|
}
|
|
@@ -51,6 +51,7 @@ export function createExtractor() {
|
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
let loadedTamaguiConfig: TamaguiInternalConfig
|
|
54
|
+
let hasLogged = false
|
|
54
55
|
|
|
55
56
|
return {
|
|
56
57
|
getTamaguiConfig() {
|
|
@@ -66,7 +67,8 @@ export function createExtractor() {
|
|
|
66
67
|
sourcePath = '',
|
|
67
68
|
onExtractTag,
|
|
68
69
|
getFlattenedNode,
|
|
69
|
-
|
|
70
|
+
disableExtraction,
|
|
71
|
+
disableDebugAttr,
|
|
70
72
|
...props
|
|
71
73
|
}: ExtractorParseProps
|
|
72
74
|
) => {
|
|
@@ -87,12 +89,6 @@ export function createExtractor() {
|
|
|
87
89
|
loadedTamaguiConfig = tamaguiConfig
|
|
88
90
|
|
|
89
91
|
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]
|
|
90
|
-
|
|
91
|
-
// TODO this can be passed in / set based on if source changed
|
|
92
|
-
// const shouldReCheckTheme = false //Date.now() - hasParsedFileLast > 600
|
|
93
|
-
// hasParsedFileLast = Date.now()
|
|
94
|
-
|
|
95
|
-
let doesUseValidImport = false
|
|
96
92
|
const body = fileOrPath.type === 'Program' ? fileOrPath.get('body') : fileOrPath.program.body
|
|
97
93
|
|
|
98
94
|
/**
|
|
@@ -108,6 +104,8 @@ export function createExtractor() {
|
|
|
108
104
|
return obj
|
|
109
105
|
}, {})
|
|
110
106
|
|
|
107
|
+
let doesUseValidImport = false
|
|
108
|
+
|
|
111
109
|
for (const bodyPath of body) {
|
|
112
110
|
if (bodyPath.type !== 'ImportDeclaration') continue
|
|
113
111
|
const node = ('node' in bodyPath ? bodyPath.node : bodyPath) as any
|
|
@@ -119,7 +117,6 @@ export function createExtractor() {
|
|
|
119
117
|
return validComponents[name] || validHooks[name]
|
|
120
118
|
})
|
|
121
119
|
) {
|
|
122
|
-
console.log('WHAT')
|
|
123
120
|
doesUseValidImport = true
|
|
124
121
|
break
|
|
125
122
|
}
|
|
@@ -149,6 +146,12 @@ export function createExtractor() {
|
|
|
149
146
|
*/
|
|
150
147
|
let programPath: NodePath<t.Program>
|
|
151
148
|
|
|
149
|
+
const res = {
|
|
150
|
+
flattened: 0,
|
|
151
|
+
optimized: 0,
|
|
152
|
+
modified: 0,
|
|
153
|
+
}
|
|
154
|
+
|
|
152
155
|
callTraverse({
|
|
153
156
|
Program: {
|
|
154
157
|
enter(path) {
|
|
@@ -187,8 +190,41 @@ export function createExtractor() {
|
|
|
187
190
|
return
|
|
188
191
|
}
|
|
189
192
|
|
|
190
|
-
const { staticConfig } = component
|
|
191
193
|
const originalNodeName = node.name.name
|
|
194
|
+
|
|
195
|
+
if (shouldPrintDebug) {
|
|
196
|
+
console.log(`\n<${originalNodeName} />`)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const filePath = sourcePath.replace(process.cwd(), '.')
|
|
200
|
+
const lineNumbers = node.loc
|
|
201
|
+
? node.loc.start.line +
|
|
202
|
+
(node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : '')
|
|
203
|
+
: ''
|
|
204
|
+
|
|
205
|
+
// add data-is
|
|
206
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
207
|
+
const preName = componentName ? `${componentName}:` : ''
|
|
208
|
+
res.modified++
|
|
209
|
+
node.attributes.unshift(
|
|
210
|
+
t.jsxAttribute(
|
|
211
|
+
t.jsxIdentifier('data-is'),
|
|
212
|
+
t.stringLiteral(
|
|
213
|
+
` ${preName}${node.name.name} ${filePath.replace('./', '')}:${lineNumbers} `
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (disableExtraction) {
|
|
220
|
+
if (!hasLogged) {
|
|
221
|
+
console.log('🥚 Tamagui disableExtraction set: no CSS or optimizations will be run')
|
|
222
|
+
hasLogged = true
|
|
223
|
+
}
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const { staticConfig } = component
|
|
192
228
|
const isTextView = staticConfig.isText || false
|
|
193
229
|
const validStyles = staticConfig?.validStyles ?? {}
|
|
194
230
|
|
|
@@ -225,10 +261,6 @@ export function createExtractor() {
|
|
|
225
261
|
return res
|
|
226
262
|
}
|
|
227
263
|
|
|
228
|
-
if (shouldPrintDebug) {
|
|
229
|
-
console.log(`\n<${originalNodeName} />`)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
264
|
// Generate scope object at this level
|
|
233
265
|
const staticNamespace = getStaticBindingsForScope(
|
|
234
266
|
traversePath.scope,
|
|
@@ -401,9 +433,9 @@ export function createExtractor() {
|
|
|
401
433
|
}
|
|
402
434
|
const propName = prop.key['name']
|
|
403
435
|
if (!isStaticAttributeName(propName) && propName !== 'tag') {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
436
|
+
if (shouldPrintDebug) {
|
|
437
|
+
console.log(' not a valid style prop!', propName)
|
|
438
|
+
}
|
|
407
439
|
return false
|
|
408
440
|
}
|
|
409
441
|
return true
|
|
@@ -491,7 +523,9 @@ export function createExtractor() {
|
|
|
491
523
|
const [test, alt, cons] = conditional
|
|
492
524
|
if (!test) throw new Error(`no test`)
|
|
493
525
|
if ([alt, cons].some((side) => side && !isExtractable(side))) {
|
|
494
|
-
|
|
526
|
+
if (shouldPrintDebug) {
|
|
527
|
+
console.log('not extractable', alt, cons)
|
|
528
|
+
}
|
|
495
529
|
return attr
|
|
496
530
|
}
|
|
497
531
|
// split into individual ternaries per object property
|
|
@@ -774,12 +808,6 @@ export function createExtractor() {
|
|
|
774
808
|
modifiedComponents.add(parentFn)
|
|
775
809
|
}
|
|
776
810
|
|
|
777
|
-
const filePath = sourcePath.replace(process.cwd(), '.')
|
|
778
|
-
const lineNumbers = node.loc
|
|
779
|
-
? node.loc.start.line +
|
|
780
|
-
(node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : '')
|
|
781
|
-
: ''
|
|
782
|
-
|
|
783
811
|
// combine ternaries
|
|
784
812
|
let ternaries: Ternary[] = []
|
|
785
813
|
attrs = attrs
|
|
@@ -1050,21 +1078,6 @@ export function createExtractor() {
|
|
|
1050
1078
|
console.log(' - attrs (after): ', attrs.map(attrStr).join(', '))
|
|
1051
1079
|
}
|
|
1052
1080
|
|
|
1053
|
-
// add data-is
|
|
1054
|
-
if (shouldAddDebugProp) {
|
|
1055
|
-
const preName = componentName ? `${componentName}:` : ''
|
|
1056
|
-
// unshift so spreads/nesting overwrite
|
|
1057
|
-
attrs.unshift({
|
|
1058
|
-
type: 'attr',
|
|
1059
|
-
value: t.jsxAttribute(
|
|
1060
|
-
t.jsxIdentifier('data-is'),
|
|
1061
|
-
t.stringLiteral(
|
|
1062
|
-
` ${preName}${node.name.name} ${filePath.replace('./', '')}:${lineNumbers} `
|
|
1063
|
-
)
|
|
1064
|
-
),
|
|
1065
|
-
})
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
1081
|
if (shouldFlatten) {
|
|
1069
1082
|
// DO FLATTEN
|
|
1070
1083
|
if (shouldPrintDebug) {
|
|
@@ -1072,7 +1085,7 @@ export function createExtractor() {
|
|
|
1072
1085
|
}
|
|
1073
1086
|
isFlattened = true
|
|
1074
1087
|
node.name.name = flatNode
|
|
1075
|
-
|
|
1088
|
+
res.flattened++
|
|
1076
1089
|
if (closingElement) {
|
|
1077
1090
|
closingElement.name.name = flatNode
|
|
1078
1091
|
}
|
|
@@ -1084,6 +1097,8 @@ export function createExtractor() {
|
|
|
1084
1097
|
console.log(' - attrs (end): ', attrs.map(attrStr).join(', '))
|
|
1085
1098
|
}
|
|
1086
1099
|
|
|
1100
|
+
res.optimized++
|
|
1101
|
+
|
|
1087
1102
|
onExtractTag({
|
|
1088
1103
|
attrs,
|
|
1089
1104
|
node,
|
|
@@ -1110,6 +1125,8 @@ export function createExtractor() {
|
|
|
1110
1125
|
removeUnusedHooks(comp, shouldPrintDebug)
|
|
1111
1126
|
}
|
|
1112
1127
|
}
|
|
1128
|
+
|
|
1129
|
+
return res
|
|
1113
1130
|
},
|
|
1114
1131
|
}
|
|
1115
1132
|
}
|
|
@@ -97,5 +97,6 @@ export function isValidThemeHook(
|
|
|
97
97
|
return true
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export const isInsideTamagui = (srcName: string) =>
|
|
101
|
-
srcName.includes('/tamagui/
|
|
100
|
+
export const isInsideTamagui = (srcName: string) => {
|
|
101
|
+
return srcName.includes('/tamagui/_jsx') || srcName.includes('/core/src')
|
|
102
|
+
}
|
|
@@ -79,17 +79,11 @@ export function extractToClassNames({
|
|
|
79
79
|
const cssMap = new Map<string, { css: string; commentTexts: string[] }>()
|
|
80
80
|
const existingHoists: { [key: string]: t.Identifier } = {}
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
let optimized = 0
|
|
84
|
-
|
|
85
|
-
extractor.parse(ast, {
|
|
82
|
+
const res = extractor.parse(ast, {
|
|
86
83
|
sourcePath,
|
|
87
84
|
shouldPrintDebug,
|
|
88
85
|
...options,
|
|
89
86
|
getFlattenedNode: ({ tag }) => tag,
|
|
90
|
-
onDidFlatten() {
|
|
91
|
-
flattened++
|
|
92
|
-
},
|
|
93
87
|
onExtractTag: ({
|
|
94
88
|
attrs,
|
|
95
89
|
node,
|
|
@@ -100,8 +94,6 @@ export function extractToClassNames({
|
|
|
100
94
|
lineNumbers,
|
|
101
95
|
programPath,
|
|
102
96
|
}) => {
|
|
103
|
-
optimized++
|
|
104
|
-
|
|
105
97
|
let finalClassNames: ClassNameObject[] = []
|
|
106
98
|
let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []
|
|
107
99
|
let finalStyles: StyleObject[] = []
|
|
@@ -276,15 +268,12 @@ export function extractToClassNames({
|
|
|
276
268
|
},
|
|
277
269
|
})
|
|
278
270
|
|
|
279
|
-
if (!
|
|
271
|
+
if (!res || !res.modified) {
|
|
280
272
|
return null
|
|
281
273
|
}
|
|
282
274
|
|
|
283
275
|
const styles = Array.from(cssMap.values())
|
|
284
|
-
.map((x) =>
|
|
285
|
-
// remove comments
|
|
286
|
-
return x.css //shouldInternalDedupe ? x.css : `${x.commentTexts.join('\n')}\n${x.css}`
|
|
287
|
-
})
|
|
276
|
+
.map((x) => x.css)
|
|
288
277
|
.join('\n')
|
|
289
278
|
.trim()
|
|
290
279
|
|
|
@@ -325,7 +314,7 @@ export function extractToClassNames({
|
|
|
325
314
|
const memUsed =
|
|
326
315
|
Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10
|
|
327
316
|
// prettier-ignore
|
|
328
|
-
console.log(` 🥚 ${basename(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms ׁ· ${`${optimized}`.padStart(4)} optimized · ${flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ''}`)
|
|
317
|
+
console.log(` 🥚 ${basename(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms ׁ· ${`${res.optimized}`.padStart(4)} optimized · ${res.flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ''}`)
|
|
329
318
|
}
|
|
330
319
|
|
|
331
320
|
return {
|
|
@@ -9,10 +9,28 @@ import path from 'path'
|
|
|
9
9
|
// keep it sync
|
|
10
10
|
export function patchReactNativeWeb() {
|
|
11
11
|
const rootDir = require.resolve('react-native-web').replace(/\/dist.*/, '')
|
|
12
|
+
const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')
|
|
13
|
+
const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const isEqual = (() => {
|
|
16
|
+
let res = false
|
|
17
|
+
try {
|
|
18
|
+
res =
|
|
19
|
+
fs.readFileSync(modulePath, 'utf-8') === moduleExports &&
|
|
20
|
+
fs.readFileSync(cjsPath, 'utf-8') == cjsExports
|
|
21
|
+
} catch {
|
|
22
|
+
res = false
|
|
23
|
+
}
|
|
24
|
+
return res
|
|
25
|
+
})()
|
|
26
|
+
|
|
27
|
+
if (!isEqual) {
|
|
28
|
+
console.log('🥚 Tamagui patching react-native-web to share atomic styling primitives')
|
|
29
|
+
console.log(' > adding', modulePath)
|
|
30
|
+
console.log(' > adding', cjsPath)
|
|
31
|
+
fs.writeFileSync(modulePath, moduleExports)
|
|
32
|
+
fs.writeFileSync(cjsPath, cjsExports)
|
|
33
|
+
}
|
|
16
34
|
|
|
17
35
|
// if entry files not patched, patch them:
|
|
18
36
|
const moduleEntry = path.join(rootDir, 'dist', 'index.js')
|
|
@@ -41,8 +59,6 @@ exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
|
|
|
41
59
|
// tamagui-patch-end
|
|
42
60
|
`
|
|
43
61
|
)
|
|
44
|
-
|
|
45
|
-
console.log(`Tamagui patched react-native-web`)
|
|
46
62
|
}
|
|
47
63
|
}
|
|
48
64
|
|
package/src/types.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface TamaguiOptions {
|
|
|
15
15
|
evaluateVars?: boolean
|
|
16
16
|
importsWhitelist?: string[]
|
|
17
17
|
disableExtraction?: boolean
|
|
18
|
+
disableDebugAttr?: boolean
|
|
18
19
|
exclude?: RegExp
|
|
19
20
|
logTimings?: boolean
|
|
20
21
|
|
|
@@ -32,7 +33,10 @@ export type ExtractedAttrAttr = {
|
|
|
32
33
|
|
|
33
34
|
export type ExtractedAttrStyle = { type: 'style'; value: Object }
|
|
34
35
|
|
|
35
|
-
export type ExtractedAttr =
|
|
36
|
+
export type ExtractedAttr =
|
|
37
|
+
| ExtractedAttrAttr
|
|
38
|
+
| { type: 'ternary'; value: Ternary }
|
|
39
|
+
| ExtractedAttrStyle
|
|
36
40
|
|
|
37
41
|
export type ExtractTagProps = {
|
|
38
42
|
attrs: ExtractedAttr[]
|
|
@@ -51,7 +55,6 @@ export type ExtractorParseProps = TamaguiOptions & {
|
|
|
51
55
|
shouldPrintDebug?: boolean
|
|
52
56
|
onExtractTag: (props: ExtractTagProps) => void
|
|
53
57
|
getFlattenedNode: (props: { isTextView: boolean; tag: string }) => string
|
|
54
|
-
onDidFlatten?: () => void
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
export interface Ternary {
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v5.9.0
|
|
2
|
+
|
|
3
|
+
/// <reference types="babel__traverse" />
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
|
|
6
|
+
import * as t from '@babel/types';
|
|
7
|
+
|
|
8
|
+
export interface TamaguiOptions {
|
|
9
|
+
components: string[];
|
|
10
|
+
config?: string;
|
|
11
|
+
evaluateVars?: boolean;
|
|
12
|
+
importsWhitelist?: string[];
|
|
13
|
+
disableExtraction?: boolean;
|
|
14
|
+
disableDebugAttr?: boolean;
|
|
15
|
+
exclude?: RegExp;
|
|
16
|
+
logTimings?: boolean;
|
|
17
|
+
cssPath?: string;
|
|
18
|
+
cssData?: any;
|
|
19
|
+
deoptProps?: Set<string>;
|
|
20
|
+
excludeProps?: string[];
|
|
21
|
+
}
|
|
22
|
+
export declare type ExtractedAttrAttr = {
|
|
23
|
+
type: "attr";
|
|
24
|
+
value: t.JSXAttribute | t.JSXSpreadAttribute;
|
|
25
|
+
};
|
|
26
|
+
export declare type ExtractedAttrStyle = {
|
|
27
|
+
type: "style";
|
|
28
|
+
value: Object;
|
|
29
|
+
};
|
|
30
|
+
export declare type ExtractedAttr = ExtractedAttrAttr | {
|
|
31
|
+
type: "ternary";
|
|
32
|
+
value: Ternary;
|
|
33
|
+
} | ExtractedAttrStyle;
|
|
34
|
+
export declare type ExtractTagProps = {
|
|
35
|
+
attrs: ExtractedAttr[];
|
|
36
|
+
node: t.JSXOpeningElement;
|
|
37
|
+
attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any;
|
|
38
|
+
jsxPath: NodePath<t.JSXElement>;
|
|
39
|
+
programPath: NodePath<t.Program>;
|
|
40
|
+
originalNodeName: string;
|
|
41
|
+
lineNumbers: string;
|
|
42
|
+
filePath: string;
|
|
43
|
+
isFlattened: boolean;
|
|
44
|
+
};
|
|
45
|
+
export declare type ExtractorParseProps = TamaguiOptions & {
|
|
46
|
+
sourcePath?: string;
|
|
47
|
+
shouldPrintDebug?: boolean;
|
|
48
|
+
onExtractTag: (props: ExtractTagProps) => void;
|
|
49
|
+
getFlattenedNode: (props: {
|
|
50
|
+
isTextView: boolean;
|
|
51
|
+
tag: string;
|
|
52
|
+
}) => string;
|
|
53
|
+
};
|
|
54
|
+
export interface Ternary {
|
|
55
|
+
test: t.Expression;
|
|
56
|
+
inlineMediaQuery?: string;
|
|
57
|
+
remove: Function;
|
|
58
|
+
consequent: Object | null;
|
|
59
|
+
alternate: Object | null;
|
|
60
|
+
}
|
|
61
|
+
declare class Variable {
|
|
62
|
+
name: string;
|
|
63
|
+
val: string | number;
|
|
64
|
+
variable: string | number;
|
|
65
|
+
constructor({ val, name }: VariableIn);
|
|
66
|
+
toString(): string | number;
|
|
67
|
+
}
|
|
68
|
+
export declare type VariableIn = {
|
|
69
|
+
val: string | number;
|
|
70
|
+
name: string;
|
|
71
|
+
};
|
|
72
|
+
export declare type ThemeProviderProps = {
|
|
73
|
+
themes: any;
|
|
74
|
+
defaultTheme: string;
|
|
75
|
+
disableRootThemeClass?: boolean;
|
|
76
|
+
children?: any;
|
|
77
|
+
};
|
|
78
|
+
export interface CreateTokens<Val extends number | string | Variable = number | string | Variable> {
|
|
79
|
+
font: {
|
|
80
|
+
[key: string]: GenericFont;
|
|
81
|
+
};
|
|
82
|
+
color: {
|
|
83
|
+
[key: string]: Val;
|
|
84
|
+
};
|
|
85
|
+
space: {
|
|
86
|
+
[key: string]: Val;
|
|
87
|
+
};
|
|
88
|
+
size: {
|
|
89
|
+
[key: string]: Val;
|
|
90
|
+
};
|
|
91
|
+
radius: {
|
|
92
|
+
[key: string]: Val;
|
|
93
|
+
};
|
|
94
|
+
zIndex: {
|
|
95
|
+
[key: string]: Val;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export declare type GenericTokens = CreateTokens;
|
|
99
|
+
export declare type GenericThemes = {
|
|
100
|
+
[key: string]: {
|
|
101
|
+
bg: string | Variable;
|
|
102
|
+
bg2: string | Variable;
|
|
103
|
+
bg3: string | Variable;
|
|
104
|
+
bg4: string | Variable;
|
|
105
|
+
color: string | Variable;
|
|
106
|
+
color2: string | Variable;
|
|
107
|
+
color3: string | Variable;
|
|
108
|
+
color4: string | Variable;
|
|
109
|
+
borderColor: string | Variable;
|
|
110
|
+
borderColor2: string | Variable;
|
|
111
|
+
shadowColor: string | Variable;
|
|
112
|
+
shadowColor2: string | Variable;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
export declare type GenericShorthands = {};
|
|
116
|
+
export declare type GenericMedia<K extends string = string> = {
|
|
117
|
+
[key in K]: {
|
|
118
|
+
[key: string]: number | string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
export declare type CreateTamaguiConfig<A extends GenericTokens, B extends GenericThemes, C extends GenericShorthands, D extends GenericMedia> = Partial<Pick<ThemeProviderProps, "defaultTheme" | "disableRootThemeClass">> & {
|
|
122
|
+
tokens: A;
|
|
123
|
+
themes: B;
|
|
124
|
+
shorthands: C;
|
|
125
|
+
media: D;
|
|
126
|
+
};
|
|
127
|
+
export declare type TamaguiInternalConfig<A extends GenericTokens = GenericTokens, B extends GenericThemes = GenericThemes, C extends GenericShorthands = GenericShorthands, D extends GenericMedia = GenericMedia> = CreateTamaguiConfig<A, B, C, D> & {
|
|
128
|
+
Provider: (props: TamaguiProviderProps) => any;
|
|
129
|
+
themeParsed: {
|
|
130
|
+
[key: string]: Variable;
|
|
131
|
+
};
|
|
132
|
+
tokensParsed: CreateTokens<Variable>;
|
|
133
|
+
themeConfig: any;
|
|
134
|
+
getCSS: () => string;
|
|
135
|
+
};
|
|
136
|
+
export declare type GenericFont = {
|
|
137
|
+
size: {
|
|
138
|
+
[key: string | number]: number | Variable;
|
|
139
|
+
};
|
|
140
|
+
lineHeight: {
|
|
141
|
+
[key: string | number]: number | Variable;
|
|
142
|
+
};
|
|
143
|
+
letterSpacing: {
|
|
144
|
+
[key: string | number]: number | Variable;
|
|
145
|
+
};
|
|
146
|
+
weight: {
|
|
147
|
+
[key: string | number]: string | Variable;
|
|
148
|
+
};
|
|
149
|
+
family: string | Variable;
|
|
150
|
+
};
|
|
151
|
+
export declare type TamaguiProviderProps = Partial<Omit<ThemeProviderProps, "children">> & {
|
|
152
|
+
initialWindowMetrics?: any;
|
|
153
|
+
fallback?: any;
|
|
154
|
+
children?: any;
|
|
155
|
+
};
|
|
156
|
+
export declare type Extractor = ReturnType<typeof createExtractor>;
|
|
157
|
+
export declare function createExtractor(): {
|
|
158
|
+
getTamaguiConfig(): TamaguiInternalConfig<import("@tamagui/core").CreateTokens<string | number | import("@tamagui/core").Variable>, {
|
|
159
|
+
[key: string]: {
|
|
160
|
+
bg: string | import("@tamagui/core").Variable;
|
|
161
|
+
bg2: string | import("@tamagui/core").Variable;
|
|
162
|
+
bg3: string | import("@tamagui/core").Variable;
|
|
163
|
+
bg4: string | import("@tamagui/core").Variable;
|
|
164
|
+
color: string | import("@tamagui/core").Variable;
|
|
165
|
+
color2: string | import("@tamagui/core").Variable;
|
|
166
|
+
color3: string | import("@tamagui/core").Variable;
|
|
167
|
+
color4: string | import("@tamagui/core").Variable;
|
|
168
|
+
borderColor: string | import("@tamagui/core").Variable;
|
|
169
|
+
borderColor2: string | import("@tamagui/core").Variable;
|
|
170
|
+
shadowColor: string | import("@tamagui/core").Variable;
|
|
171
|
+
shadowColor2: string | import("@tamagui/core").Variable;
|
|
172
|
+
};
|
|
173
|
+
}, {}, {
|
|
174
|
+
[x: string]: {
|
|
175
|
+
[key: string]: string | number;
|
|
176
|
+
};
|
|
177
|
+
}>;
|
|
178
|
+
parse: (fileOrPath: NodePath<t.Program> | t.File, { config, importsWhitelist, evaluateVars, shouldPrintDebug, sourcePath, onExtractTag, getFlattenedNode, disableExtraction, disableDebugAttr, ...props }: ExtractorParseProps) => {
|
|
179
|
+
flattened: number;
|
|
180
|
+
optimized: number;
|
|
181
|
+
modified: number;
|
|
182
|
+
} | null;
|
|
183
|
+
};
|
|
184
|
+
export declare function literalToAst(literal: any): t.Expression;
|
|
185
|
+
export declare const CSS_FILE_NAME = "__snack.css";
|
|
186
|
+
export declare const MEDIA_SEP = "_";
|
|
187
|
+
export declare const cacheDir: any;
|
|
188
|
+
export declare const CONCAT_CLASSNAME_IMPORT = "concatClassName";
|
|
189
|
+
export declare function extractToClassNames({ loader, extractor, source, sourcePath, options, shouldPrintDebug, threaded, cssPath, }: {
|
|
190
|
+
loader: any;
|
|
191
|
+
extractor: Extractor;
|
|
192
|
+
source: string | Buffer;
|
|
193
|
+
sourcePath: string;
|
|
194
|
+
options: TamaguiOptions;
|
|
195
|
+
shouldPrintDebug: boolean;
|
|
196
|
+
cssPath: string;
|
|
197
|
+
threaded?: boolean;
|
|
198
|
+
}): null | {
|
|
199
|
+
js: string | Buffer;
|
|
200
|
+
styles: string;
|
|
201
|
+
stylesPath?: string;
|
|
202
|
+
ast: t.File;
|
|
203
|
+
map: any;
|
|
204
|
+
};
|
|
205
|
+
export declare function isPresent<T extends Object>(input: null | void | undefined | T): input is T;
|
|
206
|
+
export declare function isSimpleSpread(node: t.JSXSpreadAttribute): boolean;
|
|
207
|
+
export declare const attrStr: (attr: ExtractedAttr) => string | t.JSXIdentifier;
|
|
208
|
+
export declare const objToStr: (obj: any) => any;
|
|
209
|
+
export declare const ternaryStr: (x: Ternary) => string;
|
|
210
|
+
export declare function findComponentName(scope: any): string | undefined;
|
|
211
|
+
export declare function isValidThemeHook(jsxPath: NodePath<t.JSXElement>, n: t.MemberExpression, sourcePath: string): boolean;
|
|
212
|
+
export declare const isInsideTamagui: (srcName: string) => boolean;
|
|
213
|
+
export declare function patchReactNativeWeb(): void;
|
|
214
|
+
|
|
215
|
+
export {};
|