mirror of
https://github.com/unjs/unbuild.git
synced 2025-12-08 19:25:11 +00:00
123 lines
2.9 KiB
TypeScript
123 lines
2.9 KiB
TypeScript
import type { BuildEntry } from "../src/types.ts";
|
|
import { fileURLToPath } from "node:url";
|
|
import { consola } from "consola";
|
|
import { join } from "pathe";
|
|
import { describe, it, expect } from "vitest";
|
|
import { validateDependencies, validatePackage } from "../src/validate";
|
|
|
|
describe("validatePackage", () => {
|
|
it("detects missing files", () => {
|
|
const buildContext = {
|
|
warnings: new Set(),
|
|
} as any;
|
|
|
|
validatePackage(
|
|
{
|
|
main: "./dist/test",
|
|
bin: {
|
|
"./cli": "./dist/cli",
|
|
},
|
|
module: "dist/mod",
|
|
// @ts-expect-error TODO: fix pkg-types
|
|
exports: {
|
|
"./runtime/*": "./runtime/*.mjs",
|
|
".": { node: "./src/index.mts" },
|
|
},
|
|
},
|
|
join(fileURLToPath(import.meta.url), "../fixture"),
|
|
buildContext,
|
|
);
|
|
|
|
const warnings = [...buildContext.warnings];
|
|
|
|
expect(warnings[0]).to.include("Potential missing");
|
|
expect(warnings[0]).not.to.include("src/index.mts");
|
|
|
|
for (const file of ["dist/test", "dist/cli", "dist/mod", "runtime"]) {
|
|
expect(warnings[0]).to.include(file);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("validateDependencies", () => {
|
|
it("detects implicit deps", () => {
|
|
const warnings = new Set<string>();
|
|
|
|
validateDependencies({
|
|
warnings,
|
|
pkg: {},
|
|
buildEntries: [],
|
|
hooks: [] as any,
|
|
usedImports: new Set(["pkg-a/core"]),
|
|
options: {
|
|
externals: [],
|
|
dependencies: ["react"],
|
|
peerDependencies: [],
|
|
devDependencies: [],
|
|
rootDir: ".",
|
|
entries: [] as BuildEntry[],
|
|
clean: false,
|
|
outDir: "dist",
|
|
stub: false,
|
|
alias: {},
|
|
replace: {},
|
|
// @ts-expect-error
|
|
rollup: {
|
|
replace: false,
|
|
alias: false,
|
|
resolve: false,
|
|
json: false,
|
|
esbuild: false,
|
|
commonjs: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect([...warnings][0]).to.include(
|
|
"Potential implicit dependencies found:",
|
|
);
|
|
});
|
|
|
|
it("does not print implicit deps warning for peerDependencies", () => {
|
|
const logs: string[] = [];
|
|
consola.mockTypes((type) =>
|
|
type === "warn"
|
|
? (str: string): void => {
|
|
logs.push(str);
|
|
}
|
|
: (): void => {},
|
|
);
|
|
|
|
validateDependencies({
|
|
pkg: {},
|
|
buildEntries: [],
|
|
hooks: [] as any,
|
|
usedImports: new Set(["pkg-a/core"]),
|
|
options: {
|
|
externals: [],
|
|
dependencies: ["react"],
|
|
peerDependencies: ["pkg-a"],
|
|
devDependencies: [],
|
|
rootDir: ".",
|
|
entries: [] as BuildEntry[],
|
|
clean: false,
|
|
outDir: "dist",
|
|
stub: false,
|
|
alias: {},
|
|
replace: {},
|
|
// @ts-expect-error
|
|
rollup: {
|
|
replace: false,
|
|
alias: false,
|
|
resolve: false,
|
|
json: false,
|
|
esbuild: false,
|
|
commonjs: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(logs.length).to.eq(0);
|
|
});
|
|
});
|