@pega/custom-dx-components 0.23.36 → 0.23.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "0.23.36",
3
+ "version": "0.23.38",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/constants.js CHANGED
@@ -4,6 +4,7 @@ export const PACKAGE_JSON_FILENAME = 'package.json';
4
4
  export const BUILD_CONFIG_JSON_FILENAME = 'build.config.json';
5
5
  export const WEBPACK_CONFIG_JS_FILENAME = 'webpack.config.js';
6
6
  export const WEBPACK_PATHS_JS_FILENAME = 'paths.js';
7
+ export const USE_PROMOTED_WEB_PACK = 'usePromotedWebPack';
7
8
  export const COMPONENTS_DIRECTORY_PATH = 'components-directory-path';
8
9
  export const COMPONENTS_PATH = 'component';
9
10
  export const TOKEN_PATH = 'node_modules/@pega/custom-dx-components/.access_token';
@@ -3,12 +3,15 @@ import fs from 'fs-extra';
3
3
  import webpack from 'webpack';
4
4
  import FileSizeReporter from 'react-dev-utils/FileSizeReporter.js';
5
5
  import printBuildError from 'react-dev-utils/printBuildError.js';
6
+ import { getUseWebPackPromotion} from '../../../util.js';
6
7
 
7
8
 
9
+ const usePromoted = await getUseWebPackPromotion();
8
10
  // used by promote and revert webPack commands, do not change
9
- import configFactory from './webpack.config.js';
10
- // import configFactory from '../../../../../../../webpack.config.js';
11
- // do not change
11
+ const configFactory = (
12
+ await import(`${usePromoted ? `../../../../../../../webpack.config.js` : `./webpack.config.js`}`)
13
+ ).default
14
+
12
15
 
13
16
  import paths from './paths.js';
14
17
 
@@ -28,11 +28,11 @@
28
28
  "lint:styles": "stylelint \"./**/*.@(js|jsx|ts|tsx)\"",
29
29
  "lint:format": "prettier -c .",
30
30
  "lint:spelling": "cspell --no-progress **/*",
31
- "test": "echo 'Running functional and unit tests will DELETE existing local components, proceed (y/n)?' && read proceed && if test \"$proceed\" = \"y\"; then npm run test:full; fi ",
32
- "test:full": "npm run test:functional && npm run test:unit",
33
- "test:functional": "npm run test:functional:local --prefix node_modules/@pega/custom-dx-components",
34
31
  "test-coverage": "node --input-type=module --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand node_modules/@pega/custom-dx-component --ci --testResultsProcessor='jest-junit' --coverage",
35
- "test:unit": "npm run test:unit:local --prefix node_modules/@pega/custom-dx-components"
32
+ "_internal-test": "echo 'Running functional and unit tests will DELETE existing local components, proceed (y/n)?' && read proceed && if test \"$proceed\" = \"y\"; then npm run internal-test-full; fi ",
33
+ "_internal-test-full": "npm run _internal-test-functional && npm run _internal-test-unit",
34
+ "_internal-test-functional": "npm run test:functional:local --prefix node_modules/@pega/custom-dx-components",
35
+ "_internal-test-unit": "npm run test:unit:local --prefix node_modules/@pega/custom-dx-components"
36
36
  },
37
37
  "scriptsComments": {
38
38
  "build": "tsc -b tsconfig.build.json",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@pega/configs": "^0.6.0",
72
- "@pega/custom-dx-components": "0.23.36",
72
+ "@pega/custom-dx-components": "0.23.38",
73
73
  "@pega/pcore-pconnect-typedefs": "~2.1.1",
74
74
  "@storybook/addon-actions": "^7.6.7",
75
75
  "@storybook/addon-essentials": "^7.6.7",
@@ -27,6 +27,7 @@
27
27
  "questions_askOnce": "server,authService",
28
28
  "questions_askedOnce": ""
29
29
  },
