Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix(package-loader): resolve a bin-only dependency by its manifest

rponeb4c80563b22e
diff --git a/.gitignore b/.gitignore
index 0933319d..f7df5c41 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,3 +61,6 @@ examples/**/.svml/
# Reverse-engineering scratch projects: real output, but not the repository
/examples/*-reverse/
/examples/reference-reconstruction/
+
+# Reverse-engineering scratch projects live outside the repository too
+/projects/
diff --git a/packages/package-loader-node/src/loader.ts b/packages/package-loader-node/src/loader.ts
index 80b3adb4..89779c44 100644
--- a/packages/package-loader-node/src/loader.ts
+++ b/packages/package-loader-node/src/loader.ts
@@ -150,6 +150,23 @@ function within(root: string, candidate: string): boolean {
return relation === "" || (relation !== ".." && !relation.startsWith(`..${sep}`) && !isAbsolute(relation));
}
+/**
+ * The entry a package's identity can be read from: its main export where it has one, and otherwise
+ * its manifest. Resolving only the bare specifier reports a correctly installed bin-only package as
+ * missing, and the repair it then suggests cannot fix it.
+ */
+function resolveEither(resolver: NodeRequire, name: string): string {
+ try {
+ return resolver.resolve(name);
+ } catch (error) {
+ try {
+ return resolver.resolve(`${name}/package.json`);
+ } catch {
+ throw error;
+ }
+ }
+}
+
async function assertExternalDependencies(
item: ResolvedPackage,
distributionRoots: readonly string[],
@@ -159,7 +176,14 @@ async function assertExternalDependencies(
for (const [name, required] of Object.entries(item.json.dependencies)) {
if (name.startsWith("@hypit/") || required.startsWith("workspace:")) continue;
try {
- const resolved = await packageRoot(resolver.resolve(name), name);
+ // A dependency that ships only a `bin` declares no `main` and no `exports`, so its bare
+ // specifier never resolves however correctly it is installed. Its manifest still does, and
+ // that is what identifies and versions the package — which is also how a consumer of such a
+ // package reaches it, by resolving the manifest and walking to the executable beside it.
+ const resolved = await packageRoot(
+ resolveEither(resolver, name),
+ name,
+ );
if (/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/u.test(required)
&& resolved.json.version !== required) {
throw new Error(`installed version is ${resolved.json.version ?? "unknown"}`);