@thisismanta/semantic-version 9.1.4 → 11.0.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/lib/run.js CHANGED
@@ -1,56 +1,27 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.run = run;
37
- const cp = __importStar(require("child_process"));
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_chunk = require("./chunk.js");
3
+ let node_child_process = require("node:child_process");
4
+ node_child_process = require_chunk.__toESM(node_child_process);
5
+ let node_fs = require("node:fs");
6
+ node_fs = require_chunk.__toESM(node_fs);
7
+ //#region src/run.ts
38
8
  function run(command) {
39
- return new Promise((resolve, reject) => {
40
- cp.exec(command, (error, stdout, stderr) => {
41
- console.log('::debug::' + command);
42
- console.log('::debug::Output:');
43
- console.log('::debug::=>', stdout);
44
- if (stderr.trim().length > 0) {
45
- console.log('::debug::Error:');
46
- console.log('::debug::=>', stderr);
47
- }
48
- if (error) {
49
- reject(error);
50
- }
51
- else {
52
- resolve(stdout.trim());
53
- }
54
- });
55
- });
9
+ return new Promise((resolve, reject) => {
10
+ node_child_process.exec(command, (error, stdout, stderr) => {
11
+ console.log("::debug::" + command);
12
+ console.log("::debug::Output:");
13
+ console.log("::debug::=>", stdout);
14
+ if (stderr.trim().length > 0) {
15
+ console.log("::debug::Error:");
16
+ console.log("::debug::=>", stderr);
17
+ }
18
+ if (error) reject(error);
19
+ else resolve(stdout.trim());
20
+ });
21
+ });
56
22
  }
23
+ const packageJSON = JSON.parse(node_fs.readFileSync("./package.json", { encoding: "utf-8" }));
24
+ const npm = packageJSON?.packageManager?.replace(/@.*$/, "") ?? packageJSON?.devEngines?.packageManager?.name ?? "npm";
25
+ //#endregion
26
+ exports.npm = npm;
27
+ exports.run = run;
package/package.json CHANGED
@@ -1,42 +1,51 @@
1
1
  {
2
2
  "name": "@thisismanta/semantic-version",
3
- "version": "9.1.4",
4
- "author": "Anantachai Saothong <thisismanta@gmail.com>",
3
+ "version": "11.0.0",
5
4
  "license": "ISC",
5
+ "author": "Anantachai Saothong <thisismanta@gmail.com>",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/ThisIsManta/semantic-version.git"
9
9
  },
10
- "engines": {
11
- "node": ">=20.0.0"
12
- },
13
- "packageManager": "npm@11.6.2",
14
- "main": "lib/index.js",
15
- "types": "lib/index.d.ts",
16
10
  "bin": {
17
11
  "lint-commit-message": "bin/lint-commit-message",
18
- "auto-npm-version": "bin/auto-npm-version"
12
+ "make-next-release": "bin/make-next-release"
19
13
  },
20
14
  "files": [
21
15
  "lib",
22
16
  "bin"
23
17
  ],
18
+ "main": "lib/index.js",
19
+ "types": "lib/index.d.ts",
24
20
  "scripts": {
25
- "test": "vitest --no-watch",
26
- "build": "rm -rf lib && tsc",
21
+ "test": "tsc && vitest",
22
+ "build": "rm -rf lib && find src -name '*.ts' ! -name '*.test.ts' | xargs npm exec rolldown -- --transform.target node22 --format commonjs --dir lib --chunk-file-names [name].js",
27
23
  "preversion": "npm run build",
28
24
  "version": "npm publish --provenance --access public"
29
25
  },
30
26
  "devDependencies": {
31
- "@types/node": "^20.19.30",
27
+ "@actions/github": "^9.0.0",
28
+ "@types/node": "~24.12.2",
32
29
  "@types/semver": "^7.7.1",
33
- "lefthook": "^2.0.15",
34
- "typescript": "^5.9.3",
35
- "vite": "^7.3.1",
36
- "vitest": "^4.0.17"
30
+ "lefthook": "^2.1.5",
31
+ "semver": "^7.7.4",
32
+ "typescript": "^6.0.2",
33
+ "vite": "^8.0.5",
34
+ "vitest": "^4.1.2"
37
35
  },