30
+ "usePromotedWebPack": false,
30
31
  "component": {
31
32
  "library": "Extensions",
32
33
  "type": "",
@@ -9,7 +9,8 @@ import inquirer from 'inquirer';
9
9
  import {
10
10
  convertIntoPascalCase,
11
11
  checkPathAccess,
12
- showVersion
12
+ showVersion,
13
+ updateUseWebPackPromotion
13
14
  } from '../../util.js';
14
15
 
15
16
  import {
@@ -91,36 +92,12 @@ export const copyWebPack = async () => {
91
92
 
92
93
  }
93
94
 
94
- export const updateBuilder = async () => {
95
95
 
96
- const builderIndexDir = fileURLToPath(new URL(BUILDER_INDEX_FILE_PATH, import.meta.url));
97
-
98
- let indexFileJS = fs.readFileSync(builderIndexDir, { encoding: 'utf8' });
99
-
100
- if (indexFileJS.length > 0) {
101
- // comment out original webpack reference
102
-
103
- // if not commented out, comment out
104
- if (indexFileJS.indexOf("// import configFactory from './webpack.config.js';") < 0) {
105
- indexFileJS = indexFileJS.replaceAll("import configFactory from './webpack.config.js';", "// import configFactory from './webpack.config.js';");
106
- }
107
-
108
- // uncomment out promoted webpack reference
109
- indexFileJS = indexFileJS.replaceAll("// import configFactory from '../../../../../../../webpack.config.js';", "import configFactory from '../../../../../../../webpack.config.js';");
110
-
111
- fs.writeFileSync(builderIndexDir, indexFileJS, { encoding: 'utf8' });
112
-
113
- console.log(chalk.bold.green(`Bundler now using ${redirectFile}.`));
114
- console.log(chalk.bold.green(`Utilize this file for webpack modifications.`));
115
- }
116
-
117
-
118
- }
119
96
 
120
97
  export default async options => {
121
98
  showVersion();
122
99
 
123
100
  await copyWebPack();
124
- await updateBuilder();
101
+ await updateUseWebPackPromotion(true);
125
102
 
126
103
  };
@@ -17,7 +17,7 @@ import {
17
17
  export function getCustomTasks(componentKey, sourceMap, devBuild, content, options) {
18
18
  const sDevBuild = devBuild ? '(dev build)' : '';
19
19
  // eslint-disable no-unneeded-ternary,no-nested-ternary
20
- const doFetch = options.params.length >= 7 ? options.params[6] !== 'noFetch' : true;
20
+ const doFetch = options.params.length >= 7 ? (options.params[6] === 'noFetch' ? false : true) : true;
21
21
  return new Listr(
22
22
  [
23
23
  {
@@ -8,7 +8,8 @@ import { up } from 'inquirer/lib/utils/readline.js';
8
8
 
9
9
  import {
10
10
  convertIntoPascalCase,
11
- showVersion
11
+ showVersion,
12
+ updateUseWebPackPromotion
12
13
  } from '../../util.js';
13
14
  import {
14
15
  WEBPACK_CONFIG_JS_FILENAME,
@@ -37,33 +38,12 @@ export const renamePromotedWebPack = async () => {
37
38
 
38
39
  }
39
40
 
40
- export const revertBuilder = async () => {
41
41
 
42
- const builderIndexDir = fileURLToPath(new URL(BUILDER_INDEX_FILE_PATH, import.meta.url));
43
-
44
- let indexFileJS = fs.readFileSync(builderIndexDir, { encoding: 'utf8' });
45
-
46
- if (indexFileJS.length > 0) {
47
- // uncomment out original webpack reference
48
- indexFileJS = indexFileJS.replaceAll("// import configFactory from './webpack.config.js';", "import configFactory from './webpack.config.js';");
49
-
50
- // comment out promoted webpack reference
51
- if (indexFileJS.indexOf("// import configFactory from '../../../../../../../webpack.config.js';") < 0) {
52
- indexFileJS = indexFileJS.replaceAll("import configFactory from '../../../../../../../webpack.config.js';", "// import configFactory from '../../../../../../../webpack.config.js';");
53
- }
54
-
55
- fs.writeFileSync(builderIndexDir, indexFileJS, { encoding: 'utf8' });
56
-
57
- console.log(chalk.bold.green(`Bundler reverted to using internal webpack.config.js.`));
58
- }
59
-
60
-
61
- }
62
42
 
63
43
  export default async options => {
64
44
  showVersion();
65
45
 
66
46
  await renamePromotedWebPack();
67
- await revertBuilder();
47
+ await updateUseWebPackPromotion(false);
68
48
 
69
49
  };
package/src/util.js CHANGED
@@ -19,7 +19,8 @@ import {
19
19
  OOTB_COMPONENT_SERVICE_REST_ENDPOINT,
20
20
  DELETE_COMPONENT_SERVICE_REST_ENDPOINT,
21
21
  LP_DELETE_COMPONENT_SERVICE_REST_ENDPOINT,
22
- OOTB_COMPONENTS
22
+ OOTB_COMPONENTS,
23
+ USE_PROMOTED_WEB_PACK
23
24
  } from './constants.js';
24
25
 
25
26
  const access = promisify(fs.access);
@@ -37,6 +38,54 @@ export const checkPathAccess = async (path, options = {}) => {
37
38
  }
38
39
  };
39
40
 
41
+ export const getUseWebPackPromotion = async () => {
42
+ const currentDirectory = process.cwd();
43
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
44
+
45
+ await checkPathAccess(pegaConfigJsonPath);
46
+
47
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
48
+ data = JSON.parse(data);
49
+
50
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
51
+ console.error(
52
+ `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
53
+ );
54
+ process.exit(1);
55
+ }
56
+
57
+ if (data[USE_PROMOTED_WEB_PACK] == null) {
58
+ // value doesn't exist in task config, so add it with default of false
59
+ data[USE_PROMOTED_WEB_PACK] = false;
60
+ await updateUseWebPackPromotion(false);
61
+ }
62
+
63
+ return data[USE_PROMOTED_WEB_PACK];
64
+
65
+ }
66
+
67
+ export const updateUseWebPackPromotion = async ( useValue = false ) => {
68
+ const currentDirectory = process.cwd();
69
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
70
+
71
+ await checkPathAccess(pegaConfigJsonPath);
72
+
73
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
74
+ data = JSON.parse(data);
75
+
76
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
77
+ console.error(
78
+ `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
79
+ );
80
+ process.exit(1);
81
+ }
82
+
83
+ data["usePromotedWebPack"] = useValue;
84
+
85
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(data, null, 4), { encoding: 'utf8' });
86
+
87
+ }
88
+
40
89
  export const deleteLocalComponent = async componentKey => {
41
90
  const currentDirectory = process.cwd();
42
91
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);