Skip to content
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

Add node types to container-loader #3142

Closed
wants to merge 1 commit into from
Closed

Add node types to container-loader #3142

wants to merge 1 commit into from

Conversation

ChumpChief
Copy link
Contributor

We aren't getting type checking on node functionality we're using in the container-loader package (e.g. url.parse). This includes @types/node and does fixup for a timer type usage that was assuming window.setTimeout.

@@ -80,6 +80,7 @@
"@types/jwt-decode": "^2.2.1",
"@types/lodash": "^4.14.118",
"@types/mocha": "^5.2.5",
"@types/node": "^10.17.24",
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this goes against @curtisman changes. I think the desire is to use tslib signatures, that have number here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe the problem is unique to parse, I'll look around for if a more targeted fix exists. I'd like to understand better though if this is a safe direction to go (e.g. what if I'm running this on Node rather than in the browser, where it is in fact not a number).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More targeted fix in #3145. This PR isn't really needed anymore re: parse type and could be closed out, though I'm wondering if the implicit usage of window is something we should be concerned about.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with you that using number or timer looks wrong, as it's correct only on one target. The right fix here is to use isomorphic wrapper with its own type, I assume. I do not know if we are getting anything by not using Node types, I hope Curtis can chime in.

Copy link
Member

Choose a reason for hiding this comment

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

@heliocliu have a fix where the type is derived from the 'ReturnType' of the API, so it is correct in both context.
he returned value is abstract to us anyways, so in reality any time is fine.

We shouldn't include node types to make sure these isomorphic packages don't accidentally depends on things that needs polyfill or stop working for browser (which has happened before)

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the same change Matt makes here, minus adding the Node typings. Probably still makes sense to add the ReturnType change though, such as for tests that need the typings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I generally agree with trying to avoid polyfill usage where possible, but I don't believe excluding the types prevents that. Here we're already depending on the browserify url polyfill in utils.ts -- we just don't get type info for it.

Other options considered:

  1. Explicitly include the url package in package.json -- doesn't change anything
  2. Look for isolated typing of the url package -- doesn't seem to be an option, only included as part of @node/types here.
  3. Switch to standard URL, avoiding the polyfill and also getting typings -- tried in Use URL instead of parse in container-loader utils #3145, but learned the standard URL doesn't handle unknown protocols the same way. We should probably get rid of our usage of non-standard/unknown protocols but this would be a non-trivial change.

If adding node types is a non-starter then I'll probably just close both PRs out and log bugs for (1) removing our usage of non-standard protocols (2) converting usage of parse() to URL().

@ChumpChief
Copy link
Contributor Author

Closing this out. Opened #3187 and #3188 to track the direction of removing unknown protocols and using standard URL

@ChumpChief ChumpChief closed this Aug 14, 2020
@ChumpChief ChumpChief deleted the LoaderNodeTypes branch September 8, 2020 20:45
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.

None yet

4 participants