Skip to content

Commit 8c2a1a1

Browse files
authored
Add support for P5 v2.x.x for the upcoming wrapper 5.x.x release (#521)
* Support P5 v2.x.x for the coming v5.x.x release of the wrapper * Add a note to the docs about `p5` version 2.x.x * Add an example of using the `async` / `await` syntax in the demo * Fix test coverage generation * Use happy-dom over jsdom for more performant UI tests
1 parent 05d2f0f commit 8c2a1a1

38 files changed

+848
-682
lines changed

.github/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ A component to integrate [P5.js](https://p5js.org/) sketches into
99
> been released for internal development or experimental testing ONLY. It is
1010
> recommended to continue utilising version `4.4.1` until version `5.0.0` is out
1111
> of the `rc` versioning scheme.
12+
>
13+
> One other thing to note about the coming release of the version `5.x.x` range
14+
> is that it will support the `p5` version `2.x.x` range which means
15+
> [support for `async` and `await`](https://beta.p5js.org/reference/p5/async_await/)
16+
> in your sketches and much more besides, you can read more on the upcoming
17+
> version of the [P5 docs](https://beta.p5js.org/).
1218
1319
## Installation
1420

config/typescript/tsconfig.json

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

config/typescript/tsconfig.node.json

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

config/vite/common.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { resolve } from "node:path";
2+
import { UserConfig } from "vite";
3+
4+
export function common(root: string): UserConfig {
5+
return {
6+
resolve: {
7+
alias: {
8+
"@": resolve(root, "src"),
9+
"@components": resolve(root, "src", "components"),
10+
"@utils": resolve(root, "src", "utils"),
11+
"@constants": resolve(root, "src", "constants"),
12+
"@contracts": resolve(root, "src", "contracts")
13+
}
14+
}
15+
};
16+
}

config/vite/demo.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import react from "@vitejs/plugin-react";
2+
import { resolve } from "node:path";
3+
import { UserConfig } from "vite";
4+
5+
export function demo(root: string): UserConfig {
6+
return {
7+
root: resolve(root, "demo"),
8+
base: "./",
9+
plugins: [react()],
10+
preview: { open: true },
11+
build: {
12+
emptyOutDir: false,
13+
rollupOptions: {
14+
output: {
15+
dir: resolve(root, "dist", "demo")
16+
}
17+
}
18+
}
19+
};
20+
}

config/vite/library.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import react from "@vitejs/plugin-react";
2+
import { posix, resolve } from "node:path";
3+
import { UserConfig } from "vite";
4+
import dts from "vite-plugin-dts";
5+
6+
export function library(root: string): UserConfig {
7+
const dist = resolve(root, "dist", "component");
8+
9+
return {
10+
plugins: [
11+
dts({
12+
rollupTypes: true,
13+
tsconfigPath: resolve(root, "tsconfig.json"),
14+
outDir: dist
15+
}),
16+
react({
17+
babel: {
18+
plugins: [["babel-plugin-react-compiler", {}]]
19+
}
20+
})
21+
],
22+
esbuild: {
23+
legalComments: "external"
24+
},
25+
build: {
26+
emptyOutDir: true,
27+
lib: {
28+
entry: resolve(root, "src", "main.tsx"),
29+
name: "ReactP5Wrapper",
30+
fileName: "ReactP5Wrapper",
31+
formats: ["es", "cjs"]
32+
},
33+
rollupOptions: {
34+
external: ["react", "react/jsx-runtime", "react-dom", "p5"],
35+
output: {
36+
assetFileNames: "assets/[name][extname]",
37+
entryFileNames: "[name].[format].js",
38+
dir: dist,
39+
globals: {
40+
p5: "p5",
41+
react: "React",
42+
"react/jsx-runtime": "jsxRuntime",
43+
"react-dom": "ReactDom"
44+
}
45+
}
46+
}
47+
},
48+
test: {
49+
globals: true,
50+
environment: "happy-dom",
51+
coverage: {
52+
include: [posix.join("src", "**/*.{ts,tsx,js,jsx}")],
53+
reporter: ["text-summary", "html", "clover"]
54+
},
55+
setupFiles: resolve(root, "tests", "setup.ts"),
56+
deps: {
57+
optimizer: {
58+
web: {
59+
include: ["vitest-canvas-mock"]
60+
}
61+
}
62+
}
63+
}
64+
};
65+
}

config/vite/vite.component.config.ts

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

config/vite/vite.config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { resolve } from "node:path";
2+
import { UserConfig } from "vite";
3+
import { defineConfig } from "vitest/config";
4+
5+
import { common } from "./common";
6+
import { demo } from "./demo";
7+
import { library } from "./library";
8+
9+
const root = resolve(__dirname, "..", "..");
10+
11+
export default defineConfig(({ mode }): UserConfig => {
12+
const isVitest = process.env.VITEST === "true";
13+
const config = isVitest || mode === "lib" ? library : demo;
14+
15+
return {
16+
...common(root),
17+
...config(root)
18+
} satisfies UserConfig;
19+
});

config/vite/vite.demo.config.ts

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

demo/app.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function App() {
1616

1717
const [state, setState] = useState({
1818
rotation: 160,
19-
sketch: record,
19+
sketch: box,
2020
unmount: false
2121
});
2222

0 commit comments

Comments
 (0)