@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/extractor/extractToClassNames.ts"],
|
|
4
|
-
"sourcesContent": ["import * as path from 'path'\nimport { basename } from 'path'\nimport * as util from 'util'\n\nimport generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport { getStylesAtomic } from '@tamagui/core-node'\nimport { concatClassName } from '@tamagui/helpers'\nimport invariant from 'invariant'\nimport { getRemainingRequest } from 'loader-utils'\nimport { ViewStyle } from 'react-native'\n\nimport { ClassNameObject, StyleObject, TamaguiOptions } from '../types'\nimport { babelParse } from './babelParse'\nimport { buildClassName } from './buildClassName'\nimport { Extractor } from './createExtractor'\nimport { ensureImportingConcat } from './ensureImportingConcat'\nimport { isSimpleSpread } from './extractHelpers'\nimport { extractMediaStyle } from './extractMediaStyle'\nimport { hoistClassNames } from './hoistClassNames'\n\nexport const CONCAT_CLASSNAME_IMPORT = 'concatClassName'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n threaded,\n cssPath,\n}: {\n loader: any\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean\n cssPath: string\n threaded?: boolean\n}): null | {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n} {\n if (typeof source !== 'string') {\n throw new Error('`source` must be a string of javascript')\n }\n invariant(\n typeof sourcePath === 'string' && path.isAbsolute(sourcePath),\n '`sourcePath` must be an absolute path to a .js file'\n )\n\n const shouldLogTiming = shouldPrintDebug || options.logTimings\n const start = Date.now()\n const mem = shouldLogTiming ? process.memoryUsage() : null\n\n // Using a map for (officially supported) guaranteed insertion order\n let ast: t.File\n\n try {\n // @ts-ignore\n ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n let flattened = 0\n let optimized = 0\n\n extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => tag,\n onDidFlatten() {\n flattened++\n },\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n }) => {\n optimized++\n\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n const viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n Object.assign(viewStyles, attr.value)\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null) => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n if (shouldPrintDebug) {\n // console.log(' style', attr.value)\n console.log(' classnames', newClassNames, finalClassNames)\n }\n // prettier-ignore\n const existing = finalClassNames.find((x) => x.type == 'StringLiteral') as t.StringLiteral | null\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' classnames (after)', finalClassNames.map(x => x['value']).join(' '))\n }\n break\n case 'attr':\n const val = attr.value\n if (t.isJSXSpreadAttribute(val)) {\n if (isSimpleSpread(val)) {\n finalClassNames.push(\n t.logicalExpression(\n '&&',\n val.argument,\n t.memberExpression(val.argument, t.identifier('className'))\n )\n )\n }\n } else if (val.name.name === 'className') {\n const value = val.value\n if (value) {\n try {\n const evaluatedValue = attemptEval(value)\n finalClassNames.push(t.stringLiteral(evaluatedValue))\n } catch (e) {\n finalClassNames.push(value['expression'])\n }\n }\n continue\n }\n finalAttrs.push(val)\n break\n case 'ternary':\n const mediaExtraction = extractMediaStyle(\n attr.value,\n jsxPath,\n extractor.getTamaguiConfig(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (mediaExtraction) {\n lastMediaImportance++\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n if (!mediaExtraction.ternaryWithoutMedia) {\n continue\n }\n }\n const ternary = mediaExtraction?.ternaryWithoutMedia || attr.value\n const consInfo = addStyles(ternary.consequent)\n const altInfo = addStyles(ternary.alternate)\n const cCN = consInfo.map((x) => x.identifier).join(' ')\n const aCN = altInfo.map((x) => x.identifier).join(' ')\n if (consInfo.length && altInfo.length) {\n finalClassNames.push(\n t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN))\n )\n } else {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(' ' + cCN),\n t.stringLiteral(' ' + aCN)\n )\n )\n }\n break\n }\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n const names = buildClassName(finalClassNames)\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [\n expr,\n ...simpleSpreads.map((val) => val.value['argument']),\n ])\n }\n\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier('className'), t.jsxExpressionContainer(expr))\n )\n }\n\n const comment = util.format('/* %s:%s (%s) */', filePath, lineNumbers, originalNodeName)\n\n for (const { className, rules } of finalStyles) {\n if (cssMap.has(className)) {\n if (comment) {\n const val = cssMap.get(className)!\n val.commentTexts.push(comment)\n cssMap.set(className, val)\n }\n } else if (rules.length) {\n if (rules.length > 1) {\n console.log(' rules error', { rules })\n throw new Error(`Shouldn't have more than one rule`)\n }\n cssMap.set(className, {\n css: rules[0],\n commentTexts: [comment],\n })\n }\n }\n },\n })\n\n if (!optimized) {\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => {\n // remove comments\n return x.css //shouldInternalDedupe ? x.css : `${x.commentTexts.join('\\n')}\\n${x.css}`\n })\n .join('\\n')\n .trim()\n\n if (styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = getRemainingRequest(loader)\n const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`\n ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)))\n }\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n console.log(\n '\\n -------- output code ------- \\n\\n',\n result.code\n .split('\\n')\n .filter((x) => !x.startsWith('//'))\n .join('\\n')\n )\n console.log('\\n -------- output style -------- \\n\\n', styles)\n }\n\n if (shouldLogTiming && mem) {\n // console.log(`${parseTime} / ${traverseTime} / ${generateTime}`)\n const memUsed =\n Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n // prettier-ignore\n console.log(` \uD83E\uDD5A ${basename(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\u00B7 ${`${optimized}`.padStart(4)} optimized \u00B7 ${flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ''}`)\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AAEA;AACA;AACA;AACA;AAEO,MAAM,0BAA0B;AAEvC,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA;AAGT,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAgBA;AACA,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM;AAAA;AAElB,YACE,OAAO,eAAe,YAAY,KAAK,WAAW,aAClD;AAGF,QAAM,kBAAkB,oBAAoB,QAAQ;AACpD,QAAM,QAAQ,KAAK;AACnB,QAAM,MAAM,kBAAkB,QAAQ,gBAAgB;AAGtD,MAAI;AAEJ,MAAI;AAEF,UAAM,WAAW;AAAA,WACV,KAAP;AACA,YAAQ,MAAM,sBAAsB;AACpC,UAAM;AAAA;AAGR,QAAM,SAAS,IAAI;AACnB,QAAM,iBAAkD;AAExD,
|
|
4
|
+
"sourcesContent": ["import * as path from 'path'\nimport { basename } from 'path'\nimport * as util from 'util'\n\nimport generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport { getStylesAtomic } from '@tamagui/core-node'\nimport { concatClassName } from '@tamagui/helpers'\nimport invariant from 'invariant'\nimport { getRemainingRequest } from 'loader-utils'\nimport { ViewStyle } from 'react-native'\n\nimport { ClassNameObject, StyleObject, TamaguiOptions } from '../types'\nimport { babelParse } from './babelParse'\nimport { buildClassName } from './buildClassName'\nimport { Extractor } from './createExtractor'\nimport { ensureImportingConcat } from './ensureImportingConcat'\nimport { isSimpleSpread } from './extractHelpers'\nimport { extractMediaStyle } from './extractMediaStyle'\nimport { hoistClassNames } from './hoistClassNames'\n\nexport const CONCAT_CLASSNAME_IMPORT = 'concatClassName'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n threaded,\n cssPath,\n}: {\n loader: any\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean\n cssPath: string\n threaded?: boolean\n}): null | {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n} {\n if (typeof source !== 'string') {\n throw new Error('`source` must be a string of javascript')\n }\n invariant(\n typeof sourcePath === 'string' && path.isAbsolute(sourcePath),\n '`sourcePath` must be an absolute path to a .js file'\n )\n\n const shouldLogTiming = shouldPrintDebug || options.logTimings\n const start = Date.now()\n const mem = shouldLogTiming ? process.memoryUsage() : null\n\n // Using a map for (officially supported) guaranteed insertion order\n let ast: t.File\n\n try {\n // @ts-ignore\n ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => tag,\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n }) => {\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n const viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n Object.assign(viewStyles, attr.value)\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null) => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n if (shouldPrintDebug) {\n // console.log(' style', attr.value)\n console.log(' classnames', newClassNames, finalClassNames)\n }\n // prettier-ignore\n const existing = finalClassNames.find((x) => x.type == 'StringLiteral') as t.StringLiteral | null\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' classnames (after)', finalClassNames.map(x => x['value']).join(' '))\n }\n break\n case 'attr':\n const val = attr.value\n if (t.isJSXSpreadAttribute(val)) {\n if (isSimpleSpread(val)) {\n finalClassNames.push(\n t.logicalExpression(\n '&&',\n val.argument,\n t.memberExpression(val.argument, t.identifier('className'))\n )\n )\n }\n } else if (val.name.name === 'className') {\n const value = val.value\n if (value) {\n try {\n const evaluatedValue = attemptEval(value)\n finalClassNames.push(t.stringLiteral(evaluatedValue))\n } catch (e) {\n finalClassNames.push(value['expression'])\n }\n }\n continue\n }\n finalAttrs.push(val)\n break\n case 'ternary':\n const mediaExtraction = extractMediaStyle(\n attr.value,\n jsxPath,\n extractor.getTamaguiConfig(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (mediaExtraction) {\n lastMediaImportance++\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n if (!mediaExtraction.ternaryWithoutMedia) {\n continue\n }\n }\n const ternary = mediaExtraction?.ternaryWithoutMedia || attr.value\n const consInfo = addStyles(ternary.consequent)\n const altInfo = addStyles(ternary.alternate)\n const cCN = consInfo.map((x) => x.identifier).join(' ')\n const aCN = altInfo.map((x) => x.identifier).join(' ')\n if (consInfo.length && altInfo.length) {\n finalClassNames.push(\n t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN))\n )\n } else {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(' ' + cCN),\n t.stringLiteral(' ' + aCN)\n )\n )\n }\n break\n }\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n const names = buildClassName(finalClassNames)\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [\n expr,\n ...simpleSpreads.map((val) => val.value['argument']),\n ])\n }\n\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier('className'), t.jsxExpressionContainer(expr))\n )\n }\n\n const comment = util.format('/* %s:%s (%s) */', filePath, lineNumbers, originalNodeName)\n\n for (const { className, rules } of finalStyles) {\n if (cssMap.has(className)) {\n if (comment) {\n const val = cssMap.get(className)!\n val.commentTexts.push(comment)\n cssMap.set(className, val)\n }\n } else if (rules.length) {\n if (rules.length > 1) {\n console.log(' rules error', { rules })\n throw new Error(`Shouldn't have more than one rule`)\n }\n cssMap.set(className, {\n css: rules[0],\n commentTexts: [comment],\n })\n }\n }\n },\n })\n\n if (!res || !res.modified) {\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => x.css)\n .join('\\n')\n .trim()\n\n if (styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = getRemainingRequest(loader)\n const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`\n ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)))\n }\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n console.log(\n '\\n -------- output code ------- \\n\\n',\n result.code\n .split('\\n')\n .filter((x) => !x.startsWith('//'))\n .join('\\n')\n )\n console.log('\\n -------- output style -------- \\n\\n', styles)\n }\n\n if (shouldLogTiming && mem) {\n // console.log(`${parseTime} / ${traverseTime} / ${generateTime}`)\n const memUsed =\n Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n // prettier-ignore\n console.log(` \uD83E\uDD5A ${basename(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\u00B7 ${`${res.optimized}`.padStart(4)} optimized \u00B7 ${res.flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ''}`)\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AAEA;AACA;AACA;AACA;AAEO,MAAM,0BAA0B;AAEvC,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA;AAGT,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAgBA;AACA,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM;AAAA;AAElB,YACE,OAAO,eAAe,YAAY,KAAK,WAAW,aAClD;AAGF,QAAM,kBAAkB,oBAAoB,QAAQ;AACpD,QAAM,QAAQ,KAAK;AACnB,QAAM,MAAM,kBAAkB,QAAQ,gBAAgB;AAGtD,MAAI;AAEJ,MAAI;AAEF,UAAM,WAAW;AAAA,WACV,KAAP;AACA,YAAQ,MAAM,sBAAsB;AACpC,UAAM;AAAA;AAGR,QAAM,SAAS,IAAI;AACnB,QAAM,iBAAkD;AAExD,QAAM,MAAM,UAAU,MAAM,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,OACG;AAAA,IACH,kBAAkB,CAAC,EAAE,UAAU;AAAA,IAC/B,cAAc,CAAC;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,UACI;AACJ,UAAI,kBAAqC;A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AAE,cAAc;AAAA;AAGnE,QAAM,SAAS,SACb,KACA;AAAA,IACE,SAAS;AAAA,IACT,UAAU;AAAA,IACV,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,YAAY;AAAA,KAEd;AAGF,MAAI,kBAAkB;AACpB,YAAQ,IACN,wCACA,OAAO,KACJ,MAAM,MACN,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,OAC5B,KAAK;AAEV,YAAQ,IAAI,0CAA0C;AAAA;AAGxD,MAAI,mBAAmB,KAAK;AAE1B,UAAM,UACJ,KAAK,MAAQ,SAAQ,cAAc,WAAW,IAAI,YAAY,OAAO,OAAQ,MAAM;AAErF,YAAQ,IAAI,eAAQ,SAAS,YAAY,SAAS,OAAO,GAAG,KAAK,QAAQ,QAAQ,SAAS,mBAAW,GAAG,IAAI,YAAY,SAAS,qBAAkB,IAAI,uBAAuB,UAAU,KAAK,QAAQ,cAAc;AAAA;AAGrN,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA;AAAA;AArSA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -255,7 +255,9 @@ function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
|
255
255
|
return true;
|
|
256
256
|
}
|
|
257
257
|
__name(isValidThemeHook, "isValidThemeHook");
|
|
258
|
-
var isInsideTamagui = /* @__PURE__ */ __name((srcName) =>
|
|
258
|
+
var isInsideTamagui = /* @__PURE__ */ __name((srcName) => {
|
|
259
|
+
return srcName.includes("/tamagui/_jsx") || srcName.includes("/core/src");
|
|
260
|
+
}, "isInsideTamagui");
|
|
259
261
|
|
|
260
262
|
// src/extractor/createEvaluator.ts
|
|
261
263
|
function createEvaluator({
|
|
@@ -715,6 +717,7 @@ function createExtractor() {
|
|
|
715
717
|
format: "cjs"
|
|
716
718
|
});
|
|
717
719
|
let loadedTamaguiConfig;
|
|
720
|
+
let hasLogged = false;
|
|
718
721
|
return {
|
|
719
722
|
getTamaguiConfig() {
|
|
720
723
|
return loadedTamaguiConfig;
|
|
@@ -728,7 +731,8 @@ function createExtractor() {
|
|
|
728
731
|
sourcePath = "",
|
|
729
732
|
onExtractTag,
|
|
730
733
|
getFlattenedNode,
|
|
731
|
-
|
|
734
|
+
disableExtraction,
|
|
735
|
+
disableDebugAttr
|
|
732
736
|
} = _b, props = __objRest(_b, [
|
|
733
737
|
"config",
|
|
734
738
|
"importsWhitelist",
|
|
@@ -737,7 +741,8 @@ function createExtractor() {
|
|
|
737
741
|
"sourcePath",
|
|
738
742
|
"onExtractTag",
|
|
739
743
|
"getFlattenedNode",
|
|
740
|
-
"
|
|
744
|
+
"disableExtraction",
|
|
745
|
+
"disableDebugAttr"
|
|
741
746
|
]);
|
|
742
747
|
if (sourcePath === "") {
|
|
743
748
|
throw new Error(`Must provide a source file name`);
|
|
@@ -751,7 +756,6 @@ function createExtractor() {
|
|
|
751
756
|
});
|
|
752
757
|
loadedTamaguiConfig = tamaguiConfig;
|
|
753
758
|
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
754
|
-
let doesUseValidImport = false;
|
|
755
759
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
756
760
|
const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
|
|
757
761
|
const validComponents = Object.keys(components).filter((key) => {
|
|
@@ -761,6 +765,7 @@ function createExtractor() {
|
|
|
761
765
|
obj[name] = components[name];
|
|
762
766
|
return obj;
|
|
763
767
|
}, {});
|
|
768
|
+
let doesUseValidImport = false;
|
|
764
769
|
for (const bodyPath of body) {
|
|
765
770
|
if (bodyPath.type !== "ImportDeclaration")
|
|
766
771
|
continue;
|
|
@@ -771,7 +776,6 @@ function createExtractor() {
|
|
|
771
776
|
const name = specifier.local.name;
|
|
772
777
|
return validComponents[name] || validHooks[name];
|
|
773
778
|
})) {
|
|
774
|
-
console.log("WHAT");
|
|
775
779
|
doesUseValidImport = true;
|
|
776
780
|
break;
|
|
777
781
|
}
|
|
@@ -790,6 +794,11 @@ function createExtractor() {
|
|
|
790
794
|
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
791
795
|
}, "callTraverse");
|
|
792
796
|
let programPath;
|
|
797
|
+
const res = {
|
|
798
|
+
flattened: 0,
|
|
799
|
+
optimized: 0,
|
|
800
|
+
modified: 0
|
|
801
|
+
};
|
|
793
802
|
callTraverse({
|
|
794
803
|
Program: {
|
|
795
804
|
enter(path3) {
|
|
@@ -822,8 +831,26 @@ function createExtractor() {
|
|
|
822
831
|
if (!component || !component.staticConfig) {
|
|
823
832
|
return;
|
|
824
833
|
}
|
|
825
|
-
const { staticConfig } = component;
|
|
826
834
|
const originalNodeName = node.name.name;
|
|
835
|
+
if (shouldPrintDebug) {
|
|
836
|
+
console.log(`
|
|
837
|
+
<${originalNodeName} />`);
|
|
838
|
+
}
|
|
839
|
+
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
840
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
841
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
842
|
+
const preName = componentName ? `${componentName}:` : "";
|
|
843
|
+
res.modified++;
|
|
844
|
+
node.attributes.unshift(t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
|
|
845
|
+
}
|
|
846
|
+
if (disableExtraction) {
|
|
847
|
+
if (!hasLogged) {
|
|
848
|
+
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
849
|
+
hasLogged = true;
|
|
850
|
+
}
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const { staticConfig } = component;
|
|
827
854
|
const isTextView = staticConfig.isText || false;
|
|
828
855
|
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
829
856
|
let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
|
|
@@ -845,21 +872,17 @@ function createExtractor() {
|
|
|
845
872
|
]);
|
|
846
873
|
const excludeProps = new Set(props.excludeProps ?? []);
|
|
847
874
|
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
848
|
-
const
|
|
849
|
-
if (
|
|
875
|
+
const res2 = excludeProps.has(name);
|
|
876
|
+
if (res2 && shouldPrintDebug)
|
|
850
877
|
console.log(` excluding ${name}`);
|
|
851
|
-
return
|
|
878
|
+
return res2;
|
|
852
879
|
}, "isExcludedProp");
|
|
853
880
|
const isDeoptedProp = /* @__PURE__ */ __name((name) => {
|
|
854
|
-
const
|
|
855
|
-
if (
|
|
881
|
+
const res2 = deoptProps.has(name);
|
|
882
|
+
if (res2 && shouldPrintDebug)
|
|
856
883
|
console.log(` deopting ${name}`);
|
|
857
|
-
return
|
|
884
|
+
return res2;
|
|
858
885
|
}, "isDeoptedProp");
|
|
859
|
-
if (shouldPrintDebug) {
|
|
860
|
-
console.log(`
|
|
861
|
-
<${originalNodeName} />`);
|
|
862
|
-
}
|
|
863
886
|
const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
864
887
|
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
865
888
|
tamaguiConfig,
|
|
@@ -932,11 +955,11 @@ function createExtractor() {
|
|
|
932
955
|
let isFlattened = false;
|
|
933
956
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path3) => {
|
|
934
957
|
try {
|
|
935
|
-
const
|
|
936
|
-
if (!
|
|
958
|
+
const res2 = evaluateAttribute(path3);
|
|
959
|
+
if (!res2) {
|
|
937
960
|
path3.remove();
|
|
938
961
|
}
|
|
939
|
-
return
|
|
962
|
+
return res2;
|
|
940
963
|
} catch (err) {
|
|
941
964
|
console.log("Error extracting attribute", err.message, err.stack);
|
|
942
965
|
console.log("node", path3.node);
|
|
@@ -959,7 +982,9 @@ function createExtractor() {
|
|
|
959
982
|
}
|
|
960
983
|
const propName = prop.key["name"];
|
|
961
984
|
if (!isStaticAttributeName(propName) && propName !== "tag") {
|
|
962
|
-
|
|
985
|
+
if (shouldPrintDebug) {
|
|
986
|
+
console.log(" not a valid style prop!", propName);
|
|
987
|
+
}
|
|
963
988
|
return false;
|
|
964
989
|
}
|
|
965
990
|
return true;
|
|
@@ -1024,7 +1049,9 @@ function createExtractor() {
|
|
|
1024
1049
|
if (!test)
|
|
1025
1050
|
throw new Error(`no test`);
|
|
1026
1051
|
if ([alt, cons].some((side) => side && !isExtractable(side))) {
|
|
1027
|
-
|
|
1052
|
+
if (shouldPrintDebug) {
|
|
1053
|
+
console.log("not extractable", alt, cons);
|
|
1054
|
+
}
|
|
1028
1055
|
return attr;
|
|
1029
1056
|
}
|
|
1030
1057
|
return [
|
|
@@ -1241,8 +1268,6 @@ function createExtractor() {
|
|
|
1241
1268
|
if (parentFn) {
|
|
1242
1269
|
modifiedComponents.add(parentFn);
|
|
1243
1270
|
}
|
|
1244
|
-
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
1245
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
1246
1271
|
let ternaries = [];
|
|
1247
1272
|
attrs = attrs.reduce((out, cur) => {
|
|
1248
1273
|
const next = attrs[attrs.indexOf(cur) + 1];
|
|
@@ -1437,20 +1462,13 @@ function createExtractor() {
|
|
|
1437
1462
|
if (shouldPrintDebug) {
|
|
1438
1463
|
console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
|
|
1439
1464
|
}
|
|
1440
|
-
if (shouldAddDebugProp) {
|
|
1441
|
-
const preName = componentName ? `${componentName}:` : "";
|
|
1442
|
-
attrs.unshift({
|
|
1443
|
-
type: "attr",
|
|
1444
|
-
value: t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `))
|
|
1445
|
-
});
|
|
1446
|
-
}
|
|
1447
1465
|
if (shouldFlatten) {
|
|
1448
1466
|
if (shouldPrintDebug) {
|
|
1449
1467
|
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
1450
1468
|
}
|
|
1451
1469
|
isFlattened = true;
|
|
1452
1470
|
node.name.name = flatNode;
|
|
1453
|
-
|
|
1471
|
+
res.flattened++;
|
|
1454
1472
|
if (closingElement) {
|
|
1455
1473
|
closingElement.name.name = flatNode;
|
|
1456
1474
|
}
|
|
@@ -1459,6 +1477,7 @@ function createExtractor() {
|
|
|
1459
1477
|
console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
|
|
1460
1478
|
console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
|
|
1461
1479
|
}
|
|
1480
|
+
res.optimized++;
|
|
1462
1481
|
onExtractTag({
|
|
1463
1482
|
attrs,
|
|
1464
1483
|
node,
|
|
@@ -1481,6 +1500,7 @@ function createExtractor() {
|
|
|
1481
1500
|
removeUnusedHooks(comp, shouldPrintDebug);
|
|
1482
1501
|
}
|
|
1483
1502
|
}
|
|
1503
|
+
return res;
|
|
1484
1504
|
}
|
|
1485
1505
|
};
|
|
1486
1506
|
}
|
|
@@ -1798,16 +1818,11 @@ function extractToClassNames({
|
|
|
1798
1818
|
}
|
|
1799
1819
|
const cssMap = new Map();
|
|
1800
1820
|
const existingHoists = {};
|
|
1801
|
-
|
|
1802
|
-
let optimized = 0;
|
|
1803
|
-
extractor.parse(ast, __spreadProps(__spreadValues({
|
|
1821
|
+
const res = extractor.parse(ast, __spreadProps(__spreadValues({
|
|
1804
1822
|
sourcePath,
|
|
1805
1823
|
shouldPrintDebug
|
|
1806
1824
|
}, options), {
|
|
1807
1825
|
getFlattenedNode: ({ tag }) => tag,
|
|
1808
|
-
onDidFlatten() {
|
|
1809
|
-
flattened++;
|
|
1810
|
-
},
|
|
1811
1826
|
onExtractTag: ({
|
|
1812
1827
|
attrs,
|
|
1813
1828
|
node,
|
|
@@ -1818,7 +1833,6 @@ function extractToClassNames({
|
|
|
1818
1833
|
lineNumbers,
|
|
1819
1834
|
programPath
|
|
1820
1835
|
}) => {
|
|
1821
|
-
optimized++;
|
|
1822
1836
|
let finalClassNames = [];
|
|
1823
1837
|
let finalAttrs = [];
|
|
1824
1838
|
let finalStyles = [];
|
|
@@ -1844,11 +1858,11 @@ function extractToClassNames({
|
|
|
1844
1858
|
if (!style)
|
|
1845
1859
|
return [];
|
|
1846
1860
|
const styleWithPrev = ensureNeededPrevStyle(style);
|
|
1847
|
-
const
|
|
1848
|
-
if (
|
|
1849
|
-
finalStyles = [...finalStyles, ...
|
|
1861
|
+
const res2 = (0, import_core_node3.getStylesAtomic)(styleWithPrev);
|
|
1862
|
+
if (res2.length) {
|
|
1863
|
+
finalStyles = [...finalStyles, ...res2];
|
|
1850
1864
|
}
|
|
1851
|
-
return
|
|
1865
|
+
return res2;
|
|
1852
1866
|
}, "addStyles");
|
|
1853
1867
|
let lastMediaImportance = 1;
|
|
1854
1868
|
for (const attr of attrs) {
|
|
@@ -1951,12 +1965,10 @@ function extractToClassNames({
|
|
|
1951
1965
|
}
|
|
1952
1966
|
}
|
|
1953
1967
|
}));
|
|
1954
|
-
if (!
|
|
1968
|
+
if (!res || !res.modified) {
|
|
1955
1969
|
return null;
|
|
1956
1970
|
}
|
|
1957
|
-
const styles = Array.from(cssMap.values()).map((x) =>
|
|
1958
|
-
return x.css;
|
|
1959
|
-
}).join("\n").trim();
|
|
1971
|
+
const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
|
|
1960
1972
|
if (styles) {
|
|
1961
1973
|
const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
|
|
1962
1974
|
const remReq = (0, import_loader_utils.getRemainingRequest)(loader);
|
|
@@ -1976,7 +1988,7 @@ function extractToClassNames({
|
|
|
1976
1988
|
}
|
|
1977
1989
|
if (shouldLogTiming && mem) {
|
|
1978
1990
|
const memUsed = Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10;
|
|
1979
|
-
console.log(` \u{1F95A} ${(0, import_path3.basename)(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\xB7 ${`${optimized}`.padStart(4)} optimized \xB7 ${flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ""}`);
|
|
1991
|
+
console.log(` \u{1F95A} ${(0, import_path3.basename)(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\xB7 ${`${res.optimized}`.padStart(4)} optimized \xB7 ${res.flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ""}`);
|
|
1980
1992
|
}
|
|
1981
1993
|
return {
|
|
1982
1994
|
ast,
|
|
@@ -1992,8 +2004,24 @@ var fs = __toModule(require("fs"));
|
|
|
1992
2004
|
var import_path4 = __toModule(require("path"));
|
|
1993
2005
|
function patchReactNativeWeb() {
|
|
1994
2006
|
const rootDir = require.resolve("react-native-web").replace(/\/dist.*/, "");
|
|
1995
|
-
|
|
1996
|
-
|
|
2007
|
+
const modulePath = import_path4.default.join(rootDir, "dist", "tamagui-exports.js");
|
|
2008
|
+
const cjsPath = import_path4.default.join(rootDir, "dist", "cjs", "tamagui-exports.js");
|
|
2009
|
+
const isEqual = (() => {
|
|
2010
|
+
let res = false;
|
|
2011
|
+
try {
|
|
2012
|
+
res = fs.readFileSync(modulePath, "utf-8") === moduleExports && fs.readFileSync(cjsPath, "utf-8") == cjsExports;
|
|
2013
|
+
} catch {
|
|
2014
|
+
res = false;
|
|
2015
|
+
}
|
|
2016
|
+
return res;
|
|
2017
|
+
})();
|
|
2018
|
+
if (!isEqual) {
|
|
2019
|
+
console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
|
|
2020
|
+
console.log(" > adding", modulePath);
|
|
2021
|
+
console.log(" > adding", cjsPath);
|
|
2022
|
+
fs.writeFileSync(modulePath, moduleExports);
|
|
2023
|
+
fs.writeFileSync(cjsPath, cjsExports);
|
|
2024
|
+
}
|
|
1997
2025
|
const moduleEntry = import_path4.default.join(rootDir, "dist", "index.js");
|
|
1998
2026
|
const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
|
|
1999
2027
|
if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
|
|
@@ -2014,7 +2042,6 @@ export const TamaguiExports = TExports
|
|
|
2014
2042
|
exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
|
|
2015
2043
|
// tamagui-patch-end
|
|
2016
2044
|
`);
|
|
2017
|
-
console.log(`Tamagui patched react-native-web`);
|
|
2018
2045
|
}
|
|
2019
2046
|
}
|
|
2020
2047
|
__name(patchReactNativeWeb, "patchReactNativeWeb");
|