mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: regression in package.json merging logic that caused extraneous packages to not be removed
This commit is contained in:
@@ -41,7 +41,7 @@ pkgInstall.updatePackageFile = () => {
|
|||||||
// Sort dependencies alphabetically
|
// Sort dependencies alphabetically
|
||||||
dependencies = sortDependencies({ ...dependencies, ...defaultPackageContents.dependencies });
|
dependencies = sortDependencies({ ...dependencies, ...defaultPackageContents.dependencies });
|
||||||
|
|
||||||
const packageContents = _.merge(oldPackageContents, defaultPackageContents, { dependencies });
|
const packageContents = { ..._.merge(oldPackageContents, defaultPackageContents), dependencies };
|
||||||
|
|
||||||
fs.writeFileSync(paths.currentPackage, JSON.stringify(packageContents, null, 2));
|
fs.writeFileSync(paths.currentPackage, JSON.stringify(packageContents, null, 2));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { execSync } = require('child_process');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
@@ -27,25 +26,15 @@ describe('Package install lib', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should remove non-`nodebb-` modules not specified in `install/package.json`', async () => {
|
it('should remove non-`nodebb-` modules not specified in `install/package.json`', async () => {
|
||||||
const oldValue = process.env.NODE_ENV;
|
source.dependencies.dotenv = '16.0.0';
|
||||||
process.env.NODE_ENV = 'development';
|
await fs.writeFile(packageFilePath, JSON.stringify(source, null, 4));
|
||||||
|
delete source.dependencies.dotenv;
|
||||||
|
|
||||||
// install an extra package
|
|
||||||
// chose dotenv because it's a popular package
|
|
||||||
// and we use nconf instead
|
|
||||||
execSync('npm install dotenv --save');
|
|
||||||
|
|
||||||
// assert it saves in package.json
|
|
||||||
const packageWithExtras = JSON.parse(await fs.readFile(packageFilePath, 'utf8'));
|
|
||||||
assert(packageWithExtras.dependencies.dotenv, 'dependency did not save');
|
|
||||||
|
|
||||||
// update the package file
|
|
||||||
pkgInstall.updatePackageFile();
|
pkgInstall.updatePackageFile();
|
||||||
|
|
||||||
// assert it removed the extra package
|
// assert it removed the extra package
|
||||||
const packageCleaned = JSON.parse(await fs.readFile(packageFilePath, 'utf8'));
|
const packageCleaned = JSON.parse(await fs.readFile(packageFilePath, 'utf8'));
|
||||||
assert(!packageCleaned.dependencies.dotenv, 'dependency was not removed');
|
assert(!packageCleaned.dependencies.dotenv, 'dependency was not removed');
|
||||||
process.env.NODE_ENV = oldValue;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should merge new root level properties from `install/package.json` into `package.json`', async () => {
|
it('should merge new root level properties from `install/package.json` into `package.json`', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user