Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
11 changes: 9 additions & 2 deletions packages/pwa-kit-dev/src/configs/babel/babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// PWA-Kit Imports
import {getConfiguredExtensions} from '@salesforce/pwa-kit-extension-sdk/shared/utils'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
import path from 'path'

export default {
sourceType: 'unambiguous',
Expand Down Expand Up @@ -60,13 +61,19 @@ export default {
},
ignore: [
function (filepath) {
const normalizedPath = path.normalize(filepath)

// Return false if it's an allowed extension package @salesforce/pwa-kit-extension-sdk and extension-*
if (/node_modules\/@[^/]+\/(pwa-kit-extension-sdk|extension-)/.test(filepath)) {
if (
new RegExp(
`node_modules\\${path.sep}[^\\${path.sep}]+\\${path.sep}(pwa-kit-extension-sdk|@[^\\${path.sep}]+\\${path.sep}extension-|extension-)`
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, maybe it's worth saving this to a variable for re-use

).test(normalizedPath)
) {
return false
}

// Return true if it's in node_modules (excluding allowed packages handled above)
if (/node_modules/.test(filepath)) {
if (/node_modules/.test(normalizedPath)) {
return true
}

Expand Down
7 changes: 5 additions & 2 deletions packages/pwa-kit-dev/src/configs/webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// For more information on these settings, see https://webpack.js.org/configuration
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer'
import {resolve} from 'path'
import path, {resolve} from 'path'
import fse from 'fs-extra'
import webpack from 'webpack'

Expand Down Expand Up @@ -341,7 +341,10 @@ const ruleForBabelLoader = (babelPlugins) => {
test: /(\.js(x?)|\.ts(x?))$/,
// NOTE: Because our extensions are just folders containing source code, we need to ensure that the babel-loader processes them.
// This regex exclude everything in node_modules, but node_modules/extensions-*/ folders
exclude: /node_modules\/(?!(@?[^/]+\/)?extension-)[^/]+\/.*$/i,
exclude: new RegExp(
`node_modules\\${path.sep}(?!(@?[^\\${path.sep}]+\\${path.sep})?extension-).*`,
'i'
),
use: [
{
loader: findDepInStack('babel-loader'),
Expand Down
53 changes: 38 additions & 15 deletions packages/pwa-kit-extension-sdk/src/configs/babel/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,22 @@ import {getConfiguredExtensions} from '../../shared/utils'
* if no actual extensions are added.
*/
const NODE_MODULES_PATH = 'node_modules'
const SERVER_PATH = `${NODE_MODULES_PATH}/@salesforce/pwa-kit-runtime/ssr/server/build-remote-server.js`
const PLACEHOLDER_PATH = `${NODE_MODULES_PATH}/@salesforce/pwa-kit-extension-sdk/express/placeholders/application-extensions.js`
const SERVER_PATH = p.join(
NODE_MODULES_PATH,
'@salesforce',
'pwa-kit-runtime',
'ssr',
'server',
'build-remote-server.js'
)
const PLACEHOLDER_PATH = p.join(
NODE_MODULES_PATH,
'@salesforce',
'pwa-kit-extension-sdk',
'express',
'placeholders',
'application-extensions.js'
)

/**
* Builds Babel extensibility arguments for processing specific files and paths.
Expand All @@ -31,21 +45,30 @@ const PLACEHOLDER_PATH = `${NODE_MODULES_PATH}/@salesforce/pwa-kit-extension-sdk
* or symlinked paths that Babel doesn't support by using realpathSync.
*/
export const buildBabelExtensibilityArgs = (config: any) => {
const extensions = getConfiguredExtensions(config)
const serverPath = fse.realpathSync(p.resolve(SERVER_PATH))
const placeHolderPath = fse.realpathSync(p.resolve(PLACEHOLDER_PATH))
try {
const extensions = getConfiguredExtensions(config)
const serverPath = fse.realpathSync(p.resolve(SERVER_PATH))
const placeHolderPath = fse.realpathSync(p.resolve(PLACEHOLDER_PATH))
const appPath = p.join('app', '**')

const extensionSrcPaths =
extensions.length > 0
? extensions.map(
([packageName]) =>
fse.realpathSync(p.resolve(`${NODE_MODULES_PATH}/${packageName}/src`)) + '/**'
)
: []
const extensionSrcPaths =
extensions.length > 0
? extensions.map(([packageName]) => {
const realPath = fse.realpathSync(
p.resolve(p.join(NODE_MODULES_PATH, packageName, 'src'))
)
return p.join(realPath, '**')
})
: []

const extensionsPathsStr = extensionSrcPaths.length > 0 ? `,${extensionSrcPaths.join(',')}` : ''
const extensionsPathsStr =
extensionSrcPaths.length > 0 ? `,${extensionSrcPaths.join(',')}` : ''

const babelArgs = `--only "app/**,${serverPath},${placeHolderPath}${extensionsPathsStr}"`
const babelArgs = `--only "${appPath},${serverPath},${placeHolderPath}${extensionsPathsStr}"`

return babelArgs
return babelArgs
} catch (error) {
console.error('Error building Babel extensibility arguments:', error)
throw error
}
}
Loading