feat: support workspaces
This commit is contained in:
@@ -64,7 +64,7 @@
|
|||||||
"trailingComma": "es5"
|
"trailingComma": "es5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^2.0.1",
|
"glob-parent": "^5.0.0",
|
||||||
"joycon": "^2.2.4",
|
"joycon": "^2.2.4",
|
||||||
"md5-file": "^4.0.0",
|
"md5-file": "^4.0.0",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
|
|||||||
11
src/index.js
11
src/index.js
@@ -42,10 +42,21 @@ module.exports = async function pkgcomp(config, ident, opts = defaultOptions) {
|
|||||||
// read dependencies from package.json
|
// read dependencies from package.json
|
||||||
const pkg = utils.getFileContents(path.join(config.rootDir, 'package.json'), { format: 'json' });
|
const pkg = utils.getFileContents(path.join(config.rootDir, 'package.json'), { format: 'json' });
|
||||||
|
|
||||||
|
// read dependencies from workspace packages
|
||||||
|
const workspaces = utils.getPackageWorkspaces().map(({ name, package }) => {
|
||||||
|
const wpkg = utils.getFileContents(path.join(config.rootDir, package), { format: 'json' });
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
dependencies: wpkg.dependencies,
|
||||||
|
devDependencies: wpkg.devDependencies,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
hashes,
|
hashes,
|
||||||
dependencies: pkg.dependencies,
|
dependencies: pkg.dependencies,
|
||||||
devDependencies: pkg.devDependencies,
|
devDependencies: pkg.devDependencies,
|
||||||
|
workspaces,
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if the command should be run
|
// check if the command should be run
|
||||||
|
|||||||
22
src/utils.js
22
src/utils.js
@@ -2,6 +2,7 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const JoyCon = require('joycon');
|
const JoyCon = require('joycon');
|
||||||
|
const globParent = require('glob-parent');
|
||||||
|
|
||||||
exports.getRootPath = () => process.cwd();
|
exports.getRootPath = () => process.cwd();
|
||||||
|
|
||||||
@@ -38,6 +39,27 @@ exports.getPackageInfo = () => {
|
|||||||
return { name, workspaces };
|
return { name, workspaces };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getPackageWorkspaces = () => {
|
||||||
|
const { workspaces } = exports.getPackageInfo();
|
||||||
|
if (!workspaces) return [];
|
||||||
|
|
||||||
|
return workspaces.reduce((acc, glob) => {
|
||||||
|
const parent = globParent(glob);
|
||||||
|
const packages = fs
|
||||||
|
.readdirSync(parent)
|
||||||
|
.map(package => {
|
||||||
|
const packageJson = path.join(parent, package, 'package.json');
|
||||||
|
if (!exports.canAccessFile(packageJson)) return false;
|
||||||
|
return {
|
||||||
|
name: package,
|
||||||
|
package: packageJson,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(Boolean);
|
||||||
|
return acc.concat(packages);
|
||||||
|
}, []);
|
||||||
|
};
|
||||||
|
|
||||||
exports.getConfig = (overrides = {}) => {
|
exports.getConfig = (overrides = {}) => {
|
||||||
const joycon = new JoyCon();
|
const joycon = new JoyCon();
|
||||||
const defaults = {
|
const defaults = {
|
||||||
|
|||||||
@@ -1027,6 +1027,13 @@ getopts@^2.0.6:
|
|||||||
resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.2.4.tgz#3137fe8a5fddf304904059a851bdc1c22f0f54fb"
|
resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.2.4.tgz#3137fe8a5fddf304904059a851bdc1c22f0f54fb"
|
||||||
integrity sha512-Rz7DGyomZjrenu9Jx4qmzdlvJgvrEFHXHvjK0FcZtcTC1U5FmES7OdZHUwMuSnEE6QvBvwse1JODKj7TgbSEjQ==
|
integrity sha512-Rz7DGyomZjrenu9Jx4qmzdlvJgvrEFHXHvjK0FcZtcTC1U5FmES7OdZHUwMuSnEE6QvBvwse1JODKj7TgbSEjQ==
|
||||||
|
|
||||||
|
glob-parent@^5.0.0:
|
||||||
|
version "5.0.0"
|
||||||
|
resolved "https://npm.w33ble.com:443/glob-parent/-/glob-parent-5.0.0.tgz#1dc99f0f39b006d3e92c2c284068382f0c20e954"
|
||||||
|
integrity sha512-Z2RwiujPRGluePM6j699ktJYxmPpJKCfpGA13jz2hmFZC7gKetzrWvg5KN3+OsIFmydGyZ1AVwERCq1w/ZZwRg==
|
||||||
|
dependencies:
|
||||||
|
is-glob "^4.0.1"
|
||||||
|
|
||||||
glob@^7.0.3, glob@^7.1.2, glob@^7.1.3:
|
glob@^7.0.3, glob@^7.1.2, glob@^7.1.3:
|
||||||
version "7.1.3"
|
version "7.1.3"
|
||||||
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1"
|
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.3.tgz#3960832d3f1574108342dafd3a67b332c0969df1"
|
||||||
@@ -1324,7 +1331,7 @@ is-fullwidth-code-point@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
|
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
|
||||||
integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=
|
integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=
|
||||||
|
|
||||||
is-glob@^4.0.0:
|
is-glob@^4.0.0, is-glob@^4.0.1:
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc"
|
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc"
|
||||||
integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==
|
integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==
|
||||||
|
|||||||
Reference in New Issue
Block a user