diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b07e387..c6f9601 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/package.json b/package.json index 55d2341..d175da7 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/builders/mkdist/index.ts b/src/builders/mkdist/index.ts index e306a47..73badb2 100644 --- a/src/builders/mkdist/index.ts +++ b/src/builders/mkdist/index.ts @@ -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"; diff --git a/src/builders/rollup/plugins/esbuild.ts b/src/builders/rollup/plugins/esbuild.ts index 459128f..226af34 100644 --- a/src/builders/rollup/plugins/esbuild.ts +++ b/src/builders/rollup/plugins/esbuild.ts @@ -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", diff --git a/src/builders/rollup/plugins/json.ts b/src/builders/rollup/plugins/json.ts index e91c100..ed811c0 100644 --- a/src/builders/rollup/plugins/json.ts +++ b/src/builders/rollup/plugins/json.ts @@ -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" && diff --git a/src/validate.ts b/src/validate.ts index d7bf131..fa143cb 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -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(); diff --git a/test/auto.test.ts b/test/auto.test.ts index b0f86e1..37ed996 100644 --- a/test/auto.test.ts +++ b/test/auto.test.ts @@ -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/"], ), diff --git a/test/fixture/build.config.ts b/test/fixture/build.config.ts index d7064b5..985309b 100644 --- a/test/fixture/build.config.ts +++ b/test/fixture/build.config.ts @@ -25,6 +25,7 @@ export default defineBuildConfig([ jiti: { transformOptions: { babel: { + // @ts-expect-error - type complexity plugins: [["@babel/plugin-transform-class-properties"]], }, }, diff --git a/test/utils.test.ts b/test/utils.test.ts index 59eee3e..76db030 100644 --- a/test/utils.test.ts +++ b/test/utils.test.ts @@ -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" } }, }), diff --git a/test/validate.test.ts b/test/validate.test.ts index 1fbcd0c..0842680 100644 --- a/test/validate.test.ts +++ b/test/validate.test.ts @@ -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", () => { diff --git a/tsconfig.json b/tsconfig.json index 3d4f70a..06c6a5e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] }