@salesforce/pwa-kit-dev 3.0.0-preview.0

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.
Files changed (54) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +35 -0
  3. package/bin/pwa-kit-dev.js +461 -0
  4. package/configs/babel/babel-config.js +34 -0
  5. package/configs/eslint/README.md +21 -0
  6. package/configs/eslint/eslint-config.js +11 -0
  7. package/configs/eslint/index.js +11 -0
  8. package/configs/eslint/no-react.js +18 -0
  9. package/configs/eslint/partials/base.js +38 -0
  10. package/configs/eslint/partials/jest.js +24 -0
  11. package/configs/eslint/partials/react.js +29 -0
  12. package/configs/eslint/partials/typescript-permit-any.js +31 -0
  13. package/configs/eslint/partials/typescript.js +17 -0
  14. package/configs/eslint/recommended.js +20 -0
  15. package/configs/eslint/safe-types.js +20 -0
  16. package/configs/jest/jest-babel-transform.js +19 -0
  17. package/configs/jest/jest.config.js +33 -0
  18. package/configs/jest/mocks/fileMock.js +9 -0
  19. package/configs/jest/mocks/styleMock.js +9 -0
  20. package/configs/jest/mocks/svgMock.js +11 -0
  21. package/configs/webpack/config-names.js +24 -0
  22. package/configs/webpack/config.js +425 -0
  23. package/configs/webpack/overrides-plugin.js +120 -0
  24. package/configs/webpack/plugins.js +92 -0
  25. package/package.json +150 -0
  26. package/scripts/version.js +22 -0
  27. package/ssr/server/build-dev-server.js +443 -0
  28. package/ssr/server/build-dev-server.test.js +635 -0
  29. package/ssr/server/loading-screen/css/main.css +272 -0
  30. package/ssr/server/loading-screen/css/normalize.css +349 -0
  31. package/ssr/server/loading-screen/img/cloud-1.svg +1 -0
  32. package/ssr/server/loading-screen/img/cloud-2.svg +1 -0
  33. package/ssr/server/loading-screen/img/cloud-3.svg +1 -0
  34. package/ssr/server/loading-screen/img/cloud.svg +1 -0
  35. package/ssr/server/loading-screen/img/codey-arm.svg +1 -0
  36. package/ssr/server/loading-screen/img/codey-bear.svg +1 -0
  37. package/ssr/server/loading-screen/img/codey-bg.svg +1 -0
  38. package/ssr/server/loading-screen/img/codey-cloud.svg +1 -0
  39. package/ssr/server/loading-screen/img/codey-search.svg +1 -0
  40. package/ssr/server/loading-screen/img/codey.svg +1 -0
  41. package/ssr/server/loading-screen/img/codeyCarry.svg +1 -0
  42. package/ssr/server/loading-screen/img/devDocumentation.svg +1 -0
  43. package/ssr/server/loading-screen/img/devGithub.svg +1 -0
  44. package/ssr/server/loading-screen/img/devTrailhead.svg +1 -0
  45. package/ssr/server/loading-screen/img/logo.svg +1 -0
  46. package/ssr/server/loading-screen/img/slds_spinner_brand_9EA9F1.gif +0 -0
  47. package/ssr/server/loading-screen/index.html +130 -0
  48. package/ssr/server/test_fixtures/app/main.js +6 -0
  49. package/ssr/server/test_fixtures/app/static/favicon.ico +0 -0
  50. package/ssr/server/test_fixtures/localhost.pem +45 -0
  51. package/utils/script-utils.js +312 -0
  52. package/utils/script-utils.test.js +282 -0
  53. package/utils/test-fixtures/minimal-built-app/ssr.js +9 -0
  54. package/utils/test-fixtures/minimal-built-app/static/favicon.ico +0 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ /*
4
+ * Copyright (c) 2023, Salesforce, Inc.
5
+ * All rights reserved.
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+
10
+ /** Extension of the base configuration for use in React projects. */
11
+ module.exports = {
12
+ parserOptions: {
13
+ ecmaFeatures: {
14
+ jsx: true
15
+ }
16
+ },
17
+ extends: ['plugin:react/recommended', 'plugin:jsx-a11y/recommended'],
18
+ plugins: ['jsx-a11y', 'react', 'react-hooks', 'use-effect-no-deps'],
19
+ settings: {
20
+ react: {
21
+ version: 'detect'
22
+ }
23
+ },
24
+ rules: {
25
+ 'react-hooks/rules-of-hooks': 'error',
26
+ // react-hooks/exhaustive-deps has too many false positives; use-effect-no-deps is nicer
27
+ 'use-effect-no-deps/use-effect-no-deps': 'warn'
28
+ }
29
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ /*
9
+ * Copyright (c) 2023, Salesforce, Inc.
10
+ * All rights reserved.
11
+ * SPDX-License-Identifier: BSD-3-Clause
12
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
13
+ */
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
16
+ const base = require('./typescript');
17
+
18
+ /**
19
+ * Override configuration for TypeScript files. Adds rules that require type checking, but allows
20
+ * the use of implicit or explicit `any`.
21
+ */
22
+ module.exports = _objectSpread(_objectSpread({}, base), {}, {
23
+ rules: _objectSpread(_objectSpread({}, base.rules), {}, {
24
+ '@typescript-eslint/no-explicit-any': 'off',
25
+ '@typescript-eslint/no-unsafe-argument': 'off',
26
+ '@typescript-eslint/no-unsafe-assignment': 'off',
27
+ '@typescript-eslint/no-unsafe-call': 'off',
28
+ '@typescript-eslint/no-unsafe-member-access': 'off',
29
+ '@typescript-eslint/no-unsafe-return': 'off'
30
+ })
31
+ });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ /*
4
+ * Copyright (c) 2023, Salesforce, Inc.
5
+ * All rights reserved.
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+
10
+ /** Override configuration for TypeScript files. Adds rules that require type checking. */
11
+ module.exports = {
12
+ files: ['**/*.ts', '**/*.tsx'],
13
+ extends: ['plugin:@typescript-eslint/recommended-requiring-type-checking'],
14
+ parserOptions: {
15
+ project: true
16
+ }
17
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ /*
4
+ * Copyright (c) 2023, Salesforce, Inc.
5
+ * All rights reserved.
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+
10
+ /**
11
+ * Recommended configuration for PWA Kit projects.
12
+ * Contains rules for JavaScript, TypeScript, React, and Jest.
13
+ */
14
+ module.exports = {
15
+ extends: [require.resolve('./partials/base'),
16
+ // React rules live in `extends`, rather than `overrides`, because any file can have React code.
17
+ require.resolve('./partials/react')],
18
+ // TypeScript and Jest rules only apply to specific file paths, so they are overrides.
19
+ overrides: [require('./partials/typescript-permit-any'), require('./partials/jest')]
20
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ /*
4
+ * Copyright (c) 2023, Salesforce, Inc.
5
+ * All rights reserved.
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+
10
+ /**
11
+ * Configuration for PWA Kit projects. Extends the recommended configuration with stricter rules
12
+ * that restrict usage of the `any` type.
13
+ */
14
+ module.exports = {
15
+ extends: [require.resolve('./partials/base'),
16
+ // React rules live in `extends`, rather than `overrides`, because any file can have React code.
17
+ require.resolve('./partials/react')],
18
+ // TypeScript and Jest rules only apply to specific file paths, so they are overrides.
19
+ overrides: [require('./partials/typescript'), require('./partials/jest')]
20
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ /*
4
+ * Copyright (c) 2021, salesforce.com, inc.
5
+ * All rights reserved.
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+
10
+ // Allows us to use a single babel config at the root to be shared across
11
+ // packages. See: https://babeljs.io/docs/en/config-files#jest
12
+
13
+ /* eslint-env node */
14
+
15
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
16
+ const babelJest = require('babel-jest');
17
+ module.exports = babelJest.createTransformer({
18
+ rootMode: 'upward'
19
+ });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _path = _interopRequireDefault(require("path"));
4
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ /*
6
+ * Copyright (c) 2021, salesforce.com, inc.
7
+ * All rights reserved.
8
+ * SPDX-License-Identifier: BSD-3-Clause
9
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
10
+ */
11
+
12
+ module.exports = {
13
+ testURL: 'http://localhost/',
14
+ verbose: true,
15
+ collectCoverage: true,
16
+ testEnvironment: 'jsdom',
17
+ testPathIgnorePatterns: ['node_modules', 'build'],
18
+ moduleNameMapper: {
19
+ '\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': _path.default.join(__dirname, 'mocks', 'fileMock.js'),
20
+ '\\.(svg)$': _path.default.join(__dirname, 'mocks', 'svgMock.js'),
21
+ '\\.(css|less)$': _path.default.join(__dirname, 'mocks', 'styleMock.js')
22
+ },
23
+ globals: {
24
+ DEBUG: true,
25
+ NODE_ENV: 'test',
26
+ Progressive: {
27
+ buildOrigin: '/mobify/bundle/development/'
28
+ }
29
+ },
30
+ transform: {
31
+ '^.+\\.(js|jsx|ts|tsx)$': _path.default.join(__dirname, 'jest-babel-transform.js')
32
+ }
33
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ /*
4
+ * Copyright (c) 2021, salesforce.com, inc.
5
+ * All rights reserved.
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+ module.exports = 'test-file-stub';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ /*
4
+ * Copyright (c) 2021, salesforce.com, inc.
5
+ * All rights reserved.
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+ module.exports = {};
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ /*
4
+ * Copyright (c) 2021, salesforce.com, inc.
5
+ * All rights reserved.
6
+ * SPDX-License-Identifier: BSD-3-Clause
7
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
+ */
9
+ module.exports = {
10
+ viewBox: '0 0 24 24'
11
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SSR = exports.SERVER = exports.REQUEST_PROCESSOR = exports.CLIENT_OPTIONAL = exports.CLIENT = void 0;
7
+ /*
8
+ * Copyright (c) 2022, salesforce.com, inc.
9
+ * All rights reserved.
10
+ * SPDX-License-Identifier: BSD-3-Clause
11
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
12
+ */
13
+
14
+ // Must be named "client" and "server". See - https://www.npmjs.com/package/webpack-hot-server-middleware#usage
15
+ const CLIENT = 'client';
16
+ exports.CLIENT = CLIENT;
17
+ const SERVER = 'server';
18
+ exports.SERVER = SERVER;
19
+ const CLIENT_OPTIONAL = 'client-optional';
20
+ exports.CLIENT_OPTIONAL = CLIENT_OPTIONAL;
21
+ const SSR = 'ssr';
22
+ exports.SSR = SSR;
23
+ const REQUEST_PROCESSOR = 'request-processor';
24
+ exports.REQUEST_PROCESSOR = REQUEST_PROCESSOR;
@@ -0,0 +1,425 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EXT_OVERRIDES_DIR_NO_SLASH = exports.EXT_OVERRIDES_DIR = exports.EXT_EXTENDS = exports.EXT_EXTENDABLE = exports.DEPS_TO_DEDUPE = void 0;
7
+ var _path = _interopRequireWildcard(require("path"));
8
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
+ var _webpack = _interopRequireDefault(require("webpack"));
10
+ var _webpackNotifier = _interopRequireDefault(require("webpack-notifier"));
11
+ var _copyWebpackPlugin = _interopRequireDefault(require("copy-webpack-plugin"));
12
+ var _webpackBundleAnalyzer = require("webpack-bundle-analyzer");
13
+ var _webpackPlugin = _interopRequireDefault(require("@loadable/webpack-plugin"));
14
+ var _reactRefreshWebpackPlugin = _interopRequireDefault(require("@pmmmwh/react-refresh-webpack-plugin"));
15
+ var _speedMeasureWebpackPlugin = _interopRequireDefault(require("speed-measure-webpack-plugin"));
16
+ var _plugins = require("./plugins");
17
+ var _configNames = require("./config-names");
18
+ var _overridesPlugin = _interopRequireDefault(require("./overrides-plugin"));
19
+ var _pkg$ccExtensibility, _pkg$ccExtensibility2, _pkg$ccExtensibility3, _pkg$ccExtensibility4, _pkg$ccExtensibility5, _pkg$ccExtensibility6, _pkg$ccExtensibility7;
20
+ /*
21
+ * Copyright (c) 2021, salesforce.com, inc.
22
+ * All rights reserved.
23
+ * SPDX-License-Identifier: BSD-3-Clause
24
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
25
+ */
26
+ /* eslint-env node */
27
+ // For more information on these settings, see https://webpack.js.org/configuration
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
30
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
32
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
33
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
34
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
36
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
37
+ const projectDir = process.cwd();
38
+ const pkg = _fsExtra.default.readJsonSync((0, _path.resolve)(projectDir, 'package.json'));
39
+ const buildDir = process.env.PWA_KIT_BUILD_DIR ? (0, _path.resolve)(process.env.PWA_KIT_BUILD_DIR) : (0, _path.resolve)(projectDir, 'build');
40
+ const production = 'production';
41
+ const development = 'development';
42
+ const analyzeBundle = process.env.MOBIFY_ANALYZE === 'true';
43
+ const mode = process.env.NODE_ENV === production ? production : development;
44
+ const DEBUG = mode !== production && process.env.DEBUG === 'true';
45
+ const CI = process.env.CI;
46
+ const disableHMR = process.env.HMR === 'false';
47
+ if ([production, development].indexOf(mode) < 0) {
48
+ throw new Error(`Invalid mode "${mode}"`);
49
+ }
50
+
51
+ // for API convenience, add the leading slash if missing
52
+ const EXT_OVERRIDES_DIR = typeof (pkg === null || pkg === void 0 ? void 0 : (_pkg$ccExtensibility = pkg.ccExtensibility) === null || _pkg$ccExtensibility === void 0 ? void 0 : _pkg$ccExtensibility.overridesDir) === 'string' && !(pkg !== null && pkg !== void 0 && (_pkg$ccExtensibility2 = pkg.ccExtensibility) !== null && _pkg$ccExtensibility2 !== void 0 && (_pkg$ccExtensibility3 = _pkg$ccExtensibility2.overridesDir) !== null && _pkg$ccExtensibility3 !== void 0 && _pkg$ccExtensibility3.startsWith(_path.default.sep)) ? _path.default.sep + (pkg === null || pkg === void 0 ? void 0 : (_pkg$ccExtensibility4 = pkg.ccExtensibility) === null || _pkg$ccExtensibility4 === void 0 ? void 0 : _pkg$ccExtensibility4.overridesDir) : (pkg === null || pkg === void 0 ? void 0 : (_pkg$ccExtensibility5 = pkg.ccExtensibility) === null || _pkg$ccExtensibility5 === void 0 ? void 0 : _pkg$ccExtensibility5.overridesDir) ?? '';
53
+ exports.EXT_OVERRIDES_DIR = EXT_OVERRIDES_DIR;
54
+ const EXT_OVERRIDES_DIR_NO_SLASH = EXT_OVERRIDES_DIR === null || EXT_OVERRIDES_DIR === void 0 ? void 0 : EXT_OVERRIDES_DIR.replace((0, _plugins.makeRegExp)(`^\\${_path.default.sep}`), '');
55
+ exports.EXT_OVERRIDES_DIR_NO_SLASH = EXT_OVERRIDES_DIR_NO_SLASH;
56
+ const EXT_EXTENDS = pkg === null || pkg === void 0 ? void 0 : (_pkg$ccExtensibility6 = pkg.ccExtensibility) === null || _pkg$ccExtensibility6 === void 0 ? void 0 : _pkg$ccExtensibility6.extends;
57
+ exports.EXT_EXTENDS = EXT_EXTENDS;
58
+ const EXT_EXTENDABLE = pkg === null || pkg === void 0 ? void 0 : (_pkg$ccExtensibility7 = pkg.ccExtensibility) === null || _pkg$ccExtensibility7 === void 0 ? void 0 : _pkg$ccExtensibility7.extendable;
59
+
60
+ // TODO: can these be handled in package.json as peerDependencies?
61
+ // https://salesforce-internal.slack.com/archives/C0DKK1FJS/p1672939909212589
62
+
63
+ // due to to how the sdks work and the potential of these npm deps coming
64
+ // from multiple places, we need to force them to one place where they're found
65
+ exports.EXT_EXTENDABLE = EXT_EXTENDABLE;
66
+ const DEPS_TO_DEDUPE = ['babel-runtime', '@tanstack/react-query', '@loadable/component', '@loadable/server', '@loadable/webpack-plugin', 'svg-sprite-loader', 'react', 'react-router-dom', 'react-dom', 'react-helmet', 'webpack-hot-middleware', 'react-intl', '@chakra-ui/icons', '@chakra-ui/react', '@chakra-ui/skip-nav', '@emotion/react'];
67
+ exports.DEPS_TO_DEDUPE = DEPS_TO_DEDUPE;
68
+ if (EXT_EXTENDABLE && EXT_EXTENDS) {
69
+ const extendsAsArr = Array.isArray(EXT_EXTENDS) ? EXT_EXTENDS : [EXT_EXTENDS];
70
+ const conflicts = extendsAsArr.filter(x => EXT_EXTENDABLE === null || EXT_EXTENDABLE === void 0 ? void 0 : EXT_EXTENDABLE.includes(x));
71
+ if (conflicts !== null && conflicts !== void 0 && conflicts.length) {
72
+ throw new Error(`Dependencies in 'extendable' and 'extends' cannot overlap, fix these: ${conflicts.join(', ')}"`);
73
+ }
74
+ }
75
+ const getBundleAnalyzerPlugin = (name = 'report', pluginOptions) => new _webpackBundleAnalyzer.BundleAnalyzerPlugin(_objectSpread({
76
+ analyzerMode: 'static',
77
+ defaultSizes: 'gzip',
78
+ openAnalyzer: CI !== 'true',
79
+ generateStatsFile: true,
80
+ reportFilename: `${name}.html`,
81
+ reportTitle: `${name} bundle analysis result`,
82
+ statsFilename: `${name}-analyzer-stats.json`
83
+ }, pluginOptions));
84
+ const entryPointExists = segments => {
85
+ for (let ext of ['.js', '.jsx', '.ts', '.tsx']) {
86
+ const primary = (0, _path.resolve)(projectDir, ...segments) + ext;
87
+ const override = EXT_OVERRIDES_DIR ? (0, _path.resolve)(projectDir, EXT_OVERRIDES_DIR_NO_SLASH, ...segments) + ext : null;
88
+ if (_fsExtra.default.existsSync(primary) || override && _fsExtra.default.existsSync(override)) {
89
+ return true;
90
+ }
91
+ }
92
+ return false;
93
+ };
94
+ const getAppEntryPoint = () => {
95
+ return EXT_OVERRIDES_DIR + '/app/main';
96
+ };
97
+ const findDepInStack = pkg => {
98
+ // Look for the SDK node_modules in two places because in CI,
99
+ // pwa-kit-dev is published under a 'dist' directory, which
100
+ // changes this file's location relative to the package root.
101
+ const candidates = [(0, _path.resolve)(projectDir, 'node_modules', pkg), (0, _path.resolve)(__dirname, '..', '..', 'node_modules', pkg), (0, _path.resolve)(__dirname, '..', '..', '..', 'node_modules', pkg)];
102
+ let candidate;
103
+ for (candidate of candidates) {
104
+ if (_fsExtra.default.existsSync(candidate)) {
105
+ return candidate;
106
+ }
107
+ }
108
+ return candidate;
109
+ };
110
+ const baseConfig = target => {
111
+ if (!['web', 'node'].includes(target)) {
112
+ throw Error(`The value "${target}" is not a supported webpack target`);
113
+ }
114
+ class Builder {
115
+ constructor() {
116
+ this.config = _objectSpread(_objectSpread({
117
+ watchOptions: {
118
+ aggregateTimeout: 1000
119
+ },
120
+ target,
121
+ mode
122
+ }, target === 'node' ? {
123
+ ignoreWarnings: [
124
+ // These can be ignored fairly safely for node targets, where
125
+ // bundle size is not super critical. Express generates this warning,
126
+ // because it uses dynamic require() calls, which cause Webpack to
127
+ // bundle the whole library.
128
+ /Critical dependency: the request of a dependency is an expression/]
129
+ } : {}), {}, {
130
+ infrastructureLogging: {
131
+ level: 'error'
132
+ },
133
+ stats: {
134
+ all: false,
135
+ modules: false,
136
+ errors: true,
137
+ warnings: true,
138
+ moduleTrace: true,
139
+ errorDetails: true,
140
+ colors: true,
141
+ assets: false,
142
+ excludeAssets: [/.*img\/.*/, /.*svg\/.*/, /.*json\/.*/, /.*static\/.*/]
143
+ },
144
+ optimization: {
145
+ minimize: mode === production
146
+ },
147
+ output: {
148
+ publicPath: '',
149
+ path: buildDir
150
+ },
151
+ resolve: _objectSpread(_objectSpread({}, EXT_EXTENDS && EXT_OVERRIDES_DIR ? {
152
+ plugins: [new _overridesPlugin.default({
153
+ extends: [EXT_EXTENDS],
154
+ overridesDir: EXT_OVERRIDES_DIR,
155
+ projectDir: process.cwd()
156
+ })]
157
+ } : {}), {}, {
158
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
159
+ alias: _objectSpread(_objectSpread(_objectSpread({}, _extends(...DEPS_TO_DEDUPE.map(dep => ({
160
+ [dep]: findDepInStack(dep)
161
+ })))), EXT_OVERRIDES_DIR && EXT_EXTENDS ? _extends(
162
+ // NOTE: when an array of `extends` dirs are accepted, don't coerce here
163
+ ...[EXT_EXTENDS].map(extendTarget => ({
164
+ [extendTarget]: _path.default.resolve(projectDir, `node_modules${_path.default.sep}${extendTarget}`)
165
+ }))) : {}), EXT_EXTENDABLE ? _extends(...[EXT_EXTENDABLE].map(item => ({
166
+ [item]: _path.default.resolve(projectDir)
167
+ }))) : {})
168
+ }, target === 'web' ? {
169
+ fallback: {
170
+ crypto: false
171
+ }
172
+ } : {}),
173
+ plugins: [new _webpack.default.DefinePlugin({
174
+ DEBUG,
175
+ NODE_ENV: `'${process.env.NODE_ENV}'`,
176
+ WEBPACK_TARGET: `'${target}'`,
177
+ ['global.GENTLY']: false
178
+ }), mode === development && new _webpack.default.NoEmitOnErrorsPlugin(), (0, _plugins.sdkReplacementPlugin)(),
179
+ // Don't chunk if it's a node target – faster Lambda startup.
180
+ target === 'node' && new _webpack.default.optimize.LimitChunkCountPlugin({
181
+ maxChunks: 1
182
+ })].filter(Boolean),
183
+ module: {
184
+ rules: [ruleForBabelLoader(), target === 'node' && {
185
+ test: /\.svg$/,
186
+ loader: findDepInStack('svg-sprite-loader')
187
+ }, target === 'web' && {
188
+ test: /\.svg$/,
189
+ loader: findDepInStack('ignore-loader')
190
+ }, {
191
+ test: /\.html$/,
192
+ exclude: /node_modules/,
193
+ use: {
194
+ loader: findDepInStack('html-loader')
195
+ }
196
+ }].filter(Boolean)
197
+ }
198
+ });
199
+ }
200
+ extend(callback) {
201
+ this.config = callback(this.config);
202
+ return this;
203
+ }
204
+ build() {
205
+ // Clean up temporary properties, to be compatible with the config schema
206
+ this.config.module.rules.filter(rule => rule.id).forEach(rule => delete rule.id);
207
+ return this.config;
208
+ }
209
+ }
210
+ return new Builder();
211
+ };
212
+ const withChunking = config => {
213
+ return _objectSpread(_objectSpread({}, config), {}, {
214
+ output: _objectSpread(_objectSpread({}, config.output), {}, {
215
+ filename: '[name].js',
216
+ chunkFilename: '[name].js' // Support chunking with @loadable/components
217
+ }),
218
+
219
+ optimization: {
220
+ minimize: mode === production,
221
+ splitChunks: {
222
+ cacheGroups: {
223
+ vendor: {
224
+ // Two scenarios that we'd like to chunk vendor.js:
225
+ // 1. The package is in node_modules
226
+ // 2. The package is one of the monorepo packages.
227
+ // This is for local development to ensure the bundle
228
+ // composition is the same as a production build
229
+ // 3. If extending another template, don't include the
230
+ // baseline route files in vendor.js
231
+ test: module => {
232
+ var _module$context, _module$context2, _module$context2$matc;
233
+ if (EXT_EXTENDS && EXT_OVERRIDES_DIR && module !== null && module !== void 0 && (_module$context = module.context) !== null && _module$context !== void 0 && _module$context.includes(`/${EXT_EXTENDS}/`)) {
234
+ return false;
235
+ }
236
+ return module === null || module === void 0 ? void 0 : (_module$context2 = module.context) === null || _module$context2 === void 0 ? void 0 : (_module$context2$matc = _module$context2.match) === null || _module$context2$matc === void 0 ? void 0 : _module$context2$matc.call(_module$context2, /(node_modules)|(packages\/.*\/dist)/);
237
+ },
238
+ name: 'vendor',
239
+ chunks: 'all'
240
+ },
241
+ translations: {
242
+ priority: 10,
243
+ test: module => {
244
+ var _module$context3, _module$context3$matc;
245
+ return module === null || module === void 0 ? void 0 : (_module$context3 = module.context) === null || _module$context3 === void 0 ? void 0 : (_module$context3$matc = _module$context3.match) === null || _module$context3$matc === void 0 ? void 0 : _module$context3$matc.call(_module$context3, /app\/translations\/compiled/);
246
+ },
247
+ name: 'translations',
248
+ chunks: 'all'
249
+ }
250
+ }
251
+ }
252
+ }
253
+ });
254
+ };
255
+ const ruleForBabelLoader = babelPlugins => {
256
+ return _objectSpread(_objectSpread({
257
+ id: 'babel-loader',
258
+ test: /(\.js(x?)|\.ts(x?))$/
259
+ }, EXT_OVERRIDES_DIR && EXT_EXTENDS ?
260
+ // TODO: handle for array here when that's supported
261
+ {
262
+ exclude: (0, _plugins.makeRegExp)(`/node_modules(?!/${EXT_EXTENDS})`)
263
+ } : {
264
+ exclude: /node_modules/
265
+ }), {}, {
266
+ use: [{
267
+ loader: findDepInStack('babel-loader'),
268
+ options: _objectSpread({
269
+ rootMode: 'upward',
270
+ cacheDirectory: true
271
+ }, babelPlugins ? {
272
+ plugins: babelPlugins
273
+ } : {})
274
+ }]
275
+ });
276
+ };
277
+ const findAndReplace = (array = [], findFn = () => {}, replacement) => {
278
+ const clone = array.slice(0);
279
+ const index = clone.findIndex(findFn);
280
+ if (index === -1) {
281
+ return array;
282
+ }
283
+ clone.splice(index, 1, replacement);
284
+ return clone;
285
+ };
286
+ const enableReactRefresh = config => {
287
+ if (mode !== development || disableHMR) {
288
+ return config;
289
+ }
290
+ const newRule = ruleForBabelLoader([require.resolve('react-refresh/babel')]);
291
+ const rules = findAndReplace(config.module.rules, rule => rule.id === 'babel-loader', newRule);
292
+ return _objectSpread(_objectSpread({}, config), {}, {
293
+ module: _objectSpread(_objectSpread({}, config.module), {}, {
294
+ rules
295
+ }),
296
+ entry: _objectSpread(_objectSpread({}, config.entry), {}, {
297
+ main: ['webpack-hot-middleware/client?path=/__mrt/hmr', getAppEntryPoint()]
298
+ }),
299
+ plugins: [...config.plugins, new _webpack.default.HotModuleReplacementPlugin(), new _reactRefreshWebpackPlugin.default({
300
+ overlay: false
301
+ })],
302
+ output: _objectSpread(_objectSpread({}, config.output), {}, {
303
+ // Setting this so that *.hot-update.json requests are resolving
304
+ publicPath: '/mobify/bundle/development/'
305
+ })
306
+ });
307
+ };
308
+ const client = entryPointExists(['app', 'main']) && baseConfig('web').extend(withChunking).extend(config => {
309
+ return _objectSpread(_objectSpread({}, config), {}, {
310
+ // Must be named "client". See - https://www.npmjs.com/package/webpack-hot-server-middleware#usage
311
+ name: _configNames.CLIENT,
312
+ // use source map to make debugging easier
313
+ devtool: mode === development ? 'source-map' : false,
314
+ entry: {
315
+ main: getAppEntryPoint()
316
+ },
317
+ plugins: [...config.plugins, new _webpackPlugin.default({
318
+ writeToDisk: true
319
+ }), analyzeBundle && getBundleAnalyzerPlugin(_configNames.CLIENT)].filter(Boolean),
320
+ // Hide the performance hints, since we already have a similar `bundlesize` check in `template-retail-react-app` package
321
+ performance: {
322
+ hints: false
323
+ }
324
+ });
325
+ }).extend(enableReactRefresh).build();
326
+ const optional = (name, path) => {
327
+ return _fsExtra.default.existsSync(path) ? {
328
+ [name]: path
329
+ } : {};
330
+ };
331
+ const clientOptional = baseConfig('web').extend(config => {
332
+ return _objectSpread(_objectSpread({}, config), {}, {
333
+ name: _configNames.CLIENT_OPTIONAL,
334
+ entry: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, optional('loader', `.${EXT_OVERRIDES_DIR}/app/loader.js`)), optional('worker', `./worker/main.js`)), optional('core-polyfill', (0, _path.resolve)(projectDir, 'node_modules', 'core-js'))), optional('fetch-polyfill', (0, _path.resolve)(projectDir, 'node_modules', 'whatwg-fetch'))),
335
+ // use source map to make debugging easier
336
+ devtool: mode === development ? 'source-map' : false,
337
+ plugins: [...config.plugins, analyzeBundle && getBundleAnalyzerPlugin(_configNames.CLIENT_OPTIONAL)].filter(Boolean)
338
+ });
339
+ }).build();
340
+ const renderer = _fsExtra.default.existsSync((0, _path.resolve)(projectDir, 'node_modules', '@salesforce', 'pwa-kit-react-sdk')) && baseConfig('node').extend(config => {
341
+ return _objectSpread(_objectSpread({}, config), {}, {
342
+ // Must be named "server". See - https://www.npmjs.com/package/webpack-hot-server-middleware#usage
343
+ name: _configNames.SERVER,
344
+ entry: '@salesforce/pwa-kit-react-sdk/ssr/server/react-rendering.js',
345
+ // use eval-source-map for server-side debugging
346
+ devtool: mode === development ? 'eval-source-map' : false,
347
+ output: {
348
+ path: buildDir,
349
+ // We want to split the build on local development to reduce memory usage.
350
+ // It is required to have a single entry point for the remote server.
351
+ // See pwa-kit-runtime/ssr/server/build-remote-server.js render method.
352
+ filename: mode === development ? '[name]-server.js' : 'server-renderer.js',
353
+ libraryTarget: 'commonjs2'
354
+ },
355
+ plugins: [...config.plugins,
356
+ // This must only appear on one config – this one is the only mandatory one.
357
+ new _copyWebpackPlugin.default({
358
+ patterns: [{
359
+ from: `${EXT_OVERRIDES_DIR ? EXT_OVERRIDES_DIR_NO_SLASH + '/' : ''}app/static`,
360
+ to: 'static/'
361
+ }]
362
+ }),
363
+ // Keep this on the slowest-to-build item - the server-side bundle.
364
+ new _webpackNotifier.default({
365
+ title: `PWA Kit Project: ${pkg.name}`,
366
+ excludeWarnings: true,
367
+ skipFirstNotification: true
368
+ }),
369
+ // Must only appear on one config – this one is the only mandatory one.
370
+ new _copyWebpackPlugin.default({
371
+ patterns: [{
372
+ from: `${EXT_OVERRIDES_DIR ? EXT_OVERRIDES_DIR_NO_SLASH + '/' : ''}app/static`,
373
+ to: 'static/',
374
+ noErrorOnMissing: true
375
+ }]
376
+ }), analyzeBundle && getBundleAnalyzerPlugin('server-renderer')].filter(Boolean)
377
+ });
378
+ }).build();
379
+ const ssr = (() => {
380
+ // Only compile the ssr file when we're building for prod.
381
+ if (mode === production) {
382
+ return baseConfig('node').extend(config => {
383
+ return _objectSpread(_objectSpread({}, config), {}, {
384
+ // Must *not* be named "server". See - https://www.npmjs.com/package/webpack-hot-server-middleware#usage
385
+ name: _configNames.SSR,
386
+ entry: `.${EXT_OVERRIDES_DIR}/app/ssr.js`,
387
+ output: {
388
+ path: buildDir,
389
+ filename: 'ssr.js',
390
+ libraryTarget: 'commonjs2'
391
+ },
392
+ plugins: [...config.plugins,
393
+ // This must only appear on one config – this one is the only mandatory one.
394
+ new _copyWebpackPlugin.default({
395
+ patterns: [{
396
+ from: `${EXT_OVERRIDES_DIR ? EXT_OVERRIDES_DIR_NO_SLASH + '/' : ''}app/static`,
397
+ to: 'static/'
398
+ }]
399
+ }), analyzeBundle && getBundleAnalyzerPlugin(_configNames.SSR)].filter(Boolean)
400
+ });
401
+ }).build();
402
+ } else {
403
+ return undefined;
404
+ }
405
+ })();
406
+ const requestProcessor = entryPointExists(['app', 'request-processor']) && baseConfig('node').extend(config => {
407
+ return _objectSpread(_objectSpread({}, config), {}, {
408
+ name: _configNames.REQUEST_PROCESSOR,
409
+ // entry: './app/request-processor.js',
410
+ entry: `.${EXT_OVERRIDES_DIR}/app/request-processor.js`,
411
+ output: {
412
+ path: buildDir,
413
+ filename: 'request-processor.js',
414
+ libraryTarget: 'commonjs2'
415
+ },
416
+ // use eval-source-map for server-side debugging
417
+ devtool: mode === development ? 'eval-source-map' : false,
418
+ plugins: [...config.plugins, analyzeBundle && getBundleAnalyzerPlugin(_configNames.REQUEST_PROCESSOR)].filter(Boolean)
419
+ });
420
+ }).build();
421
+ module.exports = [client, ssr, renderer, clientOptional, requestProcessor].filter(Boolean).map(config => {
422
+ return new _speedMeasureWebpackPlugin.default({
423
+ disable: !process.env.MEASURE
424
+ }).wrap(config);
425
+ });