-
Notifications
You must be signed in to change notification settings - Fork 460
[OUTDATED] Initial TypeScript setup and conversion (CJS to ESM, ES5 class functions to ES6 classes) #705
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
Closed
Closed
[OUTDATED] Initial TypeScript setup and conversion (CJS to ESM, ES5 class functions to ES6 classes) #705
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0bd0434
Upgrade dev dependencies (eslint, mocha, chai, nyc, sinon)
ericyhwang 257de57
Set up TypeScript, rename all lib/**/*.js files to src/**/*.ts with n…
ericyhwang 6ea4c9f
Move some module.exports statements up, so class JSDoc comments are a…
ericyhwang aa2f6b3
Update tsconfig and do light refactoring to make codemod more reliable
ericyhwang e8c2157
[codemod] Run jscodeshift codemod-cjs-to-esm.ts and codemod-es5-class…
ericyhwang ddf26c5
Remove old .eslintrc.js
ericyhwang 330c74e
Run tsc before tests, ignoring TS errors for now
ericyhwang 1800fac
Run CI on PRs/pushes to "typescript" staging branch
ericyhwang 919b0af
Skip CI linting of TS code for now
ericyhwang 1c2b270
(tests) Remove extraneous clock.setTickMode
ericyhwang 7ec4caa
Remove Node 18 from CI, add Node 24
ericyhwang b2fdd15
Add sinon clock uninstall to query-subscribe tests, since they are tr…
ericyhwang 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 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 |
|---|---|---|
|
|
@@ -4,9 +4,11 @@ on: | |
| push: | ||
| branches: | ||
| - master | ||
| - typescript | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| - typescript | ||
|
|
||
| jobs: | ||
| test: | ||
|
|
@@ -15,9 +17,9 @@ jobs: | |
| strategy: | ||
| matrix: | ||
| node: | ||
| - 18 | ||
| - 20 | ||
| - 22 | ||
| - 24 | ||
| services: | ||
| mongodb: | ||
| image: mongo:4.4 | ||
|
|
@@ -32,6 +34,7 @@ jobs: | |
| - name: Install | ||
| run: npm install | ||
| - name: Lint | ||
| if: github.ref_name != 'typescript' && github.base_ref != 'typescript' # Remove this condition after TS code lints cleanly | ||
|
Collaborator
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. Again, to try to keep this as close to |
||
| run: npm run lint | ||
| - name: Test | ||
| run: npm run test-cover | ||
|
|
||
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 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,96 @@ | ||
| const jsEslint = require("@eslint/js"); | ||
| const { | ||
| defineConfig, | ||
| globalIgnores, | ||
| } = require("eslint/config"); | ||
| const eslintConfigGoogle = require('eslint-config-google'); | ||
| const tsEslint = require('typescript-eslint'); | ||
|
|
||
| // The ESLint ecmaVersion argument is inconsistently used. Some rules will ignore it entirely, so if the rule has | ||
| // been set, it will still error even if it's not applicable to that version number. Since Google sets these | ||
| // rules, we have to turn them off ourselves. | ||
| var DISABLED_ES6_OPTIONS = { | ||
| 'no-var': 'off', | ||
| 'prefer-rest-params': 'off' | ||
| }; | ||
|
|
||
| var SHAREDB_RULES = { | ||
| // Comma dangle is not supported in ES3 | ||
| 'comma-dangle': ['error', 'never'], | ||
| // We control our own objects and prototypes, so no need for this check | ||
| 'guard-for-in': 'off', | ||
| // Google prescribes different indents for different cases. Let's just use 2 spaces everywhere. Note that we have | ||
| // to override ESLint's default of 0 indents for this. | ||
| indent: ['error', 2, { | ||
| SwitchCase: 1 | ||
| }], | ||
| 'linebreak-style': 'off', | ||
| // Less aggressive line length than Google, which is especially useful when we have a lot of callbacks in our code | ||
| 'max-len': ['error', | ||
| { | ||
| code: 120, | ||
| tabWidth: 2, | ||
| ignoreUrls: true | ||
| } | ||
| ], | ||
| // Google overrides the default ESLint behaviour here, which is slightly better for catching erroneously unused | ||
| // variables | ||
| 'no-unused-vars': ['error', { | ||
| vars: 'all', | ||
| args: 'after-used', | ||
| // This can be removed once the minimum ES version is ES2019 or newer, and catch statements | ||
| // are updated to use optional catch binding. | ||
| caughtErrors: 'none', | ||
| }], | ||
| // It's more readable to ensure we only have one statement per line | ||
| 'max-statements-per-line': ['error', { max: 1 }], | ||
| // ES3 doesn't support spread | ||
| 'prefer-spread': 'off', | ||
| // as-needed quote props are easier to write | ||
| 'quote-props': ['error', 'as-needed'], | ||
| 'require-jsdoc': 'off', | ||
| 'valid-jsdoc': 'off', | ||
| }; | ||
|
|
||
| module.exports = defineConfig([ | ||
| { | ||
| extends: [eslintConfigGoogle], | ||
| files: ["**/*.js"], | ||
| ignores: ['eslint.config.js'], | ||
|
|
||
| languageOptions: { | ||
| ecmaVersion: 3, | ||
| sourceType: "commonjs", | ||
|
|
||
| parserOptions: { | ||
| allowReserved: true, | ||
| }, | ||
| }, | ||
|
|
||
| rules: Object.assign({}, DISABLED_ES6_OPTIONS, SHAREDB_RULES), | ||
| }, | ||
| { | ||
| extends: [ | ||
| jsEslint.configs.recommended, | ||
| tsEslint.configs.recommended, | ||
| ], | ||
| files: ["**/*.ts"], | ||
| }, | ||
| globalIgnores(["docs/"]), | ||
| { | ||
| files: ["examples/counter-json1-vite/*.js"], | ||
|
|
||
| languageOptions: { | ||
| ecmaVersion: 2015, | ||
| sourceType: "module", | ||
|
|
||
| parserOptions: { | ||
| allowReserved: false, | ||
| }, | ||
| }, | ||
|
|
||
| rules: { | ||
| quotes: ["error", "single"], | ||
| }, | ||
| } | ||
| ]); |
Oops, something went wrong.
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.
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.
To try to keep this PR smaller, can we move all the dependency / environment bumps into a separate PR that we can merge first?
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.
Sure, I can cherry-pick those. Do you have a preference for getting the dep updates into master, or just into the typescript staging branch?
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.
Let's get it on
master. I'm generally of the opinion that the more stuff we can get intomasteras early as possible, the less painful things will be later.