Skip to content

Commit

Permalink
fix(auto): avoid warning for existing files (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Jul 18, 2023
1 parent 11c47c8 commit 66177cc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/auto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { normalize, join } from "pathe";
import { existsSync } from "node:fs";
import { normalize, join, resolve } from "pathe";
import { consola } from "consola";
import chalk from "chalk";
import type { PackageJson } from "pkg-types";
Expand All @@ -21,7 +22,7 @@ export const autoPreset = definePreset(() => {
return;
}
const sourceFiles = listRecursively(join(ctx.options.rootDir, "src"));
const res = inferEntries(ctx.pkg, sourceFiles);
const res = inferEntries(ctx.pkg, sourceFiles, ctx.options.rootDir);
for (const message of res.warnings) {
warn(ctx, message);
}
Expand Down Expand Up @@ -66,6 +67,7 @@ export const autoPreset = definePreset(() => {
export function inferEntries(
pkg: PackageJson,
sourceFiles: string[],
rootDir?: string,
): InferEntriesResult {
const warnings = [];

Expand Down Expand Up @@ -135,7 +137,9 @@ export function inferEntries(
}, undefined as any);

if (!input) {
warnings.push(`Could not find entrypoint for ${output.file}`);
if (!existsSync(resolve(rootDir || ".", output.file))) {
warnings.push(`Could not find entrypoint for \`${output.file}\``);
}
continue;
}

Expand Down
4 changes: 2 additions & 2 deletions test/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("inferEntries", () => {
cjs: true,
dts: false,
entries: [{ input: "src/test" }],
warnings: ["Could not find entrypoint for custom/handwritten.d.ts"],
warnings: ["Could not find entrypoint for `custom/handwritten.d.ts`"],
});
expect(
inferEntries(
Expand Down Expand Up @@ -160,7 +160,7 @@ describe("inferEntries", () => {
cjs: false,
entries: [],
dts: false,
warnings: ["Could not find entrypoint for dist/test.js"],
warnings: ["Could not find entrypoint for `dist/test.js`"],
});
});

Expand Down
3 changes: 3 additions & 0 deletions test/fixture/bin/cli.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

console.log("hello");
3 changes: 3 additions & 0 deletions test/fixture/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "fixture",
"private": "true",
"bin": {
"fixture": "./bin/cli.mjs"
},
"exports": {
".": "./dist/index.mjs",
"./nested/subpath": "./dist/nested/subpath.mjs"
Expand Down

0 comments on commit 66177cc

Please sign in to comment.