@webority/ensemble 0.5.2 → 0.5.4

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/bin/ensemble.js CHANGED
@@ -39,8 +39,8 @@ async function login(args) {
39
39
  core.openBrowser(grant.verificationUriComplete);
40
40
  core.log('• waiting for your approval …');
41
41
  const token = await waitForApproval(api, grant);
42
- core.log('\n✓ Approved. Connecting this machine …');
43
- const { runnerPath } = core.requireRuntime();
42
+ core.log('\n✓ Approved. Setting up this machine …');
43
+ const { runnerPath } = await core.ensureRuntime();
44
44
  reportSetup(core.finishSetup(api, token, runnerPath));
45
45
  }
46
46
 
@@ -73,7 +73,7 @@ async function enroll(args) {
73
73
  core.log('Ensemble — enrolling "' + name + '" with ' + api);
74
74
  core.log('• exchanging the enrollment token for a per-machine token');
75
75
  const machineToken = await core.enrollMachine(api, token, name);
76
- const { runnerPath } = core.requireRuntime();
76
+ const { runnerPath } = await core.ensureRuntime();
77
77
  reportSetup(core.finishSetup(api, machineToken, runnerPath));
78
78
  }
79
79
 
@@ -97,7 +97,7 @@ function usage() {
97
97
  `ensemble — connect this machine to your Ensemble control plane
98
98
 
99
99
  ensemble login [--api <url>] [--name <machine>]
100
- sign in via your browser + connect this machine (runtime is installed at npm install)
100
+ sign in via your browser + set up this machine (downloads the runtime on first run)
101
101
  ensemble enroll --token <enrollment-token> [--api <url>] [--name <machine>]
102
102
  headless / CI: enrol with an enrollment token from the portal
103
103
  ensemble install (re)download the runner + bus for this platform
package/lib/core.js CHANGED
@@ -101,20 +101,58 @@ function requireRuntime() {
101
101
  return runtimePaths();
102
102
  }
103
103
 
104
+ // Ensure the runner + bus are present, downloading them if this is the first run. Called by
105
+ // `login`/`enroll` AFTER authentication, so the whole thing is: `npm i` then `ensemble login`.
106
+ async function ensureRuntime() {
107
+ if (runtimeInstalled()) {
108
+ return runtimePaths();
109
+ }
110
+ return ensureBinaries();
111
+ }
112
+
113
+ // The per-platform npm optionalDependency (esbuild model): npm installs only the one matching this
114
+ // OS/arch, with the binaries inside. Returns its directory, or null if it isn't installed (then we
115
+ // fall back to the CDN). require.resolve finds it whether hoisted or nested in node_modules.
116
+ function platformPackageDir() {
117
+ const map = {
118
+ 'win-x64': '@webority/ensemble-win-x64',
119
+ 'osx-arm64': '@webority/ensemble-darwin-arm64',
120
+ 'osx-x64': '@webority/ensemble-darwin-x64',
121
+ 'linux-x64': '@webority/ensemble-linux-x64',
122
+ 'linux-arm64': '@webority/ensemble-linux-arm64',
123
+ };
124
+ const pkg = map[platform().key];
125
+ if (!pkg) return null;
126
+ try {
127
+ return path.dirname(require.resolve(pkg + '/package.json'));
128
+ } catch (e) {
129
+ return null;
130
+ }
131
+ }
132
+
133
+ // Put the runner + bus in ~/.ensemble (the stable location the daemon, hooks, and autostart use).
134
+ // Source them from the npm-installed platform package (instant copy, no download); only if that
135
+ // package isn't present do we download from the CDN. So `npm i` delivers the binary and `login`
136
+ // just copies + wires it.
104
137
  async function ensureBinaries() {
105
138
  ensureDirs();
106
139
  const pf = platform();
107
140
  assertSupported();
108
141
  const busPath = path.join(BIN_DIR, 'ensemble-bus' + pf.exe);
109
142
  const runnerPath = path.join(RUNNER_DIR, 'Ensemble.Runner' + pf.exe);
143
+ const pkgDir = platformPackageDir();
110
144
  const targets = [
111
- { name: 'ensemble-bus-' + pf.key + pf.exe, dest: busPath },
112
- { name: 'ensemble-runner-' + pf.key + pf.exe, dest: runnerPath },
145
+ { src: pkgDir && path.join(pkgDir, 'ensemble-bus' + pf.exe), cdn: 'ensemble-bus-' + pf.key + pf.exe, dest: busPath },
146
+ { src: pkgDir && path.join(pkgDir, 'Ensemble.Runner' + pf.exe), cdn: 'ensemble-runner-' + pf.key + pf.exe, dest: runnerPath },
113
147
  ];
114
148
  for (const t of targets) {
115
149
  if (fs.existsSync(t.dest) && fs.statSync(t.dest).size > 0) continue;
116
- log(' downloading ' + t.name + ' …');
117
- await downloadTo(DL_BASE + '/' + t.name, t.dest);
150
+ if (t.src && fs.existsSync(t.src) && fs.statSync(t.src).size > 0) {
151
+ fs.copyFileSync(t.src, t.dest); // from the npm platform package — no download
152
+ } else {
153
+ log(' downloading ' + t.cdn + ' …');
154
+ await downloadTo(DL_BASE + '/' + t.cdn, t.dest);
155
+ }
118
156
  if (pf.os !== 'windows') {
119
157
  fs.chmodSync(t.dest, 0o755);
120
158
  // macOS requires at least an ad-hoc signature to run an unsigned binary.
@@ -315,5 +353,5 @@ module.exports = {
315
353
  log, warn, die, platform, DEFAULT_API, ENSEMBLE_DIR, RUNNER_DIR, BIN_DIR,
316
354
  ensureBinaries, enrollMachine, writeRunnerConfig, wireHooks, installAutostart, startRunner, request,
317
355
  sleep, openBrowser, startDevice, pollDevice, finishSetup, assertSupported,
318
- runtimePaths, runtimeInstalled, requireRuntime,
356
+ runtimePaths, runtimeInstalled, requireRuntime, ensureRuntime,
319
357
  };
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@webority/ensemble",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Connect this machine to your Ensemble control plane — runs the local agent runner and wires the ensemble-bus session bus so your coding sessions talk (per-org, isolated).",
5
5
  "bin": {
6
6
  "ensemble": "bin/ensemble.js"
7
7
  },
8
- "scripts": {
9
- "postinstall": "node lib/postinstall.js"
10
- },
11
8
  "engines": {
12
9
  "node": ">=18"
13
10
  },
11
+ "optionalDependencies": {
12
+ "@webority/ensemble-darwin-arm64": "0.5.4",
13
+ "@webority/ensemble-darwin-x64": "0.5.4",
14
+ "@webority/ensemble-linux-arm64": "0.5.4",
15
+ "@webority/ensemble-linux-x64": "0.5.4",
16
+ "@webority/ensemble-win-x64": "0.5.4"
17
+ },
14
18
  "files": [
15
19
  "bin",
16
20
  "lib",
@@ -1,22 +0,0 @@
1
- 'use strict';
2
- // Runs at `npm install` (postinstall). Downloads the runner + bus for this platform so that
3
- // `ensemble login` is auth-only. Resilient by design: any failure (offline, unsupported OS,
4
- // --ignore-scripts) warns and exits 0 so it never breaks `npm install` — `ensemble install`
5
- // (or the next install) can retry.
6
- const core = require('./core');
7
-
8
- (async () => {
9
- try {
10
- if (core.runtimeInstalled()) {
11
- return; // already present (e.g. reinstall of the same version)
12
- }
13
- core.assertSupported();
14
- core.log('Ensemble: installing the runner + bus for this machine …');
15
- await core.ensureBinaries();
16
- core.log('Ensemble: runtime installed. Next: ensemble login');
17
- } catch (e) {
18
- core.warn('Ensemble: could not install the runtime now (' + (e && e.message ? e.message : e) + ').');
19
- core.warn(' Run ensemble install when ready, then ensemble login.');
20
- // exit 0 — never fail `npm install`.
21
- }
22
- })();