Skip to content

pr05 Typescript #2: automatically resolve imports of ts files & migrate instance of client/utils file #3540

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
"import/no-unresolved": 0,
"import/no-named-as-default": 0,
"import/no-named-as-default-member": 0,
"import/extensions": [ // override airbnb setting to allow imports of js, jsx, ts, and tsx files to auto-resolve instead of error
"error",
"ignorePackages",
{
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
],
"comma-dangle": 0, // not sure why airbnb turned this on. gross!
"indent": 0,
"no-console": 0,
Expand Down Expand Up @@ -72,6 +82,11 @@
],
"settings": {
"import/parser": "@babel/eslint-parser",
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
},
"import/resolve": {
"moduleDirectory": ["node_modules"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import friendlyWords from 'friendly-words';

export function generateProjectName() {
/**
* Generates a random friendly project name composed of an adjective and an object.
* @example
* generateProjectName(); // "brave mountain"
*/
export function generateProjectName(): string {
const adj =
friendlyWords.predicates[
Math.floor(Math.random() * friendlyWords.predicates.length)
Expand All @@ -12,7 +17,12 @@ export function generateProjectName() {
return `${adj} ${obj}`;
}

export function generateCollectionName() {
/**
* Generates a random friendly collection name using an adjective.
* @example
* generateCollectionName(); // "My clever collection"
*/
export function generateCollectionName(): string {
const adj =
friendlyWords.predicates[
Math.floor(Math.random() * friendlyWords.predicates.length)
Expand Down
3 changes: 0 additions & 3 deletions client/utils/isSecurePage.js

This file was deleted.

13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@
"<rootDir>/server/jest.setup.js"
],
"testMatch": [
"<rootDir>/server/**/*.test.(js|jsx)"
"<rootDir>/server/**/*.test.(js|jsx|ts|tsx)"
]
},
{
"displayName": "client",
"testEnvironment": "jsdom",
"transform": {
"^.+\\.[jt]sx?$": "babel-jest"
},
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
"setupFilesAfterEnv": [
"<rootDir>/client/jest.setup.js"
],
Expand All @@ -63,7 +67,7 @@
"\\.(css|less|scss)$": "<rootDir>/client/__mocks__/styleMock.js"
},
"testMatch": [
"<rootDir>/client/**/*.test.(js|jsx)"
"<rootDir>/client/**/*.test.(js|jsx|ts|tsx)"
]
}
]
Expand Down Expand Up @@ -114,6 +118,7 @@
"@svgr/webpack": "^6.2.1",
"@testing-library/jest-dom": "^5.15.0",
"@testing-library/react": "^12.1.2",
"@types/friendly-words": "^1.2.2",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this, if we're not using the types yet?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be a misunderstanding but i thought we'd only need it if we did something like import {aType} from '@types/sdfdsf' to use aType later on?

Copy link
Collaborator Author

@clairep94 clairep94 Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yess that's a good point!! I did some searching to double-check on this bc we also have "skipLibCheck": true(https://github.com/processing/p5.js-web-editor/blob/develop/tsconfig.base.json#L7), which should allow us to not have to have declaration files within packages in node_modules, but I think it works the following way:

So I think this is expected, and as we go we will likely have to continue installing @types packages for any third-party packages we are using in a file that is being migrated (eg. react-router-dom, jest-react etc)

https://stackoverflow.com/questions/59906323/typescript-skiplibcheck-still-checking-node-modules-libs

"@types/jest": "^29.5.14",
"@types/node": "^16.18.126",
"@types/react": "^16.14.0",
Expand Down