38
- "dependencies": {
39
- "@actions/github": "^7.0.0",
40
- "semver": "^7.7.3"
36
+ "devEngines": {
37
+ "packageManager": {
38
+ "name": "npm",
39
+ "version": "^11.9.0",
40
+ "onFail": "error"
41
+ },
42
+ "runtime": {
43
+ "name": "node",
44
+ "version": "^24.14.0",
45
+ "onFail": "warn"
46
+ }
47
+ },
48
+ "engines": {
49
+ "node": ">=22.0.0"
41
50
  }
42
51
  }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- require('../lib/auto-npm-version').default()
@@ -1,9 +0,0 @@
1
- export default function main(): Promise<void>;
2
- interface GitCommit {
3
- hash: string;
4
- type: string | undefined;
5
- breaking: boolean;
6
- subject: string;
7
- }
8
- export declare function getReleaseType(commits: Array<GitCommit>): string | null;
9
- export {};
@@ -1,180 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.default = main;
40
- exports.getReleaseType = getReleaseType;
41
- const valid_1 = __importDefault(require("semver/functions/valid"));
42
- const github = __importStar(require("@actions/github"));
43
- const index_1 = require("./index");
44
- const run_1 = require("./run");
45
- async function main() {
46
- // See https://github.com/actions/checkout#push-a-commit-using-the-built-in-token
47
- const existingGitUserName = await (0, run_1.run)(`git config user.name`).catch(() => '');
48
- if (!existingGitUserName) {
49
- console.log('Setting Git commit author for further use in `npm version` and `git push` command...');
50
- const name = github.context.payload.pusher?.name || github.context.actor;
51
- console.log(' user.name =', name);
52
- await (0, run_1.run)(`git config user.name ${name}`);
53
- const email = github.context.payload.pusher?.email || 'github-actions@github.com';
54
- console.log(' user.email =', name);
55
- await (0, run_1.run)(`git config user.email ${email}`);
56
- }
57
- console.log('Getting the remote repository...');
58
- const remote = await (0, run_1.run)(`git remote`) || 'origin';
59
- console.log(' remote =', remote);
60
- if (!process.env.GITHUB_TOKEN) {
61
- throw new Error('Expected "GITHUB_TOKEN" to be set in the environment variables.');
62
- }
63
- // See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#configuring-the-default-github_token-permissions
64
- console.log('Checking if the current setup has the permission to push to the remote repository...');
65
- await (0, run_1.run)(`git push --dry-run ${remote}`);
66
- console.log(' OK');
67
- console.log('Getting the current package version...');
68
- const currentVersion = await getCurrentPackageVersion();
69
- console.log(' version =', currentVersion ?? JSON.stringify(currentVersion));
70
- if (!currentVersion) {
71
- throw new Error('Expected "version" field to exist in package.json.');
72
- }
73
- console.log('Getting the commit history since the current version...');
74
- const commits = await getGitHistory(currentVersion);
75
- if (commits.length === 0) {
76
- console.log(' Found 0 commits.');
77
- }
78
- else {
79
- for (const commit of commits) {
80
- console.log(` - ${commit.type}${commit.breaking ? '!' : ''}: ${commit.subject} (${commit.hash.substring(0, 7)})`);
81
- }
82
- }
83
- console.log('Determining the upcoming release type...');
84
- const releaseType = getReleaseType(commits);
85
- console.log(' ' + JSON.stringify(releaseType));
86
- if (!releaseType) {
87
- console.log('');
88
- console.log('Done without a new version.');
89
- return;
90
- }
91
- console.log('Running `npm version` command and its pre-post scripts...');
92
- await (0, run_1.run)(`npm version ${releaseType} --git-tag-version --no-commit-hooks`);
93
- console.log(' OK');
94
- console.log('Pushing the new version to the remote repository...');
95
- await (0, run_1.run)(`git push --follow-tags ${remote}`);
96
- console.log(' OK');
97
- console.log('Verifying the new version...');
98
- const latestVersion = await getCurrentPackageVersion();
99
- console.log(' version =', latestVersion ?? JSON.stringify(latestVersion));
100
- console.log('Creating a release note on GitHub...');
101
- const releaseNote = getReleaseNote(commits);
102
- // See https://octokit.github.io/rest.js/v19#repos-create-release
103
- const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
104
- const releaseCreationRespond = await octokit.rest.repos.createRelease({
105
- ...github.context.repo,
106
- tag_name: 'v' + latestVersion,
107
- body: releaseNote,
108
- make_latest: 'legacy',
109
- });
110
- console.log(' ' + releaseCreationRespond.data.html_url);
111
- console.log('');
112
- console.log('Done with the new version.');
113
- }
114
- async function getCurrentPackageVersion() {
115
- const version = JSON.parse(await (0, run_1.run)('npm pkg get version'));
116
- if (typeof version === 'string' && (0, valid_1.default)(version)) {
117
- return version;
118
- }
119
- else {
120
- throw new Error('Expected a valid version field in package.json.');
121
- }
122
- }
123
- async function getGitHistory(version) {
124
- const tag = (await (0, run_1.run)(`git tag --list v${version}`) ||
125
- await (0, run_1.run)('git describe --tags --abbrev=0'));
126
- return getCommits(await (0, run_1.run)(`git --no-pager log ${tag ? tag + '..HEAD' : ''} --format=%H%s`));
127
- }
128
- function getCommits(gitLogs) {
129
- return gitLogs
130
- .split('\n')
131
- .filter(line => line.length > 0)
132
- .map(line => ({
133
- hash: line.substring(0, 40),
134
- message: line.substring(40),
135
- }))
136
- .filter(({ message }) => (0, valid_1.default)(message) === null)
137
- .map(({ hash, message }) => {
138
- const { type, breaking, subject } = (0, index_1.checkConventionalMessage)(message);
139
- return { hash, type, breaking, subject };
140
- });
141
- }
142
- function getReleaseType(commits) {
143
- if (commits.find(({ breaking }) => breaking)) {
144
- return 'major';
145
- }
146
- if (commits.find(({ type }) => type === 'feat')) {
147
- return 'minor';
148
- }
149
- if (commits.find(({ type }) => type === 'fix' || type === 'build')) {
150
- return 'patch';
151
- }
152
- return null;
153
- }
154
- function getReleaseNote(commits) {
155
- const groups = {
156
- 'BREAKING CHANGES': [],
157
- 'Features': [],
158
- 'Bug Fixes': [],
159
- 'Others': [],
160
- };
161
- for (const commit of commits) {
162
- if (commit.breaking) {
163
- groups['BREAKING CHANGES'].push(commit);
164
- }
165
- else if (commit.type === 'feat') {
166
- groups['Features'].push(commit);
167
- }
168
- else if (commit.type === 'fix') {
169
- groups['Bug Fixes'].push(commit);
170
- }
171
- else {
172
- groups['Others'].push(commit);
173
- }
174
- }
175
- return Object.entries(groups)
176
- .filter(([title, commits]) => commits.length > 0)
177
- .map(([title, commits]) => `### ${title}\n\n` +
178
- commits.map(({ subject, hash }) => `- ${subject} (${hash})`).join('\n'))
179
- .join('\n\n');
180
- }
package/lib/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export declare const allowedTypes: readonly ["feat", "fix", "build", "chore"];
2
- export type SemanticType = typeof allowedTypes[number];
3
- export declare function checkConventionalMessage(message: string): {
4
- type: "feat" | "fix" | "build" | "chore" | undefined;
5
- breaking: boolean;
6
- subject: string;
7
- errors: string[];
8
- };
@@ -1 +0,0 @@
1
- export default function main(messageFilePath: string): Promise<void>;
package/lib/run.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function run(command: string): Promise<string>;