@thisismanta/semantic-version 10.0.0 → 11.1.0

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.
package/README.md CHANGED
@@ -1,53 +1,76 @@
1
- # `npx lint-commit-message <path>`
1
+ The following commands respect [`packageManager`](https://github.com/nodejs/corepack?tab=readme-ov-file#when-authoring-packages) field first then [`devEngines.packageManager.name`](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#devengines) in _package.json_, but fallback to **npm** if none is specified.
2
+
3
+ ---
4
+
5
+ ### `npx lint-commit-message <path>`
2
6
 
3
7
  The `<path>` must point to a text file containing commit message that complies with the following pattern:
4
8
 
5
9
  ```
6
10
  <type>[!]: <subject>
7
11
  ```
12
+
8
13
  Where
9
- - `<type>` can be either `feat`, `fix`, `test`, `refactor` or `chore`.
10
- - `!` indicates that the commit contains breaking changes.
14
+
15
+ - `<type>` can be either `feat`, `fix`, `build` or `chore`.
16
+ - `!` indicates that the commit contains a breaking change.
11
17
  - `<subject>` is the actual commit message where the first word must be written in lower cases.
12
18
 
13
- > Usage example with [**lefthook**](https://www.npmjs.com/package/lefthook)
14
- > ```yml
15
- > # lefthook.yml
16
- > commit-msg:
17
- > commands:
18
- > lint:
19
- > run: npx lint-commit-message {1}
20
- > ```
21
-
22
- # `npx auto-npm-version`
23
-
24
- This command is supposed to be run on CI, such as **GitHub Actions**. It will run `npm version <new-version>`, which `<new-version>` is automatically derived from your commit messages according to the table below and then it creates a new entry on [**GitHub releases**](https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases).
25
-
26
- |Commit message type|Post-commit command|
27
- |---|---|
28
- |`!`|`npm version major`|
29
- |`feat`|`npm version minor`|
30
- |`fix`|`npm version patch`|
31
- |Others|Does not run `npm version`|
32
-
33
- > Usage example with **GitHub Actions**
34
- > ```yml
35
- > on:
36
- > push:
37
- > branches: [master]
38
- > jobs:
39
- > release:
40
- > runs-on: ubuntu-latest
41
- > steps:
42
- > - uses: actions/checkout@v4
43
- > with:
44
- > fetch-depth: 0 # Ensure Git tags are fetched
45
- > - uses: actions/setup-node@v4
46
- > with:
47
- > node-version-file: 'package.json'
48
- > cache: npm
49
- > - run: npm ci # Install semantic-version as part of the dependencies
50
- > - run: npx auto-npm-version
51
- > env:
52
- > GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Make it possible to create a new release using GitHub API
53
- > ```
19
+ Usage example with [**lefthook**](https://www.npmjs.com/package/lefthook):
20
+
21
+ ```yml
22
+ # lefthook.yml
23
+ commit-msg:
24
+ commands:
25
+ lint:
26
+ run: npx lint-commit-message {1}
27
+ ```
28
+
29
+ ---
30
+
31
+ ### `npx make-next-release`
32
+
33
+ This command is supposed to be run on **GitHub Actions**. It will run `npm version <new-version>`, which `<new-version>` is automatically derived from your commit messages according to the table below and then it creates a new entry on [**GitHub releases**](https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases).
34
+
35
+ | Commit message type | Trigger |
36
+ | ------------------- | -------------------------- |
37
+ | `!` | `npm version major` |
38
+ | `feat` | `npm version minor` |
39
+ | `fix` or `build` | `npm version patch` |
40
+ | Others | Does not run `npm version` |
41
+
42
+ ```json
43
+ // package.json
44
+ {
45
+ "scripts": {
46
+ "version": "npm run build",
47
+ "postversion": "npm publish"
48
+ }
49
+ }
50
+ ```
51
+
52
+ ```yml
53
+ # .github/workflows/push.yml
54
+ on:
55
+ push:
56
+ branches: [master]
57
+
58
+ jobs:
59
+ release:
60
+ runs-on: ubuntu-latest
61
+ steps:
62
+ - uses: actions/checkout@v6
63
+ with:
64
+ fetch-depth: 0 # Ensure Git tags are fetched
65
+
66
+ - uses: actions/setup-node@v6
67
+ with:
68
+ node-version-file: 'package.json'
69
+ cache: npm
70
+
71
+ - run: npm ci # Install semantic-version as part of the dependencies
72
+
73
+ - run: npx make-next-release
74
+ env:
75
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Make it possible to create a new release using GitHub API
76
+ ```
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('../lib/lint-commit-message').default(process.argv.at(2))
2
+ require('../lib/lint-commit-message.js')
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../lib/make-next-release.js')
package/lib/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export declare function debug(text: string | number): void;
2
+ export declare function run(command: string): Promise<string>;
3
+ export declare const npm: string;
4
+ export declare const allowedTypes: readonly ["feat", "fix", "build", "chore"];
5
+ export type SemanticType = (typeof allowedTypes)[number];
6
+ export declare function checkConventionalMessage(message: string): {
7
+ type: "feat" | "fix" | "build" | "chore" | undefined;
8
+ breaking: boolean;
9
+ subject: string;
10
+ errors: string[];
11
+ };
12
+ interface GitCommit {
13
+ hash: string;
14
+ type: string | undefined;
15
+ breaking: boolean;
16
+ subject: string;
17
+ }
18
+ export declare function getReleaseType(commits: Array<GitCommit>): string | null;
19
+ export declare function getCurrentPackageVersion(): Promise<string>;
20
+ export declare function getGitHistory(version: string): Promise<Array<GitCommit>>;
21
+ export declare function getReleaseNote(commits: Array<GitCommit>): string;
22
+ export {};
package/lib/index.js CHANGED
@@ -1 +1,11 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var index_exports={};__export(index_exports,{allowedTypes:()=>allowedTypes,checkConventionalMessage:()=>checkConventionalMessage});module.exports=__toCommonJS(index_exports);var titlePattern=/^(?<type>\w+)(?<scope>\(.*?\))?(?<breaking>\!)?:(?<subject>.+)/;var allowedTypes=["feat","fix","build","chore"];function checkConventionalMessage(message){const pattern=message.match(titlePattern)?.groups||{};const{type,scope,breaking,subject}=pattern;const errors=[!type&&'The pull request title must match the pattern of "<type>[!]: <subject>" which is a reduced set of https://www.conventionalcommits.org/en/v1.0.0/',typeof type==="string"&&allowedTypes.includes(type.toLowerCase())===false&&"The type in a pull request title must be one of "+allowedTypes.map(name=>'"'+name+'"').join(", ")+".",typeof type==="string"&&/^[a-z]+$/.test(type)===false&&"The type in a pull request title must be in lower case only.",scope&&"A scope in a pull request title is never allowed.",typeof type==="string"&&typeof subject!=="string"&&"The subject in a pull request title must be provided.",typeof subject==="string"&&(subject.match(/^ +/)?.[0].length||0)!==1&&'A single space must be after ":" symbol.',typeof subject==="string"&&/^[a-z]/.test(subject.trim())===false&&"The subject must start with a lower case latin alphabet.",typeof subject==="string"&&/[\s\.]+$/.test(subject)&&/\.{3}$/.test(subject.trim())===false&&"The subject must not end with a period or a space."].filter(error=>typeof error==="string");return{type:allowedTypes.includes(type)?type:void 0,breaking:!!breaking,subject:typeof subject==="string"?subject.trim().replace(/[\s\.]+$/,"")+(/\.{3}$/.test(subject.trim())?"...":""):message,errors}}0&&(module.exports={allowedTypes,checkConventionalMessage});
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_src = require("./src.js");
3
+ exports.allowedTypes = require_src.allowedTypes;
4
+ exports.checkConventionalMessage = require_src.checkConventionalMessage;
5
+ exports.debug = require_src.debug;
6
+ exports.getCurrentPackageVersion = require_src.getCurrentPackageVersion;
7
+ exports.getGitHistory = require_src.getGitHistory;
8
+ exports.getReleaseNote = require_src.getReleaseNote;
9
+ exports.getReleaseType = require_src.getReleaseType;
10
+ exports.npm = require_src.npm;
11
+ exports.run = require_src.run;
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1,14 @@
1
- "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:true})};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from==="object"||typeof from==="function"){for(let key of __getOwnPropNames(from))if(!__hasOwnProp.call(to,key)&&key!==except)__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:true}):target,mod));var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:true}),mod);var lint_commit_message_exports={};__export(lint_commit_message_exports,{default:()=>main});module.exports=__toCommonJS(lint_commit_message_exports);var fs=__toESM(require("fs/promises"));var titlePattern=/^(?<type>\w+)(?<scope>\(.*?\))?(?<breaking>\!)?:(?<subject>.+)/;var allowedTypes=["feat","fix","build","chore"];function checkConventionalMessage(message){const pattern=message.match(titlePattern)?.groups||{};const{type,scope,breaking,subject}=pattern;const errors=[!type&&'The pull request title must match the pattern of "<type>[!]: <subject>" which is a reduced set of https://www.conventionalcommits.org/en/v1.0.0/',typeof type==="string"&&allowedTypes.includes(type.toLowerCase())===false&&"The type in a pull request title must be one of "+allowedTypes.map(name=>'"'+name+'"').join(", ")+".",typeof type==="string"&&/^[a-z]+$/.test(type)===false&&"The type in a pull request title must be in lower case only.",scope&&"A scope in a pull request title is never allowed.",typeof type==="string"&&typeof subject!=="string"&&"The subject in a pull request title must be provided.",typeof subject==="string"&&(subject.match(/^ +/)?.[0].length||0)!==1&&'A single space must be after ":" symbol.',typeof subject==="string"&&/^[a-z]/.test(subject.trim())===false&&"The subject must start with a lower case latin alphabet.",typeof subject==="string"&&/[\s\.]+$/.test(subject)&&/\.{3}$/.test(subject.trim())===false&&"The subject must not end with a period or a space."].filter(error=>typeof error==="string");return{type:allowedTypes.includes(type)?type:void 0,breaking:!!breaking,subject:typeof subject==="string"?subject.trim().replace(/[\s\.]+$/,"")+(/\.{3}$/.test(subject.trim())?"...":""):message,errors}}async function main(messageFilePath){console.log("Verifying the commit message...");const message=(await fs.readFile(messageFilePath,"utf-8")).trim();console.log(" input =",message);const{errors}=checkConventionalMessage(message);for(const error of errors){console.error(" error =",error)}process.exitCode=errors.length}
1
+ const require_src = require("./src.js");
2
+ let node_fs_promises = require("node:fs/promises");
3
+ node_fs_promises = require_src.__toESM(node_fs_promises);
4
+ //#region src/lint-commit-message.ts
5
+ (async () => {
6
+ const messageFilePath = process.argv[2];
7
+ console.log("Verifying the commit message...");
8
+ const message = (await node_fs_promises.readFile(messageFilePath, "utf-8")).trim();
9
+ console.log(" input =", message);
10
+ const { errors } = require_src.checkConventionalMessage(message);
11
+ for (const error of errors) console.error(" error =", error);
12
+ process.exitCode = errors.length;
13
+ })();
14
+ //#endregion
@@ -0,0 +1 @@
1
+ export {};