Skip to content

Commit c8b49fe

Browse files
authored
TS migration setup for url-utils
ref https://linear.app/ghost/issue/PRO-1535/ - 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. - Added TS dependencies and config - Moved files to /src - Renamed files to .ts with // @ts-nocheck - Updated tests to use compiled lib output instead of TS source
1 parent 8c4f1f2 commit c8b49fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+113
-5
lines changed

packages/url-utils/.eslintrc.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
module.exports = {
22
plugins: ['ghost'],
33
extends: [
4-
'plugin:ghost/node'
4+
'plugin:ghost/ts'
5+
],
6+
overrides: [
7+
{
8+
// Files with @ts-nocheck are intentionally not fully migrated yet
9+
// Disable all linting rules that would fail on these files
10+
files: ['**/*.ts'],
11+
rules: {
12+
'@typescript-eslint/ban-ts-comment': ['error', {
13+
'ts-nocheck': false
14+
}],
15+
'@typescript-eslint/no-var-requires': 'off',
16+
'prefer-const': 'off'
17+
}
18+
}
519
]
620
};

packages/url-utils/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/

packages/url-utils/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
module.exports = require('./lib/UrlUtils');
2+

packages/url-utils/package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
"author": "Ghost Foundation",
1010
"license": "MIT",
1111
"main": "index.js",
12+
"types": "lib/UrlUtils.d.ts",
1213
"scripts": {
1314
"dev": "echo \"Implement me!\"",
14-
"test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura --reporter html mocha './test/**/*.test.js'",
15-
"lint": "eslint . --ext .js --cache",
15+
"pretest": "yarn build",
16+
"test": "NODE_ENV=testing c8 --src lib --all --reporter text --reporter cobertura --reporter html mocha './test/**/*.test.js'",
17+
"build": "tsc -p tsconfig.json",
18+
"lint": "eslint src test index.js --ext .js,.ts --cache",
19+
"prepare": "NODE_ENV=production yarn build",
1620
"posttest": "yarn lint"
1721
},
1822
"files": [
@@ -24,11 +28,15 @@
2428
},
2529
"devDependencies": {
2630
"@tryghost/config-url-helpers": "^1.0.18",
31+
"@types/cheerio": "^0.22.31",
32+
"@types/lodash": "^4.14.202",
33+
"@types/node": "^20.0.0",
2734
"c8": "10.1.3",
2835
"mocha": "11.7.5",
2936
"rewire": "9.0.1",
3037
"should": "13.2.3",
31-
"sinon": "21.0.0"
38+
"sinon": "21.0.0",
39+
"typescript": "5.9.3"
3240
},
3341
"dependencies": {
3442
"cheerio": "^0.22.0",

packages/url-utils/lib/UrlUtils.js renamed to packages/url-utils/src/UrlUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
// Contains all path information to be used throughout the codebase.
23
const _ = require('lodash');
34
const utils = require('./utils');

packages/url-utils/lib/utils/absolute-to-relative.js renamed to packages/url-utils/src/utils/absolute-to-relative.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
// require the whatwg compatible URL library (same behaviour in node and browser)
23
const {URL} = require('url');
34
const stripSubdirectoryFromPath = require('./strip-subdirectory-from-path');

packages/url-utils/lib/utils/absolute-to-transform-ready.js renamed to packages/url-utils/src/utils/absolute-to-transform-ready.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
const {URL} = require('url');
23
const absoluteToRelative = require('./absolute-to-relative');
34

packages/url-utils/lib/utils/build-early-exit-match.js renamed to packages/url-utils/src/utils/build-early-exit-match.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
function escapeRegExp(string) {
23
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
34
}

packages/url-utils/lib/utils/deduplicate-double-slashes.js renamed to packages/url-utils/src/utils/deduplicate-double-slashes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
function deduplicateDoubleSlashes(url) {
23
// Preserve protocol slashes (e.g., http://, https://) and only deduplicate
34
// slashes in the path portion. The pattern (^|[^:])\/\/+ matches double slashes

packages/url-utils/lib/utils/deduplicate-subdirectory.js renamed to packages/url-utils/src/utils/deduplicate-subdirectory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-nocheck
12
const {URL} = require('url');
23

34
/**

0 commit comments

Comments
 (0)