-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add config package to normalize tsdown options #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 4 commits
61e26ae
2a58302
f77e199
b60c084
4999b26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| { | ||
| "files.associations": { | ||
| "wrangler.json": "jsonc" | ||
| } | ||
| }, | ||
| "typescript.experimental.useTsgo": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| { | ||
| "name": "@mcansh/config", | ||
| "version": "0.1.0", | ||
| "description": "shared configuration for packages in the mcansh/packages monorepo", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/mcansh/packages.git", | ||
| "directory": "./packages/vitest-response-matchers" | ||
|
mcansh marked this conversation as resolved.
Outdated
|
||
| }, | ||
| "author": "Logan McAnsh <logan@mcan.sh> (https://mcan.sh/)", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "tsdown", | ||
| "dev": "tsdown --watch", | ||
| "format": "prettier --ignore-path .gitignore --ignore-path .prettierignore --ignore-unknown --write .", | ||
| "prepublishOnly": "node --run build", | ||
| "test": "vitest", | ||
| "typecheck": "tsgo" | ||
| }, | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": "./dist/index.js", | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "files": [ | ||
| "dist", | ||
| "package.json", | ||
| "README.md", | ||
| "LICENSE" | ||
| ], | ||
| "engines": { | ||
| "node": ">=20" | ||
| }, | ||
| "dependencies": { | ||
| "ts-deepmerge": "^7.0.3" | ||
| }, | ||
| "peerDependencies": { | ||
| "tsdown": "^0.12.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@arethetypeswrong/core": "catalog:", | ||
| "@total-typescript/tsconfig": "catalog:", | ||
| "@types/node": "catalog:", | ||
| "@typescript/native-preview": "catalog:", | ||
| "@vitest/coverage-v8": "catalog:", | ||
| "tsdown": "catalog:", | ||
| "typescript": "catalog:", | ||
| "vitest": "^3.2.4" | ||
| }, | ||
| "imports": { | ||
| "#*": "./*" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { merge } from "ts-deepmerge"; | ||
| import type { UserConfig, UserConfigFn } from "tsdown"; | ||
|
|
||
| export const defaultBuildConfig = { | ||
| dts: true, | ||
| format: "esm", | ||
| tsconfig: "./tsconfig.json", | ||
| sourcemap: true, | ||
| exports: true, | ||
| clean: true, | ||
| publint: true, | ||
| attw: { profile: "node16" }, | ||
| skipNodeModulesBundle: true, | ||
| platform: "neutral", | ||
| define: { | ||
| "import.meta.vitest": "undefined", | ||
| }, | ||
| } satisfies UserConfig; | ||
|
|
||
| export function mergeBuildConfig( | ||
| userConfig?: UserConfig | UserConfigFn, | ||
| ): UserConfig { | ||
| if (typeof userConfig === "undefined") return defaultBuildConfig; | ||
| let config = | ||
| typeof userConfig === "function" | ||
| ? userConfig(defaultBuildConfig) | ||
| : userConfig; | ||
| return merge(defaultBuildConfig, config); | ||
| } | ||
|
|
||
| if (import.meta.vitest) { | ||
| let { describe, expect, it } = import.meta.vitest; | ||
|
|
||
| describe("mergeBuildConfig", () => { | ||
| it("returns default config when no input is provided", () => { | ||
| let config = mergeBuildConfig(); | ||
| expect(config).toEqual(defaultBuildConfig); | ||
| }); | ||
|
|
||
| it("returns default config when empty object is provided", () => { | ||
| let config = mergeBuildConfig({}); | ||
| expect(config).toEqual(defaultBuildConfig); | ||
| }); | ||
|
|
||
| it("returns default config when function returns empty object", () => { | ||
| let config = mergeBuildConfig(() => ({})); | ||
| expect(config).toEqual(defaultBuildConfig); | ||
| }); | ||
|
|
||
| it("merges user config when using function", () => { | ||
| let config = mergeBuildConfig((config) => { | ||
| config.dts = false; | ||
| return {}; | ||
| }); | ||
|
Comment on lines
+51
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case is a bit confusing because it relies on mutating the A clearer way to write this test would be to have the function return the desired configuration overrides without modifying the input object. This avoids side effects and makes the test's intent more explicit. let config = mergeBuildConfig(() => ({
dts: false,
})); |
||
|
|
||
| expect(config).toEqual({ | ||
| ...defaultBuildConfig, | ||
| dts: false, | ||
| }); | ||
| }); | ||
|
|
||
| it.each([ | ||
| { dts: false }, | ||
| { format: "cjs" }, | ||
| { sourcemap: false }, | ||
| { format: ["cjs", "esm"] }, | ||
| { define: { __DEV__: "true" } }, | ||
| ] satisfies UserConfig[])("merges configs", (input) => { | ||
| let config = mergeBuildConfig(input); | ||
| expect(config).toEqual({ | ||
| ...defaultBuildConfig, | ||
| ...input, | ||
| define: { | ||
| ...defaultBuildConfig.define, | ||
| ...input.define, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { defaultBuildConfig, mergeBuildConfig } from "./build"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "@total-typescript/tsconfig/bundler/no-dom", | ||
| "include": ["./src/**/*", "./vitest.setup.ts"], | ||
| "compilerOptions": { | ||
| "allowImportingTsExtensions": true, | ||
| "moduleResolution": "Bundler", | ||
| "forceConsistentCasingInFileNames": true, | ||
| "types": ["vitest/importMeta"] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { defineConfig } from "tsdown"; | ||
| import { defaultBuildConfig } from "./src/build.ts"; | ||
|
|
||
| export default defineConfig({ | ||
| ...defaultBuildConfig, | ||
| entry: { index: "./src/index.ts" }, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "entryPoints": ["./src/index.ts", "./src/build.ts"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { defineProject } from "vitest/config"; | ||
|
|
||
| export default defineProject({ | ||
| test: { | ||
| includeSource: ["./src/**/*.{js,ts}"], | ||
| name: "config", | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
repository.directoryfield appears to have an incorrect value. It should point to this package's directory,./packages/config, instead of./packages/vitest-response-matchers. This could cause issues for tools that rely on this metadata for package discovery and linking.