@ozyman42/ozy-cli 0.4.8 → 0.4.9-darwin-arm64.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/multi-call-binary +0 -0
- package/package.json +11 -52
- package/bin/ozy +0 -191
- package/bin/ozy-signing-agent +0 -191
- package/bin/ozy-ssh-keygen +0 -191
- package/bin/ozy-virtual-security-key +0 -191
- package/dist/commands/git/hosts.js +0 -18
- package/dist/commands/git/hosts.js.map +0 -1
- package/dist/commands/git/index.js +0 -8
- package/dist/commands/git/index.js.map +0 -1
- package/dist/commands/git/setup.js +0 -145
- package/dist/commands/git/setup.js.map +0 -1
- package/dist/commands/index.js +0 -13
- package/dist/commands/index.js.map +0 -1
- package/dist/commands/npm/index.js +0 -7
- package/dist/commands/npm/index.js.map +0 -1
- package/dist/commands/npm/setup/git-remote.js +0 -66
- package/dist/commands/npm/setup/git-remote.js.map +0 -1
- package/dist/commands/npm/setup/index.js +0 -168
- package/dist/commands/npm/setup/index.js.map +0 -1
- package/dist/commands/npm/setup/npm-auth.js +0 -62
- package/dist/commands/npm/setup/npm-auth.js.map +0 -1
- package/dist/commands/npm/setup/package-json-validate.js +0 -47
- package/dist/commands/npm/setup/package-json-validate.js.map +0 -1
- package/dist/commands/npm/setup/package-registry.js +0 -20
- package/dist/commands/npm/setup/package-registry.js.map +0 -1
- package/dist/commands/npm/setup/setup.test.js +0 -95
- package/dist/commands/npm/setup/setup.test.js.map +0 -1
- package/dist/commands/npm/setup/trusted-publishing.js +0 -84
- package/dist/commands/npm/setup/trusted-publishing.js.map +0 -1
- package/dist/commands/npm/setup/workflow.js +0 -19
- package/dist/commands/npm/setup/workflow.js.map +0 -1
- package/dist/commands/ssh/get-sk-credential.js +0 -104
- package/dist/commands/ssh/get-sk-credential.js.map +0 -1
- package/dist/commands/ssh/index.js +0 -7
- package/dist/commands/ssh/index.js.map +0 -1
- package/dist/commands/upgrade.js +0 -199
- package/dist/commands/upgrade.js.map +0 -1
- package/dist/common/command.js +0 -15
- package/dist/common/command.js.map +0 -1
- package/dist/common/constants.js +0 -25
- package/dist/common/constants.js.map +0 -1
- package/dist/common/effective-modules-extensions.js +0 -13
- package/dist/common/effective-modules-extensions.js.map +0 -1
- package/dist/common/log.js +0 -4
- package/dist/common/log.js.map +0 -1
- package/dist/common/render-caller-tree.js +0 -20
- package/dist/common/render-caller-tree.js.map +0 -1
- package/dist/entrypoints/ozy-signing-agent.js +0 -48
- package/dist/entrypoints/ozy-signing-agent.js.map +0 -1
- package/dist/entrypoints/ozy-ssh-keygen.js +0 -9
- package/dist/entrypoints/ozy-ssh-keygen.js.map +0 -1
- package/dist/entrypoints/ozy-virtual-security-key.js +0 -18
- package/dist/entrypoints/ozy-virtual-security-key.js.map +0 -1
- package/dist/entrypoints/ozy.js +0 -3
- package/dist/entrypoints/ozy.js.map +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/internal/thing.js +0 -4
- package/dist/internal/thing.js.map +0 -1
- package/dist/modules/cli/agent-client/impl.js +0 -109
- package/dist/modules/cli/agent-client/impl.js.map +0 -1
- package/dist/modules/cli/agent-client/interface.js +0 -11
- package/dist/modules/cli/agent-client/interface.js.map +0 -1
- package/dist/modules/cli/git/impl.js +0 -124
- package/dist/modules/cli/git/impl.js.map +0 -1
- package/dist/modules/cli/git/interface.js +0 -3
- package/dist/modules/cli/git/interface.js.map +0 -1
- package/dist/modules/cli/git/submodule/fix.js +0 -257
- package/dist/modules/cli/git/submodule/fix.js.map +0 -1
- package/dist/modules/cli/git/submodule/git-state.js +0 -154
- package/dist/modules/cli/git/submodule/git-state.js.map +0 -1
- package/dist/modules/cli/git/submodule/gitmodules.js +0 -113
- package/dist/modules/cli/git/submodule/gitmodules.js.map +0 -1
- package/dist/modules/cli/git/submodule/printer.js +0 -232
- package/dist/modules/cli/git/submodule/printer.js.map +0 -1
- package/dist/modules/cli/git/submodule/resolve-git-dir.js +0 -16
- package/dist/modules/cli/git/submodule/resolve-git-dir.js.map +0 -1
- package/dist/modules/cli/github/impl.js +0 -137
- package/dist/modules/cli/github/impl.js.map +0 -1
- package/dist/modules/cli/github/interface.js +0 -2
- package/dist/modules/cli/github/interface.js.map +0 -1
- package/dist/modules/cli/index.js +0 -9
- package/dist/modules/cli/index.js.map +0 -1
- package/dist/modules/common/crypto/impl.js +0 -133
- package/dist/modules/common/crypto/impl.js.map +0 -1
- package/dist/modules/common/crypto/interface.js +0 -2
- package/dist/modules/common/crypto/interface.js.map +0 -1
- package/dist/modules/common/index.js +0 -10
- package/dist/modules/common/index.js.map +0 -1
- package/dist/modules/common/kep-map-store/impl.js +0 -42
- package/dist/modules/common/kep-map-store/impl.js.map +0 -1
- package/dist/modules/common/kep-map-store/interface.js +0 -2
- package/dist/modules/common/kep-map-store/interface.js.map +0 -1
- package/dist/modules/common/os-platform/caller-info.js +0 -132
- package/dist/modules/common/os-platform/caller-info.js.map +0 -1
- package/dist/modules/common/os-platform/impl.js +0 -95
- package/dist/modules/common/os-platform/impl.js.map +0 -1
- package/dist/modules/common/os-platform/interface.js +0 -2
- package/dist/modules/common/os-platform/interface.js.map +0 -1
- package/dist/modules/common/os-platform/virtual-hid/index.js +0 -12
- package/dist/modules/common/os-platform/virtual-hid/index.js.map +0 -1
- package/dist/modules/common/os-platform/virtual-hid/linux.js +0 -5
- package/dist/modules/common/os-platform/virtual-hid/linux.js.map +0 -1
- package/dist/modules/common/os-platform/virtual-hid/mac.js +0 -119
- package/dist/modules/common/os-platform/virtual-hid/mac.js.map +0 -1
- package/dist/modules/common/os-platform/virtual-hid/windows.js +0 -5
- package/dist/modules/common/os-platform/virtual-hid/windows.js.map +0 -1
- package/dist/modules/common/ssh-config/impl.js +0 -116
- package/dist/modules/common/ssh-config/impl.js.map +0 -1
- package/dist/modules/common/ssh-config/interface.js +0 -10
- package/dist/modules/common/ssh-config/interface.js.map +0 -1
- package/dist/modules/ssh-agent/index.js +0 -8
- package/dist/modules/ssh-agent/index.js.map +0 -1
- package/dist/modules/ssh-agent/session/impl.js +0 -265
- package/dist/modules/ssh-agent/session/impl.js.map +0 -1
- package/dist/modules/ssh-agent/session/interface-rpc.js +0 -20
- package/dist/modules/ssh-agent/session/interface-rpc.js.map +0 -1
- package/dist/modules/ssh-agent/session/interface.js +0 -32
- package/dist/modules/ssh-agent/session/interface.js.map +0 -1
- package/dist/modules/ssh-agent/session/passkey-prf-page.js +0 -204
- package/dist/modules/ssh-agent/session/passkey-prf-page.js.map +0 -1
- package/dist/modules/ssh-agent/session/prf-flow.js +0 -103
- package/dist/modules/ssh-agent/session/prf-flow.js.map +0 -1
- package/dist/modules/ssh-agent/ssh-agent/impl.js +0 -117
- package/dist/modules/ssh-agent/ssh-agent/impl.js.map +0 -1
- package/dist/modules/ssh-agent/ssh-agent/interface.js +0 -2
- package/dist/modules/ssh-agent/ssh-agent/interface.js.map +0 -1
- package/dist/scripts/build.js +0 -410
- package/dist/scripts/build.js.map +0 -1
- package/dist/scripts/check-npm-version.js +0 -8
- package/dist/scripts/check-npm-version.js.map +0 -1
- package/dist/scripts/kill-existing-agent.js +0 -21
- package/dist/scripts/kill-existing-agent.js.map +0 -1
- package/dist/scripts/publish.js +0 -46
- package/dist/scripts/publish.js.map +0 -1
- package/src/commands/git/hosts.ts +0 -20
- package/src/commands/git/index.ts +0 -9
- package/src/commands/git/setup.ts +0 -182
- package/src/commands/index.ts +0 -15
- package/src/commands/npm/index.ts +0 -8
- package/src/commands/npm/setup/git-remote.ts +0 -78
- package/src/commands/npm/setup/index.ts +0 -189
- package/src/commands/npm/setup/npm-auth.ts +0 -58
- package/src/commands/npm/setup/package-json-validate.ts +0 -68
- package/src/commands/npm/setup/package-registry.ts +0 -24
- package/src/commands/npm/setup/publish-workflow.yml +0 -35
- package/src/commands/npm/setup/setup.test.ts +0 -117
- package/src/commands/npm/setup/trusted-publishing.ts +0 -106
- package/src/commands/npm/setup/workflow.ts +0 -20
- package/src/commands/ssh/get-sk-credential.ts +0 -110
- package/src/commands/ssh/index.ts +0 -8
- package/src/commands/upgrade.ts +0 -220
- package/src/common/command.ts +0 -16
- package/src/common/constants.ts +0 -26
- package/src/common/effective-modules-extensions.ts +0 -24
- package/src/common/log.ts +0 -3
- package/src/common/render-caller-tree.ts +0 -22
- package/src/entrypoints/ozy-signing-agent.ts +0 -48
- package/src/entrypoints/ozy-ssh-keygen.ts +0 -10
- package/src/entrypoints/ozy-virtual-security-key.ts +0 -21
- package/src/entrypoints/ozy.ts +0 -2
- package/src/index.ts +0 -1
- package/src/internal/thing.ts +0 -3
- package/src/modules/cli/agent-client/impl.ts +0 -152
- package/src/modules/cli/agent-client/interface.ts +0 -17
- package/src/modules/cli/git/impl.ts +0 -133
- package/src/modules/cli/git/interface.ts +0 -23
- package/src/modules/cli/git/submodule/fix.ts +0 -298
- package/src/modules/cli/git/submodule/git-state.ts +0 -217
- package/src/modules/cli/git/submodule/gitmodules.ts +0 -126
- package/src/modules/cli/git/submodule/printer.ts +0 -256
- package/src/modules/cli/git/submodule/resolve-git-dir.ts +0 -14
- package/src/modules/cli/github/impl.ts +0 -169
- package/src/modules/cli/github/interface.ts +0 -29
- package/src/modules/cli/index.ts +0 -16
- package/src/modules/common/crypto/impl.ts +0 -173
- package/src/modules/common/crypto/interface.ts +0 -20
- package/src/modules/common/index.ts +0 -19
- package/src/modules/common/kep-map-store/impl.ts +0 -47
- package/src/modules/common/kep-map-store/interface.ts +0 -9
- package/src/modules/common/os-platform/caller-info.ts +0 -152
- package/src/modules/common/os-platform/impl.ts +0 -91
- package/src/modules/common/os-platform/interface.ts +0 -16
- package/src/modules/common/os-platform/virtual-hid/index.ts +0 -12
- package/src/modules/common/os-platform/virtual-hid/linux.ts +0 -7
- package/src/modules/common/os-platform/virtual-hid/mac.ts +0 -150
- package/src/modules/common/os-platform/virtual-hid/windows.ts +0 -7
- package/src/modules/common/ssh-config/impl.ts +0 -130
- package/src/modules/common/ssh-config/interface.ts +0 -33
- package/src/modules/ssh-agent/index.ts +0 -13
- package/src/modules/ssh-agent/session/agent-notes.md +0 -210
- package/src/modules/ssh-agent/session/design.md +0 -2
- package/src/modules/ssh-agent/session/html-refactor.md +0 -23
- package/src/modules/ssh-agent/session/impl.ts +0 -328
- package/src/modules/ssh-agent/session/interface-rpc.ts +0 -24
- package/src/modules/ssh-agent/session/interface.ts +0 -62
- package/src/modules/ssh-agent/session/passkey-prf-page.ts +0 -224
- package/src/modules/ssh-agent/session/prf-flow.ts +0 -152
- package/src/modules/ssh-agent/ssh-agent/impl.ts +0 -136
- package/src/modules/ssh-agent/ssh-agent/interface.ts +0 -9
- package/src/scripts/build.ts +0 -504
- package/src/scripts/check-npm-version.ts +0 -7
- package/src/scripts/command-launcher.js.ejs +0 -168
- package/src/scripts/kill-existing-agent.ts +0 -22
- package/src/scripts/publish.ts +0 -47
- package/src/scripts/windows-bin-shims.md +0 -1104
package/src/scripts/build.ts
DELETED
|
@@ -1,504 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
access,
|
|
3
|
-
chmod,
|
|
4
|
-
cp,
|
|
5
|
-
mkdir,
|
|
6
|
-
readdir,
|
|
7
|
-
readFile,
|
|
8
|
-
rename,
|
|
9
|
-
rm,
|
|
10
|
-
writeFile,
|
|
11
|
-
} from "node:fs/promises";
|
|
12
|
-
import { basename, dirname, relative, resolve } from "node:path";
|
|
13
|
-
import { Schema } from "effect";
|
|
14
|
-
import {
|
|
15
|
-
applyEdits,
|
|
16
|
-
modify,
|
|
17
|
-
parse as parseJsonc,
|
|
18
|
-
printParseErrorCode,
|
|
19
|
-
type FormattingOptions,
|
|
20
|
-
type ParseError,
|
|
21
|
-
} from "jsonc-parser";
|
|
22
|
-
import ejs from "ejs";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Jive library builder.
|
|
26
|
-
*
|
|
27
|
-
* Source package:
|
|
28
|
-
* src/index.ts Optional package TypeScript ESM entrypoint.
|
|
29
|
-
* src/entrypoints/* Command entrypoints included in the generated multi-call binary.
|
|
30
|
-
* src/agents/* Agent entrypoints, if present, included in the same multi-call binary.
|
|
31
|
-
*
|
|
32
|
-
* Generated base package:
|
|
33
|
-
* package.json Stripped package manifest plus generated command launchers.
|
|
34
|
-
* src/ Source tree for package consumers.
|
|
35
|
-
* dist/ TypeScript-emitted library files, when a source entrypoint exists.
|
|
36
|
-
* bin/<command> Generated JS launcher that self-repairs to the platform multi-call executable.
|
|
37
|
-
*
|
|
38
|
-
* Generated platform packages:
|
|
39
|
-
* package.json Same package name with platform-specific prerelease version and os/cpu.
|
|
40
|
-
* multi-call-binary Native Bun-compiled multi-call executable (`multi-call-binary.exe` on Windows).
|
|
41
|
-
*
|
|
42
|
-
* The dist folder contains only packed .tgz files. The file name is the npm dist-tag to publish:
|
|
43
|
-
* latest.tgz for the base package and one <platform>.tgz per platform package.
|
|
44
|
-
*
|
|
45
|
-
* Files in the following directories will be non importable from dependents
|
|
46
|
-
* src/entrypoints/*
|
|
47
|
-
* src/agents/*
|
|
48
|
-
* src/internal
|
|
49
|
-
* So for example `import * as a from "my-package/internal"` will fail to compile
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
const COMMAND_SOURCE_DIRS = ["src/entrypoints", "src/agents"] as const;
|
|
53
|
-
const PRIVATE_SOURCE_DIRS = [...COMMAND_SOURCE_DIRS, "src/internal"] as const;
|
|
54
|
-
const SOURCE_ENTRYPOINT = "src/index.ts";
|
|
55
|
-
const SOURCE_SUFFIX = ".ts";
|
|
56
|
-
const OUTDIR = "dist";
|
|
57
|
-
const WORKDIR = "build-temp";
|
|
58
|
-
const MULTI_CALL_BINARY = "multi-call-binary";
|
|
59
|
-
const WINDOWS_EXECUTABLE_SUFFIX = ".exe";
|
|
60
|
-
const BIN_DIR = "bin";
|
|
61
|
-
const COMMAND_LAUNCHER_TEMPLATE = "src/scripts/command-launcher.js.ejs";
|
|
62
|
-
const TSCONFIG_INCLUDE = ["src/**/*.ts"];
|
|
63
|
-
const TSCONFIG_EXCLUDE = [OUTDIR, "node_modules"];
|
|
64
|
-
const JSONC_FORMATTING_OPTIONS = {
|
|
65
|
-
insertSpaces: true,
|
|
66
|
-
tabSize: 2,
|
|
67
|
-
eol: "\n",
|
|
68
|
-
insertFinalNewline: true,
|
|
69
|
-
} as const satisfies FormattingOptions;
|
|
70
|
-
|
|
71
|
-
type Platform = {
|
|
72
|
-
readonly id: string;
|
|
73
|
-
readonly target: Bun.Build.CompileTarget;
|
|
74
|
-
readonly os: string;
|
|
75
|
-
readonly cpu: string;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const PLATFORMS = [
|
|
79
|
-
{ id: "darwin-arm64", target: "bun-darwin-arm64", os: "darwin", cpu: "arm64" },
|
|
80
|
-
{ id: "darwin-x64", target: "bun-darwin-x64", os: "darwin", cpu: "x64" },
|
|
81
|
-
{ id: "linux-arm64", target: "bun-linux-arm64", os: "linux", cpu: "arm64" },
|
|
82
|
-
{ id: "linux-x64", target: "bun-linux-x64", os: "linux", cpu: "x64" },
|
|
83
|
-
{ id: "windows-x64", target: "bun-windows-x64", os: "win32", cpu: "x64" },
|
|
84
|
-
] as const satisfies readonly Platform[];
|
|
85
|
-
|
|
86
|
-
const PackageJson = Schema.Struct({
|
|
87
|
-
name: Schema.String,
|
|
88
|
-
version: Schema.String,
|
|
89
|
-
description: Schema.optional(Schema.String),
|
|
90
|
-
type: Schema.optional(Schema.Literal("module")),
|
|
91
|
-
license: Schema.optional(Schema.String),
|
|
92
|
-
author: Schema.optional(Schema.Unknown),
|
|
93
|
-
contributors: Schema.optional(Schema.Unknown),
|
|
94
|
-
keywords: Schema.optional(Schema.Unknown),
|
|
95
|
-
homepage: Schema.optional(Schema.String),
|
|
96
|
-
bugs: Schema.optional(Schema.Unknown),
|
|
97
|
-
funding: Schema.optional(Schema.Unknown),
|
|
98
|
-
repository: Schema.optional(Schema.Unknown),
|
|
99
|
-
publishConfig: Schema.optional(Schema.Unknown),
|
|
100
|
-
dependencies: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
101
|
-
});
|
|
102
|
-
type PackageJson = Schema.Schema.Type<typeof PackageJson>;
|
|
103
|
-
|
|
104
|
-
type CommandSource = {
|
|
105
|
-
readonly command: string;
|
|
106
|
-
readonly sourcePath: string;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
class TscFailed extends Error {
|
|
110
|
-
constructor(readonly exitCode: number) {
|
|
111
|
-
super(`tsc failed with exit code ${exitCode}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const rootDir = process.cwd();
|
|
116
|
-
const outDir = resolve(rootDir, OUTDIR);
|
|
117
|
-
const workDir = resolve(outDir, WORKDIR);
|
|
118
|
-
const multiCallEntrypointPath = resolve(workDir, "multi-call.ts");
|
|
119
|
-
const packageJson = await readPackageJson();
|
|
120
|
-
const commandSources = await collectCommandSources();
|
|
121
|
-
const sourceEntrypoint = resolve(rootDir, SOURCE_ENTRYPOINT);
|
|
122
|
-
const hasSourceEntrypoint = await pathExists(sourceEntrypoint);
|
|
123
|
-
const hasCommandSources = commandSources.length > 0;
|
|
124
|
-
|
|
125
|
-
await rm(outDir, { recursive: true, force: true });
|
|
126
|
-
await mkdir(outDir, { recursive: true });
|
|
127
|
-
await mkdir(workDir, { recursive: true });
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
if (hasCommandSources) {
|
|
131
|
-
await writeFile(multiCallEntrypointPath, generateMultiCallEntrypoint(multiCallEntrypointPath));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
await buildBasePackage();
|
|
135
|
-
|
|
136
|
-
if (hasCommandSources) {
|
|
137
|
-
await Promise.all(PLATFORMS.map(buildPlatformPackage));
|
|
138
|
-
}
|
|
139
|
-
} catch (error) {
|
|
140
|
-
if (error instanceof TscFailed) {
|
|
141
|
-
process.exitCode = error.exitCode;
|
|
142
|
-
} else {
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
} finally {
|
|
146
|
-
await rm(workDir, { recursive: true, force: true });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async function readPackageJson(): Promise<PackageJson> {
|
|
150
|
-
const parsed = JSON.parse(await readFile(resolve(rootDir, "package.json"), "utf-8"));
|
|
151
|
-
return Schema.decodeUnknownSync(PackageJson)(parsed);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
async function collectCommandSources(): Promise<readonly CommandSource[]> {
|
|
155
|
-
const commands = new Map<string, CommandSource>();
|
|
156
|
-
|
|
157
|
-
for (const sourceDir of COMMAND_SOURCE_DIRS) {
|
|
158
|
-
const absoluteSourceDir = resolve(rootDir, sourceDir);
|
|
159
|
-
if (!(await pathExists(absoluteSourceDir))) continue;
|
|
160
|
-
|
|
161
|
-
for (const child of (await readdir(absoluteSourceDir)).sort()) {
|
|
162
|
-
if (!child.endsWith(SOURCE_SUFFIX)) continue;
|
|
163
|
-
|
|
164
|
-
const command = basename(child, SOURCE_SUFFIX);
|
|
165
|
-
const sourcePath = resolve(absoluteSourceDir, child);
|
|
166
|
-
const existing = commands.get(command);
|
|
167
|
-
if (existing) {
|
|
168
|
-
throw new Error(`Duplicate command "${command}" in ${existing.sourcePath} and ${sourcePath}`);
|
|
169
|
-
}
|
|
170
|
-
commands.set(command, { command, sourcePath });
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return [...commands.values()].sort((a, b) => a.command.localeCompare(b.command));
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function buildBasePackage(): Promise<void> {
|
|
178
|
-
const packageDir = resolve(workDir, "base-package");
|
|
179
|
-
await mkdir(packageDir, { recursive: true });
|
|
180
|
-
|
|
181
|
-
if (hasSourceEntrypoint) {
|
|
182
|
-
await transpileLibrarySource(packageDir);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
await cp(resolve(rootDir, "src"), resolve(packageDir, "src"), { recursive: true });
|
|
186
|
-
if (hasCommandSources) {
|
|
187
|
-
await writeCommandLaunchers(packageDir);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
await writePackageJson(packageDir, generateBasePackageJson());
|
|
191
|
-
await packPackage(packageDir, "latest");
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async function buildPlatformPackage(platform: Platform): Promise<void> {
|
|
195
|
-
const packageDir = resolve(workDir, platform.id);
|
|
196
|
-
await mkdir(packageDir, { recursive: true });
|
|
197
|
-
|
|
198
|
-
const binaryPath = resolve(packageDir, platformBinaryFile(platform));
|
|
199
|
-
const buildResult = await Bun.build({
|
|
200
|
-
entrypoints: [multiCallEntrypointPath],
|
|
201
|
-
compile: {
|
|
202
|
-
outfile: binaryPath,
|
|
203
|
-
target: platform.target,
|
|
204
|
-
},
|
|
205
|
-
sourcemap: "inline",
|
|
206
|
-
});
|
|
207
|
-
assertBuildSucceeded(buildResult, `compile ${platform.id} multi-call binary`);
|
|
208
|
-
|
|
209
|
-
await chmod(binaryPath, 0o755);
|
|
210
|
-
|
|
211
|
-
await writePackageJson(packageDir, generatePlatformPackageJson(platform));
|
|
212
|
-
await packPackage(packageDir, platform.id);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async function writeCommandLaunchers(packageDir: string): Promise<void> {
|
|
216
|
-
const binDir = resolve(packageDir, BIN_DIR);
|
|
217
|
-
await mkdir(binDir, { recursive: true });
|
|
218
|
-
|
|
219
|
-
const launcher = await renderCommandLauncher();
|
|
220
|
-
await Promise.all(
|
|
221
|
-
commandSources.map(({ command }) => writeFile(resolve(binDir, command), launcher, { mode: 0o755 }))
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function assertBuildSucceeded(result: Bun.BuildOutput, label: string): void {
|
|
226
|
-
if (result.success) return;
|
|
227
|
-
|
|
228
|
-
for (const log of result.logs) {
|
|
229
|
-
console.error(log);
|
|
230
|
-
}
|
|
231
|
-
throw new Error(`Failed to ${label}`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async function writePackageJson(packageDir: string, value: Record<string, unknown>): Promise<void> {
|
|
235
|
-
await writeFile(resolve(packageDir, "package.json"), `${JSON.stringify(value, null, 2)}\n`);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
async function transpileLibrarySource(packageDir: string): Promise<void> {
|
|
239
|
-
const rootTsconfigPath = resolve(rootDir, "tsconfig.json");
|
|
240
|
-
await ensureTsconfigSourceBoundary(rootTsconfigPath);
|
|
241
|
-
|
|
242
|
-
const tscPath = resolve(rootDir, "node_modules", ".bin", process.platform === "win32" ? "tsc.cmd" : "tsc");
|
|
243
|
-
|
|
244
|
-
// TODO: tool should just come bundled with typescript.
|
|
245
|
-
if (!(await pathExists(tscPath))) {
|
|
246
|
-
throw new Error("TypeScript is required to emit library source. Install typescript as a devDependency.");
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const exitCode = await Bun.spawn(
|
|
250
|
-
[
|
|
251
|
-
tscPath,
|
|
252
|
-
"--project",
|
|
253
|
-
rootTsconfigPath,
|
|
254
|
-
"--rootDir",
|
|
255
|
-
resolve(rootDir, "src"),
|
|
256
|
-
"--outDir",
|
|
257
|
-
resolve(packageDir, "dist"),
|
|
258
|
-
"--pretty",
|
|
259
|
-
"true",
|
|
260
|
-
"--noEmit",
|
|
261
|
-
"false",
|
|
262
|
-
"--declaration",
|
|
263
|
-
"false",
|
|
264
|
-
"--declarationMap",
|
|
265
|
-
"false",
|
|
266
|
-
"--sourceMap",
|
|
267
|
-
"--rewriteRelativeImportExtensions",
|
|
268
|
-
],
|
|
269
|
-
{
|
|
270
|
-
stdin: "inherit",
|
|
271
|
-
stdout: "inherit",
|
|
272
|
-
stderr: "inherit",
|
|
273
|
-
}
|
|
274
|
-
).exited;
|
|
275
|
-
if (exitCode !== 0) {
|
|
276
|
-
throw new TscFailed(exitCode);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async function ensureTsconfigSourceBoundary(tsconfigPath: string): Promise<void> {
|
|
281
|
-
const originalText = await readFile(tsconfigPath, "utf-8");
|
|
282
|
-
assertValidJsonc(tsconfigPath, originalText);
|
|
283
|
-
|
|
284
|
-
const withInclude = applyEdits(
|
|
285
|
-
originalText,
|
|
286
|
-
modify(originalText, ["include"], TSCONFIG_INCLUDE, {
|
|
287
|
-
formattingOptions: JSONC_FORMATTING_OPTIONS,
|
|
288
|
-
getInsertionIndex: (properties) => insertAfter(properties, "compilerOptions"),
|
|
289
|
-
})
|
|
290
|
-
);
|
|
291
|
-
const withExclude = applyEdits(
|
|
292
|
-
withInclude,
|
|
293
|
-
modify(withInclude, ["exclude"], TSCONFIG_EXCLUDE, {
|
|
294
|
-
formattingOptions: JSONC_FORMATTING_OPTIONS,
|
|
295
|
-
getInsertionIndex: (properties) => insertAfter(properties, "include"),
|
|
296
|
-
})
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
assertValidJsonc(tsconfigPath, withExclude);
|
|
300
|
-
if (withExclude !== originalText) {
|
|
301
|
-
await writeFile(tsconfigPath, withExclude);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function assertValidJsonc(filePath: string, text: string): void {
|
|
306
|
-
const errors: ParseError[] = [];
|
|
307
|
-
parseJsonc(text, errors, { allowTrailingComma: true });
|
|
308
|
-
if (errors.length === 0) return;
|
|
309
|
-
|
|
310
|
-
const details = errors
|
|
311
|
-
.map((error) => `${printParseErrorCode(error.error)} at offset ${error.offset}`)
|
|
312
|
-
.join(", ");
|
|
313
|
-
throw new Error(`${filePath} is invalid JSONC: ${details}`);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function insertAfter(properties: readonly string[], property: string): number {
|
|
317
|
-
const index = properties.indexOf(property);
|
|
318
|
-
return index === -1 ? properties.length : index + 1;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function generateBasePackageJson(): Record<string, unknown> {
|
|
322
|
-
const generated: Record<string, unknown> = {};
|
|
323
|
-
for (const key of [
|
|
324
|
-
"name",
|
|
325
|
-
"version",
|
|
326
|
-
"description",
|
|
327
|
-
"type",
|
|
328
|
-
"license",
|
|
329
|
-
"author",
|
|
330
|
-
"contributors",
|
|
331
|
-
"keywords",
|
|
332
|
-
"homepage",
|
|
333
|
-
"bugs",
|
|
334
|
-
"funding",
|
|
335
|
-
"repository",
|
|
336
|
-
"publishConfig",
|
|
337
|
-
] as const) {
|
|
338
|
-
const value = packageJson[key];
|
|
339
|
-
if (value !== undefined) generated[key] = value;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
generated["type"] = packageJson["type"] ?? "module";
|
|
343
|
-
if (hasSourceEntrypoint) {
|
|
344
|
-
generated["main"] = "./dist/index.js";
|
|
345
|
-
generated["module"] = "./dist/index.js";
|
|
346
|
-
generated["types"] = "./src/index.ts";
|
|
347
|
-
generated["exports"] = {
|
|
348
|
-
".": {
|
|
349
|
-
types: "./src/index.ts",
|
|
350
|
-
import: "./dist/index.js",
|
|
351
|
-
},
|
|
352
|
-
...Object.fromEntries(
|
|
353
|
-
PRIVATE_SOURCE_DIRS.flatMap((sourceDir) => {
|
|
354
|
-
const subpath = sourceDir.replace(/^src\//, "");
|
|
355
|
-
return [
|
|
356
|
-
[`./${subpath}`, null],
|
|
357
|
-
[`./${subpath}/*`, null],
|
|
358
|
-
];
|
|
359
|
-
})
|
|
360
|
-
),
|
|
361
|
-
"./*": {
|
|
362
|
-
types: "./src/*.ts",
|
|
363
|
-
import: "./dist/*.js",
|
|
364
|
-
},
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const files = hasSourceEntrypoint ? ["dist", "src"] : [];
|
|
368
|
-
if (hasCommandSources) files.push(BIN_DIR);
|
|
369
|
-
if (files.length > 0) generated["files"] = files;
|
|
370
|
-
if (hasCommandSources) {
|
|
371
|
-
generated["bin"] = generateBaseBinEntries();
|
|
372
|
-
}
|
|
373
|
-
if (packageJson["dependencies"]) generated["dependencies"] = packageJson["dependencies"];
|
|
374
|
-
if (hasCommandSources) {
|
|
375
|
-
generated["optionalDependencies"] = Object.fromEntries(
|
|
376
|
-
PLATFORMS.map((platform) => [
|
|
377
|
-
platformAliasName(platform),
|
|
378
|
-
`npm:${packageJson.name}@${platformVersion(platform)}`,
|
|
379
|
-
])
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return generated;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
function generatePlatformPackageJson(platform: Platform): Record<string, unknown> {
|
|
387
|
-
const generated: Record<string, unknown> = {
|
|
388
|
-
name: packageJson.name,
|
|
389
|
-
version: platformVersion(platform),
|
|
390
|
-
type: packageJson.type ?? "module",
|
|
391
|
-
os: [platform.os],
|
|
392
|
-
cpu: [platform.cpu],
|
|
393
|
-
files: [platformBinaryFile(platform)],
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
for (const key of ["description", "license", "repository", "publishConfig"] as const) {
|
|
397
|
-
const value = packageJson[key];
|
|
398
|
-
if (value !== undefined) generated[key] = value;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
return generated;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
function platformVersion(platform: Platform): string {
|
|
405
|
-
return `${packageJson.version}-${platform.id}.0`;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
function platformAliasName(platform: Platform): string {
|
|
409
|
-
return `${packageJson.name}-${platform.id}`;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
function platformBinaryFile(platform: Platform): string {
|
|
413
|
-
return platform.os === "win32" ? `${MULTI_CALL_BINARY}${WINDOWS_EXECUTABLE_SUFFIX}` : MULTI_CALL_BINARY;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
function generateBaseBinEntries(): Record<string, string> {
|
|
417
|
-
return Object.fromEntries(commandSources.map(({ command }) => [command, `./${BIN_DIR}/${command}`]));
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
async function packPackage(packageDir: string, tag: string): Promise<void> {
|
|
421
|
-
const npmCacheDir = resolve(workDir, "npm-cache");
|
|
422
|
-
const output = await Bun.$`npm pack ${packageDir} --pack-destination ${outDir} --ignore-scripts --cache ${npmCacheDir} --loglevel error`.text();
|
|
423
|
-
const generatedFile = output.trim().split("\n").at(-1);
|
|
424
|
-
if (!generatedFile) throw new Error(`npm pack did not report an output file for ${packageDir}`);
|
|
425
|
-
|
|
426
|
-
const sourcePath = resolve(outDir, generatedFile);
|
|
427
|
-
const taggedPath = resolve(outDir, `${tag}.tgz`);
|
|
428
|
-
await rm(taggedPath, { force: true });
|
|
429
|
-
await rename(sourcePath, taggedPath);
|
|
430
|
-
console.log(`${packageDir} -> ${relative(rootDir, taggedPath)}`);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
function generateMultiCallEntrypoint(dispatcherPath: string): string {
|
|
434
|
-
const dispatcherDir = dirname(dispatcherPath);
|
|
435
|
-
const loaders = commandSources
|
|
436
|
-
.map(({ command, sourcePath }) => {
|
|
437
|
-
const importPath = toImportPath(relative(dispatcherDir, sourcePath));
|
|
438
|
-
return ` ${JSON.stringify(command)}: () => import(${JSON.stringify(importPath)}),`;
|
|
439
|
-
})
|
|
440
|
-
.join("\n");
|
|
441
|
-
|
|
442
|
-
return `import { basename } from "node:path";
|
|
443
|
-
// console.log("multi-call argv", JSON.stringify({ argv0: process.argv0, argv: process.argv }));
|
|
444
|
-
const commandLoaders: Record<string, () => Promise<unknown>> = {
|
|
445
|
-
${loaders}
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
const invokedPath = process.argv0 || process.argv[1] || "";
|
|
449
|
-
const command = basename(invokedPath).replace(/\\.(?:exe|cmd|ps1)$/i, "");
|
|
450
|
-
const loadCommand = commandLoaders[command];
|
|
451
|
-
|
|
452
|
-
if (!loadCommand) {
|
|
453
|
-
console.error(\`Unknown ${packageJson.name} command "\${command}". Expected one of: \${Object.keys(commandLoaders).sort().join(", ")}\`);
|
|
454
|
-
process.exit(1);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
await loadCommand();
|
|
458
|
-
`;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
async function renderCommandLauncher(): Promise<string> {
|
|
462
|
-
const platformMap = Object.fromEntries(
|
|
463
|
-
PLATFORMS.map((platform) => [`${platform.os}-${platform.cpu}`, platform.id])
|
|
464
|
-
);
|
|
465
|
-
const platformPackages = Object.fromEntries(
|
|
466
|
-
PLATFORMS.map((platform) => [platform.id, platformAliasName(platform)])
|
|
467
|
-
);
|
|
468
|
-
const platformBinaries = Object.fromEntries(
|
|
469
|
-
PLATFORMS.map((platform) => [platform.id, platformBinaryFile(platform)])
|
|
470
|
-
);
|
|
471
|
-
const commandNames = commandSources.map(({ command }) => command);
|
|
472
|
-
const template = await readFile(resolve(rootDir, COMMAND_LAUNCHER_TEMPLATE), "utf-8");
|
|
473
|
-
return ejs.render(
|
|
474
|
-
template,
|
|
475
|
-
{
|
|
476
|
-
commandNames,
|
|
477
|
-
json: (value: unknown) => JSON.stringify(value, null, 2),
|
|
478
|
-
platformBinaries,
|
|
479
|
-
platformMap,
|
|
480
|
-
platformPackages,
|
|
481
|
-
windowsExecutableSuffix: WINDOWS_EXECUTABLE_SUFFIX,
|
|
482
|
-
},
|
|
483
|
-
{ async: false }
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function toImportPath(path: string): string {
|
|
488
|
-
const normalized = toPosixPath(path);
|
|
489
|
-
if (normalized.startsWith(".") || normalized.startsWith("/")) return normalized;
|
|
490
|
-
return `./${normalized}`;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function toPosixPath(path: string): string {
|
|
494
|
-
return path.split("\\").join("/");
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
async function pathExists(path: string): Promise<boolean> {
|
|
498
|
-
try {
|
|
499
|
-
await access(path);
|
|
500
|
-
return true;
|
|
501
|
-
} catch {
|
|
502
|
-
return false;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { spawnSync } from "node:child_process";
|
|
4
|
-
import {
|
|
5
|
-
chmodSync,
|
|
6
|
-
copyFileSync,
|
|
7
|
-
existsSync,
|
|
8
|
-
linkSync,
|
|
9
|
-
mkdirSync,
|
|
10
|
-
readFileSync,
|
|
11
|
-
renameSync,
|
|
12
|
-
rmSync,
|
|
13
|
-
writeFileSync,
|
|
14
|
-
} from "node:fs";
|
|
15
|
-
import { basename, dirname, join } from "node:path";
|
|
16
|
-
import { fileURLToPath } from "node:url";
|
|
17
|
-
|
|
18
|
-
const PLATFORM_MAP = <%- json(platformMap) %>;
|
|
19
|
-
const PLATFORM_PACKAGES = <%- json(platformPackages) %>;
|
|
20
|
-
const PLATFORM_BINARIES = <%- json(platformBinaries) %>;
|
|
21
|
-
const COMMANDS = <%- json(commandNames) %>;
|
|
22
|
-
const WINDOWS_EXECUTABLE_SUFFIX = <%- json(windowsExecutableSuffix) %>;
|
|
23
|
-
const INSTALLED_JSON = "installed.json";
|
|
24
|
-
|
|
25
|
-
const require = createRequire(import.meta.url);
|
|
26
|
-
const launcherPath = fileURLToPath(import.meta.url);
|
|
27
|
-
const launcherDir = dirname(launcherPath);
|
|
28
|
-
const commandName = basename(launcherPath);
|
|
29
|
-
|
|
30
|
-
function fail(message) {
|
|
31
|
-
console.error(message);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function currentPlatformKey() {
|
|
36
|
-
const platformKey = PLATFORM_MAP[`${process.platform}-${process.arch}`];
|
|
37
|
-
if (!platformKey) {
|
|
38
|
-
fail(`Unsupported platform: ${process.platform}-${process.arch}`);
|
|
39
|
-
}
|
|
40
|
-
return platformKey;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function currentPlatformPackageName() {
|
|
44
|
-
const platformKey = currentPlatformKey();
|
|
45
|
-
const packageName = PLATFORM_PACKAGES[platformKey];
|
|
46
|
-
if (!packageName) {
|
|
47
|
-
fail(`No platform package is configured for ${platformKey}`);
|
|
48
|
-
}
|
|
49
|
-
return packageName;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* When a Jive library contains any number of CLIs (entrypoints or agents), then the base package
|
|
54
|
-
* will have an optional dependency for each possible architecture, with those platform-specific
|
|
55
|
-
* packages containing a platform build of the CLI.
|
|
56
|
-
* @returns the path to the platform binary and the exact version of the platform package.
|
|
57
|
-
*/
|
|
58
|
-
function currentPlatformPackage() {
|
|
59
|
-
const platformKey = currentPlatformKey();
|
|
60
|
-
const binaryFile = PLATFORM_BINARIES[platformKey];
|
|
61
|
-
if (!binaryFile) {
|
|
62
|
-
fail(`No platform binary is configured for ${platformKey}`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const packageName = currentPlatformPackageName();
|
|
66
|
-
try {
|
|
67
|
-
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
68
|
-
const packageDir = dirname(packageJsonPath);
|
|
69
|
-
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
70
|
-
return {
|
|
71
|
-
binaryPath: join(packageDir, binaryFile),
|
|
72
|
-
version: packageJson.version,
|
|
73
|
-
};
|
|
74
|
-
} catch (error) {
|
|
75
|
-
fail(`Could not resolve optional platform package ${packageName}. Reinstall dependencies for ${process.platform}-${process.arch}.`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function targetPathFor(command) {
|
|
80
|
-
const suffix = process.platform === "win32" ? WINDOWS_EXECUTABLE_SUFFIX : "";
|
|
81
|
-
return join(launcherDir, `${command}${suffix}`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function installedJsonPath() {
|
|
85
|
-
return join(launcherDir, INSTALLED_JSON);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function windowsTargetsAreCurrent(version) {
|
|
89
|
-
if (process.platform !== "win32") return false;
|
|
90
|
-
if (!COMMANDS.every((command) => existsSync(targetPathFor(command)))) return false;
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
const installed = JSON.parse(readFileSync(installedJsonPath(), "utf-8"));
|
|
94
|
-
return installed.version === version;
|
|
95
|
-
} catch {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function linkOrCopyFirstExecutable(sourcePath, targetPath) {
|
|
101
|
-
mkdirSync(dirname(targetPath), { recursive: true });
|
|
102
|
-
const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp${process.platform === "win32" ? WINDOWS_EXECUTABLE_SUFFIX : ""}`;
|
|
103
|
-
rmSync(tempPath, { force: true });
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
try {
|
|
107
|
-
linkSync(sourcePath, tempPath);
|
|
108
|
-
} catch {
|
|
109
|
-
copyFileSync(sourcePath, tempPath);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
chmodSync(tempPath, 0o755);
|
|
113
|
-
rmSync(targetPath, { force: true });
|
|
114
|
-
renameSync(tempPath, targetPath);
|
|
115
|
-
} finally {
|
|
116
|
-
rmSync(tempPath, { force: true });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function hardLinkCommandTarget(sourcePath, targetPath) {
|
|
121
|
-
if (sourcePath === targetPath) return;
|
|
122
|
-
|
|
123
|
-
const tempPath = `${targetPath}.${process.pid}.${Date.now()}.tmp${process.platform === "win32" ? WINDOWS_EXECUTABLE_SUFFIX : ""}`;
|
|
124
|
-
rmSync(tempPath, { force: true });
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
linkSync(sourcePath, tempPath);
|
|
128
|
-
chmodSync(tempPath, 0o755);
|
|
129
|
-
rmSync(targetPath, { force: true });
|
|
130
|
-
renameSync(tempPath, targetPath);
|
|
131
|
-
} finally {
|
|
132
|
-
rmSync(tempPath, { force: true });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function repairCommandTargets() {
|
|
137
|
-
const platformPackage = currentPlatformPackage();
|
|
138
|
-
|
|
139
|
-
if (windowsTargetsAreCurrent(platformPackage.version)) {
|
|
140
|
-
return targetPathFor(commandName);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const firstTargetPath = targetPathFor(COMMANDS[0]);
|
|
144
|
-
linkOrCopyFirstExecutable(platformPackage.binaryPath, firstTargetPath);
|
|
145
|
-
|
|
146
|
-
for (const command of COMMANDS.slice(1)) {
|
|
147
|
-
hardLinkCommandTarget(firstTargetPath, targetPathFor(command));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (process.platform === "win32") {
|
|
151
|
-
writeFileSync(installedJsonPath(), `${JSON.stringify({ version: platformPackage.version }, null, 2)}\n`);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return targetPathFor(commandName);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function runExecutable(executablePath) {
|
|
158
|
-
const result = spawnSync(executablePath, process.argv.slice(2), { stdio: "inherit" });
|
|
159
|
-
|
|
160
|
-
if (result.error) {
|
|
161
|
-
fail(result.error.message);
|
|
162
|
-
}
|
|
163
|
-
if (result.status !== 0) {
|
|
164
|
-
process.exit(result.status ?? 1);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
runExecutable(repairCommandTargets());
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
|
|
4
|
-
const pidFile = path.resolve(import.meta.dir, "../../dist/ozy-signing-agent.pid");
|
|
5
|
-
|
|
6
|
-
function isProcessRunning(pid: number): boolean {
|
|
7
|
-
try {
|
|
8
|
-
// signal 0 sends nothing; it only checks whether the PID exists
|
|
9
|
-
process.kill(pid, 0);
|
|
10
|
-
return true;
|
|
11
|
-
} catch {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (existsSync(pidFile)) {
|
|
17
|
-
const pid = parseInt(readFileSync(pidFile, "utf-8"));
|
|
18
|
-
if (isProcessRunning(pid)) {
|
|
19
|
-
console.log(`Killing agent on PID ${pid}`);
|
|
20
|
-
process.kill(pid, "SIGTERM");
|
|
21
|
-
}
|
|
22
|
-
}
|