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

Test cases from #11 for reference implementation #40

Merged
merged 2 commits into from
Jun 26, 2018

Conversation

guybedford
Copy link
Collaborator

I've tried to apply some of the cases mentioned in #11 to the reference implementation and managed to get some odd results for perusal.

Happy to discuss possible solutions here or in #11.

Great work @justinfagnani, the source is a pleasure to read and I was almost worried for a second there you'd managed to elegantly avoid all the edge case issues giving me nothing to complain about :)

@guybedford
Copy link
Collaborator Author

(note that the test results being asserted here are the ones that make the tests pass, not what the expectations should necessarily be)

@guybedford
Copy link
Collaborator Author

I've added a second commit here that adds some basic validations.

I guess the first question is as mentioned in #11 if validations should be performed early (during parsing) or at resolution time as resolution errors.

No stress at all if this implementation is entirely undesired - just trying to move conversations forward on this.

@domenic
Copy link
Collaborator

domenic commented Jun 8, 2018

Splitting this up into two commits was really helpful; thanks for doing that.

I do think validations should be performed during parsing, not resolution, if possible.

Your tests seem to rely on the implicit "default path is derived from name" rule a bit, which is somewhat confusing. Because I think the rules should probably be different for package names and for paths. For example I think a package like:

  "moment/../notmoment": {
    "path": "moment-slash-dotdot-slash-notmoment",'
    "main": "index.js"
  }

might be fine. You'd just resolve import "moment/../notmoment" to import "http://foo.com/node_modules/moment-slash-dotdot-slash-notmoment/index.js".

So I think it would be helpful to separate validation of package names (which as I stated in #38, I would rather not do) from validation of paths. This would indeed cause validation errors if you use the implicit path-derived-from-name rule and then have a weird package name. But as written the tests don't make it clear which is being checked right now.

As for how we should validate paths: I wonder if we can lean on the URL spec here. The definitions around https://url.spec.whatwg.org/#url-path-segment-string seem helpful. Those definitions are intentionally stricter than what browsers parse; they are what are considered "valid" URLs, mostly for use by conformance checkers or similar things. But we could use that framework to start out restrictive.

@guybedford
Copy link
Collaborator Author

Sure, I've updated the basic type validations to happen on initialization of the package map. For now I've kept the package name validation to happen in this phase as well, until we can work out how to handle these cases.

I do think it would be better to carefully restrict package names to sensible cases by disallowing internal dot segments and trailing slashes, also in terms of users understanding the difference between package names and URLs. While yes these apply to the "package names as path" cases, they are still interpretations of the package name. Paths can be looser by definition so I do very much see these as package name validations.

For example, if a user were to mistakenly provide a URL-like into a package name (absolute URL, dot seegments). I've added the leading separator and URL case as well as a validation for now to demonstrate the usability here, which I think would be a nice cue for users to understand package names as something different.

If we do decide to go with more loose package name interpretations allowing these things without the stricter validations, that still leaves us with the trailing slash case which is problematic - package-name/ as the package name:

@domenic domenic changed the base branch from implementation to master June 14, 2018 21:52
@domenic domenic changed the base branch from master to implementation June 14, 2018 21:52
@guybedford guybedford changed the base branch from implementation to master June 17, 2018 15:05
Copy link
Collaborator

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Thanks, looks great! We'll start here and perhaps get more restrictive over time.

@domenic domenic merged commit 315fbed into WICG:master Jun 26, 2018
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