Skip to content

Commit 00173d4

Browse files
committed
【update】打包时监测根package.json和端package.json是否一致; review by sonym
1 parent 9a51de7 commit 00173d4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

build/webpack.config.base.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,27 @@ const webpack = require('webpack');
22
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
33
const ESLintPlugin = require('eslint-webpack-plugin');
44
const LintExportWebpackPlugin = require('./lint-export-webpack-plugin');
5+
const chalk = require('chalk');
56
const pkg = require('../package.json');
67

8+
function compareDependencies(pkgName, dependenciesToCompare, rootDependencies = pkg.dependencies) {
9+
Object.keys(dependenciesToCompare).forEach(name => {
10+
if (!rootDependencies[name] || rootDependencies[name] !== dependenciesToCompare[name]) {
11+
if (rootDependencies[name].includes('file:src/')){
12+
return;
13+
}
14+
console.log(chalk.red(`ERROR [${pkgName}]: The dependency ${name} version can not match in root package.json!\n`));
15+
}
16+
});
17+
}
18+
19+
const packageToClients = ['common', 'classic', 'leaflet', 'openlayers', 'mapboxgl'];
20+
packageToClients.forEach(client => {
21+
// eslint-disable-next-line import/no-dynamic-require
22+
const clientPkg = require(`../src/${client}/package.json`);
23+
compareDependencies(clientPkg.name, clientPkg.dependencies);
24+
});
25+
726
//包版本(ES6或者ES5)
827
let moduleVersion = process.env.moduleVersion || 'es5';
928

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"browserify": "^17.0.0",
7171
"browserify-css": "^0.15.0",
7272
"browserify-imgify": "^0.0.1",
73+
"chalk": "^3.0.0",
7374
"chromedriver": "87.0.5",
7475
"clean-css-cli": "^4.3.0",
7576
"commander": "^9.0.0",

0 commit comments

Comments
 (0)