@air-jam/server 0.9.1 → 0.9.3

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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { spawn } from "node:child_process";
3
4
  import { existsSync } from "node:fs";
4
5
  import path from "node:path";
5
- import { spawn } from "node:child_process";
6
6
  import { fileURLToPath, pathToFileURL } from "node:url";
7
7
 
8
8
  const packageRoot = path.resolve(
@@ -10,40 +10,63 @@ const packageRoot = path.resolve(
10
10
  "..",
11
11
  );
12
12
  const distEntry = path.join(packageRoot, "dist", "cli.js");
13
- const sourceEntry = path.join(packageRoot, "src", "cli.ts");
13
+ const repoRoot = path.resolve(packageRoot, "../..");
14
+ const workspaceBuildScript = path.join(
15
+ repoRoot,
16
+ "scripts",
17
+ "ensure-workspace-package-build.mjs",
18
+ );
19
+
20
+ const buildWorkspacePackage = async () => {
21
+ if (!existsSync(workspaceBuildScript)) {
22
+ throw new Error(
23
+ "The installed @air-jam/server package is missing its built CLI entrypoint.",
24
+ );
25
+ }
14
26
 
15
- const forwardToSourceCli = async () =>
16
- new Promise((resolve, reject) => {
27
+ await new Promise((resolve, reject) => {
17
28
  const child = spawn(
18
29
  process.execPath,
19
- ["--import", "tsx", sourceEntry, ...process.argv.slice(2)],
30
+ [workspaceBuildScript, "@air-jam/server"],
20
31
  {
21
- cwd: packageRoot,
32
+ cwd: repoRoot,
22
33
  stdio: "inherit",
23
34
  env: process.env,
24
35
  },
25
36
  );
26
37
 
27
38
  child.on("exit", (code, signal) => {
28
- if (signal) {
29
- process.kill(process.pid, signal);
39
+ if (code === 0) {
40
+ resolve(undefined);
30
41
  return;
31
42
  }
32
43
 
33
- process.exitCode = code ?? 0;
34
- resolve(undefined);
44
+ reject(
45
+ new Error(
46
+ signal
47
+ ? `Workspace server build terminated by signal ${signal}.`
48
+ : `Workspace server build exited with code ${code}.`,
49
+ ),
50
+ );
35
51
  });
36
-
37
52
  child.on("error", reject);
38
53
  });
54
+ };
39
55
 
40
- if (existsSync(distEntry)) {
41
- const loaded = await import(pathToFileURL(distEntry).href);
42
- if (typeof loaded.runServerCli === "function") {
43
- await loaded.runServerCli();
44
- } else {
45
- await forwardToSourceCli();
46
- }
47
- } else {
48
- await forwardToSourceCli();
56
+ if (!existsSync(distEntry)) {
57
+ await buildWorkspacePackage();
58
+ }
59
+
60
+ if (!existsSync(distEntry)) {
61
+ throw new Error(
62
+ "The @air-jam/server build completed without producing dist/cli.js.",
63
+ );
64
+ }
65
+
66
+ const loaded = await import(pathToFileURL(distEntry).href);
67
+ if (typeof loaded.runServerCli !== "function") {
68
+ throw new Error(
69
+ "The @air-jam/server built CLI entrypoint does not export runServerCli.",
70
+ );
49
71
  }
72
+ process.exitCode = await loaded.runServerCli();