@pega/custom-dx-components 26.1.12-alpha.0.4 → 26.1.12-alpha.0.6

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": "26.1.12-alpha.0.4",
3
+ "version": "26.1.12-alpha.0.6",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": {
6
6
  "custom-dx-components": "./bin/index.js"
@@ -37,7 +37,7 @@
37
37
  "@pega/constellation-dx-components-build-utils": "^2.0.18",
38
38
  "@pega/inquirer-fuzzy-path": "^4.0.0",
39
39
  "ajv": "^8.20.0",
40
- "archiver": "^7.0.1",
40
+ "archiver": "^8.0.0",
41
41
  "arg": "^5.0.2",
42
42
  "chalk": "^6.0.1",
43
43
  "compression-webpack-plugin": "^12.0.0",
@@ -57,7 +57,6 @@
57
57
  "postcss": "^8.5.32",
58
58
  "postcss-loader": "8.2.1",
59
59
  "postcss-preset-env": "11.6.2",
60
- "react-dev-utils": "^12.0.1",
61
60
  "resolve-url-loader": "^5.0.0",
62
61
  "sass-loader": "^17.1.0",
63
62
  "terser-webpack-plugin": "5.6.1",
@@ -1,7 +1,8 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
 
4
- import archiver from 'archiver';
4
+ // archiver v8 has no default export; ZipArchive replaces the archiver('zip') factory.
5
+ import { ZipArchive } from 'archiver';
5
6
  import chalk from 'chalk';
6
7
 
7
8
  import { getComponentDirectoryPath, getComponents, getPegaServerConfig, addDebugLog } from '../../util.js';
