|
|
@ -4,28 +4,24 @@ const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const fs = require('fs');
|
|
|
|
const cproc = require('child_process');
|
|
|
|
const cproc = require('child_process');
|
|
|
|
|
|
|
|
|
|
|
|
const packageFilePath = path.join(__dirname, '../../package.json');
|
|
|
|
const { paths, pluginNamePattern } = require('../constants');
|
|
|
|
const packageDefaultFilePath = path.join(__dirname, '../../install/package.json');
|
|
|
|
|
|
|
|
const modulesPath = path.join(__dirname, '../../node_modules');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isPackage = /^(@\w+\/)?nodebb-(plugin|theme|widget|reward)-\w+/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function updatePackageFile() {
|
|
|
|
function updatePackageFile() {
|
|
|
|
let oldPackageContents = {};
|
|
|
|
let oldPackageContents = {};
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
oldPackageContents = JSON.parse(fs.readFileSync(packageFilePath, 'utf8'));
|
|
|
|
oldPackageContents = JSON.parse(fs.readFileSync(paths.currentPackage, 'utf8'));
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
if (e.code !== 'ENOENT') {
|
|
|
|
if (e.code !== 'ENOENT') {
|
|
|
|
throw e;
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const defaultPackageContents = JSON.parse(fs.readFileSync(packageDefaultFilePath, 'utf8'));
|
|
|
|
const defaultPackageContents = JSON.parse(fs.readFileSync(paths.installPackage, 'utf8'));
|
|
|
|
|
|
|
|
|
|
|
|
let dependencies = {};
|
|
|
|
let dependencies = {};
|
|
|
|
Object.entries(oldPackageContents.dependencies || {}).forEach(([dep, version]) => {
|
|
|
|
Object.entries(oldPackageContents.dependencies || {}).forEach(([dep, version]) => {
|
|
|
|
if (isPackage.test(dep)) {
|
|
|
|
if (pluginNamePattern.test(dep)) {
|
|
|
|
dependencies[dep] = version;
|
|
|
|
dependencies[dep] = version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -38,7 +34,7 @@ function updatePackageFile() {
|
|
|
|
|
|
|
|
|
|
|
|
const packageContents = { ...oldPackageContents, ...defaultPackageContents, dependencies: dependencies };
|
|
|
|
const packageContents = { ...oldPackageContents, ...defaultPackageContents, dependencies: dependencies };
|
|
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(packageFilePath, JSON.stringify(packageContents, null, 2));
|
|
|
|
fs.writeFileSync(paths.currentPackage, JSON.stringify(packageContents, null, 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.updatePackageFile = updatePackageFile;
|
|
|
|
exports.updatePackageFile = updatePackageFile;
|
|
|
@ -54,7 +50,7 @@ function installAll() {
|
|
|
|
const prod = global.env !== 'development';
|
|
|
|
const prod = global.env !== 'development';
|
|
|
|
let command = 'npm install';
|
|
|
|
let command = 'npm install';
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
fs.accessSync(path.join(modulesPath, 'nconf/package.json'), fs.constants.R_OK);
|
|
|
|
fs.accessSync(path.join(paths.nodeModules, 'nconf/package.json'), fs.constants.R_OK);
|
|
|
|
const supportedPackageManagerList = exports.supportedPackageManager; // load config from src/cli/package-install.js
|
|
|
|
const supportedPackageManagerList = exports.supportedPackageManager; // load config from src/cli/package-install.js
|
|
|
|
const packageManager = require('nconf').get('package_manager');
|
|
|
|
const packageManager = require('nconf').get('package_manager');
|
|
|
|
if (supportedPackageManagerList.indexOf(packageManager) >= 0) {
|
|
|
|
if (supportedPackageManagerList.indexOf(packageManager) >= 0) {
|
|
|
@ -94,34 +90,34 @@ exports.installAll = installAll;
|
|
|
|
function preserveExtraneousPlugins() {
|
|
|
|
function preserveExtraneousPlugins() {
|
|
|
|
// Skip if `node_modules/` is not found or inaccessible
|
|
|
|
// Skip if `node_modules/` is not found or inaccessible
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
fs.accessSync(modulesPath, fs.constants.R_OK);
|
|
|
|
fs.accessSync(paths.nodeModules, fs.constants.R_OK);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const packages = fs.readdirSync(modulesPath).filter(function (pkgName) {
|
|
|
|
const packages = fs.readdirSync(paths.nodeModules).filter(function (pkgName) {
|
|
|
|
return isPackage.test(pkgName);
|
|
|
|
return pluginNamePattern.test(pkgName);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const packageContents = JSON.parse(fs.readFileSync(packageFilePath, 'utf8'));
|
|
|
|
const packageContents = JSON.parse(fs.readFileSync(paths.currentPackage, 'utf8'));
|
|
|
|
|
|
|
|
|
|
|
|
const extraneous = packages
|
|
|
|
const extraneous = packages
|
|
|
|
// only extraneous plugins (ones not in package.json) which are not links
|
|
|
|
// only extraneous plugins (ones not in package.json) which are not links
|
|
|
|
.filter(function (pkgName) {
|
|
|
|
.filter(function (pkgName) {
|
|
|
|
const extraneous = !packageContents.dependencies.hasOwnProperty(pkgName);
|
|
|
|
const extraneous = !packageContents.dependencies.hasOwnProperty(pkgName);
|
|
|
|
const isLink = fs.lstatSync(path.join(modulesPath, pkgName)).isSymbolicLink();
|
|
|
|
const isLink = fs.lstatSync(path.join(paths.nodeModules, pkgName)).isSymbolicLink();
|
|
|
|
|
|
|
|
|
|
|
|
return extraneous && !isLink;
|
|
|
|
return extraneous && !isLink;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
// reduce to a map of package names to package versions
|
|
|
|
// reduce to a map of package names to package versions
|
|
|
|
.reduce(function (map, pkgName) {
|
|
|
|
.reduce(function (map, pkgName) {
|
|
|
|
const pkgConfig = JSON.parse(fs.readFileSync(path.join(modulesPath, pkgName, 'package.json'), 'utf8'));
|
|
|
|
const pkgConfig = JSON.parse(fs.readFileSync(path.join(paths.nodeModules, pkgName, 'package.json'), 'utf8'));
|
|
|
|
map[pkgName] = pkgConfig.version;
|
|
|
|
map[pkgName] = pkgConfig.version;
|
|
|
|
return map;
|
|
|
|
return map;
|
|
|
|
}, {});
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
|
|
// Add those packages to package.json
|
|
|
|
// Add those packages to package.json
|
|
|
|
Object.assign(packageContents.dependencies, extraneous);
|
|
|
|
Object.assign(packageContents.dependencies, extraneous);
|
|
|
|
fs.writeFileSync(packageFilePath, JSON.stringify(packageContents, null, 2));
|
|
|
|
fs.writeFileSync(paths.currentPackage, JSON.stringify(packageContents, null, 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.preserveExtraneousPlugins = preserveExtraneousPlugins;
|
|
|
|
exports.preserveExtraneousPlugins = preserveExtraneousPlugins;
|
|
|
|