Skip to content

Commit 4a89d09

Browse files
committed
Fix JavaScript build artifacts
Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
1 parent cb37079 commit 4a89d09

9 files changed

Lines changed: 69 additions & 32 deletions

File tree

‎python/cppjswasm/js/build.mjs.jinja‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,39 @@ const BUNDLES = [
1818
];
1919

2020
async function build() {
21+
if (fs.existsSync("dist")) {
22+
for (const entry of fs.readdirSync("dist")) {
23+
if (entry !== "pkg") {
24+
fs.rmSync(`dist/${entry}`, { recursive: true, force: true });
25+
}
26+
}
27+
}
28+
fs.rmSync("../{{ module }}/extension", {
29+
recursive: true,
30+
force: true,
31+
});
32+
2133
// Bundle css
2234
await bundle_css();
2335

2436
// Copy HTML
25-
cpy("src/html/*", "dist/");
37+
await cpy("src/html/*", "dist/");
2638

2739
// Copy images
28-
fs.mkdirSync("dist/img", { recursive: true });
29-
cpy("src/img/*", "dist/img");
40+
if (fs.existsSync("src/img")) {
41+
fs.mkdirSync("dist/img", { recursive: true });
42+
await cpy("src/img/*", "dist/img");
43+
}
3044

3145
await Promise.all(BUNDLES.map(bundle)).catch(() => process.exit(1));
3246

3347
// Copy servable assets to python extension (exclude esm/)
3448
fs.mkdirSync("../{{ module }}/extension", { recursive: true });
35-
cpy("dist/**/*", "../{{ module }}/extension", {
36-
filter: (file) => !file.relativePath.startsWith("esm"),
49+
await cpy("dist/**/*", "../{{ module }}/extension", {
50+
filter: (file) =>
51+
!file.relativePath.startsWith("esm/") &&
52+
!file.relativePath.startsWith("dist/esm/"),
3753
});
3854
}
3955

40-
build();
56+
await build();

‎python/cppjswasm/js/package.json.jinja‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
"./package.json": "./package.json"
1919
},
2020
"files": [
21-
"dist/**/*",
22-
"index.d.ts"
21+
"dist/**/*"
2322
],
2423
"types": "./dist/esm/index.d.ts",
2524
"publishConfig": {
2625
"access": "public"
2726
},
2827
"scripts": {
28+
"build:clean": "node -e \"const fs=require('fs'); fs.rmSync('dist',{recursive:true,force:true}); fs.rmSync('../{{ module }}/extension',{recursive:true,force:true})\"",
2929
"build:cpp": "node -e \"require('fs').mkdirSync('dist/pkg',{recursive:true})\" && em++ -O2 -std=c++17 -s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s SINGLE_FILE=1 -s ALLOW_MEMORY_GROWTH=1 -s ENVIRONMENT=web,worker --bind -I ../cpp ../cpp/{{ project_name_formatted }}/example.cpp src/cpp/bindings.cpp -o dist/pkg/{{ module }}.js",
3030
"build:debug": "node build.mjs --debug",
3131
"build:prod": "node build.mjs",
32-
"build": "npm-run-all build:cpp build:prod",
32+
"build:types": "tsc",
33+
"build": "npm-run-all build:clean build:cpp build:prod build:types",
3334
"clean": "rm -rf dist lib playwright-report ../{{ module }}/extension",
3435
"dev": "npm-run-all -p start watch",
3536
"lint:js": "oxlint . && oxfmt --check \"src/**/*.{js,ts,jsx,tsx,css}\" \"tests/**/*.{js,ts,jsx,tsx}\" \"*.mjs\" \"*.json\"",

‎python/cppjswasm/js/tsconfig.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"noFallthroughCasesInSwitch": true,
1515
"outDir": "./dist/esm",
1616
"resolveJsonModule": true,
17-
"rootDir": ".",
17+
"rootDir": "./src/ts",
1818
"skipLibCheck": true,
1919
"strict": true,
2020
"target": "ES2020",
2121
"useDefineForClassFields": true
2222
},
23-
"include": ["./src/ts/*.ts", "./tests/*.ts"]
23+
"include": ["./src/ts/*.ts"]
2424
}

‎python/js/js/build.mjs.jinja‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,33 @@ const BUNDLES = [
1818
];
1919

