@di-framework/cli-plugin-platform 0.0.1 → 6.0.2
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 +408 -0
- package/dist/actor-protocol.d.ts +4 -0
- package/dist/actor-protocol.js +162 -0
- package/dist/actors.d.ts +31 -0
- package/dist/actors.js +296 -0
- package/dist/args.d.ts +15 -0
- package/dist/args.js +66 -0
- package/dist/assets/http-adapter.js +876 -0
- package/dist/assets/platform/.gitignore.tmpl +6 -0
- package/dist/assets/platform/Pulumi.yaml.tmpl +6 -0
- package/dist/assets/platform/README.md +208 -0
- package/dist/assets/platform/index.ts.tmpl +2 -0
- package/dist/assets/platform/package.json.tmpl +18 -0
- package/dist/assets/platform/tsconfig.json +11 -0
- package/dist/assets/queue-adapter.js +60 -0
- package/dist/assets/sqlite/BUILD-INFO.txt +13 -0
- package/dist/assets/sqlite/SHA256SUMS +2 -0
- package/dist/assets/sqlite/di-framework-sqlite.wasm +0 -0
- package/dist/assets/sqlite/di-framework-sqlite.wit +337 -0
- package/dist/assets/wit/deps/LICENSE.md +8 -0
- package/dist/assets/wit/deps/di-framework-queues/package.wit +18 -0
- package/dist/assets/wit/deps/di-framework-sqlite/package.wit +211 -0
- package/dist/assets/wit/deps/wasi-cli/package.wit +70 -0
- package/dist/assets/wit/deps/wasi-clocks/package.wit +42 -0
- package/dist/assets/wit/deps/wasi-config/package.wit +15 -0
- package/dist/assets/wit/deps/wasi-filesystem/package.wit +184 -0
- package/dist/assets/wit/deps/wasi-http/package.wit +170 -0
- package/dist/assets/wit/deps/wasi-random/package.wit +17 -0
- package/dist/assets/wit/deps/wasi-sockets/package.wit +105 -0
- package/dist/assets/wit/deps/wasi-tls/package.wit +26 -0
- package/dist/assets/wit/deps/wasmcloud-blobstore/package.wit +153 -0
- package/dist/assets/wit/deps/wasmcloud-keyvalue/package.wit +370 -0
- package/dist/assets/wit/deps/wasmcloud-messaging/package.wit +125 -0
- package/dist/assets/wit/deps/wasmcloud-postgres/package.wit +435 -0
- package/dist/assets/wit/deps/wasmcloud-secrets/package.wit +80 -0
- package/dist/async-transform.d.ts +3 -0
- package/dist/async-transform.js +60 -0
- package/dist/bindings.d.ts +34 -0
- package/dist/bindings.js +307 -0
- package/dist/build.d.ts +29 -0
- package/dist/build.js +325 -0
- package/dist/command.d.ts +3 -0
- package/dist/command.js +141 -0
- package/dist/control/auth.d.ts +18 -0
- package/dist/control/auth.js +89 -0
- package/dist/control/cron.d.ts +7 -0
- package/dist/control/cron.js +86 -0
- package/dist/control/index.d.ts +4 -0
- package/dist/control/index.js +4 -0
- package/dist/control/network.d.ts +12 -0
- package/dist/control/network.js +49 -0
- package/dist/control/queues.d.ts +15 -0
- package/dist/control/queues.js +77 -0
- package/dist/cron.d.ts +26 -0
- package/dist/cron.js +239 -0
- package/dist/deploy.d.ts +29 -0
- package/dist/deploy.js +57 -0
- package/dist/deps.d.ts +96 -0
- package/dist/deps.js +303 -0
- package/dist/destroy.d.ts +3 -0
- package/dist/destroy.js +24 -0
- package/dist/dev-runner.d.ts +24 -0
- package/dist/dev-runner.js +83 -0
- package/dist/dev.d.ts +8 -0
- package/dist/dev.js +76 -0
- package/dist/discovery.d.ts +15 -0
- package/dist/discovery.js +182 -0
- package/dist/doctor.d.ts +8 -0
- package/dist/doctor.js +82 -0
- package/dist/guests.d.ts +9 -0
- package/dist/guests.js +56 -0
- package/dist/host-interface.d.ts +29 -0
- package/dist/host-interface.js +142 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +39 -0
- package/dist/kubernetes.d.ts +9 -0
- package/dist/kubernetes.js +17 -0
- package/dist/managed-bindings.d.ts +9 -0
- package/dist/managed-bindings.js +150 -0
- package/dist/manifest.d.ts +36 -0
- package/dist/manifest.js +257 -0
- package/dist/namespace.d.ts +2 -0
- package/dist/namespace.js +4 -0
- package/dist/node-compat/async-hooks.d.ts +29 -0
- package/dist/node-compat/async-hooks.js +80 -0
- package/dist/node-compat/bootstrap.d.ts +1 -0
- package/dist/node-compat/bootstrap.js +9 -0
- package/dist/node-compat/bytes.d.ts +7 -0
- package/dist/node-compat/bytes.js +41 -0
- package/dist/node-compat/crypto-hash.d.ts +27 -0
- package/dist/node-compat/crypto-hash.js +108 -0
- package/dist/node-compat/crypto-subtle.d.ts +59 -0
- package/dist/node-compat/crypto-subtle.js +288 -0
- package/dist/node-compat/crypto.d.ts +136 -0
- package/dist/node-compat/crypto.js +142 -0
- package/dist/node-compat/dgram.d.ts +49 -0
- package/dist/node-compat/dgram.js +197 -0
- package/dist/node-compat/env.d.ts +6 -0
- package/dist/node-compat/env.js +88 -0
- package/dist/node-compat/fetch-runtime.d.ts +80 -0
- package/dist/node-compat/fetch-runtime.js +314 -0
- package/dist/node-compat/fs.d.ts +84 -0
- package/dist/node-compat/fs.js +285 -0
- package/dist/node-compat/http-parser.d.ts +40 -0
- package/dist/node-compat/http-parser.js +185 -0
- package/dist/node-compat/http.d.ts +130 -0
- package/dist/node-compat/http.js +688 -0
- package/dist/node-compat/https.d.ts +28 -0
- package/dist/node-compat/https.js +88 -0
- package/dist/node-compat/module.d.ts +11 -0
- package/dist/node-compat/module.js +35 -0
- package/dist/node-compat/net.d.ts +119 -0
- package/dist/node-compat/net.js +441 -0
- package/dist/node-compat/process.d.ts +25 -0
- package/dist/node-compat/process.js +63 -0
- package/dist/node-compat/runtime-application.d.ts +4 -0
- package/dist/node-compat/runtime-application.js +24 -0
- package/dist/node-compat/seed-virtual.d.ts +6 -0
- package/dist/node-compat/seed-virtual.js +6 -0
- package/dist/node-compat/seed.d.ts +20 -0
- package/dist/node-compat/seed.js +106 -0
- package/dist/node-compat/socket-address.d.ts +35 -0
- package/dist/node-compat/socket-address.js +162 -0
- package/dist/node-compat/timers.d.ts +32 -0
- package/dist/node-compat/timers.js +96 -0
- package/dist/node-compat/tls.d.ts +57 -0
- package/dist/node-compat/tls.js +290 -0
- package/dist/node-compat/wasi-random.d.ts +2 -0
- package/dist/node-compat/wasi-random.js +25 -0
- package/dist/node-compat/wasi-sockets.d.ts +47 -0
- package/dist/node-compat/wasi-sockets.js +134 -0
- package/dist/oci.d.ts +9 -0
- package/dist/oci.js +9 -0
- package/dist/paths.d.ts +7 -0
- package/dist/paths.js +13 -0
- package/dist/platform-init.d.ts +13 -0
- package/dist/platform-init.js +265 -0
- package/dist/platform.d.ts +22 -0
- package/dist/platform.js +170 -0
- package/dist/project.d.ts +39 -0
- package/dist/project.js +130 -0
- package/dist/publish.d.ts +15 -0
- package/dist/publish.js +57 -0
- package/dist/pulumi.d.ts +4 -0
- package/dist/pulumi.js +27 -0
- package/dist/queues-module.d.ts +4 -0
- package/dist/queues-module.js +89 -0
- package/dist/queues.d.ts +16 -0
- package/dist/queues.js +167 -0
- package/dist/registry.d.ts +16 -0
- package/dist/registry.js +27 -0
- package/dist/service.d.ts +162 -0
- package/dist/service.js +678 -0
- package/dist/support.d.ts +14 -0
- package/dist/support.js +37 -0
- package/dist/target.d.ts +18 -0
- package/dist/target.js +45 -0
- package/dist/toml.d.ts +6 -0
- package/dist/toml.js +245 -0
- package/dist/wash-dev.d.ts +18 -0
- package/dist/wash-dev.js +80 -0
- package/dist/wit.d.ts +76 -0
- package/dist/wit.js +248 -0
- package/dist/workload-members.d.ts +12 -0
- package/dist/workload-members.js +136 -0
- package/dist/workload.d.ts +45 -0
- package/dist/workload.js +457 -0
- package/package.json +55 -8
- package/src/index.ts +0 -2
package/dist/deps.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { transformAsync } from '@babel/core';
|
|
7
|
+
import asyncToGenerator from '@babel/plugin-transform-async-to-generator';
|
|
8
|
+
import { rolldown } from 'rolldown';
|
|
9
|
+
import { emptyActorsModule } from './actors.js';
|
|
10
|
+
import { lowerForAwait } from './async-transform.js';
|
|
11
|
+
import { emptyGuestsModule } from './guests.js';
|
|
12
|
+
import { rolldownInject, wasmcloudNodeEnv } from './node-compat/env.js';
|
|
13
|
+
import { createNodeCompatSeed, EMPTY_NODE_COMPAT_SEED, isNodeCompatSeedSource, NODE_COMPAT_SEED_ID, renderNodeCompatSeedModule, } from './node-compat/seed.js';
|
|
14
|
+
/** Component imports are WIT specifiers, not npm packages. */
|
|
15
|
+
export const COMPONENT_IMPORT_EXTERNAL = /^(wasi|wasmcloud|di-framework):/;
|
|
16
|
+
const NODE_COMPAT_SEED_RESOLVED = `\0${NODE_COMPAT_SEED_ID}`;
|
|
17
|
+
/** Resolves the virtual application module and Node built-ins through unenv. */
|
|
18
|
+
export function nodeCompatibilityPlugin(entryPath, guestsPath, seedOrActorsPath, maybeSeed) {
|
|
19
|
+
let actorsPath;
|
|
20
|
+
let cronPath;
|
|
21
|
+
let queuesPath;
|
|
22
|
+
let resolvedGuestsPath;
|
|
23
|
+
let seed = EMPTY_NODE_COMPAT_SEED;
|
|
24
|
+
if (guestsPath !== undefined && typeof guestsPath === 'object') {
|
|
25
|
+
resolvedGuestsPath = guestsPath.guestsPath;
|
|
26
|
+
actorsPath = guestsPath.actorsPath;
|
|
27
|
+
cronPath = guestsPath.cronPath;
|
|
28
|
+
queuesPath = guestsPath.queuesPath;
|
|
29
|
+
if (typeof seedOrActorsPath === 'object' && seedOrActorsPath) {
|
|
30
|
+
seed = seedOrActorsPath;
|
|
31
|
+
}
|
|
32
|
+
else if (maybeSeed) {
|
|
33
|
+
seed = maybeSeed;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
resolvedGuestsPath = guestsPath;
|
|
38
|
+
if (typeof seedOrActorsPath === 'string') {
|
|
39
|
+
actorsPath = seedOrActorsPath;
|
|
40
|
+
seed = maybeSeed ?? EMPTY_NODE_COMPAT_SEED;
|
|
41
|
+
}
|
|
42
|
+
else if (seedOrActorsPath && typeof seedOrActorsPath === 'object') {
|
|
43
|
+
seed = seedOrActorsPath;
|
|
44
|
+
}
|
|
45
|
+
else if (maybeSeed) {
|
|
46
|
+
seed = maybeSeed;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const aliases = wasmcloudNodeEnv().alias;
|
|
50
|
+
return {
|
|
51
|
+
name: 'di-framework-component-runtime',
|
|
52
|
+
resolveId(source, importer) {
|
|
53
|
+
if (resolvedGuestsPath &&
|
|
54
|
+
importer === resolvedGuestsPath &&
|
|
55
|
+
/^[a-z][a-z0-9-]*-(query|prepared)$/.test(source))
|
|
56
|
+
return { id: source, external: true };
|
|
57
|
+
if (source === 'virtual:di-framework-application')
|
|
58
|
+
return entryPath;
|
|
59
|
+
if (source === 'virtual:di-framework-wasmcloud-runtime') {
|
|
60
|
+
return join(dirname(fileURLToPath(import.meta.url)), 'node-compat', `runtime-application.${import.meta.url.endsWith('.ts') ? 'ts' : 'js'}`);
|
|
61
|
+
}
|
|
62
|
+
if (source === 'virtual:di-framework-wasmcloud-guests') {
|
|
63
|
+
return resolvedGuestsPath ?? '\0virtual:di-framework-wasmcloud-guests-empty';
|
|
64
|
+
}
|
|
65
|
+
if (source === 'virtual:di-framework-wasmcloud-actors') {
|
|
66
|
+
return actorsPath ?? '\0virtual:di-framework-wasmcloud-actors-empty';
|
|
67
|
+
}
|
|
68
|
+
if (source === 'virtual:di-framework-wasmcloud-cron') {
|
|
69
|
+
return cronPath ?? '\0virtual:di-framework-wasmcloud-cron-empty';
|
|
70
|
+
}
|
|
71
|
+
if (source === 'virtual:di-framework-wasmcloud-queues') {
|
|
72
|
+
return queuesPath ?? '\0virtual:di-framework-wasmcloud-queues-empty';
|
|
73
|
+
}
|
|
74
|
+
if (isNodeCompatSeedSource(source))
|
|
75
|
+
return NODE_COMPAT_SEED_RESOLVED;
|
|
76
|
+
return aliases[source] ?? null;
|
|
77
|
+
},
|
|
78
|
+
load(id) {
|
|
79
|
+
if (id === '\0virtual:di-framework-wasmcloud-guests-empty')
|
|
80
|
+
return emptyGuestsModule();
|
|
81
|
+
if (id === '\0virtual:di-framework-wasmcloud-actors-empty')
|
|
82
|
+
return emptyActorsModule();
|
|
83
|
+
if (id === '\0virtual:di-framework-wasmcloud-cron-empty') {
|
|
84
|
+
return 'export async function invokeJob() { throw new Error("No cron jobs registered"); }\n';
|
|
85
|
+
}
|
|
86
|
+
if (id === '\0virtual:di-framework-wasmcloud-queues-empty') {
|
|
87
|
+
return 'export function getQueueBackend() { return undefined; }\nexport async function ensureQueueWorkers() {}\nexport async function pumpQueueWorkers() { return 0; }\n';
|
|
88
|
+
}
|
|
89
|
+
if (id === NODE_COMPAT_SEED_RESOLVED)
|
|
90
|
+
return renderNodeCompatSeedModule(seed);
|
|
91
|
+
return null;
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** Points at a wasmtime-48+ componentize-qjs CLI that can stub imported `async func`s. */
|
|
96
|
+
export const COMPONENTIZE_QJS_ENV = 'DI_FRAMEWORK_COMPONENTIZE_QJS';
|
|
97
|
+
/** npm wrapper that selects the matching optional platform CLI package. */
|
|
98
|
+
export const COMPONENTIZE_QJS_PACKAGE = '@di-framework/componentize-qjs';
|
|
99
|
+
// Real path, not a store symlink, so walking up reaches this package's node_modules.
|
|
100
|
+
const packageRoot = resolve(dirname(realpathSync(fileURLToPath(import.meta.url))), '..');
|
|
101
|
+
export function componentizeQjsPlatformPackageName() {
|
|
102
|
+
return COMPONENTIZE_QJS_PACKAGE;
|
|
103
|
+
}
|
|
104
|
+
export function componentizeQjsPlatformPackageVersion(platform = process.platform, arch = process.arch, wrapperVersion = '0.4.4-di.3') {
|
|
105
|
+
return `${wrapperVersion}-${platform}-${arch}`;
|
|
106
|
+
}
|
|
107
|
+
function platformPackageBinMatches(packageDirectory, platform, arch) {
|
|
108
|
+
const packageJsonPath = join(packageDirectory, 'package.json');
|
|
109
|
+
if (!existsSync(packageJsonPath))
|
|
110
|
+
return true;
|
|
111
|
+
try {
|
|
112
|
+
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
113
|
+
if (Array.isArray(pkg.os) && pkg.os.length > 0 && !pkg.os.includes(platform)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(pkg.cpu) && pkg.cpu.length > 0 && !pkg.cpu.includes(arch)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (typeof pkg.version === 'string' &&
|
|
120
|
+
/-(?:darwin|linux|win32|android)-(?:arm64|x64)$/.test(pkg.version)) {
|
|
121
|
+
return pkg.version.endsWith(`-${platform}-${arch}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Locate the native CLI shipped as `@di-framework/componentize-qjs@<version>-<os>-<arch>`.
|
|
131
|
+
* Walks `node_modules` from `startDirectory` (same strategy as `findJcoEntry`)
|
|
132
|
+
* so Bun's install cache is not required. The wrapper aliases that version into
|
|
133
|
+
* an unscoped `componentize-qjs-<os>-<arch>` folder.
|
|
134
|
+
*/
|
|
135
|
+
export function findInstalledComponentizeQjsCli(startDirectory = packageRoot, platform = process.platform, arch = process.arch) {
|
|
136
|
+
const packageDirectories = (nodeModules) => [
|
|
137
|
+
join(nodeModules, `componentize-qjs-${platform}-${arch}`),
|
|
138
|
+
join(nodeModules, '@di-framework', 'componentize-qjs'),
|
|
139
|
+
];
|
|
140
|
+
const binName = platform === 'win32' ? 'componentize-qjs.exe' : 'componentize-qjs';
|
|
141
|
+
let previous = '';
|
|
142
|
+
let current = startDirectory;
|
|
143
|
+
while (current !== previous) {
|
|
144
|
+
for (const packageDirectory of packageDirectories(join(current, 'node_modules'))) {
|
|
145
|
+
const bin = join(packageDirectory, 'bin', binName);
|
|
146
|
+
if (existsSync(bin) && platformPackageBinMatches(packageDirectory, platform, arch)) {
|
|
147
|
+
return bin;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
previous = current;
|
|
151
|
+
current = dirname(current);
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
const require = createRequire(join(startDirectory, 'package.json'));
|
|
155
|
+
const loaded = require(COMPONENTIZE_QJS_PACKAGE);
|
|
156
|
+
const fromPackage = loaded.nativeCliPath?.(platform, arch);
|
|
157
|
+
return fromPackage !== undefined && existsSync(fromPackage) ? fromPackage : undefined;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export function resolveComponentizeQjsPath(env = process.env, installedCliPath, pathCli) {
|
|
164
|
+
const explicit = env[COMPONENTIZE_QJS_ENV]?.trim();
|
|
165
|
+
if (explicit !== undefined && explicit !== '')
|
|
166
|
+
return explicit;
|
|
167
|
+
return installedCliPath ?? pathCli;
|
|
168
|
+
}
|
|
169
|
+
/** PATH entries inside node_modules are the npm wrapper, not a native wasmtime-48 CLI. */
|
|
170
|
+
export function nativeComponentizeQjsOnPath(whichPath = Bun.which('componentize-qjs') ?? undefined) {
|
|
171
|
+
if (whichPath === undefined)
|
|
172
|
+
return undefined;
|
|
173
|
+
if (whichPath.split(/[/\\]/).includes('node_modules'))
|
|
174
|
+
return undefined;
|
|
175
|
+
return whichPath;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* jco's entry inside a real node_modules tree, walking up from this package.
|
|
179
|
+
* Bun's `import.meta.resolve` can return its global install cache, where jco's
|
|
180
|
+
* own dependencies are not resolvable by Node; a node_modules path always is.
|
|
181
|
+
*/
|
|
182
|
+
export function findJcoEntry(startDirectory) {
|
|
183
|
+
let previous = '';
|
|
184
|
+
let current = startDirectory;
|
|
185
|
+
while (current !== previous) {
|
|
186
|
+
const candidates = [
|
|
187
|
+
join(current, 'node_modules', '@bytecodealliance', 'jco', 'dist', 'jco.js'),
|
|
188
|
+
join(current, 'node_modules', '@bytecodealliance', 'jco', 'src', 'jco.js'),
|
|
189
|
+
];
|
|
190
|
+
const candidate = candidates.find((path) => existsSync(path));
|
|
191
|
+
if (candidate !== undefined)
|
|
192
|
+
return candidate;
|
|
193
|
+
previous = current;
|
|
194
|
+
current = dirname(current);
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
export const DEFAULT_DEPS = {
|
|
199
|
+
runner: async (command, args, options) => {
|
|
200
|
+
const child = Bun.spawn([command, ...args], {
|
|
201
|
+
cwd: options.cwd,
|
|
202
|
+
env: options.env ?? process.env,
|
|
203
|
+
stdio: ['inherit', 'inherit', 'inherit'],
|
|
204
|
+
});
|
|
205
|
+
return { exitCode: await child.exited };
|
|
206
|
+
},
|
|
207
|
+
capture: (command, args) => {
|
|
208
|
+
// Bounded so a wedged tool (e.g. docker with an unreachable daemon) reads as unavailable.
|
|
209
|
+
const result = spawnSync(command, args, { encoding: 'utf8', timeout: 5_000 });
|
|
210
|
+
if (result.error || result.status !== 0)
|
|
211
|
+
return undefined;
|
|
212
|
+
return (result.stdout || result.stderr).trim().split('\n')[0];
|
|
213
|
+
},
|
|
214
|
+
runCaptured: async (command, args, options) => {
|
|
215
|
+
const child = Bun.spawn([command, ...args], {
|
|
216
|
+
cwd: options.cwd,
|
|
217
|
+
env: options.env ?? process.env,
|
|
218
|
+
stdin: 'ignore',
|
|
219
|
+
stdout: 'pipe',
|
|
220
|
+
stderr: 'pipe',
|
|
221
|
+
});
|
|
222
|
+
const stdout = await new Response(child.stdout).text();
|
|
223
|
+
const stderr = await new Response(child.stderr).text();
|
|
224
|
+
return { exitCode: await child.exited, stdout, stderr };
|
|
225
|
+
},
|
|
226
|
+
wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
227
|
+
bundler: async ({ adapterPath, entryPath, outFile, guestsPath, actorsPath, cronPath, queuesPath, projectRoot, files, env, cwd, }) => {
|
|
228
|
+
const nodeEnv = wasmcloudNodeEnv();
|
|
229
|
+
const bundle = await rolldown({
|
|
230
|
+
input: 'virtual:di-framework-runtime-entry',
|
|
231
|
+
external: COMPONENT_IMPORT_EXTERNAL,
|
|
232
|
+
resolve: { alias: { ...nodeEnv.alias }, conditionNames: ['wasmcloud', 'import', 'default'] },
|
|
233
|
+
plugins: [
|
|
234
|
+
{
|
|
235
|
+
name: 'di-framework-runtime-bootstrap',
|
|
236
|
+
resolveId(id) {
|
|
237
|
+
if (id === 'virtual:di-framework-runtime-entry')
|
|
238
|
+
return `\0${id}`;
|
|
239
|
+
},
|
|
240
|
+
load(id) {
|
|
241
|
+
if (id === '\0virtual:di-framework-runtime-entry') {
|
|
242
|
+
const bootstrap = join(dirname(fileURLToPath(import.meta.url)), 'node-compat', `bootstrap.${import.meta.url.endsWith('.ts') ? 'ts' : 'js'}`);
|
|
243
|
+
return `import ${JSON.stringify(bootstrap)}; export * from ${JSON.stringify(adapterPath)};`;
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
nodeCompatibilityPlugin(entryPath, { guestsPath, actorsPath, cronPath, queuesPath }, createNodeCompatSeed({ files, env, cwd, projectRoot })),
|
|
248
|
+
],
|
|
249
|
+
transform: {
|
|
250
|
+
decorator: { legacy: true },
|
|
251
|
+
inject: rolldownInject(nodeEnv.inject),
|
|
252
|
+
},
|
|
253
|
+
// Registration modules and application initialization are observable side effects.
|
|
254
|
+
treeshake: { moduleSideEffects: true },
|
|
255
|
+
});
|
|
256
|
+
try {
|
|
257
|
+
await bundle.write({
|
|
258
|
+
file: outFile,
|
|
259
|
+
format: 'esm',
|
|
260
|
+
codeSplitting: false,
|
|
261
|
+
plugins: [
|
|
262
|
+
{
|
|
263
|
+
name: 'di-framework-async-context',
|
|
264
|
+
async renderChunk(code) {
|
|
265
|
+
// Transform async functions only. Broad ES2016 lowering changes the
|
|
266
|
+
// prototype of async generators used by unenv's EventEmitter.
|
|
267
|
+
const transformed = await transformAsync(code, {
|
|
268
|
+
babelrc: false,
|
|
269
|
+
configFile: false,
|
|
270
|
+
sourceType: 'module',
|
|
271
|
+
plugins: [lowerForAwait, asyncToGenerator],
|
|
272
|
+
});
|
|
273
|
+
if (!transformed?.code)
|
|
274
|
+
throw new Error('Failed to lower guest async functions');
|
|
275
|
+
return { code: transformed.code, map: null };
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
finally {
|
|
282
|
+
await bundle.close();
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
jcoCliPath: () => findJcoEntry(packageRoot) ??
|
|
286
|
+
join(dirname(fileURLToPath(import.meta.resolve('@bytecodealliance/jco'))), 'jco.js'),
|
|
287
|
+
componentizeQjsPath: () => resolveComponentizeQjsPath(process.env, findInstalledComponentizeQjsCli(), nativeComponentizeQjsOnPath()),
|
|
288
|
+
nodeBinaryPath: () => Bun.which('node') ?? undefined,
|
|
289
|
+
wasmtimeBinaryPath: () => Bun.which('wasmtime') ?? undefined,
|
|
290
|
+
washBinaryPath: () => Bun.which('wash') ?? undefined,
|
|
291
|
+
// Assets ship transpiled under dist/assets; src and dist are siblings of it.
|
|
292
|
+
assetsDirectory: () => join(packageRoot, 'dist', 'assets'),
|
|
293
|
+
resolveFromProject: (projectRoot, specifier) => {
|
|
294
|
+
try {
|
|
295
|
+
return createRequire(join(projectRoot, 'package.json')).resolve(specifier);
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
env: process.env,
|
|
302
|
+
cwd: () => process.cwd(),
|
|
303
|
+
};
|
package/dist/destroy.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { parseAppCommandArgs } from './args.js';
|
|
2
|
+
import { DEFAULT_DEPS } from './deps.js';
|
|
3
|
+
import { resolveApplication } from './discovery.js';
|
|
4
|
+
import { loadDeployManifest } from './manifest.js';
|
|
5
|
+
import { resolveConnection, resolveTarget } from './target.js';
|
|
6
|
+
import { deleteWorkload, deploymentResourceName } from './workload.js';
|
|
7
|
+
export async function runWasmcloudDestroy(args, io, deps = DEFAULT_DEPS) {
|
|
8
|
+
const options = parseAppCommandArgs(args, 'platform destroy');
|
|
9
|
+
const manifest = loadDeployManifest(deps.cwd(), deps.env);
|
|
10
|
+
const target = resolveTarget(manifest, options.target);
|
|
11
|
+
const project = resolveApplication(deps.cwd(), options.name, manifest.workspaceRoot, manifest.discovery);
|
|
12
|
+
const connection = await resolveConnection(target, manifest.workspaceRoot, manifest.path, deps);
|
|
13
|
+
await deleteWorkload(project, connection, io, deps);
|
|
14
|
+
const service = deploymentResourceName(project);
|
|
15
|
+
return {
|
|
16
|
+
data: {
|
|
17
|
+
application: project.applicationName,
|
|
18
|
+
target: connection.target,
|
|
19
|
+
namespace: connection.namespace,
|
|
20
|
+
service,
|
|
21
|
+
},
|
|
22
|
+
text: `Removed ${project.applicationName} from ${connection.target} (namespace ${connection.namespace}).`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WasmcloudDeps } from './deps.js';
|
|
2
|
+
export declare const DEV_RUNNER_ENV = "DI_FRAMEWORK_WASMCLOUD_DEV_RUNNER";
|
|
3
|
+
export type DevRunnerKind = 'wasmtime' | 'wash' | 'jco';
|
|
4
|
+
export type DevServeTarget = {
|
|
5
|
+
componentPath: string;
|
|
6
|
+
host: string;
|
|
7
|
+
port: string;
|
|
8
|
+
washConfigPath?: string;
|
|
9
|
+
tls?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type ResolvedDevRunner = {
|
|
12
|
+
kind: DevRunnerKind;
|
|
13
|
+
command: string;
|
|
14
|
+
args(target: DevServeTarget): string[];
|
|
15
|
+
};
|
|
16
|
+
export type DevRunnerOptions = {
|
|
17
|
+
/** Prefer wash: wasmtime and jco cannot host `wasmcloud:*` imports. */
|
|
18
|
+
wasmCloudHost?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** True when the guest imports a wasmCloud host interface, not only WASI. */
|
|
21
|
+
export declare function requiresWasmCloudHost(requirements: readonly {
|
|
22
|
+
package: string;
|
|
23
|
+
}[]): boolean;
|
|
24
|
+
export declare function resolveDevRunner(deps: WasmcloudDeps, options?: DevRunnerOptions): ResolvedDevRunner;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { CommandFailure } from '@di-framework/cli-extension';
|
|
2
|
+
export const DEV_RUNNER_ENV = 'DI_FRAMEWORK_WASMCLOUD_DEV_RUNNER';
|
|
3
|
+
/** True when the guest imports a wasmCloud host interface, not only WASI. */
|
|
4
|
+
export function requiresWasmCloudHost(requirements) {
|
|
5
|
+
return requirements.some((requirement) => requirement.package.startsWith('wasmcloud:'));
|
|
6
|
+
}
|
|
7
|
+
const KINDS = ['wasmtime', 'wash', 'jco'];
|
|
8
|
+
function binaryFor(kind, deps) {
|
|
9
|
+
switch (kind) {
|
|
10
|
+
case 'wasmtime':
|
|
11
|
+
return deps.wasmtimeBinaryPath();
|
|
12
|
+
case 'wash':
|
|
13
|
+
return deps.washBinaryPath();
|
|
14
|
+
case 'jco':
|
|
15
|
+
return deps.nodeBinaryPath();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function argsFor(kind, deps, target) {
|
|
19
|
+
switch (kind) {
|
|
20
|
+
case 'wasmtime':
|
|
21
|
+
// qjs guests import wasi:cli@0.2.x; WASI 0.3 HTTP is off unless -S p3 is set.
|
|
22
|
+
// `-S config` hosts unlabeled wasi:config@0.2.0-rc.1 (sync) locally.
|
|
23
|
+
return [
|
|
24
|
+
'serve',
|
|
25
|
+
'-S',
|
|
26
|
+
'cli',
|
|
27
|
+
'-S',
|
|
28
|
+
'p3',
|
|
29
|
+
'-S',
|
|
30
|
+
'config',
|
|
31
|
+
...(target.tls ? ['-S', 'tls=y,inherit-network=y,allow-ip-name-lookup=y'] : []),
|
|
32
|
+
'--addr',
|
|
33
|
+
`${target.host}:${target.port}`,
|
|
34
|
+
target.componentPath,
|
|
35
|
+
];
|
|
36
|
+
case 'wash': {
|
|
37
|
+
// wash 2.5.x has no --address flag; address and hostInterfaces live in config.
|
|
38
|
+
const args = ['dev'];
|
|
39
|
+
if (target.washConfigPath !== undefined) {
|
|
40
|
+
args.push('--user-config', target.washConfigPath);
|
|
41
|
+
}
|
|
42
|
+
return args;
|
|
43
|
+
}
|
|
44
|
+
case 'jco':
|
|
45
|
+
return [
|
|
46
|
+
deps.jcoCliPath(),
|
|
47
|
+
'serve',
|
|
48
|
+
target.componentPath,
|
|
49
|
+
'--host',
|
|
50
|
+
target.host,
|
|
51
|
+
'--port',
|
|
52
|
+
target.port,
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function resolveDevRunner(deps, options = {}) {
|
|
57
|
+
const requested = deps.env[DEV_RUNNER_ENV]?.trim();
|
|
58
|
+
if (requested !== undefined && requested !== '') {
|
|
59
|
+
if (!KINDS.includes(requested)) {
|
|
60
|
+
throw new CommandFailure('WASMCLOUD_DEV_RUNNER_UNKNOWN', `Unknown ${DEV_RUNNER_ENV} value "${requested}". Expected wasmtime, wash, or jco.`, 2, { runner: requested });
|
|
61
|
+
}
|
|
62
|
+
const kind = requested;
|
|
63
|
+
const command = binaryFor(kind, deps);
|
|
64
|
+
if (command === undefined) {
|
|
65
|
+
throw new CommandFailure('WASMCLOUD_DEV_RUNNER_REQUIRED', `${kind} is required to serve the component locally; install it and make sure it is on PATH`, 3, { tool: kind });
|
|
66
|
+
}
|
|
67
|
+
return { kind, command, args: (target) => argsFor(kind, deps, target) };
|
|
68
|
+
}
|
|
69
|
+
if (options.wasmCloudHost === true) {
|
|
70
|
+
const command = binaryFor('wash', deps);
|
|
71
|
+
if (command === undefined) {
|
|
72
|
+
throw new CommandFailure('WASMCLOUD_DEV_RUNNER_REQUIRED', 'wash is required to serve a component that imports wasmCloud host interfaces; install wash or set DI_FRAMEWORK_WASMCLOUD_DEV_RUNNER', 3, { tool: 'wash' });
|
|
73
|
+
}
|
|
74
|
+
return { kind: 'wash', command, args: (target) => argsFor('wash', deps, target) };
|
|
75
|
+
}
|
|
76
|
+
for (const kind of KINDS) {
|
|
77
|
+
const command = binaryFor(kind, deps);
|
|
78
|
+
if (command === undefined)
|
|
79
|
+
continue;
|
|
80
|
+
return { kind, command, args: (target) => argsFor(kind, deps, target) };
|
|
81
|
+
}
|
|
82
|
+
throw new CommandFailure('WASMCLOUD_DEV_RUNNER_REQUIRED', 'A local component runner is required (wasmtime 46+, wash, or jco); install one and make sure it is on PATH', 3, { tool: 'dev-runner' });
|
|
83
|
+
}
|
package/dist/dev.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type CliIo, type CommandResult } from '@di-framework/cli-extension';
|
|
2
|
+
import { type WasmcloudDeps } from './deps.js';
|
|
3
|
+
export type DevOptions = {
|
|
4
|
+
host: string;
|
|
5
|
+
port: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function parseDevArgs(args: readonly string[]): DevOptions;
|
|
8
|
+
export declare function runWasmcloudDev(args: readonly string[], io: CliIo, deps?: WasmcloudDeps): Promise<CommandResult>;
|
package/dist/dev.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { CommandFailure } from '@di-framework/cli-extension';
|
|
4
|
+
import { discoverBindings } from './bindings.js';
|
|
5
|
+
import { buildComponent, requirementsForProject } from './build.js';
|
|
6
|
+
import { DEFAULT_DEPS } from './deps.js';
|
|
7
|
+
import { requiresWasmCloudHost, resolveDevRunner } from './dev-runner.js';
|
|
8
|
+
import { loadProject } from './project.js';
|
|
9
|
+
import { invalidUsage, readOptionValue, toolFailed } from './support.js';
|
|
10
|
+
import { writeWashDevConfig } from './wash-dev.js';
|
|
11
|
+
export function parseDevArgs(args) {
|
|
12
|
+
let host;
|
|
13
|
+
let port;
|
|
14
|
+
for (let position = 0; position < args.length; position++) {
|
|
15
|
+
const token = args[position] ?? '';
|
|
16
|
+
switch (token) {
|
|
17
|
+
case '--host':
|
|
18
|
+
if (host !== undefined)
|
|
19
|
+
invalidUsage(`Option may be provided only once: ${token}`, token);
|
|
20
|
+
host = readOptionValue(args, ++position, token);
|
|
21
|
+
break;
|
|
22
|
+
case '--port':
|
|
23
|
+
if (port !== undefined)
|
|
24
|
+
invalidUsage(`Option may be provided only once: ${token}`, token);
|
|
25
|
+
port = readOptionValue(args, ++position, token);
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
invalidUsage(`Unknown option or argument: ${token}`, token);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { host: host ?? '127.0.0.1', port: port ?? '8000' };
|
|
32
|
+
}
|
|
33
|
+
export async function runWasmcloudDev(args, io, deps = DEFAULT_DEPS) {
|
|
34
|
+
const options = parseDevArgs(args);
|
|
35
|
+
const project = loadProject(deps.cwd());
|
|
36
|
+
await buildComponent(project, io, deps);
|
|
37
|
+
const lockPath = join(project.projectRoot, '.di-framework', 'wit.lock.json');
|
|
38
|
+
let tls;
|
|
39
|
+
let wasmCloudHost;
|
|
40
|
+
try {
|
|
41
|
+
const lock = JSON.parse(readFileSync(lockPath, 'utf8'));
|
|
42
|
+
tls = lock.requirements.some((requirement) => requirement.package === 'wasi:tls');
|
|
43
|
+
wasmCloudHost = requiresWasmCloudHost(lock.requirements);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw new CommandFailure('WASMCLOUD_WIT_LOCK_INVALID', `Cannot read generated WIT requirements from ${lockPath}. Rerun platform build before starting the dev server.`, 3, { path: lockPath, cause: String(error) });
|
|
47
|
+
}
|
|
48
|
+
const runner = resolveDevRunner(deps, { wasmCloudHost });
|
|
49
|
+
const washConfigPath = runner.kind === 'wash'
|
|
50
|
+
? writeWashDevConfig(project, requirementsForProject(project, deps), discoverBindings(project, deps), {
|
|
51
|
+
host: options.host,
|
|
52
|
+
port: options.port,
|
|
53
|
+
postgresUrl: deps.env.WASMCLOUD_POSTGRES_URL,
|
|
54
|
+
})
|
|
55
|
+
: undefined;
|
|
56
|
+
io.stdout.write(`Serving on http://${options.host}:${options.port} (${runner.kind})\n`);
|
|
57
|
+
const served = await deps.runner(runner.command, runner.args({
|
|
58
|
+
componentPath: project.outputPath,
|
|
59
|
+
host: options.host,
|
|
60
|
+
port: options.port,
|
|
61
|
+
washConfigPath,
|
|
62
|
+
tls,
|
|
63
|
+
}), { cwd: project.projectRoot });
|
|
64
|
+
if (served.exitCode !== 0) {
|
|
65
|
+
throw toolFailed(`${runner.kind} serve`, served.exitCode);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
data: {
|
|
69
|
+
application: project.applicationName,
|
|
70
|
+
host: options.host,
|
|
71
|
+
port: options.port,
|
|
72
|
+
runner: runner.kind,
|
|
73
|
+
},
|
|
74
|
+
text: 'Dev server stopped.',
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import type { DiscoveryConfig } from './manifest.js';
|
|
3
|
+
import { type WasmcloudProject } from './project.js';
|
|
4
|
+
export type DiscoveredProjects = Map<string, WasmcloudProject>;
|
|
5
|
+
export declare function discoverProjects(workspaceRoot: string, discovery: DiscoveryConfig): DiscoveredProjects;
|
|
6
|
+
export declare function resolveApplication(startDirectory: string, name: string | undefined, workspaceRoot: string, discovery: DiscoveryConfig): WasmcloudProject;
|
|
7
|
+
export declare function findConfigFiles(workspaceRoot: string, discovery: DiscoveryConfig): string[];
|
|
8
|
+
export declare function readDirents(directory: string): fs.Dirent[];
|
|
9
|
+
export declare function statLinkTarget(path: string): {
|
|
10
|
+
isDirectory: boolean;
|
|
11
|
+
isFile: boolean;
|
|
12
|
+
} | undefined;
|
|
13
|
+
export declare function isIncluded(relativeFile: string, patterns: readonly string[]): boolean;
|
|
14
|
+
export declare function isExcluded(relativePathValue: string, patterns: readonly string[]): boolean;
|
|
15
|
+
export declare function matchGlob(path: string, pattern: string): boolean;
|