Skip to content

Commit 728f9f7

Browse files
authored
Replace Lerna with custom scripts (#3527)
1 parent 17acfb4 commit 728f9f7

32 files changed

+4884
-14232
lines changed

.github/workflows/compatibility.yml

-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,4 @@ jobs:
3030
~/cypress-binary-cache
3131
key: compat_buildcache
3232
- run: cp -r ~/tmp_build/* .
33-
# - run: npm i -g lerna
34-
# - run: lerna bootstrap --ci --force-local --ignore docs
35-
# - run: lerna run bundle --ignore docs --scope luigi-client-private
36-
# - run: lerna run bundle --ignore docs --scope @luigi-project/testing-utilities
37-
#- run: lerna run bundle --ignore docs
3833
- run: bash ./scripts/testCompatibility.sh --tag latest

.github/workflows/prepare.yml

+5-8
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,11 @@ jobs:
5252
~/cypress-binary-cache
5353
key: ${{ inputs.buildcache_key }}
5454
- run: ls test
55-
- run: npm i -g [email protected]
56-
- run: lerna bootstrap --ci --force-local --ignore docs
57-
- run: lerna run bundle --ignore docs --scope luigi-client-private
58-
- run: lerna run bundle --ignore docs --scope @luigi-project/testing-utilities
59-
- run: lerna run bundle --ignore docs --scope @luigi-project/client-support-angular
60-
- run: lerna run bundle --ignore docs
61-
- run: lerna run bundlesizeOnly --ignore docs
62-
- run: lerna run build --ignore docs
55+
# Bundle all
56+
- run: npm run bootstrap
57+
- run: npm run bundle
58+
# Check bundlesize not exceeded
59+
- run: npm run bundlesize
6360
- run: pwd
6461
- run: sudo cp -r . ~/tmp_build
6562
- run: ls -l ~/tmp_build

.github/workflows/test.yml

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ jobs:
5050
key: buildcache
5151
- run: cp -r ~/tmp_build/* .
5252
- run: npm i -g cypress
53-
- run: npm i -g [email protected]
5453
- run: npm i -g live-server
5554
- run: bash ./test/mockengine.sh || exit 1
5655

.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ node_modules
88
.vscode/diff
99
.vscode/settings.json
1010

11-
# Lerna
12-
lerna-debug.log
13-
1411
.changelog
1512

1613
# temporary files and folders
@@ -25,3 +22,4 @@ core/dev-tools/latest_build.log
2522
core/dev-tools/simple-app
2623
/full_eslint_report.html
2724
test/e2e-test-application/cypress/screenshots
25+
**/.DS_Store

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Once the applications are ready:
7171

7272
### Backward compatibility tests
7373

74-
Use these tests to ensure that applications written for previous versions of Luigi still work after Luigi gets updated with npm. Before running the tests, bundle Luigi by running `lerna run bundle` in the main repository folder.
74+
Use these tests to ensure that applications written for previous versions of Luigi still work after Luigi gets updated with npm. Before running the tests, bundle Luigi by running `npm run bundle` in the main repository folder.
7575

7676
Install [jq](https://stedolan.github.io/jq/) using the `brew install jq` command. It is required for the script to work, however, you can omit it if the command you are using to run your tests is tagged `latest`.
7777

bootstrap.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* This file is used to run (npm install) in all of the folders which have it as a prerequisite in the pipeline and during local development
3+
*/
4+
5+
const { exec } = require('child_process');
6+
7+
// Array of folder names
8+
const folders = [
9+
'./',
10+
'core',
11+
'client',
12+
'client-frameworks-support/client-support-angular',
13+
'client-frameworks-support/testing-utilities',
14+
'container',
15+
'plugins',
16+
'scripts',
17+
'test/e2e-test-application',
18+
'test/e2e-js-test-application',
19+
'client-frameworks-support/testing-utilities/test'
20+
];
21+
// Check for verbose flag
22+
const verboseFlagIndex = process.argv.indexOf('--verbose');
23+
let isVerbose = verboseFlagIndex !== -1;
24+
25+
// Function to install npm packages in given folder
26+
function installPackages(folder, index, totalFolders) {
27+
return new Promise((resolve, reject) => {
28+
const command = `cd ${folder} && npm install`;
29+
30+
exec(command, (error, stdout, stderr) => {
31+
if (error) {
32+
console.error(`\x1b[31mError installing npm packages in ${folder} \x1b[0m`);
33+
reject(error);
34+
} else {
35+
console.log(
36+
`\x1b[32m[${index + 1}/${totalFolders}] : npm packages installed successfully in \x1b[33m${folder}\x1b[0m`
37+
);
38+
// Print logs if needed
39+
if (isVerbose) {
40+
console.log('VERBOSE:', stdout);
41+
}
42+
resolve();
43+
}
44+
});
45+
});
46+
}
47+
48+
// Function to install packages in all folders sequentially
49+
async function installAllPackages() {
50+
for (let i = 0; i < folders.length; i++) {
51+
await installPackages(folders[i], i, folders.length);
52+
}
53+
}
54+
55+
/**
56+
* Function to handle the error case for promises
57+
* @param {*} error error
58+
*/
59+
function errorHandler(error) {
60+
console.error('Stopping execution of the process due to error:', error);
61+
process.exit(1);
62+
}
63+
64+
// EXECUTE CODE STARTS HERE
65+
66+
console.log(
67+
`\x1b[36m\n\nInstalling node_modules packages in these folders in the following order:\x1b[0m ${
68+
isVerbose ? '\x1b[41m\x1b[37m(VERBOSE)\x1b[0m' : ''
69+
}`
70+
);
71+
for (const folder of folders) {
72+
console.log('- ' + folder);
73+
}
74+
75+
console.log('Starting ---------->');
76+
77+
installAllPackages().then(() => {
78+
console.log('\x1b[32m+++++++++++> Finished installing packages successfuly. <++++++++++++++++\x1b[0m\n');
79+
}, errorHandler);

bundle-size.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* This file is used to check if bundle size threshold is not exceded
3+
*/
4+
5+
const fs = require('fs');
6+
const path = require('path');
7+
8+
const filesAndLimits = [
9+
{
10+
path: 'client/public/luigi-client.js',
11+
limit: 50
12+
},
13+
{
14+
path: 'core/public/luigi.js',
15+
limit: 650
16+
},
17+
{
18+
path: 'core/public/luigi.css',
19+
limit: 800
20+
},
21+
{
22+
path: 'plugins/auth/public/auth-oauth2/plugin.js',
23+
limit: 75
24+
}
25+
];
26+
27+
async function checkFileSizes() {
28+
for (const { path: filePath, limit } of filesAndLimits) {
29+
const fullPath = path.resolve(__dirname, filePath);
30+
console.log(`\x1b[33m\n\nChecking bundlesize in \x1b[32m${filePath}\x1b[0m`);
31+
32+
try {
33+
const stats = await fs.promises.stat(fullPath);
34+
const fileSizeInKB = (stats.size / 1024).toFixed(2);
35+
36+
if (fileSizeInKB > limit) {
37+
console.error(
38+
`\x1b[31m \n ERROR: ${filePath} exceeds the size limit. Actual size: ${fileSizeInKB} KB, Limit: ${limit} KB ! \x1b[0m\n`
39+
);
40+
process.exit(1);
41+
} else {
42+
console.log(
43+
`\x1b[32m\u2713\x1b[0m ${filePath} is within the size limit. Size: \x1b[33m${fileSizeInKB} KB\x1b[0m < \x1b[32m${limit} KB\x1b[0m`
44+
);
45+
}
46+
} catch (error) {
47+
console.error(`Error reading file ${filePath}: ${error.message}`);
48+
process.exit(1);
49+
}
50+
}
51+
52+
console.log('\x1b[32m\u2713\x1b[0m \x1b[32m All files are within their size limits.\x1b[0m \x1b[32m\u2713\x1b[0m');
53+
}
54+
55+
checkFileSizes();

bundle.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const { exec } = require('child_process');
2+
3+
// Array of folder names
4+
const foldersToBundle = [
5+
'core',
6+
'client',
7+
'client-frameworks-support/testing-utilities',
8+
'client-frameworks-support/client-support-angular',
9+
'container',
10+
'plugins'
11+
];
12+
13+
const foldersToBuild = ['test/e2e-test-application'];
14+
15+
let timeToBundle = 0;
16+
let timeToBuild = 0;
17+
18+
// Check for verbose flag
19+
const verboseFlagIndex = process.argv.indexOf('--verbose');
20+
let isVerbose = verboseFlagIndex !== -1;
21+
22+
// Function to run 'npm run <operation>' in a folder
23+
function runCommand(folder, index, totalFolders, operation) {
24+
const startTime = new Date();
25+
26+
return new Promise((resolve, reject) => {
27+
const command = `cd ${folder} && npm run ${operation}`;
28+
29+
exec(command, (error, stdout, stderr) => {
30+
const endTime = new Date();
31+
const elapsedTime = (endTime - startTime) / 1000;
32+
timeToBundle += operation === 'bundle' ? elapsedTime : 0;
33+
timeToBuild += operation === 'build' ? elapsedTime : 0;
34+
35+
if (error) {
36+
console.error(`\x1b[31mError when trying to ${operation} packages in ${folder} \x1b[0m`);
37+
reject(error);
38+
} else {
39+
console.log(
40+
`\x1b[36m[${index +
41+
1}/${totalFolders}]\x1b[0m: \x1b[33m${folder}\x1b[0m ${operation} successful (\x1b[33m${elapsedTime.toFixed(
42+
2
43+
)}s\x1b[0m)`
44+
);
45+
// Print logs if needed
46+
if (isVerbose) {
47+
console.log('VERBOSE:', stdout);
48+
}
49+
resolve();
50+
}
51+
});
52+
});
53+
}
54+
55+
// Function to run 'npm run bundle' in all specified folders
56+
async function runCommandInAllFolders(folders, operation) {
57+
console.log(
58+
`\x1b[36m\n\nRunning (npm run ${operation}) in these folders in the following order:\x1b[0m ${
59+
isVerbose ? '\x1b[41m\x1b[37m(VERBOSE)\x1b[0m' : ''
60+
}`
61+
);
62+
for (const folder of folders) {
63+
console.log('- ' + folder);
64+
}
65+
66+
for (let i = 0; i < folders.length; i++) {
67+
console.log(`\n\x1b[37m${operation} \x1b[33m${folders[i]}\x1b[0m ...`);
68+
await runCommand(folders[i], i, folders.length, operation);
69+
}
70+
}
71+
72+
// Run the 'npm run bundle' command in the specified folders
73+
runCommandInAllFolders(foldersToBundle, 'bundle').then(() => {
74+
console.log(`Bundle finished in ${timeToBundle.toFixed(2)}s`);
75+
76+
// Run the 'npm run build' command in the specified folders
77+
runCommandInAllFolders(foldersToBuild, 'build').then(() => {
78+
console.log(`Build finished in ${timeToBuild.toFixed(2)}s\n`);
79+
console.log(`\nBuild+Bundle finished in ${(timeToBuild + timeToBundle).toFixed(2)}s\n`);
80+
}, errorHandler);
81+
}, errorHandler);
82+
83+
/**
84+
* Function to handle the error case for promises
85+
* @param {*} error error
86+
*/
87+
function errorHandler(error) {
88+
console.error('Stopping execution of the process due to error:', error);
89+
process.exit(1);
90+
}

0 commit comments

Comments
 (0)