chore: stricter type checks (#413)

This commit is contained in:
Pooya Parsa 2024-07-02 16:25:52 +02:00 committed by GitHub
parent af26e404b5
commit 027fdf657e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 36 additions and 21 deletions

View File

@ -20,5 +20,6 @@ jobs:
cache: "pnpm"
- run: pnpm install
- run: pnpm lint
- run: pnpm test:types
- run: pnpm build
- run: pnpm vitest run --coverage

View File

@ -4,6 +4,7 @@
"description": "A unified javascript build system",
"repository": "unjs/unbuild",
"license": "MIT",
"type": "module",
"exports": {
".": {
"import": "./dist/index.mjs"
@ -24,7 +25,8 @@
"prepack": "pnpm unbuild",
"release": "pnpm test && changelogen --release --prerelease --publish && git push --follow-tags",
"stub": "pnpm unbuild --stub",
"test": "pnpm lint && vitest run --coverage",
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
"test:types": "tsc --noEmit",
"unbuild": "jiti ./src/cli"
},
"dependencies": {

View File

@ -1,5 +1,5 @@
import { relative } from "pathe";
import { mkdist, MkdistOptions } from "mkdist";
import { mkdist, type MkdistOptions } from "mkdist";
import { symlink, rmdir } from "../../utils";
import type { MkdistBuildEntry, BuildContext } from "../../types";
import consola from "consola";

View File

@ -1,10 +1,10 @@
// Based on https://github.com/egoist/rollup-plugin-esbuild and nitropack fork (MIT)
import { extname, relative } from "pathe";
import type { Plugin, PluginContext } from "rollup";
import { Loader, TransformResult, CommonOptions, transform } from "esbuild";
import { createFilter } from "@rollup/pluginutils";
import type { FilterPattern } from "@rollup/pluginutils";
import type { Loader, TransformResult, CommonOptions } from "esbuild";
import { transform } from "esbuild";
import { extname, relative } from "pathe";
import { createFilter } from "@rollup/pluginutils";
const DefaultLoaders: { [ext: string]: Loader } = {
".js": "js",

View File

@ -1,4 +1,4 @@
import type { Plugin } from "rollup";
import type { Plugin, TransformHook } from "rollup";
import type { RollupJsonOptions } from "@rollup/plugin-json";
import rollupJSONPlugin from "@rollup/plugin-json";
@ -10,7 +10,7 @@ export function JSONPlugin(options: RollupJsonOptions): Plugin {
...plugin,
name: "unbuild-json",
transform(code, id) {
const res = plugin.transform!.call(this, code, id);
const res = (plugin.transform as TransformHook)!.call(this, code, id);
if (
res &&
typeof res !== "string" &&

View File

@ -1,9 +1,9 @@
import type { PackageJson } from "pkg-types";
import type { BuildContext } from "./types";
import { existsSync } from "node:fs";
import chalk from "chalk";
import { resolve } from "pathe";
import { PackageJson } from "pkg-types";
import { arrayIncludes, extractExportFilenames, getpkg, warn } from "./utils";
import { BuildContext } from "./types";
export function validateDependencies(ctx: BuildContext): void {
const usedDependencies = new Set<string>();

View File

@ -132,6 +132,7 @@ describe("inferEntries", () => {
it("handles types within exports`", () => {
const result = inferEntries(
{
// @ts-expect-error - fix pkg-types
exports: {
import: {
types: "dist/test.d.mts",
@ -166,6 +167,7 @@ describe("inferEntries", () => {
it("ignores top-level exports", () => {
expect(
// @ts-expect-error - fix pkg-types
inferEntries({ exports: { "./*": "./*" } }, [
"src/",
"src/",
@ -183,6 +185,7 @@ describe("inferEntries", () => {
expect(
inferEntries(
{
// @ts-expect-error - fix pkg-types
exports: {
".": "./dist/index.cjs",
"first-test": "./dist/first-test.cjs",
@ -219,6 +222,7 @@ describe("inferEntries", () => {
warnings: [],
});
expect(
// @ts-expect-error - fix pkg-types
inferEntries({ exports: { "./runtime/*": "./dist/runtime/*.mjs," } }, [
"src/",
"src/runtime/",
@ -233,6 +237,7 @@ describe("inferEntries", () => {
});
expect(
inferEntries(
// @ts-expect-error - fix pkg-types
{ exports: { "./runtime/*": { require: "./dist/runtime/*" } } },
["src/", "src/runtime/"],
),

View File

@ -25,6 +25,7 @@ export default defineBuildConfig([
jiti: {
transformOptions: {
babel: {
// @ts-expect-error - type complexity
plugins: [["@babel/plugin-transform-class-properties"]],
},
},

View File

@ -27,11 +27,12 @@ describe("extractExportFilenames", () => {
]);
});
it("handles nested objects", () => {
// @ts-expect-error - fix pkg-types
expect(extractExportFilenames({ require: "test" })).to.deep.equal([
{ file: "test", type: "cjs" },
]);
// @ts-ignore TODO: fix pkg-types
expect(
// @ts-expect-error - fix pkg-types
extractExportFilenames({
require: { node: "test", other: { import: "this", require: "that" } },
}),

View File

@ -1,9 +1,9 @@
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";
import { BuildEntry } from "../src/types";
describe("validatePackage", () => {
it("detects missing files", () => {

View File

@ -1,16 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"module": "Preserve",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"outDir": "dist",
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"allowJs": true,
"checkJs": true,
"strict": true,
"declaration": true
"verbatimModuleSyntax": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"allowImportingTsExtensions": true,
"noImplicitOverride": true,
"noEmit": true
},
"include": [
"src",
"test"
]
"include": ["src", "test"]
}