Skip to content

Commit

Permalink
fix(semantic-release-plugin): Removed dependancy on commit analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivanpj committed Nov 1, 2023
1 parent 51f4809 commit 4796955
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/semantic-release-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"type": "commonjs",
"main": "./index.cjs",
"dependencies": {
"@semantic-release/commit-analyzer": "^11.0.0",
"@semantic-release/release-notes-generator": "^12.0.0",
"conventional-commits-filter": "^4.0.0",
"conventional-commits-parser": "^5.0.0",
"import-from": "^4.0.0",
"lodash": "^4.17.21",
"micromatch": "^4.0.5",
"remeda": "^1.28.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ProjectGraph, createProjectGraphAsync } from "@nx/devkit";

import { execSync } from "child_process";
import filter from "conventional-commits-filter";
import { sync as parser } from "conventional-commits-parser";
Expand All @@ -11,6 +10,8 @@ import { DEFAULT_RELEASE_RULES, RELEASE_TYPES } from "../constants";
import { ReleaseContext } from "../types";
import { analyzeCommit } from "./analyze-commit";
import { compareReleaseTypes } from "./compare-release-types";
import { loadParserConfig } from "./load-parser-config";
import { loadReleaseRules } from "./load-release-rules";
import { CurrentContext } from "./release-context";

interface CommitAffectingProjectsParams {
Expand Down Expand Up @@ -98,13 +99,6 @@ const analyzeCommits = async (pluginConfig: any, context: any) => {
return null;
}

const loadParserConfig = await import(
"@semantic-release/commit-analyzer/lib/load-parser-config.js"
);
const loadReleaseRules = await import(
"@semantic-release/commit-analyzer/lib/load-release-rules.js"
);

const releaseRules = await loadReleaseRules(pluginConfig, context);
const config = await loadParserConfig(pluginConfig, context);
let releaseType = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import importFrom from "import-from";
import { dirname } from "path";
import { getWorkspaceRoot } from "./utils";

export const loadParserConfig = async (
{ preset, config, parserOpts, presetConfig },
{ cwd }
) => {
let loadedConfig;
const __dirname = dirname(getWorkspaceRoot());

if (preset) {
const presetPackage = `conventional-changelog-${preset.toLowerCase()}`;
loadedConfig = await (
importFrom.silent(__dirname, presetPackage) ||
importFrom(cwd, presetPackage)
)(presetConfig);
} else if (config) {
loadedConfig = await (
importFrom.silent(__dirname, config) || importFrom(cwd, config)
)();
}

return { ...loadedConfig.parserOpts, ...parserOpts };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import importFrom from "import-from";
import { isUndefined } from "lodash";
import { dirname } from "node:path";
import { RELEASE_TYPES } from "../constants";
import { getWorkspaceRoot } from "./utils";

export const loadReleaseRules = async ({ releaseRules }, { cwd }) => {
let loadedReleaseRules;
const __dirname = dirname(getWorkspaceRoot());

if (releaseRules) {
loadedReleaseRules =
typeof releaseRules === "string"
? importFrom.silent(__dirname, releaseRules) ||
importFrom(cwd, releaseRules)
: releaseRules;

if (!Array.isArray(loadedReleaseRules)) {
throw new TypeError(
'Error in commit-analyzer configuration: "releaseRules" must be an array of rules'
);
}

loadedReleaseRules.forEach(rule => {
if (!rule || isUndefined(rule.release)) {
throw new Error(
'Error in commit-analyzer configuration: rules must be an object with a "release" property'
);
} else if (
!RELEASE_TYPES.includes(rule.release) &&
rule.release !== null &&
rule.release !== false
) {
throw new Error(
`Error in commit-analyzer configuration: "${
rule.release
}" is not a valid release type. Valid values are: ${JSON.stringify(
RELEASE_TYPES
)}`
);
}
});
}

return loadedReleaseRules;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { findWorkspaceRoot } from "nx/src/utils/find-workspace-root";

export const getWorkspaceRoot = () => {
const root = findWorkspaceRoot(process.cwd());
process.env.DEV_REPO_ROOT ??= root?.dir;
process.env.NX_WORKSPACE_ROOT_PATH ??= root?.dir;

return root?.dir;
};
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4796955

Please sign in to comment.