-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat(*): typescript prettier vitest #57
base: main
Are you sure you want to change the base?
Conversation
@@ -43,7 +43,7 @@ reducer.buildInitialState = buildInitialState; | |||
``` |
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.
I will add the new documentation for how to use this library with typescript before this PR can be merged
}); | ||
} | ||
|
||
export function runVitruviusImmutableTests( |
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.
Its a shame that this function is bifurcated for the sake of the two different type of Vitruvius. However the gymnastics that would be required to do this in a single function like it was before are not worth it for a test file.
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.
aww, by TS overrides are sooooo fun 🤡
other: otherReducer, | ||
static: staticReducer, | ||
}); | ||
const store = configureStore({ reducer }, reducer.buildInitialState(locals)); |
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.
Note, this test did not make it into the other file because TS does not allow it. This is because configureStore
expects 1 parameter and we are passing 2. I can not find any reference online to this function ever taking 2 parameters.
import collectBuiltState, { VitruviusImmutableReducers } from './collectBuiltState'; | ||
|
||
// internal type for use before assigning buildInitial state | ||
type VitruviusImmutableOptionalCombinedReducer<Locals> = ReturnType<typeof combineReducers> & { |
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.
Ironically, the use of ReturnType<typeof combineReducers>
actually weakens the types of vitruvius. This is because redux-immutable does not preserve the types of the combined reducers. Therefore when using the immutable variation of vitruvius, callers will not be able to rely on typescript when accessing the resultant store.
I looked briefly into preserving the types of the reducers within vitruvius itself, but it is extremely complex. I recommend we proceed with the above types, and re-visit this hole in the type chain 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.
Need to circle back to review the code more.
vitest.config.js
Outdated
@@ -0,0 +1,14 @@ | |||
import { defineConfig } from 'vitest/config'; |
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.
Maybe make the vitest.config.js a typescript file?
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.
addressed in 5990a67
@@ -5,27 +5,18 @@ | |||
"main": "lib/index.js", |
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.
Think we need to add a types key.
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.
addressed in 5990a67
package.json
Outdated
"test:lockfile": "lockfile-lint -p package-lock.json -t npm -a npm -o https: -c -i", | ||
"test:unit": "jest", | ||
"test:unit": "npm run build --ignore-scripts && vitest --run", |
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.
Can you make the build a "pretest:unit" script?
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.
addressed in 5990a67
package.json
Outdated
"redux": "^5.0.1", | ||
"redux-immutable": "^4.0.0", | ||
"rimraf": "^5.0.5" | ||
"rimraf": "^5.0.5", | ||
"typescript": "^5.4.4", |
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.
Typescript doesn't follow semver because every change is breaking.
"typescript": "^5.4.4", | |
"typescript": ">=5.4.4", |
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.
wouldn't it be better to pin it then?
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.
Perhaps ~
? Or are even patch versions breaking?
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.
Yeah since it's a dev dep it honestly doesn't really matter.
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.
I just like pointing it out.
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.
addressed in 5990a67
vitest.config.js
Outdated
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.
I wonder why this file didn't get flagged by the issue this PR fixes:
americanexpress/eslint-config-amex#130
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.
This file is being ignored currently
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.
addressed in 5990a67
tsconfig.json
Outdated
"webworker.importscripts", | ||
"scripthost" | ||
], | ||
"jsx": "react", |
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.
"jsx": "react", | |
"jsx": "react", |
Is this needed? this package doesn't contain any react code
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.
addressed in 5990a67
.github/workflows/release-please.yml
Outdated
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.
shouldn't this include a build step now?
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.
We already had an existing build step, its covered by:
"prepublishOnly": "npm run build",
Though, personally, I prefer prepack
over prepublishOnly
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.
Yes, I would suggest prepack
. Otherwise when you run npm pack
it doesn't rebuild.
@@ -1,3 +1,4 @@ | |||
{ | |||
"presets": ["amex"] | |||
"presets": ["amex"], | |||
"plugins": ["@babel/plugin-transform-typescript"] |
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.
Does babel-preset-amex need TS support?
e.g.
{
"presets": ["amex/ts"]
}
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.
honestly, we maybe don't even need a separate file. could just use overrides for .ts
and .tsx
.eslintignore
Outdated
@@ -1,3 +1,5 @@ | |||
lib | |||
node_modules | |||
test-results | |||
vitest.config.js |
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.
Why ignore this?
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.
Aha! That's why it didn't run into this issue:
americanexpress/eslint-config-amex#130
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.
addressed in 5990a67
package.json
Outdated
"amex-jest-preset": "^7.0.0", | ||
"@types/redux-immutable": "^4.0.6", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
"@vitest/coverage-v8": "^2.1.4", | ||
"babel-preset-amex": "^4.0.3", | ||
"coveralls": "^3.1.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-amex": "^16.0.0", |
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.
"eslint-config-amex": "^16.0.0", | |
"eslint-config-amex": "^16.2.0", |
May as well 🤷🏼♀️
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.
addressed in 5990a67
package.json
Outdated
@@ -5,27 +5,18 @@ | |||
"main": "lib/index.js", | |||
"scripts": { | |||
"clean": "rimraf lib", |
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.
"clean": "rimraf lib", | |
"rimraf": "node -e \"process.argv.slice(1).forEach(path => require('node:fs').rmSync(path, { recursive: true, force: true }));\" --", | |
"clean": "npm run rimraf lib", |
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.
addressed in 5990a67
package.json
Outdated
"redux": "^5.0.1", | ||
"redux-immutable": "^4.0.0", | ||
"rimraf": "^5.0.5" | ||
"rimraf": "^5.0.5", |
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.
"rimraf": "^5.0.5", |
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.
addressed in 5990a67
package.json
Outdated
"babel-preset-amex": "^4.0.3", | ||
"coveralls": "^3.1.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-amex": "^16.0.0", | ||
"eslint-import-resolver-typescript": "^3.6.3", | ||
"eslint-plugin-jest": "^27.6.3", |
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.
Is this still needed?
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.
addressed in 5990a67
|
||
exports[`vitruvius should return an initialState that is acceptable to redux toolkit's configureStore 1`] = ` |
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.
Intentionally deleted snapshot?
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.
restored now that this test has been restored as per your suggestion
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.
addressed in
5990a67
other: otherReducer, | ||
static: staticReducer, | ||
}); | ||
const store = configureStore({ reducer }, reducer.buildInitialState(locals)); |
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.
I think it should be:
const store = configureStore({
reducer,
preloadedState: reducer.buildInitialState(locals)
});
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.
you are right
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.
addressed in 5990a67
}); | ||
} | ||
|
||
export function runVitruviusImmutableTests( |
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.
aww, by TS overrides are sooooo fun 🤡
"prebuild": "npm run test:lint && npm run clean", | ||
"build": "babel src -d lib --copy-files", | ||
"prebuild": "npm run test:lint", | ||
"build": "babel src -d lib --extensions '.ts' --copy-files & tsc", | ||
"test": "npm run test:lint && npm run test:unit", |
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.
Can we implement tsd and test our types?
e.g. https://github.com/pinojs/pino-abstract-transport/blob/main/test/types/index.test-d.ts
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.
The idea is that the types are implicitly tested by the incredibly strict configuration we have for tsc and eslint.
I would be happy to investigate tsd as a follow up piece of work
A little feedback on the commit message. It is debatable whether this is a feature, but if it is, only the addition of types is a feature and that's all that should be in the head of the message. Details about refactors and tests should be in the body. This will make for a better changelog upon release |
785fd5e
to
f04d16d
Compare
did an amend to fix, look good now? |
Refactor all code into typescript
f04d16d
to
5990a67
Compare
@code-forger this isn't working for me. I'm not getting the types in the package: As a result getting this error:
|
@smackfu an |
Convert this codebase to typescript (from js), prettier (from nothing) and vitest (from jest)