Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
197 lines
5.9 KiB
JavaScript
197 lines
5.9 KiB
JavaScript
// Scans packaged dist JavaScript for relative imports and missing closure entries.
|
|
import path from "node:path";
|
|
|
|
const JS_DIST_FILE_RE = /^dist\/.*\.(?:cjs|js|mjs)$/u;
|
|
|
|
function normalizePackagePath(value) {
|
|
return value.replace(/\\/gu, "/").replace(/^package\//u, "");
|
|
}
|
|
|
|
function stripSpecifierSuffix(value) {
|
|
return value.replace(/[?#].*$/u, "");
|
|
}
|
|
|
|
function hasJavaScriptFileExtension(value) {
|
|
return /\.(?:cjs|js|mjs)$/u.test(path.posix.basename(stripSpecifierSuffix(value)));
|
|
}
|
|
|
|
function resolveDistImportPath(importerPath, specifier) {
|
|
if (!specifier.startsWith(".")) {
|
|
return null;
|
|
}
|
|
const stripped = stripSpecifierSuffix(specifier);
|
|
if (!stripped) {
|
|
return null;
|
|
}
|
|
return path.posix.normalize(path.posix.join(path.posix.dirname(importerPath), stripped));
|
|
}
|
|
|
|
function findStatementStart(source, index) {
|
|
return (
|
|
Math.max(
|
|
source.lastIndexOf(";", index),
|
|
source.lastIndexOf("{", index),
|
|
source.lastIndexOf("}", index),
|
|
source.lastIndexOf("\n", index),
|
|
source.lastIndexOf("\r", index),
|
|
) + 1
|
|
);
|
|
}
|
|
|
|
function isImportSpecifierContext(source, index) {
|
|
const dynamicPrefix = source.slice(Math.max(0, index - 32), index);
|
|
if (/\bimport\s*\(\s*$/u.test(dynamicPrefix)) {
|
|
return true;
|
|
}
|
|
const statementPrefix = source.slice(findStatementStart(source, index), index).trimStart();
|
|
return (
|
|
/^(?:import|export)\b[\s\S]*\bfrom\s*$/u.test(statementPrefix) ||
|
|
/^import\s*$/u.test(statementPrefix)
|
|
);
|
|
}
|
|
|
|
function isRequireSpecifierContext(source, index) {
|
|
const prefix = source.slice(Math.max(0, index - 32), index);
|
|
return /\brequire\s*\(\s*$/u.test(prefix);
|
|
}
|
|
|
|
function isImportMetaUrlContext(source, quoteStart, quoteEnd) {
|
|
const prefix = source.slice(Math.max(0, quoteStart - 32), quoteStart);
|
|
if (!/\bnew\s+URL\s*\(\s*$/u.test(prefix)) {
|
|
return false;
|
|
}
|
|
const suffix = source.slice(quoteEnd + 1, quoteEnd + 96);
|
|
return /^\s*,\s*import\.meta\.url\s*,?\s*\)/u.test(suffix);
|
|
}
|
|
|
|
function collectImportSpecifiers(source) {
|
|
const specifiers = [];
|
|
let inBlockComment = false;
|
|
let inLineComment = false;
|
|
for (let index = 0; index < source.length; index += 1) {
|
|
if (inBlockComment) {
|
|
if (source[index] === "*" && source[index + 1] === "/") {
|
|
inBlockComment = false;
|
|
index += 1;
|
|
}
|
|
continue;
|
|
}
|
|
if (inLineComment) {
|
|
if (source[index] === "\n" || source[index] === "\r") {
|
|
inLineComment = false;
|
|
}
|
|
continue;
|
|
}
|
|
if (source[index] === "/" && source[index + 1] === "*") {
|
|
inBlockComment = true;
|
|
index += 1;
|
|
continue;
|
|
}
|
|
if (source[index] === "/" && source[index + 1] === "/") {
|
|
inLineComment = true;
|
|
index += 1;
|
|
continue;
|
|
}
|
|
|
|
const quote = source[index];
|
|
if (quote !== '"' && quote !== "'") {
|
|
continue;
|
|
}
|
|
|
|
let cursor = index + 1;
|
|
let value = "";
|
|
while (cursor < source.length) {
|
|
const char = source[cursor];
|
|
if (char === "\\") {
|
|
value += source.slice(cursor, cursor + 2);
|
|
cursor += 2;
|
|
continue;
|
|
}
|
|
if (char === quote) {
|
|
break;
|
|
}
|
|
value += char;
|
|
cursor += 1;
|
|
}
|
|
if (cursor >= source.length) {
|
|
break;
|
|
}
|
|
|
|
if (value.startsWith(".")) {
|
|
const isDistDependency =
|
|
isImportSpecifierContext(source, index) ||
|
|
isRequireSpecifierContext(source, index) ||
|
|
(isImportMetaUrlContext(source, index, cursor) && hasJavaScriptFileExtension(value));
|
|
if (isDistDependency) {
|
|
specifiers.push(value);
|
|
}
|
|
}
|
|
index = cursor;
|
|
}
|
|
return specifiers;
|
|
}
|
|
|
|
/** Collect missing-file errors for relative imports inside package dist files. */
|
|
export function collectPackageDistImportErrors(params) {
|
|
const files = [...new Set(params.files.map(normalizePackagePath))];
|
|
const fileSet = new Set(files);
|
|
const errors = [];
|
|
const imports = params.imports ?? collectPackageDistImports({ files, readText: params.readText });
|
|
|
|
for (const { importerPath, importedPath } of imports) {
|
|
if (!fileSet.has(importedPath)) {
|
|
errors.push(`${importerPath} imports missing ${importedPath}`);
|
|
}
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
/** Collect relative dist import edges from package JavaScript files. */
|
|
export function collectPackageDistImports(params) {
|
|
const files = [...new Set(params.files.map(normalizePackagePath))];
|
|
const imports = [];
|
|
|
|
for (const importerPath of files.toSorted((left, right) => left.localeCompare(right))) {
|
|
if (!JS_DIST_FILE_RE.test(importerPath) || importerPath.includes("/node_modules/")) {
|
|
continue;
|
|
}
|
|
const source = params.readText(importerPath);
|
|
for (const specifier of collectImportSpecifiers(source)) {
|
|
const importedPath = resolveDistImportPath(importerPath, specifier);
|
|
if (!importedPath) {
|
|
continue;
|
|
}
|
|
imports.push({ importerPath, importedPath });
|
|
}
|
|
}
|
|
|
|
return imports;
|
|
}
|
|
|
|
/** Expand seed dist files to include all reachable relative dist imports. */
|
|
export function expandPackageDistImportClosure(params) {
|
|
const files = [...new Set(params.files.map(normalizePackagePath))];
|
|
const fileSet = new Set(files);
|
|
const expectedSet = new Set(params.seedFiles.map(normalizePackagePath));
|
|
const imports = params.imports ?? collectPackageDistImports({ files, readText: params.readText });
|
|
const importsByImporter = new Map();
|
|
for (const { importerPath, importedPath } of imports) {
|
|
const importerImports = importsByImporter.get(importerPath) ?? [];
|
|
importerImports.push(importedPath);
|
|
importsByImporter.set(importerPath, importerImports);
|
|
}
|
|
|
|
const queue = [...expectedSet].filter((file) => fileSet.has(file));
|
|
for (const importerPath of queue) {
|
|
for (const importedPath of importsByImporter.get(importerPath) ?? []) {
|
|
if (fileSet.has(importedPath) && !expectedSet.has(importedPath)) {
|
|
expectedSet.add(importedPath);
|
|
queue.push(importedPath);
|
|
}
|
|
}
|
|
}
|
|
|
|
return [...expectedSet].toSorted((left, right) => left.localeCompare(right));
|
|
}
|