@tamagui/static 1.0.1-beta.190 → 1.0.1-beta.192
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 +72 -49
- 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 +7 -5
- 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 +53 -33
- 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 +9 -7
- 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 Be sure you \"export default\" the config.`)\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;AAA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 -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
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.192",
|
|
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.192",
|
|
41
|
+
"@tamagui/cli-color": "^1.0.1-beta.192",
|
|
42
|
+
"@tamagui/config-default-node": "^1.0.1-beta.192",
|
|
43
|
+
"@tamagui/core-node": "^1.0.1-beta.192",
|
|
44
|
+
"@tamagui/fake-react-native": "^1.0.1-beta.192",
|
|
45
|
+
"@tamagui/helpers": "^1.0.1-beta.192",
|
|
46
|
+
"@tamagui/helpers-node": "^1.0.1-beta.192",
|
|
47
|
+
"@tamagui/patch-rnw": "^1.0.1-beta.192",
|
|
48
|
+
"@tamagui/proxy-worm": "^1.0.1-beta.192",
|
|
49
|
+
"@tamagui/react-native-svg": "^1.0.1-beta.192",
|
|
50
|
+
"@tamagui/shorthands": "^1.0.1-beta.192",
|
|
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.192",
|
|
60
|
+
"tamagui": "^1.0.1-beta.192"
|
|
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 })
|
|
@@ -190,9 +189,17 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
190
189
|
|
|
191
190
|
tm.mark('load-tamagui', !!shouldPrintDebug)
|
|
192
191
|
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
const firstThemeName = Object.keys(tamaguiConfig.themes)[0]
|
|
193
|
+
const firstTheme = tamaguiConfig.themes[firstThemeName]
|
|
194
|
+
|
|
195
|
+
if (!firstTheme || typeof firstTheme !== 'object') {
|
|
196
|
+
console.error(`Missing theme, an error occurred when importing your config`)
|
|
197
|
+
console.log(`Got themes:`, tamaguiConfig.themes)
|
|
198
|
+
console.log(`Looking for theme:`, firstThemeName)
|
|
199
|
+
process.exit(0)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const proxiedTheme = proxyThemeVariables(firstTheme)
|
|
196
203
|
|
|
197
204
|
type AccessListener = (key: string) => void
|
|
198
205
|
const themeAccessListeners = new Set<AccessListener>()
|
|
@@ -211,9 +218,6 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
211
218
|
/**
|
|
212
219
|
* Step 1: Determine if importing any statically extractable components
|
|
213
220
|
*/
|
|
214
|
-
const isInternalImport = (importStr: string) => {
|
|
215
|
-
return isInsideTamagui(sourcePath) && importStr[0] === '.'
|
|
216
|
-
}
|
|
217
221
|
|
|
218
222
|
const validComponents: { [key: string]: any } = Object.keys(components)
|
|
219
223
|
// check if uppercase to avoid hitting media query proxy before init
|
|
@@ -241,15 +245,12 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
241
245
|
if (bodyPath.type !== 'ImportDeclaration') continue
|
|
242
246
|
const node = ('node' in bodyPath ? bodyPath.node : bodyPath) as t.ImportDeclaration
|
|
243
247
|
const from = node.source.value
|
|
248
|
+
|
|
244
249
|
// if importing styled()
|
|
245
|
-
const isValidImport
|
|
246
|
-
props.components.includes(from) ||
|
|
247
|
-
isInternalImport(from) ||
|
|
248
|
-
from === '@tamagui/core' ||
|
|
249
|
-
from === 'tamagui'
|
|
250
|
+
const valid = isValidImport(propsWithFileInfo, from)
|
|
250
251
|
|
|
251
252
|
if (extractStyledDefinitions) {
|
|
252
|
-
if (
|
|
253
|
+
if (valid) {
|
|
253
254
|
if (
|
|
254
255
|
node.specifiers.some((specifier) => {
|
|
255
256
|
return specifier.local.name === 'styled'
|
|
@@ -261,7 +262,7 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
261
262
|
}
|
|
262
263
|
}
|
|
263
264
|
|
|
264
|
-
if (
|
|
265
|
+
if (valid) {
|
|
265
266
|
const names = node.specifiers.map((specifier) => specifier.local.name)
|
|
266
267
|
const isValidComponent = names.some((name) => !!(validComponents[name] || validHooks[name]))
|
|
267
268
|
if (shouldPrintDebug === 'verbose') {
|
|
@@ -363,11 +364,13 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
363
364
|
logger.info([`Loaded`, Object.keys(out.components).join(', '), !!Component].join(' '))
|
|
364
365
|
}
|
|
365
366
|
} catch (err: any) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
367
|
+
if (shouldPrintDebug) {
|
|
368
|
+
logger.info(
|
|
369
|
+
`${getPrefixLogs(
|
|
370
|
+
options
|
|
371
|
+
)} skip optimize styled(${name}), unable to pre-process (DEBUG=tamagui for more)`
|
|
372
|
+
)
|
|
373
|
+
}
|
|
371
374
|
if (process.env.DEBUG === 'tamagui') {
|
|
372
375
|
logger.info(
|
|
373
376
|
` Disable this with "disableExtractFoundComponents" in your build-time configuration. \n\n ${err.message} ${err.stack}`
|
|
@@ -408,7 +411,7 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
408
411
|
const attemptEval = !evaluateVars
|
|
409
412
|
? evaluateAstNode
|
|
410
413
|
: createEvaluator({
|
|
411
|
-
|
|
414
|
+
props: options,
|
|
412
415
|
staticNamespace,
|
|
413
416
|
sourcePath,
|
|
414
417
|
shouldPrintDebug,
|
|
@@ -506,19 +509,33 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
506
509
|
|
|
507
510
|
if (binding) {
|
|
508
511
|
if (!t.isImportDeclaration(binding.path.parent)) {
|
|
512
|
+
if (shouldPrintDebug) {
|
|
513
|
+
logger.info(` - Binding not import declaration, skip`)
|
|
514
|
+
}
|
|
509
515
|
return
|
|
510
516
|
}
|
|
511
517
|
const source = binding.path.parent.source
|
|
512
|
-
if (!
|
|
518
|
+
if (!isValidImport(propsWithFileInfo, source.value)) {
|
|
519
|
+
if (shouldPrintDebug) {
|
|
520
|
+
logger.info(` - Binding not internal import or from components ${source.value}`)
|
|
521
|
+
}
|
|
513
522
|
return
|
|
514
523
|
}
|
|
515
524
|
if (!validComponents[binding.identifier.name]) {
|
|
525
|
+
if (shouldPrintDebug) {
|
|
526
|
+
logger.info(
|
|
527
|
+
` - Binding not valid component (binding.identifier.name) ${binding.identifier.name}`
|
|
528
|
+
)
|
|
529
|
+
}
|
|
516
530
|
return
|
|
517
531
|
}
|
|
518
532
|
}
|
|
519
533
|
|
|
520
534
|
const component = validComponents[node.name.name] as { staticConfig?: StaticConfigParsed }
|
|
521
535
|
if (!component || !component.staticConfig) {
|
|
536
|
+
if (shouldPrintDebug) {
|
|
537
|
+
logger.info(` - No Tamagui conf on this: ${node.name.name}`)
|
|
538
|
+
}
|
|
522
539
|
return
|
|
523
540
|
}
|
|
524
541
|
|
|
@@ -616,14 +633,14 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
616
633
|
const flatNode = getFlattenedNode?.({ isTextView, tag: tagName })
|
|
617
634
|
|
|
618
635
|
const inlineProps = new Set([
|
|
619
|
-
...(
|
|
636
|
+
...(restProps.inlineProps || []),
|
|
620
637
|
...(staticConfig.inlineProps || []),
|
|
621
638
|
])
|
|
622
639
|
|
|
623
640
|
const deoptProps = new Set([
|
|
624
641
|
// always de-opt animation
|
|
625
642
|
'animation',
|
|
626
|
-
...(
|
|
643
|
+
...(restProps.deoptProps || []),
|
|
627
644
|
...(staticConfig.deoptProps || []),
|
|
628
645
|
])
|
|
629
646
|
|
|
@@ -641,7 +658,7 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
641
658
|
const attemptEval = !evaluateVars
|
|
642
659
|
? evaluateAstNode
|
|
643
660
|
: createEvaluator({
|
|
644
|
-
|
|
661
|
+
props: options,
|
|
645
662
|
staticNamespace,
|
|
646
663
|
sourcePath,
|
|
647
664
|
traversePath,
|
|
@@ -1014,7 +1031,10 @@ export function createExtractor({ logger = console }: ExtractorOptions = { logge
|
|
|
1014
1031
|
if (
|
|
1015
1032
|
validHTMLAttributes[key] ||
|
|
1016
1033
|
key.startsWith('aria-') ||
|
|
1017
|
-
key.startsWith('data-')
|
|
1034
|
+
key.startsWith('data-') ||
|
|
1035
|
+
// this is debug stuff added by vite / new jsx transform
|
|
1036
|
+
key === '__source' ||
|
|
1037
|
+
key === '__self'
|
|
1018
1038
|
) {
|
|
1019
1039
|
return attr
|
|
1020
1040
|
}
|
|
@@ -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
|
+
})
|