Skip to content

Commit

Permalink
drop emition for theme-store
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes committed Aug 11, 2021
1 parent 28b872d commit 61f3523
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,26 @@
import 'requestidlecallback-polyfill'

import React, { StrictMode } from 'react'
import { UIProvider } from '@vtex/store-sdk'
import ReactDOM from 'react-dom'
import type { WrapRootElementBrowserArgs } from 'gatsby'
import type { ReactChild } from 'react'
import { UIProvider } from '@vtex/store-sdk'

import ErrorBoundary from './components/Error/ErrorBoundary'
import { Provider as OrderFormProvider } from './sdk/orderForm/Provider'
import { Provider as VTEXRCProvider } from './sdk/pixel/vtexrc/Provider'
import ErrorBoundary from './src/components/Error/ErrorBoundary'
import { Provider as OrderFormProvider } from './src/sdk/orderForm/Provider'
import { Provider as VTEXRCProvider } from './src/sdk/pixel/vtexrc/Provider'
import {
onRouteUpdate as progressOnRouteUpdate,
Progress,
} from './sdk/progress'
import { Provider as RegionProvider } from './sdk/region/Provider'
import { Provider as ToastProvider } from './sdk/toast/Provider'
} from './src/sdk/progress'
import { Provider as RegionProvider } from './src/sdk/region/Provider'
import { Provider as ToastProvider } from './src/sdk/toast/Provider'

export const onClientEntry = async () => {
if (typeof IntersectionObserver === 'undefined') {
await import('intersection-observer')
}
}

export const replaceHydrateFunction = () => (
element: ReactChild,
container: Element
) => {
export const replaceHydrateFunction = () => (element, container) => {
let hydrate = true

// This part will be removed by webpack on production builds since this only
Expand All @@ -42,13 +37,12 @@ export const replaceHydrateFunction = () => (
}

// There are versions of React currently exporting createRoot and others exporting unstable_createRoot
const createRoot =
ReactDOM.createRoot || (ReactDOM as any).unstable_createRoot
const createRoot = ReactDOM.createRoot || ReactDOM.unstable_createRoot

createRoot(container, { hydrate }).render(element)
}

export const wrapRootElement = ({ element }: WrapRootElementBrowserArgs) => {
export const wrapRootElement = ({ element }) => {
const root = (
<ErrorBoundary>
<VTEXRCProvider>
Expand All @@ -74,10 +68,7 @@ export const onInitialClientRender = () => {
globalThis.__REACT_HYDRATED__ = true
}

export const wrapPageElement = ({
element,
props: { location },
}: WrapRootElementBrowserArgs | any) => (
export const wrapPageElement = ({ element, props: { location } }) => (
<Progress location={location}>{element}</Progress>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { Options } from './gatsby-node'

const root = process.cwd()

module.exports = ({ locales, defaultLocale }: Options) => ({
module.exports = ({ locales, defaultLocale }) => ({
plugins: [
{
resolve: require.resolve('gatsby-plugin-bundle-stats'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
import { resolve, relative } from 'path'
const { resolve, relative } = require('path')

import type {
CreateWebpackConfigArgs,
PluginOptionsSchemaArgs,
ParentSpanPluginArgs,
} from 'gatsby'

export const onPostBootstrap = (
_: ParentSpanPluginArgs,
{ storeId }: Options
) => {
exports.onPostBootstrap = (_, { storeId }) => {
process.env.GATSBY_STORE_ID = storeId
}

export interface Options {
storeId: string
locales: string[]
defaultLocale: string
profiling?: boolean
}

export const pluginOptionsSchema = ({ Joi }: PluginOptionsSchemaArgs) =>
exports.pluginOptionsSchema = ({ Joi }) =>
Joi.object({
storeId: Joi.string().required(),
locales: Joi.array().items(Joi.string()).required(),
defaultLocale: Joi.string().required(),
profiling: Joi.boolean(),
})

const resolveToTS = (
pkg: string,
file: 'gatsby-browser' | 'gatsby-ssr' | 'gatsby-node'
): Record<string, string> => {
const resolveToTS = (pkg, file) => {
const root = `${process.cwd()}/.cache`

let cjs = require.resolve(`${pkg}/${file}.js`, { paths: [process.cwd()] })
Expand All @@ -47,9 +28,9 @@ const resolveToTS = (
}
}

export const onCreateWebpackConfig = (
{ actions: { setWebpackConfig }, stage }: CreateWebpackConfigArgs,
{ profiling = false }: Options
exports.onCreateWebpackConfig = (
{ actions: { setWebpackConfig }, stage },
{ profiling = false }
) => {
const profilingConfig =
stage === 'build-javascript' && profiling === true
Expand Down Expand Up @@ -92,8 +73,6 @@ export const onCreateWebpackConfig = (
// Resolve to the .ts versions of gatsby-(browser|ssr) so we don't end up by adding the whole lib.
...resolveToTS('gatsby-plugin-next-seo', 'gatsby-browser'),
...resolveToTS('gatsby-plugin-next-seo', 'gatsby-ssr'),
...resolveToTS('@vtex/gatsby-theme-store', 'gatsby-browser'),
...resolveToTS('@vtex/gatsby-theme-store', 'gatsby-ssr'),
'@vtex/order-manager': require.resolve(
'@vtex/order-manager/src/index.tsx'
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { UIProvider } from '@vtex/store-sdk'
import React from 'react'
import type { RenderBodyArgs, WrapRootElementNodeArgs } from 'gatsby'

import { handleUserBackOnline } from './sdk/offline'
import { Provider as RegionProvider } from './sdk/region/Provider'
import { Provider as ToastProvider } from './sdk/toast/Provider'
import { handleUserBackOnline } from './src/sdk/offline'
import { Provider as RegionProvider } from './src/sdk/region/Provider'
import { Provider as ToastProvider } from './src/sdk/toast/Provider'

export const wrapRootElement = ({ element }: WrapRootElementNodeArgs) => (
export const wrapRootElement = ({ element }) => (
<UIProvider>
<RegionProvider>
<ToastProvider>{element}</ToastProvider>
</RegionProvider>
</UIProvider>
)

export const onRenderBody = ({
setPostBodyComponents,
pathname,
}: RenderBodyArgs) => {
export const onRenderBody = ({ setPostBodyComponents, pathname }) => {
if (!pathname.startsWith('/offline')) {
return null
}
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-theme-store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// noop
12 changes: 9 additions & 3 deletions packages/gatsby-theme-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
"version": "0.373.6",
"description": "Gatsby theme for building ecommerce websites",
"main": "index.js",
"module": "src/index.ts",
"browser": "src/index.ts",
"sideEffects": false,
"files": [
"dist",
"gatsby-*",
"index.js",
"src"
],
"repository": {
"type": "git",
"url": "https://github.com/vtex/faststore",
"directory": "packages/gatsby-theme-store"
},
"module": "src/index.ts",
"browser": "src/index.ts",
"sideEffects": false,
"scripts": {
"build": "cross-env NODE_ENV=production tsc",
"develop": "tsc --watch",
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-theme-store/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"outDir": ".",
"alwaysStrict": false,
"noEmit": true,
"jsx": "react"
},
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
Expand Down

0 comments on commit 61f3523

Please sign in to comment.