@git.zone/cli 7.2.6 → 7.3.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.
Files changed (43) hide show
  1. package/assets/templates/npm/.package.json +1 -1
  2. package/assets/templates/service/.package.json +1 -1
  3. package/assets/templates/wcc/.package.json +1 -1
  4. package/assets/templates/website/.package.json +1 -1
  5. package/dist_ts/00_commitinfo_data.js +1 -1
  6. package/dist_ts/helpers.climode.js +2 -1
  7. package/dist_ts/helpers.workflow.d.ts +19 -1
  8. package/dist_ts/helpers.workflow.js +31 -2
  9. package/dist_ts/mod_config/index.js +18 -2
  10. package/dist_ts/mod_release/classes.detachedrelease.d.ts +85 -0
  11. package/dist_ts/mod_release/classes.detachedrelease.js +506 -0
  12. package/dist_ts/mod_release/classes.releasejournal.d.ts +34 -0
  13. package/dist_ts/mod_release/classes.releasejournal.js +134 -2
  14. package/dist_ts/mod_release/helpers.giteaassets.d.ts +19 -0
  15. package/dist_ts/mod_release/helpers.giteaassets.js +53 -4
  16. package/dist_ts/mod_release/helpers.gitremote.d.ts +52 -0
  17. package/dist_ts/mod_release/helpers.gitremote.js +87 -0
  18. package/dist_ts/mod_release/helpers.releasebranch.d.ts +5 -0
  19. package/dist_ts/mod_release/helpers.releasebranch.js +39 -15
  20. package/dist_ts/mod_release/helpers.releasepreparation.js +18 -8
  21. package/dist_ts/mod_release/helpers.releasepublication.d.ts +3 -0
  22. package/dist_ts/mod_release/helpers.releasepublication.js +19 -15
  23. package/dist_ts/mod_release/index.js +303 -66
  24. package/dist_ts/mod_services/classes.interprocesslock.d.ts +12 -0
  25. package/dist_ts/mod_services/classes.interprocesslock.js +35 -12
  26. package/dist_ts/paths.d.ts +6 -0
  27. package/dist_ts/paths.js +7 -1
  28. package/package.json +4 -4
  29. package/readme.md +158 -21
  30. package/ts/00_commitinfo_data.ts +1 -1
  31. package/ts/helpers.climode.ts +1 -0
  32. package/ts/helpers.workflow.ts +50 -0
  33. package/ts/mod_config/index.ts +19 -0
  34. package/ts/mod_release/classes.detachedrelease.ts +655 -0
  35. package/ts/mod_release/classes.releasejournal.ts +181 -1
  36. package/ts/mod_release/helpers.giteaassets.ts +67 -5
  37. package/ts/mod_release/helpers.gitremote.ts +147 -0
  38. package/ts/mod_release/helpers.releasebranch.ts +75 -30
  39. package/ts/mod_release/helpers.releasepreparation.ts +25 -7
  40. package/ts/mod_release/helpers.releasepublication.ts +27 -36
  41. package/ts/mod_release/index.ts +443 -87
  42. package/ts/mod_services/classes.interprocesslock.ts +44 -15
  43. package/ts/paths.ts +10 -0
@@ -7,6 +7,12 @@ interface ILockOwner {
7
7
  createdAt: string;
8
8
  }
9
9
 
10
+ /** The process a held lock names, as far as its owner metadata tells. */
11
+ export interface IInterProcessLockHolder {
12
+ pid: number | null;
13
+ createdAt: string | null;
14
+ }
15
+
10
16
  export interface IInterProcessLockOptions {
11
17
  lockPath: string;
12
18
  description: string;
@@ -102,21 +108,11 @@ export class InterProcessLock {
102
108
  }
103
109
  const remaining = deadlineAt - Date.now();
104
110
  if (remaining <= 0) {
105
- let ownerDescription = 'owner metadata unavailable';
106
- try {
107
- const existingOwner = JSON.parse(await plugins.fs.readFile(ownerPath, 'utf8')) as {
108
- pid?: unknown;
109
- createdAt?: unknown;
110
- };
111
- if (
112
- typeof existingOwner.pid === 'number' &&
113
- typeof existingOwner.createdAt === 'string'
114
- ) {
115
- ownerDescription = `pid ${existingOwner.pid}, created ${existingOwner.createdAt}`;
116
- }
117
- } catch {
118
- // Incomplete stale locks remain fail-closed and require operator review.
119
- }
111
+ const holder = await this.readOwnerMetadata();
112
+ const ownerDescription =
113
+ holder.pid !== null && holder.createdAt !== null
114
+ ? `pid ${holder.pid}, created ${holder.createdAt}`
115
+ : 'owner metadata unavailable';
120
116
  throw new Error(
121
117
  `${this.description} is locked (${ownerDescription}). ` +
122
118
  `If that process no longer exists, inspect and remove ${this.lockPath}.`,
@@ -127,6 +123,39 @@ export class InterProcessLock {
127
123
  }
128
124
  }
129
125
 
126
+ /**
127
+ * The holder of the lock, or null while it is free. A lock whose owner
128
+ * metadata is missing or incomplete is still held; its holder is then
129
+ * unknown, and stale-lock recovery stays manual.
130
+ */
131
+ public async readHolder(): Promise<IInterProcessLockHolder | null> {
132
+ try {
133
+ await plugins.fs.lstat(this.lockPath);
134
+ } catch (error) {
135
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return null;
136
+ throw new Error(`${this.description} lock could not be inspected.`, { cause: error });
137
+ }
138
+ return this.readOwnerMetadata();
139
+ }
140
+
141
+ private async readOwnerMetadata(): Promise<IInterProcessLockHolder> {
142
+ try {
143
+ const owner: unknown = JSON.parse(
144
+ await plugins.fs.readFile(plugins.path.join(this.lockPath, 'owner.json'), 'utf8'),
145
+ );
146
+ if (
147
+ isPlainObject(owner) &&
148
+ typeof owner.pid === 'number' &&
149
+ typeof owner.createdAt === 'string'
150
+ ) {
151
+ return { pid: owner.pid, createdAt: owner.createdAt };
152
+ }
153
+ } catch {
154
+ // Incomplete stale locks remain fail-closed and require operator review.
155
+ }
156
+ return { pid: null, createdAt: null };
157
+ }
158
+
130
159
  private async release(tokenArg: string, requireOwnerArg: boolean): Promise<void> {
131
160
  const ownerPath = plugins.path.join(this.lockPath, 'owner.json');
132
161
  if (requireOwnerArg) {
package/ts/paths.ts CHANGED
@@ -7,3 +7,13 @@ export let packageDir = plugins.path.join(
7
7
  export let assetsDir = plugins.path.join(packageDir, './assets');
8
8
  export let templatesDir = plugins.path.join(assetsDir, 'templates');
9
9
  export let cwd = process.cwd();
10
+
11
+ /**
12
+ * The executable that runs this build of gitzone: `cli.js` loads `dist_ts`, and
13
+ * `cli.ts.js` runs the TypeScript sources through tsrun. A process that starts
14
+ * another gitzone process uses it, so both run the same code.
15
+ */
16
+ export let cliEntryPath = plugins.path.join(
17
+ packageDir,
18
+ import.meta.url.endsWith('.ts') ? 'cli.ts.js' : 'cli.js',
19
+ );