Files
openclaw/scripts/lib/extension-source-classifier.mts
Peter Steinberger c70aee247e refactor(scripts): migrate JavaScript tools to TypeScript (#121005)
* refactor(scripts): migrate JavaScript tools to TypeScript

* fix(ci): keep changed-scope preflight zero-install

* fix(ci): preserve zero-install script owners

* fix(ci): complete script migration follow-through

* fix(release): keep stable closeout zero-install

* fix(scripts): preserve standalone execution boundaries

* fix(scripts): repair standalone loader boundaries

* fix(scripts): normalize gateway observation ids

* fix(scripts): keep Docker packager standalone

* test(scripts): preserve rebase cleanup helpers

* test(sessions): use tracked temp directory
2026-08-09 07:21:35 -07:00

47 lines
2.2 KiB
TypeScript

// Classifies bundled extension files as production, barrel, test-like, or infra artifacts.
const CODE_FILE_RE = /\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const DECLARATION_FILE_RE = /\.d\.ts$/u;
const RUNTIME_API_BARREL_RE = /(^|\/)runtime-api\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const PUBLIC_API_BARREL_RE = /(^|\/)api\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const TEST_LIKE_SEGMENT_RE =
/(^|\/)(?:__tests__|fixtures|test|tests|test-fixtures|test-support|test-utils)(?:\/|$)/u;
const TEST_LIKE_FILENAME_RE =
/(^|\/)[^/]*test-(?:support|helpers|fixtures|harness)\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const TEST_SHARED_FILENAME_RE = /(^|\/)[^/]*\.test-[^/]*\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const TEST_CANARY_FILENAME_RE = /(^|\/)__rootdir_boundary_canary__\.(?:[cm]?ts|[cm]?js|tsx|jsx)$/u;
const SNAPSHOT_FILE_RE = /\.snap$/u;
const SUFFIX_SKIP_RE = /\.(?:test|spec|fixture)\./u;
const INFRA_DIR_RE = /(^|\/)(?:coverage|dist|node_modules)(?:\/|$)/u;
const INFRA_NAME_RE = /(test-harness|test-support|test-helpers|test-fixtures)/u;
function normalizeExtensionSourcePath(filePath: string) {
return filePath.replaceAll("\\", "/");
}
/** Classify one bundled extension source path for boundary and packaging guards. */
export function classifyBundledExtensionSourcePath(filePath: string) {
const normalizedPath = normalizeExtensionSourcePath(filePath);
const isCodeFile = CODE_FILE_RE.test(normalizedPath) && !DECLARATION_FILE_RE.test(normalizedPath);
const isRuntimeApiBarrel = RUNTIME_API_BARREL_RE.test(normalizedPath);
const isPublicApiBarrel = PUBLIC_API_BARREL_RE.test(normalizedPath);
const isTestLike =
TEST_LIKE_SEGMENT_RE.test(normalizedPath) ||
TEST_LIKE_FILENAME_RE.test(normalizedPath) ||
TEST_SHARED_FILENAME_RE.test(normalizedPath) ||
TEST_CANARY_FILENAME_RE.test(normalizedPath) ||
SUFFIX_SKIP_RE.test(normalizedPath) ||
SNAPSHOT_FILE_RE.test(normalizedPath) ||
INFRA_NAME_RE.test(normalizedPath);
const isInfraArtifact = INFRA_DIR_RE.test(normalizedPath);
return {
normalizedPath,
isCodeFile,
isRuntimeApiBarrel,
isPublicApiBarrel,
isTestLike,
isInfraArtifact,
isProductionSource: isCodeFile && !isRuntimeApiBarrel && !isTestLike && !isInfraArtifact,
};
}