@matheusbbarni/atelier 0.1.0 → 0.1.1

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
@@ -14,3 +14,9 @@ glibc Linux, or Windows on arm64/x64.
14
14
 
15
15
  Installation does not initialize configuration, probe credentials, or start the
16
16
  TUI. Run `atelier --doctor` after installation to inspect runtime readiness.
17
+
18
+ Update the global npm install with:
19
+
20
+ ```sh
21
+ atelier --update
22
+ ```
package/lib/launcher.cjs CHANGED
@@ -2,12 +2,15 @@
2
2
 
3
3
  const { spawn } = require("node:child_process");
4
4
  const os = require("node:os");
5
+ const path = require("node:path");
5
6
  const {
6
7
  TARGETS,
7
8
  supportedTargetKeys,
8
9
  targetForPlatform,
9
10
  } = require("./targets.cjs");
10
11
 
12
+ const TOP_LEVEL_PACKAGE = "@matheusbbarni/atelier";
13
+
11
14
  function unsupportedPlatformMessage(platform, arch, libc) {
12
15
  const libcSuffix = libc ? ` libc=${libc}` : "";
13
16
  return [
@@ -65,6 +68,85 @@ function exitCodeForSignal(signal) {
65
68
  return typeof signalNumber === "number" ? 128 + signalNumber : 1;
66
69
  }
67
70
 
71
+ function isUpdateCommand(argv) {
72
+ return argv.length === 1 && argv[0] === "--update";
73
+ }
74
+
75
+ function pathApiForPlatform(platform) {
76
+ return platform === "win32" ? path.win32 : path.posix;
77
+ }
78
+
79
+ function inferNpmPrefix(packageRoot, platform = process.platform) {
80
+ const pathApi = pathApiForPlatform(platform);
81
+ const resolved = pathApi.resolve(packageRoot);
82
+ const parts = resolved.split(pathApi.sep);
83
+ const nodeModulesIndex = parts.lastIndexOf("node_modules");
84
+ if (nodeModulesIndex === -1) {
85
+ return null;
86
+ }
87
+
88
+ let prefixParts = parts.slice(0, nodeModulesIndex);
89
+ if (platform !== "win32" && prefixParts[prefixParts.length - 1] === "lib") {
90
+ prefixParts = prefixParts.slice(0, -1);
91
+ }
92
+
93
+ return prefixParts.join(pathApi.sep) || pathApi.parse(resolved).root;
94
+ }
95
+
96
+ function npmCommand(platform = process.platform) {
97
+ return platform === "win32" ? "npm.cmd" : "npm";
98
+ }
99
+
100
+ function updateArgs({ packageName = TOP_LEVEL_PACKAGE, prefix = null } = {}) {
101
+ const args = ["install", "--global"];
102
+ if (prefix) {
103
+ args.push("--prefix", prefix);
104
+ }
105
+ args.push(
106
+ "--include=optional",
107
+ "--ignore-scripts",
108
+ "--no-audit",
109
+ "--no-fund",
110
+ `${packageName}@latest`,
111
+ );
112
+ return args;
113
+ }
114
+
115
+ function runUpdate({
116
+ env = process.env,
117
+ cwd = process.cwd(),
118
+ platform = process.platform,
119
+ packageRoot = path.resolve(__dirname, ".."),
120
+ spawnImpl = spawn,
121
+ exit = process.exit,
122
+ stderr = process.stderr,
123
+ } = {}) {
124
+ const prefix = inferNpmPrefix(packageRoot, platform);
125
+ const args = updateArgs({ prefix });
126
+ stderr.write(
127
+ prefix
128
+ ? `Updating atelier with npm in ${prefix}\n`
129
+ : "Updating atelier with npm\n",
130
+ );
131
+
132
+ const child = spawnImpl(npmCommand(platform), args, {
133
+ cwd,
134
+ env,
135
+ stdio: "inherit",
136
+ });
137
+
138
+ child.on("error", (error) => {
139
+ stderr.write(`atelier update failed to start npm: ${error.message}\n`);
140
+ exit(1);
141
+ });
142
+
143
+ child.on("exit", (code, signal) => {
144
+ exit(code ?? exitCodeForSignal(signal));
145
+ });
146
+
147
+ return child;
148
+ }
149
+
68
150
  function spawnBinary({
69
151
  binaryPath,
70
152
  argv = process.argv.slice(2),
@@ -99,11 +181,24 @@ function main({
99
181
  platform = process.platform,
100
182
  arch = process.arch,
101
183
  libc,
184
+ packageRoot = path.resolve(__dirname, ".."),
102
185
  requireResolve = require.resolve,
103
186
  spawnImpl = spawn,
104
187
  exit = process.exit,
105
188
  stderr = process.stderr,
106
189
  } = {}) {
190
+ if (isUpdateCommand(argv)) {
191
+ return runUpdate({
192
+ env,
193
+ cwd,
194
+ platform,
195
+ packageRoot,
196
+ spawnImpl,
197
+ exit,
198
+ stderr,
199
+ });
200
+ }
201
+
107
202
  let resolved;
108
203
  try {
109
204
  resolved = resolveBinary({ env, platform, arch, libc, requireResolve });
@@ -126,9 +221,13 @@ function main({
126
221
 
127
222
  module.exports = {
128
223
  TARGETS,
224
+ inferNpmPrefix,
225
+ isUpdateCommand,
129
226
  main,
130
227
  missingOptionalDependencyMessage,
228
+ runUpdate,
131
229
  resolveBinary,
132
230
  spawnBinary,
231
+ updateArgs,
133
232
  unsupportedPlatformMessage,
134
233
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matheusbbarni/atelier",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Terminal-native agent orchestration harness",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -24,11 +24,11 @@
24
24
  "url": "https://github.com/MatheusBBarni/atelier/issues"
25
25
  },
26
26
  "optionalDependencies": {
27
- "@matheusbbarni/atelier-darwin-arm64": "0.1.0",
28
- "@matheusbbarni/atelier-darwin-x64": "0.1.0",
29
- "@matheusbbarni/atelier-linux-arm64": "0.1.0",
30
- "@matheusbbarni/atelier-linux-x64": "0.1.0",
31
- "@matheusbbarni/atelier-win32-arm64": "0.1.0",
32
- "@matheusbbarni/atelier-win32-x64": "0.1.0"
27
+ "@matheusbbarni/atelier-darwin-arm64": "0.1.1",
28
+ "@matheusbbarni/atelier-darwin-x64": "0.1.1",
29
+ "@matheusbbarni/atelier-linux-arm64": "0.1.1",
30
+ "@matheusbbarni/atelier-linux-x64": "0.1.1",
31
+ "@matheusbbarni/atelier-win32-arm64": "0.1.1",
32
+ "@matheusbbarni/atelier-win32-x64": "0.1.1"
33
33
  }
34
34
  }