@monoweave/git 1.20.0 → 2.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/getCommitMessages.js +4 -8
- package/lib/gitCommands.js +27 -79
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -19
- package/lib/parseRepositoryProperty.js +13 -8
- package/lib/testMock.d.ts +86 -0
- package/lib/testMock.js +115 -0
- package/package.json +26 -11
package/lib/getCommitMessages.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCommitMessages = void 0;
|
|
4
|
-
const gitCommands_1 = require("./gitCommands");
|
|
1
|
+
import { gitLastTaggedCommit, gitLog } from './gitCommands.js';
|
|
5
2
|
const DELIMITER = '-----------------monoweave-----------------';
|
|
6
|
-
const getCommitMessages = async (config, context) => {
|
|
3
|
+
export const getCommitMessages = async (config, context) => {
|
|
7
4
|
const to = config.git.commitSha;
|
|
8
5
|
let from = config.git.baseBranch;
|
|
9
6
|
if (!from) {
|
|
10
|
-
const { sha, tag } = await
|
|
7
|
+
const { sha, tag } = await gitLastTaggedCommit({
|
|
11
8
|
cwd: config.cwd,
|
|
12
9
|
context,
|
|
13
10
|
prerelease: config.prerelease,
|
|
@@ -18,7 +15,7 @@ const getCommitMessages = async (config, context) => {
|
|
|
18
15
|
return [];
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
const logOutput = await
|
|
18
|
+
const logOutput = await gitLog(from, to, {
|
|
22
19
|
cwd: config.cwd,
|
|
23
20
|
DELIMITER,
|
|
24
21
|
context,
|
|
@@ -32,4 +29,3 @@ const getCommitMessages = async (config, context) => {
|
|
|
32
29
|
})
|
|
33
30
|
.filter((msg) => msg.body);
|
|
34
31
|
};
|
|
35
|
-
exports.getCommitMessages = getCommitMessages;
|
package/lib/gitCommands.js
CHANGED
|
@@ -1,51 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.gitCommit = exports.gitAdd = exports.gitGlob = exports.gitLastTaggedCommit = exports.gitPush = exports.gitPull = exports.gitPushTags = exports.gitTag = exports.gitLog = exports.gitDiffTree = exports.gitResolveSha = exports.gitCheckout = exports.gitUpstreamBranch = void 0;
|
|
40
|
-
const io_1 = require("@monoweave/io");
|
|
41
|
-
const logging_1 = __importStar(require("@monoweave/logging"));
|
|
42
|
-
const micromatch_1 = __importDefault(require("micromatch"));
|
|
1
|
+
import { exec } from '@monoweave/io';
|
|
2
|
+
import logging, { assertProduction } from '@monoweave/logging';
|
|
3
|
+
import micromatch from 'micromatch';
|
|
43
4
|
const git = async (subcommand, { cwd, context }) => {
|
|
44
5
|
const command = `git ${subcommand}`;
|
|
45
|
-
|
|
46
|
-
return await
|
|
6
|
+
logging.debug(`[Exec] ${command}`, { report: context?.report });
|
|
7
|
+
return await exec(command, { cwd, env: { GIT_TERMINAL_PROMPT: '0', ...process.env } });
|
|
47
8
|
};
|
|
48
|
-
const gitUpstreamBranch = async ({ cwd, context, remote, }) => {
|
|
9
|
+
export const gitUpstreamBranch = async ({ cwd, context, remote, }) => {
|
|
49
10
|
if (process.env.GITHUB_ACTION) {
|
|
50
11
|
if (process.env.GITHUB_REF && process.env.GITHUB_EVENT_NAME === 'push') {
|
|
51
12
|
// In GitHub actions for push events, we can use GITHUB_REF.
|
|
@@ -61,24 +22,21 @@ const gitUpstreamBranch = async ({ cwd, context, remote, }) => {
|
|
|
61
22
|
});
|
|
62
23
|
return branch;
|
|
63
24
|
};
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const branch = await (0, exports.gitUpstreamBranch)({ cwd, context, remote });
|
|
25
|
+
export const gitCheckout = async ({ files }, { cwd, context, remote }) => {
|
|
26
|
+
const branch = await gitUpstreamBranch({ cwd, context, remote });
|
|
67
27
|
await git(`checkout ${branch.trim()} -- ${files.map((f) => `"${f}"`).join(' ')}`, {
|
|
68
28
|
cwd,
|
|
69
29
|
context,
|
|
70
30
|
});
|
|
71
31
|
};
|
|
72
|
-
|
|
73
|
-
const gitResolveSha = async (ref, { cwd, context }) => {
|
|
32
|
+
export const gitResolveSha = async (ref, { cwd, context }) => {
|
|
74
33
|
const { stdout } = await git(`log --format=%H -n 1 ${ref}`, {
|
|
75
34
|
cwd,
|
|
76
35
|
context,
|
|
77
36
|
});
|
|
78
37
|
return stdout.trim();
|
|
79
38
|
};
|
|
80
|
-
|
|
81
|
-
const gitDiffTree = async (ref, { cwd, context, onlyIncludeDeletedFiles, paths, fetch = false, }) => {
|
|
39
|
+
export const gitDiffTree = async (ref, { cwd, context, onlyIncludeDeletedFiles, paths, fetch = false, }) => {
|
|
82
40
|
if (fetch) {
|
|
83
41
|
await git('fetch', { cwd, context });
|
|
84
42
|
}
|
|
@@ -96,8 +54,7 @@ const gitDiffTree = async (ref, { cwd, context, onlyIncludeDeletedFiles, paths,
|
|
|
96
54
|
});
|
|
97
55
|
return stdout.trim();
|
|
98
56
|
};
|
|
99
|
-
|
|
100
|
-
const gitLog = async (from, to, { cwd, DELIMITER, context }) => {
|
|
57
|
+
export const gitLog = async (from, to, { cwd, DELIMITER, context }) => {
|
|
101
58
|
let command = `log ${from}..${to} --format=%H%n%B%n${DELIMITER}`;
|
|
102
59
|
if (from === to) {
|
|
103
60
|
/* Special case where we'll just return a single log entry for "to". */
|
|
@@ -106,14 +63,12 @@ const gitLog = async (from, to, { cwd, DELIMITER, context }) => {
|
|
|
106
63
|
const { stdout } = await git(command, { cwd, context });
|
|
107
64
|
return stdout;
|
|
108
65
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
(0, logging_1.assertProduction)();
|
|
66
|
+
export const gitTag = async (tag, { cwd, context }) => {
|
|
67
|
+
assertProduction();
|
|
112
68
|
await git(`tag ${tag} -m ${tag}`, { cwd, context });
|
|
113
69
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(0, logging_1.assertProduction)();
|
|
70
|
+
export const gitPushTags = async ({ cwd, remote, context, dryRun = false, }) => {
|
|
71
|
+
assertProduction();
|
|
117
72
|
const args = ['--tags'];
|
|
118
73
|
if (dryRun)
|
|
119
74
|
args.push('--dry-run');
|
|
@@ -122,9 +77,8 @@ const gitPushTags = async ({ cwd, remote, context, dryRun = false, }) => {
|
|
|
122
77
|
context,
|
|
123
78
|
});
|
|
124
79
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
(0, logging_1.assertProduction)();
|
|
80
|
+
export const gitPull = async ({ cwd, remote, context, autostash = false, strategyOption, }) => {
|
|
81
|
+
assertProduction();
|
|
128
82
|
const args = ['--rebase', '--no-verify'];
|
|
129
83
|
if (autostash)
|
|
130
84
|
args.push('--autostash');
|
|
@@ -135,9 +89,8 @@ const gitPull = async ({ cwd, remote, context, autostash = false, strategyOption
|
|
|
135
89
|
context,
|
|
136
90
|
});
|
|
137
91
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
(0, logging_1.assertProduction)();
|
|
92
|
+
export const gitPush = async ({ cwd, remote, context, dryRun = false, }) => {
|
|
93
|
+
assertProduction();
|
|
141
94
|
const args = ['--no-verify'];
|
|
142
95
|
if (dryRun)
|
|
143
96
|
args.push('--dry-run');
|
|
@@ -146,8 +99,7 @@ const gitPush = async ({ cwd, remote, context, dryRun = false, }) => {
|
|
|
146
99
|
context,
|
|
147
100
|
});
|
|
148
101
|
};
|
|
149
|
-
|
|
150
|
-
const gitLastTaggedCommit = async ({ cwd, context, prerelease = false, }) => {
|
|
102
|
+
export const gitLastTaggedCommit = async ({ cwd, context, prerelease = false, }) => {
|
|
151
103
|
let command = "describe --abbrev=0 --match '*@*[[:digit:]]*.[[:digit:]]*.[[:digit:]]*'";
|
|
152
104
|
if (!prerelease) {
|
|
153
105
|
// The glob matches prerelease ranges. The 'complexity' comes from not wanting
|
|
@@ -160,7 +112,7 @@ const gitLastTaggedCommit = async ({ cwd, context, prerelease = false, }) => {
|
|
|
160
112
|
tag = (await git(command, { cwd, context })).stdout.trim();
|
|
161
113
|
}
|
|
162
114
|
catch {
|
|
163
|
-
|
|
115
|
+
logging.warning('[Exec] Fetching most recent tag failed, falling back to HEAD', {
|
|
164
116
|
report: context?.report,
|
|
165
117
|
});
|
|
166
118
|
}
|
|
@@ -172,23 +124,19 @@ const gitLastTaggedCommit = async ({ cwd, context, prerelease = false, }) => {
|
|
|
172
124
|
.trim();
|
|
173
125
|
return { sha, tag };
|
|
174
126
|
};
|
|
175
|
-
|
|
176
|
-
const gitGlob = async (globs, { cwd, context }) => {
|
|
127
|
+
export const gitGlob = async (globs, { cwd, context }) => {
|
|
177
128
|
const rawStdout = [
|
|
178
129
|
(await git('ls-files --modified', { cwd, context })).stdout,
|
|
179
130
|
(await git('ls-files -o --exclude-standard', { cwd, context })).stdout,
|
|
180
131
|
].join('\n');
|
|
181
132
|
const files = rawStdout.split('\n').filter((v) => Boolean(v));
|
|
182
|
-
return (
|
|
133
|
+
return micromatch(files, globs);
|
|
183
134
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
(0, logging_1.assertProduction)();
|
|
135
|
+
export const gitAdd = async (paths, { cwd, context }) => {
|
|
136
|
+
assertProduction();
|
|
187
137
|
await git(`add ${paths.join(' ')}`, { cwd, context });
|
|
188
138
|
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
(0, logging_1.assertProduction)();
|
|
139
|
+
export const gitCommit = async (message, { cwd, context }) => {
|
|
140
|
+
assertProduction();
|
|
192
141
|
await git(`commit -m "${message}" -n`, { cwd, context });
|
|
193
142
|
};
|
|
194
|
-
exports.gitCommit = gitCommit;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './gitCommands';
|
|
2
|
-
export * from './getCommitMessages';
|
|
3
|
-
export * from './parseRepositoryProperty';
|
|
1
|
+
export * from './gitCommands.js';
|
|
2
|
+
export * from './getCommitMessages.js';
|
|
3
|
+
export * from './parseRepositoryProperty.js';
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./gitCommands"), exports);
|
|
18
|
-
__exportStar(require("./getCommitMessages"), exports);
|
|
19
|
-
__exportStar(require("./parseRepositoryProperty"), exports);
|
|
1
|
+
export * from './gitCommands.js';
|
|
2
|
+
export * from './getCommitMessages.js';
|
|
3
|
+
export * from './parseRepositoryProperty.js';
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseRepositoryProperty = void 0;
|
|
4
|
-
const core_1 = require("@yarnpkg/core");
|
|
1
|
+
import { structUtils } from '@yarnpkg/core';
|
|
5
2
|
const REPOSITORY_PATTERNS = [
|
|
3
|
+
[
|
|
4
|
+
/((?:git\+)?(ssh:\/\/git@github.com)\/([^.]+)\/([^/.]+))(?:\.git)?/,
|
|
5
|
+
(m) => ({
|
|
6
|
+
repoUrl: `https://github.com/${m[3]}/${m[4]}`,
|
|
7
|
+
host: 'https://github.com',
|
|
8
|
+
owner: m[3],
|
|
9
|
+
repository: m[4],
|
|
10
|
+
}),
|
|
11
|
+
],
|
|
6
12
|
[
|
|
7
13
|
/((?:git\+)?(https?:\/\/[^/]+)\/([^.]+)\/([^/.]+))(?:\.git)?/,
|
|
8
14
|
(m) => ({ repoUrl: m[1], host: m[2], owner: m[3], repository: m[4] }),
|
|
@@ -17,7 +23,7 @@ const REPOSITORY_PATTERNS = [
|
|
|
17
23
|
}),
|
|
18
24
|
],
|
|
19
25
|
];
|
|
20
|
-
const parseRepositoryProperty = async (workspace, { fallbackToTopLevel = true } = {}) => {
|
|
26
|
+
export const parseRepositoryProperty = async (workspace, { fallbackToTopLevel = true } = {}) => {
|
|
21
27
|
const rawManifest = workspace.manifest.raw;
|
|
22
28
|
const data = {
|
|
23
29
|
host: null,
|
|
@@ -42,10 +48,9 @@ const parseRepositoryProperty = async (workspace, { fallbackToTopLevel = true }
|
|
|
42
48
|
catch { }
|
|
43
49
|
}
|
|
44
50
|
if (fallbackToTopLevel &&
|
|
45
|
-
!
|
|
51
|
+
!structUtils.areDescriptorsEqual(workspace.anchoredDescriptor, workspace.project.topLevelWorkspace.anchoredDescriptor) &&
|
|
46
52
|
!data.repository) {
|
|
47
|
-
return await
|
|
53
|
+
return await parseRepositoryProperty(workspace.project.topLevelWorkspace);
|
|
48
54
|
}
|
|
49
55
|
return data;
|
|
50
56
|
};
|
|
51
|
-
exports.parseRepositoryProperty = parseRepositoryProperty;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { CommitMessage, MonoweaveConfiguration, YarnContext } from '@monoweave/types';
|
|
2
|
+
import { parseRepositoryProperty } from './parseRepositoryProperty.js';
|
|
3
|
+
declare const registry: {
|
|
4
|
+
commits: CommitMessage[];
|
|
5
|
+
filesModified: Map<string, string[]>;
|
|
6
|
+
tags: string[];
|
|
7
|
+
pushedTags: string[];
|
|
8
|
+
lastTaggedCommit?: string;
|
|
9
|
+
pushedCommits: string[];
|
|
10
|
+
stagedFiles: string[];
|
|
11
|
+
};
|
|
12
|
+
declare const _reset_: () => void;
|
|
13
|
+
declare const _commitFiles_: (sha: string, commit: string, files: string[]) => void;
|
|
14
|
+
declare const _getPushedTags_: () => string[];
|
|
15
|
+
declare const _getTags_: () => string[];
|
|
16
|
+
declare const _getRegistry_: () => typeof registry;
|
|
17
|
+
declare const gitResolveSha: (ref: string, { cwd, context }: {
|
|
18
|
+
cwd: string;
|
|
19
|
+
context: YarnContext;
|
|
20
|
+
}) => Promise<string>;
|
|
21
|
+
declare const gitUpstreamBranch: ({ cwd, context, remote, }: {
|
|
22
|
+
cwd: string;
|
|
23
|
+
context?: YarnContext;
|
|
24
|
+
remote: string;
|
|
25
|
+
}) => Promise<string>;
|
|
26
|
+
declare const gitDiffTree: (ref: string, { cwd, context, onlyIncludeDeletedFiles, paths, fetch, }: {
|
|
27
|
+
cwd: string;
|
|
28
|
+
context?: YarnContext;
|
|
29
|
+
onlyIncludeDeletedFiles?: boolean;
|
|
30
|
+
paths?: string[];
|
|
31
|
+
fetch?: boolean;
|
|
32
|
+
}) => Promise<string>;
|
|
33
|
+
declare const gitLog: (from: string, to: string, { cwd, DELIMITER, context }: {
|
|
34
|
+
cwd: string;
|
|
35
|
+
DELIMITER: string;
|
|
36
|
+
context: YarnContext;
|
|
37
|
+
}) => Promise<string>;
|
|
38
|
+
declare const gitTag: (tag: string, { cwd, context }: {
|
|
39
|
+
cwd: string;
|
|
40
|
+
context: YarnContext;
|
|
41
|
+
}) => Promise<void>;
|
|
42
|
+
declare const gitPushTags: ({ cwd, remote, context, dryRun, }: {
|
|
43
|
+
cwd: string;
|
|
44
|
+
remote: string;
|
|
45
|
+
context: YarnContext;
|
|
46
|
+
dryRun?: boolean;
|
|
47
|
+
}) => Promise<void>;
|
|
48
|
+
declare const gitPull: ({ cwd, remote, context, }: {
|
|
49
|
+
cwd: string;
|
|
50
|
+
remote: string;
|
|
51
|
+
context?: YarnContext;
|
|
52
|
+
}) => Promise<void>;
|
|
53
|
+
declare const gitPush: ({ cwd, remote, context, dryRun, }: {
|
|
54
|
+
cwd: string;
|
|
55
|
+
remote: string;
|
|
56
|
+
context: YarnContext;
|
|
57
|
+
dryRun?: boolean;
|
|
58
|
+
}) => Promise<void>;
|
|
59
|
+
declare const gitAdd: (paths: string[], { cwd, context }: {
|
|
60
|
+
cwd: string;
|
|
61
|
+
context?: YarnContext;
|
|
62
|
+
}) => Promise<void>;
|
|
63
|
+
declare const gitCommit: (message: string, { cwd, context }: {
|
|
64
|
+
cwd: string;
|
|
65
|
+
context?: YarnContext;
|
|
66
|
+
}) => Promise<void>;
|
|
67
|
+
declare const gitLastTaggedCommit: ({ cwd, context, prerelease, }: {
|
|
68
|
+
cwd: string;
|
|
69
|
+
context: YarnContext;
|
|
70
|
+
prerelease?: boolean;
|
|
71
|
+
}) => Promise<{
|
|
72
|
+
sha: string;
|
|
73
|
+
tag: string | null;
|
|
74
|
+
}>;
|
|
75
|
+
declare const getCommitMessages: (config: MonoweaveConfiguration, context: YarnContext) => Promise<CommitMessage[]>;
|
|
76
|
+
declare const gitGlob: (globs: string[], { cwd, context }: {
|
|
77
|
+
cwd: string;
|
|
78
|
+
context?: YarnContext;
|
|
79
|
+
}) => Promise<string[]>;
|
|
80
|
+
declare const gitCheckout: ({ files }: {
|
|
81
|
+
files: string[];
|
|
82
|
+
}, { cwd, context }: {
|
|
83
|
+
cwd: string;
|
|
84
|
+
context?: YarnContext;
|
|
85
|
+
}) => Promise<void>;
|
|
86
|
+
export { _commitFiles_, _getPushedTags_, _getTags_, _reset_, _getRegistry_, getCommitMessages, gitAdd, gitCommit, gitDiffTree, gitLastTaggedCommit, gitLog, gitPull, gitGlob, gitPush, gitPushTags, gitResolveSha, gitTag, gitUpstreamBranch, gitCheckout, parseRepositoryProperty, };
|
package/lib/testMock.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// This file is used for internal mocking within the monoweave codebase. It is not exposed
|
|
2
|
+
// in the production build.
|
|
3
|
+
import { parseRepositoryProperty } from './parseRepositoryProperty.js';
|
|
4
|
+
const registry = {
|
|
5
|
+
commits: [],
|
|
6
|
+
filesModified: new Map(),
|
|
7
|
+
tags: [],
|
|
8
|
+
pushedTags: [],
|
|
9
|
+
pushedCommits: [],
|
|
10
|
+
lastTaggedCommit: undefined,
|
|
11
|
+
stagedFiles: [],
|
|
12
|
+
};
|
|
13
|
+
const _reset_ = () => {
|
|
14
|
+
registry.commits = [];
|
|
15
|
+
registry.filesModified = new Map();
|
|
16
|
+
registry.tags = [];
|
|
17
|
+
registry.pushedTags = [];
|
|
18
|
+
registry.pushedCommits = [];
|
|
19
|
+
registry.lastTaggedCommit = undefined;
|
|
20
|
+
registry.stagedFiles = [];
|
|
21
|
+
};
|
|
22
|
+
const _commitFiles_ = (sha, commit, files) => {
|
|
23
|
+
registry.commits.push({ sha, body: commit });
|
|
24
|
+
registry.filesModified.set(sha, registry.filesModified.get(sha) ?? []);
|
|
25
|
+
registry.filesModified.get(sha).push(...files);
|
|
26
|
+
};
|
|
27
|
+
const _getPushedTags_ = () => {
|
|
28
|
+
return registry.pushedTags;
|
|
29
|
+
};
|
|
30
|
+
const _getTags_ = () => {
|
|
31
|
+
return registry.tags;
|
|
32
|
+
};
|
|
33
|
+
const _getRegistry_ = () => registry;
|
|
34
|
+
const gitResolveSha = async (ref, { cwd, context }) => {
|
|
35
|
+
return `sha:${ref}`;
|
|
36
|
+
};
|
|
37
|
+
const gitUpstreamBranch = async ({ cwd, context, remote, }) => {
|
|
38
|
+
return `${remote}/main`;
|
|
39
|
+
};
|
|
40
|
+
const gitDiffTree = async (ref, { cwd, context, onlyIncludeDeletedFiles, paths, fetch = false, }) => {
|
|
41
|
+
return (registry.filesModified.get(ref) ?? []).join('\n');
|
|
42
|
+
};
|
|
43
|
+
const gitLog = async (from, to, { cwd, DELIMITER, context }) => {
|
|
44
|
+
return registry.commits.map((commit) => `${commit.sha}\n${commit.body}`).join(`${DELIMITER}\n`);
|
|
45
|
+
};
|
|
46
|
+
const gitTag = async (tag, { cwd, context }) => {
|
|
47
|
+
registry.tags.push(tag);
|
|
48
|
+
registry.lastTaggedCommit = registry.commits[registry.commits.length - 1]?.sha;
|
|
49
|
+
};
|
|
50
|
+
const gitPushTags = async ({ cwd, remote, context, dryRun = false, }) => {
|
|
51
|
+
if (dryRun)
|
|
52
|
+
return;
|
|
53
|
+
registry.pushedTags = Array.from(new Set([...registry.pushedTags, ...registry.tags]));
|
|
54
|
+
};
|
|
55
|
+
const gitPull = async ({ cwd, remote, context, }) => {
|
|
56
|
+
/* do nothing */
|
|
57
|
+
};
|
|
58
|
+
const gitPush = async ({ cwd, remote, context, dryRun = false, }) => {
|
|
59
|
+
if (dryRun)
|
|
60
|
+
return;
|
|
61
|
+
for (const commit of registry.commits) {
|
|
62
|
+
registry.pushedCommits.push(commit.sha);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const gitAdd = async (paths, { cwd, context }) => {
|
|
66
|
+
registry.stagedFiles.push(...paths);
|
|
67
|
+
};
|
|
68
|
+
const gitCommit = async (message, { cwd, context }) => {
|
|
69
|
+
const newSha = Math.random().toString(36).substr(2, 5);
|
|
70
|
+
_commitFiles_(newSha, message, registry.stagedFiles);
|
|
71
|
+
registry.stagedFiles = [];
|
|
72
|
+
};
|
|
73
|
+
const gitLastTaggedCommit = async ({ cwd, context, prerelease = false, }) => {
|
|
74
|
+
if (!registry.lastTaggedCommit) {
|
|
75
|
+
throw new Error('No tagged commit.');
|
|
76
|
+
}
|
|
77
|
+
return { sha: registry.lastTaggedCommit, tag: registry.tags[registry.tags.length - 1] ?? null };
|
|
78
|
+
};
|
|
79
|
+
const getCommitMessages = async (config, context) => {
|
|
80
|
+
const DELIMITER = '-----------------monoweave-----------------';
|
|
81
|
+
const to = config.git.commitSha;
|
|
82
|
+
let from = config.git.baseBranch;
|
|
83
|
+
if (!from) {
|
|
84
|
+
const { sha, tag } = await gitLastTaggedCommit({
|
|
85
|
+
cwd: config.cwd,
|
|
86
|
+
context,
|
|
87
|
+
prerelease: config.prerelease,
|
|
88
|
+
});
|
|
89
|
+
from = sha;
|
|
90
|
+
if (to === from && tag !== null) {
|
|
91
|
+
// the latest commit is the tagged commit, this run of monoweave should be a no-op
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const logOutput = await gitLog(from, to, {
|
|
96
|
+
cwd: config.cwd,
|
|
97
|
+
DELIMITER,
|
|
98
|
+
context,
|
|
99
|
+
});
|
|
100
|
+
return logOutput
|
|
101
|
+
.toString()
|
|
102
|
+
.split(`${DELIMITER}\n`)
|
|
103
|
+
.map((logEntry) => {
|
|
104
|
+
const [sha, ...msg] = logEntry.split('\n');
|
|
105
|
+
return { sha, body: msg.join('\n') };
|
|
106
|
+
})
|
|
107
|
+
.filter((msg) => msg.body);
|
|
108
|
+
};
|
|
109
|
+
const gitGlob = async (globs, { cwd, context }) => {
|
|
110
|
+
return globs; // TODO: not entirely accurate
|
|
111
|
+
};
|
|
112
|
+
const gitCheckout = async ({ files }, { cwd, context }) => {
|
|
113
|
+
//
|
|
114
|
+
};
|
|
115
|
+
export { _commitFiles_, _getPushedTags_, _getTags_, _reset_, _getRegistry_, getCommitMessages, gitAdd, gitCommit, gitDiffTree, gitLastTaggedCommit, gitLog, gitPull, gitGlob, gitPush, gitPushTags, gitResolveSha, gitTag, gitUpstreamBranch, gitCheckout, parseRepositoryProperty, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoweave/git",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"repository": {
|
|
5
6
|
"type": "git",
|
|
6
7
|
"url": "https://github.com/monoweave/monoweave.git",
|
|
@@ -13,12 +14,26 @@
|
|
|
13
14
|
"license": "BSD-3",
|
|
14
15
|
"publishConfig": {
|
|
15
16
|
"main": "./lib/index.js",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./lib/index.d.ts",
|
|
20
|
+
"default": "./lib/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./test-mocks": null
|
|
23
|
+
},
|
|
16
24
|
"registry": "https://registry.npmjs.org/",
|
|
17
25
|
"types": "./lib/index.d.ts",
|
|
18
26
|
"access": "public"
|
|
19
27
|
},
|
|
20
28
|
"group": "monoweave",
|
|
21
29
|
"main": "./lib/index.js",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./lib/index.d.ts",
|
|
33
|
+
"default": "./lib/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./test-mocks": null
|
|
36
|
+
},
|
|
22
37
|
"files": [
|
|
23
38
|
"lib"
|
|
24
39
|
],
|
|
@@ -30,24 +45,24 @@
|
|
|
30
45
|
"prepack": "run workspace:build \"$(pwd)\""
|
|
31
46
|
},
|
|
32
47
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@monoweave/
|
|
35
|
-
"@monoweave/
|
|
36
|
-
"@monoweave/
|
|
37
|
-
"@monoweave/types": "1.20.0",
|
|
48
|
+
"@monoweave/io": "2.0.0",
|
|
49
|
+
"@monoweave/logging": "2.0.0",
|
|
50
|
+
"@monoweave/test-utils": "0.0.0",
|
|
51
|
+
"@monoweave/types": "2.0.0",
|
|
38
52
|
"@types/micromatch": "^4.0.9",
|
|
39
|
-
"@types/node": "^22.
|
|
53
|
+
"@types/node": "^22.0.0",
|
|
40
54
|
"@yarnpkg/core": "^4.4.4",
|
|
41
55
|
"@yarnpkg/fslib": "^3.1.3",
|
|
42
|
-
"@yarnpkg/shell": "^4.1.3"
|
|
56
|
+
"@yarnpkg/shell": "^4.1.3",
|
|
57
|
+
"vitest": "^3.2.4"
|
|
43
58
|
},
|
|
44
59
|
"dependencies": {
|
|
45
60
|
"micromatch": "^4.0.8"
|
|
46
61
|
},
|
|
47
62
|
"peerDependencies": {
|
|
48
|
-
"@monoweave/io": "^
|
|
49
|
-
"@monoweave/logging": "^
|
|
50
|
-
"@monoweave/types": "^
|
|
63
|
+
"@monoweave/io": "^2.0.0",
|
|
64
|
+
"@monoweave/logging": "^2.0.0",
|
|
65
|
+
"@monoweave/types": "^2.0.0",
|
|
51
66
|
"@yarnpkg/core": "^4.4.4",
|
|
52
67
|
"@yarnpkg/fslib": "^3.1.3",
|
|
53
68
|
"@yarnpkg/shell": "^4.1.3"
|