Files
heroui-vue/scripts/check-package.mjs
T
maoyingjie dc859fb8ae feat(styles): export shared field variant maps and restore the border fallback
HD-05 scope, against heroui ce90ea3 styles sources:

- add labelVariants/descriptionVariants/fieldErrorVariants/
  textFieldVariants/switchGroupVariants (+ VariantProps types) to
  @heroui-vue/styles and re-export them from @heroui-vue/components;
  variant keys, defaultVariants and slot sets match the pinned
  *.styles.ts files key for key (hv- namespace only)
- Label/Description/FieldError/useTextField/SwitchGroup now consume
  those mappings instead of inline class strings, so the state classes
  have a single source; rendered class output is unchanged and pinned
  by tests/shared-field-styles.test.ts (mapping output <-> component
  output)
- restore the global border-color fallback
  (*, ::after, ::before, ::backdrop, ::file-selector-button ->
  border-color: var(--border, currentColor)) in a new base/base.css,
  imported layer(base) right after preflight like the pinned entry:
  a low-priority default that components, utilities and consumer CSS
  override without !important
- view-transition globals from the pinned base.css stay unported: no
  View Transitions API usage exists in the library or docs site
- shared-styles package contract: packed runtime exports from both
  entries, variant-output assertions, CSS tokens incl. the fallback,
  strict nodenext+bundler type contract, and a real-browser consumer
  fixture (light/dark --border, explicit colors, consumer overrides,
  currentColor fallback) wired into check-package.mjs
- docs: styling layers/border fallback/exports notes, five component
  API pages, compatibility matrix and upstream source records

Full suite 111 files / 1634 tests, typecheck and build:docs pass;
shared-styles + api-root-aliases + handbook-styles verified against
the final tarballs.
2026-10-28 23:36:59 +08:00

133 lines
4.2 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
import os from "node:os";
import { spawnSync } from "node:child_process";
const root = path.resolve(import.meta.dirname, "..");
const fixtures = path.join(root, "tests/package");
const args = process.argv.slice(2);
const offline = args.includes("--offline");
const ids = args.filter((arg) => arg !== "--offline");
const specs = JSON.parse(
fs.readFileSync(path.join(fixtures, "client-checks.json"), "utf8"),
);
if (!ids.length || ids.some((id) => !Object.hasOwn(specs, id))) {
console.error(
`Usage: node scripts/check-package.mjs <${Object.keys(specs).join("|")}> [...] [--offline]`,
);
process.exit(1);
}
// Every run consumes final tarballs outside the workspace: no source paths/alias.
// Keep this directory for optional browser checks; never start a server here.
const consumer = fs.realpathSync(
fs.mkdtempSync(path.join(os.tmpdir(), "heroui-client-package-")),
);
console.log(`Independent consumer: ${consumer}`);
function run(bin, argv, cwd = root) {
const result = spawnSync(bin, argv, { cwd, stdio: "inherit", shell: false });
if (result.error) throw result.error;
if (result.status !== 0) throw new Error(`${bin} exited ${result.status}`);
}
run("pnpm", ["build"]);
const tarballs = {};
for (const pkg of ["styles", "vue"]) {
run(
"pnpm",
["pack", "--pack-destination", consumer],
path.join(root, "packages", pkg),
);
const manifest = JSON.parse(
fs.readFileSync(path.join(root, "packages", pkg, "package.json"), "utf8"),
);
tarballs[manifest.name] =
`file:./${manifest.name.replace(/^@/, "").replaceAll("/", "-")}-${manifest.version}.tgz`;
}
const installedVersion = (pkg) =>
JSON.parse(
fs.readFileSync(
path.join(root, "node_modules", pkg, "package.json"),
"utf8",
),
).version;
fs.writeFileSync(
path.join(consumer, "package.json"),
JSON.stringify(
{
name: "heroui-client-consumer",
private: true,
type: "module",
dependencies: {
...tarballs,
vue: installedVersion("vue"),
"@internationalized/date": installedVersion("@internationalized/date"),
},
devDependencies: { typescript: installedVersion("typescript") },
},
null,
2,
),
);
fs.writeFileSync(
path.join(consumer, "pnpm-workspace.yaml"),
`overrides:\n "@heroui-vue/styles": ${JSON.stringify(tarballs["@heroui-vue/styles"])}\n`,
);
for (const name of ["check-client.mjs", "client-checks.json"])
fs.copyFileSync(path.join(fixtures, name), path.join(consumer, name));
const contracts = ids
.map((id) => `${id}-contract.ts`)
.filter((file) => fs.existsSync(path.join(fixtures, file)));
for (const file of contracts)
fs.copyFileSync(path.join(fixtures, file), path.join(consumer, file));
run("pnpm", ["install", ...(offline ? ["--offline"] : [])], consumer);
run(process.execPath, ["check-client.mjs", ...ids], consumer);
if (contracts.length) {
const tsc = path.join(consumer, "node_modules/typescript/bin/tsc");
for (const [module, resolution] of [
["nodenext", "nodenext"],
["esnext", "bundler"],
])
run(
process.execPath,
[
tsc,
"--noEmit",
"--strict",
"--skipLibCheck",
"--target",
"es2022",
"--module",
module,
"--moduleResolution",
resolution,
...contracts,
],
consumer,
);
}
const browser = ids.includes("b02-pickers")
? "b02"
: ids.includes("b01-menu-dropdown")
? "b01"
: ids.includes("color-picker")
? "color-picker"
: ids.includes("shared-styles")
? "shared-styles"
: null;
if (browser) {
for (const file of ["index.html", "main.js", "style.css"])
fs.copyFileSync(
path.join(fixtures, `${browser}-consumer-app`, file),
path.join(consumer, file),
);
fs.copyFileSync(
path.join(fixtures, "b02-consumer-app", "vite.config.js"),
path.join(consumer, "vite.config.js"),
);
console.log(
`${browser.toUpperCase()} browser fixture prepared. Optional: cd ${consumer} && ${path.join(root, "node_modules/.bin/vite")} --host 127.0.0.1 --port <free-port> --strictPort`,
);
}
console.log(
`Package checks passed: ${ids.join(", ")}. No SSR/hydration checks or server started.`,
);