Skip to content

Commit

Permalink
experiment: patch local deps for measure bundle size action
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-kot committed Jul 24, 2023
1 parent 8a75704 commit caea95b
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions scripts/unlock-package-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@ const path = require('path');
/**
* Remove specific @cloudscape-design/* packages where we should always use the latest minor release.
*/
const filename = path.resolve(__dirname, '..', 'package-lock.json');
const packageLock = JSON.parse(fs.readFileSync(filename));
[
path.resolve(__dirname, '..', 'package-lock.json'),
path.resolve(__dirname, '..', '.github', 'workflows', 'bundle-size', 'package-lock.json'),
].forEach(filename => unlock(filename));

function unlock(filename) {
const packageLock = JSON.parse(fs.readFileSync(filename));

Object.keys(packageLock.packages).forEach(dependencyName => {
removeDependencies(dependencyName, packageLock.packages);
});

Object.keys(packageLock.dependencies).forEach(dependencyName => {
removeDependencies(dependencyName, packageLock.dependencies);
});

fs.writeFileSync(filename, JSON.stringify(packageLock, null, 2) + '\n');
console.log('Removed @cloudscape-design/ dependencies from package-lock file');
}

function removeDependencies(dependencyName, packages) {
if (dependencyName.includes('@cloudscape-design/')) {
delete packages[dependencyName];
}
}

Object.keys(packageLock.packages).forEach(dependencyName => {
removeDependencies(dependencyName, packageLock.packages);
});

Object.keys(packageLock.dependencies).forEach(dependencyName => {
removeDependencies(dependencyName, packageLock.dependencies);
});

fs.writeFileSync(filename, JSON.stringify(packageLock, null, 2) + '\n');
console.log('Removed @cloudscape-design/ dependencies from package-lock file');

0 comments on commit caea95b

Please sign in to comment.