Skip to content

Commit

Permalink
fix: process optional deps during manifest update
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Aug 3, 2020
1 parent 494d5df commit 4b7066c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
13 changes: 10 additions & 3 deletions lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const debug = require("debug")("msr:inlinePlugin");
const getCommitsFiltered = require("./getCommitsFiltered");
const { getManifest, getIndent } = require("./getManifest");
const hasChangedDeep = require("./hasChangedDeep");
const { get } = require("lodash");

/**
* Create an inline plugin creator for a multirelease.
Expand Down Expand Up @@ -32,6 +33,11 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags)
// Get and parse manifest file contents.
const manifest = getManifest(path);
const indent = getIndent(path);
const updateDependency = (scope, name, version) => {
if (get(manifest, `${scope}.${name}`)) {
manifest[scope][name] = version;
}
};

// Loop through localDeps to update dependencies/devDependencies/peerDependencies in manifest.
pkg._localDeps.forEach((d) => {
Expand All @@ -43,9 +49,10 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags)
throw Error(`Cannot release because dependency ${d.name} has not been released`);

// Update version of dependency in manifest.
if (manifest.dependencies.hasOwnProperty(d.name)) manifest.dependencies[d.name] = release.version;
if (manifest.devDependencies.hasOwnProperty(d.name)) manifest.devDependencies[d.name] = release.version;
if (manifest.peerDependencies.hasOwnProperty(d.name)) manifest.peerDependencies[d.name] = release.version;
updateDependency("dependencies", d.name, release.version);
updateDependency("devDependencies", d.name, release.version);
updateDependency("peerDependencies", d.name, release.version);
updateDependency("optionalDependencies", d.name, release.version);
});

// Write package.json back out.
Expand Down
3 changes: 1 addition & 2 deletions lib/getManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ function getManifest(path) {

// Check dependencies.
const checkDeps = (scope) => {
if (!manifest.hasOwnProperty(scope)) manifest[scope] = {};
else if (typeof manifest[scope] !== "object")
if (manifest.hasOwnProperty(scope) && typeof manifest[scope] !== "object")
throw new SyntaxError(`Package ${scope} must be object: "${path}"`);
};

Expand Down
11 changes: 6 additions & 5 deletions lib/multiSemanticRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ async function getPackage(path, { options: globalOptions, env, cwd, stdout, stde
const name = manifest.name;

// Combine list of all dependency names.
const deps = [
...Object.keys(manifest.dependencies),
...Object.keys(manifest.devDependencies),
...Object.keys(manifest.peerDependencies),
];
const deps = Object.keys({
...manifest.dependencies,
...manifest.devDependencies,
...manifest.peerDependencies,
...manifest.optionalDependencies,
});

// Load the package-specific options.
const { options: pkgOptions } = await getConfig(dir);
Expand Down

0 comments on commit 4b7066c

Please sign in to comment.