Socket
Socket
Sign inDemoInstall

@covector/assemble

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@covector/assemble - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0

__snapshots__/index.test.ts.snap

23

CHANGELOG.md
# Changelog
## \[0.7.0]
- Adjust output from assemble and covector to expose the template that is piped into each command. This allows us to set it as an output in the github action.
- [5797e79](https://www.github.com/jbolda/covector/commit/5797e792f532ad9bcb40c19cda080ca7713c0d91) feat: github action output template pipe ([#208](https://www.github.com/jbolda/covector/pull/208)) on 2021-05-18
- Assemble considers preMode and will return `pre*` bumps to be used in apply.
- [e388cc7](https://www.github.com/jbolda/covector/commit/e388cc7ee98080e33744898737635711f3f30987) feat: prerelease mode and publishing ([#180](https://www.github.com/jbolda/covector/pull/180)) on 2021-05-13
- Implement `errorOnVersionRange` which allows one to set a range which, when satisfied, will fail a `covector status` or `covector version`. This guardrail can help prevent a package from accidentally being bumped to the next major version.
- [e388cc7](https://www.github.com/jbolda/covector/commit/e388cc7ee98080e33744898737635711f3f30987) feat: prerelease mode and publishing ([#180](https://www.github.com/jbolda/covector/pull/180)) on 2021-05-13
- Improve types on generator based shell commands. This won't affect the published assets, but improve use to downstream TS users (and covector).
- [e388cc7](https://www.github.com/jbolda/covector/commit/e388cc7ee98080e33744898737635711f3f30987) feat: prerelease mode and publishing ([#180](https://www.github.com/jbolda/covector/pull/180)) on 2021-05-13
- This switches to using Typescript project references to build (previously rollup). It should affect the underlying packages or use.
- [a9aedb1](https://www.github.com/jbolda/covector/commit/a9aedb1d5de01972b0576cc339788397e6ad829f) chore: build workflow updates ([#175](https://www.github.com/jbolda/covector/pull/175)) on 2021-04-07
- [5506b19](https://www.github.com/jbolda/covector/commit/5506b195e176ecec1c49af83cac0f8c490ba845e) feat: add preview command to covector ([#187](https://www.github.com/jbolda/covector/pull/187)) on 2021-05-05
- [e388cc7](https://www.github.com/jbolda/covector/commit/e388cc7ee98080e33744898737635711f3f30987) feat: prerelease mode and publishing ([#180](https://www.github.com/jbolda/covector/pull/180)) on 2021-05-13
- Pass head branch name into covector for running preview in action
Tag gets piped into template in assemble
Fix published boolean bug in command
- [2bdc840](https://www.github.com/jbolda/covector/commit/2bdc84046523f3dca61f3623f1ea893445c9fffb) feat: Add dist-tag for preview publishing... and fix the published boolean bug ([#200](https://www.github.com/jbolda/covector/pull/200)) on 2021-05-13
- Add support for yaml based package files. Add support for generic file whose only content is a version number.
- [e8c98f5](https://www.github.com/jbolda/covector/commit/e8c98f5c627e172f56c11d17022f198ca3cb9883) feat: yaml and generic file support ([#196](https://www.github.com/jbolda/covector/pull/196)) on 2021-05-07
- Throw an error if we receive a malformed change file or one that is otherwise missing any changes. Closes #201.
- [073202b](https://www.github.com/jbolda/covector/commit/073202b3517ebda6f2edb9ce743ccf69a01d3e48) fix: throw error on empty change file ([#205](https://www.github.com/jbolda/covector/pull/205)) on 2021-05-12
## \[0.6.1]

@@ -4,0 +27,0 @@

259

dist/index.js

@@ -1,39 +0,31 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var unified = require('unified');
var parse = require('remark-parse');
var stringify = require('remark-stringify');
var frontmatter = require('remark-frontmatter');
var yaml = require('js-yaml');
var lodash = require('lodash');
var files = require('@covector/files');
var command = require('@covector/command');
var path = require('path');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var unified__default = /*#__PURE__*/_interopDefaultLegacy(unified);
var parse__default = /*#__PURE__*/_interopDefaultLegacy(parse);
var stringify__default = /*#__PURE__*/_interopDefaultLegacy(stringify);
var frontmatter__default = /*#__PURE__*/_interopDefaultLegacy(frontmatter);
var yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
const parseChange = function* ({ cwd, vfile }) {
const processor = unified__default['default']()
.use(parse__default['default'])
.use(frontmatter__default['default'], ["yaml"])
.use(stringify__default['default'], {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeIntoConfig = exports.mergeChangesToConfig = exports.assemble = exports.compareBumps = void 0;
const unified_1 = __importDefault(require("unified"));
const remark_parse_1 = __importDefault(require("remark-parse"));
const remark_stringify_1 = __importDefault(require("remark-stringify"));
const remark_frontmatter_1 = __importDefault(require("remark-frontmatter"));
const js_yaml_1 = __importDefault(require("js-yaml"));
const lodash_1 = require("lodash");
const files_1 = require("@covector/files");
const command_1 = require("@covector/command");
const parseChange = function* ({ cwd, vfile, }) {
const processor = unified_1.default()
.use(remark_parse_1.default)
.use(remark_frontmatter_1.default, ["yaml"])
.use(remark_stringify_1.default, {
bullet: "-",
});
const parsed = processor.parse(vfile.contents.trim());
//@ts-ignore
const processed = yield processor.run(parsed);
let changeset = {};
const [parsedChanges, ...remaining] = processed.children;
const parsedYaml = yaml__default['default'].load(parsedChanges.value);
const parsedYaml = js_yaml_1.default.load(parsedChanges.value);
changeset.releases =
typeof parsedYaml === "object" && parsedYaml !== null ? parsedYaml : {};
if (Object.keys(changeset.releases).length === 0)
throw new Error(`${vfile.data.filename} didn't have any packages bumped. Please add a package bump.`);
changeset.summary = processor

@@ -47,4 +39,3 @@ .stringify({

try {
//@ts-ignore TODO generator error
let gitInfo = yield command.runCommand({
let gitInfo = yield command_1.runCommand({
cwd,

@@ -72,13 +63,15 @@ pkgPath: "",

};
// major, minor, or patch
// enum and use Int to compare
const bumpMap = new Map([
["major", 1],
["minor", 2],
["patch", 3],
["prerelease", 4],
["noop", 5],
]);
const compareBumps = (bumpOne, bumpTwo) => {
// major, minor, or patch
// enum and use Int to compare
let bumps = new Map([
["major", 1],
["minor", 2],
["patch", 3],
["noop", 4],
]);
return bumps.get(bumpOne) < bumps.get(bumpTwo) ? bumpOne : bumpTwo;
return bumpMap.get(bumpOne) < bumpMap.get(bumpTwo) ? bumpOne : bumpTwo;
};
exports.compareBumps = compareBumps;
const mergeReleases = (changes, { additionalBumpTypes = [] }) => {

@@ -95,3 +88,3 @@ return changes.reduce((release, change) => {

type: bumpType,
changes: lodash.cloneDeep([change]),
changes: lodash_1.cloneDeep([change]),
};

@@ -101,4 +94,4 @@ }

release[pkg] = {
type: compareBumps(release[pkg].type, bumpType),
changes: lodash.cloneDeep([...release[pkg].changes, change]),
type: exports.compareBumps(release[pkg].type, bumpType),
changes: lodash_1.cloneDeep([...release[pkg].changes, change]),
};

@@ -118,14 +111,58 @@ }

}
const assemble = function* ({ cwd, vfiles, config, }) {
const assemble = function* ({ cwd, vfiles, config, preMode = { on: false, prevFiles: [] }, }) {
let plan = {};
let changes = yield function* () {
let allVfiles = vfiles.map((vfile) => parseChange({ cwd, vfile }));
let yieldedV = [];
for (let v of allVfiles) {
yieldedV = [...yieldedV, yield v];
// if in prerelease mode, we only make bumps if the new one is "larger" than the last
// otherwise we only want a prerelease bump (which just increments the ending number)
if (preMode.on) {
const allChanges = yield changesParsed({ cwd, vfiles });
const allMergedRelease = mergeReleases(allChanges, config || {});
if (preMode.prevFiles.length > 0) {
const newVfiles = vfiles.reduce((newVFiles, vfile) => {
const prevFile = preMode.prevFiles.find((filename) => vfile.data.filename === filename);
if (!prevFile) {
return newVFiles.concat([vfile]);
}
else {
return newVFiles;
}
}, []);
const newChanges = yield changesParsed({
cwd,
vfiles: newVfiles,
});
const newMergedRelease = mergeReleases(newChanges, config || {});
const oldVfiles = vfiles.reduce((newVFiles, vfile) => {
const prevFile = preMode.prevFiles.find((filename) => vfile.data.filename === filename);
if (prevFile) {
return newVFiles.concat([vfile]);
}
else {
return newVFiles;
}
}, []);
const oldChanges = yield changesParsed({
cwd,
vfiles: oldVfiles,
});
const oldMergedRelease = mergeReleases(oldChanges, config || {});
const diffed = changeDiff({
allMergedRelease,
newMergedRelease,
oldMergedRelease,
});
plan.changes = newChanges;
plan.releases = diffed;
}
return yieldedV;
};
plan.changes = changes;
plan.releases = mergeReleases(changes, config || {});
else {
plan.changes = allChanges;
plan.releases = changeDiff({
allMergedRelease,
});
}
}
else {
let changes = yield changesParsed({ cwd, vfiles });
plan.changes = changes;
plan.releases = mergeReleases(changes, config || {});
}
if (config && Object.keys(config).length > 0) {

@@ -144,19 +181,50 @@ for (let pkg of Object.keys(plan.releases)) {

};
const mergeChangesToConfig = function* ({ config, assembledChanges, command, dryRun = false, filterPackages = [], }) {
exports.assemble = assemble;
const changesParsed = function* ({ cwd, vfiles, }) {
const allVfiles = vfiles.map((vfile) => parseChange({ cwd, vfile }));
let yieldedV = [];
for (let v of allVfiles) {
yieldedV = [...yieldedV, yield v];
}
return yieldedV;
};
const changeDiff = ({ allMergedRelease, newMergedRelease, oldMergedRelease, }) => {
if (newMergedRelease && oldMergedRelease) {
let diffed = Object.assign({}, newMergedRelease);
Object.keys(newMergedRelease).forEach((pkg) => {
var _a, _b;
const nextBump = ((_a = newMergedRelease[pkg]) === null || _a === void 0 ? void 0 : _a.type) || "noop";
const oldBump = ((_b = oldMergedRelease[pkg]) === null || _b === void 0 ? void 0 : _b.type) || "noop";
//@ts-ignore bumpMap could be undefined?
if (bumpMap.get(nextBump) < bumpMap.get(oldBump)) {
//@ts-ignore TODO template string doesn't play nice with the type
diffed[pkg].type = `pre${nextBump}`;
}
else {
diffed[pkg].type = "prerelease";
}
});
return diffed;
}
else {
return Object.keys(allMergedRelease).reduce((diffed, pkg) => {
diffed[pkg] = Object.assign({}, allMergedRelease[pkg]);
//@ts-ignore TODO template string doesn't play nice with the type
diffed[pkg].type = `pre${allMergedRelease[pkg].type}`;
return diffed;
}, {});
}
};
const mergeChangesToConfig = function* ({ config, assembledChanges, command, cwd, dryRun = false, filterPackages = [], }) {
// build in assembledChanges to only issue commands with ones with changes
// and pipe in data to template function
const pkgCommands = Object.keys(config.packages).reduce((pkged, pkg) => {
var _a, _b;
const pkgManager = config.packages[pkg].manager;
const commandItems = { pkg, pkgManager, config };
const mergedCommand = mergeCommand(Object.assign(Object.assign({}, commandItems), { command }));
if (!!mergedCommand) {
pkged[pkg] = {
pkg: pkg,
path: config.packages[pkg].path,
precommand: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `pre${command}` })),
command: mergedCommand,
postcommand: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `post${command}` })),
manager: config.packages[pkg].manager,
dependencies: config.packages[pkg].dependencies,
};
if (!!mergedCommand || command === "status") {
pkged[pkg] = Object.assign(Object.assign({ pkg: pkg, path: config.packages[pkg].path }, (!((_a = config.packages[pkg]) === null || _a === void 0 ? void 0 : _a.packageFileName)
? {}
: { packageFileName: (_b = config.packages[pkg]) === null || _b === void 0 ? void 0 : _b.packageFileName })), { precommand: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `pre${command}` })), command: mergedCommand, postcommand: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `post${command}` })), manager: config.packages[pkg].manager, dependencies: config.packages[pkg].dependencies, errorOnVersionRange: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `errorOnVersionRange` })) });
}

@@ -175,11 +243,9 @@ return pkged;

};
if (dryRun) {
pipeOutput[pkg] = {};
pipeOutput[pkg].name = pkg;
pipeOutput[pkg].pipe = pipeToTemplate;
}
pipeOutput[pkg] = {};
pipeOutput[pkg].name = pkg;
pipeOutput[pkg].pipe = pipeToTemplate;
const merged = Object.assign(Object.assign({ pkg }, (!pkgs[pkg].parents ? {} : { parents: pkgs[pkg].parents })), { path: pkgCommands[pkg].path, type: pkgs[pkg].type || null, manager: pkgCommands[pkg].manager, dependencies: pkgCommands[pkg].dependencies, precommand: templateCommands(pkgCommands[pkg].precommand, pipeToTemplate, ["command", "dryRunCommand", "runFromRoot"]), command: templateCommands(pkgCommands[pkg].command, pipeToTemplate, [
"command",
"dryRunCommand",
]), postcommand: templateCommands(pkgCommands[pkg].postcommand, pipeToTemplate, ["command", "dryRunCommand", "runFromRoot"]) });
]), postcommand: templateCommands(pkgCommands[pkg].postcommand, pipeToTemplate, ["command", "dryRunCommand", "runFromRoot"]), errorOnVersionRange: pkgCommands[pkg].errorOnVersionRange });
commands = [...commands, merged];

@@ -191,8 +257,10 @@ }

}
return commands;
return { commands, pipeTemplate: pipeOutput };
};
const mergeIntoConfig = function* ({ config, assembledChanges, command, cwd, dryRun = false, filterPackages = [], }) {
exports.mergeChangesToConfig = mergeChangesToConfig;
const mergeIntoConfig = function* ({ config, assembledChanges, command, cwd, dryRun = false, filterPackages = [], changelogs, tag = "", }) {
// build in assembledChanges to only issue commands with ones with changes
// and pipe in data to template function
const pkgCommands = Object.keys(config.packages).reduce((pkged, pkg) => {
var _a, _b;
const pkgManager = config.packages[pkg].manager;

@@ -208,4 +276,8 @@ const commandItems = { pkg, pkgManager, config };

if (!!mergedCommand) {
pkged[pkg] = Object.assign(Object.assign(Object.assign({ pkg: pkg, path: config.packages[pkg].path || "", precommand: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `pre${command}` })), command: mergedCommand, postcommand: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `post${command}` })) }, (!publishElements[`getPublishedVersion${publishElements.subPublishCommand}`]
pkged[pkg] = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ pkg: pkg, path: config.packages[pkg].path }, (!((_a = config.packages[pkg]) === null || _a === void 0 ? void 0 : _a.packageFileName)
? {}
: { packageFileName: (_b = config.packages[pkg]) === null || _b === void 0 ? void 0 : _b.packageFileName })), (!changelogs || !changelogs[pkg]
? {}
: { changelog: changelogs[pkg].changelog })), { precommand: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `pre${command}` })), command: mergedCommand, postcommand: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `post${command}` })) }), (!publishElements[`getPublishedVersion${publishElements.subPublishCommand}`]
? {}
: {

@@ -215,3 +287,3 @@ [`getPublishedVersion${publishElements.subPublishCommand}`]: publishElements[`getPublishedVersion${publishElements.subPublishCommand}`],

? {}
: { assets: publishElements.assets })), { manager: config.packages[pkg].manager || "", dependencies: config.packages[pkg].dependencies });
: { assets: publishElements.assets })), { manager: config.packages[pkg].manager || "", dependencies: config.packages[pkg].dependencies, errorOnVersionRange: mergeCommand(Object.assign(Object.assign({}, commandItems), { command: `errorOnVersionRange` })) });
}

