Skip to content

fix: improve types and remove path-exists dependency #6552

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

outslept
Copy link
Contributor

🎉 Thanks for submitting a pull request! 🎉

Summary

Refactor the functions-utils package to fix linting & types and remove the external path-exists dependency.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

image

outslept added 4 commits July 12, 2025 17:45
Remove temporary TypeScript ESLint rule suppressions for:
- packages/functions-utils/src/main.ts
- packages/functions-utils/tests/main.test.ts
Replace the external `path-exists` dependency with native Node.js fs/promises
access() function to eliminate external dependency.

Add FailOptions interface to eliminate all unsafe type assignments.

Updated import statements to use specific named imports instead of namespace
imports.

Update error
patterns to use return statements after fail() calls.
Replace path-exists dependency in tests with native fs/promises access().

Add TypeScript interface for the
normalizeFiles function to ensure type safety for params.

Replace unsafe type assertions with TypeScript error suppression
comment.

Add null checks and type guards for list/listAll function results.
@outslept outslept requested a review from a team as a code owner July 12, 2025 15:01
@outslept outslept changed the title refactor: improve types and remove path-exists dependency fix: improve types and remove path-exists dependency Jul 12, 2025
@outslept
Copy link
Contributor Author

outslept commented Jul 12, 2025

off topic: based on the logs, the nudge action expects comment-tag but the current workflow uses comment_tag. perhaps this param can be updated in the future?

and regarding the failing edge-bundler test - it should be unrelated to my changes.

@mrstork
Copy link
Contributor

mrstork commented Jul 12, 2025

off topic: based on the logs, the nudge action expects comment-tag but the current workflow uses comment_tag. perhaps this param can be updated in the future?

Thank you! I'll look into correcting this separate from your changes

and regarding the failing edge-bundler test - it should be unrelated to my changes.

Correct, we unfortunately have some flakiness in our test suite currently. I've cleared that red x up for you

'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of these appear to still be necessary to suppress issues that have not yet been resolved
Running npm run lint returns ✖ 23 problems (23 errors, 0 warnings)
It does look as though this line specifically (i.e. '@typescript-eslint/restrict-template-expressions': 'off',) can be removed.

@@ -117,7 +139,8 @@ const normalizeFiles = function (fixtureDir, { name, mainFile, runtime, extensio
test('Can list function main files with list()', async () => {
const fixtureDir = `${FIXTURES_DIR}/list`
const functions = await list(fixtureDir)
expect(sortOn(functions, ['mainFile', 'extension'])).toEqual(
expect(functions).toBeDefined()
expect(sortOn(functions!, ['mainFile', 'extension'])).toEqual(
Copy link
Contributor

@mrstork mrstork Jul 12, 2025

Choose a reason for hiding this comment

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

Using functions! here gives me the following lint error:

This assertion is unnecessary since the receiver accepts the original type of the expression.eslint[@typescript-eslint/no-unnecessary-type-assertion](https://typescript-eslint.io/rules/no-unnecessary-type-assertion)

(side note for me to look into - I'm not sure why this isn't raising an error in CI)

Would you be able to share some context on this change? I'm thinking we should be able to stick with the original assertions

Copy link
Contributor Author

@outslept outslept Jul 12, 2025

Choose a reason for hiding this comment

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

That's sort of weird, but I cannot reproduce. Ran npx eslint packages/functions-utils/tests/main.test.ts from root - no type assertion errors (doesn't show any errors at all for me for some reason)

Verified config via npx eslint --print-config (eslint --inspect-config works as well) - rule is enabled and set to [2] (error)

Even tried reinstalling the editor and still zero success.

Output tab in VS Code with eslint.debug enabled in .vscode/settings.json also shows nothing except ESLint working without errors.

image

And this is the npm run lint run from root

image

I'll try to reproduce in neovim.

Copy link
Contributor Author

@outslept outslept Jul 12, 2025

Choose a reason for hiding this comment

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

Was able to get the errors in Github Codespaces.

This still has some "quirks":

In Codespaces, running npm installnpm run lint shows the errors (including the @typescript-eslint/no-unnecessary-type-assertion you mentioned). However, after running npm run build, subsequent npm run lint runs show zero errors.

I know about --cache and stuff, but even without --cache eslint shows zero errors after build.

Copy link
Contributor Author

@outslept outslept Jul 12, 2025

Choose a reason for hiding this comment

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

To keep the experiment clean, I removed .eslintcache from .gitignore

image

Output is clean after running the command. And we get the error without !:

image

Copy link
Contributor Author

@outslept outslept Jul 12, 2025

Choose a reason for hiding this comment

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

Hope this is helpful and can help us find the cause! I don't think I can dig any further. Perhaps this is caused by project references in Typescript?

https://www.typescriptlang.org/docs/handbook/project-references.html

Copy link
Contributor

Choose a reason for hiding this comment

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

When you have some time, could you please remove your .eslintcache and see if you can still reproduce?

Copy link
Contributor Author

@outslept outslept Jul 17, 2025

Choose a reason for hiding this comment

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

Nope, can only reproduce the same inconsistent ESLint behavior: git clonenpm installnpm run lint:ci shows errors, after rm .eslintcache -> npm run buildnpm run lint:ci no previous errors are shown.

Locally I've migrated to projectService and added additional tsconfig files since some files weren't being caught properly, which was causing slow processing.

I'll open a separate PR with this proposal over the weekend.

Also this should be solved by that PR:

(side note for me to look into - I'm not sure why this isn't raising an error in CI)

UPD: I'll convert this to draft until this behavior is resolved

@outslept outslept marked this pull request as draft July 17, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants