Skip to content

Commit

Permalink
Fix exports; Add attw to CI (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikrsna-buf authored Oct 5, 2023
1 parent e6ee21b commit bb70049
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ jobs:
uses: ./.github/actions/setup
- name: test
run: pnpm run test
- name: attw
run: pnpm run attw
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"clean": "turbo run clean --no-daemon --cache-dir=.turbo",
"build": "turbo run build --no-daemon --cache-dir=.turbo",
"lint": "turbo run lint --no-daemon --cache-dir=.turbo",
"attw": "turbo run attw --no-daemon --cache-dir=.turbo",
"test": "turbo run test --no-daemon --cache-dir=.turbo",
"test:watch": "turbo run test:watch --no-daemon --cache-dir=.turbo",
"buf:generate": "turbo run buf:generate --no-daemon --cache-dir=.turbo",
Expand All @@ -21,7 +22,8 @@
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"turbo": "^1.10.14",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"@arethetypeswrong/cli": "^0.11.0"
},
"engines": {
"node": ">=18.16.0",
Expand Down
43 changes: 27 additions & 16 deletions packages/knit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,46 @@
},
"sideEffects": false,
"type": "module",
"scripts": {
"clean": "rm -rf ./dist/* .turbo/*",
"lint": "eslint .",
"attw": "attw --pack",
"test": "NODE_OPTIONS=--experimental-vm-modules ../../node_modules/.bin/jest",
"test:watch": "pnpm run build:esm+types --watch & pnpm run test --watchAll",
"build:esm": "tsup --format esm",
"build:cjs": "tsup --format cjs && mv ./dist/cjs/index.d.cts ./dist/cjs/index.d.ts && mv ./dist/cjs/gateway/index.d.cts ./dist/cjs/gateway/index.d.ts",
"build": "pnpm run build:esm && pnpm run build:cjs"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js"
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.js"
}
},
"./gateway": {
"import": "./dist/esm/gateway/index.js",
"require": "./dist/cjs/gateway/index.js"
"import": {
"types": "./dist/esm/gateway/index.d.ts",
"default": "./dist/esm/gateway/index.js"
},
"require": {
"types": "./dist/cjs/gateway/index.d.ts",
"default": "./dist/cjs/gateway/index.js"
}
}
},
"typesVersions": {
"*": {
"gateway": [
"./dist/esm/gateway/index.d.ts",
"./dist/cjs/gateway/index.d.ts"
]
}
},
"scripts": {
"clean": "rm -rf ./dist/* .turbo/*",
"lint": "eslint .",
"test": "NODE_OPTIONS=--experimental-vm-modules ../../node_modules/.bin/jest",
"test:watch": "pnpm run build:esm+types --watch & pnpm run test --watchAll",
"build:esm": "tsup --format esm",
"build:cjs": "tsup --format cjs",
"build": "pnpm run build:esm && pnpm run build:cjs"
},
"dependencies": {
"@bufbuild/protobuf": "^1.3.1",
"@connectrpc/connect": "^1.0.0",
Expand All @@ -56,4 +67,4 @@
"files": [
"dist/**"
]
}
}
43 changes: 7 additions & 36 deletions packages/knit/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,11 @@ import { writeFileSync } from "fs";

const cjsPackageJson = {
type: "commonjs",
main: "./index.js",
types: "./index.d.ts",
exports: {
".": {
types: "./index.d.ts",
require: "./index.js",
},
"./gateway": {
types: "./gateway/index.d.ts",
require: "./gateway/index.js",
},
},
typesVersions: {
"*": {
gateway: ["./gateway/index.d.ts"],
},
},
};

const esmPackageJson = {
sideEffects: false,
type: "module",
types: "./index.d.ts",
module: "./index.js",
exports: {
".": {
types: "./index.d.ts",
import: "./index.js",
},
"./gateway": {
types: "./gateway/index.d.ts",
import: "./gateway/index.js",
},
},
typesVersions: {
"*": {
gateway: ["./gateway/index.d.ts"],
},
},
sideEffects: false,
};

const sharedOptions = {
Expand All @@ -50,12 +16,17 @@ const sharedOptions = {
clean: true,
treeshake: true,
entry: ["./src/index.ts", "./src/gateway/index.ts"],
outExtension() {
return {
js: ".js",
dts: ".d.ts",
};
},
} satisfies Options;

const cjsOptions = {
...sharedOptions,
format: "cjs",
legacyOutput: true, // Outputs `.js` instead of `.cjs`.
outDir: "./dist/cjs",
onSuccess: async () =>
writeFileSync("./dist/cjs/package.json", JSON.stringify(cjsPackageJson)),
Expand Down
Loading

0 comments on commit bb70049

Please sign in to comment.