Skip to content

Commit 39d3ebb

Browse files
committed
remove well known worlds and simplify package configuration
Signed-off-by: karthik2804 <[email protected]>
1 parent c21889d commit 39d3ebb

File tree

23 files changed

+391
-231
lines changed

23 files changed

+391
-231
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/build-tools/plugins/webpack/index.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPackagesWithWasiDeps, processWasiDeps, processWellKnownWorlds } from "../../dist/wasiDepsParser.js";
1+
import { getPackagesWithWasiDeps, processWasiDeps } from "../../dist/wasiDepsParser.js";
22
class SpinSdkPlugin {
33
constructor() {
44
this.externals = {};
@@ -9,14 +9,7 @@ class SpinSdkPlugin {
99
let plugin = new SpinSdkPlugin();
1010

1111
let wasiDeps = getPackagesWithWasiDeps(process.cwd(), new Set(), true);
12-
let { witPaths, targetWorlds, wellKnownWorlds } = processWasiDeps(wasiDeps)
13-
let { witPaths: wellKnownWitPaths, targetWorlds: wellKnownTargetWorlds } = await processWellKnownWorlds(wellKnownWorlds);
14-
wellKnownWitPaths.forEach((path) => {
15-
witPaths.push(path)
16-
})
17-
wellKnownTargetWorlds.forEach((target) => {
18-
targetWorlds.push(target)
19-
})
12+
let { witPaths, targetWorlds } = processWasiDeps(wasiDeps)
2013

2114
let imports = getWitImports(witPaths, targetWorlds);
2215

packages/build-tools/src/index.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
import { componentize } from "@bytecodealliance/componentize-js";
4-
import { getPackagesWithWasiDeps, processWasiDeps, processWellKnownWorlds } from "./wasiDepsParser.js";
4+
import { getPackagesWithWasiDeps, processWasiDeps } from "./wasiDepsParser.js";
55
import { basename } from 'node:path';
66

77
import { calculateChecksum, getPackageVersion, saveBuildData } from "./utils.js";
@@ -30,17 +30,10 @@ async function main() {
3030
// generate wit world string
3131
let wasiDeps = getPackagesWithWasiDeps(process.cwd(), new Set(), true);
3232

33-
let { witPaths, targetWorlds, wellKnownWorlds } = processWasiDeps(wasiDeps)
34-
let { witPaths: wellKnownWitPaths, targetWorlds: wellKnownTargetWorlds } = await processWellKnownWorlds(wellKnownWorlds);
35-
wellKnownWitPaths.forEach((path) => {
36-
witPaths.push(path)
37-
})
38-
wellKnownTargetWorlds.forEach((target) => {
39-
targetWorlds.push(target)
40-
})
33+
let { witPaths, targetWorlds } = processWasiDeps(wasiDeps);
4134

4235
// Get inline wit by merging the wits specified by all the dependencies
43-
let inlineWit = mergeWit(witPaths, targetWorlds, "combined", "combined-wit:[email protected]")
36+
let inlineWit = mergeWit(witPaths, targetWorlds, "combined", "combined-wit:[email protected]");
4437

4538
const source = await readFile(src, 'utf8');
4639

packages/build-tools/src/wasiDepsParser.ts

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
import fs from "fs";
22
import { TargetWorld } from "../lib/wit_tools.js";
33
import path from "path";
4-
import { setupWellKnownWits } from "./wellKnownWits.js"
54

65

76
// Define the structure of a package.json file
87
// Includes dependencies and an optional config section for 'knitwit'
98
type PackageJson = {
109
name: string,
1110
dependencies?: Record<string, string>;
12-
devDependencies?: Record<string, string>;
13-
peerDependencies?: Record<string, string>;
14-
optionalDependencies?: Record<string, string>;
1511
config?: {
16-
wasiDep?: {
17-
witDeps?: witDep[];
18-
wellKnownWorlds?: string[];
19-
};
20-
};
12+
witDeps?: witDep[];
13+
}
2114
};
2215

2316
type witDep = {
@@ -30,11 +23,8 @@ type witDep = {
3023
type DependencyResult = {
3124
name: string;
3225
config: {
33-
wasiDep: {
34-
witDeps?: witDep[];
35-
wellKnownWorlds?: string[];
36-
}
37-
};
26+
witDeps?: witDep[];
27+
}
3828
}[];
3929

4030
// Reads and parses a package.json file
@@ -68,8 +58,8 @@ export function resolveDependencyPath(
6858

6959
// Converts the 'witPath' inside the config section to an absolute path if it is relative
7060
function absolutizeWitPath(depPackageJsonPath: string, depPackageJson: PackageJson): void {
71-
if (depPackageJson.config?.wasiDep?.witDeps) {
72-
depPackageJson.config.wasiDep.witDeps.forEach((witDep) => {
61+
if (depPackageJson.config?.witDeps) {
62+
depPackageJson.config.witDeps.forEach((witDep) => {
7363
if (!path.isAbsolute(witDep.witPath)) {
7464
witDep.witPath = path.resolve(depPackageJsonPath, witDep.witPath);
7565
}
@@ -96,19 +86,16 @@ export function getPackagesWithWasiDeps(
9686
const result: DependencyResult = [];
9787

9888
if (topLevel) {
99-
if (packageJson.config?.wasiDep) {
100-
if (packageJson.config.wasiDep.witDeps || packageJson.config.wasiDep.wellKnownWorlds) {
101-
if (packageJson.config.wasiDep.witDeps) {
89+
if (packageJson.config?.witDeps) {
90+
if (packageJson.config.witDeps) {
91+
if (packageJson.config.witDeps) {
10292
absolutizeWitPath(dir, packageJson);
10393
}
10494

10595
result.push({
10696
name: packageJson.name,
10797
config: {
108-
wasiDep: {
109-
...(packageJson.config.wasiDep.witDeps && { witDeps: packageJson.config.wasiDep.witDeps }),
110-
...(packageJson.config.wasiDep.wellKnownWorlds && { wellKnownWorlds: packageJson.config.wasiDep.wellKnownWorlds }),
111-
}
98+
witDeps: packageJson.config.witDeps
11299
}
113100
});
114101
}
@@ -129,14 +116,12 @@ export function getPackagesWithWasiDeps(
129116
absolutizeWitPath(depPath, depPackageJson);
130117

131118
// If the package has a 'knitwit' config, add it to the result
132-
if (depPackageJson.config?.wasiDep) {
119+
if (depPackageJson.config?.witDeps) {
133120
result.push({
134121
name: dep,
135122
config: {
136-
wasiDep: {
137-
witDeps: depPackageJson.config.wasiDep.witDeps ?? undefined,
138-
wellKnownWorlds: depPackageJson.config.wasiDep.wellKnownWorlds ?? undefined,
139-
}
123+
witDeps:
124+
depPackageJson.config.witDeps ?? [],
140125
}
141126
});
142127
}
@@ -153,32 +138,15 @@ export function getPackagesWithWasiDeps(
153138
export function processWasiDeps(wasiDeps: DependencyResult) {
154139
let witPaths: string[] = [];
155140
let targetWorlds: TargetWorld[] = [];
156-
let wellKnownWorlds: string[] = [];
157141

158142
wasiDeps.forEach((dep) => {
159-
if (dep.config?.wasiDep?.witDeps) {
160-
dep.config.wasiDep.witDeps.forEach((witDep) => {
143+
if (dep.config?.witDeps) {
144+
dep.config.witDeps.forEach((witDep) => {
161145
witPaths.push(witDep.witPath!);
162-
targetWorlds.push({ packageName: witDep.package, worldName: witDep.world });
146+
targetWorlds.push({ packageName: witDep.package, worldName: witDep.world })
163147
});
164148
}
165-
if (dep.config?.wasiDep?.wellKnownWorlds) {
166-
wellKnownWorlds.push(...dep.config.wasiDep.wellKnownWorlds);
167-
}
168149
});
169150

170-
return { witPaths, targetWorlds, wellKnownWorlds };
171-
}
172-
173-
export async function processWellKnownWorlds(wellKnownWorlds: string[]) {
174-
let witPaths: string[] = [];
175-
let targetWorlds: TargetWorld[] = [];
176-
177-
for (let wellKnownWorld of wellKnownWorlds) {
178-
let { withPath, targetWorld } = await setupWellKnownWits(wellKnownWorld);
179-
witPaths.push(withPath);
180-
targetWorlds.push(targetWorld);
181-
}
182-
183151
return { witPaths, targetWorlds };
184152
}

packages/build-tools/src/wellKnownWits.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/build-tools/test/wasiDepsTest.spec.ts

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from "fs";
2-
import { getPackagesWithWasiDeps, processWasiDeps, processWellKnownWorlds, readPackageJson, resolveDependencyPath } from "../dist/wasiDepsParser.js";
2+
import { getPackagesWithWasiDeps, processWasiDeps, readPackageJson, resolveDependencyPath } from "../dist/wasiDepsParser.js";
33
import { expect } from "chai";
44
import sinon from "sinon";
55

@@ -64,10 +64,7 @@ describe("getPackagesWithWasiDeps", () => {
6464
const packageJson = {
6565
name: "test-package",
6666
config: {
67-
wasiDep: {
68-
witDeps: [{ witPath: "./test.wit", package: "test-pkg", world: "test-world" }],
69-
wellKnownWorlds: ["world-1"]
70-
}
67+
witDeps: [{ witPath: "./test.wit", package: "test-pkg", world: "test-world" }],
7168
}
7269
};
7370
existsSyncStub.returns(true);
@@ -76,11 +73,7 @@ describe("getPackagesWithWasiDeps", () => {
7673
{
7774
name: "test-package",
7875
config: {
79-
wasiDep: {
80-
// WitPath is resolved to an absolute path
81-
wellKnownWorlds: ["world-1"],
82-
witDeps: [{ witPath: "/project/test.wit", package: "test-pkg", world: "test-world" }]
83-
}
76+
witDeps: [{ witPath: "/project/test.wit", package: "test-pkg", world: "test-world" }]
8477
}
8578
}
8679
]);
@@ -93,31 +86,17 @@ describe("processWasiDeps", () => {
9386
{
9487
name: "test-package",
9588
config: {
96-
wasiDep: {
97-
witDeps: [{ witPath: "./test.wit", package: "test-pkg", world: "test-world" }],
98-
wellKnownWorlds: ["world-1"]
99-
}
89+
witDeps: [{ witPath: "./test.wit", package: "test-pkg", world: "test-world" }],
10090
}
10191
}
10292
];
10393
expect(processWasiDeps(wasiDeps)).to.deep.equal({
10494
witPaths: ["./test.wit"],
10595
targetWorlds: [{ packageName: "test-pkg", worldName: "test-world" }],
106-
wellKnownWorlds: ["world-1"]
10796
});
10897
});
10998
});
11099

111-
describe("processWellKnownWorlds", () => {
112-
113-
it("should call setupWellKnownWits for each world", async () => {
114-
const result = await processWellKnownWorlds(["[email protected]"]);
115-
// get absolutized directory path from setupWellKnownWits module
116-
let absolutePath = path.resolve(__dirname, '../dist/');
117-
expect(result).to.deep.equal({ witPaths: [path.resolve(absolutePath, "../well-known-wits/[email protected]")], targetWorlds: [{ packageName: "spinframework:[email protected]", worldName: "http-trigger" }] });
118-
});
119-
});
120-
121100
describe("getPackagesWithWasiDeps (recursive)", () => {
122101
let existsSyncStub, readFileSyncStub;
123102

@@ -138,9 +117,7 @@ describe("getPackagesWithWasiDeps (recursive)", () => {
138117
"package-2": "^1.0.0"
139118
},
140119
config: {
141-
wasiDep: {
142-
witDeps: [{ witPath: "./test1.wit", package: "test-pkg-1", world: "world-1" }],
143-
}
120+
witDeps: [{ witPath: "./test1.wit", package: "test-pkg-1", world: "world-1" }],
144121
}
145122
};
146123

@@ -153,9 +130,7 @@ describe("getPackagesWithWasiDeps (recursive)", () => {
153130
"package-4": "^1.0.0"
154131
},
155132
config: {
156-
wasiDep: {
157-
witDeps: [{ witPath: "./test2.wit", package: "test-pkg-2", world: "world-2" }],
158-
}
133+
witDeps: [{ witPath: "./test2.wit", package: "test-pkg-2", world: "world-2" }],
159134
}
160135
};
161136

@@ -166,27 +141,21 @@ describe("getPackagesWithWasiDeps (recursive)", () => {
166141
"package-5": "^1.0.0"
167142
},
168143
config: {
169-
wasiDep: {
170-
witDeps: [{ witPath: "./test3.wit", package: "test-pkg-3", world: "world-3" }],
171-
}
144+
witDeps: [{ witPath: "./test3.wit", package: "test-pkg-3", world: "world-3" }],
172145
}
173146
};
174147

175148
const packageJson4 = {
176149
name: "package-4",
177150
config: {
178-
wasiDep: {
179-
witDeps: [{ witPath: "./test4.wit", package: "test-pkg-4", world: "world-4" }],
180-
}
151+
witDeps: [{ witPath: "./test4.wit", package: "test-pkg-4", world: "world-4" }],
181152
}
182153
};
183154

184155
const packageJson5 = {
185156
name: "package-5",
186157
config: {
187-
wasiDep: {
188-
witDeps: [{ witPath: "./test5.wit", package: "test-pkg-5", world: "world-5" }],
189-
}
158+
witDeps: [{ witPath: "./test5.wit", package: "test-pkg-5", world: "world-5" }],
190159
}
191160
};
192161

@@ -214,15 +183,11 @@ describe("getPackagesWithWasiDeps (recursive)", () => {
214183
let visited: Set<string> = new Set()
215184
let result = getPackagesWithWasiDeps("/project", visited, true);
216185

217-
let { witPaths, targetWorlds, wellKnownWorlds } = processWasiDeps(result);
218-
let { witPaths: wellKnownWitPaths, targetWorlds: wellKnownTargetWorlds } = await processWellKnownWorlds(wellKnownWorlds);
219-
wellKnownWitPaths.forEach((witPath) => witPaths.push(witPath));
220-
wellKnownTargetWorlds.forEach((targetWorld) => targetWorlds.push(targetWorld));
186+
let { witPaths, targetWorlds } = processWasiDeps(result);
221187

222188

223189
expect(witPaths.length).to.equal(5);
224190
expect(targetWorlds.length).to.equal(5);
225-
expect(wellKnownWitPaths.length).to.equal(0);
226191
expect(witPaths).to.deep.equal([
227192
"/project/test1.wit",
228193
"/project/node_modules/package-2/test2.wit",

0 commit comments

Comments
 (0)