@hagicode/hagiscript 0.1.8 → 0.1.9

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
@@ -45,7 +45,7 @@ The split is intentional:
45
45
  The packaged manifest currently manages:
46
46
 
47
47
  - `node` - managed Node.js runtime
48
- - `dotnet` - managed .NET runtime
48
+ - `dotnet` - managed .NET and ASP.NET Core runtime
49
49
  - `npm-packages` - managed npm prefix, including `pm2`
50
50
  - `omniroute` - vendored bundled runtime
51
51
  - `code-server` - vendored bundled runtime
@@ -0,0 +1,37 @@
1
+ import { type CommandRunner } from "./command-launch.js";
2
+ export interface InstallManagedDotnetRuntimeOptions {
3
+ targetDirectory: string;
4
+ version: string;
5
+ runner?: CommandRunner;
6
+ fetchImpl?: typeof fetch;
7
+ platform?: NodeJS.Platform;
8
+ architecture?: string;
9
+ timeoutMs?: number;
10
+ scriptBaseUrl?: string;
11
+ verbose?: boolean;
12
+ }
13
+ export interface ManagedDotnetVerificationResult {
14
+ valid: boolean;
15
+ targetDirectory: string;
16
+ dotnetPath: string;
17
+ installedRuntimes: Record<string, string[]>;
18
+ requiredVersion: string;
19
+ failureReason?: string;
20
+ infoOutput?: string;
21
+ listRuntimesOutput?: string;
22
+ }
23
+ export interface InstallManagedDotnetRuntimeResult extends ManagedDotnetVerificationResult {
24
+ valid: true;
25
+ }
26
+ export declare function installManagedDotnetRuntime(options: InstallManagedDotnetRuntimeOptions): Promise<InstallManagedDotnetRuntimeResult>;
27
+ export declare function verifyManagedDotnetRuntime(options: {
28
+ targetDirectory: string;
29
+ version: string;
30
+ runner?: CommandRunner;
31
+ platform?: NodeJS.Platform;
32
+ timeoutMs?: number;
33
+ }): Promise<ManagedDotnetVerificationResult>;
34
+ export declare function getManagedDotnetExecutablePath(targetDirectory: string, platform?: NodeJS.Platform): string;
35
+ export declare function parseInstalledDotnetRuntimes(output: string): Record<string, string[]>;
36
+ export declare function mapDotnetArchitecture(architecture: string): "x64" | "arm64";
37
+ export declare function buildDotnetInstallScriptUrl(platform: NodeJS.Platform, scriptBaseUrl?: string): string;
@@ -0,0 +1,226 @@
1
+ import { access, chmod, mkdtemp, rm, writeFile } from "node:fs/promises";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { assertTargetIsEmptyOrMissing, moveExtractedRootToTarget } from "./node-extract.js";
4
+ import { runCommand } from "./command-launch.js";
5
+ const managedDotnetRuntimeNames = [
6
+ "Microsoft.NETCore.App",
7
+ "Microsoft.AspNetCore.App"
8
+ ];
9
+ export async function installManagedDotnetRuntime(options) {
10
+ const targetDirectory = resolve(options.targetDirectory);
11
+ const version = normalizeRequiredVersion(options.version);
12
+ const runner = options.runner ?? runCommand;
13
+ const platform = options.platform ?? process.platform;
14
+ const architecture = mapDotnetArchitecture(options.architecture ?? process.arch);
15
+ const stagingRoot = await mkdtemp(join(dirname(targetDirectory), ".hagiscript-dotnet-"));
16
+ const stagedRuntimeDirectory = join(stagingRoot, "runtime");
17
+ const installerScriptPath = join(stagingRoot, platform === "win32" ? "dotnet-install.ps1" : "dotnet-install.sh");
18
+ await assertTargetIsEmptyOrMissing(targetDirectory);
19
+ try {
20
+ await downloadDotnetInstallScript(installerScriptPath, {
21
+ platform,
22
+ scriptBaseUrl: options.scriptBaseUrl,
23
+ fetchImpl: options.fetchImpl
24
+ });
25
+ for (const runtimeKind of ["dotnet", "aspnetcore"]) {
26
+ const invocation = buildDotnetInstallInvocation({
27
+ installerScriptPath,
28
+ installDirectory: stagedRuntimeDirectory,
29
+ version,
30
+ runtime: runtimeKind,
31
+ platform,
32
+ architecture,
33
+ verbose: options.verbose
34
+ });
35
+ await runner(invocation.command, invocation.args, {
36
+ timeoutMs: options.timeoutMs,
37
+ env: {
38
+ ...process.env,
39
+ DOTNET_CLI_TELEMETRY_OPTOUT: "1",
40
+ DOTNET_NOLOGO: "1",
41
+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1"
42
+ }
43
+ });
44
+ }
45
+ const verification = await verifyManagedDotnetRuntime({
46
+ targetDirectory: stagedRuntimeDirectory,
47
+ version,
48
+ runner,
49
+ platform,
50
+ timeoutMs: options.timeoutMs
51
+ });
52
+ if (!verification.valid) {
53
+ throw new Error(`Installed .NET runtime failed verification: ${verification.failureReason ?? "unknown failure"}`);
54
+ }
55
+ await moveExtractedRootToTarget(stagedRuntimeDirectory, targetDirectory);
56
+ return {
57
+ ...verification,
58
+ valid: true,
59
+ targetDirectory
60
+ };
61
+ }
62
+ finally {
63
+ await rm(stagingRoot, { recursive: true, force: true }).catch(() => undefined);
64
+ }
65
+ }
66
+ export async function verifyManagedDotnetRuntime(options) {
67
+ const targetDirectory = resolve(options.targetDirectory);
68
+ const version = normalizeRequiredVersion(options.version);
69
+ const platform = options.platform ?? process.platform;
70
+ const runner = options.runner ?? runCommand;
71
+ const dotnetPath = getManagedDotnetExecutablePath(targetDirectory, platform);
72
+ try {
73
+ await access(dotnetPath);
74
+ }
75
+ catch (error) {
76
+ return {
77
+ valid: false,
78
+ targetDirectory,
79
+ dotnetPath,
80
+ installedRuntimes: {},
81
+ requiredVersion: version,
82
+ failureReason: error instanceof Error
83
+ ? `Managed dotnet executable is missing: ${error.message}`
84
+ : "Managed dotnet executable is missing."
85
+ };
86
+ }
87
+ try {
88
+ const [infoResult, listRuntimesResult] = await Promise.all([
89
+ runner(dotnetPath, ["--info"], {
90
+ timeoutMs: options.timeoutMs
91
+ }),
92
+ runner(dotnetPath, ["--list-runtimes"], {
93
+ timeoutMs: options.timeoutMs
94
+ })
95
+ ]);
96
+ const installedRuntimes = parseInstalledDotnetRuntimes(listRuntimesResult.stdout);
97
+ for (const runtimeName of managedDotnetRuntimeNames) {
98
+ if (!installedRuntimes[runtimeName]?.includes(version)) {
99
+ return {
100
+ valid: false,
101
+ targetDirectory,
102
+ dotnetPath,
103
+ installedRuntimes,
104
+ requiredVersion: version,
105
+ infoOutput: infoResult.stdout,
106
+ listRuntimesOutput: listRuntimesResult.stdout,
107
+ failureReason: `Missing required runtime ${runtimeName} ${version}.`
108
+ };
109
+ }
110
+ }
111
+ return {
112
+ valid: true,
113
+ targetDirectory,
114
+ dotnetPath,
115
+ installedRuntimes,
116
+ requiredVersion: version,
117
+ infoOutput: infoResult.stdout,
118
+ listRuntimesOutput: listRuntimesResult.stdout
119
+ };
120
+ }
121
+ catch (error) {
122
+ return {
123
+ valid: false,
124
+ targetDirectory,
125
+ dotnetPath,
126
+ installedRuntimes: {},
127
+ requiredVersion: version,
128
+ failureReason: error instanceof Error ? error.message : "Failed to execute managed dotnet verification."
129
+ };
130
+ }
131
+ }
132
+ export function getManagedDotnetExecutablePath(targetDirectory, platform = process.platform) {
133
+ return join(resolve(targetDirectory), platform === "win32" ? "dotnet.exe" : "dotnet");
134
+ }
135
+ export function parseInstalledDotnetRuntimes(output) {
136
+ const runtimes = {};
137
+ for (const line of output.split(/\r?\n/u)) {
138
+ const match = /^(?<name>\S+)\s+(?<version>\S+)\s+\[[^\]]+\]$/u.exec(line.trim());
139
+ if (!match?.groups?.name || !match.groups.version) {
140
+ continue;
141
+ }
142
+ const versions = (runtimes[match.groups.name] ??= []);
143
+ versions.push(match.groups.version);
144
+ }
145
+ return runtimes;
146
+ }
147
+ export function mapDotnetArchitecture(architecture) {
148
+ switch (architecture) {
149
+ case "x64":
150
+ return "x64";
151
+ case "arm64":
152
+ case "aarch64":
153
+ return "arm64";
154
+ default:
155
+ throw new Error(`Unsupported .NET runtime architecture: ${architecture}`);
156
+ }
157
+ }
158
+ function normalizeRequiredVersion(version) {
159
+ const normalized = version.trim();
160
+ if (!normalized) {
161
+ throw new Error("Managed .NET runtime version must be a non-empty string.");
162
+ }
163
+ return normalized;
164
+ }
165
+ async function downloadDotnetInstallScript(destinationPath, options) {
166
+ const fetchImpl = options.fetchImpl ?? globalThis.fetch;
167
+ if (typeof fetchImpl !== "function") {
168
+ throw new Error("Global fetch is unavailable for downloading the .NET installer.");
169
+ }
170
+ const url = buildDotnetInstallScriptUrl(options.platform, options.scriptBaseUrl);
171
+ const response = await fetchImpl(url);
172
+ if (!response.ok) {
173
+ throw new Error(`Failed to download .NET installer ${url}: HTTP ${response.status}`);
174
+ }
175
+ const scriptContents = await response.text();
176
+ await writeFile(destinationPath, scriptContents, "utf8");
177
+ if (options.platform !== "win32") {
178
+ await chmod(destinationPath, 0o755);
179
+ }
180
+ }
181
+ export function buildDotnetInstallScriptUrl(platform, scriptBaseUrl = "https://dot.net/v1") {
182
+ const normalizedBaseUrl = scriptBaseUrl.replace(/\/+$/u, "");
183
+ return `${normalizedBaseUrl}/${platform === "win32" ? "dotnet-install.ps1" : "dotnet-install.sh"}`;
184
+ }
185
+ function buildDotnetInstallInvocation(options) {
186
+ if (options.platform === "win32") {
187
+ return {
188
+ command: "powershell.exe",
189
+ args: [
190
+ "-NoLogo",
191
+ "-NoProfile",
192
+ "-ExecutionPolicy",
193
+ "Bypass",
194
+ "-File",
195
+ options.installerScriptPath,
196
+ "-InstallDir",
197
+ options.installDirectory,
198
+ "-Version",
199
+ options.version,
200
+ "-Runtime",
201
+ options.runtime,
202
+ "-Architecture",
203
+ options.architecture,
204
+ "-NoPath",
205
+ ...(options.verbose ? ["-Verbose"] : [])
206
+ ]
207
+ };
208
+ }
209
+ return {
210
+ command: "bash",
211
+ args: [
212
+ options.installerScriptPath,
213
+ "--install-dir",
214
+ options.installDirectory,
215
+ "--version",
216
+ options.version,
217
+ "--runtime",
218
+ options.runtime,
219
+ "--architecture",
220
+ options.architecture,
221
+ "--no-path",
222
+ ...(options.verbose ? ["--verbose"] : [])
223
+ ]
224
+ };
225
+ }
226
+ //# sourceMappingURL=dotnet-installer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dotnet-installer.js","sourceRoot":"","sources":["../../src/runtime/dotnet-installer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,OAAO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AO,CAAC,gBAAgB;YACxB,WAAW;YACX,OAAO,CAAC,OAAO;YACf,WAAW;YACX,OAAO,CAAC,OAAO;YACf,gBAAgB;YAChB,OAAO,CAAC,YAAY;YACpB,WAAW;YACX,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1C;KACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hagicode/hagiscript",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Scoped npm package foundation for Hagiscript language tooling.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/HagiCode-org/hagiscript#readme",
@@ -35,6 +35,7 @@ components:
35
35
  channelVersion: "10.0"
