-
-
Notifications
You must be signed in to change notification settings - Fork 89
Migrate kg-default-atoms to TypeScript #1759
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
Open
kevinansfield
wants to merge
2
commits into
main
Choose a base branch
from
ts/kg-default-atoms
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−76
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| build/ | ||
| tsconfig.tsbuildinfo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +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 [ | ||
| export default defineConfig([ | ||
| {ignores: ['build/**']}, | ||
| eslint.configs.recommended, | ||
| { | ||
| files: ['**/*.js'], | ||
| plugins: {ghost}, | ||
| files: ['**/*.ts'], | ||
| extends: [ | ||
| eslint.configs.recommended, | ||
| tseslint.configs.recommended | ||
| ], | ||
| languageOptions: { | ||
| globals: globals.node | ||
| parserOptions: {ecmaVersion: 2022, sourceType: 'module'} | ||
| }, | ||
| plugins: {ghost: ghostPlugin}, | ||
| 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' | ||
| ...ghostPlugin.configs.ts.rules, | ||
| '@typescript-eslint/no-explicit-any': 'error' | ||
| } | ||
| }, | ||
| { | ||
| files: ['test/**/*.js'], | ||
| plugins: {ghost}, | ||
| languageOptions: { | ||
| globals: { | ||
| ...globals.node, | ||
| ...globals.mocha, | ||
| should: true, | ||
| sinon: true | ||
| } | ||
| }, | ||
| files: ['test/**/*.ts'], | ||
| rules: { | ||
| ...ghostPlugin.configs.test.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' | ||
| } | ||
| } | ||
| ]; | ||
| ]); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,50 @@ | ||
| { | ||
| "name": "@tryghost/kg-default-atoms", | ||
| "version": "5.1.7", | ||
| "repository": "https://github.com/TryGhost/Koenig/tree/master/packages/kg-default-atoms", | ||
| "repository": "https://github.com/TryGhost/Koenig/tree/main/packages/kg-default-atoms", | ||
| "author": "Ghost Foundation", | ||
| "license": "MIT", | ||
| "main": "index.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" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "dev": "echo \"Implement me!\"", | ||
| "test": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha './test/**/*.test.js'", | ||
| "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": "NODE_ENV=testing c8 --all --reporter text --reporter cobertura mocha --require tsx './test/**/*.test.ts'", | ||
| "lint": "eslint . --cache", | ||
| "posttest": "yarn lint" | ||
| }, | ||
| "engines": { | ||
| "node": "^22.13.1 || ^24.0.0" | ||
| }, | ||
| "files": [ | ||
| "index.js", | ||
| "lib" | ||
| "build" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "devDependencies": { | ||
| "@eslint/js": "9.28.0", | ||
| "@types/mocha": "10.0.10", | ||
| "@types/node": "22.15.29", | ||
| "@types/should": "13.0.0", | ||
| "@types/sinon": "17.0.4", | ||
| "c8": "11.0.0", | ||
| "simple-dom": "1.4.0" | ||
| "mocha": "11.7.5", | ||
| "should": "13.2.3", | ||
| "simple-dom": "1.4.0", | ||
| "sinon": "21.0.1", | ||
| "tsx": "4.19.4", | ||
| "typescript": "5.8.3", | ||
| "typescript-eslint": "8.33.1" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import softReturn from './soft-return.js'; | ||
|
|
||
| export const atoms = [softReturn]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| export interface AtomEnv { | ||
| dom: { | ||
| createElement(tag: string): unknown; | ||
| }; | ||
| } | ||
|
|
||
| export interface AtomOpts { | ||
| env: AtomEnv; | ||
| } | ||
|
|
||
| export default { | ||
| name: 'soft-return', | ||
| type: 'dom', | ||
| render(opts: AtomOpts) { | ||
| return opts.env.dom.createElement('br'); | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export {atoms} from './atoms/index.js'; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import '../utils/index.js'; | ||
| import atom from '../../src/atoms/soft-return.js'; | ||
| import {Document as SimpleDomDocument, HTMLSerializer, voidMap} from 'simple-dom'; | ||
| import type {SerializableNode} from '@simple-dom/interface'; | ||
|
|
||
| const serializer = new HTMLSerializer(voidMap); | ||
|
|
||
| describe('Soft return atom', function () { | ||
| it('generates a `br` tag', function () { | ||
| const opts = { | ||
| env: { | ||
| dom: new SimpleDomDocument() | ||
| } | ||
| }; | ||
|
|
||
| serializer.serialize(atom.render(opts) as SerializableNode).should.match('<br>'); | ||
| }); | ||
| }); |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // This file is required before any test is run | ||
|
|
||
| // Taken from the should wiki, this is how to make should global | ||
| // Should is a global in our eslint test config | ||
| import should from 'should'; | ||
| import sinon from 'sinon'; | ||
|
|
||
| // @types/should is incomplete — noConflict and extend exist at runtime | ||
| const shouldModule = should as unknown as {noConflict(): typeof should; extend(): void}; | ||
| Object.defineProperty(globalThis, 'should', {value: shouldModule.noConflict(), writable: true, configurable: true}); | ||
| shouldModule.extend(); | ||
|
|
||
| // Sinon is a simple case | ||
| // Sinon is a global in our eslint test config | ||
| Object.defineProperty(globalThis, 'sinon', {value: sinon, writable: true, configurable: true}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "module": "NodeNext", | ||
| "moduleResolution": "NodeNext", | ||
| "outDir": "build/cjs", | ||
| "verbatimModuleSyntax": false, | ||
| "declaration": false, | ||
| "declarationMap": false, | ||
| "sourceMap": false, | ||
| "incremental": false | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "es2022", | ||
| "module": "ES2022", | ||
| "moduleResolution": "bundler", | ||
| "rootDir": "src", | ||
| "outDir": "build/esm", | ||
| "strict": true, | ||
| "declaration": true, | ||
| "declarationMap": true, | ||
| "sourceMap": true, | ||
| "incremental": true, | ||
| "esModuleInterop": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "skipLibCheck": true, | ||
| "resolveJsonModule": true, | ||
| "isolatedModules": true | ||
| }, | ||
| "include": [ | ||
| "src/**/*" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "rootDir": ".", | ||
| "outDir": null, | ||
| "noEmit": true, | ||
| "declaration": false, | ||
| "declarationMap": false, | ||
| "sourceMap": false, | ||
| "incremental": false | ||
| }, | ||
| "include": [ | ||
| "src/**/*", | ||
| "test/**/*" | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.