Skip to content

Commit 7bb385f

Browse files
authored
build: always install wasm32 package (#637)
1 parent 2cc4a5f commit 7bb385f

File tree

6 files changed

+105
-150
lines changed

6 files changed

+105
-150
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@
1414

1515
## Quick Start
1616

17-
```
18-
npm i rrule-rust
19-
```
20-
21-
If you need a browser-compatible version with WASM support:
17+
Install the package using npm:
2218

2319
```
24-
npm i rrule-rust --cpu "wasm32"
20+
npm i rrule-rust
2521
```
2622

2723
For more usage examples and advanced scenarios, see the [tests directory](https://github.com/lsndr/rrule-rust/tree/master/tests) in the repository.

npm/wasm32-wasi/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"name": "@rrule-rust/lib-wasm32-wasi",
33
"version": "0.0.0",
4-
"cpu": [
5-
"wasm32"
6-
],
74
"main": "rrule-rust.wasi.cjs",
85
"files": [
96
"rrule-rust.wasm32-wasi.wasm",

tests/e2e/commonjs.spec.ts

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,51 @@ describe('Commonjs', () => {
2020
sandbox.uninstall();
2121
});
2222

23-
it('yearly in June and July for 10 occurrences', () => {
24-
const result = sandbox.run(() => {
25-
const rrule = new RRule({
26-
frequency: Frequency.Yearly,
27-
byMonth: [Month.June, Month.July],
28-
count: 10,
29-
});
30-
const set = new RRuleSet(
31-
new DtStart({
32-
value: DateTime.create(1997, 6, 10, 9, 0, 0, false),
33-
tzid: 'US/Eastern',
34-
}),
35-
).addRRule(rrule);
23+
describe.each([undefined, 'error'])(
24+
'NAPI_RS_FORCE_WASI=%s',
25+
(NAPI_RS_FORCE_WASI) => {
26+
it('yearly in June and July for 10 occurrences', () => {
27+
const result = sandbox.run(
28+
() => {
29+
const rrule = new RRule({
30+
frequency: Frequency.Yearly,
31+
byMonth: [Month.June, Month.July],
32+
count: 10,
33+
});
34+
const set = new RRuleSet(
35+
new DtStart({
36+
value: DateTime.create(1997, 6, 10, 9, 0, 0, false),
37+
tzid: 'US/Eastern',
38+
}),
39+
).addRRule(rrule);
3640

37-
return {
38-
asString: set.toString(),
39-
dates: set.all().map((dt) => dt.toString()),
40-
};
41-
});
41+
return {
42+
asString: set.toString(),
43+
dates: set.all().map((dt) => dt.toString()),
44+
};
45+
},
46+
{
47+
env: { NAPI_RS_FORCE_WASI },
48+
},
49+
);
4250

43-
expect(result).toEqual({
44-
asString:
45-
'DTSTART;TZID=US/Eastern:19970610T090000\nRRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7',
46-
dates: [
47-
DateTime.create(1997, 6, 10, 9, 0, 0, false),
48-
DateTime.create(1997, 7, 10, 9, 0, 0, false),
49-
DateTime.create(1998, 6, 10, 9, 0, 0, false),
50-
DateTime.create(1998, 7, 10, 9, 0, 0, false),
51-
DateTime.create(1999, 6, 10, 9, 0, 0, false),
52-
DateTime.create(1999, 7, 10, 9, 0, 0, false),
53-
DateTime.create(2000, 6, 10, 9, 0, 0, false),
54-
DateTime.create(2000, 7, 10, 9, 0, 0, false),
55-
DateTime.create(2001, 6, 10, 9, 0, 0, false),
56-
DateTime.create(2001, 7, 10, 9, 0, 0, false),
57-
].map((dt) => dt.toString()),
58-
});
59-
});
51+
expect(result).toEqual({
52+
asString:
53+
'DTSTART;TZID=US/Eastern:19970610T090000\nRRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7',
54+
dates: [
55+
DateTime.create(1997, 6, 10, 9, 0, 0, false),
56+
DateTime.create(1997, 7, 10, 9, 0, 0, false),
57+
DateTime.create(1998, 6, 10, 9, 0, 0, false),
58+
DateTime.create(1998, 7, 10, 9, 0, 0, false),
59+
DateTime.create(1999, 6, 10, 9, 0, 0, false),
60+
DateTime.create(1999, 7, 10, 9, 0, 0, false),
61+
DateTime.create(2000, 6, 10, 9, 0, 0, false),
62+
DateTime.create(2000, 7, 10, 9, 0, 0, false),
63+
DateTime.create(2001, 6, 10, 9, 0, 0, false),
64+
DateTime.create(2001, 7, 10, 9, 0, 0, false),
65+
].map((dt) => dt.toString()),
66+
});
67+
});
68+
},
69+
);
6070
});

tests/e2e/esm.spec.ts

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,51 @@ describe('ESM', () => {
2222
sandbox.uninstall();
2323
});
2424

25-
it('yearly in June and July for 10 occurrences', () => {
26-
const result = sandbox.run(() => {
27-
const rrule = new RRule({
28-
frequency: Frequency.Yearly,
29-
byMonth: [Month.June, Month.July],
30-
count: 10,
31-
});
32-
const set = new RRuleSet(
33-
new DtStart({
34-
value: DateTime.create(1997, 6, 10, 9, 0, 0, false),
35-
tzid: 'US/Eastern',
36-
}),
37-
).addRRule(rrule);
25+
describe.each([undefined, 'error'])(
26+
'NAPI_RS_FORCE_WASI=%s',
27+
(NAPI_RS_FORCE_WASI) => {
28+
it('yearly in June and July for 10 occurrences', () => {
29+
const result = sandbox.run(
30+
() => {
31+
const rrule = new RRule({
32+
frequency: Frequency.Yearly,
33+
byMonth: [Month.June, Month.July],
34+
count: 10,
35+
});
36+
const set = new RRuleSet(
37+
new DtStart({
38+
value: DateTime.create(1997, 6, 10, 9, 0, 0, false),
39+
tzid: 'US/Eastern',
40+
}),
41+
).addRRule(rrule);
3842

39-
return {
40-
asString: set.toString(),
41-
dates: set.all().map((dt) => dt.toString()),
42-
};
43-
});
43+
return {
44+
asString: set.toString(),
45+
dates: set.all().map((dt) => dt.toString()),
46+
};
47+
},
48+
{
49+
env: { NAPI_RS_FORCE_WASI },
50+
},
51+
);
4452

45-
expect(result).toEqual({
46-
asString:
47-
'DTSTART;TZID=US/Eastern:19970610T090000\nRRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7',
48-
dates: [
49-
DateTime.create(1997, 6, 10, 9, 0, 0, false),
50-
DateTime.create(1997, 7, 10, 9, 0, 0, false),
51-
DateTime.create(1998, 6, 10, 9, 0, 0, false),
52-
DateTime.create(1998, 7, 10, 9, 0, 0, false),
53-
DateTime.create(1999, 6, 10, 9, 0, 0, false),
54-
DateTime.create(1999, 7, 10, 9, 0, 0, false),
55-
DateTime.create(2000, 6, 10, 9, 0, 0, false),
56-
DateTime.create(2000, 7, 10, 9, 0, 0, false),
57-
DateTime.create(2001, 6, 10, 9, 0, 0, false),
58-
DateTime.create(2001, 7, 10, 9, 0, 0, false),
59-
].map((dt) => dt.toString()),
60-
});
61-
});
53+
expect(result).toEqual({
54+
asString:
55+
'DTSTART;TZID=US/Eastern:19970610T090000\nRRULE:FREQ=YEARLY;COUNT=10;BYMONTH=6,7',
56+
dates: [
57+
DateTime.create(1997, 6, 10, 9, 0, 0, false),
58+
DateTime.create(1997, 7, 10, 9, 0, 0, false),
59+
DateTime.create(1998, 6, 10, 9, 0, 0, false),
60+
DateTime.create(1998, 7, 10, 9, 0, 0, false),
61+
DateTime.create(1999, 6, 10, 9, 0, 0, false),
62+
DateTime.create(1999, 7, 10, 9, 0, 0, false),
63+
DateTime.create(2000, 6, 10, 9, 0, 0, false),
64+
DateTime.create(2000, 7, 10, 9, 0, 0, false),
65+
DateTime.create(2001, 6, 10, 9, 0, 0, false),
66+
DateTime.create(2001, 7, 10, 9, 0, 0, false),
67+
].map((dt) => dt.toString()),
68+
});
69+
});
70+
},
71+
);
6272
});

tests/e2e/sandbox/sandbox.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ export interface SandboxOptions {
99
cpu?: string[];
1010
}
1111

12+
export interface RunOptions {
13+
env?: Record<string, string | undefined>;
14+
}
15+
1216
export class Sandbox {
1317
private readonly projectPath: string;
1418
private readonly esm: boolean;
15-
private readonly cpu: string[];
1619

1720
public constructor(options?: SandboxOptions) {
1821
this.projectPath = path.resolve(__dirname, 'app');
1922
this.esm = options?.esm ?? false;
20-
this.cpu = options?.cpu ?? [];
2123
}
2224

2325
public install(): void {
@@ -29,11 +31,7 @@ export class Sandbox {
2931
execSync(`npm pkg set type=module`, { cwd: this.projectPath });
3032
}
3133

32-
let cmd = `npm install rrule-rust@${this.getVersion()}`;
33-
34-
if (this.cpu.length > 0) {
35-
cmd += ` --cpu ${this.cpu.join(' --cpu ')}`;
36-
}
34+
const cmd = `npm install rrule-rust@${this.getVersion()}`;
3735

3836
execSync(cmd, {
3937
cwd: this.projectPath,
@@ -44,7 +42,7 @@ export class Sandbox {
4442
rimrafSync(path.resolve(this.projectPath));
4543
}
4644

47-
public run<T>(code: () => T): T {
45+
public run<T>(code: () => T, options?: RunOptions): T {
4846
writeFileSync(
4947
path.resolve(this.projectPath, 'index.js'),
5048
`
@@ -62,7 +60,13 @@ export class Sandbox {
6260

6361
try {
6462
return JSON.parse(
65-
execSync('node index.js', { cwd: this.projectPath }).toString(),
63+
execSync('node index.js', {
64+
cwd: this.projectPath,
65+
env: {
66+
...process.env,
67+
...options?.env,
68+
},
69+
}).toString(),
6670
);
6771
} finally {
6872
rmSync(path.resolve(this.projectPath, 'index.js'));

tests/e2e/wasm.spec.ts

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

0 commit comments

Comments
 (0)