-
Notifications
You must be signed in to change notification settings - Fork 28
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
Adding support for npm namespaces #143
Conversation
Codecov Report
@@ Coverage Diff @@
## master #143 +/- ##
=========================================
+ Coverage 85.87% 86.08% +0.2%
=========================================
Files 1 1
Lines 545 546 +1
Branches 135 133 -2
=========================================
+ Hits 468 470 +2
Misses 32 32
+ Partials 45 44 -1
Continue to review full report at Codecov.
|
@rorticus which issue does this resolve? |
The linked one is this PR :) |
@rorticus presumably this doesn't break support for having all packages under one pseudo package, which I think we get as a side effect currently? https://github.com/dojo/widget-core/blob/master/tests/intern.ts#L60 |
src/loader.ts
Outdated
@@ -544,7 +544,7 @@ declare const Packages: {} | undefined; | |||
} | |||
|
|||
function getModuleInformation(moduleId: string, referenceModule?: DojoLoader.Module): DojoLoader.Module { | |||
let match = moduleId.match(/^([^\/]+)(\/(.+))?$/); | |||
let match = moduleId.match(/^((?:@[^\/]*\/)?[^\/]+)(\/(.+))?$/); |
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 know you were fixing this, but I think we should clean this regex up.
It seems like the second capture group isn't used and should be ?:
out.
Also, we should use destructuring to be more modern in the way we deal with 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.
@kitsonk so I actually ended up taking the regex out..
OK, this has been updated to support @matt-gadd 's example he mentioned above. The way it works now is that it searches all configured packages and finds the longest match, then uses that to load the module, assuming that the rest of the unmatched package is the module id. Example, require.config({
packages: [
{ name: '@dojo', location: 'node_modules/@dojo' },
{ name: '@dojo/shim', location: '/path/to/shim' },
]
});
require([
'@dojo/shim', // will load from /path/to/shim/main
'@dojo/shim/Map', // will load from /path/to/shim/Map
'@dojo/has/has' // will load from node_modules/@dojo/has/has
], (shim, has ) => { /*...*/ }) |
Type: feature
The following has been addressed in the PR:
Description:
Adding support for npm namespaces when loading modules. Previously, a configuration like this,
@some-package/some-module
would get interpreted as@some-package/some-module.js
becausepackage/main
syntax is supported. This would cause the package configuration to not apply as the name would not be what you expected.With this change, if a module id contains the
@
sign, it is considered part of the package name.Resolves #143