|
21 | 21 | throw reason;
|
22 | 22 | });
|
23 | 23 |
|
24 |
| - const fs = require('fs'); |
25 |
| - const join = require('path').join; |
| 24 | + const fs = require('node:fs'); |
| 25 | + const join = require('node:path').join; |
26 | 26 | const shell = require('shelljs');
|
27 | 27 | const { echo, cp, mkdir, mv, rm } = shell;
|
28 | 28 | shell.config.fatal = true;
|
|
32 | 32 | // https://github.com/shelljs/shelljs/issues/1024#issuecomment-1001552543
|
33 | 33 | shell.env.NODE_OPTIONS = '--max_old_space_size=4096'; // Increase heap size for the CI
|
34 | 34 | shell.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = 'true'; // Skip download and avoid `ERROR: Failed to download Chromium`.
|
35 |
| - const template = require('./config').generateTemplate( |
| 35 | + const template = await require('./config').generateTemplate( |
36 | 36 | new Date().toISOString()
|
37 | 37 | );
|
38 | 38 | const utils = require('./utils');
|
|
74 | 74 | // Clean up the `./electron/build/resources` folder with Git.
|
75 | 75 | // To avoid file duplication between bundled app and dev mode, some files are copied from `./electron-app` to `./electron/build` folder.
|
76 | 76 | const foldersToSyncFromDev = ['resources'];
|
77 |
| - foldersToSyncFromDev.forEach((filename) => |
78 |
| - shell.exec( |
79 |
| - `git -C ${join(repoRoot, 'electron', 'build', filename)} clean -ffxdq`, |
80 |
| - { |
81 |
| - async: false, |
82 |
| - } |
| 77 | + await Promise.all( |
| 78 | + foldersToSyncFromDev.map((filename) => |
| 79 | + exec('git', [ |
| 80 | + '-C', |
| 81 | + join(repoRoot, 'electron', 'build', filename), |
| 82 | + 'clean', |
| 83 | + '-ffxdq', |
| 84 | + ]) |
83 | 85 | )
|
84 | 86 | );
|
85 | 87 |
|
|
104 | 106 | // Build and test the extensions |
|
105 | 107 | //-------------------------------+
|
106 | 108 | for (const extension of extensions) {
|
107 |
| - exec( |
108 |
| - `yarn --network-timeout 1000000 --cwd ${join(repoRoot, extension)}`, |
| 109 | + await exec( |
| 110 | + 'yarn', |
| 111 | + ['--network-timeout', '1000000', '--cwd', join(repoRoot, extension)], |
109 | 112 | `Building and testing ${extension}`
|
110 | 113 | );
|
111 |
| - exec( |
112 |
| - `yarn --network-timeout 1000000 --cwd ${join( |
113 |
| - repoRoot, |
114 |
| - extension |
115 |
| - )} test:slow`, |
| 114 | + await exec( |
| 115 | + 'yarn', |
| 116 | + [ |
| 117 | + '--network-timeout', |
| 118 | + '1000000', |
| 119 | + '--cwd', |
| 120 | + join(repoRoot, extension), |
| 121 | + 'test:slow', |
| 122 | + ], |
116 | 123 | `Executing slow tests ${extension}`
|
117 | 124 | );
|
118 | 125 | }
|
|
142 | 149 | for (const extension of extensions) {
|
143 | 150 | const packageJsonPath = join(repoRoot, extension, 'package.json');
|
144 | 151 | const versionToRestore = readJson(packageJsonPath).version;
|
145 |
| - exec( |
146 |
| - `yarn --network-timeout 1000000 --cwd ${join( |
147 |
| - repoRoot, |
148 |
| - extension |
149 |
| - )} publish --ignore-scripts --new-version ${version} --no-git-tag-version --registry http://localhost:4873`, |
| 152 | + await exec( |
| 153 | + 'yarn', |
| 154 | + [ |
| 155 | + '--network-timeout', |
| 156 | + '1000000', |
| 157 | + '--cwd', |
| 158 | + join(repoRoot, extension), |
| 159 | + 'publish', |
| 160 | + '--ignore-scripts', |
| 161 | + '--new-version', |
| 162 | + version, |
| 163 | + '--no-git-tag-version', |
| 164 | + '--registry', |
| 165 | + 'http://localhost:4873', |
| 166 | + ], |
150 | 167 | `Publishing ${extension}@${version} to the private npm registry`
|
151 | 168 | );
|
152 | 169 | // Publishing will change the version number, this should be reverted up after the build.
|
@@ -250,20 +267,26 @@ ${fs
|
250 | 267 | //-------------------------------------------------------------------------------------------+
|
251 | 268 | // Install all private and public dependencies for the electron application and build Theia. |
|
252 | 269 | //-------------------------------------------------------------------------------------------+
|
253 |
| - exec( |
254 |
| - `yarn --network-timeout 1000000 --cwd ${join( |
255 |
| - repoRoot, |
256 |
| - 'electron', |
257 |
| - 'build' |
258 |
| - )} --registry http://localhost:4873`, |
| 270 | + await exec( |
| 271 | + 'yarn', |
| 272 | + [ |
| 273 | + '--network-timeout', |
| 274 | + '1000000', |
| 275 | + '--cwd', |
| 276 | + join(repoRoot, 'electron', 'build'), |
| 277 | + '--registry', |
| 278 | + 'http://localhost:4873', |
| 279 | + ], |
259 | 280 | 'Installing dependencies'
|
260 | 281 | );
|
261 |
| - exec( |
262 |
| - `yarn --cwd ${join(repoRoot, 'electron', 'build')} build`, |
| 282 | + await exec( |
| 283 | + 'yarn', |
| 284 | + ['--cwd', join(repoRoot, 'electron', 'build'), 'build'], |
263 | 285 | `Building the ${productName} application`
|
264 | 286 | );
|
265 |
| - exec( |
266 |
| - `yarn --cwd ${join(repoRoot, 'electron', 'build')} rebuild`, |
| 287 | + await exec( |
| 288 | + 'yarn', |
| 289 | + ['--cwd', join(repoRoot, 'electron', 'build'), 'rebuild'], |
267 | 290 | 'Rebuilding native dependencies'
|
268 | 291 | );
|
269 | 292 |
|
|
284 | 307 | //-----------------------------------+
|
285 | 308 | // Package the electron application. |
|
286 | 309 | //-----------------------------------+
|
287 |
| - exec( |
288 |
| - `yarn --cwd ${join(repoRoot, 'electron', 'build')} package`, |
| 310 | + await exec( |
| 311 | + 'yarn', |
| 312 | + ['--cwd', join(repoRoot, 'electron', 'build'), 'package'], |
289 | 313 | `Packaging the ${productName} application`
|
290 | 314 | );
|
291 | 315 |
|
@@ -317,15 +341,19 @@ ${fs
|
317 | 341 | //--------+
|
318 | 342 | // Utils. |
|
319 | 343 | //--------+
|
320 |
| - function exec(command, toEcho) { |
| 344 | + /** |
| 345 | + * @param {string} command |
| 346 | + * @param {readonly string[]} args |
| 347 | + */ |
| 348 | + async function exec(command, args, toEcho = '') { |
321 | 349 | if (toEcho) {
|
322 | 350 | echo(`⏱️ >>> ${toEcho}...`);
|
323 | 351 | }
|
324 |
| - const { stdout } = shell.exec(command); |
| 352 | + const stdout = await utils.exec(command, args); |
325 | 353 | if (toEcho) {
|
326 | 354 | echo(`👌 <<< ${toEcho}.`);
|
327 | 355 | }
|
328 |
| - return stdout; |
| 356 | + return stdout.trim(); |
329 | 357 | }
|
330 | 358 |
|
331 | 359 | async function copyFilesToBuildArtifacts() {
|
@@ -437,13 +465,13 @@ ${fs
|
437 | 465 | }
|
438 | 466 |
|
439 | 467 | /**
|
440 |
| - * @param {import('fs').PathLike} file |
| 468 | + * @param {import('node:fs').PathLike} file |
441 | 469 | * @param {string|undefined} [algorithm="sha512"]
|
442 | 470 | * @param {BufferEncoding|undefined} [encoding="base64"]
|
443 | 471 | * @param {object|undefined} [options]
|
444 | 472 | */
|
445 | 473 | function hashFile(file, algorithm = 'sha512', encoding = 'base64', options) {
|
446 |
| - const crypto = require('crypto'); |
| 474 | + const crypto = require('node:crypto'); |
447 | 475 | return new Promise((resolve, reject) => {
|
448 | 476 | const hash = crypto.createHash(algorithm);
|
449 | 477 | hash.on('error', reject).setEncoding(encoding);
|
@@ -500,11 +528,11 @@ ${fs
|
500 | 528 |
|
501 | 529 | /**
|
502 | 530 | * @param {string} configPath
|
503 |
| - * @return {Promise<import('child_process').ChildProcess>} |
| 531 | + * @return {Promise<import('node:child_process').ChildProcess>} |
504 | 532 | */
|
505 | 533 | function startNpmRegistry(configPath) {
|
506 | 534 | return new Promise((resolve, reject) => {
|
507 |
| - const fork = require('child_process').fork( |
| 535 | + const fork = require('node:child_process').fork( |
508 | 536 | require.resolve('verdaccio/bin/verdaccio'),
|
509 | 537 | ['-c', configPath]
|
510 | 538 | );
|
|
0 commit comments