@tamagui/static 1.0.1-beta.190 → 1.0.1-beta.191
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/constants.js +0 -3
- package/dist/constants.js.map +2 -2
- package/dist/extractor/buildClassName.js +20 -5
- package/dist/extractor/buildClassName.js.map +2 -2
- package/dist/extractor/createEvaluator.js +3 -3
- package/dist/extractor/createEvaluator.js.map +2 -2
- package/dist/extractor/createExtractor.js +63 -46
- package/dist/extractor/createExtractor.js.map +3 -3
- package/dist/extractor/ensureImportingConcat.js +4 -8
- package/dist/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/extractor/extractHelpers.js +37 -9
- package/dist/extractor/extractHelpers.js.map +3 -3
- package/dist/extractor/extractMediaStyle.js +11 -11
- package/dist/extractor/extractMediaStyle.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +5 -17
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/extractor/getStaticBindingsForScope.js +3 -3
- package/dist/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/extractor/loadTamagui.js +4 -4
- package/dist/extractor/loadTamagui.js.map +2 -2
- package/dist/types.js.map +1 -1
- package/package.json +16 -14
- package/src/constants.ts +0 -1
- package/src/extractor/buildClassName.ts +20 -4
- package/src/extractor/createEvaluator.ts +5 -5
- package/src/extractor/createExtractor.ts +42 -30
- package/src/extractor/ensureImportingConcat.ts +4 -11
- package/src/extractor/extractHelpers.ts +41 -7
- package/src/extractor/extractMediaStyle.ts +17 -10
- package/src/extractor/extractToClassNames.ts +6 -20
- package/src/extractor/getStaticBindingsForScope.ts +4 -4
- package/src/extractor/loadTamagui.ts +6 -6
- package/src/types.ts +5 -2
- package/types/constants.d.ts +0 -1
- package/types/extractor/buildClassName.d.ts +4 -1
- package/types/extractor/createEvaluator.d.ts +3 -3
- package/types/extractor/createExtractor.d.ts +1 -1
- package/types/extractor/extractHelpers.d.ts +5 -3
- package/types/extractor/extractMediaStyle.d.ts +3 -3
- package/types/types.d.ts +4 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/extractor/loadTamagui.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-console */\nimport { basename, dirname, join, relative, sep } from 'path'\n\nimport { Color, colorLog } from '@tamagui/cli-color'\nimport { getDefaultTamaguiConfig } from '@tamagui/config-default-node'\nimport type { StaticConfig, TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core-node'\nimport { createTamagui } from '@tamagui/core-node'\nimport esbuild from 'esbuild'\nimport { ensureDir, pathExists, stat, writeFile } from 'fs-extra'\n\nimport { SHOULD_DEBUG } from '../constants.js'\nimport { getNameToPaths, registerRequire, unregisterRequire } from '../require.js'\n\ntype NameToPaths = {\n [key: string]: Set<string>\n}\n\nexport type TamaguiProjectInfo = {\n components: Record<string, TamaguiComponent>\n tamaguiConfig: TamaguiInternalConfig\n nameToPaths: NameToPaths\n}\n\ntype Props = {\n components: string[]\n config?: string\n forceExports?: boolean\n bubbleErrors?: boolean\n}\n\nconst cache = {}\n\n// TODO needs a plugin for webpack / vite to run this once at startup and not again until changed...\n\nexport async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {\n const key = JSON.stringify(props)\n if (cache[key]) {\n if (cache[key] instanceof Promise) {\n return await cache[key]\n }\n return cache[key]\n }\n\n let resolver: Function = () => {}\n cache[key] = new Promise((res) => {\n resolver = res\n })\n\n const tmpDir = join(process.cwd(), 'dist', 'tamagui-node')\n const configOutPath = join(tmpDir, `tamagui.config.js`)\n const includesCore = props.components.includes('@tamagui/core')\n const baseComponents = props.components.filter((x) => x !== '@tamagui/core')\n const componentOutPaths = baseComponents.map((componentModule) =>\n join(\n tmpDir,\n `${componentModule\n .split(sep)\n .join('-')\n .replace(/[^a-z0-9]+/gi, '')}-components.config.js`\n )\n )\n\n const external = ['@tamagui/core', '@tamagui/core-node', 'react', 'react-dom']\n const configEntry = props.config ? join(process.cwd(), props.config) : ''\n\n if (process.env.DEBUG?.startsWith('tamagui')) {\n console.log(`Building config entry`, configEntry)\n }\n\n // build them to node-compat versions\n try {\n await ensureDir(tmpDir)\n } catch {\n //\n }\n\n colorLog(\n Color.FgYellow,\n `\nTamagui built config and components:`\n )\n colorLog(\n Color.Dim,\n `\n - Config: .${sep}${relative(process.cwd(), configOutPath)}\n - Components: .${sep}${relative(process.cwd(), componentOutPaths.join(', '))}\n`\n )\n\n await Promise.all([\n props.config\n ? buildTamaguiConfig(props, {\n entryPoints: [configEntry],\n external,\n outfile: configOutPath,\n })\n : null,\n ...baseComponents.map((componentModule, i) => {\n return buildTamaguiConfig(props, {\n entryPoints: [componentModule],\n external,\n outfile: componentOutPaths[i],\n })\n }),\n ])\n\n if (process.env.DEBUG?.startsWith('tamagui')) {\n console.log(`Built configs`)\n }\n\n const coreNode = require('@tamagui/core-node')\n\n registerRequire(props.bubbleErrors)\n const config = require(configOutPath).default\n unregisterRequire()\n\n const components = {\n ...loadComponents({\n ...props,\n components: componentOutPaths,\n }),\n ...(includesCore && gatherTamaguiComponentInfo([coreNode])),\n }\n\n cache[key] = {\n components,\n nameToPaths: {},\n tamaguiConfig: config,\n }\n\n // init core-node\n createTamagui(cache[key].tamaguiConfig)\n\n resolver(cache[key])\n\n return cache[key]\n}\n\nasync function buildTamaguiConfig(\n props: Props,\n options: Partial<esbuild.BuildOptions> & { outfile: string },\n aliases?: Record<string, string>\n) {\n const alias = require('@tamagui/core-node').aliasPlugin\n // until i do fancier things w plugins:\n const lockFile = join(dirname(options.outfile), basename(options.outfile, '.lock'))\n const lockStat = await stat(lockFile).catch(() => {\n // ok\n })\n const lockedMsAgo = !lockStat\n ? Infinity\n : new Date().getTime() - new Date(lockStat.mtime).getTime()\n if (lockedMsAgo < 500) {\n if (process.env.DEBUG?.startsWith('tamagui')) {\n console.log(`Waiting for existing build`, options.entryPoints)\n }\n let tries = 5\n while (tries--) {\n if (await pathExists(options.outfile)) {\n return\n } else {\n await new Promise((res) => setTimeout(res, 50))\n }\n }\n }\n\n void writeFile(lockFile, '')\n\n if (process.env.DEBUG?.startsWith('tamagui')) {\n console.log(`Building`, options.entryPoints)\n }\n\n const tsconfig = join(__dirname, '..', '..', 'tamagui.tsconfig.json')\n\n return esbuild.build({\n bundle: true,\n ...options,\n format: 'cjs',\n target: 'node18',\n jsx: 'transform',\n jsxFactory: 'react',\n allowOverwrite: true,\n keepNames: true,\n platform: 'node',\n tsconfig,\n loader: {\n '.js': 'jsx',\n },\n logLevel: 'warning',\n plugins: [\n {\n name: 'external',\n setup(build) {\n build.onResolve({ filter: /@tamagui\\/core/ }, (args) => {\n return {\n path: '@tamagui/core-node',\n external: true,\n }\n })\n\n build.onResolve({ filter: /^(react-native|react-native\\/.*)$/ }, (args) => {\n return {\n path: 'react-native-web-lite',\n external: true,\n }\n })\n },\n },\n alias({\n 'react-native-svg': require.resolve('@tamagui/react-native-svg'),\n 'react-native-safe-area-context': require.resolve('@tamagui/fake-react-native'),\n 'react-native-gesture-handler': require.resolve('@tamagui/proxy-worm'),\n 'react-native-reanimated': require.resolve('@tamagui/proxy-worm'),\n ...aliases,\n }),\n ],\n })\n}\n\nconst esbuildOptions: esbuild.BuildOptions = {\n target: 'es2019',\n format: 'cjs',\n jsx: 'transform',\n}\n\n// loads in-process using esbuild-register\nexport function loadTamaguiSync(props: Props): TamaguiProjectInfo {\n const key = JSON.stringify(props)\n if (cache[key]) {\n return cache[key]\n }\n\n const { unregister } = require('esbuild-register/dist/node').register(esbuildOptions)\n\n try {\n registerRequire(props.bubbleErrors)\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = process.env.NODE_ENV === 'development'\n }\n\n try {\n // import config\n let tamaguiConfig: TamaguiInternalConfig | null = null\n\n if (props.config) {\n const configPath = join(process.cwd(), props.config)\n const exp = require(configPath)\n tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig\n if (!tamaguiConfig || !tamaguiConfig.parsed) {\n const confPath = require.resolve(configPath)\n throw new Error(`Can't find valid config in ${confPath}`)\n }\n }\n\n const components = loadComponents(props)\n\n if (process.env.DEBUG === 'tamagui') {\n console.log(`components`, components)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n\n // set up core-node\n if (tamaguiConfig) {\n createTamagui(tamaguiConfig)\n }\n\n cache[key] = {\n components,\n tamaguiConfig,\n nameToPaths: getNameToPaths(),\n }\n } catch (err) {\n if (props.bubbleErrors) {\n throw err\n }\n\n if (err instanceof Error) {\n console.warn(\n `Error loading tamagui.config.ts (set DEBUG=tamagui to see full stack), running tamagui without custom config`\n )\n console.log(`\\n\\n ${err.message}\\n\\n`)\n if (SHOULD_DEBUG) {\n console.log(err.stack)\n }\n } else {\n console.error(`Error loading tamagui.config.ts`, err)\n }\n return {\n components: {},\n tamaguiConfig: getDefaultTamaguiConfig(),\n nameToPaths: {},\n }\n }\n\n return cache[key]\n } catch (err) {\n if (!props.bubbleErrors) {\n console.log('Error loading Tamagui', err)\n }\n throw err\n } finally {\n unregister()\n unregisterRequire()\n }\n}\n\nfunction interopDefaultExport(mod: any) {\n return mod?.default ?? mod\n}\n\nconst cacheComponents = {}\n\nfunction loadComponents(props: Props) {\n const componentsModules = props.components\n const key = componentsModules.join('')\n if (cacheComponents[key]) {\n return cacheComponents[key]\n }\n try {\n const requiredModules = componentsModules.map((name) => {\n return interopDefaultExport(require(name))\n })\n const res = gatherTamaguiComponentInfo(requiredModules)\n cacheComponents[key] = res\n return res\n } catch (err: any) {\n if (props.bubbleErrors) {\n throw err\n }\n console.log(`Tamagui error bundling components`, err.message, err.stack)\n }\n}\n\nfunction gatherTamaguiComponentInfo(packages: any[]) {\n const components = {}\n for (const exported of packages) {\n try {\n for (const componentName in exported) {\n const found = getTamaguiComponent(componentName, exported[componentName])\n if (found) {\n // remove non-stringifyable\n const { Component, reactNativeWebComponent, ...sc } = found.staticConfig\n Object.assign(components, { [componentName]: { staticConfig: sc } })\n }\n }\n } catch (err) {\n console.error(`Tamagui failed getting components`)\n if (err instanceof Error) {\n console.error(err.message, err.stack)\n } else {\n console.error(err)\n }\n }\n }\n return components\n}\n\nfunction getTamaguiComponent(\n name: string,\n Component: any\n): undefined | { staticConfig: StaticConfig } {\n if (name[0].toUpperCase() !== name[0]) {\n return\n }\n const staticConfig = Component?.staticConfig as StaticConfig | undefined\n if (staticConfig) {\n return Component\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAuD;AAEvD,uBAAgC;AAChC,iCAAwC;AAExC,uBAA8B;AAC9B,qBAAoB;AACpB,sBAAuD;AAEvD,uBAA6B;AAC7B,qBAAmE;AAmBnE,MAAM,QAAQ,CAAC;AAIf,eAAsB,YAAY,OAA2C;AAlC7E;AAmCE,QAAM,MAAM,KAAK,UAAU,KAAK;AAChC,MAAI,MAAM,MAAM;AACd,QAAI,MAAM,gBAAgB,SAAS;AACjC,aAAO,MAAM,MAAM;AAAA,IACrB;AACA,WAAO,MAAM;AAAA,EACf;AAEA,MAAI,WAAqB,MAAM;AAAA,EAAC;AAChC,QAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ;AAChC,eAAW;AAAA,EACb,CAAC;AAED,QAAM,aAAS,kBAAK,QAAQ,IAAI,GAAG,QAAQ,cAAc;AACzD,QAAM,oBAAgB,kBAAK,QAAQ,mBAAmB;AACtD,QAAM,eAAe,MAAM,WAAW,SAAS,eAAe;AAC9D,QAAM,iBAAiB,MAAM,WAAW,OAAO,CAAC,MAAM,MAAM,eAAe;AAC3E,QAAM,oBAAoB,eAAe;AAAA,IAAI,CAAC,wBAC5C;AAAA,MACE;AAAA,MACA,GAAG,gBACA,MAAM,eAAG,EACT,KAAK,GAAG,EACR,QAAQ,gBAAgB,EAAE;AAAA,IAC/B;AAAA,EACF;AAEA,QAAM,WAAW,CAAC,iBAAiB,sBAAsB,SAAS,WAAW;AAC7E,QAAM,cAAc,MAAM,aAAS,kBAAK,QAAQ,IAAI,GAAG,MAAM,MAAM,IAAI;AAEvE,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\nimport { basename, dirname, join, relative, sep } from 'path'\n\nimport { Color, colorLog } from '@tamagui/cli-color'\nimport { getDefaultTamaguiConfig } from '@tamagui/config-default-node'\nimport type { StaticConfig, TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core-node'\nimport { createTamagui } from '@tamagui/core-node'\nimport esbuild from 'esbuild'\nimport { ensureDir, pathExists, stat, writeFile } from 'fs-extra'\n\nimport { SHOULD_DEBUG } from '../constants.js'\nimport { getNameToPaths, registerRequire, unregisterRequire } from '../require.js'\n\ntype NameToPaths = {\n [key: string]: Set<string>\n}\n\nexport type TamaguiProjectInfo = {\n components: Record<string, TamaguiComponent>\n tamaguiConfig: TamaguiInternalConfig\n nameToPaths: NameToPaths\n}\n\ntype Props = {\n components: string[]\n config?: string\n forceExports?: boolean\n bubbleErrors?: boolean\n}\n\nconst cache = {}\n\n// TODO needs a plugin for webpack / vite to run this once at startup and not again until changed...\n\nexport async function loadTamagui(props: Props): Promise<TamaguiProjectInfo> {\n const key = JSON.stringify(props)\n if (cache[key]) {\n if (cache[key] instanceof Promise) {\n return await cache[key]\n }\n return cache[key]\n }\n\n let resolver: Function = () => {}\n cache[key] = new Promise((res) => {\n resolver = res\n })\n\n const tmpDir = join(process.cwd(), 'dist', 'tamagui-node')\n const configOutPath = join(tmpDir, `tamagui.config.js`)\n const includesCore = props.components.includes('@tamagui/core')\n const baseComponents = props.components.filter((x) => x !== '@tamagui/core')\n const componentOutPaths = baseComponents.map((componentModule) =>\n join(\n tmpDir,\n `${componentModule\n .split(sep)\n .join('-')\n .replace(/[^a-z0-9]+/gi, '')}-components.config.js`\n )\n )\n\n const external = ['@tamagui/core', '@tamagui/core-node', 'react', 'react-dom']\n const configEntry = props.config ? join(process.cwd(), props.config) : ''\n\n if (process.env.NODE_ENV === 'development' && process.env.DEBUG?.startsWith('tamagui')) {\n console.log(`Building config entry`, configEntry)\n }\n\n // build them to node-compat versions\n try {\n await ensureDir(tmpDir)\n } catch {\n //\n }\n\n colorLog(\n Color.FgYellow,\n `\nTamagui built config and components:`\n )\n colorLog(\n Color.Dim,\n `\n - Config: .${sep}${relative(process.cwd(), configOutPath)}\n - Components: .${sep}${relative(process.cwd(), componentOutPaths.join(', '))}\n`\n )\n\n await Promise.all([\n props.config\n ? buildTamaguiConfig(props, {\n entryPoints: [configEntry],\n external,\n outfile: configOutPath,\n })\n : null,\n ...baseComponents.map((componentModule, i) => {\n return buildTamaguiConfig(props, {\n entryPoints: [componentModule],\n external,\n outfile: componentOutPaths[i],\n })\n }),\n ])\n\n const coreNode = require('@tamagui/core-node')\n\n registerRequire(props.bubbleErrors)\n const config = require(configOutPath).default\n unregisterRequire()\n\n const components = {\n ...loadComponents({\n ...props,\n components: componentOutPaths,\n }),\n ...(includesCore && gatherTamaguiComponentInfo([coreNode])),\n }\n\n if (process.env.NODE_ENV === 'development' && process.env.DEBUG?.startsWith('tamagui')) {\n console.log('Loaded components', components)\n }\n\n cache[key] = {\n components,\n nameToPaths: {},\n tamaguiConfig: config,\n }\n\n // init core-node\n createTamagui(cache[key].tamaguiConfig)\n\n resolver(cache[key])\n\n return cache[key]\n}\n\nasync function buildTamaguiConfig(\n props: Props,\n options: Partial<esbuild.BuildOptions> & { outfile: string },\n aliases?: Record<string, string>\n) {\n const alias = require('@tamagui/core-node').aliasPlugin\n // until i do fancier things w plugins:\n const lockFile = join(dirname(options.outfile), basename(options.outfile, '.lock'))\n const lockStat = await stat(lockFile).catch(() => {\n // ok\n })\n const lockedMsAgo = !lockStat\n ? Infinity\n : new Date().getTime() - new Date(lockStat.mtime).getTime()\n if (lockedMsAgo < 500) {\n if (process.env.DEBUG?.startsWith('tamagui')) {\n console.log(`Waiting for existing build`, options.entryPoints)\n }\n let tries = 5\n while (tries--) {\n if (await pathExists(options.outfile)) {\n return\n } else {\n await new Promise((res) => setTimeout(res, 50))\n }\n }\n }\n\n void writeFile(lockFile, '')\n\n if (process.env.DEBUG?.startsWith('tamagui')) {\n console.log(`Building`, options.entryPoints)\n }\n\n const tsconfig = join(__dirname, '..', '..', 'tamagui.tsconfig.json')\n\n return esbuild.build({\n bundle: true,\n ...options,\n format: 'cjs',\n target: 'node18',\n jsx: 'transform',\n jsxFactory: 'react',\n allowOverwrite: true,\n keepNames: true,\n platform: 'node',\n tsconfig,\n loader: {\n '.js': 'jsx',\n },\n logLevel: 'warning',\n plugins: [\n {\n name: 'external',\n setup(build) {\n build.onResolve({ filter: /@tamagui\\/core/ }, (args) => {\n return {\n path: '@tamagui/core-node',\n external: true,\n }\n })\n\n build.onResolve({ filter: /^(react-native|react-native\\/.*)$/ }, (args) => {\n return {\n path: 'react-native-web-lite',\n external: true,\n }\n })\n },\n },\n alias({\n 'react-native-svg': require.resolve('@tamagui/react-native-svg'),\n 'react-native-safe-area-context': require.resolve('@tamagui/fake-react-native'),\n 'react-native-gesture-handler': require.resolve('@tamagui/proxy-worm'),\n 'react-native-reanimated': require.resolve('@tamagui/proxy-worm'),\n ...aliases,\n }),\n ],\n })\n}\n\nconst esbuildOptions: esbuild.BuildOptions = {\n target: 'es2019',\n format: 'cjs',\n jsx: 'transform',\n}\n\n// loads in-process using esbuild-register\nexport function loadTamaguiSync(props: Props): TamaguiProjectInfo {\n const key = JSON.stringify(props)\n if (cache[key]) {\n return cache[key]\n }\n\n const { unregister } = require('esbuild-register/dist/node').register(esbuildOptions)\n\n try {\n registerRequire(props.bubbleErrors)\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = process.env.NODE_ENV === 'development'\n }\n\n try {\n // import config\n let tamaguiConfig: TamaguiInternalConfig | null = null\n\n if (props.config) {\n const configPath = join(process.cwd(), props.config)\n const exp = require(configPath)\n tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig\n if (!tamaguiConfig || !tamaguiConfig.parsed) {\n const confPath = require.resolve(configPath)\n throw new Error(`Can't find valid config in ${confPath}`)\n }\n }\n\n const components = loadComponents(props)\n\n if (process.env.DEBUG === 'tamagui') {\n console.log(`components`, components)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n\n // set up core-node\n if (tamaguiConfig) {\n createTamagui(tamaguiConfig as any)\n }\n\n cache[key] = {\n components,\n tamaguiConfig,\n nameToPaths: getNameToPaths(),\n }\n } catch (err) {\n if (props.bubbleErrors) {\n throw err\n }\n\n if (err instanceof Error) {\n console.warn(\n `Error loading tamagui.config.ts (set DEBUG=tamagui to see full stack), running tamagui without custom config`\n )\n console.log(`\\n\\n ${err.message}\\n\\n`)\n if (SHOULD_DEBUG) {\n console.log(err.stack)\n }\n } else {\n console.error(`Error loading tamagui.config.ts`, err)\n }\n return {\n components: {},\n tamaguiConfig: getDefaultTamaguiConfig(),\n nameToPaths: {},\n }\n }\n\n return cache[key]\n } catch (err) {\n if (!props.bubbleErrors) {\n console.log('Error loading Tamagui', err)\n }\n throw err\n } finally {\n unregister()\n unregisterRequire()\n }\n}\n\nfunction interopDefaultExport(mod: any) {\n return mod?.default ?? mod\n}\n\nconst cacheComponents = {}\n\nfunction loadComponents(props: Props) {\n const componentsModules = props.components\n const key = componentsModules.join('')\n if (cacheComponents[key]) {\n return cacheComponents[key]\n }\n try {\n const requiredModules = componentsModules.map((name) => {\n return interopDefaultExport(require(name))\n })\n const res = gatherTamaguiComponentInfo(requiredModules)\n cacheComponents[key] = res\n return res\n } catch (err: any) {\n if (props.bubbleErrors) {\n throw err\n }\n console.log(`Tamagui error bundling components`, err.message, err.stack)\n }\n}\n\nfunction gatherTamaguiComponentInfo(packages: any[]) {\n const components = {}\n for (const exported of packages) {\n try {\n for (const componentName in exported) {\n const found = getTamaguiComponent(componentName, exported[componentName])\n if (found) {\n // remove non-stringifyable\n const { Component, reactNativeWebComponent, ...sc } = found.staticConfig\n Object.assign(components, { [componentName]: { staticConfig: sc } })\n }\n }\n } catch (err) {\n console.error(`Tamagui failed getting components`)\n if (err instanceof Error) {\n console.error(err.message, err.stack)\n } else {\n console.error(err)\n }\n }\n }\n return components\n}\n\nfunction getTamaguiComponent(\n name: string,\n Component: any\n): undefined | { staticConfig: StaticConfig } {\n if (name[0].toUpperCase() !== name[0]) {\n return\n }\n const staticConfig = Component?.staticConfig as StaticConfig | undefined\n if (staticConfig) {\n return Component\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAuD;AAEvD,uBAAgC;AAChC,iCAAwC;AAExC,uBAA8B;AAC9B,qBAAoB;AACpB,sBAAuD;AAEvD,uBAA6B;AAC7B,qBAAmE;AAmBnE,MAAM,QAAQ,CAAC;AAIf,eAAsB,YAAY,OAA2C;AAlC7E;AAmCE,QAAM,MAAM,KAAK,UAAU,KAAK;AAChC,MAAI,MAAM,MAAM;AACd,QAAI,MAAM,gBAAgB,SAAS;AACjC,aAAO,MAAM,MAAM;AAAA,IACrB;AACA,WAAO,MAAM;AAAA,EACf;AAEA,MAAI,WAAqB,MAAM;AAAA,EAAC;AAChC,QAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ;AAChC,eAAW;AAAA,EACb,CAAC;AAED,QAAM,aAAS,kBAAK,QAAQ,IAAI,GAAG,QAAQ,cAAc;AACzD,QAAM,oBAAgB,kBAAK,QAAQ,mBAAmB;AACtD,QAAM,eAAe,MAAM,WAAW,SAAS,eAAe;AAC9D,QAAM,iBAAiB,MAAM,WAAW,OAAO,CAAC,MAAM,MAAM,eAAe;AAC3E,QAAM,oBAAoB,eAAe;AAAA,IAAI,CAAC,wBAC5C;AAAA,MACE;AAAA,MACA,GAAG,gBACA,MAA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
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["import type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { PseudoStyles, StaticConfig } from '@tamagui/core-node'\nimport type { StyleObject } from '@tamagui/helpers'\nimport type { TamaguiOptions } from '@tamagui/helpers-node'\nimport type { ViewStyle } from 'react-native'\n\nexport type { TamaguiOptions } from '@tamagui/helpers-node'\n\nexport type { StyleObject } from '@tamagui/helpers'\n\nexport type ClassNameObject = t.StringLiteral | t.Expression\n\nexport interface CacheObject {\n [key: string]: any\n}\n\nexport interface LogOptions {\n clear?: boolean\n timestamp?: boolean\n error?: Error | null\n}\n\nexport interface Logger {\n info(msg: string, options?: LogOptions): void\n warn(msg: string, options?: LogOptions): void\n error(msg: string, options?: LogOptions): void\n}\n\nexport type ExtractorOptions = {\n logger?: Logger\n}\n\nexport type ExtractedAttrAttr = {\n type: 'attr'\n value: t.JSXAttribute | t.JSXSpreadAttribute\n}\n\nexport type ExtractedAttrStyle = {\n type: 'style'\n value: ViewStyle & PseudoStyles\n attr?: t.JSXAttribute | t.JSXSpreadAttribute\n name?: string\n}\n\nexport type ExtractedAttr =\n | ExtractedAttrAttr\n | { type: 'ternary'; value: Ternary }\n | ExtractedAttrStyle\n\nexport type ExtractTagProps = {\n attrs: ExtractedAttr[]\n node: t.JSXOpeningElement\n attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any\n jsxPath: NodePath<t.JSXElement>\n programPath: NodePath<t.Program>\n originalNodeName: string\n lineNumbers: string\n filePath: string\n isFlattened: boolean\n completeProps: Record<string, any>\n staticConfig: StaticConfig\n}\n\nexport type
|
|
4
|
+
"sourcesContent": ["import type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { PseudoStyles, StaticConfig } from '@tamagui/core-node'\nimport type { StyleObject } from '@tamagui/helpers'\nimport type { TamaguiOptions } from '@tamagui/helpers-node'\nimport type { ViewStyle } from 'react-native'\n\nexport type { TamaguiOptions } from '@tamagui/helpers-node'\n\nexport type { StyleObject } from '@tamagui/helpers'\n\nexport type ClassNameObject = t.StringLiteral | t.Expression\n\nexport interface CacheObject {\n [key: string]: any\n}\n\nexport interface LogOptions {\n clear?: boolean\n timestamp?: boolean\n error?: Error | null\n}\n\nexport interface Logger {\n info(msg: string, options?: LogOptions): void\n warn(msg: string, options?: LogOptions): void\n error(msg: string, options?: LogOptions): void\n}\n\nexport type ExtractorOptions = {\n logger?: Logger\n}\n\nexport type ExtractedAttrAttr = {\n type: 'attr'\n value: t.JSXAttribute | t.JSXSpreadAttribute\n}\n\nexport type ExtractedAttrStyle = {\n type: 'style'\n value: ViewStyle & PseudoStyles\n attr?: t.JSXAttribute | t.JSXSpreadAttribute\n name?: string\n}\n\nexport type ExtractedAttr =\n | ExtractedAttrAttr\n | { type: 'ternary'; value: Ternary }\n | ExtractedAttrStyle\n\nexport type ExtractTagProps = {\n attrs: ExtractedAttr[]\n node: t.JSXOpeningElement\n attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any\n jsxPath: NodePath<t.JSXElement>\n programPath: NodePath<t.Program>\n originalNodeName: string\n lineNumbers: string\n filePath: string\n isFlattened: boolean\n completeProps: Record<string, any>\n staticConfig: StaticConfig\n}\n\nexport type TamaguiOptionsWithFileInfo = TamaguiOptions & {\n sourcePath: string\n}\n\nexport type ExtractorParseProps = TamaguiOptionsWithFileInfo & {\n target: 'native' | 'html'\n shouldPrintDebug?: boolean | 'verbose'\n onExtractTag: (props: ExtractTagProps) => void\n getFlattenedNode?: (props: { isTextView: boolean; tag: string }) => string\n extractStyledDefinitions?: boolean\n // identifer, rule\n onStyleRule?: (identifier: string, rules: string[]) => void\n}\n\nexport interface Ternary {\n test: t.Expression\n // shorthand props that don't use hooks\n inlineMediaQuery?: string\n remove: Function\n consequent: Object | null\n alternate: Object | null\n}\n\nexport type ClassNameToStyleObj = {\n [key: string]: StyleObject\n}\n\nexport interface PluginContext {\n write: (path: string, rules: { [key: string]: string }) => any\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/static",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.191",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist",
|
|
@@ -37,32 +37,34 @@
|
|
|
37
37
|
"@babel/runtime": "^7.18.9",
|
|
38
38
|
"@babel/traverse": "^7.18.11",
|
|
39
39
|
"@expo/match-media": "^0.3.0",
|
|
40
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
41
|
-
"@tamagui/cli-color": "^1.0.1-beta.
|
|
42
|
-
"@tamagui/config-default-node": "^1.0.1-beta.
|
|
43
|
-
"@tamagui/core-node": "^1.0.1-beta.
|
|
44
|
-
"@tamagui/fake-react-native": "^1.0.1-beta.
|
|
45
|
-
"@tamagui/helpers": "^1.0.1-beta.
|
|
46
|
-
"@tamagui/helpers-node": "^1.0.1-beta.
|
|
47
|
-
"@tamagui/patch-rnw": "^1.0.1-beta.
|
|
48
|
-
"@tamagui/proxy-worm": "^1.0.1-beta.
|
|
49
|
-
"@tamagui/react-native-svg": "^1.0.1-beta.
|
|
50
|
-
"@tamagui/shorthands": "^1.0.1-beta.
|
|
40
|
+
"@tamagui/build": "^1.0.1-beta.191",
|
|
41
|
+
"@tamagui/cli-color": "^1.0.1-beta.191",
|
|
42
|
+
"@tamagui/config-default-node": "^1.0.1-beta.191",
|
|
43
|
+
"@tamagui/core-node": "^1.0.1-beta.191",
|
|
44
|
+
"@tamagui/fake-react-native": "^1.0.1-beta.191",
|
|
45
|
+
"@tamagui/helpers": "^1.0.1-beta.191",
|
|
46
|
+
"@tamagui/helpers-node": "^1.0.1-beta.191",
|
|
47
|
+
"@tamagui/patch-rnw": "^1.0.1-beta.191",
|
|
48
|
+
"@tamagui/proxy-worm": "^1.0.1-beta.191",
|
|
49
|
+
"@tamagui/react-native-svg": "^1.0.1-beta.191",
|
|
50
|
+
"@tamagui/shorthands": "^1.0.1-beta.191",
|
|
51
51
|
"babel-literal-to-ast": "^2.1.0",
|
|
52
52
|
"esbuild": "^0.15.6",
|
|
53
53
|
"esbuild-register": "^3.3.3",
|
|
54
54
|
"find-cache-dir": "^3.3.2",
|
|
55
|
+
"find-root": "^1.1.0",
|
|
55
56
|
"fs-extra": "^10.1.0",
|
|
56
57
|
"invariant": "^2.2.4",
|
|
57
58
|
"lodash": "^4.17.21",
|
|
58
|
-
"react-native-web-lite": "^1.0.1-beta.
|
|
59
|
-
"tamagui": "^1.0.1-beta.
|
|
59
|
+
"react-native-web-lite": "^1.0.1-beta.191",
|
|
60
|
+
"tamagui": "^1.0.1-beta.191"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@babel/plugin-syntax-typescript": "^7.18.6",
|
|
63
64
|
"@babel/types": "^7.18.10",
|
|
64
65
|
"@dish/babel-preset": "^0.0.6",
|
|
65
66
|
"@testing-library/react": "^13.3.0",
|
|
67
|
+
"@types/find-root": "^1.1.2",
|
|
66
68
|
"@types/node": "^16.11.9",
|
|
67
69
|
"@types/react-native": "^0.69.2",
|
|
68
70
|
"@types/webpack": "^4.41.26",
|
package/src/constants.ts
CHANGED
|
@@ -10,6 +10,5 @@ export const MEDIA_SEP = '_'
|
|
|
10
10
|
export const cacheDir = findCacheDir({ name: 'tamagui', create: true })
|
|
11
11
|
|
|
12
12
|
export const FAILED_EVAL = Symbol('failed_style_eval')
|
|
13
|
-
export const CONCAT_CLASSNAME_IMPORT = 'concatClassName'
|
|
14
13
|
|
|
15
14
|
export const SHOULD_DEBUG = process.env.DEBUG === '*' || process.env.DEBUG?.startsWith('tamagui')
|
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import * as t from '@babel/types'
|
|
2
|
+
import { concatClassName } from '@tamagui/helpers'
|
|
2
3
|
|
|
3
4
|
import type { ClassNameObject } from '../types.js'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
type Builder = (
|
|
7
|
+
objects: ClassNameObject[],
|
|
8
|
+
extras?: string
|
|
9
|
+
) => t.Expression | t.StringLiteral | null
|
|
10
|
+
|
|
11
|
+
export const buildClassName: Builder = (objectsIn, extras = '') => {
|
|
12
|
+
let objects = buildClassNameLogic(objectsIn)
|
|
13
|
+
if (!objects) return null
|
|
14
|
+
if (t.isStringLiteral(objects)) {
|
|
15
|
+
objects.value = concatClassName(objects.value)
|
|
16
|
+
objects.value = `${extras} ${objects.value}`
|
|
17
|
+
} else {
|
|
18
|
+
objects = t.binaryExpression('+', t.stringLiteral(extras), objects)
|
|
19
|
+
}
|
|
20
|
+
return objects
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const buildClassNameLogic: Builder = (objects) => {
|
|
24
|
+
return objects.reduce<t.Expression | null>((acc, val) => {
|
|
9
25
|
if (acc == null) {
|
|
10
26
|
if (
|
|
11
27
|
// pass conditional expressions through
|
|
@@ -3,22 +3,22 @@ import vm from 'vm'
|
|
|
3
3
|
import generate from '@babel/generator'
|
|
4
4
|
import { NodePath } from '@babel/traverse'
|
|
5
5
|
import * as t from '@babel/types'
|
|
6
|
-
import type { TamaguiConfig } from '@tamagui/core-node'
|
|
7
6
|
import { createCSSVariable } from '@tamagui/core-node'
|
|
8
7
|
import esbuild from 'esbuild'
|
|
9
8
|
|
|
10
9
|
import { FAILED_EVAL } from '../constants.js'
|
|
10
|
+
import { TamaguiOptionsWithFileInfo } from '../types.js'
|
|
11
11
|
import { evaluateAstNode } from './evaluateAstNode.js'
|
|
12
12
|
import { isValidThemeHook } from './extractHelpers.js'
|
|
13
13
|
|
|
14
14
|
export function createEvaluator({
|
|
15
|
-
|
|
15
|
+
props,
|
|
16
16
|
staticNamespace,
|
|
17
17
|
sourcePath,
|
|
18
18
|
traversePath,
|
|
19
19
|
shouldPrintDebug,
|
|
20
20
|
}: {
|
|
21
|
-
|
|
21
|
+
props: TamaguiOptionsWithFileInfo
|
|
22
22
|
staticNamespace: Record<string, any>
|
|
23
23
|
sourcePath: string
|
|
24
24
|
traversePath?: NodePath<t.JSXElement>
|
|
@@ -31,7 +31,7 @@ export function createEvaluator({
|
|
|
31
31
|
t.isMemberExpression(n) &&
|
|
32
32
|
t.isIdentifier(n.property) &&
|
|
33
33
|
traversePath &&
|
|
34
|
-
isValidThemeHook(traversePath, n, sourcePath)
|
|
34
|
+
isValidThemeHook(props, traversePath, n, sourcePath)
|
|
35
35
|
) {
|
|
36
36
|
const key = n.property.name
|
|
37
37
|
if (shouldPrintDebug) {
|
|
@@ -41,7 +41,7 @@ export function createEvaluator({
|
|
|
41
41
|
return createCSSVariable(key)
|
|
42
42
|
}
|
|
43
43
|
// variable
|
|
44
|
-
if (t.isIdentifier(n) && staticNamespace
|
|
44
|
+
if (t.isIdentifier(n) && typeof staticNamespace[n.name] !== 'undefined') {
|
|
45
45
|
return staticNamespace[n.name]
|
|
46
46
|
}
|
|
47
47
|
const evalContext = vm.createContext(staticNamespace)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import { basename, relative } from 'path'
|
|
2
|
+
import path, { basename, relative } from 'path'
|
|
3
3
|
|
|
4
4
|
import traverse, { NodePath, Visitor } from '@babel/traverse'
|
|
5
5
|
import * as t from '@babel/types'
|
|
@@ -24,17 +24,12 @@ import type {
|
|
|
24
24
|
ExtractorOptions,
|
|
25
25
|
ExtractorParseProps,
|
|
26
26
|
TamaguiOptions,
|
|
27
|
+
TamaguiOptionsWithFileInfo,
|
|
27
28
|
Ternary,
|
|
28
29
|
} from '../types.js'
|
|
29
30
|
import { createEvaluator, createSafeEvaluator } from './createEvaluator.js'
|
|
30
31
|
import { evaluateAstNode } from './evaluateAstNode.js'
|
|
31
|
-
import {
|
|
32
|
-
attrStr,
|
|
33
|
-
findComponentName,
|
|
34
|
-
isInsideTamagui,
|
|
35
|
-
isPresent,
|
|
36
|
-
objToStr,
|
|
37
|
-
} from './extractHelpers.js'
|
|
32
|
+
import { attrStr, findComponentName, isPresent, isValidImport, objToStr } from './extractHelpers.js'
|
|
38
33
|
import { findTopmostFunction } from './findTopmostFunction.js'
|
|
39
34
|
import { getPrefixLogs } from './getPrefixLogs.js'
|
|
40
35
|
import { cleanupBeforeExit, getStaticBindingsForScope } from './getStaticBindingsForScope.js'
|
|
@@ -165,7 +160,7 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
165
160
|
prefixLogs,
|
|
166
161
|
excludeProps,
|
|
167
162
|
target,
|
|
168
|
-
...
|
|
163
|
+
...restProps
|
|
169
164
|
} = options
|
|
170
165
|
|
|
171
166
|
let shouldPrintDebug = options.shouldPrintDebug || false
|
|
@@ -183,6 +178,10 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
183
178
|
const isTargetingHTML = target === 'html'
|
|
184
179
|
const ogDebug = shouldPrintDebug
|
|
185
180
|
const tm = timer()
|
|
181
|
+
const propsWithFileInfo: TamaguiOptionsWithFileInfo = {
|
|
182
|
+
...options,
|
|
183
|
+
sourcePath,
|
|
184
|
+
}
|
|
186
185
|
|
|
187
186
|
if (shouldPrintDebug === 'verbose') {
|
|
188
187
|
console.log('tamagui.config.ts:', { components, config })
|
|
@@ -211,9 +210,6 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
211
210
|
/**
|
|
212
211
|
* Step 1: Determine if importing any statically extractable components
|
|
213
212
|
*/
|
|
214
|
-
const isInternalImport = (importStr: string) => {
|
|
215
|
-
return isInsideTamagui(sourcePath) && importStr[0] === '.'
|
|
216
|
-
}
|
|
217
213
|
|
|
218
214
|
const validComponents: { [key: string]: any } = Object.keys(components)
|
|
219
215
|
// check if uppercase to avoid hitting media query proxy before init
|
|
@@ -241,15 +237,12 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
241
237
|
if (bodyPath.type !== 'ImportDeclaration') continue
|
|
242
238
|
const node = ('node' in bodyPath ? bodyPath.node : bodyPath) as t.ImportDeclaration
|
|
243
239
|
const from = node.source.value
|
|
240
|
+
|
|
244
241
|
// if importing styled()
|
|
245
|
-
const isValidImport
|
|
246
|
-
props.components.includes(from) ||
|
|
247
|
-
isInternalImport(from) ||
|
|
248
|
-
from === '@tamagui/core' ||
|
|
249
|
-
from === 'tamagui'
|
|
242
|
+
const valid = isValidImport(propsWithFileInfo, from)
|
|
250
243
|
|
|
251
244
|
if (extractStyledDefinitions) {
|
|
252
|
-
if (
|
|
245
|
+
if (valid) {
|
|
253
246
|
if (
|
|
254
247
|
node.specifiers.some((specifier) => {
|
|
255
248
|
return specifier.local.name === 'styled'
|
|
@@ -261,7 +254,7 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
261
254
|
}
|
|
262
255
|
}
|
|
263
256
|
|
|
264
|
-
if (
|
|
257
|
+
if (valid) {
|
|
265
258
|
const names = node.specifiers.map((specifier) => specifier.local.name)
|
|
266
259
|
const isValidComponent = names.some((name) => !!(validComponents[name] || validHooks[name]))
|
|
267
260
|
if (shouldPrintDebug === 'verbose') {
|
|
@@ -363,11 +356,13 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
363
356
|
logger.info([`Loaded`, Object.keys(out.components).join(', '), !!Component].join(' '))
|
|
364
357
|
}
|
|
365
358
|
} catch (err: any) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
359
|
+
if (shouldPrintDebug) {
|
|
360
|
+
logger.info(
|
|
361
|
+
`${getPrefixLogs(
|
|
362
|
+
options
|
|
363
|
+
)} skip optimize styled(${name}), unable to pre-process (DEBUG=tamagui for more)`
|
|
364
|
+
)
|
|
365
|
+
}
|
|
371
366
|
if (process.env.DEBUG === 'tamagui') {
|
|
372
367
|
logger.info(
|
|
373
368
|
` Disable this with "disableExtractFoundComponents" in your build-time configuration. \n\n ${err.message} ${err.stack}`
|
|
@@ -408,7 +403,7 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
408
403
|
const attemptEval = !evaluateVars
|
|
409
404
|
? evaluateAstNode
|
|
410
405
|
: createEvaluator({
|
|
411
|
-
|
|
406
|
+
props: options,
|
|
412
407
|
staticNamespace,
|
|
413
408
|
sourcePath,
|
|
414
409
|
shouldPrintDebug,
|
|
@@ -506,19 +501,33 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
506
501
|
|
|
507
502
|
if (binding) {
|
|
508
503
|
if (!t.isImportDeclaration(binding.path.parent)) {
|
|
504
|
+
if (shouldPrintDebug) {
|
|
505
|
+
logger.info(` - Binding not import declaration, skip`)
|
|
506
|
+
}
|
|
509
507
|
return
|
|
510
508
|
}
|
|
511
509
|
const source = binding.path.parent.source
|
|
512
|
-
if (!
|
|
510
|
+
if (!isValidImport(propsWithFileInfo, source.value)) {
|
|
511
|
+
if (shouldPrintDebug) {
|
|
512
|
+
logger.info(` - Binding not internal import or from components ${source.value}`)
|
|
513
|
+
}
|
|
513
514
|
return
|
|
514
515
|
}
|
|
515
516
|
if (!validComponents[binding.identifier.name]) {
|
|
517
|
+
if (shouldPrintDebug) {
|
|
518
|
+
logger.info(
|
|
519
|
+
` - Binding not valid component (binding.identifier.name) ${binding.identifier.name}`
|
|
520
|
+
)
|
|
521
|
+
}
|
|
516
522
|
return
|
|
517
523
|
}
|
|
518
524
|
}
|
|
519
525
|
|
|
520
526
|
const component = validComponents[node.name.name] as { staticConfig?: StaticConfigParsed }
|
|
521
527
|
if (!component || !component.staticConfig) {
|
|
528
|
+
if (shouldPrintDebug) {
|
|
529
|
+
logger.info(` - No Tamagui conf on this: ${node.name.name}`)
|
|
530
|
+
}
|
|
522
531
|
return
|
|
523
532
|
}
|
|
524
533
|
|
|
@@ -616,14 +625,14 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
616
625
|
const flatNode = getFlattenedNode?.({ isTextView, tag: tagName })
|
|
617
626
|
|
|
618
627
|
const inlineProps = new Set([
|
|
619
|
-
...(
|
|
628
|
+
...(restProps.inlineProps || []),
|
|
620
629
|
...(staticConfig.inlineProps || []),
|
|
621
630
|
])
|
|
622
631
|
|
|
623
632
|
const deoptProps = new Set([
|
|
624
633
|
// always de-opt animation
|
|
625
634
|
'animation',
|
|
626
|
-
...(
|
|
635
|
+
...(restProps.deoptProps || []),
|
|
627
636
|
...(staticConfig.deoptProps || []),
|
|
628
637
|
])
|
|
629
638
|
|
|
@@ -641,7 +650,7 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
641
650
|
const attemptEval = !evaluateVars
|
|
642
651
|
? evaluateAstNode
|
|
643
652
|
: createEvaluator({
|
|
644
|
-
|
|
653
|
+
props: options,
|
|
645
654
|
staticNamespace,
|
|
646
655
|
sourcePath,
|
|
647
656
|
traversePath,
|
|
@@ -1014,7 +1023,10 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
1014
1023
|
if (
|
|
1015
1024
|
validHTMLAttributes[key] ||
|
|
1016
1025
|
key.startsWith('aria-') ||
|
|
1017
|
-
key.startsWith('data-')
|
|
1026
|
+
key.startsWith('data-') ||
|
|
1027
|
+
// this is debug stuff added by vite / new jsx transform
|
|
1028
|
+
key === '__source' ||
|
|
1029
|
+
key === '__self'
|
|
1018
1030
|
) {
|
|
1019
1031
|
return attr
|
|
1020
1032
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
|
|
4
|
-
import { CONCAT_CLASSNAME_IMPORT } from '../constants.js'
|
|
5
|
-
|
|
6
4
|
const importConcatPkg = '@tamagui/helpers'
|
|
7
5
|
|
|
8
6
|
export function ensureImportingConcat(path: NodePath<t.Program>) {
|
|
@@ -11,8 +9,8 @@ export function ensureImportingConcat(path: NodePath<t.Program>) {
|
|
|
11
9
|
(x) => x.isImportDeclaration() && x.node.source.value === importConcatPkg
|
|
12
10
|
) as any
|
|
13
11
|
const importSpecifier = t.importSpecifier(
|
|
14
|
-
t.identifier(
|
|
15
|
-
t.identifier(
|
|
12
|
+
t.identifier('concatClassName'),
|
|
13
|
+
t.identifier('concatClassName')
|
|
16
14
|
)
|
|
17
15
|
|
|
18
16
|
if (!imported) {
|
|
@@ -23,17 +21,12 @@ export function ensureImportingConcat(path: NodePath<t.Program>) {
|
|
|
23
21
|
const specifiers = imported.node.specifiers
|
|
24
22
|
const alreadyImported = specifiers.some(
|
|
25
23
|
(x) =>
|
|
26
|
-
t.isImportSpecifier(x) &&
|
|
27
|
-
t.isIdentifier(x.imported) &&
|
|
28
|
-
x.imported.name === CONCAT_CLASSNAME_IMPORT
|
|
24
|
+
t.isImportSpecifier(x) && t.isIdentifier(x.imported) && x.imported.name === 'concatClassName'
|
|
29
25
|
)
|
|
30
26
|
|
|
31
27
|
if (!alreadyImported) {
|
|
32
28
|
specifiers.push(
|
|
33
|
-
t.importSpecifier(
|
|
34
|
-
t.identifier(CONCAT_CLASSNAME_IMPORT),
|
|
35
|
-
t.identifier(CONCAT_CLASSNAME_IMPORT)
|
|
36
|
-
)
|
|
29
|
+
t.importSpecifier(t.identifier('concatClassName'), t.identifier('concatClassName'))
|
|
37
30
|
)
|
|
38
31
|
}
|
|
39
32
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { basename, relative } from 'path'
|
|
2
|
+
|
|
1
3
|
import generate from '@babel/generator'
|
|
2
4
|
import type { NodePath } from '@babel/traverse'
|
|
3
5
|
import * as t from '@babel/types'
|
|
6
|
+
import findRoot from 'find-root'
|
|
7
|
+
import { memoize } from 'lodash'
|
|
4
8
|
|
|
5
|
-
import type { ExtractedAttr, Ternary } from '../types.js'
|
|
9
|
+
import type { ExtractedAttr, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'
|
|
6
10
|
|
|
7
11
|
// import { astToLiteral } from './literalToAst'
|
|
8
12
|
|
|
@@ -91,6 +95,7 @@ export function findComponentName(scope) {
|
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
export function isValidThemeHook(
|
|
98
|
+
props: TamaguiOptionsWithFileInfo,
|
|
94
99
|
jsxPath: NodePath<t.JSXElement>,
|
|
95
100
|
n: t.MemberExpression,
|
|
96
101
|
sourcePath: string
|
|
@@ -107,14 +112,43 @@ export function isValidThemeHook(
|
|
|
107
112
|
if (init.callee.name !== 'useTheme') return false
|
|
108
113
|
const importNode = binding.scope.getBinding('useTheme')?.path.parent
|
|
109
114
|
if (!t.isImportDeclaration(importNode)) return false
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
return false
|
|
113
|
-
}
|
|
115
|
+
if (!isValidImport(props, sourcePath)) {
|
|
116
|
+
return false
|
|
114
117
|
}
|
|
115
118
|
return true
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
export const
|
|
119
|
-
return
|
|
121
|
+
export const isInsideComponentPackage = (props: TamaguiOptionsWithFileInfo, srcName: string) => {
|
|
122
|
+
return getValidComponentsPaths(props).some((path) => {
|
|
123
|
+
return srcName.startsWith(path)
|
|
124
|
+
})
|
|
120
125
|
}
|
|
126
|
+
|
|
127
|
+
export const isComponentPackage = (props: TamaguiOptionsWithFileInfo, srcName: string) => {
|
|
128
|
+
return getValidComponentsPaths(props).some((path) => {
|
|
129
|
+
return srcName.startsWith(path)
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const isValidImport = (props: TamaguiOptionsWithFileInfo, srcName: string) => {
|
|
134
|
+
if (typeof srcName !== 'string') {
|
|
135
|
+
// eslint-disable-next-line no-console
|
|
136
|
+
console.trace(`Invalid file name: ${srcName}`)
|
|
137
|
+
return false
|
|
138
|
+
}
|
|
139
|
+
return srcName.startsWith('.')
|
|
140
|
+
? isInsideComponentPackage(props, srcName)
|
|
141
|
+
: isComponentPackage(props, srcName)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const getValidComponentPackages = memoize((props: TamaguiOptionsWithFileInfo) => {
|
|
145
|
+
// just always look for `tamagui` and `@tamagui/core`
|
|
146
|
+
return [...new Set(['@tamagui/core', 'tamagui', ...props.components])]
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const getValidComponentsPaths = memoize((props: TamaguiOptionsWithFileInfo) => {
|
|
150
|
+
return getValidComponentPackages(props).map((pkg) => {
|
|
151
|
+
const root = findRoot(pkg)
|
|
152
|
+
return basename(root)
|
|
153
|
+
})
|
|
154
|
+
})
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
import { TamaguiInternalConfig, getStylesAtomic, mediaObjectToString } from '@tamagui/core-node'
|
|
4
|
-
import { ViewStyle } from 'react-native'
|
|
4
|
+
import type { ViewStyle } from 'react-native'
|
|
5
5
|
|
|
6
6
|
import { MEDIA_SEP } from '../constants.js'
|
|
7
|
-
import type { StyleObject, Ternary } from '../types.js'
|
|
8
|
-
import {
|
|
7
|
+
import type { StyleObject, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'
|
|
8
|
+
import { isPresent, isValidImport } from './extractHelpers.js'
|
|
9
9
|
|
|
10
10
|
export function extractMediaStyle(
|
|
11
|
+
props: TamaguiOptionsWithFileInfo,
|
|
11
12
|
ternary: Ternary,
|
|
12
13
|
jsxPath: NodePath<t.JSXElement>,
|
|
13
14
|
tamaguiConfig: TamaguiInternalConfig,
|
|
@@ -15,13 +16,14 @@ export function extractMediaStyle(
|
|
|
15
16
|
importance = 0,
|
|
16
17
|
shouldPrintDebug: boolean | 'verbose' = false
|
|
17
18
|
) {
|
|
18
|
-
const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath)
|
|
19
|
+
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)
|
|
19
20
|
if (!mt) {
|
|
20
21
|
return null
|
|
21
22
|
}
|
|
22
23
|
const { key } = mt
|
|
23
24
|
const mq = tamaguiConfig.media[key]
|
|
24
25
|
if (!mq) {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
25
27
|
console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`)
|
|
26
28
|
return null
|
|
27
29
|
}
|
|
@@ -33,6 +35,7 @@ export function extractMediaStyle(
|
|
|
33
35
|
getStyleObj(ternary.alternate, true),
|
|
34
36
|
].filter(isPresent)
|
|
35
37
|
if (shouldPrintDebug && !styleOpts.length) {
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
36
39
|
console.log(' media query, no styles?')
|
|
37
40
|
return null
|
|
38
41
|
}
|
|
@@ -80,6 +83,7 @@ export function extractMediaStyle(
|
|
|
80
83
|
})
|
|
81
84
|
if (shouldPrintDebug === 'verbose') {
|
|
82
85
|
// prettier-ignore
|
|
86
|
+
// eslint-disable-next-line no-console
|
|
83
87
|
console.log(' media styles:', importance, styleObj, singleMediaStyles.map(x => x.identifier).join(', '))
|
|
84
88
|
}
|
|
85
89
|
// add to output
|
|
@@ -91,6 +95,7 @@ export function extractMediaStyle(
|
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
function getMediaQueryTernary(
|
|
98
|
+
props: TamaguiOptionsWithFileInfo,
|
|
94
99
|
ternary: Ternary,
|
|
95
100
|
jsxPath: NodePath<t.JSXElement>,
|
|
96
101
|
sourcePath: string
|
|
@@ -104,6 +109,7 @@ function getMediaQueryTernary(
|
|
|
104
109
|
if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {
|
|
105
110
|
// *should* be normalized to always be on left side
|
|
106
111
|
const mediaLeft = getMediaInfoFromExpression(
|
|
112
|
+
props,
|
|
107
113
|
ternary.test.left,
|
|
108
114
|
jsxPath,
|
|
109
115
|
sourcePath,
|
|
@@ -122,6 +128,7 @@ function getMediaQueryTernary(
|
|
|
122
128
|
// const media = useMedia()
|
|
123
129
|
// ... media.sm
|
|
124
130
|
const result = getMediaInfoFromExpression(
|
|
131
|
+
props,
|
|
125
132
|
ternary.test,
|
|
126
133
|
jsxPath,
|
|
127
134
|
sourcePath,
|
|
@@ -137,6 +144,7 @@ function getMediaQueryTernary(
|
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
function getMediaInfoFromExpression(
|
|
147
|
+
props: TamaguiOptionsWithFileInfo,
|
|
140
148
|
test: t.Expression,
|
|
141
149
|
jsxPath: NodePath<t.JSXElement>,
|
|
142
150
|
sourcePath: string,
|
|
@@ -156,20 +164,21 @@ function getMediaInfoFromExpression(
|
|
|
156
164
|
if (!binding) return false
|
|
157
165
|
const bindingNode = binding.path?.node
|
|
158
166
|
if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false
|
|
159
|
-
if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath)) return false
|
|
167
|
+
if (!isValidMediaCall(props, jsxPath, bindingNode.init, sourcePath)) return false
|
|
160
168
|
return { key, bindingName: name }
|
|
161
169
|
}
|
|
162
170
|
if (t.isIdentifier(test)) {
|
|
163
171
|
const key = test.name
|
|
164
172
|
const node = jsxPath.scope.getBinding(test.name)?.path?.node
|
|
165
173
|
if (!t.isVariableDeclarator(node)) return false
|
|
166
|
-
if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath)) return false
|
|
174
|
+
if (!node.init || !isValidMediaCall(props, jsxPath, node.init, sourcePath)) return false
|
|
167
175
|
return { key, bindingName: key }
|
|
168
176
|
}
|
|
169
177
|
return null
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
export function isValidMediaCall(
|
|
181
|
+
props: TamaguiOptionsWithFileInfo,
|
|
173
182
|
jsxPath: NodePath<t.JSXElement>,
|
|
174
183
|
init: t.Expression,
|
|
175
184
|
sourcePath: string
|
|
@@ -183,10 +192,8 @@ export function isValidMediaCall(
|
|
|
183
192
|
if (!mediaBinding) return false
|
|
184
193
|
const useMediaImport = mediaBinding.path.parent
|
|
185
194
|
if (!t.isImportDeclaration(useMediaImport)) return false
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
return false
|
|
189
|
-
}
|
|
195
|
+
if (!isValidImport(props, sourcePath)) {
|
|
196
|
+
return false
|
|
190
197
|
}
|
|
191
198
|
return true
|
|
192
199
|
}
|