Skip to content

Commit ef572c1

Browse files
committed
Migrate kg-default-nodes to TypeScript
- Remove Rollup build (rollup.config.mjs, rollup-plugin-svg, @babel/*) - Move lib/ to src/, rename .js to .ts - Add tsconfig.json (strict, NodeNext, ESM) - Add "type": "module" to package.json - Convert 100 source files and 36 test files to ESM with Lexical types - Inline SVG import in AtLinkNode (replaces rollup-plugin-svg) - Replace .eslintrc.js with eslint.config.js (flat config) - Output to build/ via tsc (replaces cjs/ and es/ dirs) - 668 tests passing
1 parent 949501a commit ef572c1

File tree

149 files changed

+3005
-1973
lines changed

Some content is hidden

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

149 files changed

+3005
-1973
lines changed
Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
1-
import {fixupPluginRules} from '@eslint/compat';
21
import eslint from '@eslint/js';
2+
import {defineConfig} from 'eslint/config';
33
import ghostPlugin from 'eslint-plugin-ghost';
4-
import globals from 'globals';
4+
import tseslint from 'typescript-eslint';
55

6-
const ghost = fixupPluginRules(ghostPlugin);
7-
8-
export default [
9-
{ignores: ['build/**', 'cjs/**', 'es/**']},
10-
eslint.configs.recommended,
11-
{
12-
files: ['**/*.{js,mjs}'],
13-
plugins: {ghost},
14-
languageOptions: {
15-
globals: {
16-
...globals.node,
17-
...globals.browser
18-
}
19-
},
20-
rules: {
21-
...ghostPlugin.configs.node.rules,
22-
// match ESLint 8 behavior for catch clause variables
23-
'no-unused-vars': ['error', {caughtErrors: 'none'}],
24-
// disable rules incompatible with ESLint 9 flat config
25-
'ghost/filenames/match-exported-class': 'off',
26-
'ghost/filenames/match-exported': 'off',
27-
'ghost/filenames/match-regex': 'off'
28-
}
6+
export default defineConfig([
7+
{ ignores: ['build/**'] },
8+
{
9+
files: ['**/*.ts'],
10+
extends: [
11+
eslint.configs.recommended,
12+
tseslint.configs.recommended,
13+
],
14+
languageOptions: {
15+
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
16+
},
17+
plugins: { ghost: ghostPlugin },
18+
rules: {
19+
...ghostPlugin.configs.ts.rules,
20+
'@typescript-eslint/no-explicit-any': 'error',
21+
},
22+
},
23+
{
24+
files: ['src/**/*.ts'],
25+
rules: {
26+
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
27+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
28+
},
29+
},
30+
{
31+
files: ['test/**/*.ts'],
32+
rules: {
33+
...ghostPlugin.configs['ts-test'].rules,
34+
'ghost/mocha/no-global-tests': 'off',
35+
'ghost/mocha/handle-done-callback': 'off',
36+
'ghost/mocha/no-mocha-arrows': 'off',
37+
'ghost/mocha/max-top-level-suites': 'off',
38+
'ghost/mocha/no-setup-in-describe': 'off',
2939
},
30-
{
31-
files: ['test/**/*.{js,mjs}'],
32-
plugins: {ghost},
33-
languageOptions: {
34-
globals: {
35-
...globals.node,
36-
...globals.mocha,
37-
should: true,
38-
sinon: true
39-
}
40-
},
41-
rules: {
42-
...ghostPlugin.configs.test.rules
43-
}
44-
}
45-
];
40+
},
41+
]);

packages/kg-default-nodes/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/kg-default-nodes/package.json

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,56 @@
44
"repository": "https://github.com/TryGhost/Koenig/tree/main/packages/kg-default-nodes",
55
"author": "Ghost Foundation",
66
"license": "MIT",
7-
"main": "cjs/kg-default-nodes.js",
8-
"module": "es/kg-default-nodes.js",
9-
"source": "lib/kg-default-nodes.js",
7+
"main": "build/cjs/index.js",
8+
"module": "build/esm/index.js",
9+
"types": "build/esm/index.d.ts",
10+
"exports": {
11+
".": {
12+
"types": "./build/esm/index.d.ts",
13+
"import": "./build/esm/index.js",
14+
"require": "./build/cjs/index.js"
15+
}
16+
},
1017
"scripts": {
11-
"dev": "rollup -c -w",
12-
"build": "rollup -c",
13-
"prepare": "NODE_ENV=production yarn build",
14-
"pretest": "yarn build",
15-
"test:unit": "NODE_ENV=testing c8 --all --check-coverage --reporter text --reporter cobertura mocha './test/**/*.test.*js'",
18+
"dev": "tsc --watch --preserveWatchOutput",
19+
"build": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json",
20+
"prepare": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json",
21+
"pretest": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json && tsc -p tsconfig.test.json",
22+
"test:unit": "NODE_ENV=testing c8 --src src --all --check-coverage --reporter text --reporter cobertura mocha --require tsx './test/**/*.test.ts'",
1623
"test": "yarn test:unit",
17-
"test:no-coverage": "yarn pretest && mocha './test/**/*.test.*js'",
18-
"lint": "eslint . --cache"
24+
"lint:code": "eslint src/ --cache",
25+
"lint": "yarn lint:code && yarn lint:test",
26+
"lint:test": "eslint test/ --cache"
1927
},
2028
"files": [
2129
"LICENSE",
2230
"README.md",
23-
"cjs/",
24-
"es/",
25-
"lib/"
31+
"build"
2632
],
2733
"publishConfig": {
2834
"access": "public"
2935
},
3036
"devDependencies": {
31-
"@babel/eslint-parser": "7.28.6",
32-
"@babel/plugin-syntax-import-assertions": "^7.27.1",
37+
"@eslint/js": "9.39.4",
3338
"@lexical/headless": "0.13.1",
3439
"@lexical/html": "0.13.1",
3540
"@prettier/sync": "^0.6.0",
36-
"@rollup/plugin-babel": "7.0.0",
41+
"@types/jsdom": "^21.1.7",
42+
"@types/lodash": "^4.17.24",
43+
"@types/luxon": "^3.6.2",
44+
"@types/mocha": "10.0.10",
45+
"@types/node": "24.12.0",
46+
"@types/should": "^13.0.0",
47+
"@types/sinon": "21.0.0",
3748
"c8": "11.0.0",
3849
"html-minifier": "^4.0.0",
3950
"mocha": "11.7.5",
4051
"prettier": "3.8.1",
41-
"rollup": "4.59.0",
42-
"rollup-plugin-svg": "2.0.0",
4352
"should": "13.2.3",
44-
"sinon": "21.0.3"
53+
"sinon": "21.0.3",
54+
"tsx": "4.21.0",
55+
"typescript": "5.8.3",
56+
"typescript-eslint": "8.57.0"
4557
},
4658
"dependencies": {
4759
"@lexical/clipboard": "0.13.1",

packages/kg-default-nodes/rollup.config.mjs

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* c8 ignore start */
2+
import {DecoratorNode} from 'lexical';
3+
4+
export class KoenigDecoratorNode extends DecoratorNode<unknown> {
5+
decorate(): unknown {
6+
return null;
7+
}
8+
}
9+
10+
export function $isKoenigCard(node: unknown): node is KoenigDecoratorNode {
11+
return node instanceof KoenigDecoratorNode;
12+
}
13+
/* c8 ignore end */

0 commit comments

Comments
 (0)