Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"files.associations": {
"wrangler.json": "jsonc"
}
},
"typescript.experimental.useTsgo": true
}
2 changes: 1 addition & 1 deletion apps/http-helmet/remix-classic-compiler/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('@remix-run/dev').AppConfig} */
/** @type {import("@remix-run/dev").AppConfig} */
export default {
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
Expand Down
7 changes: 4 additions & 3 deletions apps/http-helmet/remix-vite/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* By default, Remix will handle hydrating your app on the client for you.
* You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨
* For more information, see https://remix.run/file-conventions/entry.client
* By default, Remix will handle hydrating your app on the client for you. You
* are free to delete this file if you'd like to, but if you ever want it
* revealed again, you can run `npx remix reveal` ✨ For more information, see
* https://remix.run/file-conventions/entry.client
*/

import { RemixBrowser } from "@remix-run/react";
Expand Down
7 changes: 4 additions & 3 deletions apps/http-helmet/remix-vite/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* By default, Remix will handle generating the HTTP Response for you.
* You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨
* For more information, see https://remix.run/file-conventions/entry.server
* By default, Remix will handle generating the HTTP Response for you. You are
* free to delete this file if you'd like to, but if you ever want it revealed
* again, you can run `npx remix reveal` ✨ For more information, see
* https://remix.run/file-conventions/entry.server
*/

import {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"license": "MIT",
"type": "module",
"scripts": {
"build:packages": "pnpm run --recursive --parallel --filter \"./packages/**\" build",
"build:apps": "pnpm run --recursive --parallel --filter \"./apps/**\" build",
"build:packages": "pnpm run --recursive --parallel --sort --filter \"./packages/**\" build",
"build:apps": "pnpm run --recursive --parallel --sort --filter \"./apps/**\" build",
"build": "pnpm run --sequential \"/^build:.*/\"",
"changeset": "changeset",
"changeset:release": "pnpm run build && changeset publish",
Expand All @@ -16,7 +16,6 @@
"format": "prettier --cache --ignore-path .gitignore --ignore-path .prettierignore --write .",
"lint": "pnpm run --recursive --parallel lint",
"prepublishOnly": "pnpm run build",
"publish": "./scripts/publish.js",
"test": "vitest",
"test:ci": "vitest --coverage",
"typecheck": "pnpm run --recursive typecheck",
Expand All @@ -27,17 +26,20 @@
"@changesets/cli": "^2.29.5",
"@manypkg/get-packages": "^3.0.0",
"@types/node": "catalog:",
"@typescript/native-preview": "catalog:",
"@vitest/coverage-v8": "catalog:",
"chalk": "^5.4.1",
"jsonfile": "^6.1.0",
"junit": "^1.4.9",
"pkg-pr-new": "^0.0.54",
"prettier": "^3.6.2",
"prettier-plugin-jsdoc": "^1.3.3",
"prettier-plugin-organize-imports": "^4.1.0",
"prettier-plugin-sort-package-json": "^1.1.0",
"prompt-confirm": "^2.0.4",
"semver": "^7.7.2",
"typedoc": "^0.28.7",
"typescript": "catalog:",
"vitest": "catalog:",
"wrangler": "^4.25.0"
},
Expand Down
56 changes: 56 additions & 0 deletions packages/config/package.json
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/config"
},
"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": {
"#*": "./*"
}
}
80 changes: 80 additions & 0 deletions packages/config/src/build.ts
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test case is a bit confusing because it relies on mutating the defaultBuildConfig object. While it currently passes, this approach can be brittle and hard to reason about.

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,
},
});
});
});
}
1 change: 1 addition & 0 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { defaultBuildConfig, mergeBuildConfig } from "./build";
10 changes: 10 additions & 0 deletions packages/config/tsconfig.json
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"]
}
}
7 changes: 7 additions & 0 deletions packages/config/tsdown.config.ts
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" },
});
3 changes: 3 additions & 0 deletions packages/config/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entryPoints": ["./src/index.ts", "./src/build.ts"]
}
8 changes: 8 additions & 0 deletions packages/config/vitest.config.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",
},
});
4 changes: 3 additions & 1 deletion packages/http-helmet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dev": "tsdown --watch",
"prepublishOnly": "npm run build",
"test": "vitest --project http-helmet",
"typecheck": "tsc"
"typecheck": "tsgo"
},
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -64,13 +64,15 @@
},
"devDependencies": {
"@arethetypeswrong/core": "catalog:",
"@mcansh/config": "workspace:",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
"@total-typescript/tsconfig": "catalog:",
"@types/node": "catalog:",
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
"@typescript/native-preview": "catalog:",
"@vitest/coverage-v8": "catalog:",
"content-security-policy-parser": "^0.6.0",
"happy-dom": "^18.0.1",
Expand Down
Loading