Skip to content

Commit

Permalink
fix(security): remove cpx and glob dependency from the monorepo (#1173)
Browse files Browse the repository at this point in the history
## Proposed change

Remove `cpx` and `glob` dependencies from the monorepo
Fixing issue reported on
https://github.com/AmadeusITGroup/otter/security/dependabot/3
  • Loading branch information
kpanot authored Dec 21, 2023
2 parents 20a9d14 + a096572 commit 2ab6847
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1,148 deletions.
4 changes: 2 additions & 2 deletions packages/@ama-sdk/showcase-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"cpx": "^1.5.0",
"chokidar": "^3.5.2",
"eslint": "^8.42.0",
"eslint-plugin-jest": "~27.6.0",
"eslint-plugin-jsdoc": "~46.9.0",
"eslint-plugin-prefer-arrow": "~1.2.3",
"eslint-plugin-unicorn": "^49.0.0",
"glob": "^10.0.0",
"globby": "^11.1.0",
"husky": "~8.0.3",
"isomorphic-fetch": "~3.0.0",
"jest": "~29.7.0",
Expand Down
20 changes: 13 additions & 7 deletions packages/@ama-sdk/showcase-sdk/scripts/files-pack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const cpx = require('cpx');
const chokidar = require('chokidar');
const minimist = require('minimist');
const path = require('node:path');
const { sync } = require('glob');
const { sync } = require('globby');
const fs = require('node:fs').promises;
const promisify = require('util').promisify;

Expand Down Expand Up @@ -53,16 +53,22 @@ const updateExports = async () => {

// Move files into the dist folder
const copies = files.reduce((acc, glob) => {
acc.push(
watch ?
if (watch) {
acc.push(
// eslint-disable-next-line no-console
cpx.watch(path.join(baseDir, glob), distFolder).on('copy', (e) => {
chokidar.watch(glob, {cwd: baseDir}).on('all', async (_event, file) => {
await fs.copyFile(path.resolve(baseDir, file), path.resolve(baseDir, distFolder, file))
console.log(`${e.srcPath} copied to ${e.dstPath}`);
if (!noExports) {
void updateExports()
}
}) :
promisify(cpx.copy)(path.join(baseDir, glob), distFolder));
})
);
} else {
acc.push(...sync(glob, { cwd: baseDir, absolute: false })
.map((file) => fs.copyFile(path.resolve(baseDir, file), path.resolve(baseDir, distFolder, file)))
);
}
return acc;
}, []);
await Promise.all(copies);
Expand Down
8 changes: 3 additions & 5 deletions packages/@ama-sdk/showcase-sdk/scripts/override-readme.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const cpx = require('cpx');
const fs = require('node:fs');
const path = require('node:path');
const util = require('util');
const minimist = require('minimist');

const copyFile = util.promisify(cpx.copy);

const root = path.resolve(__dirname, '..');
const argv = minimist(process.argv.slice(2));
const folderName = argv.folderName || '@ama-sdk/showcase-sdk';

(async () => {
await copyFile(path.join(root, 'readme.md'), path.join(root, '.readme-backup'));
await copyFile(path.join(root, 'packages', folderName, 'readme.md'), root);
await fs.promises.copyFile(path.join(root, 'readme.md'), path.join(root, '.readme-backup', 'readme.md'));
await fs.promises.copyFile(path.join(root, 'packages', folderName, 'readme.md'), path.join(root, 'readme.md'));
})();
5 changes: 2 additions & 3 deletions packages/@ama-sdk/showcase-sdk/scripts/restore-readme.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const cpx = require('cpx');
const fs = require('node:fs');
const path = require('node:path');
const util = require('util');
const rimraf = require('rimraf');

const copyFile = util.promisify(cpx.copy);
const rimrafDir = util.promisify(rimraf);

const root = path.resolve(__dirname, '..');

(async () => {
await copyFile(path.join(root, '.readme-backup', 'readme.md'), root);
await fs.promises.copyFile(path.join(root, '.readme-backup', 'readme.md'), path.join(root, 'readme.md'));
await rimrafDir(path.join(root, '.readme-backup'));
})();
Loading

0 comments on commit 2ab6847

Please sign in to comment.