@changesets/assemble-release-plan
Advanced tools
Comparing version 0.3.1 to 1.0.0
# @changesets/assemble-release-plan | ||
## 1.0.0 | ||
### Major Changes | ||
- [`cc8c921`](https://github.com/atlassian/changesets/commit/cc8c92143d4c4b7cca8b9917dfc830a40b5cda20) [#290](https://github.com/atlassian/changesets/pull/290) Thanks [@mitchellhamilton](https://github.com/mitchellhamilton)! - Accept `Packages` object instead of `Workspace[]` and remove `dependentsGraph` argument | ||
### Patch Changes | ||
- Updated dependencies [[`41e2e3d`](https://github.com/atlassian/changesets/commit/41e2e3dd1053ff2f35a1a07e60793c9099f26997), [`cc8c921`](https://github.com/atlassian/changesets/commit/cc8c92143d4c4b7cca8b9917dfc830a40b5cda20), [`cc8c921`](https://github.com/atlassian/changesets/commit/cc8c92143d4c4b7cca8b9917dfc830a40b5cda20), [`2363366`](https://github.com/atlassian/changesets/commit/2363366756d1b15bddf6d803911baccfca03cbdf), [`cc8c921`](https://github.com/atlassian/changesets/commit/cc8c92143d4c4b7cca8b9917dfc830a40b5cda20), [`cc8c921`](https://github.com/atlassian/changesets/commit/cc8c92143d4c4b7cca8b9917dfc830a40b5cda20)]: | ||
- @changesets/types@1.0.0 | ||
- @changesets/get-dependents-graph@1.0.0 | ||
- @changesets/config@1.0.0 | ||
## 0.3.1 | ||
@@ -4,0 +17,0 @@ |
@@ -7,6 +7,6 @@ 'use strict'; | ||
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty')); | ||
var semver = require('semver'); | ||
var semver__default = _interopDefault(semver); | ||
var errors = require('@changesets/errors'); | ||
var getDependentsGraph = require('@changesets/get-dependents-graph'); | ||
@@ -44,3 +44,3 @@ function incrementVersion(release, preInfo) { | ||
function getDependents(releases, workspacesByName, dependencyGraph, preInfo) { | ||
function getDependents(releases, packagesByName, dependencyGraph, preInfo) { | ||
let updated = false; // NOTE this is intended to be called recursively | ||
@@ -65,8 +65,8 @@ | ||
let type; | ||
const dependentWorkspace = workspacesByName.get(dependent); | ||
if (!dependentWorkspace) throw new Error("Dependency map is incorrect"); | ||
const dependentPackage = packagesByName.get(dependent); | ||
if (!dependentPackage) throw new Error("Dependency map is incorrect"); | ||
const { | ||
depTypes, | ||
versionRange | ||
} = getDependencyVersionRange(dependentWorkspace.config, nextRelease.name); // Firstly we check if it is a peerDependency because if it is, our dependent bump type needs to be major. | ||
} = getDependencyVersionRange(dependentPackage.packageJson, nextRelease.name); // Firstly we check if it is a peerDependency because if it is, our dependent bump type needs to be major. | ||
@@ -85,3 +85,3 @@ if (depTypes.includes("peerDependencies") && nextRelease.type !== "patch" && (!releases.has(dependent) || releases.has(dependent) && releases.get(dependent).type !== "major")) { | ||
type, | ||
pkgJSON: dependentWorkspace.config | ||
pkgJSON: dependentPackage.packageJson | ||
}; | ||
@@ -149,3 +149,3 @@ }).filter(({ | ||
// package listed in the changesets | ||
function flattenReleases(changesets, workspacesByName) { | ||
function flattenReleases(changesets, packagesByName) { | ||
let releases = new Map(); | ||
@@ -158,12 +158,8 @@ changesets.forEach(changeset => { | ||
let release = releases.get(name); | ||
let ws = workspacesByName.get(name); | ||
let pkg = packagesByName.get(name); | ||
if (!ws) { | ||
if (!pkg) { | ||
throw new Error(`Could not find package information for ${name}`); | ||
} | ||
let { | ||
config | ||
} = ws; | ||
if (!release) { | ||
@@ -173,3 +169,3 @@ release = { | ||
type, | ||
oldVersion: config.version, | ||
oldVersion: pkg.packageJson.version, | ||
changesets: [changeset.id] | ||
@@ -209,3 +205,3 @@ }; | ||
*/ | ||
function applyLinks(releases, workspacesByName, linked) { | ||
function applyLinks(releases, packagesByName, linked) { | ||
let updated = false; | ||
@@ -236,7 +232,7 @@ if (!linked) return updated; // We do this for each set of linked packages | ||
for (let linkedPackage of linkedPackages) { | ||
let workspace = workspacesByName.get(linkedPackage); | ||
let pkg = packagesByName.get(linkedPackage); | ||
if (workspace) { | ||
if (highestVersion === undefined || semver__default.gt(workspace.config.version, highestVersion)) { | ||
highestVersion = workspace.config.version; | ||
if (pkg) { | ||
if (highestVersion === undefined || semver__default.gt(pkg.packageJson.version, highestVersion)) { | ||
highestVersion = pkg.packageJson.version; | ||
} | ||
@@ -269,4 +265,6 @@ } else { | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function getPreVersion(version) { | ||
@@ -284,7 +282,7 @@ let parsed = semver.parse(version); | ||
function assembleReleasePlan(changesets, workspaces, dependentsGraph, config, preState) { | ||
function assembleReleasePlan(changesets, packages, config, preState) { | ||
let updatedPreState = preState === undefined ? undefined : _objectSpread({}, preState, { | ||
initialVersions: _objectSpread({}, preState.initialVersions) | ||
}); | ||
let workspacesByName = new Map(workspaces.map(x => [x.name, x])); | ||
let packagesByName = new Map(packages.packages.map(x => [x.packageJson.name, x])); | ||
let unfilteredChangesets = changesets; | ||
@@ -294,5 +292,5 @@ let preVersions = new Map(); | ||
if (updatedPreState !== undefined) { | ||
for (let workspace of workspaces) { | ||
if (updatedPreState.initialVersions[workspace.name] === undefined) { | ||
updatedPreState.initialVersions[workspace.name] = workspace.config.version; | ||
for (let pkg of packages.packages) { | ||
if (updatedPreState.initialVersions[pkg.packageJson.name] === undefined) { | ||
updatedPreState.initialVersions[pkg.packageJson.name] = pkg.packageJson.version; | ||
} | ||
@@ -306,4 +304,4 @@ } | ||
for (let workspace of workspaces) { | ||
preVersions.set(workspace.name, getPreVersion(workspace.config.version)); | ||
for (let pkg of packages.packages) { | ||
preVersions.set(pkg.packageJson.name, getPreVersion(pkg.packageJson.version)); | ||
} | ||
@@ -315,3 +313,3 @@ | ||
for (let linkedPackage of linkedGroup) { | ||
highestPreVersion = Math.max(getPreVersion(workspacesByName.get(linkedPackage).config.version), highestPreVersion); | ||
highestPreVersion = Math.max(getPreVersion(packagesByName.get(linkedPackage).packageJson.version), highestPreVersion); | ||
} | ||
@@ -325,6 +323,6 @@ | ||
for (let workspace of workspaces) { | ||
workspacesByName.set(workspace.name, _objectSpread({}, workspace, { | ||
config: _objectSpread({}, workspace.config, { | ||
version: updatedPreState.initialVersions[workspace.name] | ||
for (let pkg of packages.packages) { | ||
packagesByName.set(pkg.packageJson.name, _objectSpread({}, pkg, { | ||
packageJson: _objectSpread({}, pkg.packageJson, { | ||
version: updatedPreState.initialVersions[pkg.packageJson.name] | ||
}) | ||
@@ -338,14 +336,14 @@ })); | ||
let releases = flattenReleases(changesets, workspacesByName); | ||
let releases = flattenReleases(changesets, packagesByName); | ||
if (updatedPreState !== undefined) { | ||
if (updatedPreState.mode === "exit") { | ||
for (let workspace of workspaces) { | ||
if (preVersions.get(workspace.name) !== -1) { | ||
if (!releases.has(workspace.name)) { | ||
releases.set(workspace.name, { | ||
for (let pkg of packages.packages) { | ||
if (preVersions.get(pkg.packageJson.name) !== -1) { | ||
if (!releases.has(pkg.packageJson.name)) { | ||
releases.set(pkg.packageJson.name, { | ||
type: "patch", | ||
name: workspace.name, | ||
name: pkg.packageJson.name, | ||
changesets: [], | ||
oldVersion: workspace.config.version | ||
oldVersion: pkg.packageJson.version | ||
}); | ||
@@ -361,3 +359,3 @@ } | ||
// because if they're not being released, the version will already have been bumped with the highest bump type | ||
let releasesFromUnfilteredChangesets = flattenReleases(unfilteredChangesets, workspacesByName); | ||
let releasesFromUnfilteredChangesets = flattenReleases(unfilteredChangesets, packagesByName); | ||
releases.forEach((value, key) => { | ||
@@ -385,2 +383,3 @@ let releaseFromUnfilteredChangesets = releasesFromUnfilteredChangesets.get(key); | ||
}; | ||
let dependentsGraph = getDependentsGraph.getDependentsGraph(packages); | ||
let releaseObjectValidated = false; | ||
@@ -390,5 +389,5 @@ | ||
// The map passed in to determineDependents will be mutated | ||
let dependentAdded = getDependents(releases, workspacesByName, dependentsGraph, preInfo); // The map passed in to determineDependents will be mutated | ||
let dependentAdded = getDependents(releases, packagesByName, dependentsGraph, preInfo); // The map passed in to determineDependents will be mutated | ||
let linksUpdated = applyLinks(releases, workspacesByName, config.linked); | ||
let linksUpdated = applyLinks(releases, packagesByName, config.linked); | ||
releaseObjectValidated = !linksUpdated && !dependentAdded; | ||
@@ -395,0 +394,0 @@ } |
@@ -11,3 +11,3 @@ "use strict"; | ||
var _defineProperty = _interopDefault(require("@babel/runtime/helpers/defineProperty")), semver = require("semver"), semver__default = _interopDefault(semver), errors = require("@changesets/errors"); | ||
var semver = require("semver"), semver__default = _interopDefault(semver), errors = require("@changesets/errors"), getDependentsGraph = require("@changesets/get-dependents-graph"); | ||
@@ -24,3 +24,3 @@ function incrementVersion(release, preInfo) { | ||
function getDependents(releases, workspacesByName, dependencyGraph, preInfo) { | ||
function getDependents(releases, packagesByName, dependencyGraph, preInfo) { | ||
let updated = !1, pkgsToSearch = [ ...releases.values() ]; | ||
@@ -34,5 +34,5 @@ for (;pkgsToSearch.length > 0; ) { | ||
let type; | ||
const dependentWorkspace = workspacesByName.get(dependent); | ||
if (!dependentWorkspace) throw new Error("Dependency map is incorrect"); | ||
const {depTypes: depTypes, versionRange: versionRange} = getDependencyVersionRange(dependentWorkspace.config, nextRelease.name); | ||
const dependentPackage = packagesByName.get(dependent); | ||
if (!dependentPackage) throw new Error("Dependency map is incorrect"); | ||
const {depTypes: depTypes, versionRange: versionRange} = getDependencyVersionRange(dependentPackage.packageJson, nextRelease.name); | ||
return depTypes.includes("peerDependencies") && "patch" !== nextRelease.type && (!releases.has(dependent) || releases.has(dependent) && "major" !== releases.get(dependent).type) ? type = "major" : releases.has(dependent) || semver__default.satisfies(incrementVersion(nextRelease, preInfo), versionRange) || (type = "patch"), | ||
@@ -42,3 +42,3 @@ { | ||
type: type, | ||
pkgJSON: dependentWorkspace.config | ||
pkgJSON: dependentPackage.packageJson | ||
}; | ||
@@ -75,9 +75,8 @@ }).filter(({type: type}) => type).forEach(({name: name, type: type, pkgJSON: pkgJSON}) => { | ||
function flattenReleases(changesets, workspacesByName) { | ||
let releases = new Map(); | ||
function flattenReleases(changesets, packagesByName) { | ||
let releases = new Map; | ||
return changesets.forEach(changeset => { | ||
changeset.releases.forEach(({name: name, type: type}) => { | ||
let release = releases.get(name), ws = workspacesByName.get(name); | ||
if (!ws) throw new Error(`Could not find package information for ${name}`); | ||
let {config: config} = ws; | ||
let release = releases.get(name), pkg = packagesByName.get(name); | ||
if (!pkg) throw new Error(`Could not find package information for ${name}`); | ||
release ? ("minor" === release.type && "major" === type ? release.type = type : "patch" !== release.type || "major" !== type && "minor" !== type || (release.type = type), | ||
@@ -87,3 +86,3 @@ release.changesets.push(changeset.id)) : release = { | ||
type: type, | ||
oldVersion: config.version, | ||
oldVersion: pkg.packageJson.version, | ||
changesets: [ changeset.id ] | ||
@@ -95,3 +94,3 @@ }, releases.set(name, release); | ||
function applyLinks(releases, workspacesByName, linked) { | ||
function applyLinks(releases, packagesByName, linked) { | ||
let updated = !1; | ||
@@ -104,6 +103,6 @@ if (!linked) return updated; | ||
for (let linkedPackage of linkedPackages) { | ||
let workspace = workspacesByName.get(linkedPackage); | ||
if (!workspace) throw console.error(`FATAL ERROR IN CHANGESETS! We were unable to version for linked package: ${linkedPackage} in linkedPackages: ${linkedPackages.toString()}`), | ||
let pkg = packagesByName.get(linkedPackage); | ||
if (!pkg) throw console.error(`FATAL ERROR IN CHANGESETS! We were unable to version for linked package: ${linkedPackage} in linkedPackages: ${linkedPackages.toString()}`), | ||
new Error("fatal: could not resolve linked packages"); | ||
(void 0 === highestVersion || semver__default.gt(workspace.config.version, highestVersion)) && (highestVersion = workspace.config.version); | ||
(void 0 === highestVersion || semver__default.gt(pkg.packageJson.version, highestVersion)) && (highestVersion = pkg.packageJson.version); | ||
} | ||
@@ -123,5 +122,5 @@ if (!highestVersion || !highestReleaseType) throw new Error("Large internal changesets error in calculating linked versions. Please contact the maintainers"); | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function(sym) { | ||
enumerableOnly && (symbols = symbols.filter((function(sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
}))), keys.push.apply(keys, symbols); | ||
} | ||
@@ -134,7 +133,7 @@ return keys; | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(source, !0).forEach(function(key) { | ||
i % 2 ? ownKeys(Object(source), !0).forEach((function(key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(source).forEach(function(key) { | ||
})) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach((function(key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
})); | ||
} | ||
@@ -144,38 +143,47 @@ return target; | ||
function _defineProperty(obj, key, value) { | ||
return key in obj ? Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}) : obj[key] = value, obj; | ||
} | ||
function getPreVersion(version) { | ||
let parsed = semver.parse(version), preVersion = void 0 === parsed.prerelease[1] ? -1 : parsed.prerelease[1]; | ||
if ("number" != typeof preVersion) throw new errors.InternalError("preVersion is not a number"); | ||
return ++preVersion; | ||
return preVersion++, preVersion; | ||
} | ||
function assembleReleasePlan(changesets, workspaces, dependentsGraph, config, preState) { | ||
function assembleReleasePlan(changesets, packages, config, preState) { | ||
let updatedPreState = void 0 === preState ? void 0 : _objectSpread({}, preState, { | ||
initialVersions: _objectSpread({}, preState.initialVersions) | ||
}), workspacesByName = new Map(workspaces.map(x => [ x.name, x ])), unfilteredChangesets = changesets, preVersions = new Map(); | ||
}), packagesByName = new Map(packages.packages.map(x => [ x.packageJson.name, x ])), unfilteredChangesets = changesets, preVersions = new Map; | ||
if (void 0 !== updatedPreState) { | ||
for (let workspace of workspaces) void 0 === updatedPreState.initialVersions[workspace.name] && (updatedPreState.initialVersions[workspace.name] = workspace.config.version); | ||
for (let pkg of packages.packages) void 0 === updatedPreState.initialVersions[pkg.packageJson.name] && (updatedPreState.initialVersions[pkg.packageJson.name] = pkg.packageJson.version); | ||
if ("exit" !== updatedPreState.mode) { | ||
let usedChangesetIds = new Set(updatedPreState.changesets); | ||
updatedPreState.changesets = changesets.map(x => x.id), changesets = changesets.filter(changeset => !usedChangesetIds.has(changeset.id)); | ||
for (let workspace of workspaces) preVersions.set(workspace.name, getPreVersion(workspace.config.version)); | ||
for (let pkg of packages.packages) preVersions.set(pkg.packageJson.name, getPreVersion(pkg.packageJson.version)); | ||
for (let linkedGroup of config.linked) { | ||
let highestPreVersion = 0; | ||
for (let linkedPackage of linkedGroup) highestPreVersion = Math.max(getPreVersion(workspacesByName.get(linkedPackage).config.version), highestPreVersion); | ||
for (let linkedPackage of linkedGroup) highestPreVersion = Math.max(getPreVersion(packagesByName.get(linkedPackage).packageJson.version), highestPreVersion); | ||
for (let linkedPackage of linkedGroup) preVersions.set(linkedPackage, highestPreVersion); | ||
} | ||
} | ||
for (let workspace of workspaces) workspacesByName.set(workspace.name, _objectSpread({}, workspace, { | ||
config: _objectSpread({}, workspace.config, { | ||
version: updatedPreState.initialVersions[workspace.name] | ||
for (let pkg of packages.packages) packagesByName.set(pkg.packageJson.name, _objectSpread({}, pkg, { | ||
packageJson: _objectSpread({}, pkg.packageJson, { | ||
version: updatedPreState.initialVersions[pkg.packageJson.name] | ||
}) | ||
})); | ||
} | ||
let releases = flattenReleases(changesets, workspacesByName); | ||
if (void 0 !== updatedPreState) if ("exit" === updatedPreState.mode) for (let workspace of workspaces) -1 !== preVersions.get(workspace.name) && (releases.has(workspace.name) || releases.set(workspace.name, { | ||
let releases = flattenReleases(changesets, packagesByName); | ||
if (void 0 !== updatedPreState) if ("exit" === updatedPreState.mode) for (let pkg of packages.packages) -1 !== preVersions.get(pkg.packageJson.name) && (releases.has(pkg.packageJson.name) || releases.set(pkg.packageJson.name, { | ||
type: "patch", | ||
name: workspace.name, | ||
name: pkg.packageJson.name, | ||
changesets: [], | ||
oldVersion: workspace.config.version | ||
oldVersion: pkg.packageJson.version | ||
})); else { | ||
let releasesFromUnfilteredChangesets = flattenReleases(unfilteredChangesets, workspacesByName); | ||
let releasesFromUnfilteredChangesets = flattenReleases(unfilteredChangesets, packagesByName); | ||
releases.forEach((value, key) => { | ||
@@ -192,6 +200,6 @@ let releaseFromUnfilteredChangesets = releasesFromUnfilteredChangesets.get(key); | ||
preVersions: preVersions | ||
}, releaseObjectValidated = !1; | ||
}, dependentsGraph = getDependentsGraph.getDependentsGraph(packages), releaseObjectValidated = !1; | ||
for (;!1 === releaseObjectValidated; ) { | ||
let dependentAdded = getDependents(releases, workspacesByName, dependentsGraph, preInfo); | ||
releaseObjectValidated = !applyLinks(releases, workspacesByName, config.linked) && !dependentAdded; | ||
let dependentAdded = getDependents(releases, packagesByName, dependentsGraph, preInfo); | ||
releaseObjectValidated = !applyLinks(releases, packagesByName, config.linked) && !dependentAdded; | ||
} | ||
@@ -198,0 +206,0 @@ return { |
@@ -1,4 +0,4 @@ | ||
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty'; | ||
import semver__default, { inc, parse } from 'semver'; | ||
import { InternalError } from '@changesets/errors'; | ||
import { getDependentsGraph } from '@changesets/get-dependents-graph'; | ||
@@ -36,3 +36,3 @@ function incrementVersion(release, preInfo) { | ||
function getDependents(releases, workspacesByName, dependencyGraph, preInfo) { | ||
function getDependents(releases, packagesByName, dependencyGraph, preInfo) { | ||
let updated = false; // NOTE this is intended to be called recursively | ||
@@ -57,8 +57,8 @@ | ||
let type; | ||
const dependentWorkspace = workspacesByName.get(dependent); | ||
if (!dependentWorkspace) throw new Error("Dependency map is incorrect"); | ||
const dependentPackage = packagesByName.get(dependent); | ||
if (!dependentPackage) throw new Error("Dependency map is incorrect"); | ||
const { | ||
depTypes, | ||
versionRange | ||
} = getDependencyVersionRange(dependentWorkspace.config, nextRelease.name); // Firstly we check if it is a peerDependency because if it is, our dependent bump type needs to be major. | ||
} = getDependencyVersionRange(dependentPackage.packageJson, nextRelease.name); // Firstly we check if it is a peerDependency because if it is, our dependent bump type needs to be major. | ||
@@ -77,3 +77,3 @@ if (depTypes.includes("peerDependencies") && nextRelease.type !== "patch" && (!releases.has(dependent) || releases.has(dependent) && releases.get(dependent).type !== "major")) { | ||
type, | ||
pkgJSON: dependentWorkspace.config | ||
pkgJSON: dependentPackage.packageJson | ||
}; | ||
@@ -141,3 +141,3 @@ }).filter(({ | ||
// package listed in the changesets | ||
function flattenReleases(changesets, workspacesByName) { | ||
function flattenReleases(changesets, packagesByName) { | ||
let releases = new Map(); | ||
@@ -150,12 +150,8 @@ changesets.forEach(changeset => { | ||
let release = releases.get(name); | ||
let ws = workspacesByName.get(name); | ||
let pkg = packagesByName.get(name); | ||
if (!ws) { | ||
if (!pkg) { | ||
throw new Error(`Could not find package information for ${name}`); | ||
} | ||
let { | ||
config | ||
} = ws; | ||
if (!release) { | ||
@@ -165,3 +161,3 @@ release = { | ||
type, | ||
oldVersion: config.version, | ||
oldVersion: pkg.packageJson.version, | ||
changesets: [changeset.id] | ||
@@ -201,3 +197,3 @@ }; | ||
*/ | ||
function applyLinks(releases, workspacesByName, linked) { | ||
function applyLinks(releases, packagesByName, linked) { | ||
let updated = false; | ||
@@ -228,7 +224,7 @@ if (!linked) return updated; // We do this for each set of linked packages | ||
for (let linkedPackage of linkedPackages) { | ||
let workspace = workspacesByName.get(linkedPackage); | ||
let pkg = packagesByName.get(linkedPackage); | ||
if (workspace) { | ||
if (highestVersion === undefined || semver__default.gt(workspace.config.version, highestVersion)) { | ||
highestVersion = workspace.config.version; | ||
if (pkg) { | ||
if (highestVersion === undefined || semver__default.gt(pkg.packageJson.version, highestVersion)) { | ||
highestVersion = pkg.packageJson.version; | ||
} | ||
@@ -261,4 +257,6 @@ } else { | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function getPreVersion(version) { | ||
@@ -276,7 +274,7 @@ let parsed = parse(version); | ||
function assembleReleasePlan(changesets, workspaces, dependentsGraph, config, preState) { | ||
function assembleReleasePlan(changesets, packages, config, preState) { | ||
let updatedPreState = preState === undefined ? undefined : _objectSpread({}, preState, { | ||
initialVersions: _objectSpread({}, preState.initialVersions) | ||
}); | ||
let workspacesByName = new Map(workspaces.map(x => [x.name, x])); | ||
let packagesByName = new Map(packages.packages.map(x => [x.packageJson.name, x])); | ||
let unfilteredChangesets = changesets; | ||
@@ -286,5 +284,5 @@ let preVersions = new Map(); | ||
if (updatedPreState !== undefined) { | ||
for (let workspace of workspaces) { | ||
if (updatedPreState.initialVersions[workspace.name] === undefined) { | ||
updatedPreState.initialVersions[workspace.name] = workspace.config.version; | ||
for (let pkg of packages.packages) { | ||
if (updatedPreState.initialVersions[pkg.packageJson.name] === undefined) { | ||
updatedPreState.initialVersions[pkg.packageJson.name] = pkg.packageJson.version; | ||
} | ||
@@ -298,4 +296,4 @@ } | ||
for (let workspace of workspaces) { | ||
preVersions.set(workspace.name, getPreVersion(workspace.config.version)); | ||
for (let pkg of packages.packages) { | ||
preVersions.set(pkg.packageJson.name, getPreVersion(pkg.packageJson.version)); | ||
} | ||
@@ -307,3 +305,3 @@ | ||
for (let linkedPackage of linkedGroup) { | ||
highestPreVersion = Math.max(getPreVersion(workspacesByName.get(linkedPackage).config.version), highestPreVersion); | ||
highestPreVersion = Math.max(getPreVersion(packagesByName.get(linkedPackage).packageJson.version), highestPreVersion); | ||
} | ||
@@ -317,6 +315,6 @@ | ||
for (let workspace of workspaces) { | ||
workspacesByName.set(workspace.name, _objectSpread({}, workspace, { | ||
config: _objectSpread({}, workspace.config, { | ||
version: updatedPreState.initialVersions[workspace.name] | ||
for (let pkg of packages.packages) { | ||
packagesByName.set(pkg.packageJson.name, _objectSpread({}, pkg, { | ||
packageJson: _objectSpread({}, pkg.packageJson, { | ||
version: updatedPreState.initialVersions[pkg.packageJson.name] | ||
}) | ||
@@ -330,14 +328,14 @@ })); | ||
let releases = flattenReleases(changesets, workspacesByName); | ||
let releases = flattenReleases(changesets, packagesByName); | ||
if (updatedPreState !== undefined) { | ||
if (updatedPreState.mode === "exit") { | ||
for (let workspace of workspaces) { | ||
if (preVersions.get(workspace.name) !== -1) { | ||
if (!releases.has(workspace.name)) { | ||
releases.set(workspace.name, { | ||
for (let pkg of packages.packages) { | ||
if (preVersions.get(pkg.packageJson.name) !== -1) { | ||
if (!releases.has(pkg.packageJson.name)) { | ||
releases.set(pkg.packageJson.name, { | ||
type: "patch", | ||
name: workspace.name, | ||
name: pkg.packageJson.name, | ||
changesets: [], | ||
oldVersion: workspace.config.version | ||
oldVersion: pkg.packageJson.version | ||
}); | ||
@@ -353,3 +351,3 @@ } | ||
// because if they're not being released, the version will already have been bumped with the highest bump type | ||
let releasesFromUnfilteredChangesets = flattenReleases(unfilteredChangesets, workspacesByName); | ||
let releasesFromUnfilteredChangesets = flattenReleases(unfilteredChangesets, packagesByName); | ||
releases.forEach((value, key) => { | ||
@@ -377,2 +375,3 @@ let releaseFromUnfilteredChangesets = releasesFromUnfilteredChangesets.get(key); | ||
}; | ||
let dependentsGraph = getDependentsGraph(packages); | ||
let releaseObjectValidated = false; | ||
@@ -382,5 +381,5 @@ | ||
// The map passed in to determineDependents will be mutated | ||
let dependentAdded = getDependents(releases, workspacesByName, dependentsGraph, preInfo); // The map passed in to determineDependents will be mutated | ||
let dependentAdded = getDependents(releases, packagesByName, dependentsGraph, preInfo); // The map passed in to determineDependents will be mutated | ||
let linksUpdated = applyLinks(releases, workspacesByName, config.linked); | ||
let linksUpdated = applyLinks(releases, packagesByName, config.linked); | ||
releaseObjectValidated = !linksUpdated && !dependentAdded; | ||
@@ -387,0 +386,0 @@ } |
@@ -1,4 +0,5 @@ | ||
import { Linked, Workspace } from "@changesets/types"; | ||
import { Package } from "@manypkg/get-packages"; | ||
import { Linked } from "@changesets/types"; | ||
import { InternalRelease } from "./types"; | ||
declare function applyLinks(releases: Map<string, InternalRelease>, workspacesByName: Map<string, Workspace>, linked: Linked): boolean; | ||
declare function applyLinks(releases: Map<string, InternalRelease>, packagesByName: Map<string, Package>, linked: Linked): boolean; | ||
export default applyLinks; |
@@ -1,3 +0,3 @@ | ||
import { Workspace } from "@changesets/types"; | ||
import { Package } from "@manypkg/get-packages"; | ||
import { InternalRelease, PreInfo } from "./types"; | ||
export default function getDependents(releases: Map<string, InternalRelease>, workspacesByName: Map<string, Workspace>, dependencyGraph: Map<string, string[]>, preInfo: PreInfo | undefined): boolean; | ||
export default function getDependents(releases: Map<string, InternalRelease>, packagesByName: Map<string, Package>, dependencyGraph: Map<string, string[]>, preInfo: PreInfo | undefined): boolean; |
@@ -1,3 +0,4 @@ | ||
import { NewChangeset, Workspace } from "@changesets/types"; | ||
import { NewChangeset } from "@changesets/types"; | ||
import { Package } from "@manypkg/get-packages"; | ||
import { InternalRelease } from "./types"; | ||
export default function flattenReleases(changesets: NewChangeset[], workspacesByName: Map<string, Workspace>): Map<string, InternalRelease>; | ||
export default function flattenReleases(changesets: NewChangeset[], packagesByName: Map<string, Package>): Map<string, InternalRelease>; |
@@ -1,3 +0,4 @@ | ||
import { ReleasePlan, Workspace, Config, NewChangeset, PreState } from "@changesets/types"; | ||
declare function assembleReleasePlan(changesets: NewChangeset[], workspaces: Workspace[], dependentsGraph: Map<string, string[]>, config: Config, preState: PreState | undefined): ReleasePlan; | ||
import { ReleasePlan, Config, NewChangeset, PreState } from "@changesets/types"; | ||
import { Packages } from "@manypkg/get-packages"; | ||
declare function assembleReleasePlan(changesets: NewChangeset[], packages: Packages, config: Config, preState: PreState | undefined): ReleasePlan; | ||
export default assembleReleasePlan; |
{ | ||
"name": "@changesets/assemble-release-plan", | ||
"version": "0.3.1", | ||
"version": "1.0.0", | ||
"description": "Reads changesets and adds information on dependents that need bumping", | ||
@@ -12,3 +12,5 @@ "main": "dist/assemble-release-plan.cjs.js", | ||
"@changesets/errors": "^0.1.2", | ||
"@changesets/types": "^0.4.0", | ||
"@changesets/get-dependents-graph": "^1.0.0", | ||
"@changesets/types": "^1.0.0", | ||
"@manypkg/get-packages": "^1.0.0", | ||
"semver": "^5.4.1" | ||
@@ -15,0 +17,0 @@ }, |
@@ -9,9 +9,13 @@ # Assemble Release Plan | ||
import assembleReleasePlan from "@changesets/assemble-release-plan"; | ||
import readChangesets from "@changesets/read"; | ||
import { read } from "@changesets/config"; | ||
import { getPackages } from "@manypkg/get-packages"; | ||
import { readPreState } from "@changesets/pre"; | ||
const releasePlan = await assembleReleasePlan( | ||
changesets, | ||
workspaces, | ||
dependentsGraph, | ||
config | ||
); | ||
const packages = await getPackages(cwd); | ||
const preState = await readPreState(cwd); | ||
const config = await read(cwd, packages); | ||
const changesets = await readChangesets(cwd, sinceRef); | ||
const releasePlan = assembleReleasePlan(changesets, packages, config, preState); | ||
``` | ||
@@ -22,13 +26,8 @@ | ||
```ts | ||
import { | ||
NewChangeset, | ||
Workspace, | ||
Config, | ||
ReleasePlan | ||
} from "@changesets/types"; | ||
import { NewChangeset, Config, ReleasePlan } from "@changesets/types"; | ||
import { Packages } from "@manypkg/get-packages"; | ||
assembleReleasePlan = ( | ||
changesets: NewChangeset[], | ||
workspaces: Workspace[], | ||
dependentsGraph: Map<string, string[]>, | ||
packages: Packages, | ||
config: Config | ||
@@ -35,0 +34,0 @@ ) => ReleasePlan; |
import semver from "semver"; | ||
import { Linked, Workspace, VersionType } from "@changesets/types"; | ||
import { Package } from "@manypkg/get-packages"; | ||
import { Linked, VersionType } from "@changesets/types"; | ||
import { InternalRelease } from "./types"; | ||
@@ -19,3 +20,3 @@ | ||
releases: Map<string, InternalRelease>, | ||
workspacesByName: Map<string, Workspace>, | ||
packagesByName: Map<string, Package>, | ||
linked: Linked | ||
@@ -53,10 +54,10 @@ ): boolean { | ||
for (let linkedPackage of linkedPackages) { | ||
let workspace = workspacesByName.get(linkedPackage); | ||
let pkg = packagesByName.get(linkedPackage); | ||
if (workspace) { | ||
if (pkg) { | ||
if ( | ||
highestVersion === undefined || | ||
semver.gt(workspace.config.version, highestVersion) | ||
semver.gt(pkg.packageJson.version, highestVersion) | ||
) { | ||
highestVersion = workspace.config.version; | ||
highestVersion = pkg.packageJson.version; | ||
} | ||
@@ -63,0 +64,0 @@ } else { |
import semver from "semver"; | ||
import { | ||
Release, | ||
Workspace, | ||
DependencyType, | ||
@@ -9,2 +8,3 @@ PackageJSON, | ||
} from "@changesets/types"; | ||
import { Package } from "@manypkg/get-packages"; | ||
import { InternalRelease, PreInfo } from "./types"; | ||
@@ -27,3 +27,3 @@ import { incrementVersion } from "./increment"; | ||
releases: Map<string, InternalRelease>, | ||
workspacesByName: Map<string, Workspace>, | ||
packagesByName: Map<string, Package>, | ||
dependencyGraph: Map<string, string[]>, | ||
@@ -53,6 +53,6 @@ preInfo: PreInfo | undefined | ||
const dependentWorkspace = workspacesByName.get(dependent); | ||
if (!dependentWorkspace) throw new Error("Dependency map is incorrect"); | ||
const dependentPackage = packagesByName.get(dependent); | ||
if (!dependentPackage) throw new Error("Dependency map is incorrect"); | ||
const { depTypes, versionRange } = getDependencyVersionRange( | ||
dependentWorkspace.config, | ||
dependentPackage.packageJson, | ||
nextRelease.name | ||
@@ -82,3 +82,3 @@ ); | ||
} | ||
return { name: dependent, type, pkgJSON: dependentWorkspace.config }; | ||
return { name: dependent, type, pkgJSON: dependentPackage.packageJson }; | ||
}) | ||
@@ -85,0 +85,0 @@ .filter(({ type }) => type) |
// This function takes in changesets and returns one release per | ||
// package listed in the changesets | ||
import { NewChangeset, Workspace } from "@changesets/types"; | ||
import { NewChangeset } from "@changesets/types"; | ||
import { Package } from "@manypkg/get-packages"; | ||
import { InternalRelease } from "./types"; | ||
@@ -9,3 +10,3 @@ | ||
changesets: NewChangeset[], | ||
workspacesByName: Map<string, Workspace> | ||
packagesByName: Map<string, Package> | ||
): Map<string, InternalRelease> { | ||
@@ -17,7 +18,6 @@ let releases: Map<string, InternalRelease> = new Map(); | ||
let release = releases.get(name); | ||
let ws = workspacesByName.get(name); | ||
if (!ws) { | ||
let pkg = packagesByName.get(name); | ||
if (!pkg) { | ||
throw new Error(`Could not find package information for ${name}`); | ||
} | ||
let { config } = ws; | ||
if (!release) { | ||
@@ -27,3 +27,3 @@ release = { | ||
type, | ||
oldVersion: config.version, | ||
oldVersion: pkg.packageJson.version, | ||
changesets: [changeset.id] | ||
@@ -30,0 +30,0 @@ }; |
@@ -10,5 +10,5 @@ import { defaultConfig } from "@changesets/config"; | ||
setup.addWorkspace("pkg-b", "1.0.0"); | ||
setup.addWorkspace("pkg-c", "1.0.0"); | ||
setup.addWorkspace("pkg-d", "1.0.0"); | ||
setup.addPackage("pkg-b", "1.0.0"); | ||
setup.addPackage("pkg-c", "1.0.0"); | ||
setup.addPackage("pkg-d", "1.0.0"); | ||
}); | ||
@@ -19,4 +19,3 @@ | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -47,4 +46,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -72,4 +70,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -93,4 +90,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -115,4 +111,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"]] }, | ||
@@ -135,8 +130,7 @@ undefined | ||
setup.updateWorkspace("pkg-c", "2.0.0"); | ||
setup.updatePackage("pkg-c", "2.0.0"); | ||
let { releases } = assembleReleasePlan( | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
{ ...defaultConfig, linked: [["pkg-a", "pkg-b", "pkg-c"]] }, | ||
@@ -171,4 +165,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"], ["pkg-c", "pkg-d"]] }, | ||
@@ -187,4 +180,3 @@ undefined | ||
[], | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"], ["pkg-c", "pkg-d"]] }, | ||
@@ -202,4 +194,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"], ["pkg-c", "pkg-d"]] }, | ||
@@ -223,4 +214,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
{ ...defaultConfig, linked: [["pkg-a", "pkg-b"], ["pkg-c", "pkg-d"]] }, | ||
@@ -249,4 +239,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
{ ...defaultConfig, linked: [["pkg-a", "pkg-c"]] }, | ||
@@ -280,4 +269,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -300,5 +288,5 @@ undefined | ||
setup.addWorkspace("pkg-b", "1.0.0"); | ||
setup.addWorkspace("pkg-c", "1.0.0"); | ||
setup.addWorkspace("pkg-d", "1.0.0"); | ||
setup.addPackage("pkg-b", "1.0.0"); | ||
setup.addPackage("pkg-c", "1.0.0"); | ||
setup.addPackage("pkg-d", "1.0.0"); | ||
setup.updateDependency("pkg-b", "pkg-a", "1.0.0"); | ||
@@ -312,4 +300,3 @@ setup.updateDependency("pkg-c", "pkg-a", "~1.0.0"); | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -332,4 +319,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -355,4 +341,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -378,3 +363,3 @@ undefined | ||
setup = new FakeFullState(); | ||
setup.addWorkspace("pkg-b", "1.0.0"); | ||
setup.addPackage("pkg-b", "1.0.0"); | ||
}); | ||
@@ -387,4 +372,3 @@ | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -405,4 +389,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -425,4 +408,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -447,4 +429,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -465,4 +446,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -485,4 +465,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -507,4 +486,3 @@ undefined | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -522,3 +500,3 @@ undefined | ||
setup.updatePeerDep("pkg-b", "pkg-a", "^1.0.0"); | ||
setup.addWorkspace("pkg-c", "1.0.0"); | ||
setup.addPackage("pkg-c", "1.0.0"); | ||
setup.updateDependency("pkg-c", "pkg-b", "^1.0.0"); | ||
@@ -532,4 +510,3 @@ setup.addChangeset({ | ||
setup.changesets, | ||
setup.workspaces, | ||
setup.dependentsGraph, | ||
setup.packages, | ||
defaultConfig, | ||
@@ -536,0 +513,0 @@ undefined |
@@ -1,8 +0,2 @@ | ||
import { | ||
ReleasePlan, | ||
Workspace, | ||
Config, | ||
NewChangeset, | ||
PreState | ||
} from "@changesets/types"; | ||
import { ReleasePlan, Config, NewChangeset, PreState } from "@changesets/types"; | ||
import determineDependents from "./determine-dependents"; | ||
@@ -14,2 +8,4 @@ import flattenReleases from "./flatten-releases"; | ||
import { InternalError } from "@changesets/errors"; | ||
import { Packages } from "@manypkg/get-packages"; | ||
import { getDependentsGraph } from "@changesets/get-dependents-graph"; | ||
import { PreInfo } from "./types"; | ||
@@ -30,4 +26,3 @@ | ||
changesets: NewChangeset[], | ||
workspaces: Workspace[], | ||
dependentsGraph: Map<string, string[]>, | ||
packages: Packages, | ||
config: Config, | ||
@@ -46,3 +41,5 @@ preState: PreState | undefined | ||
let workspacesByName = new Map(workspaces.map(x => [x.name, x])); | ||
let packagesByName = new Map( | ||
packages.packages.map(x => [x.packageJson.name, x]) | ||
); | ||
@@ -53,6 +50,6 @@ let unfilteredChangesets = changesets; | ||
if (updatedPreState !== undefined) { | ||
for (let workspace of workspaces) { | ||
if (updatedPreState.initialVersions[workspace.name] === undefined) { | ||
updatedPreState.initialVersions[workspace.name] = | ||
workspace.config.version; | ||
for (let pkg of packages.packages) { | ||
if (updatedPreState.initialVersions[pkg.packageJson.name] === undefined) { | ||
updatedPreState.initialVersions[pkg.packageJson.name] = | ||
pkg.packageJson.version; | ||
} | ||
@@ -66,6 +63,6 @@ } | ||
); | ||
for (let workspace of workspaces) { | ||
for (let pkg of packages.packages) { | ||
preVersions.set( | ||
workspace.name, | ||
getPreVersion(workspace.config.version) | ||
pkg.packageJson.name, | ||
getPreVersion(pkg.packageJson.version) | ||
); | ||
@@ -77,3 +74,5 @@ } | ||
highestPreVersion = Math.max( | ||
getPreVersion(workspacesByName.get(linkedPackage)!.config.version), | ||
getPreVersion( | ||
packagesByName.get(linkedPackage)!.packageJson.version | ||
), | ||
highestPreVersion | ||
@@ -87,8 +86,8 @@ ); | ||
} | ||
for (let workspace of workspaces) { | ||
workspacesByName.set(workspace.name, { | ||
...workspace, | ||
config: { | ||
...workspace.config, | ||
version: updatedPreState.initialVersions[workspace.name] | ||
for (let pkg of packages.packages) { | ||
packagesByName.set(pkg.packageJson.name, { | ||
...pkg, | ||
packageJson: { | ||
...pkg.packageJson, | ||
version: updatedPreState.initialVersions[pkg.packageJson.name] | ||
} | ||
@@ -102,14 +101,14 @@ }); | ||
// changesets, and with a calculated new versions | ||
let releases = flattenReleases(changesets, workspacesByName); | ||
let releases = flattenReleases(changesets, packagesByName); | ||
if (updatedPreState !== undefined) { | ||
if (updatedPreState.mode === "exit") { | ||
for (let workspace of workspaces) { | ||
if (preVersions.get(workspace.name) !== -1) { | ||
if (!releases.has(workspace.name)) { | ||
releases.set(workspace.name, { | ||
for (let pkg of packages.packages) { | ||
if (preVersions.get(pkg.packageJson.name) !== -1) { | ||
if (!releases.has(pkg.packageJson.name)) { | ||
releases.set(pkg.packageJson.name, { | ||
type: "patch", | ||
name: workspace.name, | ||
name: pkg.packageJson.name, | ||
changesets: [], | ||
oldVersion: workspace.config.version | ||
oldVersion: pkg.packageJson.version | ||
}); | ||
@@ -127,3 +126,3 @@ } | ||
unfilteredChangesets, | ||
workspacesByName | ||
packagesByName | ||
); | ||
@@ -161,2 +160,4 @@ | ||
let dependentsGraph = getDependentsGraph(packages); | ||
let releaseObjectValidated = false; | ||
@@ -167,3 +168,3 @@ while (releaseObjectValidated === false) { | ||
releases, | ||
workspacesByName, | ||
packagesByName, | ||
dependentsGraph, | ||
@@ -174,3 +175,3 @@ preInfo | ||
// The map passed in to determineDependents will be mutated | ||
let linksUpdated = applyLinks(releases, workspacesByName, config.linked); | ||
let linksUpdated = applyLinks(releases, packagesByName, config.linked); | ||
@@ -177,0 +178,0 @@ releaseObjectValidated = !linksUpdated && !dependentAdded; |
@@ -1,37 +0,10 @@ | ||
import { | ||
NewChangeset, | ||
Workspace, | ||
Config, | ||
Release, | ||
VersionType | ||
} from "@changesets/types"; | ||
import { NewChangeset, Release, VersionType } from "@changesets/types"; | ||
import { Package, Packages } from "@manypkg/get-packages"; | ||
function getFakeData( | ||
data: { | ||
changesets?: NewChangeset[]; | ||
workspaces?: Workspace[]; | ||
dependentsGraph?: Map<string, string[]>; | ||
config?: Config; | ||
} = {} | ||
) { | ||
let changesets = data.changesets || []; | ||
let workspaces = data.workspaces || []; | ||
let dependentsGraph = data.dependentsGraph || new Map(); | ||
let config = data.config || {}; | ||
return { | ||
changesets, | ||
workspaces, | ||
dependentsGraph, | ||
config | ||
}; | ||
} | ||
function getWorkspace( | ||
function getPackage( | ||
name: string = "pkg-a", | ||
version: string = "1.0.0" | ||
): Workspace { | ||
): Package { | ||
return { | ||
name, | ||
config: { | ||
packageJson: { | ||
name, | ||
@@ -68,42 +41,25 @@ version | ||
function getDependentsGraph( | ||
thing: [[string, Array<String>]] = [["pkg-a", []]] | ||
) { | ||
let map = new Map(); | ||
for (let acity of thing) { | ||
let [name, depenents] = acity; | ||
map.set(name, depenents); | ||
} | ||
return map; | ||
} | ||
let getSimpleSetup = () => ({ | ||
packages: { | ||
root: { | ||
packageJson: { | ||
name: "root", | ||
version: "0.0.0" | ||
}, | ||
dir: "/" | ||
}, | ||
packages: [getPackage()], | ||
tool: "yarn" as const | ||
}, | ||
changesets: [getChangeset({ releases: [getRelease()] })] | ||
}); | ||
function getSimpleSetup( | ||
custom: { | ||
workspaces?: Workspace[]; | ||
changesets?: NewChangeset[]; | ||
dependentsGraph?: Map<string, string[]>; | ||
} = {} | ||
) { | ||
return getFakeData({ | ||
workspaces: [getWorkspace()], | ||
changesets: [getChangeset({ releases: [getRelease()] })], | ||
dependentsGraph: getDependentsGraph(), | ||
...custom | ||
}); | ||
} | ||
class FakeFullState { | ||
workspaces: Workspace[]; | ||
packages: Packages; | ||
changesets: NewChangeset[]; | ||
dependentsGraph: Map<string, string[]>; | ||
constructor(custom?: { | ||
workspaces?: Workspace[]; | ||
changesets?: NewChangeset[]; | ||
dependentsGraph?: Map<string, string[]>; | ||
}) { | ||
let { workspaces, changesets, dependentsGraph } = getSimpleSetup(custom); | ||
this.workspaces = workspaces; | ||
constructor(custom?: { packages?: Packages; changesets?: NewChangeset[] }) { | ||
let { packages, changesets } = { ...getSimpleSetup(), ...custom }; | ||
this.packages = packages; | ||
this.changesets = changesets; | ||
this.dependentsGraph = dependentsGraph; | ||
} | ||
@@ -128,40 +84,39 @@ | ||
updateDependency(pkgA: string, pkgB: string, version: string) { | ||
let ws = this.workspaces.find(a => a.name === pkgA); | ||
if (!ws) throw new Error("no ws"); | ||
if (!ws.config.dependencies) ws.config.dependencies = {}; | ||
ws.config.dependencies[pkgB] = version; | ||
let depList = this.dependentsGraph.get(pkgB); | ||
if (!depList) throw new Error("could not add dependency"); | ||
this.dependentsGraph.set(pkgB, [...depList, pkgA]); | ||
let pkg = this.packages.packages.find(a => a.packageJson.name === pkgA); | ||
if (!pkg) throw new Error("no pkg"); | ||
if (!pkg.packageJson.dependencies) { | ||
pkg.packageJson.dependencies = {}; | ||
} | ||
pkg.packageJson.dependencies[pkgB] = version; | ||
} | ||
updatePeerDep(pkgA: string, pkgB: string, version: string) { | ||
let ws = this.workspaces.find(a => a.name === pkgA); | ||
if (!ws) throw new Error("no ws"); | ||
if (!ws.config.peerDependencies) ws.config.peerDependencies = {}; | ||
ws.config.peerDependencies[pkgB] = version; | ||
let depList = this.dependentsGraph.get(pkgB); | ||
if (!depList) throw new Error("could not add dependency"); | ||
this.dependentsGraph.set(pkgB, [...depList, pkgA]); | ||
let pkg = this.packages.packages.find(a => a.packageJson.name === pkgA); | ||
if (!pkg) throw new Error("no pkg"); | ||
if (!pkg.packageJson.peerDependencies) { | ||
pkg.packageJson.peerDependencies = {}; | ||
} | ||
pkg.packageJson.peerDependencies[pkgB] = version; | ||
} | ||
addWorkspace(name: string, version: string) { | ||
let ws = getWorkspace(name, version); | ||
if (this.workspaces.find(c => c.name === ws.name)) { | ||
addPackage(name: string, version: string) { | ||
let pkg = getPackage(name, version); | ||
if ( | ||
this.packages.packages.find( | ||
c => c.packageJson.name === pkg.packageJson.name | ||
) | ||
) { | ||
throw new Error( | ||
`tried to add a second workspace with same name': ${ws.name}` | ||
`tried to add a second package with same name': ${pkg.packageJson.name}` | ||
); | ||
} | ||
this.workspaces.push(ws); | ||
this.dependentsGraph.set(name, []); | ||
this.packages.packages.push(pkg); | ||
} | ||
updateWorkspace(name: string, version: string) { | ||
let ws = this.workspaces.find(c => c.name === name); | ||
if (!ws) { | ||
updatePackage(name: string, version: string) { | ||
let pkg = this.packages.packages.find(c => c.packageJson.name === name); | ||
if (!pkg) { | ||
throw new Error( | ||
`could not update workspace ${name} because it doesn't exist - try addWorskpace` | ||
`could not update package ${name} because it doesn't exist - try addWorskpace` | ||
); | ||
} | ||
ws.config.version = version; | ||
pkg.packageJson.version = version; | ||
} | ||
@@ -168,0 +123,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
84933
1
0
6
1883
41
+ Added@manypkg/get-packages@^1.0.0
+ Added@changesets/get-dependents-graph@1.3.6(transitive)
+ Added@changesets/types@1.0.14.1.05.2.1(transitive)
+ Added@manypkg/find-root@1.1.0(transitive)
+ Added@manypkg/get-packages@1.1.3(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@types/node@12.20.55(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedarray-union@2.1.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addeddir-glob@3.0.1(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedfs-extra@7.0.18.1.0(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedglobby@11.1.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedjsonfile@4.0.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-type@4.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedpify@4.0.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedread-yaml-file@1.1.0(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addeduniversalify@0.1.2(transitive)
- Removed@changesets/types@0.4.0(transitive)
Updated@changesets/types@^1.0.0