From 92628d4a36805f119cce5403365a02bb67043f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Valero=20S=C3=A1nchez?= Date: Fri, 23 Jun 2023 12:30:37 +0100 Subject: [PATCH 1/5] fix: remove directories using node 14 recommended way --- .gitignore | 1 + package.json | 2 +- src/lib/git-clone.ts | 2 +- src/scripts/sync/clone-and-analyze.ts | 2 +- test/lib/git-clone.spec.ts | 4 ++-- test/scripts/sync/clone-and-analyze.spec.ts | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ee4ced28..96a9ff59 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ yarn.lock .eslintcache local.* test/research +.idea diff --git a/package.json b/package.json index 11994310..fd19698f 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "author": "Snyk Tech Services", "license": "Apache-2.0", "engines": { - "node": ">=14" + "node": ">=14.14" }, "files": [ "bin", diff --git a/src/lib/git-clone.ts b/src/lib/git-clone.ts index b690ad11..bdcc04ac 100644 --- a/src/lib/git-clone.ts +++ b/src/lib/git-clone.ts @@ -53,7 +53,7 @@ export async function gitClone( } catch (err: any) { debug(`Could not shallow clone the repo:\n ${err}`); if (fs.existsSync(repoClonePath)) { - fs.rmdirSync(repoClonePath, { recursive: true, maxRetries: 3 }); + fs.rmSync(repoClonePath, { recursive: true, maxRetries: 3, force: true }); } return { success: false, diff --git a/src/scripts/sync/clone-and-analyze.ts b/src/scripts/sync/clone-and-analyze.ts index 9cb0ffd2..deb5d138 100644 --- a/src/scripts/sync/clone-and-analyze.ts +++ b/src/scripts/sync/clone-and-analyze.ts @@ -63,7 +63,7 @@ export async function cloneAndAnalyze( ); try { - fs.rmdirSync(repoPath, { recursive: true, maxRetries: 3 }); + fs.rmSync(repoPath, { recursive: true, maxRetries: 3, force: true}); } catch (error) { debug(`Failed to delete ${repoPath}. Error was ${error}.`); } diff --git a/test/lib/git-clone.spec.ts b/test/lib/git-clone.spec.ts index 38f87171..8c78fa9d 100644 --- a/test/lib/git-clone.spec.ts +++ b/test/lib/git-clone.spec.ts @@ -13,7 +13,7 @@ describe('gitClone', () => { afterEach(() => { for (const f of removeFolders) { try { - fs.rmdirSync(f, { recursive: true, maxRetries: 3 }); + fs.rmSync(f, { recursive: true, force: true, maxRetries: 3 }); } catch (e) { console.log('Failed to clean up test', e); } @@ -76,7 +76,7 @@ describe('gitClone', () => { afterEach(() => { for (const f of removeFolders) { try { - fs.rmdirSync(f, { recursive: true, maxRetries: 3 }); + fs.rmSync(f, { recursive: true, maxRetries: 3, force: true }); } catch (e) { console.log('Failed to clean up test', e); } diff --git a/test/scripts/sync/clone-and-analyze.spec.ts b/test/scripts/sync/clone-and-analyze.spec.ts index 79caa794..2af8c65d 100644 --- a/test/scripts/sync/clone-and-analyze.spec.ts +++ b/test/scripts/sync/clone-and-analyze.spec.ts @@ -15,7 +15,7 @@ describe('cloneAndAnalyze', () => { afterEach(() => { for (const f of removeFolders) { try { - fs.rmdirSync(f, { recursive: true, maxRetries: 3 }); + fs.rmSync(f, { recursive: true, maxRetries: 3, force: true }); } catch (e) { console.log('Failed to clean up test', e); } From d1ca361754db11417fd4f1418d25247f167ac6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Valero=20S=C3=A1nchez?= Date: Fri, 23 Jun 2023 13:46:23 +0100 Subject: [PATCH 2/5] fix: upgrade node version to 14 --- .releaserc | 8 ++++---- package.json | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.releaserc b/.releaserc index 26dbf041..ec1f661c 100644 --- a/.releaserc +++ b/.releaserc @@ -9,22 +9,22 @@ { "//": "build the macos", "path": "@semantic-release/exec", - "cmd": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t mac-x64-12.9.0 -o snyk-api-import-macos" + "cmd": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t mac-x64-14.15.3 -o snyk-api-import-macos" }, { "//": "build the linux", "path": "@semantic-release/exec", - "cmd": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t linux-x64-12.9.0 -o snyk-api-import-linux" + "cmd": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t linux-x64-14.15.3 -o snyk-api-import-linux" }, { "//": "build the alpine", "path": "@semantic-release/exec", - "cmd": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t alpine-x64-12.9.0 -o snyk-api-import-alpine" + "cmd": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t alpine-x64-14.15.3 -o snyk-api-import-alpine" }, { "//": "build the windows binaries", "path": "@semantic-release/exec", - "cmd": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t windows-x64-12.9.0 -o snyk-api-import-win.exe" + "cmd": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t windows-x64-14.15.3 -o snyk-api-import-win.exe" }, { "//": "shasum all binaries", diff --git a/package.json b/package.json index fd19698f..8a4addfd 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "build-watch": "tsc -w", "prepare": "npm run build", "snyk-test": "snyk test", - "pkg-binaries-linux": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t linux-x64-12.9.0 -o snyk-api-import-linux", - "pkg-binaries": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t mac-x64-12.9.0 -o snyk-api-import-macos" + "pkg-binaries-linux": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t linux-x64-14.15.3 -o snyk-api-import-linux", + "pkg-binaries": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t mac-x64-14.15.3 -o snyk-api-import-macos" }, "types": "./dist/index.d.ts", "repository": { @@ -30,7 +30,7 @@ "author": "Snyk Tech Services", "license": "Apache-2.0", "engines": { - "node": ">=14.14" + "node": ">=14" }, "files": [ "bin", From 7c4289d24ebf49b3ff9ba5196aa4b801ad1661ab Mon Sep 17 00:00:00 2001 From: Jose Carlos Valero Sanchez Date: Fri, 23 Jun 2023 13:51:06 +0100 Subject: [PATCH 3/5] fix: lint --- src/scripts/sync/clone-and-analyze.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/sync/clone-and-analyze.ts b/src/scripts/sync/clone-and-analyze.ts index deb5d138..69f68f7f 100644 --- a/src/scripts/sync/clone-and-analyze.ts +++ b/src/scripts/sync/clone-and-analyze.ts @@ -63,7 +63,7 @@ export async function cloneAndAnalyze( ); try { - fs.rmSync(repoPath, { recursive: true, maxRetries: 3, force: true}); + fs.rmSync(repoPath, { recursive: true, maxRetries: 3, force: true }); } catch (error) { debug(`Failed to delete ${repoPath}. Error was ${error}.`); } From 7a3e975db4cf7c43693623017cb79eefa3d589ab Mon Sep 17 00:00:00 2001 From: Jose Carlos Valero Sanchez Date: Tue, 27 Jun 2023 17:08:22 +0100 Subject: [PATCH 4/5] fix: update test so it does not delete fixtures --- package.json | 2 ++ test/scripts/sync/sync-org-projects.test.ts | 27 ++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 8a4addfd..b060c5e4 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "bottleneck": "2.19.5", "bunyan": "1.8.15", "debug": "4.3.4", + "fs-extra": "^11.1.1", "lodash": "4.17.21", "micromatch": "4.0.5", "needle": "2.9.1", @@ -64,6 +65,7 @@ "@semantic-release/exec": "5.0.0", "@types/bunyan": "1.8.6", "@types/debug": "4.1.5", + "@types/fs-extra": "^11.0.1", "@types/jest": "^25.1.1", "@types/lodash": "^4.14.149", "@types/micromatch": "4.0.2", diff --git a/test/scripts/sync/sync-org-projects.test.ts b/test/scripts/sync/sync-org-projects.test.ts index aac932ca..7bc59e20 100644 --- a/test/scripts/sync/sync-org-projects.test.ts +++ b/test/scripts/sync/sync-org-projects.test.ts @@ -2,6 +2,7 @@ import { requestsManager } from 'snyk-request-manager'; import * as uuid from 'uuid'; import * as path from 'path'; import * as fs from 'fs'; +import * as fse from 'fs-extra'; import { updateOrgTargets, updateTargets, @@ -244,7 +245,7 @@ describe('updateTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'monorepo-new'), + repoPath: fixture('monorepo-new'), gitResponse: '', }), ); @@ -353,7 +354,7 @@ describe('updateTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'goof'), + repoPath: fixture('goof'), gitResponse: '', }), ); @@ -463,7 +464,7 @@ describe('updateTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'goof'), + repoPath: fixture('goof'), gitResponse: '', }), ); @@ -554,7 +555,7 @@ describe('updateTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'goof'), + repoPath: fixture('goof'), gitResponse: '', }), ); @@ -680,7 +681,7 @@ describe('updateTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'monorepo'), + repoPath: fixture('monorepo'), gitResponse: '', }), ); @@ -890,7 +891,7 @@ describe('updateTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'monorepo'), + repoPath: fixture('monorepo'), gitResponse: '', }), ); @@ -1033,7 +1034,7 @@ describe('updateTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'monorepo'), + repoPath: fixture('monorepo'), gitResponse: '', }), ); @@ -1400,7 +1401,7 @@ describe('updateOrgTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'goof'), + repoPath: fixture('goof'), gitResponse: '', }), ); @@ -1585,7 +1586,7 @@ describe('updateOrgTargets', () => { cloneSpy.mockImplementation(() => Promise.resolve({ success: true, - repoPath: path.resolve(fixturesFolderPath, 'goof'), + repoPath: fixture('goof'), gitResponse: '', }), ); @@ -1876,3 +1877,11 @@ describe('bulkImportTargetFiles', () => { expect(updated.length).toEqual(5); }); }); + +function fixture(name: string) { + const tempDir = fs.mkdtempSync('snyk-api-import-test-'); + fse.copySync(path.resolve(fixturesFolderPath, name), tempDir, { + overwrite: true, + }); + return tempDir; +} From 38b05e473a793a018393688a00b9b73afead9b0b Mon Sep 17 00:00:00 2001 From: Jose Carlos Valero Sanchez Date: Wed, 28 Jun 2023 12:13:45 +0100 Subject: [PATCH 5/5] chore: bump nexe version to overcome nodev14 bug --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b060c5e4..0d3c9e48 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "build-watch": "tsc -w", "prepare": "npm run build", "snyk-test": "snyk test", - "pkg-binaries-linux": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t linux-x64-14.15.3 -o snyk-api-import-linux", - "pkg-binaries": "npx nexe@3.3.7 dist/index.js -r './dist/**/*.js' -t mac-x64-14.15.3 -o snyk-api-import-macos" + "pkg-binaries-linux": "npx nexe@4.0.0-rc.2 dist/index.js -r './dist/**/*.js' -t linux-x64-14.15.3 -o snyk-api-import-linux", + "pkg-binaries": "npx nexe@4.0.0-rc.2 dist/index.js -r './dist/**/*.js' -t mac-x64-14.15.3 -o snyk-api-import-macos" }, "types": "./dist/index.d.ts", "repository": {