Skip to content

Conversation

@vershwal
Copy link
Member

@vershwal vershwal commented Nov 12, 2025

TypeScript Migration for @tryghost/url-utils

Overview

This PR does the basic TS setup for urlUtils without changing/adding the actual types. This adds // @ts-nocheck in code files and changes the dir structure with TS conventions.

Current State

  • Main entry: index.jslib/UrlUtils.js
  • Utilities: 42 utility files in lib/utils/

Migration Steps

  • Added TS dependencies and config
  • Moved files to /src
  • Renames files to .ts with // @ts-nocheck
  • Updated tests to use compiled cjs output instead of TS source

Checks after this set-up

✅ All tests pass
✅ TypeScript compiles without errors
✅ Package can be imported and used as before

Cursor Summary


Note

Introduce TypeScript build/tooling for @tryghost/url-utils, migrating sources to src/*.ts (ts-nocheck), adding a new early-exit helper, and updating scripts/lint to build to lib/ with type declarations.

  • Build/Tooling:
    • Set up TypeScript: add tsconfig.json, compile to lib/ with tsc, and export types via "types": "lib/UrlUtils.d.ts".
    • Update package.json scripts (build, prepare, pretest, test now targets lib, lint supports .ts), and .gitignore to ignore lib/.
    • Switch ESLint to plugin:ghost/ts with overrides for // @ts-nocheck files.
    • Add TS dev deps (typescript, @types/*).
  • Source layout:
    • Move sources to src/ and convert files to .ts with // @ts-nocheck; keep CommonJS exports.
    • New helper src/utils/build-early-exit-match.ts; update HTML/Markdown/plaintext transforms to use it where applicable.
    • Ensure runtime entry remains index.js -> ./lib/UrlUtils.

Written by Cursor Bugbot for commit 8045015. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 3

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@vershwal vershwal changed the title Url utils ts migration setup [wip] Url utils ts migration setup Nov 13, 2025
@vershwal vershwal force-pushed the urlUtilsTSMigrationSetup branch from 3ae53e0 to 34cd4e4 Compare November 13, 2025 06:55
@vershwal vershwal changed the title [wip] Url utils ts migration setup Url utils TS migration setup Nov 13, 2025
Base automatically changed from testUrlUtils to main November 13, 2025 07:51
@vershwal vershwal force-pushed the urlUtilsTSMigrationSetup branch from 34cd4e4 to 41554dc Compare November 13, 2025 07:59
@vershwal vershwal requested a review from allouis November 13, 2025 08:06
@vershwal vershwal force-pushed the urlUtilsTSMigrationSetup branch from 108f965 to 9bb7431 Compare November 13, 2025 12:06
@vershwal vershwal force-pushed the urlUtilsTSMigrationSetup branch 2 times, most recently from ec936c8 to 2dec475 Compare November 19, 2025 08:52
@vershwal vershwal force-pushed the urlUtilsTSMigrationSetup branch from 751eac0 to 9f15a9e Compare November 19, 2025 09:20
Copy link
Contributor

@allouis allouis left a comment

Choose a reason for hiding this comment

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

Can we compile to the lib directory instead of cjs?

That will give us better backwards compatibility with koenig as it reads directly from lib, for example here https://github.com/TryGhost/Koenig/blob/main/packages/kg-default-cards/lib/cards/file.js#L5

@@ -0,0 +1,4 @@
cjs/
umd/
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we generate any umd, es or types directories?

Copy link
Member Author

Choose a reason for hiding this comment

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

No we don't. This didn't get cleared up from rollup.

"pretest": "yarn build",
"test": "NODE_ENV=testing c8 --src cjs --all --reporter text --reporter cobertura --reporter html mocha './test/**/*.test.js'",
"build": "tsc -p tsconfig.json",
"lint": "eslint . --ext .js,.ts --cache",
Copy link
Contributor

Choose a reason for hiding this comment

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

If we run this on src explicitly we can get rid of the .eslintignore file

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES2019",
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for this target? Ghost & ActivityPub use ES2022

Copy link
Member Author

Choose a reason for hiding this comment

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

No reason actually, updated.

- Added `typescript` to devDependencies
- Added `@types/node`, `@types/lodash`, `@types/cheerio` to devDependencies
- Added build scripts to package.json:
  * build: Compile TypeScript and generate type definitions
  * pretest: Build before running tests
  * prepare: Build before publish
- Updated files field to include build output directories
- Moved entire `lib/` directory to `src/` directory to follow TypeScript convention
- Updated test files to use the new path
- Added @ts-nocheck to skip type-check
- Updated `index.js` to use compiled output instead of TypeScript source
…ts-nocheck

- Allowed @ts-nocheck comments in TypeScript files
- Disabled @typescript-eslint/no-var-requires for .ts files
- Disabled prefer-const rule for .ts files

This ensures linting passes while TypeScript migration is in progress.
@vershwal vershwal force-pushed the urlUtilsTSMigrationSetup branch from 3d96b0d to 8045015 Compare November 19, 2025 12:28
@vershwal vershwal merged commit c8b49fe into main Nov 19, 2025
3 checks passed
@vershwal vershwal deleted the urlUtilsTSMigrationSetup branch November 19, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants