Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARAZDO-400 Drop obsolete gulp dependencies & Fix vulnerabilities
Browse files Browse the repository at this point in the history
7PH committed Aug 13, 2024
1 parent f4b3731 commit ff7ee83
Showing 4 changed files with 207 additions and 663 deletions.
12 changes: 0 additions & 12 deletions config/utils.js
Original file line number Diff line number Diff line change
@@ -8,11 +8,9 @@ const exec = require("gulp-exec");
const dateformat = require("dateformat");
const orderedStreams = require("ordered-read-streams");
const gulpRename = require("gulp-rename");
const gulpDownload = require("gulp-download");
const map = require("map-stream");
const { globSync: glob } = require("glob");
const sonarqubeScanner = require("sonarqube-scanner").default;
const collect = require("gulp-collect");
const Vinyl = require("vinyl");
const { resolveRelativePath, SOURCE_DIR, DIST_DIR, BUILD_DIR } = require("./paths");

@@ -41,16 +39,6 @@ function run(cl, options = {}) {
}
exports.run = run;

// Return a stream that downloads the file if urlOrPath is a link, or copies it otherwise (if it is a relaitve path)
function downloadOrCopy(urlOrPath) {
if (urlOrPath.startsWith("http")) {
return gulpDownload(urlOrPath);
} else {
return gulp.src(urlOrPath);
}
}
exports.downloadOrCopy = downloadOrCopy;

