Skip to content

Commit b5edee9

Browse files
authored
feat!: drop CommonJS support (#59)
## Summary - publish an ESM-only package from one Bazel build target - ignore `src/generated` in Oxlint and Oxfmt - enforce Conventional Commits with Commitlint in Lefthook and CI - replace Release Doctor with the upstream Release Please action used by Codescythe ## Breaking change CommonJS output and export conditions are removed. Consumers must use ESM imports. ## Test - `bazel test //...` - `pnpm build` - Commitlint hook - ESM package import smoke test
1 parent 05ad99f commit b5edee9

19 files changed

Lines changed: 601 additions & 131 deletions

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
2323
steps:
2424
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25+
with:
26+
fetch-depth: 0
2527

2628
- name: Set up Bazel
2729
uses: bazel-contrib/setup-bazel@c5acdfb288317d0b5c0bbd7a396a3dc868bb0f86
@@ -41,6 +43,18 @@ jobs:
4143
- name: Install dependencies
4244
run: pnpm install --frozen-lockfile
4345

46+
- name: Lint commits
47+
env:
48+
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }}
49+
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
50+
run: |
51+
set -euo pipefail
52+
if git cat-file -e "$BASE_SHA^{commit}" 2>/dev/null && [ "$BASE_SHA" != "0000000000000000000000000000000000000000" ]; then
53+
pnpm exec commitlint --from "$BASE_SHA" --to "$HEAD_SHA" --verbose
54+
else
55+
pnpm exec commitlint --last --verbose
56+
fi
57+
4458
- name: Lint
4559
run: bazel test //:lint
4660

.github/workflows/release-doctor.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release Please
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}
11+
cancel-in-progress: false
12+
13+
jobs:
14+
release-please:
15+
name: Create or update release PR
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
issues: write
20+
pull-requests: write
21+
22+
steps:
23+
- name: Run Release Please
24+
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7
25+
with:
26+
token: ${{ secrets.RELEASE_TOKEN }}
27+
config-file: release-please-config.json
28+
manifest-file: .release-please-manifest.json

.oxfmtrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"singleQuote": true,
66
"trailingComma": "all",
77
"sortPackageJson": false,
8-
"ignorePatterns": ["dist/**", "bazel-*/**"]
8+
"ignorePatterns": ["dist/**", "bazel-*/**", "src/generated/**"]
99
}

.oxlintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "./node_modules/oxlint/configuration_schema.json",
3-
"ignorePatterns": ["dist/**", "bazel-*/**"],
3+
"ignorePatterns": ["dist/**", "bazel-*/**", "src/generated/**"],
44
"categories": {
55
"correctness": "off"
66
},

BUILD.bazel

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,11 @@ TS_SOURCES = glob(["src/**/*.ts"])
3232
TEST_SOURCES = glob(["tests/**/*.ts"])
3333

3434
ts_project(
35-
name = "dist_cjs",
35+
name = "dist",
3636
srcs = TS_SOURCES,
3737
declaration = True,
3838
declaration_map = True,
39-
out_dir = "dist/cjs",
40-
root_dir = "src",
41-
source_map = True,
42-
transpiler = "tsc",
43-
tsc = ":tsc",
44-
tsconfig = {
45-
"compilerOptions": dict(
46-
BASE_COMPILER_OPTIONS,
47-
declaration = True,
48-
declarationMap = True,
49-
module = "Node16",
50-
moduleResolution = "Node16",
51-
noEmit = False,
52-
outDir = "dist/cjs",
53-
rootDir = "src",
54-
sourceMap = True,
55-
types = ["node"],
56-
),
57-
},
58-
deps = [":node_modules/@types/node"],
59-
)
60-
61-
ts_project(
62-
name = "dist_esm",
63-
srcs = TS_SOURCES,
64-
declaration = True,
65-
declaration_map = True,
66-
out_dir = "dist/esm",
39+
out_dir = "dist",
6740
root_dir = "src",
6841
source_map = True,
6942
transpiler = "tsc",
@@ -76,7 +49,7 @@ ts_project(
7649
module = "ESNext",
7750
moduleResolution = "Bundler",
7851
noEmit = False,
79-
outDir = "dist/esm",
52+
outDir = "dist",
8053
rootDir = "src",
8154
sourceMap = True,
8255
types = ["node"],
@@ -91,21 +64,13 @@ npm_package(
9164
"CHANGELOG.md",
9265
"LICENSE",
9366
"README.md",
94-
":dist_cjs",
95-
":dist_esm",
67+
":dist",
9668
"//npm:package",
97-
"//npm:index.d.cts",
98-
"//npm:index.js",
99-
] + TS_SOURCES + [
100-
"esm/package.json",
101-
],
69+
] + TS_SOURCES,
10270
out = "package",
10371
package = "@perplexity-ai/perplexity_ai",
10472
publishable = True,
10573
replace_prefixes = {
106-
"esm": "dist/esm",
107-
"npm/index.d.cts": "dist/index.d.cts",
108-
"npm/index.js": "dist/index.js",
10974
"npm/package.json": "package.json",
11075
},
11176
)
@@ -126,8 +91,8 @@ ts_project(
12691
tsconfig = {
12792
"compilerOptions": dict(
12893
BASE_COMPILER_OPTIONS,
129-
module = "Node16",
130-
moduleResolution = "Node16",
94+
module = "ESNext",
95+
moduleResolution = "Bundler",
13196
noEmit = False,
13297
outDir = "test-dist",
13398
rootDir = "tests",
@@ -166,9 +131,19 @@ FORMAT_SOURCES = glob(
166131
"tests/**/*.ts",
167132
"*.json",
168133
"*.md",
134+
"*.mjs",
169135
"*.yml",
170136
],
171137
allow_empty = True,
138+
exclude = ["src/generated/**"],
139+
)
140+
141+
LINT_SOURCES = glob(
142+
[
143+
"src/**/*.ts",
144+
"tests/**/*.ts",
145+
],
146+
exclude = ["src/generated/**"],
172147
)
173148

174149
oxfmt_bin.oxfmt_test(
@@ -188,10 +163,10 @@ oxlint_bin.oxlint_test(
188163
name = "oxlint",
189164
args = [
190165
"--config=$(rootpath :.oxlintrc.json)",
191-
] + TS_SOURCES + TEST_SOURCES,
166+
] + LINT_SOURCES,
192167
data = [
193168
".oxlintrc.json",
194-
] + TS_SOURCES + TEST_SOURCES,
169+
] + LINT_SOURCES,
195170
)
196171

197172
publint_bin.publint_test(
@@ -211,7 +186,6 @@ attw_bin.attw_test(
211186
"--pack",
212187
"--ignore-rules",
213188
"cjs-resolves-to-esm",
214-
"missing-export-equals",
215189
"internal-resolution-error",
216190
],
217191
data = [":pkg"],

commitlint.config.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
extends: ['@commitlint/config-conventional'],
3+
};

esm/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

lefthook.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ output:
44

55
no_auto_install: true
66

7+
commit-msg:
8+
commands:
9+
commitlint:
10+
run: ./node_modules/.bin/commitlint --edit {1}
11+
712
pre-commit:
813
commands:
914
oxlint:

npm/BUILD.bazel

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
load("@jq.bzl//jq:jq.bzl", "jq")
22

3-
exports_files([
4-
"index.d.cts",
5-
"index.js",
6-
])
7-
83
jq(
94
name = "package",
105
srcs = ["//:package.json"],

0 commit comments

Comments
 (0)