Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@W-16442332@ Add support for environment level base path (the base path for /mobify routes) #1970

Merged
merged 42 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f4f4207
Groundwork for configuring the base path for /mobify routes
vcua-mobify Aug 8, 2024
a84ca50
Groundwork for local dev server basepaths
vcua-mobify Aug 9, 2024
3da7260
Rename getNamespace
vcua-mobify Aug 9, 2024
e3c9529
Lint
vcua-mobify Aug 9, 2024
4ee69de
Rename path getters
vcua-mobify Aug 9, 2024
f08d5ab
Add unit test
vcua-mobify Aug 9, 2024
c87f4d4
Fix runtime tests
vcua-mobify Aug 9, 2024
2c8f932
Fix dev server test
vcua-mobify Aug 12, 2024
d4debd5
Fix for HMR to work with local dev server envBasePath
vcua-mobify Aug 12, 2024
eb6b2cd
getEnvBasePath log
vcua-mobify Aug 13, 2024
b5f98f4
Remove console.log
vcua-mobify Aug 13, 2024
c3175bd
Use let instead of const
vcua-mobify Aug 13, 2024
b443b33
Update app-config handlebars
vcua-mobify Aug 13, 2024
bff2cd4
Merge branch 'develop' into basePaths-impl
vcua-mobify Aug 13, 2024
1d639c2
Update changelogs
vcua-mobify Aug 13, 2024
fc3e8b0
Improve test coverage
vcua-mobify Aug 13, 2024
afeed04
Adjust to fix a tests
vcua-mobify Aug 13, 2024
7c1c48a
Adjust coverage threshold
vcua-mobify Aug 13, 2024
549ca8d
Lint fixes for handlebars
vcua-mobify Aug 13, 2024
1d96b0e
Another handlebar lint fix
vcua-mobify Aug 13, 2024
4d8fc73
Update packages/pwa-kit-dev/src/ssr/server/build-dev-server.js
kevinxh Aug 26, 2024
d20e099
move logic to enableReactRefresh
kevinxh Aug 27, 2024
25cccab
add deprecation warning
kevinxh Aug 27, 2024
268f6d7
remove test code
kevinxh Aug 27, 2024
c9af5eb
fix client side getConfig from giving bad data
kevinxh Aug 27, 2024
a829dfb
Update packages/pwa-kit-runtime/src/utils/ssr-namespace-paths.js
kevinxh Aug 27, 2024
1400175
strip away trailing slash
kevinxh Aug 27, 2024
5183e01
refactor deprecated code
kevinxh Aug 27, 2024
6f52df8
fix comment
kevinxh Aug 27, 2024
802055d
update comment
kevinxh Aug 27, 2024
5dd6dbe
update comment
kevinxh Aug 27, 2024
b75cc76
use logger
kevinxh Aug 27, 2024
9eaa191
fix import statements
kevinxh Aug 27, 2024
32fcd2f
fix lint
kevinxh Aug 27, 2024
16e8835
remove unnecessary changes
kevinxh Aug 27, 2024
cf475d3
fix test
kevinxh Aug 27, 2024
f91b4ba
fix generator
kevinxh Aug 27, 2024
4927f21
bump test coverage
kevinxh Aug 27, 2024
a442ddd
add more deprecation jsdoc
kevinxh Aug 27, 2024
b7e6339
fix lint
kevinxh Aug 27, 2024
ca4b260
revert getConfig changes
kevinxh Aug 28, 2024
23c2151
Merge branch 'develop' into basePaths-impl
kevinxh Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/pwa-kit-create-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## v3.8.0-dev (Aug 8, 2024)
- Add support for environment level base paths [#1970](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1970)

## v3.7.0 (Aug 7, 2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
resolveLocaleFromUrl
} from '@salesforce/retail-react-app/app/utils/site-utils'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
import {proxyBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
import {getEnvBasePath, getProxyPath} from '@salesforce/pwa-kit-runtime/utils/ssr-paths'
import {createUrlTemplate} from '@salesforce/retail-react-app/app/utils/url'
import createLogger from '@salesforce/pwa-kit-runtime/utils/logger-factory'

Expand Down Expand Up @@ -46,6 +46,9 @@ const AppConfig = ({children, locals = {}}) => {

const appOrigin = getAppOrigin()

const redirectURI = `${appOrigin}/callback`
const proxy = `${appOrigin}${getEnvBasePath()}${commerceApiConfig.proxyPath}`

return (
<CommerceApiProvider
shortCode={commerceApiConfig.parameters.shortCode}
Expand All @@ -54,10 +57,12 @@ const AppConfig = ({children, locals = {}}) => {
siteId={locals.site?.id}
locale={locals.locale?.id}
currency={locals.locale?.preferredCurrency}
redirectURI={`${appOrigin}/callback`}
proxy={`${appOrigin}${commerceApiConfig.proxyPath}`}
redirectURI={redirectURI}
proxy={proxy}
headers={headers}
OCAPISessionsURL={`${appOrigin}${proxyBasePath}/ocapi/s/${locals.site?.id}/dw/shop/v22_8/sessions`}
OCAPISessionsURL={`${appOrigin}${getProxyPath()}/ocapi/s/${
locals.site?.id
}/dw/shop/v22_8/sessions`}
logger={createLogger({packageName: 'commerce-sdk-react'})}
{{#if answers.project.commerce.isSlasPrivate}}
// Set 'enablePWAKitPrivateClient' to true use SLAS private client login flows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
resolveLocaleFromUrl
} from '@salesforce/retail-react-app/app/utils/site-utils'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
import {proxyBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
import {getEnvBasePath, getProxyPath} from '@salesforce/pwa-kit-runtime/utils/ssr-paths'
import {createUrlTemplate} from '@salesforce/retail-react-app/app/utils/url'
import createLogger from '@salesforce/pwa-kit-runtime/utils/logger-factory'

Expand Down Expand Up @@ -46,6 +46,9 @@ const AppConfig = ({children, locals = {}}) => {

const appOrigin = getAppOrigin()

const redirectURI = `${appOrigin}/callback`
const proxy = `${appOrigin}${getEnvBasePath()}${commerceApiConfig.proxyPath}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I was a partner dev and I saw this line of code I would probably be quite confused. Since we are giving people this file, this code is theirs and they should probably be able to understand it.

Have you thought about either creating a new util called getAppOriginWithBasePatth or maybe modifying so we can optionally include the base path? like getAppOrigin({includeBasePath: true})

Just a thought.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good thought, but I think we may need to put more effort into this. I'd really love to get this merged soon and move on to the second part of this work...


return (
<CommerceApiProvider
shortCode={commerceApiConfig.parameters.shortCode}
Expand All @@ -54,10 +57,12 @@ const AppConfig = ({children, locals = {}}) => {
siteId={locals.site?.id}
locale={locals.locale?.id}
currency={locals.locale?.preferredCurrency}
redirectURI={`${appOrigin}/callback`}
proxy={`${appOrigin}${commerceApiConfig.proxyPath}`}
redirectURI={redirectURI}
proxy={proxy}
headers={headers}
OCAPISessionsURL={`${appOrigin}${proxyBasePath}/ocapi/s/${locals.site?.id}/dw/shop/v22_8/sessions`}
OCAPISessionsURL={`${appOrigin}${getProxyPath()}/ocapi/s/${
locals.site?.id
}/dw/shop/v22_8/sessions`}
logger={createLogger({packageName: 'commerce-sdk-react'})}
{{#if answers.project.commerce.isSlasPrivate}}
// Set 'enablePWAKitPrivateClient' to true use SLAS private client login flows.
Expand Down
3 changes: 3 additions & 0 deletions packages/pwa-kit-dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## v3.8.0-dev (Aug 08, 2024)

- Add support for environment level base paths [#1970](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1970)

## v3.7.0 (Aug 07, 2024)

## v3.6.0 (Jun 25, 2024)
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa-kit-dev/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
...base,
coverageThreshold: {
global: {
branches: 67,
branches: 68,
functions: 75,
lines: 75,
statements: 75
Expand Down
25 changes: 7 additions & 18 deletions packages/pwa-kit-dev/src/configs/webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer'
import LoadablePlugin from '@loadable/webpack-plugin'
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
import SpeedMeasurePlugin from 'speed-measure-webpack-plugin'
import {getBundlePath} from '@salesforce/pwa-kit-runtime/utils/ssr-paths'

import OverridesResolverPlugin from './overrides-plugin'
import {sdkReplacementPlugin} from './plugins'
Expand Down Expand Up @@ -121,18 +122,6 @@ const getAppEntryPoint = () => {
return resolve('./', EXT_OVERRIDES_DIR_NO_SLASH, 'app', 'main')
}

const getPublicPathEntryPoint = () => {
return resolve(
projectDir,
'node_modules',
'@salesforce',
'pwa-kit-dev',
'ssr',
'server',
'public-path'
)
}

const findDepInStack = (pkg) => {
// Look for the SDK node_modules in two places because in CI,
// pwa-kit-dev is published under a 'dist' directory, which
Expand Down Expand Up @@ -397,6 +386,7 @@ const enableReactRefresh = (config) => {

const newRule = ruleForBabelLoader([require.resolve('react-refresh/babel')])
const rules = findAndReplace(config.module.rules, (rule) => rule.id === 'babel-loader', newRule)
const hmrBasePath = `${getBundlePath()}/development/`

return {
...config,
Expand All @@ -406,15 +396,14 @@ const enableReactRefresh = (config) => {
},
entry: {
...config.entry,
main: [
'webpack-hot-middleware/client?path=/__mrt/hmr',
getPublicPathEntryPoint(),
getAppEntryPoint()
]
main: ['webpack-hot-middleware/client?path=/__mrt/hmr', getAppEntryPoint()]
},
output: {
...config.output,
publicPath: hmrBasePath
},
plugins: [
...config.plugins,

new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin({
overlay: false
Expand Down
7 changes: 4 additions & 3 deletions packages/pwa-kit-dev/src/ssr/server/build-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import open from 'open'
import requireFromString from 'require-from-string'
import {RemoteServerFactory} from '@salesforce/pwa-kit-runtime/ssr/server/build-remote-server'
import {proxyConfigs} from '@salesforce/pwa-kit-runtime/utils/ssr-shared'
import {bundleBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
import {getBundlePath} from '@salesforce/pwa-kit-runtime/utils/ssr-paths'
import {
SERVER,
CLIENT,
Expand Down Expand Up @@ -152,6 +152,7 @@ export const DevServerMixin = {
if (fs.existsSync(projectWebpackPath)) {
config = require(projectWebpackPath)
}

app.__compiler = webpack(config)
app.__devMiddleware = webpackDevMiddleware(app.__compiler, {serverSideRender: true})
app.__isInitialBuild = true
Expand All @@ -167,7 +168,7 @@ export const DevServerMixin = {
app.__hotServerMiddleware = webpackHotServerMiddleware(app.__compiler)
}

app.use(`${bundleBasePath}/development`, app.__devMiddleware)
app.use(`${getBundlePath()}/development`, app.__devMiddleware)

app.__hmrMiddleware = (_, res) => res.status(501).send('Hot Module Reloading is disabled.')
const clientCompiler = app.__compiler.compilers.find((compiler) => compiler.name === CLIENT)
Expand Down Expand Up @@ -210,7 +211,7 @@ export const DevServerMixin = {
// Proxy bundle asset requests to the local
// build directory.
app.use(
`${bundleBasePath}/development`,
`${getBundlePath()}/development`,
express.static(path.resolve(process.cwd(), 'src'), {
dotFiles: 'deny',
setHeaders: setLocalAssetHeaders,
Expand Down
60 changes: 34 additions & 26 deletions packages/pwa-kit-dev/src/ssr/server/build-dev-server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,37 @@ const insecureFetch = (url, opts) => {
})
}

const mobifyConfig = {
ssrEnabled: true,
ssrOnly: ['main.js.map', 'ssr.js', 'ssr.js.map'],
ssrShared: ['main.js', 'ssr-loader.js', 'worker.js'],
ssrParameters: {
proxyConfigs: [
{
protocol: 'https',
host: 'test.proxy.com',
path: 'base'
},
{
protocol: 'https',
// This is intentionally an unreachable host
host: '0.0.0.0',
path: 'base2'
},
{
protocol: 'https',
host: 'test.proxy.com',
path: 'base3',
caching: true
}
]
}
}

const opts = (overrides = {}) => {
const defaults = {
buildDir: path.join(testFixtures, 'build'),
mobify: {
ssrEnabled: true,
ssrOnly: ['main.js.map', 'ssr.js', 'ssr.js.map'],
ssrShared: ['main.js', 'ssr-loader.js', 'worker.js'],
ssrParameters: {
proxyConfigs: [
{
protocol: 'https',
host: 'test.proxy.com',
path: 'base'
},
{
protocol: 'https',
// This is intentionally an unreachable host
host: '0.0.0.0',
path: 'base2'
},
{
protocol: 'https',
host: 'test.proxy.com',
path: 'base3',
caching: true
}
]
}
},
mobify: mobifyConfig,
quiet: true,
port: TEST_PORT,
protocol: 'http',
Expand All @@ -102,6 +104,12 @@ const opts = (overrides = {}) => {
}
}

jest.mock('@salesforce/pwa-kit-runtime/utils/ssr-config', () => {
return {
getConfig: () => mobifyConfig
}
})

describe('DevServer error handlers', () => {
const expectServerErrorHandled = (error, times) => {
const proc = {exit: jest.fn()}
Expand Down
20 changes: 0 additions & 20 deletions packages/pwa-kit-dev/src/ssr/server/public-path.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/pwa-kit-react-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## v3.8.0-dev (Aug 08, 2024)

- Add support for environment level base paths [#1970](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1970)

## v3.7.0 (Aug 07, 2024)
- Add `beforeHydrate` option to withReactQuery component [#1912](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1912)
- Add server side rendering performance metrics via query parameter `__server_timing` or environment variable `SERVER_TIMING`, the metrics is available in the console logs and response header `server-timing`. [#1895](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1895)
Expand Down
4 changes: 2 additions & 2 deletions packages/pwa-kit-react-sdk/src/ssr/universal/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @module progressive-web-sdk/ssr/universal/utils
*/
import {proxyConfigs} from '@salesforce/pwa-kit-runtime/utils/ssr-shared'
import {bundleBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
import {getBundlePath} from '@salesforce/pwa-kit-runtime/utils/ssr-paths'

const onClient = typeof window !== 'undefined'

Expand All @@ -23,7 +23,7 @@ export const getAssetUrl = (path) => {
/* istanbul ignore next */
const publicPath = onClient
? `${window.Progressive.buildOrigin}`
: `${bundleBasePath}/${process.env.BUNDLE_ID || 'development'}/`
: `${getBundlePath()}/${process.env.BUNDLE_ID || 'development'}/`
return path ? `${publicPath}${path}` : publicPath
}

Expand Down
3 changes: 3 additions & 0 deletions packages/pwa-kit-runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## v3.8.0-dev (Aug 08, 2024)

- Add support for environment level base paths [#1970](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/1970)

## v3.7.0 (Aug 07, 2024)

## v3.6.0 (Jun 25, 2024)
Expand Down
Loading
Loading