Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 (
/node_modules[\\/][^/]+[\\/](pwa-kit-extension-sdk|@[^/]+\/extension-|extension-)/.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
2 changes: 1 addition & 1 deletion packages/pwa-kit-dev/src/configs/webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ 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: /node_modules[\\/](?!(@?[^\\/]+[\\/])?extension-)[^\\/]+[\\/].*$/i,
Copy link
Contributor

@kevinxh kevinxh Jan 30, 2025

Choose a reason for hiding this comment

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

you could use path.sep to simplify this regex a bit...

new Regex(`${path.sep}`)

use: [
{
loader: findDepInStack('babel-loader'),
Expand Down
52 changes: 37 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,29 @@ 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 extensionSrcPaths =
extensions.length > 0
? extensions.map(
([packageName]) =>
fse.realpathSync(p.resolve(`${NODE_MODULES_PATH}/${packageName}/src`)) + '/**'
)
: []
const extensionSrcPaths =
extensions.length > 0
? extensions.map(
([packageName]) =>
fse.realpathSync(
p.resolve(p.join(NODE_MODULES_PATH, packageName, 'src'))
) + '/**'
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be \** in window?

Copy link
Contributor Author

@adamraya adamraya Jan 30, 2025

Choose a reason for hiding this comment

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

Done

)
: []

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

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

Choose a reason for hiding this comment

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

same as above?


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