web/NPM Workspaces: ESbuild version cleanup (#14541)
* web: Check JS files. Add types. * web: Fix issues surrounding Vite/ESBuild types. * web: Clean up version constants. Tidy types * web: Clean up docs, types. * web: Clean up package paths. * web: (ESLint) no-lonely-if * web: Render slot before navbar. * web: Fix line-height alignment. * web: Truncate long headers. * web: Clean up page header declarations. Add story. Update paths. * web: Ignore out directory. * web: Lint Lit. * web: Use private alias. * web: Fix implicit CJS mode. * web: Update deps. * web: await all imports.
This commit is contained in:
@ -1,17 +1,33 @@
|
||||
import { spawnSync } from "child_process";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import process from "process";
|
||||
/**
|
||||
* @file Lit Localize build script.
|
||||
*
|
||||
* @remarks
|
||||
* Determines if all the Xliff translation source files are present and
|
||||
* if the Typescript source files generated from those sources are up-to-date.
|
||||
*
|
||||
* If they are not, it runs the locale building script, intercepting the
|
||||
* long spew of "this string is not translated" and replacing it with a
|
||||
* summary of how many strings are missing with respect to the source locale.
|
||||
*
|
||||
* @import { ConfigFile } from "@lit/localize-tools/lib/types/config"
|
||||
*/
|
||||
import { PackageRoot } from "#paths/node";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { readFileSync, statSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
/**
|
||||
* Determines if all the Xliff translation source files are present and if the Typescript source
|
||||
* files generated from those sources are up-to-date. If they are not, it runs the locale building
|
||||
* script, intercepting the long spew of "this string is not translated" and replacing it with a
|
||||
* summary of how many strings are missing with respect to the source locale.
|
||||
* @type {ConfigFile}
|
||||
*/
|
||||
const localizeRules = JSON.parse(
|
||||
readFileSync(path.join(PackageRoot, "lit-localize.json"), "utf-8"),
|
||||
);
|
||||
|
||||
const localizeRules = JSON.parse(fs.readFileSync("./lit-localize.json", "utf-8"));
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} loc
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function generatedFileIsUpToDateWithXliffSource(loc) {
|
||||
const xliff = path.join("./xliff", `${loc}.xlf`);
|
||||
const gened = path.join("./src/locales", `${loc}.ts`);
|
||||
@ -22,7 +38,7 @@ function generatedFileIsUpToDateWithXliffSource(loc) {
|
||||
// generates a unique error message and halts the build.
|
||||
|
||||
try {
|
||||
var xlfStat = fs.statSync(xliff);
|
||||
var xlfStat = statSync(xliff);
|
||||
} catch (_error) {
|
||||
console.error(`lit-localize expected '${loc}.xlf', but XLF file is not present`);
|
||||
process.exit(1);
|
||||
@ -30,7 +46,7 @@ function generatedFileIsUpToDateWithXliffSource(loc) {
|
||||
|
||||
// If the generated file doesn't exist, of course it's not up to date.
|
||||
try {
|
||||
var genedStat = fs.statSync(gened);
|
||||
var genedStat = statSync(gened);
|
||||
} catch (_error) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
/// <reference types="../types/esbuild.js" />
|
||||
/**
|
||||
* @file ESBuild script for building the authentik web UI.
|
||||
*
|
||||
* @import { BuildOptions } from "esbuild";
|
||||
*/
|
||||
import { mdxPlugin } from "#bundler/mdx-plugin/node";
|
||||
import { createBundleDefinitions } from "#bundler/utils/node";
|
||||
import { DistDirectory, DistDirectoryName, EntryPoint, PackageRoot } from "#paths/node";
|
||||
import { NodeEnvironment } from "@goauthentik/core/environment/node";
|
||||
import { MonoRepoRoot, resolvePackage } from "@goauthentik/core/paths/node";
|
||||
import { readBuildIdentifier } from "@goauthentik/core/version/node";
|
||||
import { liveReloadPlugin } from "@goauthentik/esbuild-plugin-live-reload/plugin";
|
||||
import {
|
||||
MonoRepoRoot,
|
||||
NodeEnvironment,
|
||||
readBuildIdentifier,
|
||||
resolvePackage,
|
||||
serializeEnvironmentVars,
|
||||
} from "@goauthentik/monorepo";
|
||||
import { DistDirectory, DistDirectoryName, EntryPoint, PackageRoot } from "@goauthentik/web/paths";
|
||||
import { deepmerge } from "deepmerge-ts";
|
||||
import esbuild from "esbuild";
|
||||
import copy from "esbuild-plugin-copy";
|
||||
@ -19,17 +18,9 @@ import { polyfillNode } from "esbuild-plugin-polyfill-node";
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as path from "node:path";
|
||||
|
||||
import { mdxPlugin } from "./esbuild/build-mdx-plugin.mjs";
|
||||
|
||||
const logPrefix = "[Build]";
|
||||
|
||||
const definitions = serializeEnvironmentVars({
|
||||
NODE_ENV: NodeEnvironment,
|
||||
CWD: process.cwd(),
|
||||
AK_API_BASE_PATH: process.env.AK_API_BASE_PATH,
|
||||
});
|
||||
|
||||
const patternflyPath = resolvePackage("@patternfly/patternfly");
|
||||
const patternflyPath = resolvePackage("@patternfly/patternfly", import.meta);
|
||||
|
||||
/**
|
||||
* @type {Readonly<BuildOptions>}
|
||||
@ -86,7 +77,7 @@ const BASE_ESBUILD_OPTIONS = {
|
||||
root: MonoRepoRoot,
|
||||
}),
|
||||
],
|
||||
define: definitions,
|
||||
define: createBundleDefinitions(),
|
||||
format: "esm",
|
||||
logOverride: {
|
||||
/**
|
||||
@ -168,6 +159,19 @@ async function doWatch() {
|
||||
await buildContext.rebuild();
|
||||
await buildContext.watch();
|
||||
|
||||
const httpURL = new URL("http://localhost");
|
||||
httpURL.port = process.env.COMPOSE_PORT_HTTP ?? "9000";
|
||||
|
||||
const httpsURL = new URL("http://localhost");
|
||||
httpsURL.port = process.env.COMPOSE_PORT_HTTPS ?? "9443";
|
||||
|
||||
console.log(`\n${logPrefix} 🚀 Server running\n\n`);
|
||||
|
||||
console.log(` 🔓 ${httpURL.href}`);
|
||||
console.log(` 🔒 ${httpsURL.href}`);
|
||||
|
||||
console.log(`\n---`);
|
||||
|
||||
return /** @type {Promise<void>} */ (
|
||||
new Promise((resolve) => {
|
||||
process.on("SIGINT", () => {
|
||||
|
@ -1,81 +0,0 @@
|
||||
/**
|
||||
* @import {
|
||||
OnLoadArgs,
|
||||
OnLoadResult,
|
||||
Plugin,
|
||||
PluginBuild
|
||||
* } from 'esbuild'
|
||||
*/
|
||||
import * as fs from "node:fs/promises";
|
||||
import * as path from "node:path";
|
||||
|
||||
/**
|
||||
* @typedef {Omit<OnLoadArgs, 'pluginData'> & LoadDataFields} LoadData
|
||||
* Data passed to `onload`.
|
||||
*
|
||||
* @typedef LoadDataFields
|
||||
* Extra fields given in `data` to `onload`.
|
||||
* @property {PluginData | null | undefined} [pluginData]
|
||||
* Plugin data.
|
||||
*
|
||||
*
|
||||
* @typedef PluginData
|
||||
* Extra data passed.
|
||||
* @property {Buffer | string | null | undefined} [contents]
|
||||
* File contents.
|
||||
*/
|
||||
|
||||
const name = "mdx-plugin";
|
||||
|
||||
/**
|
||||
* @typedef MDXPluginOptions
|
||||
*
|
||||
* @property {string} root Root directory.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Bundle MDX into JSON modules.
|
||||
*
|
||||
* @param {MDXPluginOptions} options Options.
|
||||
* @returns {Plugin} Plugin.
|
||||
*/
|
||||
export function mdxPlugin({ root }) {
|
||||
return { name, setup };
|
||||
|
||||
/**
|
||||
* @param {PluginBuild} build
|
||||
* Build.
|
||||
* @returns {undefined}
|
||||
* Nothing.
|
||||
*/
|
||||
function setup(build) {
|
||||
build.onLoad({ filter: /\.mdx?$/ }, onload);
|
||||
|
||||
/**
|
||||
* @param {LoadData} data
|
||||
* Data.
|
||||
* @returns {Promise<OnLoadResult>}
|
||||
* Result.
|
||||
*/
|
||||
async function onload(data) {
|
||||
const content = String(
|
||||
data.pluginData &&
|
||||
data.pluginData.contents !== null &&
|
||||
data.pluginData.contents !== undefined
|
||||
? data.pluginData.contents
|
||||
: await fs.readFile(data.path),
|
||||
);
|
||||
|
||||
const publicPath = path.resolve(
|
||||
"/",
|
||||
path.relative(path.join(root, "website"), data.path),
|
||||
);
|
||||
const publicDirectory = path.dirname(publicPath);
|
||||
|
||||
return {
|
||||
contents: JSON.stringify({ content, publicPath, publicDirectory }),
|
||||
loader: "file",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -35,6 +35,11 @@ const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||
const projectRoot = path.join(__dirname, "..");
|
||||
process.chdir(projectRoot);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string[]} flags
|
||||
* @returns
|
||||
*/
|
||||
const hasFlag = (flags) => process.argv.length > 1 && flags.includes(process.argv[2]);
|
||||
|
||||
const [configFile, files] = hasFlag(["-n", "--nightmare"])
|
||||
|
@ -152,6 +152,7 @@ export default [
|
||||
{
|
||||
ignores: [
|
||||
"dist/",
|
||||
"out/",
|
||||
".wireit/",
|
||||
"packages/",
|
||||
// don't ever lint node_modules
|
||||
|
@ -1,22 +1,36 @@
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
/**
|
||||
* @file Pseudo-localization script.
|
||||
*
|
||||
* @import { ConfigFile } from "@lit/localize-tools/lib/types/config.js"
|
||||
* @import { Config } from '@lit/localize-tools/lib/types/config.js';
|
||||
* @import { ProgramMessage } from "@lit/localize-tools/src/messages.js"
|
||||
* @import { Locale } from "@lit/localize-tools/src/types/locale.js"
|
||||
*/
|
||||
import { PackageRoot } from "#paths/node";
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import pseudolocale from "pseudolocale";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
import { makeFormatter } from "@lit/localize-tools/lib/formatters/index.js";
|
||||
import { sortProgramMessages } from "@lit/localize-tools/lib/messages.js";
|
||||
import { TransformLitLocalizer } from "@lit/localize-tools/lib/modes/transform.js";
|
||||
|
||||
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
||||
const pseudoLocale = "pseudo-LOCALE";
|
||||
const pseudoLocale = /** @type {Locale} */ ("pseudo-LOCALE");
|
||||
const targetLocales = [pseudoLocale];
|
||||
const baseConfig = JSON.parse(readFileSync(path.join(__dirname, "../lit-localize.json"), "utf-8"));
|
||||
|
||||
/**
|
||||
* @type {ConfigFile}
|
||||
*/
|
||||
const baseConfig = JSON.parse(readFileSync(path.join(PackageRoot, "lit-localize.json"), "utf-8"));
|
||||
|
||||
// Need to make some internal specifications to satisfy the transformer. It doesn't actually matter
|
||||
// which Localizer we use (transformer or runtime), because all of the functionality we care about
|
||||
// is in their common parent class, but I had to pick one. Everything else here is just pure
|
||||
// exploitation of the lit/localize-tools internals.
|
||||
|
||||
/**
|
||||
* @satisfies {Config}
|
||||
*/
|
||||
const config = {
|
||||
...baseConfig,
|
||||
baseDir: path.join(__dirname, ".."),
|
||||
@ -28,6 +42,11 @@ const config = {
|
||||
resolve: (path) => path,
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {ProgramMessage} message
|
||||
* @returns
|
||||
*/
|
||||
const pseudoMessagify = (message) => ({
|
||||
name: message.name,
|
||||
contents: message.contents.map((content) =>
|
||||
@ -36,7 +55,7 @@ const pseudoMessagify = (message) => ({
|
||||
});
|
||||
|
||||
const localizer = new TransformLitLocalizer(config);
|
||||
const messages = localizer.extractSourceMessages().messages;
|
||||
const { messages } = localizer.extractSourceMessages();
|
||||
const translations = messages.map(pseudoMessagify);
|
||||
const sorted = sortProgramMessages([...messages]);
|
||||
const formatter = makeFormatter(config);
|
||||
|
Reference in New Issue
Block a user