@di-framework/cli-plugin-platform 6.0.8 → 6.1.0
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/assets/sqlite/BUILD-INFO.txt +1 -1
- package/dist/build.d.ts +1 -1
- package/dist/build.js +54 -12
- package/dist/components.d.ts +52 -0
- package/dist/components.js +153 -0
- package/dist/deps.d.ts +4 -0
- package/dist/deps.js +7 -2
- package/package.json +1 -1
package/dist/build.d.ts
CHANGED
|
@@ -27,5 +27,5 @@ export declare function buildComponent(project: WasmcloudProject, io: CliIo, dep
|
|
|
27
27
|
* WIT lock, OCI configuration, pinned build profile, and (when composed) the
|
|
28
28
|
* pinned SQLite provider artifact — not the final componentize output bytes.
|
|
29
29
|
*/
|
|
30
|
-
export declare function canonicalBuildDigest(bundledJavaScript: string, witDirectory: string, ociConfig: string, lock: WitLock, profile?: string, sqliteProvider?: string): string;
|
|
30
|
+
export declare function canonicalBuildDigest(bundledJavaScript: string, witDirectory: string, ociConfig: string, lock: WitLock, profile?: string, sqliteProvider?: string, composedProviders?: readonly string[]): string;
|
|
31
31
|
export declare function runWasmcloudBuild(args: readonly string[], io: CliIo, deps?: WasmcloudDeps): Promise<CommandResult>;
|
package/dist/build.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
|
|
3
|
-
import { dirname, join, relative, sep } from 'node:path';
|
|
3
|
+
import { basename, dirname, join, relative, sep } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
import { CommandFailure } from '@di-framework/cli-extension';
|
|
6
6
|
import { discoverActors, renderActorsModule } from './actors.js';
|
|
7
7
|
import { discoverBindings, requirementsFromBindings } from './bindings.js';
|
|
8
|
+
import { copyProviderWit, discoverComponentProviders, providerNamespaces, providerRequirementsFromJavaScript, providersToCompose, } from './components.js';
|
|
8
9
|
import { discoverScheduledJobs, renderCronAdapterModule, renderCronInvokerModule } from './cron.js';
|
|
9
10
|
import { DEFAULT_DEPS } from './deps.js';
|
|
10
11
|
import { renderGuestsModule } from './guests.js';
|
|
@@ -110,6 +111,29 @@ async function composeSqliteProvider(project, deps, io, namedImports = false) {
|
|
|
110
111
|
if (!existsSync(provider)) {
|
|
111
112
|
throw new CommandFailure('WASMCLOUD_SQLITE_PROVIDER_MISSING', `Packaged SQLite provider missing at ${provider}`, 3, { application: project.applicationName });
|
|
112
113
|
}
|
|
114
|
+
await composeProvider(project, deps, io, {
|
|
115
|
+
label: 'di-framework:sqlite',
|
|
116
|
+
wasm: provider,
|
|
117
|
+
namedImports,
|
|
118
|
+
failureCode: 'WASMCLOUD_SQLITE_COMPOSE_FAILED',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async function composeComponentProvider(project, deps, io, provider, namedImports = false) {
|
|
122
|
+
if (!existsSync(provider.wasm)) {
|
|
123
|
+
throw new CommandFailure('WASMCLOUD_COMPONENT_PROVIDER_MISSING', `Dependency ${provider.dependency} declares component ${provider.wasm}, which does not exist`, 3, { application: project.applicationName, dependency: provider.dependency });
|
|
124
|
+
}
|
|
125
|
+
await composeProvider(project, deps, io, {
|
|
126
|
+
label: `${provider.package}@${provider.version} (${provider.dependency})`,
|
|
127
|
+
wasm: provider.wasm,
|
|
128
|
+
namedImports,
|
|
129
|
+
failureCode: 'WASMCLOUD_COMPONENT_COMPOSE_FAILED',
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Plugs one provider component into the built guest: `wac plug`, or the
|
|
134
|
+
* componentize-qjs composer when the guest has named imports to preserve.
|
|
135
|
+
*/
|
|
136
|
+
async function composeProvider(project, deps, io, options) {
|
|
113
137
|
const composed = `${project.outputPath}.composed`;
|
|
114
138
|
const toolsBin = sqliteToolsBin();
|
|
115
139
|
const envPath = [toolsBin, process.env.PATH ?? ''].filter(Boolean).join(':');
|
|
@@ -118,15 +142,15 @@ async function composeSqliteProvider(project, deps, io, namedImports = false) {
|
|
|
118
142
|
: toolsBin
|
|
119
143
|
? join(toolsBin, 'wac')
|
|
120
144
|
: 'wac';
|
|
121
|
-
io.stdout.write(
|
|
122
|
-
const compiler = namedImports ? deps.componentizeQjsPath() : undefined;
|
|
123
|
-
if (namedImports && !compiler)
|
|
145
|
+
io.stdout.write(`Composing ${options.label} provider...\n`);
|
|
146
|
+
const compiler = options.namedImports ? deps.componentizeQjsPath() : undefined;
|
|
147
|
+
if (options.namedImports && !compiler)
|
|
124
148
|
throw new CommandFailure('WASMCLOUD_COMPILER_REQUIRED', 'Managed PostgreSQL requires componentize-qjs 0.4.4-di.3 or newer', 3);
|
|
125
149
|
const result = await deps.runCaptured(compiler ?? wac, compiler
|
|
126
|
-
? ['compose', project.outputPath, '--definition',
|
|
127
|
-
: ['plug', '--plug',
|
|
150
|
+
? ['compose', project.outputPath, '--definition', options.wasm, '-o', composed]
|
|
151
|
+
: ['plug', '--plug', options.wasm, project.outputPath, '-o', composed], { cwd: project.projectRoot, env: { ...process.env, PATH: envPath } });
|
|
128
152
|
if (result.exitCode !== 0) {
|
|
129
|
-
throw new CommandFailure(
|
|
153
|
+
throw new CommandFailure(options.failureCode, `Composition of ${options.label} failed: ${result.stderr || result.stdout}`, 3, { application: project.applicationName, exitCode: result.exitCode });
|
|
130
154
|
}
|
|
131
155
|
writeFileSync(project.outputPath, readFileSync(composed));
|
|
132
156
|
rmSync(composed, { force: true });
|
|
@@ -178,12 +202,14 @@ export async function buildComponent(project, io, deps, options = {}) {
|
|
|
178
202
|
}
|
|
179
203
|
}
|
|
180
204
|
}
|
|
205
|
+
const providers = discoverComponentProviders(project.projectRoot);
|
|
181
206
|
rmSync(generatedDirectory, { recursive: true, force: true });
|
|
182
207
|
mkdirSync(join(generatedWit, 'deps'), { recursive: true });
|
|
183
208
|
mkdirSync(dirname(project.outputPath), { recursive: true });
|
|
184
209
|
cpSync(join(deps.assetsDirectory(), 'wit', 'deps'), join(generatedWit, 'deps'), {
|
|
185
210
|
recursive: true,
|
|
186
211
|
});
|
|
212
|
+
copyProviderWit(providers, join(generatedWit, 'deps'));
|
|
187
213
|
writeFileSync(join(generatedWit, 'world.wit'), renderWorldWit(project.witName, project.version, requirements));
|
|
188
214
|
let lock = buildWitLock(requirements, join(generatedWit, 'deps'));
|
|
189
215
|
writeFileSync(join(generatedDirectory, 'wit.lock.json'), `${JSON.stringify(lock, null, 2)}\n`);
|
|
@@ -238,12 +264,17 @@ export async function buildComponent(project, io, deps, options = {}) {
|
|
|
238
264
|
projectRoot: project.projectRoot,
|
|
239
265
|
// `"logs": false` wins over the caller: the guest keeps the noop console.
|
|
240
266
|
guestLogging: project.logs === false ? false : options.guestLogging,
|
|
267
|
+
externalNamespaces: providerNamespaces(providers),
|
|
241
268
|
});
|
|
242
269
|
}
|
|
243
270
|
catch (error) {
|
|
244
271
|
throw new CommandFailure('WASMCLOUD_BUILD_FAILED', `Bundling failed: ${error instanceof Error ? error.message : String(error)}`, 3, { entry: relative(project.projectRoot, project.entryPath) });
|
|
245
272
|
}
|
|
246
|
-
const
|
|
273
|
+
const bundledSource = readFileSync(bundledJavaScript, 'utf8');
|
|
274
|
+
const runtimeRequirements = [
|
|
275
|
+
...runtimeRequirementsFromJavaScript(bundledSource),
|
|
276
|
+
...providerRequirementsFromJavaScript(bundledSource, providers),
|
|
277
|
+
];
|
|
247
278
|
const finalRequirements = [...requirements, ...runtimeRequirements];
|
|
248
279
|
if (runtimeRequirements.length > 0) {
|
|
249
280
|
writeFileSync(join(generatedWit, 'world.wit'), renderWorldWit(project.witName, project.version, finalRequirements));
|
|
@@ -255,13 +286,21 @@ export async function buildComponent(project, io, deps, options = {}) {
|
|
|
255
286
|
throw toolFailed(componentize.tool, componentize.exitCode);
|
|
256
287
|
}
|
|
257
288
|
const needsSqliteCompose = finalRequirements.some((requirement) => requirement.package === 'di-framework:sqlite' && requirement.direction === 'import');
|
|
289
|
+
const namedImports = finalRequirements.some((r) => r.namedImport);
|
|
258
290
|
if (needsSqliteCompose) {
|
|
259
|
-
await composeSqliteProvider(project, deps, io,
|
|
291
|
+
await composeSqliteProvider(project, deps, io, namedImports);
|
|
260
292
|
}
|
|
261
|
-
|
|
293
|
+
const composedProviders = providersToCompose(providers, finalRequirements);
|
|
294
|
+
for (const provider of composedProviders) {
|
|
295
|
+
await composeComponentProvider(project, deps, io, provider, namedImports);
|
|
296
|
+
}
|
|
297
|
+
const composedPackages = new Set(composedProviders.map((provider) => provider.package));
|
|
298
|
+
await inspectComponentImports(project, finalRequirements.filter((requirement) => !(requirement.direction === 'import' &&
|
|
299
|
+
(requirement.package === 'di-framework:sqlite' ||
|
|
300
|
+
composedPackages.has(requirement.package)))), deps);
|
|
262
301
|
const deploymentDigest = canonicalBuildDigest(bundledJavaScript, generatedWit, join(generatedDirectory, 'oci-config.json'), lock, profile, needsSqliteCompose
|
|
263
302
|
? join(deps.assetsDirectory(), 'sqlite', 'di-framework-sqlite.wasm')
|
|
264
|
-
: undefined);
|
|
303
|
+
: undefined, composedProviders.map((provider) => provider.wasm));
|
|
265
304
|
const artifactDigest = digestBytes(readFileSync(project.outputPath));
|
|
266
305
|
const summary = {
|
|
267
306
|
application: project.applicationName,
|
|
@@ -283,7 +322,7 @@ export async function buildComponent(project, io, deps, options = {}) {
|
|
|
283
322
|
* WIT lock, OCI configuration, pinned build profile, and (when composed) the
|
|
284
323
|
* pinned SQLite provider artifact — not the final componentize output bytes.
|
|
285
324
|
*/
|
|
286
|
-
export function canonicalBuildDigest(bundledJavaScript, witDirectory, ociConfig, lock, profile = BUILD_PROFILE_NAME, sqliteProvider) {
|
|
325
|
+
export function canonicalBuildDigest(bundledJavaScript, witDirectory, ociConfig, lock, profile = BUILD_PROFILE_NAME, sqliteProvider, composedProviders = []) {
|
|
287
326
|
const hash = createHash('sha256');
|
|
288
327
|
addDigestEntry(hash, 'profile', `${profile}\n${COMPONENT_MODEL}`);
|
|
289
328
|
addDigestEntry(hash, 'wit-lock', JSON.stringify(lock));
|
|
@@ -296,6 +335,9 @@ export function canonicalBuildDigest(bundledJavaScript, witDirectory, ociConfig,
|
|
|
296
335
|
if (sqliteProvider !== undefined) {
|
|
297
336
|
addDigestEntry(hash, 'sqlite-provider', readFileSync(sqliteProvider));
|
|
298
337
|
}
|
|
338
|
+
for (const provider of composedProviders) {
|
|
339
|
+
addDigestEntry(hash, `component-provider/${basename(provider)}`, readFileSync(provider));
|
|
340
|
+
}
|
|
299
341
|
return hash.digest('hex');
|
|
300
342
|
}
|
|
301
343
|
function addDigestEntry(hash, name, content) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type WitRequirement } from './wit.js';
|
|
2
|
+
/**
|
|
3
|
+
* A dependency that ships a WebAssembly component the guest imports by WIT
|
|
4
|
+
* name. Declared in the dependency's package.json:
|
|
5
|
+
*
|
|
6
|
+
* ```json
|
|
7
|
+
* "component": {
|
|
8
|
+
* "package": "pqc-subtle:crypto@0.1.0",
|
|
9
|
+
* "wasm": "component/pqc-subtle.wasm",
|
|
10
|
+
* "wit": "component/wit",
|
|
11
|
+
* "interfaces": ["ml-kem", "ml-dsa", "argon2"]
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* The build copies the WIT into the guest world's deps, keeps the package's
|
|
16
|
+
* specifiers external in the bundle, adds the interfaces the bundle imports to
|
|
17
|
+
* the world, and plugs the binary in after componentize. Only direct
|
|
18
|
+
* dependencies of the project are considered.
|
|
19
|
+
*/
|
|
20
|
+
export type ComponentProvider = {
|
|
21
|
+
/** npm package name, for messages and the requirement source. */
|
|
22
|
+
dependency: string;
|
|
23
|
+
/** WIT package id, e.g. `pqc-subtle:crypto`. */
|
|
24
|
+
package: string;
|
|
25
|
+
version: string;
|
|
26
|
+
/** Interfaces the package exports, from the manifest or parsed from the WIT. */
|
|
27
|
+
interfaces: string[];
|
|
28
|
+
/** Absolute path of the component binary. */
|
|
29
|
+
wasm: string;
|
|
30
|
+
/** Absolute path of the WIT directory. */
|
|
31
|
+
wit: string;
|
|
32
|
+
};
|
|
33
|
+
/** Component providers among the project's direct dependencies, by dependency name. */
|
|
34
|
+
export declare function discoverComponentProviders(projectRoot: string): ComponentProvider[];
|
|
35
|
+
/** WIT namespaces whose module specifiers the bundler must leave external. */
|
|
36
|
+
export declare function providerNamespaces(providers: readonly ComponentProvider[]): string[];
|
|
37
|
+
/** Directory name under `wit/deps` for a provider's package. */
|
|
38
|
+
export declare function providerDepsDirectory(provider: ComponentProvider): string;
|
|
39
|
+
/**
|
|
40
|
+
* Copies each provider's WIT into the generated deps directory. A single file
|
|
41
|
+
* is written as `package.wit`, which is what the lock reads; several files are
|
|
42
|
+
* copied by name.
|
|
43
|
+
*/
|
|
44
|
+
export declare function copyProviderWit(providers: readonly ComponentProvider[], depsDirectory: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Import requirements for the provider interfaces the bundled JavaScript
|
|
47
|
+
* references. A `types` interface comes along whenever any sibling does, as
|
|
48
|
+
* the functions' signatures use it.
|
|
49
|
+
*/
|
|
50
|
+
export declare function providerRequirementsFromJavaScript(source: string, providers: readonly ComponentProvider[]): WitRequirement[];
|
|
51
|
+
/** Providers whose package the requirements import, in discovery order. */
|
|
52
|
+
export declare function providersToCompose(providers: readonly ComponentProvider[], requirements: readonly WitRequirement[]): ComponentProvider[];
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
3
|
+
import { parsePackageId } from './wit.js';
|
|
4
|
+
function readManifest(path) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** `node_modules/<name>/package.json`, searching upward from `from` (workspaces hoist). */
|
|
13
|
+
function findDependencyManifest(name, from) {
|
|
14
|
+
const candidates = [];
|
|
15
|
+
for (let directory = resolve(from);; directory = dirname(directory)) {
|
|
16
|
+
candidates.push(join(directory, 'node_modules', name, 'package.json'));
|
|
17
|
+
if (dirname(directory) === directory)
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
return candidates.find((candidate) => existsSync(candidate));
|
|
21
|
+
}
|
|
22
|
+
function interfacesFromWit(witDirectory) {
|
|
23
|
+
const names = [];
|
|
24
|
+
for (const file of witFiles(witDirectory)) {
|
|
25
|
+
for (const match of readFileSync(file, 'utf8').matchAll(/^\s*interface\s+([a-z][a-z0-9-]*)/gm)) {
|
|
26
|
+
const name = match[1] ?? '';
|
|
27
|
+
if (name && !names.includes(name))
|
|
28
|
+
names.push(name);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return names;
|
|
32
|
+
}
|
|
33
|
+
function witFiles(witDirectory) {
|
|
34
|
+
if (!existsSync(witDirectory))
|
|
35
|
+
return [];
|
|
36
|
+
return readdirSync(witDirectory)
|
|
37
|
+
.filter((entry) => entry.endsWith('.wit'))
|
|
38
|
+
.sort()
|
|
39
|
+
.map((entry) => join(witDirectory, entry));
|
|
40
|
+
}
|
|
41
|
+
function providerFromManifest(dependency, manifestPath, manifest) {
|
|
42
|
+
const declared = manifest.component;
|
|
43
|
+
if (declared === undefined ||
|
|
44
|
+
typeof declared.package !== 'string' ||
|
|
45
|
+
typeof declared.wasm !== 'string' ||
|
|
46
|
+
typeof declared.wit !== 'string') {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const packageDirectory = dirname(manifestPath);
|
|
50
|
+
const at = declared.package.lastIndexOf('@');
|
|
51
|
+
if (at <= 0) {
|
|
52
|
+
throw new Error(`Dependency ${dependency} declares component package "${declared.package}" without a version`);
|
|
53
|
+
}
|
|
54
|
+
const id = declared.package.slice(0, at);
|
|
55
|
+
parsePackageId(id);
|
|
56
|
+
const absolute = (path) => (isAbsolute(path) ? path : join(packageDirectory, path));
|
|
57
|
+
const wit = absolute(declared.wit);
|
|
58
|
+
const interfaces = Array.isArray(declared.interfaces)
|
|
59
|
+
? declared.interfaces.filter((entry) => typeof entry === 'string')
|
|
60
|
+
: interfacesFromWit(wit);
|
|
61
|
+
return {
|
|
62
|
+
dependency,
|
|
63
|
+
package: id,
|
|
64
|
+
version: declared.package.slice(at + 1),
|
|
65
|
+
interfaces,
|
|
66
|
+
wasm: absolute(declared.wasm),
|
|
67
|
+
wit,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Component providers among the project's direct dependencies, by dependency name. */
|
|
71
|
+
export function discoverComponentProviders(projectRoot) {
|
|
72
|
+
const manifest = readManifest(join(projectRoot, 'package.json'));
|
|
73
|
+
if (manifest === undefined)
|
|
74
|
+
return [];
|
|
75
|
+
const names = Object.keys({
|
|
76
|
+
...(manifest.dependencies ?? {}),
|
|
77
|
+
...(manifest.optionalDependencies ?? {}),
|
|
78
|
+
}).sort();
|
|
79
|
+
const providers = [];
|
|
80
|
+
for (const name of names) {
|
|
81
|
+
const path = findDependencyManifest(name, projectRoot);
|
|
82
|
+
if (path === undefined)
|
|
83
|
+
continue;
|
|
84
|
+
const dependencyManifest = readManifest(path);
|
|
85
|
+
if (dependencyManifest === undefined)
|
|
86
|
+
continue;
|
|
87
|
+
const provider = providerFromManifest(name, path, dependencyManifest);
|
|
88
|
+
if (provider !== undefined)
|
|
89
|
+
providers.push(provider);
|
|
90
|
+
}
|
|
91
|
+
return providers;
|
|
92
|
+
}
|
|
93
|
+
/** WIT namespaces whose module specifiers the bundler must leave external. */
|
|
94
|
+
export function providerNamespaces(providers) {
|
|
95
|
+
const namespaces = new Set();
|
|
96
|
+
for (const provider of providers)
|
|
97
|
+
namespaces.add(parsePackageId(provider.package).namespace);
|
|
98
|
+
return [...namespaces].sort();
|
|
99
|
+
}
|
|
100
|
+
/** Directory name under `wit/deps` for a provider's package. */
|
|
101
|
+
export function providerDepsDirectory(provider) {
|
|
102
|
+
const { namespace, name } = parsePackageId(provider.package);
|
|
103
|
+
return `${namespace}-${name}`;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Copies each provider's WIT into the generated deps directory. A single file
|
|
107
|
+
* is written as `package.wit`, which is what the lock reads; several files are
|
|
108
|
+
* copied by name.
|
|
109
|
+
*/
|
|
110
|
+
export function copyProviderWit(providers, depsDirectory) {
|
|
111
|
+
for (const provider of providers) {
|
|
112
|
+
const files = witFiles(provider.wit);
|
|
113
|
+
if (files.length === 0) {
|
|
114
|
+
throw new Error(`Dependency ${provider.dependency} declares WIT at ${provider.wit} but no .wit file is there`);
|
|
115
|
+
}
|
|
116
|
+
const target = join(depsDirectory, providerDepsDirectory(provider));
|
|
117
|
+
mkdirSync(target, { recursive: true });
|
|
118
|
+
if (files.length === 1) {
|
|
119
|
+
writeFileSync(join(target, 'package.wit'), readFileSync(files[0]));
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
for (const file of files)
|
|
123
|
+
writeFileSync(join(target, file.slice(provider.wit.length + 1)), readFileSync(file));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Import requirements for the provider interfaces the bundled JavaScript
|
|
128
|
+
* references. A `types` interface comes along whenever any sibling does, as
|
|
129
|
+
* the functions' signatures use it.
|
|
130
|
+
*/
|
|
131
|
+
export function providerRequirementsFromJavaScript(source, providers) {
|
|
132
|
+
const requirements = [];
|
|
133
|
+
for (const provider of providers) {
|
|
134
|
+
const used = provider.interfaces.filter((iface) => source.includes(`${provider.package}/${iface}@${provider.version}`));
|
|
135
|
+
if (used.length === 0)
|
|
136
|
+
continue;
|
|
137
|
+
const interfaces = provider.interfaces.includes('types') && !used.includes('types') ? ['types', ...used] : used;
|
|
138
|
+
requirements.push({
|
|
139
|
+
package: provider.package,
|
|
140
|
+
version: provider.version,
|
|
141
|
+
interfaces,
|
|
142
|
+
direction: 'import',
|
|
143
|
+
source: `component:${provider.dependency}`,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return requirements;
|
|
147
|
+
}
|
|
148
|
+
/** Providers whose package the requirements import, in discovery order. */
|
|
149
|
+
export function providersToCompose(providers, requirements) {
|
|
150
|
+
return providers.filter((provider) => requirements.some((requirement) => requirement.direction === 'import' &&
|
|
151
|
+
requirement.package === provider.package &&
|
|
152
|
+
requirement.version === provider.version));
|
|
153
|
+
}
|
package/dist/deps.d.ts
CHANGED
|
@@ -28,10 +28,14 @@ export type BundleOptions = {
|
|
|
28
28
|
files?: Record<string, string>;
|
|
29
29
|
env?: Record<string, string | undefined>;
|
|
30
30
|
cwd?: string;
|
|
31
|
+
/** WIT namespaces of component providers whose specifiers must stay external. */
|
|
32
|
+
externalNamespaces?: readonly string[];
|
|
31
33
|
};
|
|
32
34
|
export type Bundler = (options: BundleOptions) => Promise<void>;
|
|
33
35
|
/** Component imports are WIT specifiers, not npm packages. */
|
|
34
36
|
export declare const COMPONENT_IMPORT_EXTERNAL: RegExp;
|
|
37
|
+
/** `COMPONENT_IMPORT_EXTERNAL` widened with the namespaces of composed component providers. */
|
|
38
|
+
export declare function componentImportExternal(namespaces?: readonly string[]): RegExp;
|
|
35
39
|
/** Every process, filesystem-adjacent, and toolchain boundary the commands touch. */
|
|
36
40
|
export type WasmcloudDeps = {
|
|
37
41
|
runner: ProcessRunner;
|
package/dist/deps.js
CHANGED
|
@@ -13,6 +13,11 @@ import { rolldownInject, wasmcloudNodeEnv } from './node-compat/env.js';
|
|
|
13
13
|
import { createNodeCompatSeed, EMPTY_NODE_COMPAT_SEED, isNodeCompatSeedSource, NODE_COMPAT_SEED_ID, renderNodeCompatSeedModule, } from './node-compat/seed.js';
|
|
14
14
|
/** Component imports are WIT specifiers, not npm packages. */
|
|
15
15
|
export const COMPONENT_IMPORT_EXTERNAL = /^(wasi|wasmcloud|di-framework):/;
|
|
16
|
+
/** `COMPONENT_IMPORT_EXTERNAL` widened with the namespaces of composed component providers. */
|
|
17
|
+
export function componentImportExternal(namespaces = []) {
|
|
18
|
+
const extra = namespaces.map((namespace) => namespace.replaceAll(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
|
19
|
+
return new RegExp(`^(wasi|wasmcloud|di-framework${extra.map((n) => `|${n}`).join('')}):`);
|
|
20
|
+
}
|
|
16
21
|
const NODE_COMPAT_SEED_RESOLVED = `\0${NODE_COMPAT_SEED_ID}`;
|
|
17
22
|
/** Resolves the virtual application module and Node built-ins through unenv. */
|
|
18
23
|
export function nodeCompatibilityPlugin(entryPath, guestsPath, seedOrActorsPath, maybeSeed) {
|
|
@@ -224,11 +229,11 @@ export const DEFAULT_DEPS = {
|
|
|
224
229
|
return { exitCode: await child.exited, stdout, stderr };
|
|
225
230
|
},
|
|
226
231
|
wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
227
|
-
bundler: async ({ adapterPath, entryPath, outFile, guestsPath, actorsPath, cronPath, queuesPath, projectRoot, guestLogging, files, env, cwd, }) => {
|
|
232
|
+
bundler: async ({ adapterPath, entryPath, outFile, guestsPath, actorsPath, cronPath, queuesPath, projectRoot, guestLogging, files, env, cwd, externalNamespaces, }) => {
|
|
228
233
|
const nodeEnv = wasmcloudNodeEnv();
|
|
229
234
|
const bundle = await rolldown({
|
|
230
235
|
input: 'virtual:di-framework-runtime-entry',
|
|
231
|
-
external:
|
|
236
|
+
external: componentImportExternal(externalNamespaces),
|
|
232
237
|
resolve: { alias: { ...nodeEnv.alias }, conditionNames: ['wasmcloud', 'import', 'default'] },
|
|
233
238
|
plugins: [
|
|
234
239
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@di-framework/cli-plugin-platform",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "di-framework CLI extension that builds, serves, and deploys DI Framework apps as platform WebAssembly components.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|