From 55cd822c40f82bc955f07db6fc29b9da88190feb Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Wed, 27 Sep 2023 14:18:03 +0100 Subject: [PATCH 1/3] delete lock file when package is updated --- lib/launcher.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/launcher.js b/lib/launcher.js index f710a37..b7a8d56 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -33,6 +33,7 @@ class Launcher { this.files = { packageJSON: path.join(this.projectDir, 'package.json'), + packageLockJSON: path.join(this.projectDir, 'package-lock.json'), flows: path.join(this.projectDir, 'flows.json'), credentials: path.join(this.projectDir, 'flows_cred.json'), settings: path.join(this.projectDir, 'settings.js'), @@ -54,6 +55,13 @@ class Launcher { await fs.writeFile(this.files.packageJSON, JSON.stringify(packageData, ' ', 2)) await fs.rm(path.join(this.projectDir, '.config.nodes.json'), { force: true }) await fs.rm(path.join(this.projectDir, '.config.nodes.json.backup'), { force: true }) + + // as the package.json file has been re-written, we will "assume" different versions + // of the modules and therefore remove the package-lock.json file to permit modules + // to be updated to the versions specified in package.json + if (existsSync(this.files.packageLockJSON)) { + await fs.rm(this.files.packageLockJSON) + } } async readPackage () { From 62176e2788d86f88f7971891e2341471cf89870c Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Thu, 5 Oct 2023 16:39:00 +0100 Subject: [PATCH 2/3] move package lock deletion to own fn (for testing) --- lib/launcher.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/launcher.js b/lib/launcher.js index b7a8d56..8345c70 100644 --- a/lib/launcher.js +++ b/lib/launcher.js @@ -59,6 +59,10 @@ class Launcher { // as the package.json file has been re-written, we will "assume" different versions // of the modules and therefore remove the package-lock.json file to permit modules // to be updated to the versions specified in package.json + await this.removePackageLock() + } + + async removePackageLock () { if (existsSync(this.files.packageLockJSON)) { await fs.rm(this.files.packageLockJSON) } From 23327fcf168f1003e796d2abe3c74847df8cd5f4 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Thu, 5 Oct 2023 16:40:57 +0100 Subject: [PATCH 3/3] update test to ensure package lock is deleted --- test/unit/lib/launcher_spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unit/lib/launcher_spec.js b/test/unit/lib/launcher_spec.js index 146fea6..9e562ff 100644 --- a/test/unit/lib/launcher_spec.js +++ b/test/unit/lib/launcher_spec.js @@ -1,3 +1,4 @@ +const sinon = require('sinon') const should = require('should') const { newLauncher } = require('../../../lib/launcher') const setup = require('../setup') @@ -23,6 +24,7 @@ describe('Launcher', function () { afterEach(async function () { await fs.rm(config.dir, { recursive: true, force: true }) + sinon.restore() }) it('Create Snapshot Flow/Creds Files, instance bound device', async function () { @@ -91,6 +93,8 @@ describe('Launcher', function () { it('Write package.json', async function () { const launcher = newLauncher(config, null, 'projectId', setup.snapshot) + // spy on the removePackageLock function + sinon.spy(launcher, 'removePackageLock') await launcher.writePackage() const pkgFile = await fs.readFile(path.join(config.dir, 'project', 'package.json')) const pkg = JSON.parse(pkgFile) @@ -98,6 +102,7 @@ describe('Launcher', function () { pkg.dependencies.should.have.property('node-red-node-random', '0.4.0') pkg.name.should.eqls('TEST_PROJECT') pkg.version.should.eqls('0.0.0-aaaabbbbcccc') + launcher.removePackageLock.calledOnce.should.be.true() }) it('Write Settings - with HTTPS, raw values', async function () {