2020
async function build() {
21+
fs.rmSync("dist", { recursive: true, force: true });
22+
fs.rmSync("../{{ module }}/extension", {
23+
recursive: true,
24+
force: true,
25+
});
26+
2127
// Bundle css
2228
await bundle_css();
2329

2430
// Copy HTML
25-
cpy("src/html/*", "dist/");
31+
await cpy("src/html/*", "dist/");
2632

2733
// Copy images
28-
fs.mkdirSync("dist/img", { recursive: true });
29-
cpy("src/img/*", "dist/img");
34+
if (fs.existsSync("src/img")) {
35+
fs.mkdirSync("dist/img", { recursive: true });
36+
await cpy("src/img/*", "dist/img");
37+
}
3038

3139
await Promise.all(BUNDLES.map(bundle)).catch(() => process.exit(1));
3240

3341
// Copy servable assets to python extension (exclude esm/)
3442
fs.mkdirSync("../{{ module }}/extension", { recursive: true });
35-
cpy("dist/**/*", "../{{ module }}/extension", {
36-
filter: (file) => !file.relativePath.startsWith("esm"),
43+
await cpy("dist/**/*", "../{{ module }}/extension", {
44+
filter: (file) =>
45+
!file.relativePath.startsWith("esm/") &&
46+
!file.relativePath.startsWith("dist/esm/"),
3747
});
3848
}
3949

40-
build();
50+
await build();

‎python/js/js/package.json.jinja‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
"./package.json": "./package.json"
1919
},
2020
"files": [
21-
"dist/**/*",
22-
"index.d.ts"
21+
"dist/**/*"
2322
],
2423
"types": "./dist/esm/index.d.ts",
2524
"publishConfig": {
2625
"access": "public"
2726
},
2827
"scripts": {
2928
"build:debug": "node build.mjs --debug",
30-
"build": "node build.mjs",
29+
"build:prod": "node build.mjs",
30+
"build:types": "tsc",
31+
"build": "npm-run-all build:prod build:types",
3132
"clean": "rm -rf dist playwright-report ../{{ module }}/extension",
3233
"dev": "npm-run-all -p start watch",
3334
"lint": "oxlint . && oxfmt --check \"src/**/*.{js,ts,jsx,tsx,css}\" \"tests/**/*.{js,ts,jsx,tsx}\" \"*.mjs\" \"*.json\"",

‎python/js/js/tsconfig.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"noFallthroughCasesInSwitch": true,
1515
"outDir": "./dist/esm",
1616
"resolveJsonModule": true,
17-
"rootDir": ".",
17+
"rootDir": "./src/ts",
1818
"skipLibCheck": true,
1919
"strict": true,
2020
"target": "ES2020",
2121
"useDefineForClassFields": true
2222
},
23-
"include": ["./src/ts/*.ts", "./tests/*.ts"]
23+
"include": ["./src/ts/*.ts"]
2424
}

‎python/rustjswasm/js/build.mjs.jinja‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ const BUNDLES = [
1818
];
1919

2020
async function build() {
21+
if (fs.existsSync("dist")) {
22+
for (const entry of fs.readdirSync("dist")) {
23+
if (entry !== "pkg") {
24+
fs.rmSync(`dist/${entry}`, { recursive: true, force: true });
25+
}
26+
}
27+
}
28+
fs.rmSync("../{{ module }}/extension", {
29+
recursive: true,
30+
force: true,
31+
});
32+
2133
// Bundle css
2234
await bundle_css();
2335

@@ -33,10 +45,6 @@ async function build() {
3345
await Promise.all(BUNDLES.map(bundle)).catch(() => process.exit(1));
3446

3547
// Copy servable assets to python extension (exclude esm/)
36-
fs.rmSync("../{{ module }}/extension", {
37-
recursive: true,
38-
force: true,
39-
});
4048
fs.mkdirSync("../{{ module }}/extension", { recursive: true });
4149
await cpy("dist/**/*", "../{{ module }}/extension", {
4250
filter: (file) =>
@@ -45,4 +53,4 @@ async function build() {
4553
});
4654
}
4755

48-
build();
56+
await build();

‎python/rustjswasm/js/package.json.jinja‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@
1818
"./package.json": "./package.json"
1919
},
2020
"files": [
21-
"dist/**/*",
22-
"index.d.ts"
21+
"dist/**/*"
2322
],
2423
"types": "./dist/esm/index.d.ts",
2524
"publishConfig": {
2625
"access": "public"
2726
},
2827
"scripts": {
2928
"setup": "cargo install -f wasm-bindgen-cli --version 0.2.126 --locked",
29+
"build:clean": "node -e \"const fs=require('fs'); fs.rmSync('dist',{recursive:true,force:true}); fs.rmSync('../{{ module }}/extension',{recursive:true,force:true})\"",
3030
"build:debug": "node build.mjs --debug",
3131
"build:rust": "cargo build --release --all-features --target wasm32-unknown-unknown --target-dir ../target",
3232
"build:wasm-bindgen": "wasm-bindgen ../target/wasm32-unknown-unknown/release/{{ module }}.wasm --out-dir ./dist/pkg --target web",
3333
"build:prod": "node build.mjs",
34-
"build": "npm-run-all build:rust build:wasm-bindgen build:prod",
34+
"build:types": "tsc",
35+
"build": "npm-run-all build:clean build:rust build:wasm-bindgen build:prod build:types",
3536
"clean": "rm -rf dist lib playwright-report ../{{ module }}/extension",
3637
"dev": "npm-run-all -p start watch",
3738
"lint:js": "oxlint . && oxfmt --check \"src/**/*.{js,ts,jsx,tsx,css}\" \"tests/**/*.{js,ts,jsx,tsx}\" \"*.mjs\" \"*.json\"",

‎python/rustjswasm/js/tsconfig.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"noFallthroughCasesInSwitch": true,
1515
"outDir": "./dist/esm",
1616
"resolveJsonModule": true,
17-
"rootDir": ".",
17+
"rootDir": "./src/ts",
1818
"skipLibCheck": true,
1919
"strict": true,
2020
"target": "ES2020",
2121
"useDefineForClassFields": true
2222
},
23-
"include": ["./src/ts/*.ts", "./tests/*.ts"]
23+
"include": ["./src/ts/*.ts"]
2424
}

0 commit comments

Comments
 (0)