@@ -35,7 +36,7 @@ export const zipComponent = async (componentKey) => {
35
36
  const configJson = `${srcDirectory}/config.json`;
36
37
  const localizationJson = `${srcDirectory}/localizations.json`;
37
38
 
38
- const archive = archiver('zip', { zlib: { level: 9 } });
39
+ const archive = new ZipArchive({ zlib: { level: 9 } });
39
40
  const zipChunks = [];
40
41
  archive.on('data', (chunk) => zipChunks.push(chunk));
41
42
 
@@ -1,7 +1,8 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
 
4
- import archiver from 'archiver';
4
+ // archiver v8 has no default export; ZipArchive replaces the archiver('zip') factory.
5
+ import { ZipArchive } from 'archiver';
5
6
  import chalk from 'chalk';
6
7
 
7
8
  import { constructCompleteUrl, getComponentDirectoryPath, getComponents, getPegaServerConfig, getFetchAgent, getLibraryBased } from '../../util.js';
@@ -55,7 +56,7 @@ export const zipComponent = async (componentKey) => {
55
56
 
56
57
  const localizationJson = `${srcDirectory}/localizations.json`;
57
58
 
58
- const archive = archiver('zip', { zlib: { level: 9 } });
59
+ const archive = new ZipArchive({ zlib: { level: 9 } });
59
60
  const zipChunks = [];
60
61
  archive.on('data', (chunk) => zipChunks.push(chunk));
61
62
 
@@ -1,7 +1,5 @@
1
1
  import chalk from 'chalk';
2
2
  import webpack from 'webpack';
3
- import FileSizeReporter from 'react-dev-utils/FileSizeReporter.js';
4
- import printBuildError from 'react-dev-utils/printBuildError.js';
5
3
  import { getUseWebPackPromotion, addDebugLog, emptyDirSync } from '../../../util.js';
6
4
 
7
5
  import paths from './paths.js';
@@ -27,22 +25,11 @@ process.on('unhandledRejection', (err) => {
27
25
  // process.exit(1);
28
26
  });
29
27
 
30
- const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild;
31
- const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
32
-
33
- // These sizes are pretty large. We'll warn for bundles exceeding them.
34
- const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
35
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
36
-
37
28
  let compilationErrors = null;
38
29
 
39
30
  // Create the build and print the deployment instructions.
40
- function build(config, previousFileSizes, showStats = true) {
41
- addDebugLog(
42
- 'bundle build',
43
- `config: ${JSON.stringify(config)}, \npreviousFileSizes: ${JSON.stringify(previousFileSizes)}, showStats: ${showStats}`,
44
- '',
45
- );
31
+ function build(config, showStats = true) {
32
+ addDebugLog('bundle build', `config: ${JSON.stringify(config)}, showStats: ${showStats}`, '');
46
33
 
47
34
  if (showStats) {
48
35
  console.log(`Creating a ${Env} build...`);
@@ -108,7 +95,6 @@ function build(config, previousFileSizes, showStats = true) {
108
95
 
109
96
  const resolveArgs = {
110
97
  stats,
111
- previousFileSizes,
112
98
  warnings: messages.warnings,
113
99
  };
114
100
  return resolve(resolveArgs);
@@ -137,16 +123,16 @@ export default async ({ inputFile, outputFile, componentKey, externals, globals,
137
123
  }
138
124
 
139
125
  return new Promise((resolve, reject) => {
140
- measureFileSizesBeforeBuild(paths.appBuild)
141
- .then((previousFileSizes) => {
126
+ Promise.resolve()
127
+ .then(() => {
142
128
  // Remove all content but keep the directory so that
143
129
  // if you're in it, you don't end up in Trash
144
130
  emptyDirSync(paths.appBuild);
145
131
  // Start the webpack build
146
- return build(config, previousFileSizes, showStats);
132
+ return build(config, showStats);
147
133
  })
148
134
  .then(
149
- ({ stats, previousFileSizes, warnings }) => {
135
+ ({ warnings }) => {
150
136
  if (showStats) {
151
137
  if (warnings.length) {
152
138
  // console.log(chalk.yellow('Compiled with warnings.\n'), warnings[0].message);
@@ -157,9 +143,6 @@ export default async ({ inputFile, outputFile, componentKey, externals, globals,
157
143
  } else {
158
144
  console.log(chalk.green('Compiled successfully.\n'));
159
145
  }
160
-
161
- console.log('File sizes after gzip:\n');
162
- printFileSizesAfterBuild(stats, previousFileSizes, paths.appBuild, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
163
146
  }
164
147
 
165
148
  resolve('done emitting');
@@ -169,7 +152,7 @@ export default async ({ inputFile, outputFile, componentKey, externals, globals,
169
152
  const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
170
153
  if (tscCompileOnError) {
171
154
  console.log(chalk.yellow('Compiled with the following type errors (you may want to check these before deploying your app):\n'));
172
- printBuildError(err);
155
+ console.log(err);
173
156
  } else if (compilationErrors != null) {
174
157
  if (compilationErrors.length == undefined) {
175
158
  console.log(chalk.red('Error...'), compilationErrors.message);
@@ -182,7 +165,7 @@ export default async ({ inputFile, outputFile, componentKey, externals, globals,
182
165
  // process.exit(1);
183
166
  } else {
184
167
  console.log(chalk.red('Failed to compile.\n'));
185
- printBuildError(JSON.stringify(err));
168
+ console.log(JSON.stringify(err));
186
169
  }
187
170
  },
188
171
  )
@@ -4,8 +4,6 @@ import webpack from 'webpack';
4
4
  import TerserPlugin from 'terser-webpack-plugin';
5
5
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
6
6
  import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
7
- import getCSSModuleLocalIdent from 'react-dev-utils/getCSSModuleLocalIdent.js';
8
- import ModuleNotFoundPlugin from 'react-dev-utils/ModuleNotFoundPlugin.js';
9
7
  import CompressionPlugin from 'compression-webpack-plugin';
10
8
 
11
9
  import paths from './paths.js';
@@ -200,9 +198,6 @@ export default (
200
198
  use: getStyleLoaders({
201
199
  importLoaders: 1,
202
200
  sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
203
- modules: {
204
- getLocalIdent: getCSSModuleLocalIdent,
205
- },
206
201
  }),
207
202
  },
208
203
  // Opt-in support for SASS (using .scss or .sass extensions).
@@ -232,9 +227,6 @@ export default (
232
227
  {
233
228
  importLoaders: 3,
234
229
  sourceMap: isEnvProduction ? shouldUseSourceMap : isEnvDevelopment,
235
- modules: {
236
- getLocalIdent: getCSSModuleLocalIdent,
237
- },
238
230
  },
239
231
  'sass-loader',
240
232
  ),
@@ -262,9 +254,6 @@ export default (
262
254
  ],
263
255
  },
264
256
  plugins: [
265
- // This gives some necessary context to module not found errors, such as
266
- // the requesting resource.
267
- new ModuleNotFoundPlugin(paths.appPath),
268
257
  // Makes some environment variables available to the JS code, for example:
269
258
  // if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
270
259
  // It is absolutely essential that NODE_ENV is set to production
@@ -4,6 +4,9 @@ import fs from 'fs';
4
4
 
5
5
  import inquirer from 'inquirer';
6
6
  import chalk from 'chalk';
7
+ import { execa } from 'execa';
8
+
9
+ import { SHARED_DIRECTORY } from '../../constants.js';
7
10
 
8
11
  import {
9
12
  convertIntoPascalCase,
@@ -147,6 +150,25 @@ const compileMustacheTemplates = async (
147
150
  });
148
151
  };
149
152
 
153
+ // Formats the generated files with the project's own Prettier so they pass the project's `prettier -c .` check.
154
+ // Skipped when the project has no local Prettier. A formatting failure is reported but does not fail the create.
155
+ const formatGeneratedFiles = async (componentDirectory) => {
156
+ const projectDirectory = process.cwd();
157
+ if (!fs.existsSync(path.join(projectDirectory, 'node_modules', 'prettier'))) return;
158
+
159
+ // The shared folder only exists in library-based mode and holds files generated by this task.
160
+ const directories = [componentDirectory, path.join(path.dirname(componentDirectory), SHARED_DIRECTORY)].filter((directory) =>
161
+ fs.existsSync(directory),
162
+ );
163
+ const result = await execa('npx', ['--no-install', 'prettier', '--write', '--log-level', 'warn', ...directories], {
164
+ cwd: projectDirectory,
165
+ reject: false,
166
+ });
167
+ if (result.exitCode !== 0) {
168
+ console.log(chalk.yellow(`Generated files could not be formatted with Prettier: ${result.stderr || result.stdout}`));
169
+ }
170
+ };
171
+
150
172
  const validateCompile = async ({ componentName, componentLabel, library, version, framework, type, subtype, description, organization }, options) => {
151
173
  const isLibraryBased = getLibraryBased();
152
174
  let sSubType = subtype;
@@ -231,6 +253,7 @@ const validateCompile = async ({ componentName, componentLabel, library, version
231
253
  description,
232
254
  organization,
233
255
  });
256
+ await formatGeneratedFiles(targetDirectory);
234
257
 
235
258
  console.log(chalk.green(`${componentKey} component is created in ${targetDirectory}`));
236
259
  };
@@ -40,8 +40,8 @@ export const updateConfig = async ({ oldComponentKey, newComponentKey, library,
40
40
  configData.library = library;
41
41
  configData.version = version;
42
42
 
43
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
44
- fs.writeFileSync(join(targetDirectory, '/config.json'), JSON.stringify(configData, null, 4), {
43
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
44
+ fs.writeFileSync(join(targetDirectory, '/config.json'), JSON.stringify(configData, null, 2), {
45
45
  encoding: 'utf8',
46
46
  flag: 'w',
47
47
  });
@@ -1,7 +1,8 @@
1
1
  import chalk from 'chalk';
2
2
  import path from 'path';
3
3
  import { join } from 'path';
4
- import archiver from 'archiver';
4
+ // archiver v8 has no default export; ZipArchive replaces the archiver('zip') factory.
5
+ import { ZipArchive } from 'archiver';
5
6
  import fs from 'fs';
6
7
  import {
7
8
  addDebugLog,
@@ -200,7 +201,7 @@ export const zipComponent = async (componentKey) => {
200
201
  const configJson = `${srcDirectory}/config.json`;
201
202
  const localizationJson = `${srcDirectory}/localizations.json`;
202
203
 
203
- const archive = archiver('zip', { zlib: { level: 9 } });
204
+ const archive = new ZipArchive({ zlib: { level: 9 } });
204
205
  const zipChunks = [];
205
206
  archive.on('data', (chunk) => zipChunks.push(chunk));
206
207
 
@@ -263,7 +264,7 @@ export const zipRC = async (content, archiveDirectory, archiveFileName) => {
263
264
  const archiveFile = join(archiveDirectory, archiveFileName);
264
265
 
265
266
  const output = fs.createWriteStream(archiveFile);
266
- const archive = archiver('zip', {
267
+ const archive = new ZipArchive({
267
268
  zlib: { level: 9 }, // Sets the compression level.
268
269
  });
269
270
 
@@ -42,8 +42,8 @@ export const setTasksConfig = async (libraryName, version, devBuild, currDir) =>
42
42
  compConfig.version = version;
43
43
 
44
44
  // update file
45
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
46
- fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 4), { encoding: 'utf8', flag: 'w' });
45
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
46
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(configData, null, 2), { encoding: 'utf8', flag: 'w' });
47
47
  };
48
48
 
49
49
  export const setPackageOrg = async (organization, currDir) => {
@@ -55,8 +55,8 @@ export const setPackageOrg = async (organization, currDir) => {
55
55
  packageData.organization = organization;
56
56
 
57
57
  // update file
58
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
59
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageData, null, 4), { encoding: 'utf8', flag: 'w' });
58
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
59
+ fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageData, null, 2)}\n`, { encoding: 'utf8', flag: 'w' });
60
60
  };
61
61
 
62
62
  export const updateConfig = async ({ oldComponentKey, newComponentKey, organization, library, version, currentDirectory }) => {
@@ -71,8 +71,8 @@ export const updateConfig = async ({ oldComponentKey, newComponentKey, organizat
71
71
  configData.library = library;
72
72
  configData.version = version;
73
73
 
74
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
75
- fs.writeFileSync(join(currentDirectory, '/config.json'), JSON.stringify(configData, null, 4), {
74
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
75
+ fs.writeFileSync(join(currentDirectory, '/config.json'), `${JSON.stringify(configData, null, 2)}\n`, {
76
76
  encoding: 'utf8',
77
77
  flag: 'w',
78
78
  });
@@ -62,8 +62,8 @@ export const updateConfig = async ({ oldComponentKey, newComponentKey, library,
62
62
  configData.library = library;
63
63
  configData.version = version;
64
64
 
65
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
66
- fs.writeFileSync(join(targetDirectory, '/config.json'), JSON.stringify(configData, null, 4), {
65
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
66
+ fs.writeFileSync(join(targetDirectory, '/config.json'), `${JSON.stringify(configData, null, 2)}\n`, {
67
67
  encoding: 'utf8',
68
68
  flag: 'w',
69
69
  });
@@ -48,8 +48,8 @@ export const updateConfig = async ({ oldComponentKey, newComponentKey, library,
48
48
  configData.description = newLabel;
49
49
  }
50
50
 
51
- // stringify "4", makes the json string look like JSON in the file, formatted instead of a single line
52
- fs.writeFileSync(join(targetDirectory, '/config.json'), JSON.stringify(configData, null, 4), { encoding: 'utf8' });
51
+ // stringify "2", makes the json string look like JSON in the file, formatted instead of a single line
52
+ fs.writeFileSync(join(targetDirectory, '/config.json'), `${JSON.stringify(configData, null, 2)}\n`, { encoding: 'utf8' });
53
53
  };
54
54
 
55
55
  export const updateFile = async (fileName, oldComponentKeyPC, newComponentKeyPC, targetDirectory) => {
@@ -0,0 +1,17 @@
1
+ # Docs and templates that are not formatted with Prettier
2
+ **/*.md
3
+ **/*.mustache
4
+ **/*.txt
5
+ **/*.npmrc
6
+ **/*.gitignore
7
+ **/LICENSE
8
+
9
+ # CLI-managed state, rewritten by the CLI with its own formatting
10
+ /store/
11
+ /tasks.config.json
12
+
13
+ # Library build output (one folder per org_library, e.g. PegaQa_DxTestLib/)
14
+ /*_*/
15
+ /build/
16
+ /dist/
17
+ /coverage/