Skip to content

Commit 144759b

Browse files
authored
[App Extensibility ⚙️] Fix Babel configuration ignore node_modules folder (@W-17373534@) (#2228)
* Babel ignore node_modules files * Revert "[App Extensibility ⚙️] Fix Slow Dev Server (@W-17131556@) (#2115)" This reverts commit 712f744 * WIP Add debug logs * WIP babel-config only This reverts commit 712f744 * WIP restore pwa-kit-dev start command * WIP babel-config ignore * Clean up * Fix Babel config * Clean up * lint * Remove Babel ignore flag * PR Feedback * Clean up testing code * Re-add tests
1 parent 3289701 commit 144759b

File tree

7 files changed

+46
-28
lines changed

7 files changed

+46
-28
lines changed

packages/commerce-sdk-react/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/pwa-kit-dev/src/configs/babel/babel-config.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,21 @@ export default {
5757
presets: [require('@babel/preset-env'), require('@babel/preset-react')],
5858
plugins: [require('babel-plugin-dynamic-import-node-babel-7')]
5959
}
60-
}
60+
},
61+
ignore: [
62+
function (filepath) {
63+
// Return false if it's an allowed extension package @salesforce/pwa-kit-extension-sdk and extension-*
64+
if (/node_modules\/@[^/]+\/(pwa-kit-extension-sdk|extension-)/.test(filepath)) {
65+
return false
66+
}
67+
68+
// Return true if it's in node_modules (excluding allowed packages handled above)
69+
if (/node_modules/.test(filepath)) {
70+
return true
71+
}
72+
73+
// Return false for all other files
74+
return false
75+
}
76+
]
6177
}

packages/pwa-kit-dev/src/configs/webpack/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ const ruleForBabelLoader = (babelPlugins) => {
340340
id: 'babel-loader',
341341
test: /(\.js(x?)|\.ts(x?))$/,
342342
// NOTE: Because our extensions are just folders containing source code, we need to ensure that the babel-loader processes them.
343+
// This regex exclude everything in node_modules, but node_modules/extensions-*/ folders
344+
exclude: /node_modules\/(?!(@?[^/]+\/)?extension-)[^/]+\/.*$/i,
343345
use: [
344346
{
345347
loader: findDepInStack('babel-loader'),

packages/pwa-kit-extension-sdk/package-lock.json

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/pwa-kit-extension-sdk/src/configs/babel/utils.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import {getConfiguredExtensions} from '../../shared/utils'
1111
/**
1212
* Constants used for building Babel extensibility arguments:
1313
*
14-
* IGNORE_PATH: Provides a placeholder path that does not exist, used in Babel's `--ignore`
15-
* option to prevent processing of any unintended files by specifying a path that cannot match
16-
* any actual file. This effectively disables Babel's ignore behavior when no other paths are specified.
17-
*
1814
* SERVER_PATH: Absolute path to the server entry point (`build-remote-server.js`) within the
1915
* `@salesforce/pwa-kit-runtime` package. Required for Babel processing to ensure that server-side
2016
* code, especially for SSR, is correctly transpiled as part of the extensibility setup.
@@ -25,7 +21,6 @@ import {getConfiguredExtensions} from '../../shared/utils'
2521
* if no actual extensions are added.
2622
*/
2723
const NODE_MODULES_PATH = 'node_modules'
28-
const IGNORE_PATH = `${NODE_MODULES_PATH}/does_not_exist`
2924
const SERVER_PATH = `${NODE_MODULES_PATH}/@salesforce/pwa-kit-runtime/ssr/server/build-remote-server.js`
3025
const PLACEHOLDER_PATH = `${NODE_MODULES_PATH}/@salesforce/pwa-kit-extension-sdk/express/placeholders/application-extensions.js`
3126

@@ -42,12 +37,15 @@ export const buildBabelExtensibilityArgs = (config: any) => {
4237

4338
const extensionSrcPaths =
4439
extensions.length > 0
45-
? extensions.map(([packageName]) =>
46-
fse.realpathSync(p.resolve(`${NODE_MODULES_PATH}/${packageName}/src`))
40+
? extensions.map(
41+
([packageName]) =>
42+
fse.realpathSync(p.resolve(`${NODE_MODULES_PATH}/${packageName}/src`)) + '/**'
4743
)
4844
: []
4945

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

52-
return `--ignore "${IGNORE_PATH}" --only "app/**,${serverPath},${placeHolderPath}${extensionsPathsStr}/**"`
48+
const babelArgs = `--only "app/**,${serverPath},${placeHolderPath}${extensionsPathsStr}"`
49+
50+
return babelArgs
5351
}

packages/pwa-kit-extension-sdk/src/configs/babel/utils.test.ts renamed to packages/pwa-kit-extension-sdk/src/configs/utils.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
import * as fse from 'fs-extra'
88
import * as path from 'path'
9-
import {buildBabelExtensibilityArgs} from './utils'
10-
import {ApplicationExtensionEntryTuple} from '../../types'
9+
import {buildBabelExtensibilityArgs} from './babel/utils'
10+
import {ApplicationExtensionEntryTuple} from '../types'
1111

1212
jest.mock('fs-extra', () => ({
1313
...jest.requireActual('fs-extra'),
@@ -50,7 +50,7 @@ describe('buildBabelExtensibilityArgs', () => {
5050
})
5151

5252
test('should return the correct Babel arguments string', () => {
53-
const expectedArgs = `--ignore "node_modules/does_not_exist" --only "app/**,/absolute/path/to/build-remote-server.js,/absolute/path/to/application-extensions.js,/absolute/path/to/@salesforce/extension-this/src,/absolute/path/to/@salesforce/extension-that/src/**"`
53+
const expectedArgs = `--only "app/**,/absolute/path/to/build-remote-server.js,/absolute/path/to/application-extensions.js,/absolute/path/to/@salesforce/extension-this/src/**,/absolute/path/to/@salesforce/extension-that/src/**"`
5454
const result = buildBabelExtensibilityArgs(CONFIG)
5555
expect(result).toBe(expectedArgs)
5656
})
@@ -78,7 +78,7 @@ describe('buildBabelExtensibilityArgs', () => {
7878
})
7979

8080
test('should handle an empty list of configured extensions', () => {
81-
const expectedArgs = `--ignore "node_modules/does_not_exist" --only "app/**,/absolute/path/to/build-remote-server.js,/absolute/path/to/application-extensions.js/**"`
81+
const expectedArgs = `--only "app/**,/absolute/path/to/build-remote-server.js,/absolute/path/to/application-extensions.js"`
8282
const result = buildBabelExtensibilityArgs({app: {extensions: []}})
8383
expect(result).toBe(expectedArgs)
8484
const result2 = buildBabelExtensibilityArgs({app: {}})

packages/template-retail-react-app/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)