@salesforce/pwa-kit-dev 4.0.0-extensibility-preview.3 → 4.0.0-extensibility-preview.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/pwa-kit-dev.js +7 -0
- package/configs/babel/babel-config.js +2 -1
- package/configs/webpack/config.js +87 -24
- package/package.json +9 -8
package/bin/pwa-kit-dev.js
CHANGED
|
@@ -473,6 +473,13 @@ const main = async () => {
|
|
|
473
473
|
)
|
|
474
474
|
})
|
|
475
475
|
|
|
476
|
+
program
|
|
477
|
+
.command('list-overrides')
|
|
478
|
+
.description('List all overridable files in the project')
|
|
479
|
+
.action(() => {
|
|
480
|
+
execSync(p.join('node_modules', '.bin', 'pwa-kit-extension-sdk'))
|
|
481
|
+
})
|
|
482
|
+
|
|
476
483
|
managedRuntimeCommand('tail-logs')
|
|
477
484
|
.description(`continuously stream environment logs`)
|
|
478
485
|
.addOption(
|
|
@@ -19,7 +19,8 @@ var _default = exports.default = {
|
|
|
19
19
|
sourceType: 'unambiguous',
|
|
20
20
|
presets: [[require('@babel/preset-env'), {
|
|
21
21
|
targets: {
|
|
22
|
-
node
|
|
22
|
+
// The _minimum_ Node version supported. See https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/upgrade-node-version.html#supported-node-versions
|
|
23
|
+
node: '18'
|
|
23
24
|
}
|
|
24
25
|
}], require('@babel/preset-typescript'), require('@babel/preset-react')],
|
|
25
26
|
plugins: [[require('@salesforce/pwa-kit-extension-sdk/configs/babel/plugin-application-extensions'), {
|
|
@@ -14,6 +14,7 @@ var _reactRefreshWebpackPlugin = _interopRequireDefault(require("@pmmmwh/react-r
|
|
|
14
14
|
var _speedMeasureWebpackPlugin = _interopRequireDefault(require("speed-measure-webpack-plugin"));
|
|
15
15
|
var _webpackNotifier = _interopRequireDefault(require("webpack-notifier"));
|
|
16
16
|
var _applicationExtensionsConfigPlugin = _interopRequireDefault(require("@salesforce/pwa-kit-extension-sdk/configs/webpack/application-extensions-config-plugin"));
|
|
17
|
+
var _overrideStatsPlugin = _interopRequireDefault(require("@salesforce/pwa-kit-extension-sdk/configs/webpack/override-stats-plugin"));
|
|
17
18
|
var _plugins = require("./plugins");
|
|
18
19
|
var _configNames = require("./config-names");
|
|
19
20
|
var _webpack2 = require("@salesforce/pwa-kit-extension-sdk/configs/webpack");
|
|
@@ -98,10 +99,32 @@ const findDepInStack = pkg => {
|
|
|
98
99
|
}
|
|
99
100
|
return candidate;
|
|
100
101
|
};
|
|
102
|
+
|
|
103
|
+
// Helper function to detect extensions
|
|
104
|
+
const detectExtensions = ({
|
|
105
|
+
dependencies,
|
|
106
|
+
projectDir
|
|
107
|
+
} = {}) => {
|
|
108
|
+
const extensions = [];
|
|
109
|
+
|
|
110
|
+
// Use provided dependencies or get them from package.json
|
|
111
|
+
const allDependencies = dependencies || [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.devDependencies || {})];
|
|
112
|
+
for (const dependency of allDependencies) {
|
|
113
|
+
const packagePath = _path.default.join(projectDir || process.cwd(), 'node_modules', dependency);
|
|
114
|
+
if ((0, _utils.isExtensionPackage)(packagePath)) {
|
|
115
|
+
extensions.push(dependency);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return extensions;
|
|
119
|
+
};
|
|
120
|
+
const detectedExtensions = detectExtensions({
|
|
121
|
+
projectDir
|
|
122
|
+
});
|
|
101
123
|
const baseConfig = target => {
|
|
102
124
|
if (!['web', 'node'].includes(target)) {
|
|
103
125
|
throw Error(`The value "${target}" is not a supported webpack target`);
|
|
104
126
|
}
|
|
127
|
+
const extensions = (0, _utils.getConfiguredExtensions)((0, _ssrConfig.getConfig)());
|
|
105
128
|
class Builder {
|
|
106
129
|
constructor() {
|
|
107
130
|
this.config = _objectSpread(_objectSpread({
|
|
@@ -143,11 +166,7 @@ const baseConfig = target => {
|
|
|
143
166
|
extensions: SUPPORTED_FILE_EXTENSIONS,
|
|
144
167
|
alias: _objectSpread(_objectSpread({}, _extends(...DEPS_TO_DEDUPE.map(dep => ({
|
|
145
168
|
[dep]: findDepInStack(dep)
|
|
146
|
-
})))),
|
|
147
|
-
// TODO: This alias is temporary. When we investigate turning the retail template into an application extension
|
|
148
|
-
// we'll have to decide if we want to continue using an alias, or change back to using relative paths.
|
|
149
|
-
'@salesforce/retail-react-app': projectDir
|
|
150
|
-
}, (0, _utils.buildAliases)(Object.keys((pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies) || {}).filter(dependency => dependency.match(_utils.nameRegex))))
|
|
169
|
+
})))), (0, _utils.buildAliases)(detectedExtensions))
|
|
151
170
|
}, target === 'web' ? {
|
|
152
171
|
fallback: {
|
|
153
172
|
crypto: false
|
|
@@ -159,13 +178,13 @@ const baseConfig = target => {
|
|
|
159
178
|
}
|
|
160
179
|
},
|
|
161
180
|
plugins: [new _applicationExtensionsConfigPlugin.default({
|
|
162
|
-
extensions
|
|
181
|
+
extensions
|
|
163
182
|
}), new _webpack.default.DefinePlugin({
|
|
164
183
|
DEBUG,
|
|
165
184
|
NODE_ENV: `'${process.env.NODE_ENV}'`,
|
|
166
185
|
WEBPACK_TARGET: `'${target}'`,
|
|
167
186
|
['global.GENTLY']: false
|
|
168
|
-
}),
|
|
187
|
+
}), process.env.RECORD_OVERRIDES === 'true' && new _overrideStatsPlugin.default(),
|
|
169
188
|
// new SharedStatePlugin(),
|
|
170
189
|
mode === development && new _webpack.default.NoEmitOnErrorsPlugin(), (0, _plugins.sdkReplacementPlugin)(),
|
|
171
190
|
// Don't chunk if it's a node target – faster Lambda startup.
|
|
@@ -193,18 +212,20 @@ const baseConfig = target => {
|
|
|
193
212
|
}
|
|
194
213
|
}, (0, _webpack2.ruleForApplicationExtensibility)({
|
|
195
214
|
loaderOptions: {
|
|
196
|
-
configured:
|
|
215
|
+
configured: extensions,
|
|
197
216
|
target: 'web'
|
|
198
217
|
}
|
|
199
218
|
}), (0, _webpack2.ruleForApplicationExtensibility)({
|
|
200
219
|
loaderOptions: {
|
|
201
|
-
configured:
|
|
220
|
+
configured: extensions,
|
|
202
221
|
target: 'node'
|
|
203
222
|
}
|
|
204
223
|
}), (0, _webpack2.ruleForOverrideResolver)({
|
|
205
|
-
|
|
224
|
+
extensions,
|
|
225
|
+
resolveExtensions: SUPPORTED_FILE_EXTENSIONS,
|
|
226
|
+
isMonoRepo,
|
|
206
227
|
projectDir,
|
|
207
|
-
|
|
228
|
+
target
|
|
208
229
|
})].filter(Boolean)
|
|
209
230
|
}
|
|
210
231
|
});
|
|
@@ -245,24 +266,66 @@ const staticFolderCopyPlugin = new _copyWebpackPlugin.default({
|
|
|
245
266
|
patterns: [{
|
|
246
267
|
from: 'app/static/',
|
|
247
268
|
to: 'static/'
|
|
248
|
-
}, ...
|
|
249
|
-
const packageName = extension[0];
|
|
269
|
+
}, ...detectedExtensions.map(extension => {
|
|
250
270
|
return {
|
|
251
|
-
from: `${projectDir}/node_modules/${
|
|
252
|
-
to: `static/${EXTENIONS_NAMESPACE}/${
|
|
271
|
+
from: `${projectDir}/node_modules/${extension}/static`,
|
|
272
|
+
to: `static/${EXTENIONS_NAMESPACE}/${extension}`,
|
|
253
273
|
// Add exclude for readme file.
|
|
254
274
|
noErrorOnMissing: true
|
|
255
275
|
};
|
|
256
276
|
})]
|
|
257
277
|
});
|
|
258
278
|
const ruleForBabelLoader = babelPlugins => {
|
|
279
|
+
// Handle the case when no extensions are detected
|
|
280
|
+
if (!detectedExtensions.length) {
|
|
281
|
+
return {
|
|
282
|
+
id: 'babel-loader',
|
|
283
|
+
test: /(\.js(x?)|\.ts(x?))$/,
|
|
284
|
+
exclude: /node_modules/,
|
|
285
|
+
use: [{
|
|
286
|
+
loader: findDepInStack('thread-loader'),
|
|
287
|
+
options: {
|
|
288
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
289
|
+
workers: Math.min(4, require('os').cpus().length),
|
|
290
|
+
workerParallelJobs: 100
|
|
291
|
+
}
|
|
292
|
+
}, {
|
|
293
|
+
loader: findDepInStack('babel-loader'),
|
|
294
|
+
options: _objectSpread({
|
|
295
|
+
rootMode: 'upward',
|
|
296
|
+
cacheDirectory: true
|
|
297
|
+
}, babelPlugins ? {
|
|
298
|
+
plugins: babelPlugins
|
|
299
|
+
} : {})
|
|
300
|
+
}]
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Pre-compute the paths to extensions for performance
|
|
305
|
+
const extensionPaths = detectedExtensions.map(ext => _path.default.normalize(`node_modules${_path.default.sep}${ext}${_path.default.sep}`));
|
|
259
306
|
return {
|
|
260
307
|
id: 'babel-loader',
|
|
261
308
|
test: /(\.js(x?)|\.ts(x?))$/,
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
309
|
+
exclude: modulePath => {
|
|
310
|
+
// Not in node_modules. Include it (don't exclude)
|
|
311
|
+
if (!modulePath.includes('node_modules')) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Normalize path for consistent comparison
|
|
316
|
+
const normalizedPath = _path.default.normalize(modulePath);
|
|
317
|
+
|
|
318
|
+
// Check if the path includes any of our extension paths
|
|
319
|
+
return !extensionPaths.some(extPath => normalizedPath.includes(extPath));
|
|
320
|
+
},
|
|
265
321
|
use: [{
|
|
322
|
+
loader: findDepInStack('thread-loader'),
|
|
323
|
+
options: {
|
|
324
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
325
|
+
workers: Math.min(4, require('os').cpus().length),
|
|
326
|
+
workerParallelJobs: 100
|
|
327
|
+
}
|
|
328
|
+
}, {
|
|
266
329
|
loader: findDepInStack('babel-loader'),
|
|
267
330
|
options: _objectSpread({
|
|
268
331
|
rootMode: 'upward',
|
|
@@ -308,7 +371,7 @@ const client = entryPointExists(['app', 'main']) && baseConfig('web').extend(wit
|
|
|
308
371
|
// Must be named "client". See - https://www.npmjs.com/package/webpack-hot-server-middleware#usage
|
|
309
372
|
name: _configNames.CLIENT,
|
|
310
373
|
// use source map to make debugging easier
|
|
311
|
-
devtool: mode === development ? 'source-map' : false,
|
|
374
|
+
devtool: mode === development || process.env.PWA_KIT_SOURCE_MAP === 'true' ? 'source-map' : false,
|
|
312
375
|
entry: {
|
|
313
376
|
main: getAppEntryPoint()
|
|
314
377
|
},
|
|
@@ -329,9 +392,9 @@ const optional = (name, path) => {
|
|
|
329
392
|
const clientOptional = baseConfig('web').extend(config => {
|
|
330
393
|
return _objectSpread(_objectSpread({}, config), {}, {
|
|
331
394
|
name: _configNames.CLIENT_OPTIONAL,
|
|
332
|
-
entry: _objectSpread(_objectSpread(_objectSpread(
|
|
395
|
+
entry: _objectSpread(_objectSpread(_objectSpread({}, optional('loader', (0, _path.resolve)(projectDir, 'app', 'loader.js'))), optional('worker', (0, _path.resolve)(projectDir, 'worker', 'main.js'))), optional('fetch-polyfill', (0, _path.resolve)(projectDir, 'node_modules', 'whatwg-fetch'))),
|
|
333
396
|
// use source map to make debugging easier
|
|
334
|
-
devtool: mode === development ? 'source-map' : false,
|
|
397
|
+
devtool: mode === development || process.env.PWA_KIT_SOURCE_MAP === 'true' ? 'source-map' : false,
|
|
335
398
|
plugins: [...config.plugins, analyzeBundle && getBundleAnalyzerPlugin(_configNames.CLIENT_OPTIONAL)].filter(Boolean)
|
|
336
399
|
});
|
|
337
400
|
}).build();
|
|
@@ -341,7 +404,7 @@ const renderer = _fsExtra.default.existsSync((0, _path.resolve)(projectDir, 'nod
|
|
|
341
404
|
name: _configNames.SERVER,
|
|
342
405
|
entry: '@salesforce/pwa-kit-react-sdk/ssr/server/react-rendering.js',
|
|
343
406
|
// use eval-source-map for server-side debugging
|
|
344
|
-
devtool: mode === development && INSPECT ? 'eval-source-map' : false,
|
|
407
|
+
devtool: mode === development && INSPECT || process.env.PWA_KIT_SOURCE_MAP === 'true' ? 'eval-source-map' : false,
|
|
345
408
|
output: {
|
|
346
409
|
path: buildDir,
|
|
347
410
|
// We want to split the build on local development to reduce memory usage.
|
|
@@ -363,7 +426,7 @@ const ssr = (() => {
|
|
|
363
426
|
// Only compile the ssr file when we're building for prod.
|
|
364
427
|
if (mode === production) {
|
|
365
428
|
return baseConfig('node').extend(config => {
|
|
366
|
-
return _objectSpread(_objectSpread(_objectSpread({}, config), process.env.
|
|
429
|
+
return _objectSpread(_objectSpread(_objectSpread({}, config), process.env.PWA_KIT_SOURCE_MAP === 'true' ? {
|
|
367
430
|
devtool: 'source-map'
|
|
368
431
|
} : {}), {}, {
|
|
369
432
|
// Must *not* be named "server". See - https://www.npmjs.com/package/webpack-hot-server-middleware#usage
|
|
@@ -391,7 +454,7 @@ const requestProcessor = entryPointExists(['app', 'request-processor']) && baseC
|
|
|
391
454
|
libraryTarget: 'commonjs2'
|
|
392
455
|
},
|
|
393
456
|
// use eval-source-map for server-side debugging
|
|
394
|
-
devtool: mode === development && INSPECT ? 'eval-source-map' : false,
|
|
457
|
+
devtool: mode === development && INSPECT || process.env.PWA_KIT_SOURCE_MAP === 'true' ? 'eval-source-map' : false,
|
|
395
458
|
plugins: [...config.plugins, analyzeBundle && getBundleAnalyzerPlugin(_configNames.REQUEST_PROCESSOR)].filter(Boolean)
|
|
396
459
|
});
|
|
397
460
|
}).build();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/pwa-kit-dev",
|
|
3
|
-
"version": "4.0.0-extensibility-preview.
|
|
3
|
+
"version": "4.0.0-extensibility-preview.4",
|
|
4
4
|
"description": "Build tools for pwa-kit",
|
|
5
5
|
"homepage": "https://github.com/SalesforceCommerceCloud/pwa-kit/tree/develop/packages/pwa-kit-dev#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -58,15 +58,15 @@
|
|
|
58
58
|
"@loadable/server": "^5.15.3",
|
|
59
59
|
"@loadable/webpack-plugin": "^5.15.2",
|
|
60
60
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
|
|
61
|
-
"@salesforce/pwa-kit-extension-sdk": "4.0.0-extensibility-preview.
|
|
62
|
-
"@salesforce/pwa-kit-runtime": "4.0.0-extensibility-preview.
|
|
61
|
+
"@salesforce/pwa-kit-extension-sdk": "4.0.0-extensibility-preview.4",
|
|
62
|
+
"@salesforce/pwa-kit-runtime": "4.0.0-extensibility-preview.4",
|
|
63
63
|
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
64
64
|
"@typescript-eslint/parser": "^5.57.0",
|
|
65
65
|
"archiver": "1.3.0",
|
|
66
66
|
"babel-jest": "^27.1.0",
|
|
67
67
|
"babel-loader": "^8.3.0",
|
|
68
68
|
"babel-plugin-dynamic-import-node-babel-7": "^2.0.7",
|
|
69
|
-
"babel-plugin-formatjs": "10.
|
|
69
|
+
"babel-plugin-formatjs": "10.5.36",
|
|
70
70
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
71
71
|
"chalk": "^4.1.2",
|
|
72
72
|
"commander": "^9.5.0",
|
|
@@ -105,6 +105,7 @@
|
|
|
105
105
|
"source-map-loader": "^4.0.1",
|
|
106
106
|
"speed-measure-webpack-plugin": "^1.5.0",
|
|
107
107
|
"svg-sprite-loader": "^6.0.11",
|
|
108
|
+
"thread-loader": "^4.0.4",
|
|
108
109
|
"validator": "^13.9.0",
|
|
109
110
|
"webpack": "^5.76.3",
|
|
110
111
|
"webpack-bundle-analyzer": "^4.8.0",
|
|
@@ -123,7 +124,7 @@
|
|
|
123
124
|
"@types/node": "~16.0.3",
|
|
124
125
|
"@types/node-fetch": "~2.6.3",
|
|
125
126
|
"@types/validator": "~13.7.14",
|
|
126
|
-
"internal-lib-build": "4.0.0-extensibility-preview.
|
|
127
|
+
"internal-lib-build": "4.0.0-extensibility-preview.4",
|
|
127
128
|
"nock": "^13.3.0",
|
|
128
129
|
"nodemon": "^2.0.22",
|
|
129
130
|
"superagent": "^6.1.0",
|
|
@@ -143,11 +144,11 @@
|
|
|
143
144
|
}
|
|
144
145
|
},
|
|
145
146
|
"engines": {
|
|
146
|
-
"node": "^16.11.0 || ^18.0.0 || ^20.0.0",
|
|
147
|
-
"npm": "^8.0.0 || ^9.0.0 || ^10.0.0"
|
|
147
|
+
"node": "^16.11.0 || ^18.0.0 || ^20.0.0 || ^22.0.0",
|
|
148
|
+
"npm": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0"
|
|
148
149
|
},
|
|
149
150
|
"publishConfig": {
|
|
150
151
|
"directory": "dist"
|
|
151
152
|
},
|
|
152
|
-
"gitHead": "
|
|
153
|
+
"gitHead": "5ad3b1f0e598cfe0fbdec5b1212b4dabc0a8733c"
|
|
153
154
|
}
|