function npmInstall(packagePath) {
const cwd = process.cwd();
run(`cd ${path.dirname(packagePath)} && npm install && cd ${cwd}`);
78 changes: 36 additions & 42 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const { rimraf } = require("rimraf");
const path = require("path");
const gulp = require("gulp");
const log = require("fancy-log");
const gulpFile = require("gulp-file");
const fs = require("fs-extra");
const yargs = require("yargs");
const gulpJsonEditor = require("gulp-json-editor");
const gulpRename = require("gulp-rename");
const gulpArtifactoryUpload = require("gulp-artifactory-upload");
const ts = require("gulp-typescript");
const gulpUtil = require("gulp-util");
const { globSync: glob } = require("glob");
const { Readable } = require("stream");
const { finished } = require("stream/promises");
const orderedStreams = require("ordered-read-streams");
const typescript = require("typescript");
const decompress = require("gulp-decompress");
const decompress = require("decompress");
const needle = require("needle");
const esbuild = require("esbuild");
const {
@@ -31,7 +33,6 @@ const {
getBuildInfo,
npmInstallTask,
cycloneDxPipe,
downloadOrCopy,
getVersionWithCirrusBuildNumber,
run,
runSonarQubeScanner,
@@ -123,44 +124,37 @@ gulp.task("build:bundle", async () => {
/**
* Build all scanners needed by tasks
*/
gulp.task("build:download-scanners", () => {
gulp.task("build:download-scanners", async () => {
async function downloadScanner(url, outDir) {
await fs.mkdirp(outDir);
const outPath = path.join(outDir, url.match(/[^/]+$/)[0]);
const stream = fs.createWriteStream(outPath);
const { body } = await fetch(url);
await finished(Readable.fromWeb(body).pipe(stream));
await decompress(outPath, outDir);
}

const configJss = glob([path.join(BUILD_TS_DIR, "common", "*", "config.js")]);
const streams = [];
for (const configJs of configJss) {
// eslint-disable-next-line import/no-dynamic-require
const { scanner } = require(configJs);
streams.push(
downloadOrCopy(scanner.classicUrl)
.pipe(decompress())
.pipe(
gulp.dest(
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_NET_FRAMEWORK_DIRNAME, scanner.cliVersion),
),
),
await downloadScanner(
scanner.cliUrl,
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_NET_FRAMEWORK_DIRNAME, scanner.cliVersion),
);

streams.push(
downloadOrCopy(scanner.dotnetUrl)
.pipe(decompress())
.pipe(
gulp.dest(
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_NET_DOTNET_DIRNAME, scanner.msBuildVersion),
),
),
await downloadScanner(
scanner.dotnetUrl,
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_NET_DOTNET_DIRNAME, scanner.msBuildVersion),
);

if (scanner.cliUrl) {
streams.push(
downloadOrCopy(scanner.cliUrl)
.pipe(decompress())
.pipe(
gulp.dest(path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_CLI_DIRNAME, scanner.cliVersion)),
),
await downloadScanner(
scanner.cliUrl,
path.join(BUILD_SCANNER_DIR, BUILD_SCANNER_CLI_DIRNAME, scanner.cliVersion),
);
}
}

return orderedStreams(streams);
});

/**
@@ -502,12 +496,12 @@ gulp.task("upload:cyclonedx", () => {

gulp.task("upload:vsix:sonarqube", () => {
if (process.env.CIRRUS_BRANCH !== "master" && !process.env.CIRRUS_PR) {
gulpUtil.log("Not on master nor PR, skip upload:vsix");
return gulpUtil.noop;
log("Not on master nor PR, skip upload:vsix");
return Promise.resolve();
}
if (process.env.CIRRUS_PR && process.env.DEPLOY_PULL_REQUEST === "false") {
gulpUtil.log("On PR, but artifacts should not be deployed, skip upload:vsix");
return gulpUtil.noop;
log("On PR, but artifacts should not be deployed, skip upload:vsix");
return Promise.resolve();
}
const name = `${packageJSON.name}-sq`;

@@ -554,19 +548,19 @@ gulp.task("upload:vsix:sonarqube", () => {
},
}),
)
.on("error", gulpUtil.log);
.on("error", log);
}),
);
});

gulp.task("upload:vsix:sonarcloud", () => {
if (process.env.CIRRUS_BRANCH !== "master" && !process.env.CIRRUS_PR) {
gulpUtil.log("Not on master nor PR, skip upload:vsix");
return gulpUtil.noop;
log("Not on master nor PR, skip upload:vsix");
return Promise.resolve();
}
if (process.env.CIRRUS_PR && process.env.DEPLOY_PULL_REQUEST === "false") {
gulpUtil.log("On PR, but artifacts should not be deployed, skip upload:vsix");
return gulpUtil.noop;
log("On PR, but artifacts should not be deployed, skip upload:vsix");
return Promise.resolve();
}
const name = `${packageJSON.name}-sc`;

@@ -613,18 +607,18 @@ gulp.task("upload:vsix:sonarcloud", () => {
},
}),
)
.on("error", gulpUtil.log);
.on("error", log);
}),
);
});

gulp.task("upload:buildinfo", async () => {
if (process.env.CIRRUS_BRANCH !== "master" && !process.env.CIRRUS_PR) {
gulpUtil.log("Not on master nor PR, skip upload:buildinfo");
log("Not on master nor PR, skip upload:buildinfo");
return;
}
if (process.env.CIRRUS_PR && process.env.DEPLOY_PULL_REQUEST === "false") {
gulpUtil.log("On PR, but artifacts should not be deployed, skip upload:buildinfo");
log("On PR, but artifacts should not be deployed, skip upload:buildinfo");
return;
}

@@ -662,7 +656,7 @@ gulp.task(

gulp.task("promote", async () => {
if (process.env.CIRRUS_BRANCH !== "master" && !process.env.CIRRUS_PR) {
gulpUtil.log("Not on master nor PR, skip promote");
log("Not on master nor PR, skip promote");
return;
}

774 changes: 169 additions & 605 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -31,23 +31,21 @@
"@types/yargs": "17.0.33",
"@typescript-eslint/parser": "8.1.0",
"dateformat": "4.6.3",
"decompress": "4.2.1",
"esbuild": "0.23.0",
"eslint": "8.57.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-promise": "7.1.0",
"fancy-log": "2.0.0",
"fs-extra": "11.2.0",
"glob": "11.0.0",
"gulp": "5.0.0",
"gulp-artifactory-upload": "1.4.0",
"gulp-collect": "0.1.0",
"gulp-decompress": "3.0.0",
"gulp-download": "0.0.1",
"gulp-exec": "5.0.0",
"gulp-file": "0.4.0",
"gulp-json-editor": "2.6.0",
"gulp-rename": "2.0.0",
"gulp-typescript": "5.0.1",
"gulp-util": "3.0.8",
"jest": "29.7.0",
"jest-when": "3.6.0",
"map-stream": "0.1.0",

0 comments on commit ff7ee83

Please sign in to comment.