@@ -226,13 +298,8 @@ return pkged;

const pipeToTemplate = {
pkg: pkgCommands[pkg],
pkg: Object.assign(Object.assign({}, pkgCommands[pkg]), { tag }),
};
let extraPublishParams = {
// @ts-ignore TODO this returns a Promise and TS doesn't like that
pkgFile: yield files.readPkgFile({
file: path__default['default'].join(cwd,
//@ts-ignore
config.packages[pkg].path, !!config.packages[pkg].manager &&
config.packages[pkg].manager === "rust"
? "Cargo.toml"
: "package.json"),
pkgFile: yield files_1.readPkgFile({
cwd,
pkgConfig: pkgCommands[pkg],
nickname: pkg,

@@ -254,3 +321,3 @@ }),

: {
[`getPublishedVersion${subPublishCommand}`]: lodash.template(
[`getPublishedVersion${subPublishCommand}`]: lodash_1.template(
//@ts-ignore no index type string

@@ -266,11 +333,9 @@ pkgCommands[pkg][`getPublishedVersion${subPublishCommand}`])(pipeToTemplate),

}));
if (dryRun) {
pipeOutput[pkg] = {};
pipeOutput[pkg].name = pkg;
pipeOutput[pkg].pipe = pipeToTemplate;
}
pipeOutput[pkg] = {};
pipeOutput[pkg].name = pkg;
pipeOutput[pkg].pipe = pipeToTemplate;
const merged = Object.assign(Object.assign({ pkg }, extraPublishParams), { path: pkgCommands[pkg].path, manager: pkgCommands[pkg].manager, dependencies: pkgCommands[pkg].dependencies, precommand: templateCommands(pkgCommands[pkg].precommand, pipeToTemplate, ["command", "dryRunCommand", "runFromRoot"]), command: templateCommands(pkgCommands[pkg].command, pipeToTemplate, [
"command",
"dryRunCommand",
]), postcommand: templateCommands(pkgCommands[pkg].postcommand, pipeToTemplate, ["command", "dryRunCommand", "runFromRoot"]) });
]), postcommand: templateCommands(pkgCommands[pkg].postcommand, pipeToTemplate, ["command", "dryRunCommand", "runFromRoot"]), errorOnVersionRange: pkgCommands[pkg].errorOnVersionRange });
commands = [...commands, merged];

