Skip to content

Commit 5e8d91e

Browse files
authored
Prepare for v3.0.0-rc1 (#317)
Prepare for v3.0.0 * Bump componentizeJS and make build script dependant on the version of CJS as well * Drop responseProvider and bump router to v5 * Update test to add streaming test and use new router * Stop bundling the router as it can be used directly as a dependency * remove itty router dependency from SDK * Prepare for 3.0.0-rc1 release Signed-off-by: karthik2804 <[email protected]>
1 parent 1792398 commit 5e8d91e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+863
-645
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
uses: fermyon/actions/spin/setup@v1
3232
with:
3333
github_token: ${{ secrets.GITHUB_TOKEN }}
34-
version: "v3.0.0-rc.1"
3534

3635
- name: Run Test
3736
shell: bash

bin/j2w.mjs

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import yargs from 'yargs';
88
import { hideBin } from 'yargs/helpers';
99
import path from 'path';
1010

11+
const componentizeVersion = '0.16.0';
1112
const __filename = new URL(import.meta.url).pathname;
1213
const __dirname = __filename.substring(0, __filename.lastIndexOf('/'));
1314

@@ -39,16 +40,22 @@ const args = yargs(hideBin(process.argv))
3940

4041
const src = args.input;
4142
const outputPath = args.output;
42-
const inputChecksumPath = `${src}.checksum`;
43+
const buildDataPath = `${src}.buildData.json`;
4344

4445
// Function to calculate file checksum
4546
async function calculateChecksum(filePath) {
46-
const fileBuffer = await readFile(filePath);
47-
const hash = createHash('sha256');
48-
hash.update(fileBuffer);
49-
return hash.digest('hex');
47+
try {
48+
const fileBuffer = await readFile(filePath);
49+
const hash = createHash('sha256');
50+
hash.update(fileBuffer);
51+
return hash.digest('hex');
52+
} catch (error) {
53+
console.error(`Error calculating checksum for file ${filePath}:`, error);
54+
throw error;
55+
}
5056
}
5157

58+
5259
// Function to check if a file exists
5360
async function fileExists(filePath) {
5461
try {
@@ -59,47 +66,67 @@ async function fileExists(filePath) {
5966
}
6067
}
6168

62-
async function getExistingChecksum(checksumPath) {
63-
if (await fileExists(checksumPath)) {
64-
return await readFile(checksumPath, 'utf8');
69+
async function getExistingBuildData(buildaDataPath) {
70+
try {
71+
if (await fileExists(buildaDataPath)) {
72+
const buildData = await readFile(buildDataPath, 'utf8');
73+
return JSON.parse(buildData);
74+
}
75+
return null;
76+
} catch (error) {
77+
console.error(`Error reading existing checksum file at ${buildDataPath}:`, error);
78+
throw error;
6579
}
66-
return null;
6780
}
6881

69-
async function saveChecksum(checksumPath, checksum) {
70-
await writeFile(checksumPath, checksum);
82+
async function saveBuildData(buildDataPath, checksum, version) {
83+
try {
84+
const checksumData = {
85+
version,
86+
checksum
87+
};
88+
await writeFile(buildDataPath, JSON.stringify(checksumData, null, 2));
89+
} catch (error) {
90+
console.error(`Error saving checksum file at ${buildDataPath}:`, error);
91+
throw error;
92+
}
7193
}
7294

7395
(async () => {
74-
const sourceChecksum = await calculateChecksum(src);
75-
const existingChecksum = await getExistingChecksum(inputChecksumPath);
76-
77-
if ((existingChecksum === sourceChecksum) && fileExists(outputPath)) {
78-
console.log("No changes detected in source file. Skipping componentization.");
79-
return;
80-
}
81-
82-
const source = await readFile(src, 'utf8');
83-
84-
// Check if a non-default wit directory is supplied
85-
const witPath = args.witPath ? resolve(args.witPath) : path.join(__dirname, 'wit');
86-
if (args.witPath) {
87-
console.log(`Using user-provided wit in: ${witPath}`);
96+
try {
97+
const sourceChecksum = await calculateChecksum(src);
98+
const existingBuildData = await getExistingBuildData(buildDataPath);
99+
100+
if (existingBuildData?.version == componentizeVersion && existingBuildData?.checksum === sourceChecksum && await fileExists(outputPath)) {
101+
console.log("No changes detected in source file. Skipping componentization.");
102+
return;
103+
}
104+
105+
const source = await readFile(src, 'utf8');
106+
107+
// Check if a non-default wit directory is supplied
108+
const witPath = args.witPath ? resolve(args.witPath) : path.join(__dirname, 'wit');
109+
if (args.witPath) {
110+
console.log(`Using user-provided wit in: ${witPath}`);
111+
}
112+
113+
const { component } = await componentize(source, {
114+
sourceName: basename(src),
115+
witPath,
116+
worldName: args.triggerType,
117+
disableFeatures: [],
118+
enableFeatures: ["http"],
119+
enableAot: args.aot
120+
});
121+
122+
await writeFile(outputPath, component);
123+
124+
// Save the checksum of the input file along with the componentize version
125+
await saveBuildData(buildDataPath, sourceChecksum, componentizeVersion);
126+
127+
console.log("Component successfully written.");
128+
} catch (error) {
129+
console.error("An error occurred during the componentization process:", error);
130+
process.exit(1);
88131
}
89-
90-
const { component } = await componentize(source, {
91-
sourceName: basename(src),
92-
witPath,
93-
worldName: args.triggerType,
94-
disableFeatures: [],
95-
enableFeatures: ["http"],
96-
enableAot: args.aot
97-
});
98-
99-
await writeFile(outputPath, component);
100-
101-
// Save the checksum of the input file
102-
await saveChecksum(inputChecksumPath, sourceChecksum);
103-
104-
console.log("Component successfully written.");
105-
})();
132+
})();

bin/wit/deps/cli/command.wit

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
package wasi:cli@0.2.0;
1+
package wasi:cli@0.2.3;
22

3+
@since(version = 0.2.0)
34
world command {
5+
@since(version = 0.2.0)
46
include imports;
57

8+
@since(version = 0.2.0)
69
export run;
710
}

bin/wit/deps/cli/environment.wit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@since(version = 0.2.0)
12
interface environment {
23
/// Get the POSIX-style environment variables.
34
///
@@ -7,12 +8,15 @@ interface environment {
78
/// Morally, these are a value import, but until value imports are available
89
/// in the component model, this import function should return the same
910
/// values each time it is called.
11+
@since(version = 0.2.0)
1012
get-environment: func() -> list<tuple<string, string>>;
1113

1214
/// Get the POSIX-style arguments to the program.
15+
@since(version = 0.2.0)
1316
get-arguments: func() -> list<string>;
1417

1518
/// Return a path that programs should use as their initial current working
1619
/// directory, interpreting `.` as shorthand for this.
20+
@since(version = 0.2.0)
1721
initial-cwd: func() -> option<string>;
1822
}

bin/wit/deps/cli/exit.wit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1+
@since(version = 0.2.0)
12
interface exit {
23
/// Exit the current instance and any linked instances.
4+
@since(version = 0.2.0)
35
exit: func(status: result);
6+
7+
/// Exit the current instance and any linked instances, reporting the
8+
/// specified status code to the host.
9+
///
10+
/// The meaning of the code depends on the context, with 0 usually meaning
11+
/// "success", and other values indicating various types of failure.
12+
///
13+
/// This function does not return; the effect is analogous to a trap, but
14+
/// without the connotation that something bad has happened.
15+
@unstable(feature = cli-exit-with-code)
16+
exit-with-code: func(status-code: u8);
417
}

bin/wit/deps/cli/imports.wit

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1-
package wasi:cli@0.2.0;
1+
package wasi:cli@0.2.3;
22

3+
@since(version = 0.2.0)
34
world imports {
4-
include wasi:clocks/imports@0.2.0;
5-
include wasi:filesystem/imports@0.2.0;
6-
include wasi:sockets/imports@0.2.0;
7-
include wasi:random/imports@0.2.0;
8-
include wasi:io/imports@0.2.0;
5+
@since(version = 0.2.0)
6+
include wasi:clocks/imports@0.2.3;
7+
@since(version = 0.2.0)
8+
include wasi:filesystem/imports@0.2.3;
9+
@since(version = 0.2.0)
10+
include wasi:sockets/imports@0.2.3;
11+
@since(version = 0.2.0)
12+
include wasi:random/imports@0.2.3;
13+
@since(version = 0.2.0)
14+
include wasi:io/imports@0.2.3;
915

16+
@since(version = 0.2.0)
1017
import environment;
18+
@since(version = 0.2.0)
1119
import exit;
20+
@since(version = 0.2.0)
1221
import stdin;
22+
@since(version = 0.2.0)
1323
import stdout;
24+
@since(version = 0.2.0)
1425
import stderr;
26+
@since(version = 0.2.0)
1527
import terminal-input;
28+
@since(version = 0.2.0)
1629
import terminal-output;
30+
@since(version = 0.2.0)
1731
import terminal-stdin;
32+
@since(version = 0.2.0)
1833
import terminal-stdout;
34+
@since(version = 0.2.0)
1935
import terminal-stderr;
2036
}

bin/wit/deps/cli/run.wit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
@since(version = 0.2.0)
12
interface run {
23
/// Run the program.
4+
@since(version = 0.2.0)
35
run: func() -> result;
46
}

bin/wit/deps/cli/stdio.wit

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1+
@since(version = 0.2.0)
12
interface stdin {
2-
use wasi:io/streams@0.2.0.{input-stream};
3+
@since(version = 0.2.0)
4+
use wasi:io/streams@0.2.3.{input-stream};
35

6+
@since(version = 0.2.0)
47
get-stdin: func() -> input-stream;
58
}
69

10+
@since(version = 0.2.0)
711
interface stdout {
8-
use wasi:io/streams@0.2.0.{output-stream};
12+
@since(version = 0.2.0)
13+
use wasi:io/streams@0.2.3.{output-stream};
914

15+
@since(version = 0.2.0)
1016
get-stdout: func() -> output-stream;
1117
}
1218

19+
@since(version = 0.2.0)
1320
interface stderr {
14-
use wasi:io/streams@0.2.0.{output-stream};
21+
@since(version = 0.2.0)
22+
use wasi:io/streams@0.2.3.{output-stream};
1523

24+
@since(version = 0.2.0)
1625
get-stderr: func() -> output-stream;
1726
}

bin/wit/deps/cli/terminal.wit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
/// In the future, this may include functions for disabling echoing,
44
/// disabling input buffering so that keyboard events are sent through
55
/// immediately, querying supported features, and so on.
6+
@since(version = 0.2.0)
67
interface terminal-input {
78
/// The input side of a terminal.
9+
@since(version = 0.2.0)
810
resource terminal-input;
911
}
1012

@@ -13,37 +15,48 @@ interface terminal-input {
1315
/// In the future, this may include functions for querying the terminal
1416
/// size, being notified of terminal size changes, querying supported
1517
/// features, and so on.
18+
@since(version = 0.2.0)
1619
interface terminal-output {
1720
/// The output side of a terminal.
21+
@since(version = 0.2.0)
1822
resource terminal-output;
1923
}
2024

2125
/// An interface providing an optional `terminal-input` for stdin as a
2226
/// link-time authority.
27+
@since(version = 0.2.0)
2328
interface terminal-stdin {
29+
@since(version = 0.2.0)
2430
use terminal-input.{terminal-input};
2531

2632
/// If stdin is connected to a terminal, return a `terminal-input` handle
2733
/// allowing further interaction with it.
34+
@since(version = 0.2.0)
2835
get-terminal-stdin: func() -> option<terminal-input>;
2936
}
3037

3138
/// An interface providing an optional `terminal-output` for stdout as a
3239
/// link-time authority.
40+
@since(version = 0.2.0)
3341
interface terminal-stdout {
42+
@since(version = 0.2.0)
3443
use terminal-output.{terminal-output};
3544

3645
/// If stdout is connected to a terminal, return a `terminal-output` handle
3746
/// allowing further interaction with it.
47+
@since(version = 0.2.0)
3848
get-terminal-stdout: func() -> option<terminal-output>;
3949
}
4050

4151
/// An interface providing an optional `terminal-output` for stderr as a
4252
/// link-time authority.
53+
@since(version = 0.2.0)
4354
interface terminal-stderr {
55+
@since(version = 0.2.0)
4456
use terminal-output.{terminal-output};
4557

4658
/// If stderr is connected to a terminal, return a `terminal-output` handle
4759
/// allowing further interaction with it.
60+
@since(version = 0.2.0)
4861
get-terminal-stderr: func() -> option<terminal-output>;
4962
}

bin/wit/deps/clocks/monotonic-clock.wit

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package wasi:clocks@0.2.0;
1+
package wasi:clocks@0.2.3;
22
/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
33
/// time.
44
///
@@ -7,38 +7,43 @@ package wasi:[email protected];
77
///
88
/// A monotonic clock is a clock which has an unspecified initial value, and
99
/// successive reads of the clock will produce non-decreasing values.
10-
///
11-
/// It is intended for measuring elapsed time.
10+
@since(version = 0.2.0)
1211
interface monotonic-clock {
13-
use wasi:io/poll@0.2.0.{pollable};
12+
@since(version = 0.2.0)
13+
use wasi:io/poll@0.2.3.{pollable};
1414

1515
/// An instant in time, in nanoseconds. An instant is relative to an
1616
/// unspecified initial value, and can only be compared to instances from
1717
/// the same monotonic-clock.
18+
@since(version = 0.2.0)
1819
type instant = u64;
1920

2021
/// A duration of time, in nanoseconds.
22+
@since(version = 0.2.0)
2123
type duration = u64;
2224

2325
/// Read the current value of the clock.
2426
///
2527
/// The clock is monotonic, therefore calling this function repeatedly will
2628
/// produce a sequence of non-decreasing values.
29+
@since(version = 0.2.0)
2730
now: func() -> instant;
2831

2932
/// Query the resolution of the clock. Returns the duration of time
3033
/// corresponding to a clock tick.
34+
@since(version = 0.2.0)
3135
resolution: func() -> duration;
3236

3337
/// Create a `pollable` which will resolve once the specified instant
34-
/// occured.
38+
/// has occurred.
39+
@since(version = 0.2.0)
3540
subscribe-instant: func(
3641
when: instant,
3742
) -> pollable;
3843

39-
/// Create a `pollable` which will resolve once the given duration has
40-
/// elapsed, starting at the time at which this function was called.
41-
/// occured.
44+
/// Create a `pollable` that will resolve after the specified duration has
45+
/// elapsed from the time this function is invoked.
46+
@since(version = 0.2.0)
4247
subscribe-duration: func(
4348
when: duration,
4449
) -> pollable;

0 commit comments

Comments
 (0)