id
stringlengths 12
53
| messages
listlengths 3
3
|
|---|---|
code_micro_3de1d995
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/package.json from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"name\": \"@vtex/micro-react-router\",\n \"version\": \"1.1.1-alpha.17\",\n \"license\": \"MIT\",\n \"micro\": {\n \"plugins\": [\n \"@vtex/micro-core\",\n \"@vtex/micro-react\"\n ]\n },\n \"scripts\": {\n \"build\": \"yarn run micro build\",\n \"watch\": \"yarn run micro link\",\n \"clean\": \"rm -r dist\",\n \"prepublish\": \"yarn build\"\n },\n \"main\": \"./dist/build/cjs/index.js\",\n \"module\": \"./dist/build/es6/components/index.js\",\n \"browser\": \"./components/index.ts\",\n \"dependencies\": {\n \"@vtex/micro-core\": \"^1.1.1-alpha.16\",\n \"@vtex/micro-react\": \"^1.1.1-alpha.17\",\n \"history\": \"^4.10.1\",\n \"react-in-viewport\": \"^1.0.0-alpha.11\",\n \"react-router-dom\": \"^5.1.2\",\n \"webpack-blocks\": \"^2.1.0\"\n },\n \"devDependencies\": {\n \"@types/history\": \"^4.7.5\",\n \"@types/loadable__component\": \"^5.10.0\",\n \"@types/react\": \"^16.9.35\",\n \"@types/react-dom\": \"^16.9.7\",\n \"@types/react-router-dom\": \"^5.1.5\",\n \"@types/webpack\": \"^4.41.13\",\n \"@types/webpack-blocks\": \"^2.0.0\",\n \"@vtex/micro-cli\": \"^1.1.1-alpha.17\",\n \"typescript\": \"^3.8.3\"\n },\n \"peerDependencies\": {\n \"@loadable/component\": \"*\",\n \"react\": \"*\",\n \"react-dom\": \"*\"\n }\n}\n\n```"
}
] |
code_micro_9ed12074
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-intl/plugins/aliases.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// This plugin will enforce the following modules. This means\n// projects using this package as a plugin will use this package's\n// versions of the following packages\nexport const aliases = [\n 'react-intl'\n]\n\n```"
}
] |
code_micro_7eb3e204
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-intl/components/withIntlProvider.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\nimport { IntlProvider } from 'react-intl'\n\nexport type Messages = Record<string, string>\n\nexport interface PageProps {\n data: any\n error: any\n}\n\nexport const withIntlProvider = (\n Page: React.ElementType<PageProps>,\n messages: Messages,\n locale: string\n): React.SFC<PageProps> => {\n return function MicroReactIntl ({ data, error }) {\n return (\n <IntlProvider messages={messages} locale={locale} key={locale}>\n <Page data={data} error={error} />\n </IntlProvider>\n )\n }\n}\n\n```"
}
] |
code_micro_3a72241e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-intl/components/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport * from 'react-intl'\nexport * from './withIntlProvider'\n\n```"
}
] |
code_micro_8f75513c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-intl/plugins/bundle/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport {\n BundlePlugin,\n pagesFrameworkName,\n pagesRuntimeName\n} from '@vtex/micro-core'\nimport { cacheGroup } from '@vtex/micro-react'\nimport { Block, Context, group, resolve } from 'webpack-blocks'\n\nimport { aliases } from '../aliases'\n\nexport default class Bundle extends BundlePlugin {\n public getConfig = async (config: Block<Context>): Promise<Block<Context>> => {\n return group([\n config,\n resolve({\n alias: aliases.reduce(\n (acc, packageName) => {\n acc[packageName] = require.resolve(packageName)\n return acc\n },\n {} as Record<string, string>\n )\n }),\n cacheGroup(pagesRuntimeName, /\\/react-intl\\//),\n cacheGroup(pagesFrameworkName, /\\/micro-react-intl\\//)\n ])\n }\n}\n\n```"
}
] |
code_micro_dba5ae81
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-intl/plugins/serve/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ServePlugin } from '@vtex/micro-core'\nimport { createElement } from 'react'\nimport { IntlProvider } from 'react-intl'\n\nexport default class Serve extends ServePlugin<JSX.Element> {\n public render = (children: JSX.Element | null): JSX.Element => {\n const location = this.options.path\n // TODO: Fix this as any\n return createElement(IntlProvider as any, { location, children })\n }\n}\n\n```"
}
] |
code_micro_771e7f67
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-css/plugins/bundle/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { BundlePlugin } from '@vtex/micro-core'\nimport { Block, Context, css, group, match } from 'webpack-blocks'\n\nimport { extractCss } from './modules/extractCSS'\nimport { purgeCSS } from './modules/purgeCSS'\n\nexport default class Bundle extends BundlePlugin {\n public getConfig = async (config: Block<Context>): Promise<Block<Context>> => {\n const block: Block<Context>[] = [\n purgeCSS({\n paths: await this.project.resolveFiles('pages', 'components')\n }),\n match('*.css', [\n extractCss({\n plugin: { filename: '[name].css' },\n loader: { esModule: true }\n }),\n css({ styleLoader: false } as any)\n ])\n ]\n\n return group([\n config,\n ...block\n ])\n }\n}\n\n```"
}
] |
code_micro_3134e369
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-css/plugins/bundle/modules/htmlTags.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// TODO: Purgecss plugin does not work well\n// with standard tags, so let's leave all of them\n// there so we don't miss out any important one\nexport const htmlTags = [\n 'a',\n 'abbr',\n 'address',\n 'area',\n 'article',\n 'aside',\n 'audio',\n 'b',\n 'base',\n 'bdi',\n 'bdo',\n 'blockquote',\n 'body',\n 'br',\n 'button',\n 'canvas',\n 'caption',\n 'cite',\n 'code',\n 'col',\n 'colgroup',\n 'data',\n 'datalist',\n 'dd',\n 'del',\n 'details',\n 'dfn',\n 'dialog',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'embed',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'head',\n 'header',\n 'hgroup',\n 'hr',\n 'html',\n 'i',\n 'iframe',\n 'img',\n 'input',\n 'ins',\n 'kbd',\n 'label',\n 'legend',\n 'li',\n 'link',\n 'main',\n 'map',\n 'mark',\n 'math',\n 'menu',\n 'menuitem',\n 'meta',\n 'meter',\n 'nav',\n 'noscript',\n 'object',\n 'ol',\n 'optgroup',\n 'option',\n 'output',\n 'p',\n 'param',\n 'picture',\n 'pre',\n 'progress',\n 'q',\n 'rb',\n 'rp',\n 'rt',\n 'rtc',\n 'ruby',\n 's',\n 'samp',\n 'script',\n 'section',\n 'select',\n 'slot',\n 'small',\n 'source',\n 'span',\n 'strong',\n 'style',\n 'sub',\n 'summary',\n 'sup',\n 'svg',\n 'table',\n 'tbody',\n 'td',\n 'template',\n 'textarea',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'title',\n 'tr',\n 'track',\n 'u',\n 'ul',\n 'var',\n 'video',\n 'wbr'\n]\n\n```"
}
] |
code_micro_2e61e107
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-css/plugins/bundle/modules/extractCSS.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport webpack from 'webpack'\nimport MiniCssExtractPlugin from 'mini-css-extract-plugin'\nimport { Context, Util } from 'webpack-blocks'\n\ninterface Options {\n loader?: {\n esModule: boolean\n },\n plugin?: MiniCssExtractPlugin.PluginOptions\n}\n\nexport const extractCss = (options?: Options) => (context: Context, { merge }: Util) => merge({\n module: {\n rules: [\n {\n ...context.match,\n use: [\n {\n loader: MiniCssExtractPlugin.loader,\n options: options?.loader\n }\n ]\n }\n ]\n },\n plugins: [\n new MiniCssExtractPlugin(options?.plugin)\n ]\n})\n\n```"
}
] |
code_micro_bb6b25ef
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-css/plugins/bundle/modules/purgeCSS.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport PurgeCSSPlugin from 'purgecss-webpack-plugin'\nimport { Configuration } from 'webpack'\nimport { Context, Util } from 'webpack-blocks'\n\ntype FirstOf<T extends [any]> = T extends [infer P] ? P : never\n\ntype Options = FirstOf<ConstructorParameters<typeof PurgeCSSPlugin>>\n\ninterface EnhancedContext extends Context {\n purgeCSSOptions: Options\n}\n\nconst post = (context: Context, { addPlugin }: Util) => {\n const ctx = context as EnhancedContext\n return addPlugin(new PurgeCSSPlugin(ctx.purgeCSSOptions))\n}\n\nexport const purgeCSS = (options: Partial<Options>) => {\n return Object.assign(\n (context: Context) => {\n const ctx = context as EnhancedContext\n ctx.purgeCSSOptions = {\n ...ctx.purgeCSSOptions,\n ...options\n }\n return (config: Configuration) => config\n },\n { post }\n )\n}\n\n```"
}
] |
code_micro_bbd4ec47
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/prod.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport {\n ServeCompiler,\n Plugins,\n Project,\n PublicPaths\n} from '@vtex/micro-core'\nimport compress from 'compression'\nimport express from 'express'\nimport logger from 'morgan'\nimport { Stats } from 'webpack'\n\nimport { middleware as streamAssets } from './middlewares/assets'\nimport { middleware as respondData } from './middlewares/data'\nimport { middleware as headers } from './middlewares/headers'\nimport { middleware as router } from './middlewares/router'\nimport { middleware as ssr } from './middlewares/ssr'\nimport { Next, Req, Res } from './typings'\n\ninterface ProdServerOptions {\n statsJson: Stats.ToJsonOutput\n project: Project\n plugins: Plugins['serve'][]\n publicPaths: PublicPaths\n host: string\n port: number\n}\n\nconst context = (\n project: Project,\n plugins: any,\n statsJson: Stats.ToJsonOutput,\n publicPaths: PublicPaths\n) => (req: Req, res: Res, next: Next) => {\n const { locals: { route: { page, path } } } = res\n res.locals.compiler = new ServeCompiler({\n project,\n plugins,\n options: {\n stats: statsJson,\n mode: 'development',\n lifecycleTarget: 'bundle',\n publicPaths,\n page,\n path\n }\n })\n next()\n}\n\nexport const startProdServer = async ({\n publicPaths,\n statsJson,\n project,\n plugins,\n host,\n port\n}: ProdServerOptions) => {\n const routerMiddleware = await router(project, publicPaths)\n const contextMiddleware = context(project, plugins, statsJson, publicPaths)\n\n const app = express()\n\n app.use(logger('tiny'))\n app.use(compress())\n\n app.get('/favicon.ico', (req: Req, res: Res) => { res.status(404); res.send(null) })\n app.get(`${publicPaths.assets}*`, headers, streamAssets(project, publicPaths))\n app.get(`${publicPaths.data}*`, headers, routerMiddleware, contextMiddleware, respondData)\n app.get('/*', headers, routerMiddleware, contextMiddleware, ssr)\n\n app.listen(port, () => console.log(`π¦ ProdServer is UP on ${host}:${port}`))\n}\n\n```"
}
] |
code_micro_79999f66
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/dev.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport {\n ImportMap,\n ServeCompiler,\n Plugins,\n Project,\n PublicPaths\n} from '@vtex/micro-core'\nimport compress from 'compression'\nimport express from 'express'\nimport logger from 'morgan'\nimport { Stats } from 'webpack'\n\nimport { middleware as streamAssets } from './middlewares/assets'\nimport { middleware as respondData } from './middlewares/data'\nimport { middleware as headers } from './middlewares/headers'\nimport { middleware as router } from './middlewares/router'\nimport { devSSR } from './middlewares/ssr'\nimport { Next, Req, Res } from './typings'\n\ninterface DevServerOptions {\n importMap: ImportMap\n statsJson: Stats.ToJsonOutput\n project: Project,\n plugins: Plugins['serve'][]\n publicPaths: PublicPaths\n host: string\n port: number\n}\n\nconst context = (\n project: Project,\n plugins: any,\n statsJson: Stats.ToJsonOutput,\n publicPaths: PublicPaths\n) => (req: Req, res: Res, next: Next) => {\n const { locals: { route: { page, path } } } = res\n res.locals.compiler = new ServeCompiler({\n project,\n plugins,\n options: {\n stats: statsJson,\n mode: 'development',\n lifecycleTarget: 'build',\n publicPaths,\n page,\n path\n }\n })\n next()\n}\n\nexport const startDevServer = async ({\n publicPaths,\n importMap,\n statsJson,\n project,\n plugins,\n host,\n port\n}: DevServerOptions) => {\n const routerMiddleware = await router(project, publicPaths)\n const contextMiddleware = context(project, plugins, statsJson, publicPaths)\n\n const app = express()\n\n app.use(logger('dev'))\n app.use(compress())\n\n app.get('/favicon.ico', (req: Req, res: Res) => { res.status(404); res.send(null) })\n app.get(`${publicPaths.assets}*`, headers, streamAssets(project, publicPaths))\n app.get(`${publicPaths.data}*`, headers, routerMiddleware, contextMiddleware, respondData)\n app.get('/*', headers, routerMiddleware, contextMiddleware, devSSR(importMap))\n\n app.listen(port, () => console.log(`π¦ DevServer is UP on ${host}:${port}`))\n}\n\n```"
}
] |
code_micro_4ab255ff
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/features.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport cookie from 'cookie'\n\nimport { Req } from './typings'\n\nexport interface Features {\n disableSSR: boolean\n}\n\nconst DEFAULT_FEATURES: Features = {\n disableSSR: false\n}\n\nexport const featuresFromReq = (req: Req) => {\n const cookies = req.headers.cookie\n const maybeFeaturesStr = cookies && cookie.parse(cookies)?.['micro-features']\n if (maybeFeaturesStr) {\n const maybeFeatures = JSON.parse(maybeFeaturesStr)\n return {\n ...DEFAULT_FEATURES,\n ...maybeFeatures\n }\n }\n return DEFAULT_FEATURES\n}\n\n```"
}
] |
code_micro_40e50c02
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/package.json from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"main\": \"../dist/index.js\",\n \"types\": \"../dist/index.d.ts\"\n}\n\n```"
}
] |
code_micro_226c81b4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/typings.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ServeCompiler, ResolvedPage } from '@vtex/micro-core'\nimport express, { NextFunction, Request, Response } from 'express'\nimport { Stats } from 'webpack'\n\ninterface Locals {\n compiler: ServeCompiler<unknown>,\n route: {\n page: ResolvedPage<any>\n path: string\n },\n webpackStats?: {\n stats: Stats[]\n }\n}\n\nexport type Res = Omit<Response, 'locals'> & {\n locals: Locals\n}\n\nexport type Req = Request\n\nexport type Next = NextFunction\n\nexport default express\n\n```"
}
] |
code_micro_d2ca3091
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/middlewares/data.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Req, Res } from '../typings'\n\nexport const middleware = async (req: Req, res: Res) => {\n const {\n locals: {\n route: {\n page: { data, status }\n }\n }\n } = res\n\n res.type('json')\n res.status(status).send(data)\n}\n\n```"
}
] |
code_micro_8b983b02
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/middlewares/headers.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Next, Req, Res } from '../typings'\n\nexport const middleware = (req: Req, res: Res, next: Next) => {\n try {\n res.set('cache-control', 'max-age=1200, public, immutable')\n next()\n } catch (err) {\n res.set('cache-control', 'max-age=10, public')\n throw err\n }\n}\n\n```"
}
] |
code_micro_6994bbe0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/middlewares/router.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport {\n isResolvedPage,\n isResolvedRedirect,\n Project,\n PublicPaths\n} from '@vtex/micro-core'\nimport assert from 'assert'\n\nimport { Next, Req, Res } from '../typings'\n\nexport const middleware = async (project: Project, publicPaths: PublicPaths) => {\n const router = await project.getRouter()\n\n assert(typeof router === 'function', 'π£ No router found for package')\n console.log('π [router]: Found router config')\n\n return async (req: Req, res: Res, next: Next) => {\n const rootPath = req.path.startsWith(publicPaths!.data)\n ? publicPaths!.data\n : '/'\n const path = req.path.replace(rootPath, '/')\n\n const page = await router({ path, query: req.query as Record<string, string> }, {})\n\n if (isResolvedRedirect(page)) {\n res.redirect(page.status, page.location)\n return\n }\n\n if (isResolvedPage(page)) {\n res.locals.route = { page, path }\n return next()\n }\n\n throw new Error(`π£ Entry not resolved for path ${path}`)\n }\n}\n\n```"
}
] |
code_micro_f048d1c1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/middlewares/assets.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Project, PublicPaths } from '@vtex/micro-core'\nimport { PosixFS, ZipOpenFS } from '@yarnpkg/fslib'\nimport { getLibzipSync } from '@yarnpkg/libzip'\nimport assert from 'assert'\nimport { createReadStream, pathExists } from 'fs-extra'\nimport mime from 'mime-types'\nimport { basename, extname, join } from 'path'\nimport pnp from 'pnpapi'\n\nimport { Req, Res } from '../typings'\n\nconst libzip = getLibzipSync()\n\n// This will transparently open zip archives\nconst zipOpenFs = new ZipOpenFS({ libzip })\n\n// This will convert all paths into a Posix variant, required for cross-platform compatibility\nconst crossFs = new PosixFS(zipOpenFs)\n\nconst resolveBundleAssets = (assetsRootPath: string, path: string) => {\n const asset = join(assetsRootPath, path)\n return createReadStream(asset, { encoding: 'utf-8' })\n}\n\nconst resolveES6Assets = async (assetsRootPath: string, path: string) => {\n const relativeImport = join(assetsRootPath, path)\n if (await pathExists(relativeImport)) {\n return createReadStream(relativeImport, { encoding: 'utf-8' })\n }\n\n // Maybe this was a default import ?\n const relativeDefaultImport = join(relativeImport.replace('.js', ''), 'index.js')\n if (await pathExists(relativeDefaultImport)) {\n return createReadStream(relativeDefaultImport, { encoding: 'utf-8' })\n }\n\n // It's a module. Let's resolve it using PnP API\n const [issuer, rest] = path.split('__imports__')\n const splitted = rest.slice(1).split('/')\n const module = splitted[0].startsWith('@') ? splitted.slice(0, 2).join('/') : splitted[0]\n const filepath = rest.replace(module, '')\n\n // Let's first read the package json so we read the module property\n const unqualified = pnp.resolveToUnqualified(module, issuer) || ''\n const packageJSONPath = join(unqualified, 'package.json')\n const packageJSON = await crossFs.readJsonPromise(packageJSONPath)\n\n // Let's just try a module relative import at first\n const moduleRelativeImport = join(unqualified, filepath)\n if (await pathExists(moduleRelativeImport)) {\n return createReadStream(moduleRelativeImport, { encoding: 'utf-8' })\n }\n\n assert(packageJSON.module, `π£ The package should contain a module locator for es6 packages. Maybe package ${module} is not compatbile with Micro π`)\n\n // Now let's try to resolve the path\n const moduleSplitted = packageJSON.module.split('/')\n const dist = moduleSplitted.slice(0, moduleSplitted.length - 1).join('/')\n const moduleImport = join(unqualified, dist, filepath)\n if (await crossFs.existsPromise(moduleImport)) {\n return crossFs.createReadStream(moduleImport, { encoding: 'utf-8' })\n }\n\n // Maybe this was a default import ?\n const moduleDefaultImport = join(moduleImport.replace('.js', ''), 'index.js')\n if (await pathExists(moduleDefaultImport)) {\n return createReadStream(moduleDefaultImport, { encoding: 'utf-8' })\n }\n\n throw new Error(`π£ Asset Not Found: ${path}`)\n}\n\nexport const middleware = (project: Project, publicPaths: PublicPaths) => {\n const assetsRootPath = process.env.NODE_ENV === 'production'\n ? join(project.dist, 'bundle/webnew')\n : join(project.dist, 'build/es6')\n\n return async (req: Req, res: Res) => {\n try {\n const rootPath = req.path.startsWith(publicPaths.assets)\n ? publicPaths.assets\n : '/'\n const rawPath = req.path.replace(rootPath, '')\n const extension = extname(rawPath) ? '' : '.js'\n const path = rawPath + extension\n\n // Set correctly the MIME type of the object\n const contentType = mime.contentType(basename(path))\n if (contentType) {\n res.set('content-type', contentType)\n }\n\n const stream = process.env.NODE_ENV === 'production'\n ? resolveBundleAssets(assetsRootPath, path)\n : await resolveES6Assets(assetsRootPath, path)\n\n res.statusCode = 200\n stream.pipe(res)\n } catch (err) {\n res.status(404).send(null)\n console.error(err)\n }\n }\n}\n\n```"
}
] |
code_micro_47be06c0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-server/lib/middlewares/ssr.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ImportMap, ServeCompiler } from '@vtex/micro-core'\nimport pretty from 'pretty'\n\nimport { featuresFromReq } from '../features'\nimport { Req, Res } from '../typings'\n\nconst ok = (\n compiler: ServeCompiler<unknown>,\n body: string\n) => `<!DOCTYPE html>\n<html>\n<head>\n${compiler.getMetaTags()}\n${compiler.getLinkTags()}\n${compiler.getStyleTags()}\n</head>\n<body>\n${body}\n${compiler.getScriptTags()}\n</body>\n</html>\n`\n\nexport const middleware = (req: Req, res: Res) => {\n const { locals: { compiler, route: { page: { status } } } } = res\n const { disableSSR } = featuresFromReq(req)\n\n const body = compiler.renderToString(disableSSR)\n const html = ok(compiler, body)\n\n res.status(status).send(html)\n}\n\nconst okSSR = (\n compiler: ServeCompiler<unknown>,\n body: string,\n importMap: ImportMap\n) => `<!DOCTYPE html>\n<html>\n<head>\n${compiler.getMetaTags()}\n${compiler.getLinkTags()}\n${compiler.getStyleTags()}\n</head>\n<body>\n<script type=\"importmap-shim\">${JSON.stringify(importMap)}</script>\n${compiler.getScriptTags()}\n${body}\n</body>\n</html>\n`\n\nexport const devSSR = (importMap: ImportMap) => {\n return (req: Req, res: Res) => {\n const { locals: { route: { page: { status } } } } = res\n const { disableSSR } = featuresFromReq(req)\n const compiler = res.locals.compiler\n\n const body = compiler.renderToString(disableSSR)\n const html = pretty(okSSR(compiler, body, importMap))\n\n res.type('html')\n res.status(status).send(html)\n }\n}\n\n```"
}
] |
code_micro_a182b229
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/constants.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const SERVER_PORT = Number.parseInt(process.env.PORT || '3000')\n\nexport const HOST = 'http://localhost'\n\nexport const BUILD = 'webpack.stats.json'\n\nexport const PUBLIC_PATHS = {\n assets: '/assets/',\n data: '/api/'\n}\n\n```"
}
] |
code_micro_54f8f9be
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n#!/usr/bin/env node\nimport chalk from 'chalk'\nimport {\n CommandNotFoundError,\n find,\n MissingRequiredArgsError,\n run as unboundRun\n} from 'findhelp'\nimport { join } from 'path'\n\nimport { tree } from './modules/tree'\n\nconst run = (command: any) => unboundRun.call(tree, command, join(__dirname, 'modules'))\n\nconst main = async () => {\n try {\n console.log('π¦ Welcome to Micro')\n const args = process.argv.slice(2)\n await run(find(tree, args))\n } catch (e) {\n switch (e.name) {\n case MissingRequiredArgsError.name:\n console.error('Missing required arguments:', chalk.blue(e.message))\n break\n case CommandNotFoundError.name:\n console.error('Command not found:', chalk.blue(...process.argv.slice(2)))\n break\n default:\n console.error(chalk.red('π£ Something exploded:\\n'), e)\n }\n }\n}\n\nmain()\n\n```"
}
] |
code_micro_059fb82a
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/common/project.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport {\n LifeCycle,\n MICRO_BUILD_DIR,\n Plugins,\n Project,\n walk\n} from '@vtex/micro-core'\nimport chalk from 'chalk'\nimport { ensureDir } from 'fs-extra'\nimport { join } from 'path'\n\nexport const newProject = async () => {\n const projectPath = process.cwd()\n\n const project = new Project({ rootPath: projectPath })\n\n console.log('π¦ Resolving dependencies')\n await project.resolvePackages()\n walk(project.root, curr => {\n console.info(`π¦ Micro package found: ${curr.toString()}`)\n })\n\n return project\n}\n\nexport const ensureDist = async (target: string, path: string) => {\n console.log(`π― [${target}]: Ensuring dist folder in ${chalk.cyanBright(join(MICRO_BUILD_DIR, path.split(MICRO_BUILD_DIR)[1]))}`)\n await ensureDir(path)\n}\n\nexport const resolvePlugins = async <T extends LifeCycle>(project: Project, lifecycle: T): Promise<NonNullable<Plugins[T]>[]> => {\n console.log(`π¦ [${lifecycle}]: Resolving plugins`)\n const plugins = await project.resolvePlugins(lifecycle)\n\n for (const pkg of Object.keys(plugins)) {\n console.log(`π [${lifecycle}]: Plugin found ${pkg}`)\n }\n\n return Object.values(plugins)\n}\n\nexport const loadProject = () => {\n\n}\n\n```"
}
] |
code_micro_dc16f8e0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/common/print.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { inspect } from 'util'\n\nexport const prettyPrint = (obj: any) => {\n console.log(inspect(obj, false, 100, true))\n}\n\n```"
}
] |
code_micro_85e0cbd6
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/modules/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { help } from 'findhelp'\n\nimport { tree } from './tree'\n\nexport default async () => {\n console.log(help(tree, { name: 'micro' }))\n}\n\n```"
}
] |
code_micro_4bd9f8a0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/modules/tree.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const tree = {\n build: {\n description: 'Access for Build Micro lifecycle',\n options: [\n {\n description: 'Build with dev environment',\n long: 'dev',\n type: 'boolean'\n }\n ]\n },\n bundle: {\n description: 'Access for Bundle Micro lifecycle',\n options: [\n {\n description: 'Build with dev environment',\n long: 'dev',\n type: 'boolean'\n }\n ],\n report: {\n description: 'Generate a report using a bundled build'\n },\n config: {\n description: 'Print webpack config that would be generated in a normal bundle assembly'\n }\n },\n link: {\n description: 'Develop a Micro project'\n },\n serve: {\n description: 'Serve a bundled Micro project',\n options: [\n {\n description: 'Build with dev environment',\n long: 'dev',\n type: 'boolean'\n },\n {\n description: 'Port to Serve the micro Project',\n short: 'p',\n type: 'number'\n }\n ]\n },\n setup: {\n description: 'Setup the current package.json as a Micro project',\n options: [\n {\n description: 'Do not change files, just show what would be output by this command',\n long: 'dry',\n short: 'd',\n type: 'boolean'\n }\n ]\n },\n options: [\n {\n description: 'Show help information',\n long: 'help',\n short: 'h',\n type: 'boolean'\n }\n ]\n}\n\n```"
}
] |
code_micro_68a9aab3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/typings/findhelp/index.d.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ndeclare module 'findhelp' {\n function find (tree: any, args: any): any\n function run (...args: any[]): Promise<any>\n function help (...args: any[]): any\n\n export class CommandNotFoundError extends Error {}\n export class MissingRequiredArgsError extends Error {}\n}\n\n```"
}
] |
code_micro_268090f7
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/modules/setup/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { genManifest, genTSConfig, PackageStructure } from '@vtex/micro-core'\nimport { outputFile, readJSON } from 'fs-extra'\nimport { join } from 'path'\n\nimport { prettyPrint } from './../../common/print'\n\ninterface Options {\n dry?: boolean\n d?: boolean\n}\n\n// TODO: we should also:\n// - yarn add typescript --dev\n// - yarn add eslint --dev\n// - yarn dlx @yarnpkg/pnpify --sdk # to setup vscode\nconst main = async ({ dry, d }: Options) => {\n const dryRun = dry || d\n\n const projectPath = process.cwd()\n\n const manifestPath = join(projectPath, PackageStructure.manifest)\n const tsconfigPath = join(projectPath, PackageStructure.tsconfig)\n\n const originalManifest = await readJSON(manifestPath).catch(() => {})\n const originalTSConfig = await readJSON(tsconfigPath).catch(() => {})\n\n const manifest = genManifest(originalManifest)\n const tsconfig = genTSConfig(originalTSConfig)\n\n if (dryRun) {\n console.log(PackageStructure.manifest)\n prettyPrint(manifest)\n console.log('')\n console.log(PackageStructure.tsconfig)\n prettyPrint(tsconfig)\n return\n }\n\n console.log('π Writting new manifest file for your project')\n await outputFile(manifestPath, JSON.stringify(manifest, null, 2))\n\n console.log('π Writting new tsconfig file for your project')\n await outputFile(tsconfigPath, JSON.stringify(tsconfig, null, 2))\n}\n\nexport default main\n\n```"
}
] |
code_micro_1413dbdd
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/modules/bundle/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Mode, BundleCompiler } from '@vtex/micro-core'\nimport chalk from 'chalk'\nimport { outputJSON } from 'fs-extra'\nimport { join } from 'path'\nimport webpack, { Compiler, Stats } from 'webpack'\n\nimport { ensureDist, newProject, resolvePlugins } from '../../common/project'\nimport { BUILD } from '../../constants'\n\nconst lifecycle = 'bundle'\n\nconst runWebpack = (compiler: Compiler) => new Promise<Stats>((resolve, reject) => {\n compiler.run((err, stats) => {\n if (err) {\n reject(err)\n }\n return resolve(stats)\n })\n})\n\ninterface Options {\n dev?: boolean\n}\n\nconst main = async (options: Options) => {\n const dev = !!options.dev\n const mode: Mode = dev ? 'development' : 'production'\n process.env.NODE_ENV = mode\n\n const project = await newProject()\n\n console.log(`π¦ Starting Micro for ${chalk.magenta(project)} at ${chalk.blue(lifecycle)}:${chalk.blue(mode)}`)\n\n const partial = await resolvePlugins(project, lifecycle)\n const self = await project.getSelfPlugin(lifecycle)\n const plugins = self ? [self, ...partial] : partial\n\n console.log(`π¦ [${lifecycle}]: Creating Compiler`)\n const compiler = new BundleCompiler({ project, plugins, mode })\n const configs = await compiler.getConfig('webnew')\n\n await ensureDist(lifecycle, compiler.dist)\n\n for (const page of Object.keys(configs.entry || {})) {\n console.log(`π [${lifecycle}]: Page found: ${page}`)\n }\n\n console.log(`π¦ [${lifecycle}]: Running Build`)\n console.time(`π¦ [${lifecycle}]: Build took`)\n const stats = await runWebpack(webpack(configs))\n console.timeEnd(`π¦ [${lifecycle}]: Build took`)\n\n console.time(`π¦ [${lifecycle}]: Webpack Stats file generation took`)\n const statsJSON = stats.toJson({ all: true })\n console.timeEnd(`π¦ [${lifecycle}]: Webpack Stats file generation took`)\n\n if (stats.hasErrors()) {\n console.error('ββ Webpack build finshed with the following errors\\n')\n for (const err of statsJSON.errors) {\n console.log(err)\n }\n }\n\n if (stats.hasWarnings()) {\n console.warn('β Webpack build finshed with the following warnings\\n')\n for (const warning of statsJSON.warnings) {\n console.log(warning)\n }\n console.warn(`β Please run ${chalk.blue('micro bundle report')} for a better view of what is going on with your bundle`)\n }\n\n const dist = join(compiler.dist, BUILD)\n console.log(`π¦ [${lifecycle}]: Persisting Build on ${dist.replace(project.rootPath, '')}`)\n await outputJSON(dist, statsJSON, { spaces: 2 })\n}\n\nexport default main\n\n```"
}
] |
code_micro_50767e7b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/modules/link/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { importMapFromAliases, Mode } from '@vtex/micro-core'\nimport { startDevServer } from '@vtex/micro-server'\nimport chalk from 'chalk'\nimport chokidar from 'chokidar'\n\nimport { newProject, resolvePlugins } from '../../common/project'\nimport { HOST, PUBLIC_PATHS, SERVER_PORT } from '../../constants'\nimport {\n clean,\n createGetFolderFromFile,\n getBuilders,\n lifecycle,\n rejectDeclarationFiles\n} from '../build/builder'\n\nconst waitForReady = (watcher: chokidar.FSWatcher) => new Promise(resolve => watcher.on('ready', resolve))\n\nconst main = async () => {\n const mode: Mode = 'development'\n process.env.NODE_ENV = mode\n\n const project = await newProject()\n\n console.log(`π¦ Starting Micro for ${chalk.magenta(project)} at ${chalk.blue(lifecycle)}:${chalk.blue(mode)}`)\n\n const { createBuild, createPreBuild } = await getBuilders(project, mode)\n\n await clean(project, 'build')\n\n console.log(`π¦ [${lifecycle}]: Starting the build`)\n\n const [framework, userland] = await Promise.all([\n project.root.getFiles('lib', 'plugins', 'index').then(rejectDeclarationFiles),\n project.root.getFiles('components', 'pages', 'router').then(rejectDeclarationFiles)\n ])\n\n const msg = `π¦ [${lifecycle}]: The build of ${framework.length + userland.length} files finished in`\n console.time(msg)\n const { prebuild } = await createPreBuild()\n await Promise.all(framework.map(f => prebuild(f, false)))\n\n const { build, compiler: buildCompiler } = await createBuild()\n await Promise.all(userland.map(f => build(f, false)))\n console.timeEnd(msg)\n\n // This function will select if we should apply Build or Prebuild\n // once a watched file changes\n const entryFromFile = createGetFolderFromFile(project)\n const compile = (f: string) => {\n const entry = entryFromFile(f)\n if (['lib', 'plugins', 'index.ts'].includes(entry)) {\n return prebuild(f)\n }\n return build(f)\n }\n\n const watcher = chokidar.watch(\n project.root.getGlobby('lib', 'plugins', 'components', 'pages', 'router', 'index'),\n { cwd: project.rootPath, ignoreInitial: true }\n )\n\n // TODO: I think we can safetely implement these\n watcher.on('addDir', () => { console.error('π£ not implemented: addDir') })\n watcher.on('unlink', () => { console.error('π£ not implemented: unlink') })\n watcher.on('unlinkDir', () => { console.error('π£ not implemented: unlinkDir') })\n watcher.on('error', console.error)\n watcher.on('change', compile)\n watcher.on('add', compile)\n\n await waitForReady(watcher)\n\n const hasPages = (await project.root.getFiles('pages')).length > 0\n const hasRouter = (await project.root.getFiles('router')).length > 0\n if (hasRouter && hasPages) {\n console.log('π¦ Resolving aliases')\n const [pluginAliases, projectAliases] = await Promise.all([\n buildCompiler.getAliases('warn'),\n project.resolveAliases()\n ])\n\n console.log('π¦ Building import map')\n const importMap = importMapFromAliases(projectAliases, pluginAliases, PUBLIC_PATHS)\n\n console.log(`π¦ [${lifecycle}]: Starting DevServer`)\n\n await startDevServer({\n publicPaths: PUBLIC_PATHS,\n importMap,\n project,\n plugins: await resolvePlugins(project, 'serve'),\n host: HOST,\n port: SERVER_PORT\n } as any)\n }\n}\n\nexport default main\n\n```"
}
] |
code_micro_1f0db792
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/modules/serve/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Mode } from '@vtex/micro-core'\nimport { startDevServer, startProdServer } from '@vtex/micro-server'\nimport chalk from 'chalk'\nimport { readJSON } from 'fs-extra'\nimport { join } from 'path'\n\nimport { newProject, resolvePlugins } from '../../common/project'\nimport { BUILD, HOST, PUBLIC_PATHS, SERVER_PORT } from '../../constants'\n\nconst lifecycle = 'serve'\n\ninterface Options {\n dev: boolean\n p?: number\n}\n\nconst main = async (options: Options) => {\n const port = options.p || SERVER_PORT\n const mode: Mode = options.dev ? 'development' : 'production'\n process.env.NODE_ENV = mode\n\n const project = await newProject()\n\n console.log(`π¦ Starting Micro for ${chalk.magenta(project)} at ${chalk.blue(lifecycle)}:${chalk.blue(mode)}`)\n\n const partial = await resolvePlugins(project, lifecycle)\n const self = await project.getSelfPlugin(lifecycle)\n const plugins = self ? [...partial, self] : partial\n\n console.log(`π¦ Serving ${project.root.toString()}`)\n\n if (mode === 'production') {\n console.log(`π¦ Reading build state on ${project.dist.replace(project.rootPath, '.')}`)\n const statsJson = await readJSON(join(project.dist, 'bundle', BUILD))\n\n console.log(`π¦ [${lifecycle}]: Starting ProdServer`)\n await startProdServer({\n publicPaths: PUBLIC_PATHS,\n statsJson,\n project,\n plugins,\n host: HOST,\n port\n })\n } else if (mode === 'development') {\n console.log(`π¦ [${lifecycle}]: Starting DevServer`)\n\n await startDevServer({\n publicPaths: PUBLIC_PATHS,\n project,\n plugins,\n port,\n host: HOST\n } as any)\n }\n}\n\nexport default main\n\n```"
}
] |
code_micro_797df846
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/modules/bundle/config/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Mode, BundleCompiler } from '@vtex/micro-core'\nimport chalk from 'chalk'\n\nimport { newProject, resolvePlugins } from '../../../common/project'\nimport { prettyPrint } from '../../../common/print'\n\nconst lifecycle = 'bundle'\n\ninterface Options {\n dev?: boolean\n}\n\nconst main = async (options: Options) => {\n const dev = !!options.dev\n const mode: Mode = dev ? 'development' : 'production'\n process.env.NODE_ENV = mode\n\n const project = await newProject()\n\n console.log(`π¦ Starting Micro for ${chalk.magenta(project)} at ${chalk.blue(lifecycle)}:${chalk.blue(mode)}`)\n\n const partial = await resolvePlugins(project, lifecycle)\n const self = await project.getSelfPlugin(lifecycle)\n const plugins = self ? [self, ...partial] : partial\n\n console.log(`π¦ [${lifecycle}]: Creating Compiler`)\n const compiler = new BundleCompiler({ project, plugins, mode })\n const configs = await compiler.getConfig('webnew')\n\n prettyPrint(configs)\n}\n\nexport default main\n\n```"
}
] |
code_micro_f5ffbe38
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-cli/lib/modules/bundle/report/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport open from 'open'\n\nconst target = 'bundle'\n\nconst main = async () => {\n console.log(`π¦ Starting ${target} report`)\n\n open('http://webpack.github.io/analyse/')\n}\n\nexport default main\n\n```"
}
] |
code_micro_c2ccae42
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/aliases.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// This plugin will enforce the following modules. This means\n// projects using this package as a plugin will use this package's\n// versions of the following packages\nexport const aliases = [\n 'exenv',\n 'react',\n 'react-dom',\n '@loadable/component'\n]\n\n```"
}
] |
code_micro_9afa8c18
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/data.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { canUseDOM } from 'exenv'\n\nimport { join } from './path'\n\nconst id = '__MICRO_PAGE_DATA__'\n\nexport const getPageData = async () => {\n if (!canUseDOM) {\n throw new Error('π£ PageData fetch can only be run on the browser')\n }\n\n const dataElement = document.getElementById(id)\n if (typeof (dataElement as any)?.href === 'string') {\n const maybeDataPath = (dataElement as any)?.href\n const response = await fetch(maybeDataPath)\n return response.json()\n }\n\n return null\n}\n\nexport const withPageDataTags = (pageName: string, pageData: any, dataRootPath: string, path: string) => pageData !== undefined\n ? `<link id=\"${id}\" data-chunk=\"${pageName}\" rel=\"preload\" as=\"fetch\" href=\"${join(dataRootPath, path)}\" crossorigin=\"anonymous\">`\n : ''\n\n```"
}
] |
code_micro_162823ee
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/path.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nconst removeEndingSlash = (x: string) => x.endsWith('/') ? x.slice(0, x.length - 1) : x\n\nconst ensureStartingSlash = (x: string) => x.startsWith('/') || x === '' ? x : `/${x}`\n\nexport const join = (...args: string[]) => args.reduce(\n (acc, cur) => `${removeEndingSlash(acc)}${ensureStartingSlash(cur)}`,\n ''\n)\n\n```"
}
] |
code_micro_b7c926d7
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/loader.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { loadableReady } from '@loadable/component'\nimport { canUseDOM } from 'exenv'\nimport React, { StrictMode } from 'react'\nimport { hydrate, render } from 'react-dom'\n\nimport { getAppContainer } from './container'\nimport { Runtime } from './context/Runtime'\nimport { getPageData } from './data'\nimport { once } from './once'\nimport { getRuntimeData } from './runtime'\n\nconst printPerformance = () => {\n const timing = window.performance?.timing\n if (!timing) {\n return\n }\n const domContentLoaded = timing.domContentLoadedEventEnd - timing.navigationStart\n const loaded = timing.loadEventEnd - timing.navigationStart\n console.log(`[micro-react]: β‘β‘ DomContentLoaded ${domContentLoaded / 1e3}ms`)\n console.log(`[micro-react]: β‘β‘ Load ${loaded / 1e3}ms`)\n}\n\nconst renderOrHydrate = (App: React.ReactType) => async () => {\n const container = getAppContainer()\n const runtimeData = getRuntimeData()\n\n // This should be preloaded by now\n let error = null\n const data = await getPageData().catch(err => { error = err })\n\n const AppWithContext = (\n <StrictMode>\n <Runtime.Provider value={runtimeData}>\n <App data={data} error={error} />\n </Runtime.Provider>\n </StrictMode>\n )\n\n if (container.children.length > 0) {\n const msg = '[micro-react]: β‘β‘ Hydration took'\n console.time(msg)\n console.log('hydrationStart', (Date.now() - window.performance.timing.navigationStart) / 1e3)\n hydrate(AppWithContext, container)\n console.timeEnd(msg)\n } else {\n const msg = '[micro-react]: β‘ Rendering took'\n console.time(msg)\n console.log('renderStart', (Date.now() - window.performance.timing.navigationStart) / 1e3)\n render(AppWithContext, container)\n console.timeEnd(msg)\n }\n\n printPerformance()\n}\n\nexport const LoadMicroComponent = (App: React.ReactType) => {\n if (canUseDOM) {\n const renderOnce = once(renderOrHydrate(App))\n setTimeout(renderOnce, 6e3)\n\n if (document.readyState !== 'complete') {\n window.onload = () => loadableReady(renderOnce)\n } else {\n loadableReady(renderOnce)\n }\n }\n return App\n}\n\n```"
}
] |
code_micro_810fb90c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/once.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const once = <T extends (...args: any) => any>(fn: T) => {\n let called = false\n let ret: ReturnType<T> | null = null\n\n return (...args: Parameters<T>): ReturnType<T> => {\n if (called) {\n return ret as ReturnType<T>\n }\n called = true\n ret = fn(...args as any)\n return ret as ReturnType<T>\n }\n}\n\n```"
}
] |
code_micro_c2493244
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/container.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const appContainerId = 'root'\n\nexport const getAppContainer = () => {\n const container = document.getElementById(appContainerId)\n if (!container) {\n throw new Error('π£ This is embarrassing, the App couldnt find a container to fit it')\n }\n return container\n}\n\nexport const withAppContainerTags = (ssr: string) => `<div id=\"${appContainerId}\">${ssr}</div>`\n\n```"
}
] |
code_micro_29ac0dcf
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/runtime.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { PublicPaths } from '@vtex/micro-core'\nimport { canUseDOM } from 'exenv'\n\nexport interface RuntimeData {\n publicPaths: PublicPaths\n}\n\nconst runtimeContainerId = '__MICRO_REACT_RUNTIME__'\n\nexport const getRuntimeData = () => {\n console.assert(canUseDOM, 'π£ Runtime hydration can only be run on the browser')\n const dataElement = document.getElementById(runtimeContainerId)\n const maybeRuntime = JSON.parse(dataElement?.textContent || '{}')\n return ensureRuntime({ publicPaths: maybeRuntime })\n}\n\nexport const withRuntimeTags = (runtime: RuntimeData) =>\n `<script id=\"${runtimeContainerId}\" type=\"application/json\">${JSON.stringify(runtime.publicPaths)}</script>`\n\nconst isRuntimeData = (obj: any): obj is RuntimeData => {\n const paths = obj?.publicPaths\n return typeof paths?.assets === 'string' && typeof paths?.data === 'string'\n}\n\nconst ensureRuntime = (obj: any): RuntimeData => {\n if (!isRuntimeData(obj)) {\n throw new Error(`π£ Error while validating runtime data ${JSON.stringify(obj)}`)\n }\n return obj\n}\n\n```"
}
] |
code_micro_712d52ec
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport * from './loader'\nexport * from './context/Runtime'\nexport * from './runtime'\nexport * from './container'\nexport * from './inflight'\nexport * from './path'\nexport * from 'exenv'\n\n```"
}
] |
code_micro_0360b9a2
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/publicPaths.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const externalPublicPathVariable = 'window.__MICRO_PUBLIC_PATH__'\n\n```"
}
] |
code_micro_2d2ecc07
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/inflight.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nconst active: Record<string, Promise<any>> = {}\n\nconst cleanUp = (key: string) => <T>(result: T) => {\n delete active[key]\n return result\n}\n\nexport const inflight = <T>(key: string, doFly: () => Promise<T>): Promise<T> => {\n if (!active[key]) {\n const clean = cleanUp(key)\n active[key] = doFly()\n .then(clean)\n .catch(e => {\n clean(e)\n throw e\n })\n }\n return active[key]\n}\n\n```"
}
] |
code_micro_40a84467
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/bundle/webold.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Block, Context } from 'webpack-blocks'\n\nimport { babel } from './modules/babel'\n\nexport const weboldBabel: Block<Context> = babel({\n caller: { target: 'webold' },\n presets: [\n ['@babel/preset-env', {\n targets: {\n browsers: 'cover 99.5%'\n }\n }],\n '@babel/preset-react',\n [\n '@babel/preset-typescript', {\n isTSX: true,\n allExtensions: true\n }\n ]\n ],\n plugins: [\n '@babel/plugin-proposal-class-properties',\n '@babel/plugin-syntax-dynamic-import',\n '@loadable/babel-plugin'\n ]\n} as any)\n\n```"
}
] |
code_micro_341f4929
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/bundle/webnew.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Block, Context } from 'webpack-blocks'\n\nimport { babel } from './modules/babel'\n\nexport const webnewBabel: Block<Context> = babel({\n comments: true,\n minified: false,\n retainLines: true,\n shouldPrintComment: () => true,\n caller: { target: 'webnew' },\n presets: [\n [\n require.resolve('@babel/preset-env'), {\n targets: {\n esmodules: true\n },\n modules: false,\n bugfixes: true,\n exclude: [\n '@babel/plugin-proposal-object-rest-spread',\n '@babel/plugin-proposal-async-generator-functions',\n '@babel/plugin-transform-async-to-generator',\n '@babel/plugin-transform-regenerator',\n '@babel/plugin-transform-arrow-functions',\n '@babel/plugin-transform-destructuring',\n '@babel/plugin-transform-for-of',\n '@babel/plugin-transform-spread',\n '@babel/plugin-transform-typeof-symbol'\n ]\n }\n ],\n [\n require.resolve('@babel/preset-react'), {\n useBuiltIns: true\n }\n ],\n [\n require.resolve('@babel/preset-typescript'), {\n isTSX: true,\n allExtensions: true\n }\n ]\n ],\n plugins: [\n '@babel/plugin-proposal-class-properties',\n '@babel/plugin-syntax-dynamic-import',\n '@loadable/babel-plugin'\n ].map(require.resolve as any)\n} as any)\n\n```"
}
] |
code_micro_b9788c58
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/bundle/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport LoadablePlugin from '@loadable/webpack-plugin'\nimport {\n BundlePlugin,\n BundleTarget,\n pagesFrameworkName,\n pagesRuntimeName,\n Project\n} from '@vtex/micro-core'\nimport OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin'\nimport { basename } from 'path'\nimport PnpPlugin from 'pnp-webpack-plugin'\nimport TerserJSPlugin from 'terser-webpack-plugin'\nimport TimeFixPlugin from 'time-fix-plugin'\nimport {\n addPlugins,\n Block,\n Context,\n customConfig,\n defineConstants,\n entryPoint,\n env,\n group,\n match,\n optimization,\n performance,\n resolve,\n setContext,\n setMode,\n sourceMaps\n} from 'webpack-blocks'\nimport DynamicPublicPathPlugin from 'webpack-dynamic-public-path'\n\nimport { externalPublicPathVariable } from '../../components/publicPaths'\nimport { aliases } from '../aliases'\nimport { cacheGroup } from './modules/cacheGroups'\nimport { webnewBabel } from './webnew'\nimport { weboldBabel } from './webold'\n\nconst entriesFromPages = async (project: Project) => {\n const files = await project.root.getFiles('pages')\n return files.reduce(\n (acc, path) => {\n if (path.endsWith('.tsx')) {\n const name = basename(path, '.tsx')\n acc[name] = path.replace(project.rootPath, '.')\n }\n return acc\n },\n {} as Record<string, string>\n )\n}\n\nexport default class Bundle extends BundlePlugin {\n public getConfig = async (config: Block<Context>, target: BundleTarget): Promise<Block<Context>> => {\n const entrypoints = await entriesFromPages(this.project)\n const block: Block<Context>[] = [\n setMode(this.mode),\n setContext(this.project.rootPath),\n entryPoint(entrypoints),\n defineConstants({\n 'process.env.NODE_ENV': this.mode\n }),\n addPlugins([\n new LoadablePlugin({\n outputAsset: false,\n writeToDisk: false\n }),\n new DynamicPublicPathPlugin({\n externalPublicPath: externalPublicPathVariable\n })\n ]),\n resolve({\n alias: aliases.reduce(\n (acc, packageName) => {\n acc[packageName] = require.resolve(packageName)\n return acc\n },\n {} as Record<string, string>\n ),\n extensions: ['.tsx', '.ts', '.js', '.jsx', '.json'],\n plugins: [\n PnpPlugin\n ]\n }),\n cacheGroup(pagesRuntimeName, /\\/react\\/|\\/react-dom\\/|\\/@loadable\\//),\n cacheGroup(pagesFrameworkName, /\\/micro-react\\/components\\//),\n optimization({\n runtimeChunk: {\n name: 'webpack-runtime'\n },\n splitChunks: {\n maxInitialRequests: 30,\n maxAsyncRequests: 10\n }\n } as any),\n customConfig({\n name: target,\n target: 'web',\n bail: true,\n node: false,\n profile: true,\n resolveLoader: {\n plugins: [\n PnpPlugin.moduleLoader(module)\n ]\n }\n }) as Block<Context>,\n env('production', [\n optimization({\n noEmitOnErrors: true,\n namedModules: false,\n namedChunks: false,\n moduleIds: 'size',\n chunkIds: 'total-size',\n nodeEnv: 'production',\n removeAvailableModules: true,\n removeEmptyChunks: true,\n mergeDuplicateChunks: true,\n flagIncludedChunks: true,\n occurrenceOrder: true,\n providedExports: true,\n usedExports: true,\n concatenateModules: true,\n sideEffects: true,\n portableRecords: false,\n minimizer: [\n new TerserJSPlugin({\n extractComments: true\n }),\n new OptimizeCSSAssetsPlugin({\n cssProcessorPluginOptions: {\n preset: ['default', { discardComments: { removeAll: true } }]\n }\n })\n ]\n } as any),\n performance({\n hints: 'warning'\n })\n ]),\n env('development', [\n addPlugins([\n new TimeFixPlugin()\n ]),\n sourceMaps('inline-source-map'),\n customConfig({\n watchOptions: {\n ignored: `${this.project.dist}`,\n aggregateTimeout: 300\n }\n }) as Block<Context>\n ])\n ]\n\n return group([\n config,\n ...block,\n match(['*.tsx', '*.ts'], [target === 'webnew' ? webnewBabel : weboldBabel])\n ])\n }\n}\n\n```"
}
] |
code_micro_b3737dd3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/serve/cjsChunkExtractor.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ServePlugin } from '@vtex/micro-core'\n\nexport interface Extractor {\n addChunk: (chunk: string) => void\n getScriptTags: () => string\n getStyleTags: () => string\n getLinkTags: () => string\n}\n\n// Some dependencies think they have access to this variable. Webpack\n// has a plugin for adding this to the bundles, however we need to\n// add this while using es6 only\nconst setupEnvVar = (options: ServePlugin<unknown>['options']) =>\n`<script>\nwindow.process = {\n env: {\n NODE_ENV: \"${options.mode}\"\n }\n}\n</script>`\n\nconst getModuleImportTag = (options: ServePlugin<unknown>['options']) =>\n`<script type=\"module-shim\">\nimport \"${options.publicPaths.assets}pages/${options.page.name}.js\";\n</script>`\n\n// TODO: We should figure out a way to preload the script tags are we require them\nexport class CJSChunkExtractor implements Extractor {\n protected chunks: Set<string> = new Set()\n\n constructor (\n public options: ServePlugin<unknown>['options']\n ) {}\n\n public addChunk = (chunk: string) => {\n if (!this.chunks.has(chunk)) {\n this.chunks.add(chunk)\n }\n }\n\n public getScriptTags = () =>\n '<script id=\"__LOADABLE_REQUIRED_CHUNKS__\">[]</script>' +\n setupEnvVar(this.options) +\n getModuleImportTag(this.options) +\n '<script src=\"https://unpkg.com/es-module-shims\"></script>' // TODO: Remove this once chrome supports import maps\n\n public getStyleTags = () => ''\n public getLinkTags = () => ''\n}\n\n```"
}
] |
code_micro_ddef4a53
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/serve/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ChunkExtractor, ChunkExtractorManager } from '@loadable/server'\nimport { ServeFrameworkPlugin, ServePluginOptions } from '@vtex/micro-core'\nimport { readFileSync } from 'fs-extra'\nimport { join } from 'path'\nimport { createElement } from 'react'\nimport { renderToString } from 'react-dom/server'\n\nimport { withAppContainerTags } from '../../components/container'\nimport { withPageDataTags } from '../../components/data'\nimport { externalPublicPathVariable } from '../../components/publicPaths'\nimport { withRuntimeTags } from '../../components/runtime'\nimport { CJSChunkExtractor, Extractor } from './cjsChunkExtractor'\n\nexport default class Serve extends ServeFrameworkPlugin<JSX.Element> {\n public extractor: Extractor\n\n constructor (options: ServePluginOptions) {\n super(options)\n if (this.options.lifecycleTarget === 'bundle') {\n this.extractor = new ChunkExtractor({\n entrypoints: [options.page.name],\n publicPath: options.publicPaths.assets,\n stats: options.stats\n }) as any // TODO: fix this as any\n } else {\n this.extractor = new CJSChunkExtractor(options)\n }\n }\n\n public renderToString = (element: JSX.Element | null) => {\n let ssr = ''\n if (element) {\n ssr = renderToString(createElement(ChunkExtractorManager, {\n extractor: this.extractor,\n children: element\n } as any)) // TODO: fix this as any\n }\n return withAppContainerTags(ssr)\n }\n\n public requireEntrypoint = (): JSX.Element => {\n const { page: { data, name } } = this.options\n const locator = join(this.options.assetsDist.nodejs, 'pages', name)\n const { default: App } = require(locator)\n // TODO: Figure out a way to the error come from the router\n return createElement(App, { data, error: null } as any)\n }\n\n public getScriptTags = () => {\n const {\n publicPaths\n } = this.options\n const tags: string[] = []\n tags.push(withRuntimeTags({ publicPaths }))\n tags.push(`<script type=\"application/javascript\">${externalPublicPathVariable}=\"${this.options.publicPaths.assets}\"</script>`)\n tags.push(this.extractor.getScriptTags())\n return tags.join('\\n')\n }\n\n public getStyleTags = () => {\n if (typeof (this.extractor as any).getMainAssets === 'function') {\n const assets = (this.extractor as any).getMainAssets('style')\n return assets.map(\n ({ path, chunk }: { path: string, chunk: string }) => {\n const content = readFileSync(path)\n return `<style data-chunk=\"${chunk}\" rel=\"stylesheet\">${content}</style>`\n }\n ).join('\\n')\n }\n // return this.extractor.getStyleTags()\n }\n\n public getLinkTags = () => {\n const { page: { name, data }, publicPaths: { data: dataRootPath }, path } = this.options\n const tagsNoCSS = this.extractor!.getLinkTags().split('\\n').filter(x => !x.includes('as=\"style\"')).join('\\n')\n const dataTags = withPageDataTags(name, data, dataRootPath, path)\n return [\n tagsNoCSS,\n dataTags\n ].join('\\n')\n // return [\n // dataTags,\n // this.extractor.getLinkTags()\n // ].join('\\n')\n }\n\n public getMetaTags = () => [\n '<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">',\n '<meta name=\"generator\" content=\"micro@1.x\">',\n '<meta charset=\\'utf-8\\'>'\n ].join('\\n')\n}\n\n```"
}
] |
code_micro_18d6e853
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/bundle/modules/babel.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { babel as babelBlocks, Util } from 'webpack-blocks'\n\n// Code copied from: https://github.com/andywer/webpack-blocks/blob/master/packages/babel/index.js\n\nexport const babel: any = (options?: any) => Object.assign(\n babelBlocks(options),\n { post: postConfig }\n)\n\nexport const postConfig: any = (context: any, util: Util) => {\n const ruleConfig = {\n test: /\\.tsx?$/,\n ...context.match,\n use: [\n {\n loader: require.resolve('babel-loader'),\n options: context.babel\n }\n ]\n }\n return util.addLoader(ruleConfig)\n}\n\n```"
}
] |
code_micro_8f77888e
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/bundle/modules/extractCSS.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport webpack from 'webpack'\nimport MiniCssExtractPlugin from 'mini-css-extract-plugin'\nimport { Context, Util } from 'webpack-blocks'\n\ninterface Options {\n loader?: {\n esModule: boolean\n },\n plugin?: MiniCssExtractPlugin.PluginOptions\n}\n\nexport const extractCss = (options?: Options) => (context: Context, { merge }: Util) => merge({\n module: {\n rules: [\n {\n ...context.match,\n use: [\n {\n loader: MiniCssExtractPlugin.loader,\n options: options?.loader\n }\n ]\n }\n ]\n },\n plugins: [\n new MiniCssExtractPlugin(options?.plugin)\n ]\n})\n\n```"
}
] |
code_micro_f8fa8579
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/bundle/modules/purgeCSS.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport PurgeCSSPlugin from 'purgecss-webpack-plugin'\nimport { Configuration } from 'webpack'\nimport { Context, Util } from 'webpack-blocks'\n\ntype FirstOf<T extends [any]> = T extends [infer P] ? P : never\n\ntype Options = FirstOf<ConstructorParameters<typeof PurgeCSSPlugin>>\n\ninterface EnhancedContext extends Context {\n purgeCSSOptions: Options\n}\n\nconst post = (context: Context, { addPlugin }: Util) => {\n const ctx = context as EnhancedContext\n return addPlugin(new PurgeCSSPlugin(ctx.purgeCSSOptions))\n}\n\nexport const purgeCSS = (options: Partial<Options>) => {\n return Object.assign(\n (context: Context) => {\n const ctx = context as EnhancedContext\n ctx.purgeCSSOptions = {\n ...ctx.purgeCSSOptions,\n ...options\n }\n return (config: Configuration) => config\n },\n { post }\n )\n}\n\n```"
}
] |
code_micro_bac9b3c1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/plugins/bundle/modules/cacheGroups.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Configuration } from 'webpack'\nimport { Context } from 'webpack-blocks'\n\nexport const cacheGroup = (name: string, regexp: RegExp) => (_: Context, util: any) => (prevConfig: Configuration) => {\n const previousRegexp = getRegexFromCacheGroup(name, prevConfig.optimization)\n\n return util.merge({\n optimization: {\n splitChunks: {\n cacheGroups: {\n [name]: {\n test: mergeRegex(regexp, previousRegexp),\n reuseExistingChunk: true,\n name: name,\n chunks: 'all',\n enforce: true\n }\n }\n }\n }\n })(prevConfig)\n}\n\nconst mergeRegex = (r1: RegExp, r2: RegExp | undefined): RegExp => {\n if (!r2) {\n return r1\n }\n return new RegExp(r1.source + '|' + r2.source)\n}\n\nconst isRegExp = (a: any): a is RegExp => typeof a.exec === 'function'\n\nconst getRegexFromCacheGroup = (name: string, optimization: Configuration['optimization']) => {\n if (\n !optimization ||\n !optimization.splitChunks ||\n !optimization.splitChunks.cacheGroups ||\n typeof optimization.splitChunks.cacheGroups === 'string' ||\n typeof optimization.splitChunks.cacheGroups === 'function' ||\n isRegExp(optimization.splitChunks.cacheGroups)\n ) {\n return\n }\n const cacheGroup = optimization.splitChunks.cacheGroups[name]\n if (!cacheGroup) {\n return\n }\n if (isRegExp(cacheGroup.test)) {\n return cacheGroup.test\n }\n}\n\n```"
}
] |
code_micro_43a52dba
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react/components/context/Runtime.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\n\nimport { RuntimeData } from '../runtime'\n\nexport const Runtime = React.createContext<RuntimeData>({} as RuntimeData)\n\n```"
}
] |
code_micro_ce0c8041
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/project.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport assert from 'assert'\nimport { join } from 'path'\n\nimport { parse } from './common/semver'\nimport { MICRO_BUILD_DIR } from './constants'\nimport { resolveProjectAliases } from './importMap'\nimport { Package, PackageRootEntries, Plugins } from './package/base'\nimport { PnpPackage } from './package/pnp'\n\nexport type LifeCycle = 'serve' | 'bundle' | 'build'\n\nexport interface ProjectOptions {\n rootPath: string\n}\n\n/**\n * Resolution of the packages project wise\n * For responding, this class usually perform a DFS in the dependency graph of the project\n */\nexport class Project {\n public root: Package = null as any\n public rootPath: string\n public dist: string\n\n constructor ({ rootPath }: ProjectOptions) {\n this.dist = join(rootPath, MICRO_BUILD_DIR)\n this.rootPath = rootPath\n }\n\n public resolveFiles = async (...targets: PackageRootEntries[]): Promise<string[]> => {\n assert(this.root, 'π£ Could not find a package. Did you forget to resolve/restore packages ?')\n let promises: Array<Promise<string[]>> = []\n walk(this.root, curr => {\n const filtered = curr.getFiles(...targets)\n promises = promises.concat(filtered)\n })\n const files = await Promise.all(promises)\n return files.flat()\n }\n\n public resolvePlugins = async <T extends LifeCycle>(target: T): Promise<Record<string, NonNullable<Plugins[T]>>> => {\n assert(this.root, 'π£ Could not find a package. Did you forget to resolve/restore packages ?')\n const dependencies = this.root.manifest.dependencies || {}\n const locators: string[] | undefined = this.root!.manifest.micro.plugins\n if (!locators) {\n return {}\n }\n const packages: Package[] = []\n walk(this.root, async curr => {\n const index = locators.findIndex(x => curr.manifest.name === x)\n if (index < 0) {\n return\n }\n const maybeVersion = dependencies[curr.manifest.name]\n if (maybeVersion && parse(maybeVersion).major === parse(curr.manifest.version).major) {\n const index = locators.findIndex(x => curr.manifest.name === x)\n packages.splice(index, 0, curr)\n }\n })\n const plugins = await packages.reduce(\n async (accPromise, pkg) => {\n const [acc, plugin] = await Promise.all([\n accPromise,\n pkg.getPlugin(target)\n ])\n if (plugin) {\n acc[pkg.manifest.name] = plugin as NonNullable<Plugins[T]>\n }\n return acc\n },\n Promise.resolve({} as Record<string, NonNullable<Plugins[T]>>)\n )\n return plugins\n }\n\n public getSelfPlugin = async <T extends LifeCycle>(target: T): Promise<NonNullable<Plugins[T]> | null> => {\n const plugins = this.root!.manifest.micro.plugins\n const index = plugins?.findIndex(p => p === this.root.manifest.name)\n if (index !== undefined && index > -1) {\n const targetPlugin = await this.root.getPlugin(target)\n if (targetPlugin) {\n return targetPlugin as NonNullable<Plugins[T]>\n }\n }\n return null\n }\n\n public getRouter = () => {\n assert(this.root, 'π£ Could not find a package. Did you forget to resolve/restore packages ?')\n return this.root.getRouter()\n }\n\n public resolvePackages = async (linker: 'pnp' | 'node-modules' = 'pnp') => {\n assert(linker === 'pnp', 'π£ Only PnP linker is implemented yet') // TODO: implement other linkers\n this.root = new PnpPackage()\n await this.root.resolve(this.rootPath)\n }\n\n public toString = () => {\n assert(this.root, 'π£ Could not find a package. Did you forget to resolve/restore packages ?')\n return `${this.root.manifest.name}@${parse(this.root.manifest.version).major}.x`\n }\n\n public resolveAliases = () => resolveProjectAliases(this)\n}\n\nexport type WalkFn = (r: Package, p: Package | null) => void\n\nexport const walk = (root: Package, fn: WalkFn) => {\n const seen = new Set<string>()\n walkRec(root, null, fn, seen)\n return root\n}\n\nconst walkRec = (root: Package, parent: Package | null, fn: WalkFn, seen: Set<string>) => {\n const node = root.toString()\n\n if (seen.has(node)) {\n return\n }\n\n seen.add(node)\n fn(root, parent)\n\n for (const dependency of root.dependencies) {\n walkRec(dependency, root, fn, seen)\n }\n}\n\n```"
}
] |
code_micro_697a3e2d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/router.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface MicroRequest {\n path: string\n query: Record<string, string>\n}\n\nexport type Serializable = object | string | number | null | undefined\n\nexport interface ResolvedPage<T extends Serializable> {\n name: string\n data: T\n status: number\n}\n\ninterface ResolvedRedirect {\n location: string\n status: 301 | 302\n}\n\ntype Resolved<T extends Serializable> = ResolvedPage<T> | ResolvedRedirect\n\nexport const isResolvedPage = <T extends Serializable>(obj: Resolved<T>): obj is ResolvedPage<T> =>\n typeof (obj as any).name === 'string'\n\nexport const isResolvedRedirect = <T extends Serializable>(obj: Resolved<T>): obj is ResolvedRedirect =>\n typeof (obj as any).location === 'string'\n\nexport interface Page {\n name: string\n}\n\nexport type Router<T extends Serializable> = (\n request: MicroRequest,\n pages: Record<string, Page>\n) => Promise<Resolved<T>>\n\n```"
}
] |
code_micro_dfbafca6
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/plugin.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { LifeCycle } from './project'\n\nexport interface PluginOptions {\n target: LifeCycle\n}\n\nexport abstract class Plugin {\n public target: LifeCycle\n\n constructor ({ target }: PluginOptions) {\n this.target = target\n }\n}\n\n```"
}
] |
code_micro_8f0b3508
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport * from './constants'\nexport * from './package/manifest'\nexport * from './package/tsconfig'\nexport * from './package/base'\nexport * from './project'\nexport * from './lifecycles/bundle'\nexport * from './lifecycles/serve'\nexport * from './lifecycles/build'\nexport * from './common/webpack'\nexport * from './common/mode'\nexport * from './common/publicPaths'\nexport * from './common/semver'\nexport * from './router'\nexport * from './importMap'\n\n```"
}
] |
code_micro_05a13cc8
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/compiler.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { join } from 'path'\n\nimport { Plugins } from './package/base'\nimport { Plugin } from './plugin'\nimport { Project } from './project'\n\nexport interface CompilerOptions<T> {\n plugins: T[]\n project: Project\n target: keyof Plugins\n}\n\nexport class Compiler<T extends Plugin> {\n protected plugins: T[]\n public dist: string\n public project: Project\n\n constructor ({ project, target, plugins }: CompilerOptions<T>) {\n this.project = project\n this.plugins = plugins\n this.dist = join(this.project.dist, target)\n }\n}\n\n```"
}
] |
code_micro_aaa384a9
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/importMap.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport assert from 'assert'\nimport { join } from 'path'\nimport pnp from 'pnpapi'\n\nimport { PublicPaths } from './common/publicPaths'\nimport { Alias } from './lifecycles/build'\nimport { getLocatorFromPackageInWorkspace } from './package/pnp/common'\nimport { readManifest, walk as walkPnp } from './package/pnp/dfs'\nimport { Project } from './project'\n\nconst SEPARATOR = '__imports__'\n\nexport const parseImportPath = (x: string) => {\n const [issuer, rest] = x.split('__imports__')\n const splitted = rest.slice(1).split('/')\n const module = splitted[0].startsWith('@') ? splitted.slice(0, 2).join('/') : splitted[0]\n const filepath = rest.replace(module, '')\n return {\n issuer,\n module,\n filepath\n }\n}\n\ntype ImportMapPath = ReturnType<typeof parseImportPath>\n\nexport const formatImportPath = ({ issuer, module, filepath }: ImportMapPath) =>\n join(issuer, SEPARATOR, module, filepath)\n\n// TODO: Make it work for pure linked dependencies with `yarn link`\nexport const resolveProjectAliases = async (project: Project, linker: 'pnp' | 'node-modules' = 'pnp') => {\n assert(linker === 'pnp', 'π£ Only PnP linker is implemented yet') // TODO: implement other linkers\n const root = getLocatorFromPackageInWorkspace(project.root.manifest.name)\n let aliases: Alias[] = []\n\n await walkPnp(root, async (node, parent) => {\n if (parent === null) {\n return\n }\n\n const nodeInfo = pnp.getPackageInformation(node)\n const parentInfo = pnp.getPackageInformation(parent)\n\n const manifest = await readManifest(node, parent)\n\n const isModule = (manifest as any).module\n const isDirectDependency = parent.name === project.root.manifest.name\n const isParentLinked = (parentInfo as any).linkType === 'SOFT'\n const isLinked = (nodeInfo as any).linkType === 'SOFT'\n\n // The current package is linked, we need to serve it from the local filesystem\n if (isLinked || !isModule) {\n const absoluteImport = {\n name: manifest.name,\n version: `^${manifest.version}`,\n resolve: formatImportPath({ issuer: parent!.name!, module: manifest.name, filepath: 'index.js' })\n }\n const relativeImport = {\n name: manifest.name + '/',\n version: `^${manifest.version}`,\n resolve: formatImportPath({ issuer: parent!.name!, module: manifest.name, filepath: '/' })\n }\n aliases = aliases.concat(absoluteImport, relativeImport)\n } else if (isParentLinked || isDirectDependency) {\n aliases.push({ name: manifest.name, version: `^${manifest.version}` })\n }\n })\n\n return aliases\n}\n\nexport interface ImportMap {\n imports: Record<string, string>\n scopes?: Record<string, Record<string, string>>\n}\n\nexport const importMapFromAliases = (projectAliases: Alias[], pluginAliases: Alias[], publicPaths: PublicPaths): ImportMap => {\n const aliases = [...projectAliases, ...pluginAliases]\n const imports = aliases.reduce(\n (acc, { name, version, resolve }) => {\n acc[name] = resolve\n ? join(publicPaths.assets, resolve)\n : `https://cdn.pika.dev/${name}@${version}`\n return acc\n },\n {} as Record<string, string>\n )\n return { imports }\n}\n\n```"
}
] |
code_micro_27bb3c22
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/common/pick.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport const pick = <T, K extends keyof T>(obj: T, keys: K[]) => keys.reduce(\n (acc, key) => {\n acc[key] = obj[key]\n return acc\n },\n {} as Pick<T, K>\n)\n\n```"
}
] |
code_micro_26e48389
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/common/webpack.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { Stats } from 'webpack'\n\nexport const getStatsForTarget = (target: 'nodejs' | 'webnew' | 'webold', stats: Stats.ToJsonOutput) =>\n stats.children?.find(s => s.name === target)\n\n```"
}
] |
code_micro_d0741aa7
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/common/publicPaths.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport interface PublicPaths {\n data: string\n assets: string\n}\n\n```"
}
] |
code_micro_71c4dccd
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/common/semver.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\ninterface Semver {\n major: number\n minor: number\n patch: number\n pre?: string\n}\n\nexport const parse = (version: string): Semver => {\n const v = version.replace(/\\^|~/g, '')\n const [major, minor, ...patchAndPre] = v.split('.')\n const [patch, pre] = patchAndPre.join('.').split('-')\n return {\n major: Number(major),\n minor: Number(minor),\n patch: Number(patch),\n pre\n }\n}\n\nexport const format = ({ major, minor, patch, pre }: Semver) =>\n `${major.toString()}.${minor.toString()}.${patch.toString}${pre ? `-${pre}` : ''}`\n\n// TODO: improve this to a real regex\nexport const isSemver = (x: any): x is Semver => typeof x === 'string'\n\n```"
}
] |
code_micro_49edaa38
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/lifecycles/serve.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { join } from 'path'\nimport { Stats } from 'webpack'\n\nimport { PublicPaths } from '../common/publicPaths'\nimport { Compiler, CompilerOptions } from '../compiler'\nimport { Plugin } from '../plugin'\nimport { LifeCycle } from '../project'\nimport { ResolvedPage } from '../router'\n\nconst lifecycle = 'serve'\n\nexport type ServeCompilerOptions<T> = Omit<CompilerOptions<ServePlugin<T>>, 'target' | 'plugins'> & {\n plugins: Array<new (options: ServePluginOptions) => (ServePlugin<T> | ServeFrameworkPlugin<T>)>\n options: Omit<ServePluginOptions, 'assetsDist'>\n}\n\nconst assetsDistForLifecycle = (root: string, lifecycle: LifeCycle) => {\n if (lifecycle === 'build') {\n return {\n webnew: join(root, 'build/es6'),\n nodejs: join(root, 'build/cjs')\n }\n }\n if (lifecycle === 'bundle') {\n return {\n webnew: join(root, 'bundle/webnew'),\n webold: join(root, 'bundle/webold'),\n nodejs: join(root, 'build/cjs')\n }\n }\n throw new Error('π£ Targeting this lifecycle makes no sense')\n}\n\nexport class ServeCompiler<T> extends Compiler<ServePlugin<T>> {\n protected frameworkPlugin: ServeFrameworkPlugin<T>\n\n constructor ({ project, plugins, options }: ServeCompilerOptions<T>) {\n super({ project, plugins: [], target: lifecycle })\n const fullOptions = {\n ...options,\n assetsDist: assetsDistForLifecycle(project.dist, options.lifecycleTarget)\n }\n this.plugins = plugins.map(P => new P(fullOptions))\n const frameworkIndex = this.plugins.findIndex(p => p instanceof ServeFrameworkPlugin)\n if (frameworkIndex < 0) {\n throw new Error('π£ At least one framework plugin is required. Take a look at @vtex/micro-react for using the React Framework')\n }\n this.frameworkPlugin = this.plugins[frameworkIndex] as ServeFrameworkPlugin<T>\n }\n\n public renderToString = (disableSSR: boolean = false) => {\n let App: T | null = null\n\n if (!disableSSR) {\n // Find a plugin that is able to require an entrypoint\n // Maybe this should be done by the framework itself\n // instead of via plugin\n App = this.frameworkPlugin.requireEntrypoint()\n\n if (App === null) {\n throw new Error('π£ No entrypoint was required during Server Side Rendering')\n }\n\n // Compose the App for SSR\n App = this.plugins.reduce(\n (acc, p) => p.render(acc),\n App\n )\n }\n\n return this.frameworkPlugin.renderToString(App)\n }\n\n public getScriptTags = () => this.plugins.reduce(\n (acc, plugin) => acc + plugin.getScriptTags(),\n ''\n )\n\n public getLinkTags = () => this.plugins.reduce(\n (acc, plugin) => acc + plugin.getLinkTags(),\n ''\n )\n\n public getStyleTags = () => this.plugins.reduce(\n (acc, plugin) => acc + plugin.getStyleTags(),\n ''\n )\n\n public getMetaTags = () => this.plugins.reduce(\n (acc, plugin) => acc + plugin.getMetaTags(),\n ''\n )\n}\n\ninterface AssetsDist {\n webnew: string\n nodejs: string\n webold?: string\n}\n\nexport interface ServePluginOptions {\n mode: 'production' | 'development'\n lifecycleTarget: 'build' | 'bundle'\n stats: Stats.ToJsonOutput\n publicPaths: PublicPaths\n assetsDist: AssetsDist\n page: ResolvedPage<any>\n path: string\n}\n\nexport abstract class ServePlugin<T> extends Plugin {\n constructor (\n protected options: ServePluginOptions\n ) {\n super({ target: lifecycle })\n }\n\n public render = (element: T): T => element\n\n public getScriptTags = () => ''\n\n public getStyleTags = () => ''\n\n public getLinkTags = () => ''\n\n public getMetaTags = () => ''\n}\n\nexport abstract class ServeFrameworkPlugin<T> extends ServePlugin<T> {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public renderToString = (_element: T | null): string => ''\n\n public requireEntrypoint = (): T | null => null\n}\n\n```"
}
] |
code_micro_a21caf7c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/lifecycles/bundle.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { join } from 'path'\nimport { Configuration } from 'webpack'\nimport { Block, Context, createConfig, setOutput } from 'webpack-blocks'\n\nimport { Mode } from '../common/mode'\nimport { Compiler, CompilerOptions } from '../compiler'\nimport { Plugin } from '../plugin'\nimport { Project } from '../project'\n\nconst lifecycle = 'bundle'\n\nexport const pagesRuntimeName = 'micro-runtime'\nexport const webpackRuntimeName = 'webpack-runtime'\nexport const pagesFrameworkName = 'micro-framework'\n\nexport type BundleTarget = 'webnew' | 'webold'\n\nexport type BundleCompilerOptions = Omit<CompilerOptions<BundlePlugin>, 'target' | 'plugins'> & {\n plugins: Array<new (options: BundlePluginOptions) => BundlePlugin>\n mode: Mode\n}\n\nexport class BundleCompiler extends Compiler<BundlePlugin> {\n constructor ({ project, plugins, mode }: BundleCompilerOptions) {\n super({ project, plugins: [], target: lifecycle })\n this.plugins = plugins.map(P => new P({ project, mode }))\n }\n\n public getConfig = async (target: BundleTarget): Promise<Configuration> => {\n const initialConfig = setOutput({\n path: join(this.dist, target),\n publicPath: '/assets'\n })\n const merged = await this.plugins.reduce(\n async (acc, plugin) => plugin.getConfig(await acc, target),\n Promise.resolve(initialConfig)\n )\n return createConfig(merged)\n }\n}\n\nexport interface BundlePluginOptions {\n project: Project\n mode: Mode\n}\n\nexport abstract class BundlePlugin extends Plugin {\n public project: Project\n public mode: Mode\n\n constructor (\n options: BundlePluginOptions\n ) {\n super({ target: lifecycle })\n this.project = options.project\n this.mode = options.mode\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public abstract getConfig = async (config: Block<Context>, target: BundleTarget): Promise<Block<Context>> => {\n throw new Error(`π£ not implemented: ${target}, ${config}`)\n }\n}\n\n```"
}
] |
code_micro_d3c1a3b5
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/lifecycles/build.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { TransformOptions } from '@babel/core'\nimport { readJSON } from 'fs-extra'\nimport { join } from 'path'\n\nimport { parse } from '../common/semver'\nimport { Mode } from '../common/mode'\nimport { Compiler, CompilerOptions } from '../compiler'\nimport { Plugin } from '../plugin'\nimport { Project } from '../project'\n\nexport const lifecycle = 'build'\n\nexport type BuildTarget = 'es6' | 'cjs'\n\nexport interface Alias {\n name: string\n version: string\n resolve?: string\n}\n\nexport type BuildCompilerOptions = Omit<CompilerOptions<BuildPlugin>, 'target' | 'plugins'> & {\n plugins: Array<new (opts: BuildPluginOptions) => BuildPlugin>\n mode: Mode\n}\n\nexport class BuildCompiler extends Compiler<BuildPlugin> {\n private mode: Mode\n\n constructor ({ project, plugins, mode }: BuildCompilerOptions) {\n super({ project, plugins: [], target: lifecycle })\n this.plugins = plugins.map(P => new P({ project, mode }))\n this.mode = mode\n }\n\n public getDist = (target: BuildTarget) => join(this.dist, target)\n\n public getConfig = async (target: BuildTarget) => {\n return this.plugins.reduce(\n async (acc, plugin) => plugin.getConfig(await acc, target),\n Promise.resolve({} as TransformOptions)\n )\n }\n\n public getAliases = async (onConflict: 'throw' | 'warn' | 'skip' = 'warn'): Promise<Alias[]> => {\n const aliases = await this.plugins.reduce(\n async (acc, plugin) => plugin.getAliases(await acc),\n Promise.resolve([] as Alias[])\n )\n\n // If we don't need to resolve conflicts, let's just return the merged aliases\n if (onConflict === 'skip') {\n return aliases\n }\n\n // Let's resolve the dependencies based on chosen conflict resolution rule\n const resolvedAliases: Record<string, Alias> = {}\n for (const current of aliases) {\n const { name, version } = current\n const previous = resolvedAliases[name]\n\n if (!previous) {\n resolvedAliases[name] = current\n continue\n }\n\n const { major: previousMajor } = parse(previous.version)\n const { major: currentMajor } = parse(version)\n if (previousMajor !== currentMajor) {\n switch (onConflict) {\n case 'throw':\n throw new Error(`π£ Dependency ${name} found duplicated. Need to resolve to ${previousMajor}.x or ${currentMajor}.x`)\n case 'warn':\n console.warn(`π£ Dependency ${name} found duplicated. Resolving to ${Math.max(previousMajor, currentMajor)}.x`)\n resolvedAliases[name] = previousMajor > currentMajor ? previous : current\n }\n }\n }\n\n return Object.values(resolvedAliases)\n }\n}\n\nexport interface BuildPluginOptions {\n mode: Mode\n project: Project\n}\n\nexport class BuildPlugin extends Plugin {\n public mode: Mode\n public project: Project\n\n constructor (options: BuildPluginOptions) {\n super({ target: lifecycle })\n this.mode = options.mode\n this.project = options.project\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public getConfig = async (previous: TransformOptions, target: BuildTarget): Promise<TransformOptions> => previous\n\n public getAliases = async (previous: Alias[]): Promise<Alias[]> => previous\n}\n\nexport const packageToAlias = async (name: string, resolve: (x: string) => string): Promise<Alias> => {\n const packageJSONPath = resolve(`${name}/package.json`)\n const { version } = await readJSON(packageJSONPath)\n return { name, version: `^${version}` }\n}\n\n```"
}
] |
code_micro_5cfd2e7b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/package/base.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { parse } from '../common/semver'\nimport {\n BundlePlugin,\n BundlePluginOptions\n} from '../lifecycles/bundle'\nimport { BuildPlugin, BuildPluginOptions } from '../lifecycles/build'\nimport {\n ServeFrameworkPlugin,\n ServePlugin,\n ServePluginOptions\n} from '../lifecycles/serve'\nimport { LifeCycle } from '../project'\nimport { Router, Serializable } from '../router'\nimport { Manifest } from './manifest'\nimport { TSConfig } from './tsconfig'\n\nexport interface Plugins {\n serve?: new (options: ServePluginOptions) => ServePlugin<any> | ServeFrameworkPlugin<any>,\n bundle?: new (options: BundlePluginOptions) => BundlePlugin,\n build?: new (options: BuildPluginOptions) => BuildPlugin\n}\n\nexport const PackageStructure = {\n lib: 'lib',\n pages: 'pages',\n router: 'router',\n index: 'index.ts',\n plugins: 'plugins',\n components: 'components',\n manifest: 'package.json',\n tsconfig: 'tsconfig.json'\n}\n\nexport type PackageRootEntries = keyof typeof PackageStructure\n\nexport interface PackageOptions {\n plugins: Plugins\n tsconfig: TSConfig\n manifest: Manifest\n dependencies: Package[]\n}\n\nexport abstract class Package {\n public tsconfig: TSConfig = null as any\n public manifest: Manifest = null as any\n public dependencies: Package[] = []\n public structure = PackageStructure\n\n public abstract resolve = async (projectRoot: string): Promise<void> => {\n throw new Error(`π£ not implemented: ${projectRoot}`)\n }\n\n public abstract hydrate = async (projectRoot: string): Promise<void> => {\n throw new Error(`π£ not implemented: ${projectRoot}`)\n }\n\n public abstract persist = async (projectRoot: string): Promise<void> => {\n throw new Error(`π£ not implemented: ${projectRoot}`)\n }\n\n public abstract getFiles = async (...targets: PackageRootEntries[]): Promise<string[]> => {\n throw new Error(`π£ not implemented: ${targets}`)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n public abstract getPlugin = async <T extends LifeCycle>(target: T): Promise<Plugins[T]> => {\n throw new Error('π£ not implemented')\n }\n\n public abstract getRouter = async <T extends Serializable>(): Promise<Router<T>> => {\n throw new Error('π£ not implemented')\n }\n\n public getGlobby = (...targets: PackageRootEntries[]) =>\n `@(${targets.map(t => PackageStructure[t]).join('|')})?(/**/*.ts?(x))`\n\n public toString = () => `${this.manifest.name}@${parse(this.manifest.version).major}.x`\n}\n\n```"
}
] |
code_micro_f516bc0a
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/package/manifest.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { pick } from '../common/pick'\nimport { isSemver } from '../common/semver'\nimport { MICRO_BUILD_DIR } from '../constants'\nimport { lifecycle } from '../lifecycles/build'\n\ntype MicroOptions = {\n plugins: string[]\n}\n\nexport const BaseManifest = {\n main: `./${MICRO_BUILD_DIR}/${lifecycle}/cjs/index.js`,\n module: `./${MICRO_BUILD_DIR}/${lifecycle}/es6/components/index.js`,\n browser: './components/index.ts',\n micro: {\n plugins: []\n } as MicroOptions,\n scripts: {\n build: 'yarn run micro build',\n watch: 'yarn run micro link',\n clean: `rm -r ${MICRO_BUILD_DIR}`,\n prepublish: 'yarn build'\n }\n}\n\nconst necessary = pick(BaseManifest, ['main', 'module', 'browser'])\nconst required = pick(BaseManifest, ['micro'])\n\ntype Base = typeof BaseManifest\n\nexport interface Manifest extends Base {\n name: string\n version: string\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n peerDependencies?: Record<string, string>\n}\n\n// TODO: improve this condition\nconst isMicro = (x: any): x is MicroOptions => Array.isArray(x?.plugins)\n\nexport const isManifest = (obj: any): obj is Manifest => {\n return typeof obj?.name === 'string' &&\n isSemver(obj.version) &&\n obj.main === BaseManifest.main &&\n obj.module === BaseManifest.module &&\n obj.browser === BaseManifest.browser &&\n isMicro(obj.micro)\n}\n\nexport const genManifest = (partial: Pick<Manifest, 'name' | 'version'>): Manifest => {\n const {\n name,\n vendor,\n version,\n description,\n title,\n license,\n micro,\n main,\n types,\n module,\n browser,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n type,\n scripts,\n dependencies,\n devDependencies,\n peerDependencies,\n ...rest\n } = {\n ...required,\n ...partial,\n ...necessary\n } as any\n\n return {\n name,\n vendor,\n version,\n description,\n title,\n license,\n micro,\n scripts: {\n ...BaseManifest.scripts,\n ...scripts\n },\n main,\n types,\n module,\n browser,\n dependencies,\n devDependencies,\n peerDependencies,\n ...rest\n }\n}\n\n```"
}
] |
code_micro_b11df5d6
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/package/tsconfig.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { MICRO_BUILD_DIR } from '../constants'\nimport { lifecycle } from '../lifecycles/build'\n\nexport const BaseTSConfig = {\n compilerOptions: {\n typeRoots: [\n 'lib/typings',\n 'router/typings',\n 'plugins/typings',\n 'components/typings'\n ],\n target: 'es2019',\n module: 'commonjs',\n moduleResolution: 'node',\n outDir: `${MICRO_BUILD_DIR}/${lifecycle}/cjs`,\n jsx: 'preserve',\n strict: true,\n esModuleInterop: true,\n forceConsistentCasingInFileNames: false,\n skipLibCheck: true,\n declaration: true\n },\n include: ['index.ts', 'lib', 'router', 'plugins', 'components'],\n exclude: [MICRO_BUILD_DIR, 'pages']\n}\n\nexport type TSConfig = typeof BaseTSConfig\n\n// TODO: Maybe implement a deep merge in here with priority to BaseTSConfig\nexport const genTSConfig = (partial: any): TSConfig => {\n return {\n ...partial,\n ...BaseTSConfig,\n compilerOptions: {\n ...partial?.compilerOptions,\n ...BaseTSConfig.compilerOptions\n }\n }\n}\n\n```"
}
] |
code_micro_8efa2f46
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/package/pnp/dfs.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { PosixFS, ZipOpenFS } from '@yarnpkg/fslib'\nimport * as yarnLibZip from '@yarnpkg/libzip'\nimport assert from 'assert'\nimport globby from 'globby'\nimport { join } from 'path'\nimport pnp, { getPackageInformation, PackageLocator } from 'pnpapi'\n\nimport { PnpPackage } from '.'\nimport { PackageStructure } from '../base'\nimport { isManifest, Manifest } from '../manifest'\n\nconst libzip = yarnLibZip.getLibzipSync()\n\n// This will transparently open zip archives\nconst zipOpenFs = new ZipOpenFS({ libzip })\n\n// This will convert all paths into a Posix variant, required for cross-platform compatibility\nconst crossFs = new PosixFS(zipOpenFs)\n\n// TODO: Does it work for packages inside .pnp.js file ?\nexport const requirePnp = <T>(target: string, pkg: string, issuer: string) => {\n const locator = (pnp as any).resolveRequest(pkg, issuer)\n const path = locator.replace('/index.js', `/${target}/index.js`)\n return require(path)\n}\n\nexport const globPnp = async (pkg: string, issuer: string, query: string) => {\n const locator: string = (pnp as any).resolveRequest(`${pkg}/${PackageStructure.manifest}`, issuer)\n const path = locator.replace(`/${PackageStructure.manifest}`, '')\n const matches = await globby(query, { cwd: path })\n return matches.map(p => join(path, p))\n}\n\nexport const readJsonPnp = async (\n pkg : PackageLocator,\n issuer: PackageLocator,\n target: keyof typeof PackageStructure\n) => {\n const path = pnp.getPackageInformation(pkg).packageLocation\n // const virtualPath = pnp.resolveToUnqualified(`${pkg.name}/${PackageStructure[target]}`, issuer.name)\n assert(path, `π£ Package path can not be null: Package: ${pkg.name}, Issuer: ${issuer.name}`)\n const fullPath = join(path, PackageStructure[target])\n return crossFs.readJsonPromise(fullPath)\n}\n\nexport const readManifest = async (info: PackageLocator, issuer: PackageLocator) => {\n const manifest = await readJsonPnp(info, issuer, 'manifest')\n return manifest as Pick<Manifest, 'name' | 'version' | 'dependencies' | 'peerDependencies' | 'devDependencies'>\n}\n\nconst getKey = <T>(locator: T) => JSON.stringify(locator)\n\n// DFS\nexport const createDepTree = async (\n pkgLocator: PackageLocator,\n manifest: Manifest,\n parentLocator: PackageLocator,\n seen: Map<string, PnpPackage>\n): Promise<PnpPackage | null> => {\n const node = getKey(pkgLocator)\n\n // only go forward if it is a Micro package\n if (seen.has(node) || !isManifest(manifest)) {\n return seen.get(node) || null\n }\n\n // Set Package as seen\n const pkg = new PnpPackage()\n seen.set(node, pkg)\n\n // Finish instantiating the package\n const info = getPackageInformation(pkgLocator)\n pkg.issuer = parentLocator.name!\n pkg.manifest = manifest\n pkg.tsconfig = await readJsonPnp(pkgLocator, parentLocator, 'tsconfig')\n\n for (const [name, referencish] of info.packageDependencies) {\n const locator = referencish && (pnp as any).getLocator(name, referencish) as PackageLocator | null\n const childInfo = locator && getPackageInformation(locator)\n if (!childInfo || !locator || getKey(locator) === node) {\n continue\n }\n const childManifest = await readJsonPnp(locator, pkgLocator, 'manifest')\n const child = await createDepTree(locator, childManifest, pkgLocator, seen)\n if (child) {\n pkg.dependencies.push(child)\n }\n }\n\n return pkg\n}\n\nexport type VisitFn = (node: PackageLocator, parent: PackageLocator | null) => Promise<void>\n\nconst walkRec = async (node: PackageLocator, parent: PackageLocator | null, visit: VisitFn, seen: Set<string>) => {\n const nodeStr = getKey(node)\n\n if (seen.has(nodeStr)) {\n return\n }\n\n const info = getPackageInformation(node)\n if (!info) {\n return\n }\n\n seen.add(nodeStr)\n await visit(node, parent)\n\n for (const [name, referencish] of info.packageDependencies) {\n const locator = referencish && (pnp as any).getLocator(name, referencish) as PackageLocator | null\n if (!locator) {\n continue\n }\n await walkRec(locator, node, visit, seen)\n }\n}\n\nexport const walk = (root: PackageLocator, visit: VisitFn) =>\n walkRec(root, null, visit, new Set())\n\n```"
}
] |
code_micro_1d038a5d
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/package/pnp/common.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport pnp from 'pnpapi'\n\nexport const getLocatorFromPackageInWorkspace = (name: string) => {\n const locators = (pnp as any).getDependencyTreeRoots() // TODO: improve typings\n return locators.find((l: any) => l.name === name)\n}\n\n```"
}
] |
code_micro_c84b77ed
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-core/lib/package/pnp/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport assert from 'assert'\nimport { readJSON } from 'fs-extra'\nimport { join } from 'path'\n\nimport { LifeCycle } from '../../project'\nimport { Router, Serializable } from '../../router'\nimport { Package, PackageRootEntries, Plugins } from '../base'\nimport { isManifest } from '../manifest'\nimport { getLocatorFromPackageInWorkspace } from './common'\nimport { globPnp, requirePnp, createDepTree } from './dfs'\n\nexport class PnpPackage extends Package {\n public issuer: string = ''\n\n // TODO: Make it resolve based on major and not only on the package name\n public resolve = async (projectRoot: string) => {\n const manifestPath = join(projectRoot, this.structure.manifest)\n const manifest = await readJSON(manifestPath)\n assert(isManifest(manifest), 'π£ Root manifest needs to be a valid Micro Project')\n const root = getLocatorFromPackageInWorkspace(manifest.name)\n assert(root, 'π£ Could not find this package in this workspace')\n const resolved = await createDepTree(root, manifest, root, new Map())\n assert(resolved, 'π£ Dependency tree traversal must return a package')\n this.dependencies = resolved.dependencies\n this.manifest = resolved.manifest\n this.issuer = this.manifest.name\n this.tsconfig = resolved.tsconfig\n }\n\n public hydrate = (projectRoot: string) => {\n throw new Error(`π£ not implemented: ${projectRoot}`)\n }\n\n public persist = (projectRoot: string) => {\n throw new Error(`π£ not implemented: ${projectRoot}`)\n }\n\n public getPlugin = async (target: LifeCycle) => {\n try {\n const { default: plugins } = requirePnp<{ default: Plugins }>(`plugins/${target}`, this.manifest.name, this.issuer)\n return plugins\n } catch (err) {\n return null\n }\n }\n\n public getRouter = async <T extends Serializable>() => {\n const { default: router } = requirePnp<{ default: Router<T> }>('router', this.manifest.name, this.issuer)\n return router\n }\n\n public getFiles = async (...targets: PackageRootEntries[]) =>\n globPnp(this.manifest.name, this.issuer, this.getGlobby(...targets))\n}\n\n```"
}
] |
code_micro_0f2579d1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-assets/plugins/bundle/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { BundlePlugin } from '@vtex/micro-core'\nimport { Block, Context, file, group, match } from 'webpack-blocks'\n\nexport default class Bundle extends BundlePlugin {\n public getConfig = async (config: Block<Context>): Promise<Block<Context>> => {\n const block: Block<Context>[] = [\n match(['*.png', '*.svg', '*.jpg', '*.gif', '*.ico'], [\n file({\n name: '[name].[ext]'\n })\n ])\n ]\n\n return group([\n config,\n ...block\n ])\n }\n}\n\n```"
}
] |
code_micro_056d8636
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/plugins/aliases.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// This plugin will enforce the following modules. This means\n// projects using this package as a plugin will use this package's\n// versions of the following packages\nexport const aliases = [\n 'history',\n 'react-router-dom',\n 'react-in-viewport'\n]\n\n```"
}
] |
code_micro_10ec1115
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/Link.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { useContext, useEffect, useRef } from 'react'\nimport { useInViewport } from 'react-in-viewport'\nimport {\n Link as ReactRouterLink,\n LinkProps,\n useLocation\n} from 'react-router-dom'\n\nimport { MicroRouterContext } from './Router/Router'\nimport { onMobileDevice } from './utils/env'\nimport { locationFromProps } from './utils/location'\n\ntype Props = LinkProps & {\n prefetch?: boolean\n}\n\nconst noop = () => {}\n\nexport const Link: React.SFC<Props> = ({ children, to, prefetch = false, ...rest }) => {\n const router = useContext(MicroRouterContext)\n const currentLocation = useLocation()\n\n let fetched = false\n const prefetchPage = (condition: boolean) => () => {\n if (!fetched && condition) {\n fetched = true\n router.prefetchPage(locationFromProps(to as any, currentLocation))\n }\n }\n const preloadPage = () => {\n if (!fetched) {\n fetched = true\n router.preloadPage(locationFromProps(to as any, currentLocation))\n }\n }\n\n const node = useRef(null)\n useInViewport(node, null, { disconnectOnLeave: true }, {\n onEnterViewport: prefetchPage(onMobileDevice),\n onLeaveViewport: noop\n })\n\n useEffect(prefetchPage(prefetch), [currentLocation, prefetch])\n\n return (\n <ReactRouterLink\n ref={node}\n to={to}\n // We preload the page in here becase it seems like the user is about to navigate\n onMouseEnter={preloadPage}\n {...rest}\n >\n { children }\n </ReactRouterLink>\n )\n}\n\n```"
}
] |
code_micro_2f58aa7f
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/NavLink.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React, { useContext, useEffect, useRef } from 'react'\nimport { NavLink as ReactRouterNavLink, NavLinkProps, useLocation } from 'react-router-dom'\nimport { useInViewport } from 'react-in-viewport'\n\nimport { locationFromProps } from './utils/location'\nimport { MicroRouterContext } from './Router/Router'\nimport { onMobileDevice } from './utils/env'\n\ntype Props = NavLinkProps & {\n prefetch?: boolean\n}\n\nconst noop = () => {}\n\nexport const NavLink: React.SFC<Props> = ({ children, to, prefetch = false, ...rest }) => {\n const router = useContext(MicroRouterContext)\n const currentLocation = useLocation()\n\n let fetched = false\n const prefetchPage = (condition: boolean) => () => {\n if (!fetched && condition) {\n fetched = true\n router.prefetchPage(locationFromProps(to as any, currentLocation))\n }\n }\n const preloadPage = () => {\n if (!fetched) {\n fetched = true\n router.preloadPage(locationFromProps(to as any, currentLocation))\n }\n }\n\n const node = useRef(null)\n useInViewport(node, null, { disconnectOnLeave: true }, {\n onEnterViewport: prefetchPage(onMobileDevice),\n onLeaveViewport: noop\n })\n\n useEffect(prefetchPage(prefetch), [currentLocation, prefetch])\n\n return (\n <ReactRouterNavLink\n ref={node}\n to={to}\n // We preload the page in here becase it seems like the user is about to navigate\n onMouseEnter={preloadPage}\n {...rest}\n >\n { children }\n </ReactRouterNavLink>\n )\n}\n\n```"
}
] |
code_micro_853651dc
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nexport * from './Router/Router'\nexport * from './Link'\nexport * from './NavLink'\nexport * from './Page'\n\n```"
}
] |
code_micro_14c2f1a8
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/Page.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\n/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { ResolvedPage, Serializable } from '@vtex/micro-core'\nimport React, { Fragment, useContext } from 'react'\nimport { useLocation } from 'react-router-dom'\n\nimport { MicroRouterContext } from './Router/Router'\n\nexport interface Page<T extends Serializable = any> {\n name: string\n path: string\n data: T\n}\n\nexport type RouterResolvedEntry<T> = {\n path: string\n data: T\n}\n\nexport const unpack = <T extends Serializable>(packed: Page<T>) => packed.data\n\nexport const pack = <T extends Serializable>(resolved: ResolvedPage<T>, path: string): ResolvedPage<Page<T>> => ({\n ...resolved,\n data: {\n data: resolved.data,\n name: resolved.name,\n path\n }\n})\n\nexport const isPage = (obj: any): obj is Page =>\n typeof obj.name === 'string' &&\n typeof obj.path === 'string'\n\nexport const FetchCurrentPage: React.SFC = ({ children }) => {\n const router = useContext(MicroRouterContext)\n const location = useLocation()\n\n React.useEffect(\n () => { router.preloadPage(location) },\n [location]\n )\n\n return (\n <Fragment>\n {children}\n </Fragment>\n )\n}\n\n```"
}
] |
code_micro_d393bb00
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/plugins/bundle/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport {\n BundlePlugin,\n pagesFrameworkName,\n pagesRuntimeName\n} from '@vtex/micro-core'\nimport { cacheGroup } from '@vtex/micro-react'\nimport { Block, Context, group, resolve } from 'webpack-blocks'\n\nimport { aliases } from '../aliases'\n\nexport default class Bundle extends BundlePlugin {\n public getConfig = async (config: Block<Context>): Promise<Block<Context>> => {\n return group([\n config,\n resolve({\n alias: aliases.reduce(\n (acc, packageName) => {\n acc[packageName] = require.resolve(packageName)\n return acc\n },\n {} as Record<string, string>\n )\n }),\n cacheGroup(pagesRuntimeName, /\\/react-in-viewport\\/|\\/react-router\\/|\\/react-router-dom\\//),\n cacheGroup(pagesFrameworkName, /\\/micro-react-router\\//)\n ])\n }\n}\n\n```"
}
] |
code_micro_7d7dafef
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/plugins/serve/index.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { ServePlugin } from '@vtex/micro-core'\nimport { createElement } from 'react'\nimport { StaticRouter } from 'react-router-dom'\n\nexport default class Serve extends ServePlugin<JSX.Element> {\n public render = (children: JSX.Element | null): JSX.Element => {\n const location = this.options.path\n return createElement(StaticRouter, { location, children } as any)\n }\n}\n\n```"
}
] |
code_micro_dbaac59c
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/utils/location.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport { createLocation, Location, LocationDescriptorObject } from 'history'\nimport ReactRouter from 'react-router-dom'\n\n// Code Copied from https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/modules/utils/locationUtils.js\nconst resolveToLocation = (to: ReactRouter.LinkProps['to'], currentLocation: Location) =>\n typeof to === 'function' ? to(currentLocation) : to\n\nconst normalizeToLocation = (to: string | LocationDescriptorObject, currentLocation: Location): LocationDescriptorObject => {\n return typeof to === 'string'\n ? createLocation(to, null, undefined, currentLocation)\n : to\n}\n\nexport const locationFromProps = (to: ReactRouter.LinkProps['to'], currentLocation: Location): LocationDescriptorObject => normalizeToLocation(\n resolveToLocation(to, currentLocation),\n currentLocation\n)\n\n```"
}
] |
code_micro_3161fb00
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/utils/env.ts from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```typescript\nimport { canUseDOM } from '@vtex/micro-react'\n\n// Script grabbed from http://detectmobilebrowser.com/mobile\n\nconst isMobile = () => {\n const descriptor = navigator.userAgent || navigator.vendor || (window as any).opera\n const firstRandomTest = /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(descriptor)\n const secondRandomTest = /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(descriptor.substr(0, 4))\n return firstRandomTest || secondRandomTest\n}\n\nexport const onMobileDevice = canUseDOM && isMobile()\n\n```"
}
] |
code_micro_362e4fb1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/Router/Router.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport loadable from '@loadable/component'\nimport { canUseDOM } from '@vtex/micro-react'\nimport { LocationDescriptorObject } from 'history'\nimport React from 'react'\nimport { BrowserRouter } from 'react-router-dom'\n\nimport { Page } from '../Page'\nimport { RouterDOM } from './DynamicRouterDOM'\nimport { RouterSSR } from './RouterSSR'\n\nexport interface PageProps {\n data: any\n}\n\nexport interface AsyncPageProps extends PageProps {\n name: string\n}\n\nexport interface RouterProps {\n data: Page\n error: any\n}\n\ntype AsyncImport = (x: { name: string}) => Promise<any>\n\nexport interface RouterStateModifier {\n // Prefetching should have lower priority than a preload. Also, you should be\n // carefull about preloading too mutch\n prefetchPage: (location: LocationDescriptorObject) => Promise<void>\n // Preload means the user needs this page right now. Use it only when you are\n // almost sure the user will navigate to this page\n preloadPage: (location: LocationDescriptorObject) => Promise<void>\n}\n\nexport const MicroRouterContext = React.createContext<RouterStateModifier>({} as any)\nMicroRouterContext.displayName = 'MicroRouterContext'\n\nexport const withRouter = (\n InitialPage: React.ElementType<PageProps>,\n AsyncImport: AsyncImport\n): React.SFC<RouterProps> => {\n const AsyncPage = loadable<AsyncPageProps>(AsyncImport, {\n cacheKey: ({ name }) => name,\n ssr: false\n })\n\n return function MicroReactRouter ({ data, error }) {\n if (!canUseDOM) {\n return <RouterSSR data={data} error={error} InitialPage={InitialPage} />\n }\n\n // We could implement an static router in here as well\n return (\n <BrowserRouter>\n <RouterDOM\n data={data}\n error={error}\n InitialPage={InitialPage}\n AsyncPage={AsyncPage}\n />\n </BrowserRouter>\n )\n }\n}\n\n```"
}
] |
code_micro_16d148e4
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/Router/RouterSSR.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport React from 'react'\n\nimport { unpack } from '../Page'\nimport {\n MicroRouterContext,\n PageProps,\n RouterProps,\n RouterStateModifier\n} from './Router'\n\ninterface RouterSSRProps extends RouterProps {\n InitialPage: React.ElementType<PageProps>\n}\n\nexport class RouterSSR extends React.Component<RouterSSRProps, RouterStateModifier> {\n constructor (props: RouterSSRProps) {\n super(props)\n this.state = {\n prefetchPage: () => { throw new Error('π£ Cannot prefetch page in SSR') },\n preloadPage: () => { throw new Error('π£ Cannot fetch page in SSR') }\n }\n }\n\n public render = () => {\n const { InitialPage } = this.props\n return (\n <MicroRouterContext.Provider value={this.state}>\n <InitialPage data={unpack(this.props.data)} />\n </MicroRouterContext.Provider>\n )\n }\n}\n\n```"
}
] |
code_micro_eb15b532
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of micro/packages/micro-react-router/components/Router/DynamicRouterDOM.tsx from the micro VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```tsx\nimport { LoadableComponent } from '@loadable/component'\nimport { RuntimeData, Runtime, join, inflight } from '@vtex/micro-react'\nimport { LocationDescriptorObject } from 'history'\nimport React from 'react'\nimport { matchPath, Route, useLocation } from 'react-router-dom'\n\nimport { FetchCurrentPage, isPage, Page } from '../Page'\nimport {\n AsyncPageProps,\n MicroRouterContext,\n PageProps,\n RouterProps,\n RouterStateModifier\n} from './Router'\n\ninterface RouterState extends RouterStateModifier {\n assets: Set<string>\n // null if page was loaded with error, Page sucessfully, undefined if not prefetched\n pages: Map<string, Page>\n}\n\ninterface RouterDOMProps extends RouterProps {\n runtime: RuntimeData // root paths to prefetch\n location: LocationDescriptorObject // window location\n InitialPage: React.ElementType<PageProps> // Page that was SSR\n AsyncPage: LoadableComponent<AsyncPageProps> // Async Page loader\n}\n\nclass PrivateRouterDOM extends React.Component<RouterDOMProps, RouterState> {\n constructor (props: RouterDOMProps) {\n super(props)\n this.state = {\n prefetchPage: this.prefetchPage,\n preloadPage: this.preloadPage,\n pages: new Map(),\n assets: new Set()\n }\n }\n\n public prefetchPage = async (location: LocationDescriptorObject) => {\n const isInitialPage = location.pathname === this.props.data.path\n if (location.pathname && !isInitialPage) {\n if (!this.state.pages.has(location.pathname)) {\n return this.loadPage(location)\n }\n }\n }\n\n public preloadPage = async (location: LocationDescriptorObject) => {\n const isInitialPage = location.pathname === this.props.data.path\n if (location.pathname && !isInitialPage) {\n if (!this.state.pages.has(location.pathname)) {\n return this.loadPage(location)\n }\n }\n }\n\n public loadAsset = async (page: Page) => {\n const alreadyLoaded = this.state.assets.has(page.name)\n const isInitialPage = page.name === this.props.data.name\n if (alreadyLoaded || isInitialPage) {\n return\n }\n await inflight(page.name, async () => new Promise(resolve => {\n this.setState(state => {\n this.props.AsyncPage.preload(page)\n state.assets.add(page.name)\n resolve()\n return state\n })\n }))\n }\n\n protected async loadPage (location: LocationDescriptorObject): Promise<any> {\n const path = this.locationToPath(location) || ''\n return inflight(path, async () => {\n const page = await fetch(path).then(r => r.json())\n if (isPage(page)) {\n this.updatePages(page.path, page)\n this.loadAsset(page)\n } else {\n throw new Error(`π£ Fetched location was not a valid page: ${location.pathname}`)\n }\n })\n }\n\n protected updatePages = (path: string, page: Page) => this.setState(state => {\n state.pages.set(path, page)\n return state\n })\n\n protected locationToPath = (location: LocationDescriptorObject) => {\n if (typeof location.pathname !== 'string') {\n throw new Error('π£ You need a pathname for fecthing a page')\n }\n return join(this.props.runtime.publicPaths.data, location.pathname)\n }\n\n public render = () => {\n const { data, InitialPage, AsyncPage, location } = this.props\n const { pages } = this.state\n\n const isInitialPage = matchPath(location.pathname || '', { ...data, exact: true, strict: false })\n\n if (isInitialPage) {\n return (\n <MicroRouterContext.Provider value={this.state}>\n <Route path={location.pathname}>\n <InitialPage data={data.data} />\n </Route>\n </MicroRouterContext.Provider>\n )\n }\n\n // Iterate over the pages map and find a match\n // I think we could improve this algorithm, but YoLo\n let matched: Page<any> | null = null\n for (const [, page] of pages) {\n const m = matchPath(location.pathname || '', { ...page, exact: true, strict: false })\n if (m) {\n matched = page\n break\n }\n }\n\n if (!matched) {\n return (\n <MicroRouterContext.Provider value={this.state}>\n <Route path={location.pathname}>\n <FetchCurrentPage />\n </Route>\n </MicroRouterContext.Provider>\n )\n }\n\n return (\n <MicroRouterContext.Provider value={this.state}>\n <Route path={location.pathname}>\n <AsyncPage data={matched.data} name={matched.name} />\n </Route>\n </MicroRouterContext.Provider>\n )\n }\n}\n\ntype InjectionProps = Omit<RouterDOMProps, 'runtime' | 'location'>\n\n// PrivateRouterDOM required location and runtime. Since this is the\n// only I know how to inject runtime and location to it, I've created\n// this simple component\nexport const RouterDOM: React.SFC<InjectionProps> = ({\n data,\n error,\n InitialPage,\n AsyncPage\n}) => {\n const location = useLocation()\n const runtime = React.useContext(Runtime)\n\n return (\n <PrivateRouterDOM\n runtime={runtime}\n location={location}\n data={data}\n error={error}\n InitialPage={InitialPage}\n AsyncPage={AsyncPage}\n />\n )\n}\n\n```"
}
] |
code_affirm-qa-theme_4c540471
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/sitemap/sitemap.json from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"urlset\": {\n \"url\": [\n {\n \"loc\": \"https://storetheme.vtex.com/about-us\"\n }\n ]\n }\n}\n```"
}
] |
code_affirm-qa-theme_b14ec189
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/docs/README.md from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```markdown\n# Store theme\n<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->\n[](#contributors-)\n<!-- ALL-CONTRIBUTORS-BADGE:END -->\nOur boilerplate theme to create stores in the VTEX IO platform.\n\n## Preview\n\n\n## Tutorial\nTo understand how things work check our tutorial [Build a store using VTEX IO](https://vtex.io/docs/getting-started/build-stores-with-store-framework/1/)\n\n## Dependencies\nAll store components that you see on this document are open source too. Production ready, you can found those apps in this GitHub organization.\n\nStore framework is the baseline to create any store using _VTEX IO Web Framework_.\n- [Store](https://github.com/vtex-apps/store/blob/master/README.md)\n\nStore GraphQL is a middleware to access all VTEX APIs.\n- [Store GraphQL](https://github.com/vtex-apps/store-graphql/blob/master/docs/README.md)\n\n### Store Component Apps\n- [Header](https://github.com/vtex-apps/store-header/blob/master/docs/README.md)\n- [Footer](https://github.com/vtex-apps/store-footer/blob/master/docs/README.md)\n- [Slider Layout](https://github.com/vtex-apps/slider-layout/blob/master/docs/README.md)\n- [Shelf](https://github.com/vtex-apps/shelf/blob/master/docs/README.md)\n- [Telemarketing](https://github.com/vtex-apps/telemarketing/blob/master/docs/README.md)\n- [Menu](https://github.com/vtex-apps/menu/blob/master/docs/README.md)\n- [Login](https://github.com/vtex-apps/login/blob/master/docs/README.md)\n- [Minicart](https://github.com/vtex-apps/minicart/blob/master/docs/README.md)\n- [Category Menu](https://github.com/vtex-apps/category-menu/blob/master/docs/README.md)\n- [Product Summary](https://github.com/vtex-apps/product-summary/blob/master/docs/README.md)\n- [Breadcrumb](https://github.com/vtex-apps/breadcrumb/blob/master/docs/README.md)\n- [Search Result](https://github.com/vtex-apps/search-result/blob/master/docs/README.md)\n- [Product Details](https://github.com/vtex-apps/product-details/blob/master/docs/README.md)\n- [Store Components](https://github.com/vtex-apps/store-components/blob/master/docs/README.md)\n- [Order Placed](https://github.com/vtex-apps/order-placed/blob/master/docs/README.md) \n\n### Store Pixel Apps\n\n - [Facebook Pixel](https://github.com/vtex-apps/facebook-pixel/blob/master/docs/README.md)\n - [Google Tag Manager](https://github.com/vtex-apps/google-tag-manager/blob/master/docs/README.md)\n\n## Contributing\n\nCheck it out [how to contribute](https://github.com/vtex-apps/awesome-io#contributing) with this project.\n\n## Contributors β¨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n <tr>\n <td align=\"center\"><a href=\"http://www.hugoccosta.com\"><img src=\"https://avatars2.githubusercontent.com/u/20212776?v=4\" width=\"100px;\" alt=\"\"/><br /><sub><b>Hugo Costa</b></sub></a><br /><a href=\"https://github.com/vtex-apps/store-theme/commits?author=hugocostadev\" title=\"Documentation\">π</a></td>\n </tr>\n</table>\n\n<!-- markdownlint-enable -->\n<!-- prettier-ignore-end -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n```"
}
] |
code_affirm-qa-theme_69711c7b
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/docs/contact-schema.json from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"title\": \"Contact\",\n \"type\": \"object\",\n \"properties\": {\n \"title\": {\n \"type\": \"string\",\n \"title\": \"Title\"\n },\n \"name\": {\n \"type\": \"string\",\n \"title\": \"Name\"\n },\n \"email\": {\n \"type\": \"string\",\n \"format\": \"email\",\n \"title\": \"Email address\"\n },\n \"message\": {\n \"type\": \"string\",\n \"title\": \"Message\"\n }\n },\n \"required\": [\"email\", \"message\"],\n \"v-security\": {\n \"publicJsonSchema\": true\n }\n}\n\n```"
}
] |
code_affirm-qa-theme_1aa28237
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/store/blocks.jsonc from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n/* Blocks can be defined both on the store/blocks.json file, and in any number of json\n * files inside the store/blocks directory, with any arbitrary directory structure.\n *\n * Additionally, all blocks files can support comments, such as this one, if given the\n * .jsonc file extension.\n *\n * The store/blocks.json file is intended for backwards compatibility, for miscellaneous\n * blocks, or if the app is simple enough that it doesn't warrant splitting the file.\n */\n{\n \"store.orderplaced\": {\n \"blocks\": [\"order-placed\"]\n },\n\n \"store.account\": {\n \"blocks\": [\"my-account\"],\n \"parent\": {\n \"challenge\": \"challenge.profile\"\n }\n },\n\n \"store.login\": {\n \"blocks\": [\"login-content#default\"]\n },\n\n \"login-content#default\": {\n \"props\": {\n \"isInitialScreenOptionOnly\": false,\n \"defaultOption\": 1,\n \"showPasswordVerificationIntoTooltip\": true\n }\n },\n\n \"store.product-review-form\": {\n \"blocks\": [\"product-review-form\"]\n },\n\n \"store.not-found#product\": {\n \"blocks\": [\"rich-text#not-found\"]\n },\n\n \"store.not-found#search\": {\n \"blocks\": [\"rich-text#not-found\"]\n },\n\n \"rich-text#not-found\": {\n \"props\": {\n \"textAlignment\": \"CENTER\",\n \"textPosition\": \"CENTER\",\n \"text\": \"**PAGE NOT FOUND**\",\n \"font\": \"t-heading-1\"\n }\n }\n}\n\n```"
}
] |
code_affirm-qa-theme_f6f006ce
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/store/routes.json from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```json\n{\n \"store.custom#about-us\": {\n \"path\": \"/about-us\"\n },\n \"store.custom#faq\": {\n \"path\": \"/faq\"\n },\n \"store.custom#contact-us\": {\n \"path\": \"/contact-us\"\n }\n}\n\n```"
}
] |
code_affirm-qa-theme_4395a314
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.store-video.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.videoContainer {\n width: 100%;\n height: 300px;\n margin-top: 2%;\n}\n\n@media only screen and (min-width: 640px) {\n .videoContainer {\n height: 700px;\n }\n}\n\n```"
}
] |
code_affirm-qa-theme_f3833975
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.product-price.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.listPrice {\n color: #727273;\n margin-bottom: .25rem;\n font-size: 1rem;\n}\n\n.sellingPrice {\n color: #3f3f40;\n font-size: 1.25rem;\n}\n\n.sellingPriceValue {\n font-size: 2.25rem;\n font-weight: 700;\n}\n\n.installments {\n color: #727273;\n margin-bottom: 1rem;\n}\n\n.savings {\n font-weight: 500;\n color: #79B03A;\n}\n\n.sellingPriceValue--summary {\n font-size: 1.25rem;\n font-weight: 600;\n color: #2E2E2E;\n}\n\n.savings--summary {\n background: #8BC34A;\n border-radius: 1000px;\n align-items: center;\n display: flex;\n\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n font-size: 0.875rem;\n font-weight: 600;\n vertical-align: baseline;\n color: #FFFFFF;\n}\n\n.savings-discount--summary {\n font-size: 0.875rem;\n font-weight: 600;\n vertical-align: baseline;\n color: #FFFFFF;\n padding-left: 0.5rem;\n padding-right: 0.5rem;\n}\n\n.listPrice--summary {\n margin-bottom: 0.25rem;\n font-size: .875rem;\n}\n\n.installments--summary {\n margin-bottom: 2rem;\n font-size: 0.875rem;\n}\n\n.savings--summaryPercentage {\n background: #0f3e99;\n border-radius: 1000px;\n align-items: center;\n display: flex;\n}\n\n.savingsPercentage--summaryPercentage {\n font-size: 0.875rem;\n font-weight: 600;\n vertical-align: baseline;\n color: #FFFFFF;\n padding: 0.25rem 0.5rem 0.25rem 0.5rem;\n}\n\n```"
}
] |
code_affirm-qa-theme_0dab93f5
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.rich-text.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.container--deals {\n color: #ffffff;\n text-align: center;\n justify-content: center;\n}\n\n.container--shelfTitle {\n color: #727273;\n justify-content: center;\n text-align: center;\n}\n\n.headingLevel2--shelfTitle {\n font-weight: 200;\n}\n\n.container--deals .paragraph {\n margin: 0;\n}\n\n.container--link {\n justify-content: center;\n}\n\n.container--question {\n justify-content: center;\n}\n\n.container--question .paragraph {\n text-align: center;\n max-width: 540px;\n margin: 0 16px;\n padding-top: 120px;\n color: #03034E;\n}\n\n.container--question .strong {\n font-size: 32px;\n line-height: 2rem;\n font-weight: 700;\n}\n\n.container--link .paragraph {\n text-align: center;\n max-width: 540px;\n padding-top: 36px;\n padding-bottom: 84px;\n color: #03034E;\n}\n\n.container--link .strong {\n font-size: 16px;\n font-weight: 700;\n text-transform: uppercase;\n}\n\n.container--link .link {\n text-decoration: none;\n font-size: 36px;\n font-weight: 300;\n color: #03034E;\n}\n\n.container--title {\n color: #03034E;\n font-size: 28px;\n font-weight: 700;\n}\n\n@media only screen and (min-width: 640px) {\n .container--question .strong {\n font-size: 40px;\n line-height: 3rem;\n }\n\n .container--about {\n max-width: 85%;\n }\n\n .container--title {\n color: #03034E;\n font-size: 40px;\n font-weight: 700;\n max-width: 60%;\n }\n\n .container--title .paragraph {\n line-height: 1.3em;\n }\n}\n\n```"
}
] |
code_affirm-qa-theme_23232b21
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.product-summary.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.skuSelectorContainer--quickview .skuSelectorItemImage .frameAround, .skuSelectorContainer--quickview .skuSelectorItemImage .skuSelectorInternalBox {\n border-radius: 50%;\n}\n\n.container :global(.vtex-modal-layout-0-x-triggerContainer) {\n opacity: 0;\n transition: opacity 200ms ease-in-out;\n}\n\n.container:hover :global(.vtex-modal-layout-0-x-triggerContainer) {\n opacity: 1;\n}\n\n@media screen and (max-width: 40em) {\n .container :global(.vtex-modal-layout-0-x-triggerContainer) {\n display: none;\n }\n}\n\n.nameContainer {\n justify-content: start;\n padding-top: 1rem;\n padding-bottom: 1rem;\n}\n\n.brandName {\n font-weight: 600;\n font-size: 18px;\n color: #2E2E2E;\n}\n\n.container {\n text-align: start;\n}\n\n.imageContainer {\n text-align: center;\n}\n\n.image {\n border-radius: 0.25rem;\n}\n\n```"
}
] |
code_affirm-qa-theme_d445e8b5
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.modal-layout.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n@media screen and (min-width: 40em) {\n .paper--quickview {\n height: 260px;\n width: 580px;\n }\n\n .actionsContainer--quickview {\n padding: 0 2rem 2rem 2rem;\n }\n}\n\n@media screen and (min-width: 50em) {\n .paper--quickview {\n height: 450px;\n width: 900px;\n }\n}\n\n\n@media screen and (min-width: 75em) {\n .paper--quickview {\n width: calc(100% - 4rem);\n height: auto;\n }\n}\n\n@media screen and (min-width: 82em) {\n .actionsContainer--quickview {\n padding: 0 2.5rem 2.5rem 2.5rem;\n }\n}\n\n.paper--quickview {\n min-width: 320px;\n max-width: 96rem;\n}\n\n.headerContainer--quickview {\n border: none;\n position: absolute;\n right: 0;\n}\n\n.actionsContainer--quickview {\n height: 100%;\n width: 100%;\n transition: box-shadow 150ms ease-in-out, border-top 150ms ease-in-out;\n border-top-style: solid;\n border-top-width: 1px;\n border-top-color: transparent;\n box-shadow: -4px 0px 27px -12px transparent;\n}\n\n.actionsContentWrapper {\n border-top-width: 1px;\n border-top-style: solid;\n border-top-color: #aaa;\n padding-top: 1.5rem;\n}\n\n.contentContainer--quickviewContent {\n padding: 2.5rem 0 2.5rem 2rem;\n overflow-x: hidden;\n}\n\n.triggerContainer--quickview {\n padding: .75rem;\n}\n\n.triggerContainer {\n outline: none;\n}\n\n.actionsContainer--quickview:not(.actionsContainerEndOfContent--quickview) {\n border-top-color: rgb(238, 238, 238);\n box-shadow: -4px 0px 27px -12px rgba(0,0,0,0.64);\n}\n\n.actionsContainer--quickview:not(.actionsContainerEndOfContent--quickview) .actionsContentWrapper {\n border-top-color: transparent;\n}\n\n.closeButton {\n padding-right: 1rem;\n}\n\n.paper--product-gifts {\n padding: 1.5rem;\n}\n\n```"
}
] |
code_affirm-qa-theme_390525a3
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.store-header.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n/* add transitions */\n:global(.vtex-sticky-layout-0-x-container)\n :global(.vtex-store-components-3-x-logoLink),\n:global(.vtex-sticky-layout-0-x-container)\n :global(.vtex-minicart-2-x-openIconContainer),\n:global(.vtex-sticky-layout-0-x-container)\n :global(.vtex-store-components-3-x-searchBarContainer) {\n transition: all 0.3s ease;\n display: block;\n}\n\n/* desktop/mobile main header padding and background transitions */\n:global(.vtex-flex-layout-0-x-flexRowContent--main-header),\n:global(.vtex-flex-layout-0-x-flexRowContent--main-header-mobile) {\n transition: background 0.3s ease;\n will-change: padding, background;\n}\n\n/* main header desktop has a bigger padding when not stuck */\n:global(.vtex-flex-layout-0-x-flexRowContent--main-header) {\n padding-top: 0.5rem;\n padding-bottom: 0.5rem;\n}\n\n/* add a box-shadow to desktop/mobile header when stuck */\n:global(.vtex-sticky-layout-0-x-wrapper--stuck)\n :global(.vtex-flex-layout-0-x-flexRowContent--main-header),\n:global(.vtex-sticky-layout-0-x-wrapper--stuck)\n :global(.vtex-flex-layout-0-x-flexRowContent--main-header-mobile) {\n box-shadow: 0 4px 5px rgba(0, 0, 0, 0.1);\n}\n\n/*\n * remove the extra padding when stuck from the desktop header\n * we add a transition only when \"stuck\" for the \"unstick\" step seem faster\n */\n:global(.vtex-sticky-layout-0-x-wrapper--stuck)\n :global(.vtex-flex-layout-0-x-flexRowContent--main-header) {\n transition: padding 0.3s ease, background 0.3s ease;\n padding-top: 0;\n padding-bottom: 0;\n}\n\n/* if supported add some translucency to the desktop/mobile header background */\n@supports (backdrop-filter: blur(5px)) {\n :global(.vtex-sticky-layout-0-x-wrapper--stuck)\n :global(.vtex-flex-layout-0-x-flexRowContent--main-header),\n :global(.vtex-sticky-layout-0-x-wrapper--stuck)\n :global(.vtex-flex-layout-0-x-flexRowContent--main-header-mobile) {\n backdrop-filter: blur(8px);\n }\n\n /* header background when stuck and not hovered */\n :global(.vtex-sticky-layout-0-x-wrapper--stuck):not(:hover)\n :global(.vtex-flex-layout-0-x-flexRowContent--main-header),\n :global(.vtex-sticky-layout-0-x-wrapper--stuck):not(:hover)\n :global(.vtex-flex-layout-0-x-flexRowContent--main-header-mobile) {\n background: rgba(240, 240, 240, 0.8);\n }\n}\n\n/* stick wrapper with the same color as the desktop/mobile header */\n:global(.vtex-sticky-layout-0-x-wrapper--sticky-header) {\n background-color: #f0f0f0;\n}\n\n/* resize the logo for neat effect */\n:global(.vtex-sticky-layout-0-x-wrapper--stuck)\n :global(.vtex-store-components-3-x-logoLink) {\n transform: scale(0.85);\n}\n\n@media (prefers-reduced-motion: reduce) {\n :global(.vtex-sticky-layout-0-x-container)\n :global(.vtex-store-components-3-x-logoLink),\n :global(.vtex-sticky-layout-0-x-container)\n :global(.vtex-minicart-2-x-openIconContainer),\n :global(.vtex-sticky-layout-0-x-container)\n :global(.vtex-store-components-3-x-searchBarContainer),\n :global(.vtex-sticky-layout-0-x-wrapper--stuck)\n :global(.vtex-flex-layout-0-x-flexRowContent--main-header) {\n transition: none;\n }\n}\n\n```"
}
] |
code_affirm-qa-theme_a70df525
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.store-components.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.notificationBarContainer {\n background-color: #e6f1e6;\n color: #03034e;\n font-weight: 700;\n font-size: 12px;\n text-decoration: underline;\n}\n\n.infoCardContainer--info-card-home {\n max-width: 1520px;\n margin: 0 auto;\n background-color: #e6f1e6;\n padding: 0px;\n}\n\n.newsletter {\n background-color: #03054e;\n max-width: 1528px;\n margin: 0 auto;\n}\n\n.newsletter .container {\n padding: 60px 10px;\n}\n\n.label {\n color: #fff;\n font-size: 26px;\n}\n\n.inputGroup {\n padding-bottom: 4px;\n display: flex;\n color: #fff;\n}\n\n.inputGroup :global(.vtex-styleguide-9-x-hideDecorators) {\n background-color: transparent;\n color: #fff;\n border: none;\n}\n\n.inputGroup :global(.vtex-styleguide-9-x-hideDecorators)::placeholder {\n color: #fff;\n font-size: 16px;\n}\n\n.inputGroup :global(.vtex-button) {\n background-color: transparent;\n color: #fff;\n border: none;\n margin-right: -24px;\n}\n\n.buttonContainer {\n padding-top: 0px;\n}\n\n.imageElement--storePrint {\n max-height: 300px;\n margin-bottom: 20px;\n}\n\n.skuSelectorContainer {\n margin: 1rem 0;\n}\n\n@media only screen and (min-width: 640px) {\n .newsletter .container {\n padding: 140px;\n }\n .label {\n font-size: 40px;\n }\n .infoCardContainer--info-card-home .infoCardTextContainer {\n width: 30%;\n }\n .infoCardContainer--info-card-home .infoCardImageContainer {\n width: 70%;\n }\n .imageElement--storePrint {\n margin-bottom: 0px;\n max-height: 600px;\n }\n}\n\n.productImagesContainer--quickview .carouselContainer {\n justify-content: flex-start;\n}\n\n.productImagesContainer--quickview .productImageTag {\n object-fit: cover !important;\n}\n\n.productImagesContainer--quickview .carouselGaleryThumbs {\n display: none;\n}\n\n.productImagesContainer--quickview .carouselGaleryCursor {\n margin: 0;\n padding: 0;\n width: 100%;\n}\n\n.productNameContainer {\n color: #3f3f40;\n font-weight: bold;\n font-size: 30px;\n}\n\n.image {\n image-rendering: -webkit-optimize-contrast;\n}\n\n```"
}
] |
code_affirm-qa-theme_2373064a
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.store-footer.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.row--menu-row {\n padding-right: 24px;\n}\n\n.row--menu-row .rowContainer {\n align-items: flex-start;\n}\n\n.row--payment-methods {\n padding-top: 16px;\n}\n\n```"
}
] |
code_affirm-qa-theme_38f33bc1
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.product-identifier.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.product-identifier--productReference {\n margin-bottom: 1rem;\n}\n\n```"
}
] |
code_affirm-qa-theme_266906d0
|
[
{
"role": "system",
"content": "You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms."
},
{
"role": "user",
"content": "Show me the implementation of affirm-qa-theme/styles/css/vtex.reviews-and-ratings.css from the affirm-qa-theme VTEX app."
},
{
"role": "assistant",
"content": "Here's the implementation:\n\n```css\n.container {\n max-width: 96rem;\n padding-left: .5rem;\n padding-right: .5rem;\n}\n\n.inlineContainer {\n margin-left: 0rem;\n}\n\n.star--filled {\n color: #FFB100;\n}\n\n.star--empty {\n color: #FFB100;\n}\n\n```"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.