@nwire/cli 0.12.1 → 0.13.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/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/commands/cache.js +1 -1
- package/dist/commands/dev.d.ts +20 -7
- package/dist/commands/dev.js +142 -45
- package/dist/commands/ls.js +5 -3
- package/dist/commands/please.js +4 -2
- package/dist/commands/run.js +6 -2
- package/dist/commands/studio.js +74 -7
- package/dist/lib/dev-entry.d.ts +8 -9
- package/dist/lib/dev-entry.js +24 -25
- package/dist/lib/dev-host.d.ts +88 -0
- package/dist/lib/dev-host.js +438 -0
- package/dist/lib/ensure-built.d.ts +32 -0
- package/dist/lib/ensure-built.js +62 -0
- package/dist/lib/ensure-scan.d.ts +9 -4
- package/dist/lib/ensure-scan.js +46 -19
- package/dist/lib/studio-host-api.d.ts +97 -0
- package/dist/lib/studio-host-api.js +337 -0
- package/dist/lib/studio-probe.d.ts +63 -0
- package/dist/lib/studio-probe.js +132 -0
- package/dist/lib/vite-node.d.ts +7 -6
- package/dist/lib/vite-node.js +8 -8
- package/dist/lib/vite-run.d.ts +15 -0
- package/dist/lib/vite-run.js +33 -0
- package/dist/load-config.d.ts +10 -10
- package/dist/load-config.js +3 -3
- package/dist/studio/assets/abap-DVwoIrM0.js +1 -0
- package/dist/studio/assets/apex-B9XtvxSu.js +1 -0
- package/dist/studio/assets/azcli-D7JTNGKs.js +1 -0
- package/dist/studio/assets/bat-BNHAuPwR.js +1 -0
- package/dist/studio/assets/bicep-C3w6oSfK.js +2 -0
- package/dist/studio/assets/cameligo-DM9kSiq7.js +1 -0
- package/dist/studio/assets/clojure-FWLBUPxU.js +1 -0
- package/dist/studio/assets/codicon-ngg6Pgfi.ttf +0 -0
- package/dist/studio/assets/coffee-DCoMPIwW.js +1 -0
- package/dist/studio/assets/cpp-BNbIvdcw.js +1 -0
- package/dist/studio/assets/csharp-Dj4ULDZr.js +1 -0
- package/dist/studio/assets/csp-C-n5jZKF.js +1 -0
- package/dist/studio/assets/css-COIa8ZTR.js +3 -0
- package/dist/studio/assets/css.worker-CpJJqcA4.js +89 -0
- package/dist/studio/assets/cssMode-CFR5_xwk.js +1 -0
- package/dist/studio/assets/cypher-CW08XVUh.js +1 -0
- package/dist/studio/assets/dart-Bz550Pyv.js +1 -0
- package/dist/studio/assets/dockerfile-DW5REF8E.js +1 -0
- package/dist/studio/assets/ecl-BqdYhwmw.js +1 -0
- package/dist/studio/assets/editor-Br_kD0ds.css +1 -0
- package/dist/studio/assets/editor.api2-CTGEM8gT.js +872 -0
- package/dist/studio/assets/editor.main-sW1qgHFj.js +6 -0
- package/dist/studio/assets/elixir-Oi_9aIAu.js +1 -0
- package/dist/studio/assets/flow9-CIb9youF.js +1 -0
- package/dist/studio/assets/freemarker2-CPrni8hw.js +3 -0
- package/dist/studio/assets/fsharp-64tUaD-0.js +1 -0
- package/dist/studio/assets/go-DLKGL0rd.js +1 -0
- package/dist/studio/assets/graphql-Bz88xn3Q.js +1 -0
- package/dist/studio/assets/handlebars-DkvSNpQB.js +1 -0
- package/dist/studio/assets/hcl-Cq76tSVN.js +1 -0
- package/dist/studio/assets/html-ceN7ITxG.js +1 -0
- package/dist/studio/assets/html.worker-wsVgX3gp.js +502 -0
- package/dist/studio/assets/htmlMode-wduanCXn.js +1 -0
- package/dist/studio/assets/index-4tH0-1cA.js +41 -0
- package/dist/studio/assets/index-Fy3xDmV2.css +1 -0
- package/dist/studio/assets/ini-BTNe9zdh.js +1 -0
- package/dist/studio/assets/java-DzRJKRF3.js +1 -0
- package/dist/studio/assets/javascript-WF3LGLje.js +1 -0
- package/dist/studio/assets/json.worker-CcNiYOcv.js +58 -0
- package/dist/studio/assets/jsonMode-DSujY8tB.js +7 -0
- package/dist/studio/assets/julia-Bgv08lKa.js +1 -0
- package/dist/studio/assets/kotlin-Dzz8TWAt.js +1 -0
- package/dist/studio/assets/less-ak6GUtsl.js +2 -0
- package/dist/studio/assets/lexon-zuaObGAE.js +1 -0
- package/dist/studio/assets/liquid-C5Z7zFr3.js +1 -0
- package/dist/studio/assets/lspLanguageFeatures-B55yfFgf.js +4 -0
- package/dist/studio/assets/lua-ClKCZMmP.js +1 -0
- package/dist/studio/assets/m3-C7XHeDz_.js +1 -0
- package/dist/studio/assets/markdown-LT3qFBoR.js +1 -0
- package/dist/studio/assets/mdx-Bu5jRl19.js +1 -0
- package/dist/studio/assets/mips-B8clQ9KB.js +1 -0
- package/dist/studio/assets/monaco.contribution-KjQ4yOxj.js +2 -0
- package/dist/studio/assets/msdax-DBxc5qPJ.js +1 -0
- package/dist/studio/assets/mysql-qocW_xba.js +1 -0
- package/dist/studio/assets/objective-c-DhkpBlGX.js +1 -0
- package/dist/studio/assets/pascal-C_PJR40u.js +1 -0
- package/dist/studio/assets/pascaligo-BI_Gz9Bp.js +1 -0
- package/dist/studio/assets/perl-CIqGOHTo.js +1 -0
- package/dist/studio/assets/pgsql-DI_z9qfW.js +1 -0
- package/dist/studio/assets/php-Dkwn_yn0.js +1 -0
- package/dist/studio/assets/pla-DvzjACL6.js +1 -0
- package/dist/studio/assets/postiats-Cc9-hkUx.js +1 -0
- package/dist/studio/assets/powerquery-IGzsITFg.js +1 -0
- package/dist/studio/assets/powershell-BHlZlUN6.js +1 -0
- package/dist/studio/assets/protobuf-pGrmMUz5.js +2 -0
- package/dist/studio/assets/pug-B4eH693Y.js +1 -0
- package/dist/studio/assets/python-DpEFuk0I.js +1 -0
- package/dist/studio/assets/qsharp-CwO3kTIU.js +1 -0
- package/dist/studio/assets/r-CiZUpdIa.js +1 -0
- package/dist/studio/assets/razor-BF1svRn9.js +1 -0
- package/dist/studio/assets/redis-DjdIzLdf.js +1 -0
- package/dist/studio/assets/redshift-vCL5QMyw.js +1 -0
- package/dist/studio/assets/restructuredtext-D5hoMHB1.js +1 -0
- package/dist/studio/assets/ruby-ByPQrqP4.js +1 -0
- package/dist/studio/assets/rust-Nz5wukP7.js +1 -0
- package/dist/studio/assets/sb-DgR1RbMJ.js +1 -0
- package/dist/studio/assets/scala-BCgNuXrV.js +1 -0
- package/dist/studio/assets/scheme-TgKpKGpb.js +1 -0
- package/dist/studio/assets/scss-BKxAkvnT.js +3 -0
- package/dist/studio/assets/shell-COgstXIQ.js +1 -0
- package/dist/studio/assets/solidity-DaqmtBSV.js +1 -0
- package/dist/studio/assets/sophia-Da67i9pL.js +1 -0
- package/dist/studio/assets/sparql-CtN8jEDV.js +1 -0
- package/dist/studio/assets/sql-BnJfQHXt.js +1 -0
- package/dist/studio/assets/st-cGKU4FoP.js +1 -0
- package/dist/studio/assets/swift-DyyME8zA.js +1 -0
- package/dist/studio/assets/systemverilog-BYZY5TEG.js +1 -0
- package/dist/studio/assets/tcl-CHv1_zaR.js +1 -0
- package/dist/studio/assets/ts.worker-DfMAw22J.js +67719 -0
- package/dist/studio/assets/tsMode-BiiF1JOM.js +11 -0
- package/dist/studio/assets/twig-CNwULq4h.js +1 -0
- package/dist/studio/assets/typescript-BefpzegH.js +1 -0
- package/dist/studio/assets/typespec-B3KUNs_P.js +1 -0
- package/dist/studio/assets/vb-phZZ2pCs.js +1 -0
- package/dist/studio/assets/wgsl-Df-y4I4e.js +298 -0
- package/dist/studio/assets/workers-DqAl3RFu.js +1 -0
- package/dist/studio/assets/xml-CWw7bbeo.js +1 -0
- package/dist/studio/assets/yaml-CZ0k9DUm.js +1 -0
- package/dist/studio/index.html +13 -0
- package/dist/wire-runner.d.ts +12 -0
- package/dist/wire-runner.js +19 -0
- package/package.json +8 -6
- package/dist/cache-runner.d.ts +0 -1
- package/dist/cache-runner.js +0 -206
package/dist/cache-runner.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
// Cache runner — invoked by `nwire cache`. Imports the consumer's apps
|
|
2
|
-
// registry (resolved via nwire.config.ts or fallback paths), builds the
|
|
3
|
-
// cache, writes .nwire/.
|
|
4
|
-
//
|
|
5
|
-
// User code follows the bundler-style extensionless-import convention
|
|
6
|
-
// (e.g. `import { x } from './foo'` resolving `./foo.ts`), so we load
|
|
7
|
-
// it through jiti rather than Node's strict ESM loader — jiti gives us
|
|
8
|
-
// TS-on-the-fly + the same resolution semantics the dev server uses.
|
|
9
|
-
import { resolve } from "node:path";
|
|
10
|
-
import { createJiti } from "jiti";
|
|
11
|
-
import { buildCache, writeCache } from "@nwire/scan";
|
|
12
|
-
import { loadConfig, resolveAppsEntry } from "./load-config.js";
|
|
13
|
-
async function main() {
|
|
14
|
-
const cwd = process.cwd();
|
|
15
|
-
const config = await loadConfig(cwd);
|
|
16
|
-
const appsPath = resolveAppsEntry(cwd, config);
|
|
17
|
-
const jiti = createJiti(cwd, {
|
|
18
|
-
fsCache: false,
|
|
19
|
-
moduleCache: false,
|
|
20
|
-
interopDefault: true,
|
|
21
|
-
});
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
-
const mod = await jiti.import(appsPath);
|
|
24
|
-
// Resolve apps registry in this order:
|
|
25
|
-
// 1. named export `allApps: App[]`
|
|
26
|
-
// 2. named export `apps: App[]`
|
|
27
|
-
// 3. default export — either App[] or a single App
|
|
28
|
-
// 4. named export `app: App`
|
|
29
|
-
// 5. any single exported App the module declares
|
|
30
|
-
//
|
|
31
|
-
// "App" means either:
|
|
32
|
-
// - `AppDefinition` (legacy `defineApp(name, { modules })`)
|
|
33
|
-
// - bootable `App` (modern `createApp({ modules })`)
|
|
34
|
-
// `createApp` returns an App marked with `$nwireApp: true`.
|
|
35
|
-
// Recognized export names:
|
|
36
|
-
// - allApps: App[] | apps: App[]
|
|
37
|
-
// - default: App | App[]
|
|
38
|
-
// - app: App
|
|
39
|
-
// - buildApp(): App | Promise<App> ← factory pattern
|
|
40
|
-
// - bootstrap(): { app: App, ... } ← test-bootstrap pattern
|
|
41
|
-
// - bootstrap(opts): { app: App, ... }
|
|
42
|
-
//
|
|
43
|
-
// Factory results that boot the App themselves (bootstrap functions
|
|
44
|
-
// that call .start() and run an endpoint) are also accepted — we
|
|
45
|
-
// pull the App handle off the return value and skip the start/stop
|
|
46
|
-
// dance.
|
|
47
|
-
let apps = [];
|
|
48
|
-
let appsAlreadyBooted = false;
|
|
49
|
-
if (Array.isArray(mod.allApps))
|
|
50
|
-
apps = mod.allApps;
|
|
51
|
-
else if (Array.isArray(mod.apps))
|
|
52
|
-
apps = mod.apps;
|
|
53
|
-
else if (Array.isArray(mod.default))
|
|
54
|
-
apps = mod.default;
|
|
55
|
-
else if (isAppLike(mod.default))
|
|
56
|
-
apps = [mod.default];
|
|
57
|
-
else if (isAppLike(mod.app))
|
|
58
|
-
apps = [mod.app];
|
|
59
|
-
else if (typeof mod.buildApp === "function") {
|
|
60
|
-
const built = await mod.buildApp();
|
|
61
|
-
const candidate = isAppLike(built) ? built : findAppInResult(built);
|
|
62
|
-
if (isAppLike(candidate))
|
|
63
|
-
apps = [candidate];
|
|
64
|
-
}
|
|
65
|
-
else if (typeof mod.bootstrap === "function") {
|
|
66
|
-
// Bootstrap usually starts the App and runs an endpoint. We try
|
|
67
|
-
// common signatures: `bootstrap({port,test})`, `bootstrap(port?)`.
|
|
68
|
-
// Returned shape is anything from { app, running } to { nest, nwireApp }
|
|
69
|
-
// to a bare App — we duck-find the first $nwireApp value in the result.
|
|
70
|
-
//
|
|
71
|
-
// 10s watchdog: some bootstrap functions never resolve (e.g. they
|
|
72
|
-
// wait on Nest's signal-driven lifecycle). The scanner falls back to
|
|
73
|
-
// "no apps found" rather than hanging the build pipeline.
|
|
74
|
-
const callWithTimeout = async (fn) => {
|
|
75
|
-
return await Promise.race([
|
|
76
|
-
fn(),
|
|
77
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error("bootstrap watchdog (10s)")), 10_000)),
|
|
78
|
-
]);
|
|
79
|
-
};
|
|
80
|
-
let result;
|
|
81
|
-
try {
|
|
82
|
-
result = await callWithTimeout(() => mod.bootstrap({ port: 0, test: true }));
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
try {
|
|
86
|
-
result = await callWithTimeout(() => mod.bootstrap(0));
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
/* unscannable — leave apps empty */
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const candidate = isAppLike(result) ? result : findAppInResult(result);
|
|
93
|
-
if (isAppLike(candidate)) {
|
|
94
|
-
apps = [candidate];
|
|
95
|
-
appsAlreadyBooted = true;
|
|
96
|
-
// Tear down the endpoint the bootstrap opened — we only need the
|
|
97
|
-
// App's runtime state for the scan.
|
|
98
|
-
const r = result;
|
|
99
|
-
if (typeof r?.running?.shutdown === "function") {
|
|
100
|
-
try {
|
|
101
|
-
await r.running.shutdown("scan");
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
/* ignore */
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (apps.length === 0) {
|
|
110
|
-
apps = Object.values(mod).filter(isAppLike);
|
|
111
|
-
}
|
|
112
|
-
if (apps.length === 0) {
|
|
113
|
-
console.error(`nwire cache: no apps found in ${appsPath}.\n` +
|
|
114
|
-
`Expected one of: exported \`app\`, \`apps\`, \`allApps\`, or a \`buildApp()\` factory returning an App from createApp.\n` +
|
|
115
|
-
`Optional: nwire.config.ts with { appsEntry: "..." } to point at a custom location.`);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
// The forge plugin registers handlers/actors/projections/queries on the
|
|
119
|
-
// dispatcher during the AppBooting hook — so the dispatcher is only
|
|
120
|
-
// populated AFTER `app.start()`. Boot each app for the scan (unless the
|
|
121
|
-
// bootstrap factory already did), then stop it.
|
|
122
|
-
if (!appsAlreadyBooted) {
|
|
123
|
-
for (const a of apps) {
|
|
124
|
-
const app = a;
|
|
125
|
-
if (app.$nwireApp && typeof app.start === "function") {
|
|
126
|
-
await app.start();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const normalized = apps.map(toAppDefinitionShape);
|
|
131
|
-
const cache = buildCache(normalized);
|
|
132
|
-
for (const a of apps) {
|
|
133
|
-
const app = a;
|
|
134
|
-
if (app.$nwireApp && typeof app.stop === "function") {
|
|
135
|
-
try {
|
|
136
|
-
await app.stop();
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
/* ignore — the bootstrap may have already torn things down */
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const outDir = resolve(cwd, config.cacheDir ?? ".nwire");
|
|
144
|
-
await writeCache(cache, outDir);
|
|
145
|
-
// eslint-disable-next-line no-console
|
|
146
|
-
console.log(`nwire cache: wrote ${cache.apps.length} apps, ${cache.plugins.length} plugins, ` +
|
|
147
|
-
`${cache.actions.length} actions, ${cache.events.length} events, ` +
|
|
148
|
-
`${cache.hooks.length} hooks, ${cache.sinks.length} sinks, ` +
|
|
149
|
-
`${cache.resolvers.length} resolvers to ${outDir}/`);
|
|
150
|
-
// Some bootstrap functions leave foreign-framework servers (Nest,
|
|
151
|
-
// Fastify) listening even after we tear down the Nwire side. Force
|
|
152
|
-
// process exit so the scan doesn't hang the CI pipeline.
|
|
153
|
-
process.exit(0);
|
|
154
|
-
}
|
|
155
|
-
function isAppLike(x) {
|
|
156
|
-
if (typeof x !== "object" || x === null)
|
|
157
|
-
return false;
|
|
158
|
-
const a = x;
|
|
159
|
-
return a.$kind === "app-definition" || a.$nwireApp === true;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Bootstrap/factory functions return wrapper objects in many shapes —
|
|
163
|
-
* `{ app, running }`, `{ nest, nwireApp }`, `{ app, close }`, etc.
|
|
164
|
-
* Find the first property whose value is App-like.
|
|
165
|
-
*/
|
|
166
|
-
function findAppInResult(result) {
|
|
167
|
-
if (typeof result !== "object" || result === null)
|
|
168
|
-
return undefined;
|
|
169
|
-
for (const value of Object.values(result)) {
|
|
170
|
-
if (isAppLike(value))
|
|
171
|
-
return value;
|
|
172
|
-
}
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Normalize either flavor of "app" into the AppDefinition shape the
|
|
177
|
-
* scanner reads. `createApp` returns an `App` with `appName` + the
|
|
178
|
-
* bootable runtime; `defineApp` returns `AppDefinition` with `name` +
|
|
179
|
-
* static metadata. Both expose `modules`, which is all we need.
|
|
180
|
-
*/
|
|
181
|
-
function toAppDefinitionShape(x) {
|
|
182
|
-
const a = x;
|
|
183
|
-
const name = a.appName ?? a.name ?? "app";
|
|
184
|
-
return {
|
|
185
|
-
// Forward both fields — the scanner reads `appName`; legacy
|
|
186
|
-
// consumers may still read `name`.
|
|
187
|
-
name,
|
|
188
|
-
appName: name,
|
|
189
|
-
description: a.description,
|
|
190
|
-
plugins: a.plugins ?? [],
|
|
191
|
-
// Forward operator commands defensively. Consumers who attach a
|
|
192
|
-
// `commands: defineCommand[]` to their app flow it through to the
|
|
193
|
-
// scan emitter so `.nwire/commands.json` reflects ops surface.
|
|
194
|
-
commands: a.commands ?? [],
|
|
195
|
-
tenantModel: a.tenantModel,
|
|
196
|
-
tenantKey: a.tenantKey,
|
|
197
|
-
// Forward the container so the scanner can walk `container.list()`,
|
|
198
|
-
// resolve the forge dispatcher, and emit DI bindings.
|
|
199
|
-
container: a.container ?? a.runtime?.container,
|
|
200
|
-
runtime: a.runtime,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
main().catch((err) => {
|
|
204
|
-
console.error(err);
|
|
205
|
-
process.exit(1);
|
|
206
|
-
});
|