Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions packages/pwa-kit-dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## v4.0.0-extensibility-preview.3 (Jan 14, 2025)
- Ensure build command works on windows when path includes spaces. [#2204](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2204)
- Add loader rule for `override-resolver-loader`. [#2207](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2207)
## v4.0.0-extensibility-preview.2 (Dec 09, 2024)
## v4.0.0-extensibility-preview.1 (Dec 09, 2024)
## v4.0.0-extensibility-preview.0 (Nov 28, 2024)
Expand Down
10 changes: 7 additions & 3 deletions packages/pwa-kit-dev/src/configs/webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import {sdkReplacementPlugin} from './plugins'
import {CLIENT, SERVER, CLIENT_OPTIONAL, SSR, REQUEST_PROCESSOR} from './config-names'

// Utilities
import {ruleForApplicationExtensibility} from '@salesforce/pwa-kit-extension-sdk/configs/webpack'
import {
ruleForApplicationExtensibility,
ruleForOverrideResolver
} from '@salesforce/pwa-kit-extension-sdk/configs/webpack'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
import {
buildAliases,
Expand All @@ -43,7 +46,7 @@ const pkg = fse.readJsonSync(resolve(projectDir, 'package.json'))
const buildDir = process.env.PWA_KIT_BUILD_DIR
? resolve(process.env.PWA_KIT_BUILD_DIR)
: resolve(projectDir, 'build')

const isMonoRepo = fse.existsSync(resolve(projectDir, '..', '..', 'lerna.json'))
const production = 'production'
const development = 'development'
const analyzeBundle = process.env.MOBIFY_ANALYZE === 'true'
Expand Down Expand Up @@ -270,7 +273,8 @@ const baseConfig = (target) => {
configured: getConfiguredExtensions(getConfig()),
target: 'node'
}
})
}),
ruleForOverrideResolver({target, projectDir, isMonoRepo})
].filter(Boolean)
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/pwa-kit-extension-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
## v4.0.0-extensibility-preview.2 (Dec 09, 2024)
- Add support for `.force_overrides` project file. (#2207)[https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2207]
- Initial release of Extensibility SDK. (#2099)[https://github.com/SalesforceCommerceCloud/pwa-kit/pull/2099]
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import {runWebpackCompiler} from './test-utils'
import path from 'path'
import {runWebpackCompiler} from './test-utils'
import {validateOverrideSource, __OVERRIDABLE_CACHE__} from './overrides-resolver-loader'

// DEVELOPER NOTE:
// This loader is intended to be used as an "inline" loader, meaning that you don't typically see it configured
Expand Down Expand Up @@ -214,7 +215,7 @@ describe('Overrides Resolver Loader', () => {
`,
'/node_modules/@salesforce/extension-that/src/overrides/@salesforce/extension-this/pages/sample-page-dependency.js': `
// Should Be Referenced
export default {}
export default {}
`,

// Extension using overridable import
Expand All @@ -224,7 +225,7 @@ describe('Overrides Resolver Loader', () => {
`,
'/node_modules/@salesforce/extension-this/src/pages/sample-page-dependency.js': `
// Should Not Be Referenced
export default {}
export default {}
`,
'/node_modules/@salesforce/extension-this/package.json':
'{"name": "@salesforce/extension-this"}',
Expand Down Expand Up @@ -340,3 +341,173 @@ describe('Overrides Resolver Loader', () => {
})
})
})

describe('validateOverrideSource', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a test for handle a malformed overridable list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The overridable list in simply text file.. each line that isn't being commented out is interpreted as a path. I think the simplicity of this means we don't have to validate it or maintain code that validates it.

Let's evaluate this later and we can create a ticket if there is a benefit to doing this validation.

beforeEach(() => {
// Clear the target cache before each test
__OVERRIDABLE_CACHE__.node = []
__OVERRIDABLE_CACHE__.web = []
})

it('should return false if the file has already been processed', () => {
const source = path.join(
path.sep,
'projects',
'pwa-kit-app',
'node_modules',
'@salesforce',
'extension-sample',
'src',
'pages',
'home.js'
)

// Mock the file being processed bup adding it to the cache
__OVERRIDABLE_CACHE__.node.push(source)

const result = validateOverrideSource(source, {
target: 'node',
overridables: [path.join('@salesforce', 'extension-sample', 'src', 'pages', 'home.js')]
})
expect(result).toBe(false)
})

it('should return false if the file is not an extension file', () => {
const source = path.join(
path.sep,
'projects',
'pwa',
'node_modules',
'not-extension-sample',
'src',
'setup-app.js'
)

const result = validateOverrideSource(source, {target: 'node'})
expect(result).toBe(false)
})

it('should return false if the file is a setup file', () => {
const source = path.join(
path.sep,
'projects',
'pwa',
'node_modules',
'extension-sample',
'src',
'setup-app.js'
)

const result = validateOverrideSource(source, {target: 'node'})
expect(result).toBe(false)
})

it('should return false if the normalized source is not in the list of overridables', () => {
const source = path.join(
path.sep,
'projects',
'pwa',
'node_modules',
'extension-sample',
'src',
'pages',
'home.js'
)

const result = validateOverrideSource(source, {
target: 'node',
overridables: []
})
expect(result).toBe(false)
})

it('should return true and add the source to the cache if it is an overridable file', () => {
const source = path.join(
path.sep,
'projects',
'pwa-kit',
'packages',
'extension-sample',
'src',
'pages',
'home.js'
)
const overridables = [
`./node_modules/${path.posix.join(
'@salesforce',
'extension-sample',
'src',
'pages',
'home.js'
)}`
]

const result = validateOverrideSource(source, {
isMonoRepo: true,
target: 'node',
overridables
})

expect(result).toBe(true)
})

it('should handle non-mono-repo sources correctly', () => {
const source = path.join(
path.sep,
'projects',
'pwa',
'node_modules',
'extension-sample',
'src',
'pages',
'home.js'
)
const overridables = [
`./node_modules/${path.posix.join('extension-sample', 'src', 'pages', 'home.js')}`
]

const result = validateOverrideSource(source, {
isMonoRepo: false,
target: 'node',
overridables
})

expect(result).toBe(true)
})

it('source cache is per target', () => {
const source = path.join(
path.sep,
'projects',
'pwa-kit',
'packages',
'extension-sample',
'src',
'pages',
'home.js'
)
const overridables = [
`./node_modules/${path.posix.join(
'@salesforce',
'extension-sample',
'src',
'pages',
'home.js'
)}`
]

const resultWeb = validateOverrideSource(source, {
isMonoRepo: true,
target: 'web',
overridables
})
const resultNode = validateOverrideSource(source, {
isMonoRepo: true,
target: 'node',
overridables
})

expect(resultWeb).toBe(true)
expect(resultNode).toBe(true)
})
})
Loading
Loading