Commit graph

29 commits

Author SHA1 Message Date
Jelle van der Waa
ad4176e4ca treewide: Enable strict equality everywhere
Making test-functions strict required some test adjustments where we
incorrectly expected an number while we receive in fact a string. As
getAttribute() returns either a string or null.
2026-11-03 17:37:17 +01:00
Allison Karlitskaya
bcbd5d0c01 cockpit-po-plugin: add a 'podir' option
This plugin assumes that the 'po' directory is located at `$SRCDIR/po`
or `./po` if `$SRCDIR` is unset.  That conflicts with our desire to be
able to run `build.js` from other directories and is also a little bit
"evil" in terms of hardcoding information about project layout.

Add an optional `podir` option to the plugin which should be set to the
`po/` path.  Set it from `build.js` for Cockpit itself.  For other users
of the plugin, we preserve the fallback of using `$SRCDIR/po` or `./po`
so that we don't break them on the next cockpitlib upgrade.  The
expectation is that everyone will migrate to providing the `podir`
option, however.
2026-11-03 10:46:22 +01:00
Allison Karlitskaya
aebeeaaa58 build.js: add a -o option for output basedir
Add a -o option (default to `.`) for where to send the output.  It will
still be split into `dist/` and `qunit/` subdirectories, but relative to
the given path instead of assuming it goes in the cwd.

Make sure we send `metafile.json` and `runtime-npm-modules.txt` to the
output directory as well.
2026-11-03 10:46:22 +01:00
Allison Karlitskaya
027ec4d836 build.js: determine srcdir via import.meta.dirname
Between `build.js` and `file.js` we determine the location of `pkg` (and
various tools that we need to invoke) in one of two ways, neither of
them particularly good:

 - they're assumed to be relative to '.', which only works if ./build.js
   is invoked from the automake srcdir.  That happens to be the case
   when pkg/Makefile.am does the invocation (it does a 'cd' first) but
   it breaks if you try to run build.js manually from a different
   directory.

 - redundantly, if `$SRCDIR` is set, this will be used in some (but not
   all) places

Let's standardize on looking at `import.meta.dirname`.  This is how node
resolves imports, so it's pretty much guaranteed to be correct (or else
the script itself wouldn't be running in the first place).  This is
an absolute pathname derived from argv[1] as passed to node (ie:
build.js itself).

For the qunit plugin, `import.meta.dirname` is the path of the plugin
itself, which makes it perfect for finding the `.template.html.in` file
located immediately adjacent to itself, saving some path gymnastics.

During our computation to create `runtime-npm-modules.txt` we need to be
careful: pathnames are based on `import.meta.dirname` now and are
therefore always absolute: we need to adjust our logic for finding paths
starting with `node_modules` to consider the relative pathname.
2026-11-03 10:46:22 +01:00
Allison Karlitskaya
af3ec756f5 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/'.
2026-11-03 10:46:22 +01:00
Marius Vollmer
bc548e3f06 build: Print unexpected errors in build.js
We want to know about running out of memory, making a programming
mistake, etc.
2026-06-16 15:08:22 +02:00
Freya Gustavsson
cbada3dc06 build: Remove RH UI icons
During builds remove RH icons from being rendered as they take up space
on the DOM tree without being rendered. Until PF makes the RH icons
default this needs to be done to reduce the import size of each icon by
more than 50%.

Signed-off-by: Freya Gustavsson <freya@venefilyn.se>
2026-06-16 15:08:22 +02:00
Freya Gustavsson
5e2e0a4ee0 build: Silence if-function deprecation from PF6
Patternfly v6 uses Sass if-functions which has been deprecated in favor
of pure CSS if-functions. However, we need to wait for Patternfly to
move to this and can't do much ourselves.

Ignoring the warnings produced is not super ideal as it catches more
than just Patternfly, but given that we don't use Sass if-functions we
should be fine.

Related-to: https://github.com/patternfly/patternfly/issues/8077
Signed-off-by: Freya Gustavsson <freya@venefilyn.se>
2026-03-17 12:32:30 +01:00
Martin Pitt
74443f5b99 build.js: Suport building without qunit
We don't want to ship qunit in our release -node tarballs, and running
them during distribution package build is also a tad too expensive. So
check if `qunit` node module is available, and skip building qunit/ if
not.
2025-11-27 12:32:45 +01:00
Martin Pitt
889f4fe646 build.js: Fall back to distribution esbuild package
When a standard import from node_modules/ fails, use `node`'s
`require()` resolution to find the path to the installed distribution
esbuild package. With that, the package can be built on Debian with just
the `tools/node-modules runtime-tar` modules (i.e. runtime dependencies
minus binary eslint).

Ported from https://github.com/cockpit-project/cockpit-files/commit/c9cb61d9393d46d4e
2025-11-27 12:32:45 +01:00
Martin Pitt
3e98bd82fb build: Only include actually bundled npm modules into the spec
Our package.json's `dependencies` has transitive/optional dependencies
which don't actually end up in the bundle, e.g. `argparse`,
`attr-accept`, or `js-tokens`; or `react-dropzone` which is a
`@patternfly/react-table` dependency, but not actually used in
cockpit.

The next commit will aggravate this further.

So make the computation of the `Provides: bundled(npm(..))` lines more
precise: Ask esbuild about which modules it actually included, which it
tells us via the "metafile". Change build.js to always output that (drop
the `--metafile` option), compute a ./runtime-npm-modules.txt list, and
use that to build the spec file.

Ported from https://github.com/cockpit-project/cockpit-files/commit/e15a518fddad1
2025-11-19 11:53:54 +01:00
Martin Pitt
3f331895b9 build: Eliminate esbuild-common.js
The only significant thing in that custom plugin was the scss hacking.
But that is now obsolete:

 * We haven't built and shipped patternfly.woff in cockpit-ws in a long
   time, so the `patternfly-icons-fake-path` thing has no effect. We can
   just use PatternFly's default.

 * Our patternfly-6-cockpit.scss already sets our font path through a
   variable, so that text transform was a no-op.

Without that, build.js can use the upstream esbuild-sass-plugin
directly.
2025-08-08 15:13:20 +02:00
Martin Pitt
f26fb391a5 build: Eliminate esbuild-plugin-copy dependency
That has a number of npm dependencies, not packaged in distros, and
annoyingly silently ignores nonexistent files.

Doing this with `fs.copyFileSync()` is easy as well, so use that
directly. The only snag is that we need to resolve the globs for the
fonts ourselves.
2025-08-08 15:13:20 +02:00
Martin Pitt
ea7804c004 build: Move to es2021
This makes String.replaceAll() available, which we use a lot.
2024-12-06 10:35:32 +01:00
Allison Karlitskaya
63e3daba75 build.js: always emit sourcemaps for qunit output
We never minify the qunit output, regardless of our devel/production
setting, so let's also unconditionally emit sourcemaps there as well.

This will be useful for an upcoming code coverage feature for QUnit
tests.
2024-08-27 17:35:49 +02:00
Allison Karlitskaya
50bb15f521 test_browser: collect coverage for qunit tests
This will collect coverage data from the test runs and write .lcov files
into `lcov/` with names like `qunit-base1-test-fsinfo-html.info.gz`.
Nothing is done with these files yet, but you can manually inspect them
using `lcov`.
2024-08-15 21:00:31 +02:00
Allison Karlitskaya
cf1cca4166 pkg/lib: clean up node imports
I was playing around a bit with deno, and it's a good deal stricter
about imports.

 - make sure we don't implicitly use node modules without imports (like
   `process.env`)

 - make sure we import node modules with their `node:` prefixed names

 - minor opportunistic cleanups around quotes and sorting

With these fixes, it's possible to say:

  deno run --allow-all --unstable-byonm build.js
2024-07-10 10:12:40 +02:00
Jelle van der Waa
9f4cda65d5 build.js: support outputting esbuild metadata file
ESbuild supports outputting a metadata file which can be used to view
bundle size information using https://esbuild.github.io/analyze/

Closes: #18267
2024-06-26 11:48:41 +02:00
Allison Karlitskaya
18ec3fa7f0 test: support typescript on qunit tests
Rename qunit-tests.js to .ts and stop hanging our functions on the main
QUnit object (which isn't typesafe).  We can just export them from our
module.  Adjust the users accordingly.

Add explicit file extensions to the list of tests in files.js (removing
the hardcoded '.js' from build.js) and add our first .ts case.

This new case tests that `cockpit.assert()` works properly in the
positive and negative cases and also verifies that it can be used for
type narrowing (otherwise tsc would complain).
2024-04-16 18:21:36 +02:00
Martin Pitt
1a28b31828 build: Drop ESLint from esbuild
Similar to what commit c9ac6736b3 did for stylelint, move
ESLint to static code checks as well. It already runs from there (and
actually correctly since the previous commit).
2024-02-07 18:35:09 +01:00
Martin Pitt
c9ac6736b3 build: Move stylelint to test/static-code
stylelint 16 causes a deadlock/crash in esbuild [1]. There's no movement
on that issue, and we want stylelint 16 to be able to support the
Browser Baseline 2023.

So let's give up, and untangle stylelint from esbuild. We can just as
well call it from our static code checks. The main developer regression
is that the feedback cycle is faster in build.js watch mode than calling
test/static-code, but these days with IDE integration (like ALE) that
should hopefully not matter that much.

As we use `git ls-files` now, this also starts to cover files in doc/
and test/. Ignore the former for now, let's fix these separately.

[1] https://github.com/evanw/esbuild/issues/3542
2024-02-07 15:59:17 +01:00
Martin Pitt
0a51a881c3 build.js: Run rsync plugin also for $RSYNC env variable
starter-kit and derivatives don't understand the build.js `-r` option,
only the environment variable. So properly handle the latter, and update
the documentation to use the env variable, to get  a common workflow for
all our projects.

Also fix the destination path, the rsync plugin moved to
/usr/local/share/cockpit some time ago.
2023-05-26 13:26:54 +02:00
Katerina Koukiou
5e341a2c1f build: fix source map generation
They now correctly appear - at least for firefox.
2023-04-18 13:43:52 +02:00
Martin Pitt
9e6a43c16d build.js: Drop obsolete --config option
webpack.config.js is not a thing any more.
2023-03-28 08:24:05 +02:00
Katerina Koukiou
6073b2703a build: Move stylesheet processing into pkg/lib/build-common.js to enable reusing
There are some quite delibarate hacks there, it worths to export these
so that other projects can keep in sync with cockpit more easily.
2023-03-28 06:26:40 +02:00
Katerina Koukiou
584c9a3cac build.js: apply hack with PF fix for failing pixel tests
Patternfly-react is in freeze right now, essentially till June when v5
is first released. This is a super hacky work around - but better than
having UI regressions.

This can be undone once patternfly with
https://github.com/patternfly/patternfly-react/pull/8864 is released.
2023-03-27 15:22:36 +02:00
Katerina Koukiou
fe89f2eff5 build.js: Move our front end build tool from webpack to esbuild
We don't need the `$ESLINT`/`$STYLELINT` env variables any more to
coordinate between build.js and webpack-config.js, as everything is in
build.js now. Update HACKING.md accordingly.

Implement our own watch mode due to the deficiencies of esbuild's [1].
This is similar to podman's [2], but with recursive watching.

Because the approach for redefining breakpoints changed, update pixel
tests for the spacing noise.

Co-Authored-By: Martin Pitt <mpitt@redhat.com>

Fixes #17629

[1] https://github.com/evanw/esbuild/issues/1204#issuecomment-1482909251
[2] https://github.com/cockpit-project/cockpit-podman/pull/1243
2023-03-27 15:22:36 +02:00
Martin Pitt
5e3a892d4c Update documentation and comments to not be webpack specific
webpack is an implementation detail and soon change to esbuild. Make the
verbiage more neutral.
2023-03-22 08:07:00 +01:00
Martin Pitt
4b97d35bfa Rename tools/webpack-make.js to ./build.js
This is our primary and only interaction point with building bundles, so it
should be in the top-level directory. Also, we are going to switch to esbuild
soon, so naming it "webpack" will be confusing. Move it to ./build.js like
cockpit-podman already did.

Keep tools/webpack-{make.js,watch} as a shell shim for a little while, which
points to the new tool and the documentation.
2023-03-21 15:51:31 +01:00