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
Allow scoped Cordova packages to be installed #9334
Conversation
Fixes an issue preventing the installation of scoped Cordova packages. For example, `meteor add cordova:@somescope/some-cordova-plugin@1.0.0` will now work properly. Fixes meteor#7336.
packageName: parts[3], | ||
versionSeparator: parts[4], | ||
version: parts[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.
Maybe skip the details
object?
const [
_matchText,
scope,
scopeSeparator,
packageName,
versionSeparator,
version,
] = packageIdAndVersion.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.
@benjamn I actually did exactly that first, but was greeted with the following
TypeError: Cannot read property 'Symbol(Symbol.iterator)' of packageIdAndVersion.match
I decided to switch it around instead of chasing that down further, but I'll investigate. Thanks!
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.
And now for the life of me I can't re-create the same error. So, changes coming!
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.
Thanks for grabbing this issue!
// some-cordova-plugin@1.0.0 | ||
// @somescope/some-cordova-plugin@1.0.0 | ||
exports.parse = packageIdAndVersion => { | ||
const package = {}; |
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.
Likely best to avoid the use of package
as an identifier since it's a "Future Reserved Word" in ECMAScript.
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.
Good call - changing - thanks!
const package = {}; | ||
if (packageIdAndVersion) { | ||
const parts = packageIdAndVersion.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.
/^(@[^\/]*)?(\/)?([^@]*)(@)?(.*)?/
^
When the scope is present in this manner, is it required that there be at least a character after the @
? If so,+
("1+ occurrence") would be more appropriate here than *
("0+ occurrences"). Similar question about the other *
cases.*
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 - also a good call! Changes coming.
tools/tests/cordova-plugins.js
Outdated
const parseCordovaIdVersion = | ||
require('../cordova/package-id-version-parser.js').parse; | ||
|
||
let package = 'some-cordova-plugin'; |
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.
Some package
var concern as above.
scope: parts[1], | ||
scopeSeparator: parts[2], | ||
packageName: parts[3], | ||
versionSeparator: parts[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.
Maybe just not capture versionSeparator
?
/^(?:@([^\/]+)\/)?([^\/@]*)@?(.*)?/
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.
Sounds good!
const package = {}; | ||
if (packageIdAndVersion) { | ||
const parts = packageIdAndVersion.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.
/^(@[^\/]*)?(\/)?([^@]*)(@)?(.*)?/
^^^^^
Could this be included in the first grouping along with the scope and not explicitly captured? Right now this allows /dd@
and puts /
into scopeSeparator
with no scope
.
Maybe...
/^(@[^\/]*\/?)?([^\/@]*)(@)?(.*)?/
... you'll note I also added /
to the negated character class.
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 split the separator out intentionally; I just liked the idea of having buckets for each individual component, so the scope (when available) was the actual scope name without the trailing /
. But, there really isn't any reason to do this, so your point is well taken - changes coming!
packageName: parts[3], | ||
versionSeparator: parts[4], | ||
version: parts[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.
I could probably go further. Is there a way we could avoid the regex and just use a combination of packageIdAndVersion.startsWith('cordova:)
and split on packageIdAndVersion.lastIndexOf('@')
.
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.
Given the tests, and that you may have already spent some time on this, and that overall this is an improvement, I think it's okay as is too if you just wanted to put your hands up. 🙌
😉
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 originally avoided the regex and did just that, but the problem is that we need to catch instances where the version number isn't passed in. So the parse
function can actually have @somescope/some-cordova-plugin
passed in, which means splitting on @
doesn't quite work (since we can have both a valid and invalid package string passed in that has only one @
). We can definitely add code to address this, but it's at this point I decided a regex would probably make more sense. Happy to change it if you disagree though!
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.
Makes sense to me. Thanks for the explanation!
Review items should now be addressed - thanks guys! P.S. --> @abernix is a regex master! 🙌 🏆 |
Hi all - this PR is a continuation of the closed PR #7350, that fixes an issue preventing the installation of scoped Cordova packages. For example,
meteor add cordova:@somescope/some-cordova-plugin@1.0.0
will now work properly.I've updated the closed PR to include the requested code review changes (with a few small modifications), and added some tests.
Fixes #7336. Thanks!