@tamagui/static 1.0.1-beta.129 → 1.0.1-beta.132
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/extractor/createExtractor.js +8 -2
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +18 -6
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/getStaticBindingsForScope.js +0 -3
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/cjs/require.js +6 -5
- package/dist/cjs/require.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/createExtractor.js +8 -2
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +18 -6
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/getStaticBindingsForScope.js +0 -3
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/esm/require.js +6 -5
- package/dist/esm/require.js.map +2 -2
- package/dist/jsx/extractor/createExtractor.js +8 -2
- package/dist/jsx/extractor/createExtractor.js.map +2 -2
- package/dist/jsx/extractor/extractToClassNames.js +18 -6
- package/dist/jsx/extractor/extractToClassNames.js.map +2 -2
- package/dist/jsx/extractor/getStaticBindingsForScope.js +0 -3
- package/dist/jsx/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/jsx/require.js +6 -5
- package/dist/jsx/require.js.map +2 -2
- package/package.json +12 -20
- package/src/extractor/createExtractor.ts +9 -3
- package/src/extractor/extractToClassNames.ts +17 -5
- package/src/extractor/getStaticBindingsForScope.ts +0 -3
- package/src/require.ts +7 -5
- package/src/types.ts +3 -1
- package/types/require.d.ts +1 -1
- package/types/types.d.ts +3 -1
|
@@ -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 { ViewStyle } from 'react-native'\n\nimport { CONCAT_CLASSNAME_IMPORT } from '../constants'\nimport { ClassNameObject, StyleObject, TamaguiOptions, Ternary } 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 { getPrefixLogs } from './getPrefixLogs'\nimport { hoistClassNames } from './hoistClassNames'\nimport { logLines } from './logLines'\nimport { timer } from './timer'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport type ExtractedResponse = {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n}\n\nexport function extractToClassNames({\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n}: {\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean | 'verbose'\n}): ExtractedResponse | null {\n const tm = timer()\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 = options.logTimings ?? true\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 ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n tm.mark(`babel-parse`, shouldPrintDebug === 'verbose')\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n let hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n target: 'html',\n extractStyledDefinitions: true,\n onStyleRule(identifier, rules) {\n cssMap.set(`.${identifier}`, { css: rules.join(';'), commentTexts: [] })\n },\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n isFlattened,\n }) => {\n // reset hasFlattened\n const didFlattenThisTag = hasFlattened\n hasFlattened = false\n\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n let viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n viewStyles = {\n ...viewStyles,\n ...attr.value,\n }\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): StyleObject[] => {\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 if (!isFlattened) {\n const styles = getStylesAtomic(attr.value)\n\n finalStyles = [...finalStyles, ...styles]\n\n for (const style of styles) {\n // leave them as attributes\n const prop = style.pseudo ? `${style.property}-${style.pseudo}` : style.property\n finalAttrs.push(\n t.jsxAttribute(t.jsxIdentifier(prop), t.stringLiteral(style.identifier))\n )\n }\n } else {\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n const existing = finalClassNames.find(\n (x) => x.type == 'StringLiteral'\n ) as t.StringLiteral | null\n\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n }\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.getTamagui(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (shouldPrintDebug) {\n if (mediaExtraction) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction.mediaStyles.map((x) => x.identifier).join('.'))\n }\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, [])\n } else {\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n }\n break\n }\n }\n\n function addTernaryStyle(ternary: Ternary, a: any, b: any) {\n const cCN = a.map((x) => x.identifier).join(' ')\n const aCN = b.map((x) => x.identifier).join(' ')\n if (a.length && b.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 }\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' finalClassNames\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n let names = buildClassName(finalClassNames)\n if (t.isStringLiteral(names)) {\n names.value = concatClassName(names.value)\n }\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 if (!didFlattenThisTag) {\n // not flat\n } else {\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\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 { identifier, rules } of finalStyles) {\n const className = `.${identifier}`\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 && !res.optimized && !res.flattened && !res.styled)) {\n if (shouldPrintDebug) {\n console.log('no res or none modified', res)\n }\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => x.css)\n .join('\\n')\n .trim()\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n // this makes the debug output terrible, and i think sourcemap works already\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) {\n const memUsed = mem\n ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n : 0\n const path = basename(sourcePath)\n .replace(/\\.[jt]sx?$/, '')\n .slice(0, 22)\n .trim()\n .padStart(24)\n\n const numStyled = `${res.styled}`.padStart(3)\n const numOptimized = `${res.optimized}`.padStart(3)\n const numFound = `${res.found}`.padStart(3)\n const numFlattened = `${res.flattened}`.padStart(3)\n const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''\n const timing = Date.now() - start\n const timingWarning = timing > 150 ? '\u26A0\uFE0F' : timing > 150 ? '\u2622\uFE0F' : ''\n const timingStr = `${timing}ms ${timingWarning}`.padStart(6)\n const pre = getPrefixLogs(options)\n const memStr = memory ? `(${memory})` : ''\n console.log(\n `${pre} ${path} ${numFound} \u00B7 ${numOptimized} \u00B7 ${numFlattened} \u00B7 ${numStyled} ${timingStr} ${memStr}`\n )\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;AAGA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAChB;AAUO,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAO2B;AAnD7B;AAoDE,QAAM,KAAK,MAAM;AAEjB,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,YACE,OAAO,eAAe,YAAY,KAAK,WAAW,UAAU,GAC5D,qDACF;AAEA,QAAM,kBAAkB,cAAQ,eAAR,YAAsB;AAC9C,QAAM,QAAQ,KAAK,IAAI;AACvB,QAAM,MAAM,kBAAkB,QAAQ,YAAY,IAAI;AAGtD,MAAI;AAEJ,MAAI;AACF,UAAM,WAAW,MAAM;AAAA,EACzB,SAAS,KAAP;AACA,YAAQ,MAAM,sBAAsB,UAAU;AAC9C,UAAM;AAAA,EACR;AAEA,KAAG,KAAK,eAAe,qBAAqB,SAAS;AAErD,QAAM,SAAS,oBAAI,IAAqD;AACxE,QAAM,iBAAkD,CAAC;AAEzD,MAAI,eAAe;AAEnB,QAAM,MAAM,UAAU,MAAM,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,GAAG;AAAA,IACH,QAAQ;AAAA,IACR,0BAA0B;AAAA,IAC1B,YAAY,YAAY,OAAO;AAC7B,aAAO,IAAI,IAAI,cAAc,EAAE,KAAK,MAAM,KAAK,GAAG,GAAG,cAAc,CAAC,EAAE,CAAC;AAAA,IACzE;AAAA,IACA,kBAAkB,CAAC,EAAE,UAAU;AAC7B,qBAAe;AACf,aAAO;AAAA,IACT;AAAA,IACA,cAAc,CAAC;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,UACI;
|
|
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 { ViewStyle } from 'react-native'\n\nimport { CONCAT_CLASSNAME_IMPORT } from '../constants'\nimport { ClassNameObject, StyleObject, TamaguiOptions, Ternary } 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 { getPrefixLogs } from './getPrefixLogs'\nimport { hoistClassNames } from './hoistClassNames'\nimport { logLines } from './logLines'\nimport { timer } from './timer'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport type ExtractedResponse = {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n}\n\nexport function extractToClassNames({\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n}: {\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean | 'verbose'\n}): ExtractedResponse | null {\n const tm = timer()\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 = options.logTimings ?? true\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 ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n tm.mark(`babel-parse`, shouldPrintDebug === 'verbose')\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n let hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n target: 'html',\n extractStyledDefinitions: true,\n onStyleRule(identifier, rules) {\n cssMap.set(`.${identifier}`, { css: rules.join(';'), commentTexts: [] })\n },\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n isFlattened,\n completeProps,\n staticConfig,\n }) => {\n // reset hasFlattened\n const didFlattenThisTag = hasFlattened\n hasFlattened = false\n\n let finalClassNames: ClassNameObject[] = []\n const finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n let viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n viewStyles = {\n ...viewStyles,\n ...attr.value,\n }\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): StyleObject[] => {\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 if (!isFlattened) {\n const styles = getStylesAtomic(attr.value)\n\n finalStyles = [...finalStyles, ...styles]\n\n for (const style of styles) {\n // leave them as attributes\n const prop = style.pseudo ? `${style.property}-${style.pseudo}` : style.property\n finalAttrs.push(\n t.jsxAttribute(t.jsxIdentifier(prop), t.stringLiteral(style.identifier))\n )\n }\n } else {\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n const existing = finalClassNames.find(\n (x) => x.type == 'StringLiteral'\n ) as t.StringLiteral | null\n\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n }\n\n break\n }\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 }\n case 'ternary': {\n const mediaExtraction = extractMediaStyle(\n attr.value,\n jsxPath,\n extractor.getTamagui(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (shouldPrintDebug) {\n if (mediaExtraction) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction.mediaStyles.map((x) => x.identifier).join('.'))\n }\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, [])\n } else {\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n }\n break\n }\n }\n }\n\n function addTernaryStyle(ternary: Ternary, a: any, b: any) {\n const cCN = a.map((x) => x.identifier).join(' ')\n const aCN = b.map((x) => x.identifier).join(' ')\n if (a.length && b.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 }\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' finalClassNames\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\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 if (t.isStringLiteral(names)) {\n names.value = concatClassName(names.value)\n if (staticConfig.isText) {\n let family = completeProps.fontFamily\n if (family[0] === '$') {\n family = family.slice(1)\n }\n names.value = `font_${family} ${names.value}`\n }\n }\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 if (!didFlattenThisTag) {\n // not flat\n } else {\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\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 { identifier, rules } of finalStyles) {\n const className = `.${identifier}`\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 && !res.optimized && !res.flattened && !res.styled)) {\n if (shouldPrintDebug) {\n console.log('no res or none modified', res)\n }\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => x.css)\n .join('\\n')\n .trim()\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n // this makes the debug output terrible, and i think sourcemap works already\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) {\n const memUsed = mem\n ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n : 0\n const path = basename(sourcePath)\n .replace(/\\.[jt]sx?$/, '')\n .slice(0, 22)\n .trim()\n .padStart(24)\n\n const numStyled = `${res.styled}`.padStart(3)\n const numOptimized = `${res.optimized}`.padStart(3)\n const numFound = `${res.found}`.padStart(3)\n const numFlattened = `${res.flattened}`.padStart(3)\n const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''\n const timing = Date.now() - start\n const timingWarning = timing > 150 ? '\u26A0\uFE0F' : timing > 150 ? '\u2622\uFE0F' : ''\n const timingStr = `${timing}ms ${timingWarning}`.padStart(6)\n const pre = getPrefixLogs(options)\n const memStr = memory ? `(${memory})` : ''\n console.log(\n `${pre} ${path} ${numFound} \u00B7 ${numOptimized} \u00B7 ${numFlattened} \u00B7 ${numStyled} ${timingStr} ${memStr}`\n )\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;AAGA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAChB;AAUO,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAO2B;AAnD7B;AAoDE,QAAM,KAAK,MAAM;AAEjB,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AAO,UAAS,iBAAc,qBAAkB,qBAAkB,cAAc,aAAa,QAClG;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA,EACd;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -85,9 +85,6 @@ async function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bind
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
} catch (err) {
|
|
88
|
-
if (moduleName.includes("@tamagui/select")) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
88
|
console.warn(`\u26A0\uFE0F Failed evaluating module, continuing: ${moduleName}`);
|
|
92
89
|
}
|
|
93
90
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
|
|
4
|
-
"sourcesContent": ["import { fork, spawn } from 'child_process'\nimport { dirname, extname, join, resolve } from 'path'\n\nimport { Binding, NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport esbuild from 'esbuild'\nimport { existsSync } from 'fs-extra'\n\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { getSourceModule } from './getSourceModule'\n\nconst isLocalImport = (path: string) => path.startsWith('.') || path.startsWith('/')\n\nfunction resolveImportPath(sourcePath: string, path: string) {\n const sourceDir = dirname(sourcePath)\n if (isLocalImport(path)) {\n if (extname(path) === '') {\n path += '.js'\n }\n return resolve(sourceDir, path)\n }\n return path\n}\n\nconst cache = new Map()\nconst pending = new Map<string, Promise<any>>()\nsetInterval(() => {\n if (cache.size) {\n cache.clear()\n }\n}, 10)\n\nconst loadCmd = `${join(__dirname, 'loadFile.js')}`\nconst child = fork(loadCmd, [], {\n execArgv: ['-r', 'esbuild-register'],\n})\n\nfunction importModule(path: string) {\n if (pending.has(path)) {\n return pending.get(path)\n }\n const promise = new Promise((res, rej) => {\n if (cache.has(path)) {\n return cache.get(path)\n }\n const listener = (msg: any) => {\n if (!msg) return\n if (typeof msg !== 'string') return\n if (msg[0] === '-') {\n rej(new Error(msg.slice(1)))\n return\n }\n child.removeListener('message', listener)\n const val = JSON.parse(msg)\n cache.set(path, val)\n res(val)\n }\n child.once('message', listener)\n child.send(`${path.replace('.js', '')}`)\n })\n pending.set(path, promise)\n return promise\n}\n\nexport async function getStaticBindingsForScope(\n scope: NodePath<t.JSXElement>['scope'],\n whitelist: string[] = [],\n sourcePath: string,\n bindingCache: Record<string, string | null>,\n shouldPrintDebug: boolean | 'verbose'\n): Promise<Record<string, any>> {\n const bindings: Record<string, Binding> = scope.getAllBindings() as any\n const ret: Record<string, any> = {}\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' ', Object.keys(bindings).length, 'variables in scope')\n // .map(x => bindings[x].identifier?.name).join(', ')\n }\n\n // on react native at least it doesnt find some bindings? not sure why\n // lets add in whitelisted imports if they exist\n const program = scope.getProgramParent().block as t.Program\n for (const node of program.body) {\n if (t.isImportDeclaration(node)) {\n const importPath = node.source.value\n if (!node.specifiers.length) continue\n if (!isLocalImport(importPath)) {\n continue\n }\n const moduleName = resolveImportPath(sourcePath, importPath)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n if (!isOnWhitelist) continue\n try {\n const src = await importModule(moduleName)\n if (!src) continue\n for (const specifier of node.specifiers) {\n if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {\n if (typeof src[specifier.imported.name] !== 'undefined') {\n const val = src[specifier.local.name]\n ret[specifier.local.name] = val\n }\n }\n }\n } catch (err) {\n
|
|
5
|
-
"mappings": "AAAA;AACA;AAGA;AAIA;AACA;AAEA,MAAM,gBAAgB,CAAC,SAAiB,KAAK,WAAW,GAAG,KAAK,KAAK,WAAW,GAAG;AAEnF,2BAA2B,YAAoB,MAAc;AAC3D,QAAM,YAAY,QAAQ,UAAU;AACpC,MAAI,cAAc,IAAI,GAAG;AACvB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AEpB,YAAQ,IAAI,MAAM,OAAO,KAAK,QAAQ,EAAE,QAAQ,oBAAoB;AAAA,EAEtE;AAIA,QAAM,UAAU,MAAM,iBAAiB,EAAE;AACzC,aAAW,QAAQ,QAAQ,MAAM;AAC/B,QAAI,EAAE,oBAAoB,IAAI,GAAG;AAC/B,YAAM,aAAa,KAAK,OAAO;AAC/B,UAAI,CAAC,KAAK,WAAW;AAAQ;AAC7B,UAAI,CAAC,cAAc,UAAU,GAAG;AAC9B;AAAA,MACF;AACA,YAAM,aAAa,kBAAkB,YAAY,UAAU;AAC3D,YAAM,gBAAgB,UAAU,KAAK,CAAC,SAAS,WAAW,SAAS,IAAI,CAAC;AACxE,UAAI,CAAC;AAAe;AACpB,UAAI;AACF,cAAM,MAAM,MAAM,aAAa,UAAU;AACzC,YAAI,CAAC;AAAK;AACV,mBAAW,aAAa,KAAK,YAAY;AACvC,cAAI,EAAE,kBAAkB,SAAS,KAAK,EAAE,aAAa,UAAU,QAAQ,GAAG;AACxE,gBAAI,OAAO,IAAI,UAAU,SAAS,UAAU,aAAa;AACvD,oBAAM,MAAM,IAAI,UAAU,MAAM;AAChC,kBAAI,UAAU,MAAM,QAAQ;AAAA,YAC9B;AAAA,UACF;AAAA,QACF;AAAA,MACF,SAAS,KAAP;AACA,
|
|
4
|
+
"sourcesContent": ["import { fork, spawn } from 'child_process'\nimport { dirname, extname, join, resolve } from 'path'\n\nimport { Binding, NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport esbuild from 'esbuild'\nimport { existsSync } from 'fs-extra'\n\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { getSourceModule } from './getSourceModule'\n\nconst isLocalImport = (path: string) => path.startsWith('.') || path.startsWith('/')\n\nfunction resolveImportPath(sourcePath: string, path: string) {\n const sourceDir = dirname(sourcePath)\n if (isLocalImport(path)) {\n if (extname(path) === '') {\n path += '.js'\n }\n return resolve(sourceDir, path)\n }\n return path\n}\n\nconst cache = new Map()\nconst pending = new Map<string, Promise<any>>()\nsetInterval(() => {\n if (cache.size) {\n cache.clear()\n }\n}, 10)\n\nconst loadCmd = `${join(__dirname, 'loadFile.js')}`\nconst child = fork(loadCmd, [], {\n execArgv: ['-r', 'esbuild-register'],\n})\n\nfunction importModule(path: string) {\n if (pending.has(path)) {\n return pending.get(path)\n }\n const promise = new Promise((res, rej) => {\n if (cache.has(path)) {\n return cache.get(path)\n }\n const listener = (msg: any) => {\n if (!msg) return\n if (typeof msg !== 'string') return\n if (msg[0] === '-') {\n rej(new Error(msg.slice(1)))\n return\n }\n child.removeListener('message', listener)\n const val = JSON.parse(msg)\n cache.set(path, val)\n res(val)\n }\n child.once('message', listener)\n child.send(`${path.replace('.js', '')}`)\n })\n pending.set(path, promise)\n return promise\n}\n\nexport async function getStaticBindingsForScope(\n scope: NodePath<t.JSXElement>['scope'],\n whitelist: string[] = [],\n sourcePath: string,\n bindingCache: Record<string, string | null>,\n shouldPrintDebug: boolean | 'verbose'\n): Promise<Record<string, any>> {\n const bindings: Record<string, Binding> = scope.getAllBindings() as any\n const ret: Record<string, any> = {}\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' ', Object.keys(bindings).length, 'variables in scope')\n // .map(x => bindings[x].identifier?.name).join(', ')\n }\n\n // on react native at least it doesnt find some bindings? not sure why\n // lets add in whitelisted imports if they exist\n const program = scope.getProgramParent().block as t.Program\n for (const node of program.body) {\n if (t.isImportDeclaration(node)) {\n const importPath = node.source.value\n if (!node.specifiers.length) continue\n if (!isLocalImport(importPath)) {\n continue\n }\n const moduleName = resolveImportPath(sourcePath, importPath)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n if (!isOnWhitelist) continue\n try {\n const src = await importModule(moduleName)\n if (!src) continue\n for (const specifier of node.specifiers) {\n if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {\n if (typeof src[specifier.imported.name] !== 'undefined') {\n const val = src[specifier.local.name]\n ret[specifier.local.name] = val\n }\n }\n }\n } catch (err) {\n console.warn(`\u26A0\uFE0F Failed evaluating module, continuing: ${moduleName}`)\n }\n }\n }\n\n if (!bindingCache) {\n throw new Error('bindingCache is a required param')\n }\n\n for (const k in bindings) {\n const binding = bindings[k]\n\n // check to see if the item is a module\n const sourceModule = getSourceModule(k, binding)\n if (sourceModule) {\n if (!sourceModule.sourceModule) {\n continue\n }\n\n const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n\n // TODO we could cache this at the file level.. and check if its been touched since\n\n if (isOnWhitelist) {\n const src = importModule(moduleName)\n if (!src) {\n console.log(\n `\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`\n )\n return {}\n }\n if (sourceModule.destructured) {\n if (sourceModule.imported) {\n ret[k] = src[sourceModule.imported]\n }\n } else {\n ret[k] = src\n }\n }\n continue\n }\n\n const { parent, parentPath } = binding.path\n\n if (!t.isVariableDeclaration(parent) || parent.kind !== 'const') {\n continue\n }\n\n // pick out the right variable declarator\n const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k)\n\n // if init is not set, there's nothing to evaluate\n // TODO: handle spread syntax\n if (!dec || !dec.init) {\n continue\n }\n\n // missing start/end will break caching\n if (typeof dec.id.start !== 'number' || typeof dec.id.end !== 'number') {\n console.error('dec.id.start/end is not a number')\n continue\n }\n\n if (!t.isIdentifier(dec.id)) {\n console.error('dec is not an identifier')\n continue\n }\n\n const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`\n\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n\n // evaluate\n try {\n ret[k] = evaluateAstNode(dec.init, undefined, shouldPrintDebug)\n bindingCache[cacheKey] = ret[k]\n continue\n } catch {\n // skip\n }\n }\n\n return ret\n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A,IACF;AAGA,QAAI;AACF,UAAI,KAAK,gBAAgB,IAAI,MAAM,QAAW,gBAAgB;AAC9D,mBAAa,YAAY,IAAI;AAC7B;AAAA,IACF,QAAE;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/jsx/require.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
2
|
import { SHOULD_DEBUG } from "./constants";
|
|
3
3
|
const nameToPaths = {};
|
|
4
|
-
const
|
|
5
|
-
const og =
|
|
4
|
+
const Module = require("module");
|
|
5
|
+
const og = Module.prototype.require;
|
|
6
6
|
globalThis["ogRequire"] = og;
|
|
7
7
|
const getNameToPaths = () => nameToPaths;
|
|
8
8
|
let tries = 0;
|
|
@@ -10,14 +10,14 @@ setInterval(() => {
|
|
|
10
10
|
tries = 0;
|
|
11
11
|
}, 50);
|
|
12
12
|
function registerRequire() {
|
|
13
|
-
if (
|
|
13
|
+
if (Module.prototype.require !== globalThis["ogRequire"]) {
|
|
14
14
|
console.warn("didnt unregister before re-registering");
|
|
15
15
|
process.exit(1);
|
|
16
16
|
}
|
|
17
17
|
const proxyWorm = require("@tamagui/proxy-worm");
|
|
18
18
|
const rnw = require("react-native-web");
|
|
19
19
|
const core = require("@tamagui/core-node");
|
|
20
|
-
|
|
20
|
+
Module.prototype.require = function(path) {
|
|
21
21
|
var _a, _b, _c;
|
|
22
22
|
if (SHOULD_DEBUG) {
|
|
23
23
|
console.log("tamagui require", path);
|
|
@@ -68,9 +68,10 @@ function registerRequire() {
|
|
|
68
68
|
return proxyWorm;
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
+
return Module.prototype.require;
|
|
71
72
|
}
|
|
72
73
|
function unregisterRequire() {
|
|
73
|
-
|
|
74
|
+
Module.prototype.require = og;
|
|
74
75
|
}
|
|
75
76
|
export {
|
|
76
77
|
getNameToPaths,
|
package/dist/jsx/require.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/require.ts"],
|
|
4
|
-
"sourcesContent": ["import { join } from 'path'\n\nimport type { StaticConfig } from '@tamagui/core-node'\n\nimport { SHOULD_DEBUG } from './constants'\n\nconst nameToPaths = {}\nconst
|
|
5
|
-
"mappings": "AAAA;AAIA;AAEA,MAAM,cAAc,CAAC;AACrB,MAAM,
|
|
4
|
+
"sourcesContent": ["import { join } from 'path'\n\nimport type { StaticConfig } from '@tamagui/core-node'\n\nimport { SHOULD_DEBUG } from './constants'\n\nconst nameToPaths = {}\nconst Module = require('module')\nconst og = Module.prototype.require\nglobalThis['ogRequire'] = og\n\nexport const getNameToPaths = () => nameToPaths\n\n// just for catching egregious amounts of errors in a tight loop\nlet tries = 0\nsetInterval(() => {\n tries = 0\n}, 50)\n\nexport function registerRequire() {\n if (Module.prototype.require !== globalThis['ogRequire']) {\n console.warn('didnt unregister before re-registering')\n process.exit(1)\n }\n\n const proxyWorm = require('@tamagui/proxy-worm')\n const rnw = require('react-native-web')\n const core = require('@tamagui/core-node')\n\n Module.prototype.require = function (path: string) {\n if (SHOULD_DEBUG) {\n console.log('tamagui require', path)\n }\n if (path.endsWith('.css') || path.endsWith('.json') || path.endsWith('.ttf')) {\n return {}\n }\n if (\n path === '@gorhom/bottom-sheet' ||\n path.startsWith('react-native-reanimated') ||\n path === 'expo-linear-gradient' ||\n path === '@expo/vector-icons'\n ) {\n return proxyWorm\n }\n if (\n path.startsWith('react-native') &&\n // allow our rnw.tsx imports through\n !path.startsWith('react-native-web/dist/cjs/exports')\n ) {\n return rnw\n // return og('react-native-web')\n }\n if (path === '@tamagui/core') {\n return core\n }\n try {\n const out = og.apply(this, arguments)\n if (!nameToPaths[path]) {\n if (out && typeof out === 'object') {\n for (const key in out) {\n try {\n const conf = out[key]?.staticConfig as StaticConfig\n if (conf) {\n if (conf.componentName) {\n nameToPaths[conf.componentName] ??= new Set()\n const fullName = path.startsWith('.')\n ? join(`${this.path.replace(/dist(\\/cjs)?/, 'src')}`, path)\n : path\n nameToPaths[conf.componentName].add(fullName)\n } else {\n // console.log('no name component', path)\n }\n }\n } catch {\n // ok\n }\n }\n }\n }\n return out\n } catch (err: any) {\n if (SHOULD_DEBUG) {\n console.error(\n `Tamagui failed requiring ${path} from your tamagui.config.ts file, ignoring\\n`,\n err.message,\n err.stack\n )\n }\n const max = process.env.TAMAGUI_MAX_ERRORS ? +process.env.TAMAGUI_MAX_ERRORS : 200\n if (++tries > max) {\n console.log(\n `Too many errors loading design system, exiting (set TAMAGUI_MAX_ERRORS to override)..`\n )\n // avoid infinite loops\n process.exit(1)\n }\n // return proxyWorm by default\n return proxyWorm\n }\n }\n\n return Module.prototype.require\n}\n\nexport function unregisterRequire() {\n Module.prototype.require = og\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAIA;AAEA,MAAM,cAAc,CAAC;AACrB,MAAM,SAAS,QAAQ,QAAQ;AAC/B,MAAM,KAAK,OAAO,UAAU;AAC5B,WAAW,eAAe;AAEnB,MAAM,iBAAiB,MAAM;AAGpC,IAAI,QAAQ;AACZ,YAAY,MAAM;AAChB,UAAQ;AACV,GAAG,EAAE;AAEE,2BAA2B;AAChC,MAAI,OAAO,UAAU,YAAY,WAAW,cAAc;AACxD,YAAQ,KAAK,wCAAwC;AACrD,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,QAAM,YAAY,QAAQ,qBAAqB;AAC/C,QAAM,MAAM,QAAQ,kBAAkB;AACtC,QAAM,OAAO,QAAQ,oBAAoB;AAEzC,SAAO,UAAU,UAAU,SAAU,MAAc;AA7BrD;AA8BI,QAAI,cAAc;AAChB,cAAQ,IAAI,mBAAmB,IAAI;AAAA,IACrC;AACA,QAAI,KAAK,SAAS,MAAM,KAAK,KAAK,SAAS,OAAO,KAAK,KAAK,SAAS,MAAM,GAAG;AAC5E,aAAO,CAAC;AAAA,IACV;AACA,QACE,SAAS,0BACT,KAAK,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{
|
|
2
2
|
"name": "@tamagui/static",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.132",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -17,12 +17,8 @@
|
|
|
17
17
|
"watch": "tamagui-build --watch",
|
|
18
18
|
"clean": "tamagui-build clean",
|
|
19
19
|
"clean:build": "tamagui-build clean:build",
|
|
20
|
-
"
|
|
21
|
-
"test
|
|
22
|
-
"test:babel": "DISABLE_PRE_TEST=true yarn test tests/babel-test.tsx",
|
|
23
|
-
"test:debug": "NODE_ENV=test DEBUG_FILE=extract-specs.tsx DEBUG=1 yarn test",
|
|
24
|
-
"test:watch": "NODE_ENV=test yarn test --watch",
|
|
25
|
-
"test:update-snapshots": "NODE_ENV=test jest --updateSnapshot"
|
|
20
|
+
"pretest": "node -r esbuild-register ./tests/lib/preTest.js",
|
|
21
|
+
"test": "yarn pretest && vitest --config ../vite-plugin-internal/vite.config.ts --run --dom"
|
|
26
22
|
},
|
|
27
23
|
"tests": {
|
|
28
24
|
"parallel": true
|
|
@@ -38,13 +34,13 @@
|
|
|
38
34
|
"@babel/parser": "^7.15.7",
|
|
39
35
|
"@babel/traverse": "^7.15.4",
|
|
40
36
|
"@expo/match-media": "^0.3.0",
|
|
41
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
42
|
-
"@tamagui/core-node": "^1.0.1-beta.
|
|
43
|
-
"@tamagui/fake-react-native": "^1.0.1-beta.
|
|
44
|
-
"@tamagui/helpers": "^1.0.1-beta.
|
|
45
|
-
"@tamagui/patch-rnw": "^1.0.1-beta.
|
|
46
|
-
"@tamagui/proxy-worm": "^1.0.1-beta.
|
|
47
|
-
"@tamagui/shorthands": "^1.0.1-beta.
|
|
37
|
+
"@tamagui/build": "^1.0.1-beta.132",
|
|
38
|
+
"@tamagui/core-node": "^1.0.1-beta.132",
|
|
39
|
+
"@tamagui/fake-react-native": "^1.0.1-beta.132",
|
|
40
|
+
"@tamagui/helpers": "^1.0.1-beta.132",
|
|
41
|
+
"@tamagui/patch-rnw": "^1.0.1-beta.132",
|
|
42
|
+
"@tamagui/proxy-worm": "^1.0.1-beta.132",
|
|
43
|
+
"@tamagui/shorthands": "^1.0.1-beta.132",
|
|
48
44
|
"babel-literal-to-ast": "^2.1.0",
|
|
49
45
|
"esbuild": "^0.14.49",
|
|
50
46
|
"esbuild-register": "^3.3.3",
|
|
@@ -52,24 +48,19 @@
|
|
|
52
48
|
"fs-extra": "^10.1.0",
|
|
53
49
|
"invariant": "^2.2.4",
|
|
54
50
|
"lodash": "^4.17.21",
|
|
55
|
-
"tamagui": "^1.0.1-beta.
|
|
51
|
+
"tamagui": "^1.0.1-beta.132"
|
|
56
52
|
},
|
|
57
53
|
"devDependencies": {
|
|
58
54
|
"@babel/plugin-syntax-typescript": "^7.14.5",
|
|
59
55
|
"@babel/types": "^7.15.6",
|
|
60
56
|
"@dish/babel-preset": "^0.0.6",
|
|
61
|
-
"@testing-library/jest-dom": "^5.16.4",
|
|
62
57
|
"@testing-library/react": "^13.3.0",
|
|
63
|
-
"@types/jest": "*",
|
|
64
58
|
"@types/node": "^16.11.9",
|
|
65
59
|
"@types/react-native": "^0.69.2",
|
|
66
60
|
"@types/webpack": "^4.41.26",
|
|
67
61
|
"babel-loader": "^8.2.5",
|
|
68
62
|
"css-loader": "^5.2.4",
|
|
69
63
|
"esbuild-loader": "^2.19.0",
|
|
70
|
-
"jest": "^28.1.1",
|
|
71
|
-
"jest-dom": "^4.0.0",
|
|
72
|
-
"jest-environment-jsdom": "^28.1.1",
|
|
73
64
|
"null-loader": "^4.0.1",
|
|
74
65
|
"react": "*",
|
|
75
66
|
"react-dom": "*",
|
|
@@ -77,6 +68,7 @@
|
|
|
77
68
|
"react-test-renderer": "^18.2.0",
|
|
78
69
|
"style-loader": "^3.3.1",
|
|
79
70
|
"typescript": "^4.7.4",
|
|
71
|
+
"vitest": "^0.19.1",
|
|
80
72
|
"webpack": "^5.73.0"
|
|
81
73
|
},
|
|
82
74
|
"peerDependencies": {
|
|
@@ -261,6 +261,7 @@ export function createExtractor() {
|
|
|
261
261
|
},
|
|
262
262
|
},
|
|
263
263
|
|
|
264
|
+
// styled() calls
|
|
264
265
|
CallExpression(path) {
|
|
265
266
|
if (disable || disableExtraction || extractStyledDefinitions === false) {
|
|
266
267
|
return
|
|
@@ -451,8 +452,7 @@ export function createExtractor() {
|
|
|
451
452
|
|
|
452
453
|
// debug just one
|
|
453
454
|
const debugPropValue = node.attributes
|
|
454
|
-
.filter
|
|
455
|
-
// @ts-ignore
|
|
455
|
+
.filter(
|
|
456
456
|
(n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === 'debug'
|
|
457
457
|
)
|
|
458
458
|
.map((n) => {
|
|
@@ -1798,10 +1798,11 @@ export function createExtractor() {
|
|
|
1798
1798
|
|
|
1799
1799
|
// inlineWhenUnflattened
|
|
1800
1800
|
if (!shouldFlatten) {
|
|
1801
|
-
if (
|
|
1801
|
+
if (inlineWhenUnflattened.size) {
|
|
1802
1802
|
for (const [index, attr] of attrs.entries()) {
|
|
1803
1803
|
if (attr.type === 'style') {
|
|
1804
1804
|
for (const key in attr.value) {
|
|
1805
|
+
if (!inlineWhenUnflattened.has(key)) continue
|
|
1805
1806
|
const val = inlineWhenUnflattenedOGVals[key]
|
|
1806
1807
|
if (val) {
|
|
1807
1808
|
// delete the style
|
|
@@ -1809,6 +1810,9 @@ export function createExtractor() {
|
|
|
1809
1810
|
|
|
1810
1811
|
// and insert it before
|
|
1811
1812
|
attrs.splice(index - 1, 0, val.attr)
|
|
1813
|
+
} else {
|
|
1814
|
+
// just delete it, it was added during expansion but should be left inline
|
|
1815
|
+
delete attr.value[key]
|
|
1812
1816
|
}
|
|
1813
1817
|
}
|
|
1814
1818
|
}
|
|
@@ -1844,6 +1848,8 @@ export function createExtractor() {
|
|
|
1844
1848
|
originalNodeName,
|
|
1845
1849
|
isFlattened: shouldFlatten,
|
|
1846
1850
|
programPath,
|
|
1851
|
+
completeProps,
|
|
1852
|
+
staticConfig,
|
|
1847
1853
|
})
|
|
1848
1854
|
} finally {
|
|
1849
1855
|
if (debugPropValue) {
|
|
@@ -104,13 +104,15 @@ export function extractToClassNames({
|
|
|
104
104
|
lineNumbers,
|
|
105
105
|
programPath,
|
|
106
106
|
isFlattened,
|
|
107
|
+
completeProps,
|
|
108
|
+
staticConfig,
|
|
107
109
|
}) => {
|
|
108
110
|
// reset hasFlattened
|
|
109
111
|
const didFlattenThisTag = hasFlattened
|
|
110
112
|
hasFlattened = false
|
|
111
113
|
|
|
112
114
|
let finalClassNames: ClassNameObject[] = []
|
|
113
|
-
|
|
115
|
+
const finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []
|
|
114
116
|
let finalStyles: StyleObject[] = []
|
|
115
117
|
|
|
116
118
|
let viewStyles = {}
|
|
@@ -151,7 +153,7 @@ export function extractToClassNames({
|
|
|
151
153
|
let lastMediaImportance = 1
|
|
152
154
|
for (const attr of attrs) {
|
|
153
155
|
switch (attr.type) {
|
|
154
|
-
case 'style':
|
|
156
|
+
case 'style': {
|
|
155
157
|
if (!isFlattened) {
|
|
156
158
|
const styles = getStylesAtomic(attr.value)
|
|
157
159
|
|
|
@@ -179,7 +181,8 @@ export function extractToClassNames({
|
|
|
179
181
|
}
|
|
180
182
|
|
|
181
183
|
break
|
|
182
|
-
|
|
184
|
+
}
|
|
185
|
+
case 'attr': {
|
|
183
186
|
const val = attr.value
|
|
184
187
|
if (t.isJSXSpreadAttribute(val)) {
|
|
185
188
|
if (isSimpleSpread(val)) {
|
|
@@ -205,7 +208,8 @@ export function extractToClassNames({
|
|
|
205
208
|
}
|
|
206
209
|
finalAttrs.push(val)
|
|
207
210
|
break
|
|
208
|
-
|
|
211
|
+
}
|
|
212
|
+
case 'ternary': {
|
|
209
213
|
const mediaExtraction = extractMediaStyle(
|
|
210
214
|
attr.value,
|
|
211
215
|
jsxPath,
|
|
@@ -241,6 +245,7 @@ export function extractToClassNames({
|
|
|
241
245
|
]
|
|
242
246
|
}
|
|
243
247
|
break
|
|
248
|
+
}
|
|
244
249
|
}
|
|
245
250
|
}
|
|
246
251
|
|
|
@@ -271,9 +276,16 @@ export function extractToClassNames({
|
|
|
271
276
|
|
|
272
277
|
if (finalClassNames.length) {
|
|
273
278
|
// inserts the _cn variable and uses it for className
|
|
274
|
-
|
|
279
|
+
const names = buildClassName(finalClassNames)
|
|
275
280
|
if (t.isStringLiteral(names)) {
|
|
276
281
|
names.value = concatClassName(names.value)
|
|
282
|
+
if (staticConfig.isText) {
|
|
283
|
+
let family = completeProps.fontFamily
|
|
284
|
+
if (family[0] === '$') {
|
|
285
|
+
family = family.slice(1)
|
|
286
|
+
}
|
|
287
|
+
names.value = `font_${family} ${names.value}`
|
|
288
|
+
}
|
|
277
289
|
}
|
|
278
290
|
const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null
|
|
279
291
|
let expr = nameExpr
|
package/src/require.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { StaticConfig } from '@tamagui/core-node'
|
|
|
5
5
|
import { SHOULD_DEBUG } from './constants'
|
|
6
6
|
|
|
7
7
|
const nameToPaths = {}
|
|
8
|
-
const
|
|
9
|
-
const og =
|
|
8
|
+
const Module = require('module')
|
|
9
|
+
const og = Module.prototype.require
|
|
10
10
|
globalThis['ogRequire'] = og
|
|
11
11
|
|
|
12
12
|
export const getNameToPaths = () => nameToPaths
|
|
@@ -18,7 +18,7 @@ setInterval(() => {
|
|
|
18
18
|
}, 50)
|
|
19
19
|
|
|
20
20
|
export function registerRequire() {
|
|
21
|
-
if (
|
|
21
|
+
if (Module.prototype.require !== globalThis['ogRequire']) {
|
|
22
22
|
console.warn('didnt unregister before re-registering')
|
|
23
23
|
process.exit(1)
|
|
24
24
|
}
|
|
@@ -27,7 +27,7 @@ export function registerRequire() {
|
|
|
27
27
|
const rnw = require('react-native-web')
|
|
28
28
|
const core = require('@tamagui/core-node')
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
Module.prototype.require = function (path: string) {
|
|
31
31
|
if (SHOULD_DEBUG) {
|
|
32
32
|
console.log('tamagui require', path)
|
|
33
33
|
}
|
|
@@ -98,8 +98,10 @@ export function registerRequire() {
|
|
|
98
98
|
return proxyWorm
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
|
|
102
|
+
return Module.prototype.require
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
export function unregisterRequire() {
|
|
104
|
-
|
|
106
|
+
Module.prototype.require = og
|
|
105
107
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
|
-
import type { PseudoStyles, StyleObject } from '@tamagui/core-node'
|
|
3
|
+
import type { PseudoStyles, StaticConfig, StyleObject } from '@tamagui/core-node'
|
|
4
4
|
import { ViewStyle } from 'react-native'
|
|
5
5
|
|
|
6
6
|
export type { StyleObject } from '@tamagui/helpers'
|
|
@@ -64,6 +64,8 @@ export type ExtractTagProps = {
|
|
|
64
64
|
lineNumbers: string
|
|
65
65
|
filePath: string
|
|
66
66
|
isFlattened: boolean
|
|
67
|
+
completeProps: Record<string, any>
|
|
68
|
+
staticConfig: StaticConfig
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
export type ExtractorParseProps = TamaguiOptions & {
|
package/types/require.d.ts
CHANGED
package/types/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
|
-
import type { PseudoStyles, StyleObject } from '@tamagui/core-node';
|
|
3
|
+
import type { PseudoStyles, StaticConfig, StyleObject } from '@tamagui/core-node';
|
|
4
4
|
import { ViewStyle } from 'react-native';
|
|
5
5
|
export type { StyleObject } from '@tamagui/helpers';
|
|
6
6
|
export declare type ClassNameObject = t.StringLiteral | t.Expression;
|
|
@@ -52,6 +52,8 @@ export declare type ExtractTagProps = {
|
|
|
52
52
|
lineNumbers: string;
|
|
53
53
|
filePath: string;
|
|
54
54
|
isFlattened: boolean;
|
|
55
|
+
completeProps: Record<string, any>;
|
|
56
|
+
staticConfig: StaticConfig;
|
|
55
57
|
};
|
|
56
58
|
export declare type ExtractorParseProps = TamaguiOptions & {
|
|
57
59
|
target: 'native' | 'html';
|