Skip to content

Commit fa6b99f

Browse files
Update from copier (2026-04-10T03:21:54)
Signed-off-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 30107b5 commit fa6b99f

File tree

8 files changed

+149
-71
lines changed

8 files changed

+149
-71
lines changed

.copier-answers.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: 9b579a3
2+
_commit: 9498b78
33
_src_path: https://github.com/python-project-templates/base.git
44
add_docs: true
55
add_extension: cppjswasm

js/build.mjs

Lines changed: 16 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,42 @@
1-
import { NodeModulesExternal } from "@finos/perspective-esbuild-plugin/external.js";
2-
import { build } from "@finos/perspective-esbuild-plugin/build.js";
3-
import { transform } from "lightningcss";
1+
import { bundle } from "./tools/bundle.mjs";
2+
import { bundle_css } from "./tools/css.mjs";
3+
import { node_modules_external } from "./tools/externals.mjs";
44
import { getarg } from "./tools/getarg.mjs";
5+
6+
import { transform } from "lightningcss";
57
import fs from "fs";
68
import cpy from "cpy";
79

8-
const DEBUG = getarg("--debug");
9-
10-
const COMMON_DEFINE = {
11-
global: "window",
12-
"process.env.DEBUG": `${DEBUG}`,
13-
};
14-
15-
const BUILD = [
10+
const BUNDLES = [
1611
{
17-
define: COMMON_DEFINE,
1812
entryPoints: ["src/ts/index.ts"],
19-
plugins: [NodeModulesExternal()],
20-
format: "esm",
21-
loader: {
22-
".css": "text",
23-
".html": "text",
24-
},
13+
plugins: [node_modules_external()],
2514
outfile: "dist/esm/index.js",
2615
},
2716
{
28-
define: COMMON_DEFINE,
2917
entryPoints: ["src/ts/index.ts"],
30-
plugins: [],
31-
format: "esm",
32-
loader: {
33-
".css": "text",
34-
".html": "text",
35-
},
3618
outfile: "dist/cdn/index.js",
3719
},
3820
];
3921

40-
async function compile_css() {
41-
const process_path = (path) => {
42-
const outpath = path.replace("src/css", "dist/css");
43-
fs.mkdirSync(outpath, { recursive: true });
44-
45-
fs.readdirSync(path, { withFileTypes: true }).forEach((entry) => {
46-
const input = `${path}/${entry.name}`;
47-
const output = `${outpath}/${entry.name}`;
48-
49-
if (entry.isDirectory()) {
50-
process_path(input);
51-
} else if (entry.isFile() && entry.name.endsWith(".css")) {
52-
const source = fs.readFileSync(input);
53-
const { code } = transform({
54-
filename: entry.name,
55-
code: source,
56-
minify: !DEBUG,
57-
sourceMap: false,
58-
});
59-
fs.writeFileSync(output, code);
60-
}
61-
});
62-
};
22+
async function build() {
23+
// Bundle css
24+
await bundle_css();
6325

64-
process_path("src/css");
65-
}
66-
67-
async function copy_html() {
26+
// Copy HTML
6827
fs.mkdirSync("dist/html", { recursive: true });
6928
cpy("src/html/*", "dist/html");
70-
// also copy to top level
7129
cpy("src/html/*", "dist/");
72-
}
7330

74-
async function copy_img() {
31+
// Copy images
7532
fs.mkdirSync("dist/img", { recursive: true });
7633
cpy("src/img/*", "dist/img");
77-
}
7834

79-
async function copy_to_python() {
35+
await Promise.all(BUNDLES.map(bundle)).catch(() => process.exit(1));
36+
37+
// Copy from dist to python
8038
fs.mkdirSync("../python_template_cppjswasm/extension", { recursive: true });
8139
cpy("dist/**/*", "../python_template_cppjswasm/extension");
8240
}
8341

84-
async function build_all() {
85-
await compile_css();
86-
await copy_html();
87-
await copy_img();
88-
await Promise.all(BUILD.map(build)).catch(() => process.exit(1));
89-
await copy_to_python();
90-
}
91-
92-
build_all();
42+
build();

js/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@
4848
},
4949
"dependencies": {},
5050
"devDependencies": {
51-
"@finos/perspective-esbuild-plugin": "^3.2.1",
52-
"@playwright/test": "^1.59.0",
51+
"@playwright/test": "^1.59.1",
5352
"cpy": "^13.2.1",
54-
"esbuild": "^0.27.2",
53+
"esbuild": "^0.27.3",
5554
"lightningcss": "^1.29.3",
5655
"http-server": "^14.1.1",
5756
"nodemon": "^3.1.10",

js/tools/bundle.mjs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { getarg } from "./getarg.mjs";
2+
import esbuild from "esbuild";
3+
4+
const DEBUG = getarg("--debug");
5+
6+
const CUTOFF_PERCENT = 0.02;
7+
8+
const COMMON_DEFINE = {
9+
global: "window",
10+
"process.env.DEBUG": `${DEBUG}`,
11+
};
12+
13+
const COMMON_LOADER = {
14+
".css": "text",
15+
".html": "text",
16+
".jsx": "jsx",
17+
".png": "file",
18+
".ttf": "file",
19+
".wasm": "file",
20+
};
21+
22+
const DEFAULT_BUILD = {
23+
target: ["es2022"],
24+
bundle: true,
25+
format: "esm",
26+
minify: DEBUG,
27+
sourcemap: true,
28+
metafile: true,
29+
entryNames: "[name]",
30+
chunkNames: "[name]",
31+
assetNames: "[name]",
32+
define: COMMON_DEFINE,
33+
loader: COMMON_LOADER,
34+
plugins: [],
35+
};
36+
37+
export const bundle = async (config) => {
38+
const result = await esbuild.build({
39+
...DEFAULT_BUILD,
40+
...config,
41+
});
42+
43+
if (result.metafile) {
44+
for (const output of Object.keys(result.metafile.outputs)) {
45+
const { inputs, bytes } = result.metafile.outputs[output];
46+
for (const input of Object.keys(inputs)) {
47+
if (inputs[input].bytesInOutput / bytes < CUTOFF_PERCENT) {
48+
delete inputs[input];
49+
}
50+
}
51+
}
52+
53+
const text = await esbuild.analyzeMetafile(result.metafile, {
54+
color: true,
55+
});
56+
57+
console.log(text);
58+
}
59+
};

js/tools/css.mjs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { getarg } from "./getarg.mjs";
2+
3+
import { bundleAsync } from "lightningcss";
4+
import fs from "fs";
5+
import path from "path";
6+
7+
const DEBUG = getarg("--debug");
8+
9+
const DEFAULT_RESOLVER = {
10+
resolve(specifier, originatingFile) {
11+
if (/^https?:\/\//.test(specifier)) {
12+
return specifier;
13+
}
14+
15+
if (specifier.startsWith("perspective-viewer-")) {
16+
const viewerCssDir = path.resolve(
17+
"node_modules/@perspective-dev/viewer/dist/css",
18+
);
19+
const normalized = specifier.replace(/^perspective-viewer-/, "");
20+
const normalizedPath = path.join(viewerCssDir, normalized);
21+
if (fs.existsSync(normalizedPath)) {
22+
return normalizedPath;
23+
}
24+
return path.join(viewerCssDir, specifier);
25+
}
26+
return path.resolve(path.dirname(originatingFile), specifier);
27+
},
28+
};
29+
30+
const bundle_one = async (file, resolver) => {
31+
const { code } = await bundleAsync({
32+
filename: path.resolve(file),
33+
minify: !DEBUG,
34+
sourceMap: false,
35+
resolver: resolver || DEFAULT_RESOLVER,
36+
});
37+
const outName = path.basename(file);
38+
fs.mkdirSync("./dist", { recursive: true });
39+
fs.writeFileSync(path.join("./dist", outName), code);
40+
};
41+
42+
export const bundle_css = async (root = "src/css/index.css", resolver = null) => {
43+
const resolved = path.resolve(root);
44+
if (fs.statSync(resolved).isDirectory()) {
45+
const files = fs.readdirSync(resolved).filter((f) => f.endsWith(".css"));
46+
for (const file of files) {
47+
await bundle_one(path.join(root, file), resolver);
48+
}
49+
} else {
50+
await bundle_one(root, resolver);
51+
}
52+
}

js/tools/externals.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export const node_modules_external = (whitelist) => {
2+
function setup(build) {
3+
build.onResolve({ filter: /^[A-Za-z0-9\@]/ }, (args) => {
4+
if (!whitelist || !args.path.startsWith(whitelist)) {
5+
return {
6+
path: args.path,
7+
external: true,
8+
namespace: "skip-node-modules",
9+
};
10+
}
11+
});
12+
}
13+
14+
return {
15+
name: "node_modules_external",
16+
setup,
17+
};
18+
};

js/tools/getarg.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ export const getarg = (flag, ...args) => {
2020
})
2121
.join(" ");
2222
}
23-
};
23+
};

js/tools/html.mjs

Whitespace-only changes.

0 commit comments

Comments
 (0)