pkg/lib, build.js: DRY on 'dist/'

Stop hardcoding 'dist/' all over the place.  We already do it once in
the esbuild configuration blob, and that's enough.  The other places
(and particularly the plugins) should be reading it from there.

For the qunit plugin, remove a hardcoded instance of 'qunit/'.
This commit is contained in:
Allison Karlitskaya 2026-11-02 12:44:14 +01:00 committed by Allison Karlitskaya
parent 11b0b90ff1
commit af3ec756f5
4 changed files with 6 additions and 6 deletions

View file

@ -179,7 +179,7 @@ async function build() {
setup(build) {
build.onEnd(() => {
for (const file of [...assetFiles, ...redhat_fonts]) {
const destDir = path.join('./dist', file.to);
const destDir = path.join(pkgOptions.outdir, file.to);
fs.mkdirSync(destDir, { recursive: true });
fs.copyFileSync(file.from, path.join(destDir, path.basename(file.from)));
}
@ -202,7 +202,7 @@ async function build() {
},
...(args.rsync || process.env.RSYNC)
? [cockpitRsyncEsbuildPlugin({ source: "dist/" + (args.onlydir || '') })]
? [cockpitRsyncEsbuildPlugin({ source: `${pkgOptions.outdir}/${args.onlydir || ''}` })]
: [],
];

View file

@ -3,12 +3,12 @@ import fs from 'node:fs';
import path from 'node:path';
// always start with a fresh dist/ directory, to change between development and production, or clean up gzipped files
export const cleanPlugin = ({ outdir = './dist', subdir = '' } = {}) => ({
export const cleanPlugin = ({ subdir = '' } = {}) => ({
name: 'clean-dist',
setup(build) {
build.onStart(() => {
try {
fs.rmSync(path.resolve(outdir, subdir), { recursive: true });
fs.rmSync(path.resolve(build.initialOptions.outdir, subdir), { recursive: true });
} catch (e) {
if (e.code !== 'ENOENT')
throw e;

View file

@ -35,7 +35,7 @@ export const cockpitCompressPlugin = ({ subdir = '', exclude = null } = {}) => (
setup(build) {
build.onEnd(async () => {
const gzipPromises = [];
const outpath = "./dist/" + subdir;
const outpath = `${build.initialOptions.outdir}/${subdir}`;
for await (const dirent of getAllFiles(outpath)) {
if (exclude && exclude.test(dirent))

View file

@ -18,7 +18,7 @@ export const cockpitTestHtmlPlugin = ({ testFiles }) => ({
.replaceAll("%title%", test)
.replaceAll("%builddir%", builddir)
.replaceAll("%script%", test + '.js');
const outdir = './qunit/' + path.dirname(file);
const outdir = path.join(build.initialOptions.outdir, path.dirname(file));
const outfile = test + ".html";
fs.mkdirSync(outdir, { recursive: true });