@@ -282,4 +347,5 @@ }

}
return commands;
return { commands, pipeTemplate: pipeOutput };
};
exports.mergeIntoConfig = mergeIntoConfig;
const mergeCommand = ({ pkg, pkgManager, command, config, }) => {

@@ -322,3 +388,3 @@ const managerCommand = !!pkgManager &&

typeof c[complex] === "string"
? lodash.template(c[complex])(pipe)
? lodash_1.template(c[complex])(pipe)
: c[complex];

@@ -330,10 +396,5 @@ return templated;

// if it is a function, we pipe when we run the function
return typeof c === "function" ? c : lodash.template(c)(pipe);
return typeof c === "function" ? c : lodash_1.template(c)(pipe);
}
});
};
exports.assemble = assemble;
exports.compareBumps = compareBumps;
exports.mergeChangesToConfig = mergeChangesToConfig;
exports.mergeIntoConfig = mergeIntoConfig;
{
"name": "@covector/assemble",
"version": "0.6.1",
"version": "0.7.0",
"license": "Apache-2.0",

@@ -11,13 +11,12 @@ "homepage": "https://github.com/jbolda/covector#readme",

},
"main": "dist",
"files": [
"dist/**/*"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rollup --config",
"prepublishOnly": "rollup --config"
"build": "tsc -b",
"clean": "rimraf dist node_modules",
"prepublishOnly": "tsc -b"
},
"dependencies": {
"@covector/command": "0.3.2",
"@covector/files": "0.3.1",
"@covector/command": "0.4.0",
"@covector/files": "0.4.0",
"js-yaml": "^4.0.0",

@@ -31,8 +30,6 @@ "lodash": "^4.17.21",

"devDependencies": {
"@rollup/plugin-typescript": "^8.2.0",
"@types/js-yaml": "^4.0.0",
"@types/lodash": "^4.14.168",
"fixturez": "^1.1.0",
"rollup": "^2.42.4",
"tslib": "^2.1.0",
"tslib": "^2.2.0",
"typescript": "^4.2.3"

@@ -39,0 +36,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc