config/knip.scripts-exports.config.ts
Rama main · réplica de lectura del repositorio original.
/**
* Entry-export audit for repository scripts.
*
* Production configuration already owns the executable script roots. This
* companion pass keeps the rest of scripts/** as library project files and
* makes repository tests real consumers of deliberately testable helpers.
*/
import fs from "node:fs";
import productionConfig from "./knip.config.ts";
function isTypedShimImplementationEntry(entry: string): boolean {
const filePath = entry.endsWith("!") ? entry.slice(0, -1) : entry;
// The export-free Crabbox implementation must remain a root so its library imports stay live.
if (!filePath.endsWith(".mts") || filePath === "scripts/crabbox-wrapper.mts") {
return false;
}
const basePath = filePath.slice(0, -".mts".length);
return fs.existsSync(`${basePath}.mjs`) || fs.existsSync(`${basePath}.js`);
}
const scriptEntries = productionConfig.workspaces["."].entry.filter(
(entry) => entry.startsWith("scripts/") && !isTypedShimImplementationEntry(entry),
);
const repositoryToolEntries = [
// Knip loads this configuration, which consumes the Vite runnerImport compiler.
"config/knip.config.ts!",
// This compiler projects exact source-derived generated and module-hook imports.
"config/knip-dynamic-consumers.mjs!",
// ui/config/control-ui-locales.ts invokes the catalogue through Vite's runnerImport.
"config/knip-vite-consumers.mjs!",
".github/actions/setup-node-env/dependency-fingerprint.mjs!",
".github/workflows/labeler.yml!",
".github/workflows/openclaw-release-publish.yml!",
".github/workflows/plugin-prerelease.yml!",
"apps/android/scripts/build-release-artifacts.ts!",
"security/opengrep/check-rule-metadata.mjs!",
"security/opengrep/compile-rules.mjs!",
"skills/meme-maker/scripts/meme.mjs!",
"scripts/check-openclaw-package-tarball.mts!",
] as const;
const sourceTestConsumerEntries = [
"src/scripts/docs-link-audit.test.ts!",
"src/scripts/ci-changed-scope.contract-fixtures.test.ts!",
"src/scripts/ci-changed-scope.control-ui.test.ts!",
"src/scripts/ci-changed-scope.git-owner.test.ts!",
"src/scripts/ci-changed-scope.native-i18n.test.ts!",
"src/scripts/ci-changed-scope.test.ts!",
"src/scripts/ci-changed-scope.windows.test.ts!",
"src/scripts/ci-ios-screenshot-scope.test.ts!",
"src/plugins/prune-docker-plugin-dist.test.ts!",
"src/infra/package-update-activation-lifetime.test.ts!",
] as const;
const config = {
compilers: productionConfig.compilers,
ignoreWorkspaces: [
"apps/**",
"extensions/**",
...fs
.readdirSync("packages")
.filter((name) => name !== "gateway-protocol")
.map((name) => `packages/${name}`),
"ui",
],
ignore: [
"scripts/**/*.d.{mts,cts,ts}",
"scripts/**/*.test-support.{js,mjs,cjs,ts,mts,cts}",
// Generated declaration companions; application scans own their executable validators.
"packages/gateway-protocol/src/compiled/sender-identity.d.ts",
"packages/gateway-protocol/src/compiled/protocol.generated/*.d.ts",
],
// Script entrypoints import core and Plugin SDK APIs. Those owners are
// checked by the application scans; this pass owns only scripts/** exports.
ignoreIssues: {
// These executable modules are also loaded through variable/file-URL imports
// by build or subprocess test harnesses, which Knip cannot resolve statically.
"scripts/diffs-shiki-curated.ts": [
"exports",
"nsExports",
"types",
"nsTypes",
"enumMembers",
"namespaceMembers",
],
"scripts/e2e/lib/bundled-plugin-install-uninstall/runtime-smoke.mjs": [
"exports",
"nsExports",
"types",
"nsTypes",
"enumMembers",
"namespaceMembers",
],
// Oxlint consumes this required default export through a JSON config path.
"scripts/oxlint-boundary-guards.mjs": ["exports"],
// Oxlint consumes this required default export through a JSON config path.
"tools/solid-lint/index.mjs": ["exports"],
// Vitest consumes this required default export through the reporter CLI path.
"scripts/lib/vitest-resource-reporter.mts": ["exports"],
// Vitest loads this default class through the report owner's CLI and generated merge config.
"scripts/lib/vitest-report-capture.mts": ["exports"],
// Wrangler consumes the Worker default export and instantiates the Durable
// Object class by name from wrangler.jsonc; Knip cannot resolve either.
"scripts/cloudflare/src/index.ts": ["exports"],
"scripts/cloudflare/src/container.ts": ["exports"],
"src/**": ["exports", "nsExports", "types", "nsTypes", "enumMembers", "namespaceMembers"],
"test/**": ["exports", "nsExports", "types", "nsTypes", "enumMembers", "namespaceMembers"],
},
workspaces: {
".": {
// These opt-in commands pass non-default Vitest configs. Let Knip's
// Vitest owner load the configs and their selected suites as real inputs.
vitest: {
config: [
"scripts/control-ui-parity/vitest.config.ts",
"scripts/control-ui-retention/vitest.config.ts",
],
},
entry: [
...scriptEntries,
...repositoryToolEntries,
...sourceTestConsumerEntries,
".agents/skills/**/scripts/**/*.{js,mjs,cjs,ts,mts,cts}!",
"scripts/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts}!",
"test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts}!",
// CLI subprocess fixtures consume the shared native-report collector.
"src/cli/cli-process-child.test-helpers.test.ts!",
// Core bootstrap packaging and source updates consume shared script owners.
"src/gateway/worker-environments/node-bootstrap-artifact.ts!",
"src/infra/package-dist-inventory.ts!",
"src/plugin-sdk/api-baseline.ts!",
"src/cli/update-cli/update-command-{git-admission,runtime}.ts!",
],
project: [
".github/actions/**/*.{js,mjs,cjs,ts,mts,cts}!",
".agents/skills/**/scripts/**/*.{js,mjs,cjs,ts,mts,cts}!",
"apps/android/scripts/**/*.{js,mjs,cjs,ts,mts,cts}!",
"security/**/*.{js,mjs,cjs,ts,mts,cts}!",
"skills/**/*.{js,mjs,cjs,ts,mts,cts}!",
"scripts/**/*.{js,mjs,cjs,ts,mts,cts}!",
"test/**/*.{js,mjs,cjs,ts,mts,cts}!",
...sourceTestConsumerEntries,
"src/cli/cli-process-child.test-helpers{,.test}.ts!",
"src/gateway/worker-environments/node-bootstrap-artifact.ts!",
"src/infra/package-dist-inventory.ts!",
"src/plugin-sdk/api-baseline.ts!",
"src/cli/update-cli/update-command-{git-admission,runtime}.ts!",
],
},
"packages/gateway-protocol": {
entry: ["scripts/native-codegen.ts!"],
project: ["scripts/native-codegen.ts!"],
},
},
};
export default config;