-
-
Notifications
You must be signed in to change notification settings - Fork 89
Migrate kg-converters to TypeScript #1761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| cjs/ | ||
| es/ | ||
| build/ | ||
| tsconfig.tsbuildinfo |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,33 @@ | ||
| import {fixupPluginRules} from '@eslint/compat'; | ||
| import {defineConfig} from 'eslint/config'; | ||
| import eslint from '@eslint/js'; | ||
| import ghostPlugin from 'eslint-plugin-ghost'; | ||
| import globals from 'globals'; | ||
| import tseslint from 'typescript-eslint'; | ||
|
|
||
| const ghost = fixupPluginRules(ghostPlugin); | ||
|
|
||
| export default [ | ||
| {ignores: ['build/**', 'cjs/**', 'es/**']}, | ||
| eslint.configs.recommended, | ||
| { | ||
| files: ['**/*.js'], | ||
| plugins: {ghost}, | ||
| languageOptions: { | ||
| globals: { | ||
| ...globals.node, | ||
| ...globals.browser | ||
| } | ||
| }, | ||
| rules: { | ||
| ...ghostPlugin.configs.node.rules, | ||
| // match ESLint 8 behavior for catch clause variables | ||
| 'no-unused-vars': ['error', {caughtErrors: 'none'}], | ||
| // disable rules incompatible with ESLint 9 flat config | ||
| 'ghost/filenames/match-exported-class': 'off', | ||
| 'ghost/filenames/match-exported': 'off', | ||
| 'ghost/filenames/match-regex': 'off' | ||
| } | ||
| export default defineConfig([ | ||
| { ignores: ['build/**'] }, | ||
| { | ||
| files: ['**/*.ts'], | ||
| extends: [ | ||
| eslint.configs.recommended, | ||
| tseslint.configs.recommended, | ||
| ], | ||
| languageOptions: { | ||
| parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, | ||
| }, | ||
| plugins: { ghost: ghostPlugin }, | ||
| rules: { | ||
| ...ghostPlugin.configs.ts.rules, | ||
| '@typescript-eslint/no-explicit-any': 'error', | ||
| }, | ||
| }, | ||
| { | ||
| files: ['test/**/*.ts'], | ||
| rules: { | ||
| ...ghostPlugin.configs['ts-test'].rules, | ||
| 'ghost/mocha/no-global-tests': 'off', | ||
| 'ghost/mocha/handle-done-callback': 'off', | ||
| 'ghost/mocha/no-mocha-arrows': 'off', | ||
| 'ghost/mocha/max-top-level-suites': 'off', | ||
| }, | ||
| { | ||
| files: ['test/**/*.js'], | ||
| plugins: {ghost}, | ||
| languageOptions: { | ||
| globals: { | ||
| ...globals.node, | ||
| ...globals.mocha, | ||
| should: true, | ||
| sinon: true | ||
| } | ||
| }, | ||
| rules: { | ||
| ...ghostPlugin.configs.test.rules | ||
| } | ||
| } | ||
| ]; | ||
| }, | ||
| ]); | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,35 +4,42 @@ | |||||||||||||||||||||
| "repository": "https://github.com/TryGhost/Koenig/tree/main/packages/kg-converters", | ||||||||||||||||||||||
| "author": "Ghost Foundation", | ||||||||||||||||||||||
| "license": "MIT", | ||||||||||||||||||||||
| "main": "cjs/kg-converters.js", | ||||||||||||||||||||||
| "module": "es/kg-converters.js", | ||||||||||||||||||||||
| "source": "lib/kg-converters.js", | ||||||||||||||||||||||
| "main": "build/cjs/index.js", | ||||||||||||||||||||||
| "module": "build/esm/index.js", | ||||||||||||||||||||||
| "types": "build/esm/index.d.ts", | ||||||||||||||||||||||
| "exports": { | ||||||||||||||||||||||
| ".": { | ||||||||||||||||||||||
| "types": "./build/esm/index.d.ts", | ||||||||||||||||||||||
| "import": "./build/esm/index.js", | ||||||||||||||||||||||
| "require": "./build/cjs/index.js" | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| "scripts": { | ||||||||||||||||||||||
| "dev": "rollup -c -w", | ||||||||||||||||||||||
| "build": "rollup -c", | ||||||||||||||||||||||
| "prepare": "NODE_ENV=production yarn build", | ||||||||||||||||||||||
| "pretest": "yarn build", | ||||||||||||||||||||||
| "test:unit": "NODE_ENV=testing c8 --all --src lib/ --exclude lib/kg-converters.js --check-coverage --reporter text --reporter cobertura mocha './test/**/*.test.js'", | ||||||||||||||||||||||
| "dev": "tsc --watch --preserveWatchOutput", | ||||||||||||||||||||||
| "build": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json", | ||||||||||||||||||||||
| "prepare": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json", | ||||||||||||||||||||||
| "pretest": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json && tsc -p tsconfig.test.json", | ||||||||||||||||||||||
| "test:unit": "NODE_ENV=testing c8 --all --src src/ --check-coverage --reporter text --reporter cobertura tsx node_modules/.bin/mocha './test/**/*.test.ts'", | ||||||||||||||||||||||
|
Comment on lines
+19
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: No.
If you need cross-platform behavior, prefer a Node-based write (e.g., Sources 🏁 Script executed: # Verify the file exists and check its content
if [ -f "packages/kg-converters/package.json" ]; then
echo "=== File content (full) ==="
cat -n "packages/kg-converters/package.json"
echo ""
echo "=== Lines 15-30 (context around lines 20-23) ==="
sed -n '15,30p' "packages/kg-converters/package.json"
else
echo "File not found at packages/kg-converters/package.json"
# Try to find it
find . -name "package.json" -path "*/kg-converters/*" 2>/dev/null | head -5
fiRepository: TryGhost/Koenig Length of output: 2723 Fix shell portability and eliminate build script duplication. The Proposed fix "scripts": {
"dev": "tsc --watch --preserveWatchOutput",
- "build": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json",
- "prepare": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json",
- "pretest": "tsc && tsc -p tsconfig.cjs.json && echo '{\"type\":\"module\"}' > build/esm/package.json",
+ "write:esm-package-json": "node -e \"require('node:fs').writeFileSync('build/esm/package.json', JSON.stringify({type:'module'}))\"",
+ "build": "tsc && tsc -p tsconfig.cjs.json && yarn write:esm-package-json",
+ "prepare": "yarn build",
+ "pretest": "yarn build",
"test:unit": "NODE_ENV=testing c8 --all --src src/ --check-coverage --reporter text --reporter cobertura tsx node_modules/.bin/mocha './test/**/*.test.ts'",📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| "test": "yarn test:unit", | ||||||||||||||||||||||
| "posttest": "yarn lint", | ||||||||||||||||||||||
| "lint": "eslint . --cache" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| "files": [ | ||||||||||||||||||||||
| "LICENSE", | ||||||||||||||||||||||
| "README.md", | ||||||||||||||||||||||
| "cjs/", | ||||||||||||||||||||||
| "es/", | ||||||||||||||||||||||
| "lib" | ||||||||||||||||||||||
| "build" | ||||||||||||||||||||||
| ], | ||||||||||||||||||||||
| "publishConfig": { | ||||||||||||||||||||||
| "access": "public" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| "devDependencies": { | ||||||||||||||||||||||
| "@rollup/plugin-babel": "7.0.0", | ||||||||||||||||||||||
| "@eslint/js": "9.39.4", | ||||||||||||||||||||||
| "@types/mocha": "^10.0.0", | ||||||||||||||||||||||
| "@types/node": "^22.0.0", | ||||||||||||||||||||||
| "c8": "11.0.0", | ||||||||||||||||||||||
| "mocha": "11.7.5", | ||||||||||||||||||||||
| "rollup": "4.59.0", | ||||||||||||||||||||||
| "sinon": "21.0.2" | ||||||||||||||||||||||
| "sinon": "21.0.2", | ||||||||||||||||||||||
| "tsx": "^4.0.0", | ||||||||||||||||||||||
| "typescript": "5.9.3", | ||||||||||||||||||||||
| "typescript-eslint": "8.33.1" | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| "dependencies": { | ||||||||||||||||||||||
| "lodash": "^4.17.21" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export {lexicalToMobiledoc, mobiledocToLexical} from './kg-converters.js'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import {lexicalToMobiledoc} from './lexical-to-mobiledoc.js'; | ||
| import {mobiledocToLexical} from './mobiledoc-to-lexical.js'; | ||
|
|
||
| export {lexicalToMobiledoc, mobiledocToLexical}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: TryGhost/Koenig
Length of output: 111
🏁 Script executed:
Repository: TryGhost/Koenig
Length of output: 1368
🌐 Web query:
eslint-plugin-ghost npm preset config ts rules languageOptions💡 Result:
eslint-plugin-ghostships legacy.eslintrc*“preset configs” (exposed asplugin:ghost/<preset>), not ESLint v9 flat-configlanguageOptionsobjects. Usage is viaextends: ['plugin:ghost/<preset>'](presets includenode,browser,es,ember,ts,test,filenames, plus*-no-stylevariants, andts-test). [1]What the
tspreset does (rules / parser options)The
plugin:ghost/tspreset:env: { node: true, es6: true }parserOptions: { ecmaVersion: 2022 }@typescript-eslintand extendsplugin:@typescript-eslint/recommended``@typescript-eslint/no-inferrable-types[2]plugin:ghost/ts-testextends./tsand adds./test-rules. [3]ESLint v9 flat config (
languageOptions) equivalent (if you want to avoid.eslintrc)If you’re using
eslint.config.js, you typically bring these legacy presets in viaFlatCompat, then add/overridelanguageOptionsas needed (especially the TS parser):(Typescript-eslint’s flat-config docs show
languageOptions.parser/languageOptions.parserOptionsas the place to configure TS parsing in flat config.) [4]Sources: [1] [2] [3] [4]
Replace spread of Ghost plugin rules with proper ESLint v9 flat-config integration.
eslint-plugin-ghostv3.5.0 exports legacy.eslintrc*presets (e.g.,plugin:ghost/ts,plugin:ghost/ts-test), not ESLint v9 flat-config objects. AccessingghostPlugin.configs.ts.rulesandghostPlugin.configs['ts-test'].rulesis not compatible with the plugin's actual structure and will not work reliably.Use
@eslint/eslintrc'sFlatCompatto bridge the legacy presets into flat config, or migrate to.eslintrc.jsonformat. If using FlatCompat:♻️ Example using FlatCompat
🤖 Prompt for AI Agents