36
36
  installScript: "scripts/install-dotnet.mjs"
37
37
  verifyScript: "scripts/verify-dotnet.mjs"
38
+ removeScript: "scripts/remove-dotnet.mjs"
38
39
 
39
40
  - name: "npm-packages"
40
41
  type: "package"
@@ -1,24 +1,67 @@
1
1
  #!/usr/bin/env node
2
+ import { chmod, rm, writeFile } from "node:fs/promises"
2
3
  import path from "node:path"
3
4
  import process from "node:process"
4
5
  import {
5
6
  ensureDirectory,
6
7
  readRuntimeScriptContext,
7
- writeComponentMarker,
8
- writeJsonFile
8
+ writeComponentMarker
9
9
  } from "../lib/runtime-script-lib.mjs"
10
+ import {
11
+ installManagedDotnetRuntime
12
+ } from "../../dist/runtime/dotnet-installer.js"
10
13
 
11
14
  const context = readRuntimeScriptContext()
12
15
  const currentRoot = path.join(context.componentRoot, "current")
16
+ const dotnetPath = path.join(currentRoot, process.platform === "win32" ? "dotnet.exe" : "dotnet")
17
+ const wrapperPath = path.join(context.binDir, process.platform === "win32" ? "dotnet.cmd" : "dotnet")
18
+ const dotnetVersion = context.componentVersion ?? "10.0.5"
13
19
 
20
+ await rm(currentRoot, { recursive: true, force: true })
14
21
  await ensureDirectory(currentRoot)
15
- await writeJsonFile(path.join(currentRoot, "runtime-manifest.json"), {
22
+ await installManagedDotnetRuntime({
23
+ targetDirectory: currentRoot,
24
+ version: dotnetVersion,
25
+ scriptBaseUrl: process.env.HAGISCRIPT_DOTNET_INSTALL_SCRIPT_BASE_URL?.trim() || undefined,
26
+ verbose: process.env.HAGISCRIPT_RUNTIME_VERBOSE === "1"
27
+ })
28
+ await writeFile(path.join(currentRoot, "runtime-manifest.json"), `${JSON.stringify({
16
29
  component: context.componentName,
17
30
  channelVersion: context.componentVersion,
18
- runtimeRoot: context.runtimeRoot
19
- })
31
+ installedVersion: dotnetVersion,
32
+ runtimeRoot: context.runtimeRoot,
33
+ dotnetPath
34
+ }, null, 2)}\n`, "utf8")
35
+ await writeDotnetWrapper(wrapperPath, dotnetPath)
20
36
  await writeComponentMarker(context, {
21
37
  currentRoot,
38
+ dotnetPath,
39
+ wrapperPath,
40
+ runtimeVersion: dotnetVersion,
22
41
  ownership: "hagiscript-managed"
23
42
  })
24
- process.stdout.write(`Prepared .NET runtime placeholder in ${currentRoot}\n`)
43
+ process.stdout.write(`Installed .NET and ASP.NET Core runtime ${dotnetVersion} in ${currentRoot}\n`)
44
+
45
+ async function writeDotnetWrapper(destinationPath, targetPath) {
46
+ await ensureDirectory(path.dirname(destinationPath))
47
+
48
+ if (process.platform === "win32") {
49
+ const relativeTarget = path.relative(path.dirname(destinationPath), targetPath).replaceAll("/", "\\")
50
+ await writeFile(
51
+ destinationPath,
52
+ `@echo off\r\n"%~dp0\\${relativeTarget}" %*\r\n`,
53
+ "utf8"
54
+ )
55
+ return
56
+ }
57
+
58
+ const relativeTarget = path.relative(path.dirname(destinationPath), targetPath).replaceAll("\\", "/")
59
+ await writeFile(
60
+ destinationPath,
61
+ `#!/usr/bin/env sh
62
+ exec "$(dirname "$0")/${relativeTarget}" "$@"
63
+ `,
64
+ "utf8"
65
+ )
66
+ await chmod(destinationPath, 0o755)
67
+ }
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import { rm } from "node:fs/promises"
3
+ import path from "node:path"
4
+ import process from "node:process"
5
+ import { readRuntimeScriptContext } from "../lib/runtime-script-lib.mjs"
6
+
7
+ const context = readRuntimeScriptContext()
8
+ const wrapperPath = path.join(context.binDir, process.platform === "win32" ? "dotnet.cmd" : "dotnet")
9
+
10
+ await rm(context.componentRoot, { recursive: true, force: true })
11
+ await rm(wrapperPath, { force: true })
12
+
13
+ process.stdout.write(`Removed managed .NET runtime from ${context.componentRoot}\n`)
@@ -1,10 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
  import path from "node:path"
3
- import { access } from "node:fs/promises"
4
3
  import process from "node:process"
4
+ import {
5
+ verifyManagedDotnetRuntime
6
+ } from "../../dist/runtime/dotnet-installer.js"
5
7
  import { readRuntimeScriptContext } from "../lib/runtime-script-lib.mjs"
6
8
 
7
9
  const context = readRuntimeScriptContext()
8
- const markerPath = path.join(context.componentRoot, ".hagicode-runtime.json")
9
- await access(markerPath)
10
- process.stdout.write(`Verified .NET runtime marker at ${markerPath}\n`)
10
+ const currentRoot = path.join(context.componentRoot, "current")
11
+ const version = context.componentVersion ?? "10.0.5"
12
+ const verification = await verifyManagedDotnetRuntime({
13
+ targetDirectory: currentRoot,
14
+ version
15
+ })
16
+
17
+ if (!verification.valid) {
18
+ throw new Error(
19
+ `Managed .NET runtime verification failed for ${currentRoot}: ${verification.failureReason ?? "unknown failure"}`
20
+ )
21
+ }
22
+
23
+ process.stdout.write(
24
+ `Verified managed .NET runtime ${version} at ${verification.dotnetPath}\n`
25
+ )
26
+ process.stdout.write(verification.listRuntimesOutput ?? "")