feat!: esm - #485
Conversation
|
hi @derduher you asked me to tag you |
ReviewI built this branch locally to verify the riskier parts of the ESM migration rather than reviewing the diff text alone. That surfaced two build-breaking issues plus a few doc/process gaps. 🔴 Confirmed build-breaking issues1.
2. The built CLI is broken — const currentDir = new URL('.', import.meta.url).pathname
const packageJson = JSON.parse(
readFileSync(resolve(currentDir, '../../package.json'), 'utf8')
);The comment was updated ("one level up from dist") but the path literal ( Verified concretely — after building, i.e. it resolves one directory above the repo itself. Every case in 🟡 Other issues
RecommendationDon't merge as-is — the branch doesn't build and the CLI is non-functional post-build. Fixes are small and mechanical:
Once fixed, would want to see green CI on this PR before merging. |
8cd99f9 to
382582d
Compare
|
@derduher I think I've addressed the review |
derduher
left a comment
There was a problem hiding this comment.
Overall this is a solid ESM-only modernization — the verbatimModuleSyntax conversion, the Jest→node:test rewrite, Windows support, and pinned action SHAs all look careful and correct. Node >=22 is fine.
There's one blocker, though: the build emits no JavaScript, so both the test suite and the published package are broken. tsconfig.build.json sets emitDeclarationOnly: true, so npm run build produces only .d.ts files:
$ npm run build && find dist -name '*.js' | wc -l → 0
find dist -name '*.d.ts' | wc -l → 15
Because of this:
- The tests fail. They now import from
../dist/lib/*.js/../dist/index.js, none of which exist after a build:CI runsError [ERR_MODULE_NOT_FOUND]: Cannot find module '.../dist/lib/errors.js' ✖ tests/sitemap-stream.test.ts … pass 0 fail 1buildthentest, so it should be red for the same reason. - The published package is broken —
exports.default→./dist/index.jsandbin→./dist/cli.jswon't exist.
Fix is to drop emitDeclarationOnly: true from tsconfig.build.json so tsc emits .js alongside the declarations. Typecheck itself is clean (tsc --noEmit exits 0), so this is purely the emit config. See inline comments.
Minor: worth calling out the CJS removal as a breaking change in the PR description for consumers migrating off require('sitemap').
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "noEmit": false, | ||
| "emitDeclarationOnly": true, |
There was a problem hiding this comment.
Blocker: emitDeclarationOnly: true means tsc emits only .d.ts — no runtime .js. After npm run build, dist/ contains 15 .d.ts files and zero .js, so dist/index.js, dist/cli.js, and dist/lib/*.js never get created.
This breaks the published package (exports.default/bin point at nonexistent .js) and the test suite (tests import ../dist/lib/*.js, which fail with ERR_MODULE_NOT_FOUND).
Suggest removing this line so tsc emits JS alongside declarations:
| "emitDeclarationOnly": true, | |
| "noEmit": false, | |
| "declaration": true, | |
| "outDir": "dist" |
| npm test # Run Jest tests with coverage | ||
| npm run test:full # Run lint, build, Jest, and xmllint validation | ||
| npm run test:full # Run lint, build, coverage-enforced tests, and xmllint validation | ||
| npm run test:typecheck # Type check only (tsc) |
There was a problem hiding this comment.
Stale after this PR: it's no longer Jest, and npm test no longer collects coverage (that moved to test:coverage / test:full). Suggest updating to something like # Run tests with the Node.js test runner.
Closes #484