@anolilab/multi-semantic-release 2.0.6 → 3.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,85 +0,0 @@
1
- // eslint-disable-next-line simple-import-sort/imports
2
- import { relative } from "node:path";
3
-
4
- import { execa } from "execa";
5
- import gitLogParser from "git-log-parser";
6
-
7
- import logger from "./logger.js";
8
- import { ValueError, check } from "./utils/blork.js";
9
- import cleanPath from "./utils/clean-path.js";
10
- import streamToArray from "./utils/stream-to-array.js";
11
-
12
- const { debug } = logger.withScope("msr:commitsFilter");
13
-
14
- /**
15
- * Retrieve the list of commits on the current branch since the commit sha associated with the last release, or all the commits of the current branch if there is no last released version.
16
- * Commits are filtered to only return those that corresponding to the package directory.
17
- *
18
- * This is achieved by using "-- my/dir/path" with `git log` — passing this into gitLogParser() with
19
- * @param {string} cwd Absolute path of the working directory the Git repo is in.
20
- * @param {string} direction Path to the target directory to filter by. Either absolute, or relative to cwd param.
21
- * @param {string|void} lastRelease The SHA of the previous release (default to start of all commits if undefined)
22
- * @param {string|void} nextRelease The SHA of the next release (default to HEAD if undefined)
23
- * @param {string|void} firstParentBranch first-parent to determine which merges went into master
24
- * @returns {Promise<Array<Commit>>} The list of commits on the branch `branch` since the last release.
25
- */
26
- async function getCommitsFiltered(cwd, direction, lastRelease, nextRelease, firstParentBranch) {
27
- // Clean paths and make sure directories exist.
28
- check(cwd, "cwd: directory");
29
- check(direction, "dir: path");
30
-
31
- // eslint-disable-next-line no-param-reassign
32
- cwd = cleanPath(cwd);
33
- // eslint-disable-next-line no-param-reassign
34
- direction = cleanPath(direction, cwd);
35
-
36
- check(direction, "dir: directory");
37
- check(lastRelease, "lastRelease: alphanumeric{40}?");
38
- check(nextRelease, "nextRelease: alphanumeric{40}?");
39
-
40
- // target must be inside and different than cwd.
41
- if (direction.indexOf(cwd) !== 0) {
42
- throw new ValueError("dir: Must be inside cwd", direction);
43
- }
44
-
45
- if (direction === cwd) {
46
- throw new ValueError("dir: Must not be equal to cwd", direction);
47
- }
48
-
49
- // Get top-level Git directory as it might be higher up the tree than cwd.
50
- const root = await execa("git", ["rev-parse", "--show-toplevel"], { cwd });
51
-
52
- // Add correct fields to gitLogParser.
53
- Object.assign(gitLogParser.fields, {
54
- committerDate: { key: "ci", type: Date },
55
- gitTags: "d",
56
- hash: "H",
57
- message: "B",
58
- });
59
-
60
- // Use git-log-parser to get the commits.
61
- const relpath = relative(root.stdout, direction);
62
- const firstParentBranchFilter = firstParentBranch ? ["--first-parent", firstParentBranch] : [];
63
- const range = (lastRelease ? `${lastRelease}..` : "") + (nextRelease || "HEAD");
64
- const gitLogFilterQuery = [...firstParentBranchFilter, range, "--", relpath];
65
- const stream = gitLogParser.parse({ _: gitLogFilterQuery }, { cwd, env: process.env });
66
-
67
- const commits = await streamToArray(stream);
68
-
69
- // Trim message and tags.
70
- commits.forEach((commit) => {
71
- // eslint-disable-next-line no-param-reassign
72
- commit.message = commit.message.trim();
73
- // eslint-disable-next-line no-param-reassign
74
- commit.gitTags = commit.gitTags.trim();
75
- });
76
-
77
- debug("git log filter query: %o", gitLogFilterQuery);
78
- debug("filtered commits: %O", commits);
79
-
80
- // Return the commits.
81
- return commits;
82
- }
83
-
84
- // Exports.
85
- export default getCommitsFiltered;
@@ -1,78 +0,0 @@
1
- import { createRequire } from "node:module";
2
-
3
- import { cosmiconfig } from "cosmiconfig";
4
- // eslint-disable-next-line you-dont-need-lodash-underscore/cast-array
5
- import { castArray } from "lodash-es";
6
- import resolveFrom from "resolve-from";
7
-
8
- import mergeConfig from "./utils/merge-config.js";
9
-
10
- const CONFIG_NAME = "multi-release";
11
- const CONFIG_FILES = [
12
- "package.json",
13
- `.${CONFIG_NAME}rc`,
14
- `.${CONFIG_NAME}rc.json`,
15
- `.${CONFIG_NAME}rc.yaml`,
16
- `.${CONFIG_NAME}rc.yml`,
17
- `.${CONFIG_NAME}rc.js`,
18
- `.${CONFIG_NAME}rc.cjs`,
19
- `.${CONFIG_NAME}rc.mjs`,
20
- `${CONFIG_NAME}.config.js`,
21
- `${CONFIG_NAME}.config.cjs`,
22
- `${CONFIG_NAME}.config.mjs`,
23
- ];
24
-
25
- /**
26
- * Get the multi semantic release configuration options for a given directory.
27
- * @param {string} cwd The directory to search.
28
- * @param {object} cliOptions cli supplied options.
29
- * @returns {object} The found configuration option
30
- * @internal
31
- */
32
- export default async function getConfig(cwd, cliOptions) {
33
- const { config } = await cosmiconfig(CONFIG_NAME, { searchPlaces: CONFIG_FILES }).search(cwd) || {};
34
- const { extends: extendPaths, ...rest } = { ...config };
35
-
36
- let options = rest;
37
-
38
- if (extendPaths) {
39
- const require = createRequire(import.meta.url);
40
- // If `extends` is defined, load and merge each shareable config
41
- // eslint-disable-next-line unicorn/no-array-reduce
42
- const extendedOptions = castArray(extendPaths).reduce((result, extendPath) => {
43
- // eslint-disable-next-line import/no-dynamic-require,security/detect-non-literal-require
44
- const extendsOptions = require(resolveFrom(cwd, extendPath));
45
-
46
- return mergeConfig(result, extendsOptions);
47
- }, {});
48
-
49
- options = mergeConfig(options, extendedOptions);
50
- }
51
-
52
- // Set default options values if not defined yet
53
- options = mergeConfig(
54
- {
55
- branches: undefined,
56
- ci: undefined,
57
- debug: false,
58
- deps: {
59
- bump: "override",
60
- prefix: "",
61
- release: "patch",
62
- },
63
- dryRun: undefined,
64
- firstParent: false,
65
- ignorePackages: [],
66
- ignorePrivate: true,
67
- sequentialInit: false,
68
- sequentialPrepare: true,
69
- silent: false,
70
- // eslint-disable-next-line no-template-curly-in-string
71
- tagFormat: "${name}@${version}",
72
- },
73
- options,
74
- );
75
-
76
- // Finally merge CLI options last so they always win
77
- return mergeConfig(options, cliOptions);
78
- }
@@ -1,38 +0,0 @@
1
- import semanticGetConfig from "semantic-release/lib/get-config.js";
2
- import signale from "signale";
3
- import { WritableStreamBuffer } from "stream-buffers";
4
-
5
- import logger from "./logger.js";
6
-
7
- const { Signale } = signale;
8
-
9
- /**
10
- * Get the release configuration options for a given directory.
11
- * Unfortunately we've had to copy this over from semantic-release, creating unnecessary duplication.
12
- * @param {object} context Object containing cwd, env, and logger properties that are passed to getConfig()
13
- * @param context.cwd
14
- * @param context.env
15
- * @param {object} options Options object for the config.
16
- * @param context.stderr
17
- * @param context.stdout
18
- * @returns {object} Returns what semantic-release's get config returns (object with options and plugins objects).
19
- * @internal
20
- */
21
- async function getConfigSemantic({ cwd, env, stderr, stdout }, options) {
22
- try {
23
- // Blackhole logger (so we don't clutter output with "loaded plugin" messages).
24
- const blackhole = new Signale({ stream: new WritableStreamBuffer() });
25
-
26
- // Return semantic-release's getConfig script.
27
- return await semanticGetConfig({ cwd, env, logger: blackhole, stderr, stdout }, options);
28
- } catch (error) {
29
- // Log error and rethrow it.
30
- // istanbul ignore next (not important)
31
- logger.failure(`Error in semantic-release getConfig(): %0`, error);
32
- // istanbul ignore next (not important)
33
- throw error;
34
- }
35
- }
36
-
37
- // Exports.
38
- export default getConfigSemantic;
package/lib/get-config.js DELETED
@@ -1,33 +0,0 @@
1
- import { cosmiconfig } from "cosmiconfig";
2
-
3
- // Copied from get-config.js in semantic-release
4
- const CONFIG_NAME = "release";
5
- const CONFIG_FILES = [
6
- "package.json",
7
- `.${CONFIG_NAME}rc`,
8
- `.${CONFIG_NAME}rc.json`,
9
- `.${CONFIG_NAME}rc.yaml`,
10
- `.${CONFIG_NAME}rc.yml`,
11
- `.${CONFIG_NAME}rc.js`,
12
- `.${CONFIG_NAME}rc.cjs`,
13
- `.${CONFIG_NAME}rc.mjs`,
14
- `${CONFIG_NAME}.config.js`,
15
- `${CONFIG_NAME}.config.cjs`,
16
- `${CONFIG_NAME}.config.mjs`,
17
- ];
18
-
19
- /**
20
- * Get the release configuration options for a given directory.
21
- * Unfortunately we've had to copy this over from semantic-release, creating unnecessary duplication.
22
- * @param {string} cwd The directory to search.
23
- * @returns {object} The found configuration option
24
- * @internal
25
- */
26
- export default async function getConfig(cwd) {
27
- // Call cosmiconfig.
28
- const config = await cosmiconfig(CONFIG_NAME, { mergeSearchPlaces: false, searchPlaces: CONFIG_FILES }).search(cwd);
29
-
30
- // Return the found config or empty object.
31
- // istanbul ignore next (not important).
32
- return config ? config.config : {};
33
- }
@@ -1,89 +0,0 @@
1
- import { existsSync, lstatSync, readFileSync } from "node:fs";
2
-
3
- /**
4
- * Read the content of target package.json if exists.
5
- * @param {string} path file path
6
- * @returns {string} file content
7
- * @internal
8
- */
9
- function readManifest(path) {
10
- // Check it exists.
11
- // eslint-disable-next-line security/detect-non-literal-fs-filename
12
- if (!existsSync(path)) {
13
- throw new ReferenceError(`package.json file not found: "${path}"`);
14
- }
15
-
16
- // Stat the file.
17
- let stat;
18
-
19
- try {
20
- // eslint-disable-next-line security/detect-non-literal-fs-filename
21
- stat = lstatSync(path);
22
- } catch {
23
- // istanbul ignore next (hard to __tests__ — happens if no read access etc).
24
- throw new ReferenceError(`package.json cannot be read: "${path}"`);
25
- }
26
-
27
- // Check it's a file!
28
- if (!stat.isFile()) {
29
- throw new ReferenceError(`package.json is not a file: "${path}"`);
30
- }
31
-
32
- // Read the file.
33
- try {
34
- // eslint-disable-next-line security/detect-non-literal-fs-filename
35
- return readFileSync(path, "utf8");
36
- } catch {
37
- // istanbul ignore next (hard to __tests__ — happens if no read access etc).
38
- throw new ReferenceError(`package.json cannot be read: "${path}"`);
39
- }
40
- }
41
-
42
- /**
43
- * Get the parsed contents of a package.json manifest file.
44
- * @param {string} path The path to the package.json manifest file.
45
- * @returns {object} The manifest file's contents.
46
- * @internal
47
- */
48
- export default function getManifest(path) {
49
- // Read the file.
50
- const contents = readManifest(path);
51
-
52
- // Parse the file.
53
- let manifest;
54
-
55
- try {
56
- manifest = JSON.parse(contents);
57
- } catch {
58
- throw new SyntaxError(`package.json could not be parsed: "${path}"`);
59
- }
60
-
61
- // Must be an object.
62
- if (typeof manifest !== "object") {
63
- throw new SyntaxError(`package.json was not an object: "${path}"`);
64
- }
65
-
66
- // Must have a name.
67
- if (typeof manifest.name !== "string" || manifest.name.length === 0) {
68
- throw new SyntaxError(`Package name must be non-empty string: "${path}"`);
69
- }
70
-
71
- // Check dependencies.
72
- const checkDeps = (scope) => {
73
- // eslint-disable-next-line no-prototype-builtins
74
- if (manifest.hasOwnProperty(scope) && typeof manifest[scope] !== "object") {
75
- throw new SyntaxError(`Package ${scope} must be object: "${path}"`);
76
- }
77
- };
78
-
79
- checkDeps("dependencies");
80
- checkDeps("devDependencies");
81
- checkDeps("peerDependencies");
82
- checkDeps("optionalDependencies");
83
-
84
- // NOTE non-enumerable prop is skipped by JSON.stringify
85
- Object.defineProperty(manifest, "__contents__", { enumerable: false, value: contents });
86
-
87
- // Return contents.
88
- return manifest;
89
- }
package/lib/logger.js DELETED
@@ -1,80 +0,0 @@
1
- import dbg from "debug";
2
- import singnale from "signale";
3
-
4
- const { Signale } = singnale;
5
- const severityOrder = ["error", "warn", "info", "debug", "trace"];
6
- const assertLevel = (level, limit) => severityOrder.indexOf(level) <= severityOrder.indexOf(limit);
7
- const aliases = {
8
- complete: "info",
9
- failure: "error",
10
- log: "info",
11
- success: "info",
12
- };
13
-
14
- const logger = {
15
- config: {
16
- _level: "info",
17
- _signale: {},
18
- _stderr: process.stderr,
19
- _stdout: process.stdout,
20
- set level(l) {
21
- if (!l) {
22
- return;
23
- }
24
-
25
- if (assertLevel(l, "debug")) {
26
- dbg.enable("msr:");
27
- }
28
-
29
- if (assertLevel(l, "trace")) {
30
- dbg.enable("semantic-release:");
31
- }
32
-
33
- this._level = l;
34
- },
35
- get level() {
36
- return this._level;
37
- },
38
- set stdio([stderr, stdout]) {
39
- this._stdout = stdout;
40
- this._stderr = stderr;
41
- this._signale = new Signale({
42
- config: { displayLabel: false, displayTimestamp: true },
43
- // scope: "multirelease",
44
- stream: stdout,
45
- types: {
46
- complete: { badge: "🎉", color: "green", label: "", stream: [stdout] },
47
- error: { color: "red", label: "", stream: [stderr] },
48
- log: { badge: "•", color: "magenta", label: "", stream: [stdout] },
49
- success: { color: "green", label: "", stream: [stdout] },
50
- },
51
- });
52
- },
53
- get stdio() {
54
- return [this._stderr, this._stdout];
55
- },
56
- },
57
- prefix: "msr:",
58
- withScope(prefix) {
59
- return {
60
- ...this,
61
- debug: dbg(prefix || this.prefix),
62
- prefix,
63
- };
64
- },
65
- // eslint-disable-next-line unicorn/no-array-reduce
66
- ...[...severityOrder, ...Object.keys(aliases)].reduce((m, l) => {
67
- // eslint-disable-next-line no-param-reassign,func-names
68
- m[l] = function (...arguments_) {
69
- if (assertLevel(aliases[l] || l, this.config.level)) {
70
- // eslint-disable-next-line no-console
71
- (this.config._signale[l] || console[l] || (() => {}))(this.prefix, ...arguments_);
72
- }
73
- };
74
-
75
- return m;
76
- }, {}),
77
- debug: dbg("msr:"),
78
- };
79
-
80
- export default logger;