mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
refactor(build): reuse canonical direct-run entrypoint guard (#128715)
This commit is contained in:
committed by
GitHub
parent
97b13b1735
commit
4d8e87cc3c
+2
-10
@@ -6,10 +6,10 @@ import { createHash } from "node:crypto";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { performance } from "node:perf_hooks";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { asRecord } from "@openclaw/normalization-core/record-coerce";
|
||||
import prettyMilliseconds from "pretty-ms";
|
||||
import { resolveBuildIdentityEnvironment } from "./lib/build-identity.mts";
|
||||
import { isDirectRunUrl } from "./lib/direct-run.mjs";
|
||||
import {
|
||||
listPluginSdkDistArtifacts,
|
||||
listPluginSdkDeclarationOutputs,
|
||||
@@ -1083,15 +1083,7 @@ export function runBuildAllSteps(
|
||||
return { exitCode, timings };
|
||||
}
|
||||
|
||||
function isMainModule() {
|
||||
const argv1 = process.argv[1];
|
||||
if (!argv1) {
|
||||
return false;
|
||||
}
|
||||
return import.meta.url === pathToFileURL(argv1).href;
|
||||
}
|
||||
|
||||
if (isMainModule()) {
|
||||
if (isDirectRunUrl(process.argv[1], import.meta.url)) {
|
||||
let args;
|
||||
try {
|
||||
args = parseBuildAllArgs(process.argv.slice(2));
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
import fs from "node:fs";
|
||||
import module from "node:module";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { parse, type Node as AcornNode } from "acorn";
|
||||
import {
|
||||
WORKER_BUNDLE_ENTRY_PATH,
|
||||
WORKER_BUNDLE_RSYNC_RECEIVER_PATH,
|
||||
} from "../src/shared/worker-bundle-hash.js";
|
||||
import { isDirectRunUrl } from "./lib/direct-run.mjs";
|
||||
|
||||
const DEFAULT_ENTRYPOINTS = ["dist/entry.js", "dist/cli/run-main.js"];
|
||||
const WORKER_DEPLOY_ENTRYPOINTS = [
|
||||
@@ -42,10 +42,6 @@ type CliBootstrapCheckParams = {
|
||||
logger?: { error(message: string): void };
|
||||
};
|
||||
|
||||
function isMainModule() {
|
||||
return process.argv[1] ? path.resolve(process.argv[1]) === fileURLToPath(import.meta.url) : false;
|
||||
}
|
||||
|
||||
function isBuiltinSpecifier(specifier: string) {
|
||||
return specifier.startsWith("node:") || module.isBuiltin(specifier);
|
||||
}
|
||||
@@ -449,7 +445,7 @@ export function checkCliBootstrapExternalImports(params: CliBootstrapCheckParams
|
||||
throw new Error("CLI bootstrap static graph imports external packages.");
|
||||
}
|
||||
|
||||
if (isMainModule()) {
|
||||
if (isDirectRunUrl(process.argv[1], import.meta.url)) {
|
||||
try {
|
||||
checkCliBootstrapExternalImports();
|
||||
console.log("CLI bootstrap import guard passed.");
|
||||
|
||||
@@ -12,10 +12,10 @@ import {
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { isPathInside } from "@openclaw/fs-safe/path";
|
||||
import { decodeMountInfoPath } from "../packages/normalization-core/src/mountinfo-path.ts";
|
||||
import { BUNDLED_PLUGIN_PATH_PREFIX } from "./lib/bundled-plugin-paths.mjs";
|
||||
import { isDirectRunUrl } from "./lib/direct-run.mjs";
|
||||
import {
|
||||
inspectManagedProcessGroup,
|
||||
terminateManagedChild,
|
||||
@@ -1714,15 +1714,7 @@ export async function runTsdownBuildInvocation(
|
||||
});
|
||||
}
|
||||
|
||||
function isMainModule() {
|
||||
const argv1 = process.argv[1];
|
||||
if (!argv1) {
|
||||
return false;
|
||||
}
|
||||
return import.meta.url === pathToFileURL(argv1).href;
|
||||
}
|
||||
|
||||
if (isMainModule()) {
|
||||
if (isDirectRunUrl(process.argv[1], import.meta.url)) {
|
||||
const args = parseTsdownBuildArgs(process.argv.slice(2));
|
||||
if (args.help) {
|
||||
console.log(tsdownBuildUsage());
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { normalizeControlUiBuildInfo } from "../ui/src/build-info-normalizers.ts";
|
||||
import { isDirectRunUrl } from "./lib/direct-run.mjs";
|
||||
|
||||
const defaultRootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const FULL_GIT_COMMIT_RE = /^[0-9a-f]{40}$/iu;
|
||||
@@ -139,12 +140,7 @@ export function writeBuildInfo(options: ResolveBuildInfoOptions = {}): string {
|
||||
return outputPath;
|
||||
}
|
||||
|
||||
function isMainModule(): boolean {
|
||||
const argv1 = process.argv[1];
|
||||
return Boolean(argv1 && import.meta.url === pathToFileURL(argv1).href);
|
||||
}
|
||||
|
||||
if (isMainModule()) {
|
||||
if (isDirectRunUrl(process.argv[1], import.meta.url)) {
|
||||
try {
|
||||
writeBuildInfo();
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user