mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-07 04:23:40 +09:00
While turborepo does not work for us we can try to solve long checks time with builtin caching. Eslint provides similar one to prettier we already use. ``` pnpm -r lint 51.53s pnpm eslint . --ext .ts,.tsx --max-warnings 0 18.10s pnpm eslint . --ext .ts,.tsx --max-warnings 0 --cache (with cache) 1.82s ``` In this PR I removed all lint scripts in packages and added global one in the to github workflow. It saves like 30s on my laptop because pnpm. Already stored cache makes linting almost instant. Also bumped all eslint dependencies.
91 lines
2.2 KiB
TypeScript
Executable File
91 lines
2.2 KiB
TypeScript
Executable File
#!/usr/bin/env tsx
|
|
|
|
import { rm, cp, access, writeFile, mkdir } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { totalist } from "totalist";
|
|
import { build, context, type BuildOptions } from "esbuild";
|
|
|
|
const args = process.argv.slice(2);
|
|
const watch = args.includes("--watch");
|
|
const noGeneratedAsEntries = args.includes("--no-generated-as-entries");
|
|
|
|
const entryPoints: string[] = [];
|
|
const assets: string[] = [];
|
|
|
|
await totalist("./src", (rel) => {
|
|
if (rel.endsWith(".ts") || rel.endsWith(".tsx")) {
|
|
if (
|
|
rel.includes(".test.") ||
|
|
rel.includes(".stories.") ||
|
|
(noGeneratedAsEntries && rel.includes("__generated__/"))
|
|
) {
|
|
return;
|
|
}
|
|
entryPoints.push(join("src", rel));
|
|
}
|
|
if (rel.endsWith(".json")) {
|
|
assets.push(rel);
|
|
}
|
|
});
|
|
|
|
await rm("lib", { recursive: true, force: true });
|
|
// regenerate them so we can safely write files into those directories without relying on esbuild creating them
|
|
// in the watch mode esbuild might not create them soon enough for them to be available for other parts of the script
|
|
await mkdir("lib");
|
|
await mkdir("lib/cjs");
|
|
|
|
const esmConfig: BuildOptions = {
|
|
entryPoints,
|
|
outdir: "lib",
|
|
format: "esm",
|
|
};
|
|
|
|
const cjsConfig: BuildOptions = {
|
|
entryPoints,
|
|
outdir: "lib/cjs",
|
|
format: "cjs",
|
|
};
|
|
|
|
if (watch) {
|
|
const esmContext = await context(esmConfig);
|
|
await esmContext.watch();
|
|
const cjsContext = await context(cjsConfig);
|
|
await cjsContext.watch();
|
|
} else {
|
|
await build(esmConfig);
|
|
await build(cjsConfig);
|
|
}
|
|
|
|
await writeFile(
|
|
"lib/cjs/package.json",
|
|
JSON.stringify({ type: "commonjs" }) + "\n",
|
|
"utf8"
|
|
);
|
|
|
|
for (const rel of assets) {
|
|
await cp(join("src", rel), join("lib", rel));
|
|
await cp(join("src", rel), join("lib/cjs", rel));
|
|
}
|
|
|
|
if (noGeneratedAsEntries) {
|
|
try {
|
|
await access("./src/__generated__");
|
|
await Promise.all([
|
|
cp("./src/__generated__", "./lib/__generated__", { recursive: true }),
|
|
cp("./src/__generated__", "./lib/cjs/__generated__", {
|
|
recursive: true,
|
|
}),
|
|
]);
|
|
} catch {
|
|
// noop
|
|
}
|
|
}
|
|
|
|
if (watch) {
|
|
// eslint-disable-next-line no-console
|
|
console.info("watching...");
|
|
} else {
|
|
// eslint-disable-next-line no-console
|
|
console.info("build succeeded");
|
|
}
|