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

fix: alphabetical sort method now handles missing data better #125

Merged
merged 1 commit into from
Oct 22, 2021

Conversation

TheMcMurder
Copy link
Contributor

We had a small error where one of our import-maps didn't have a "scope" property and using alphabetical: true threw errors. Correcting the data was enough to fix it but I thought I would be nice to also handle this better and clean up the code a bit.

@@ -86,14 +86,12 @@ exports.modifyImportMap = function (env, newValues) {
const { services, scopes } = newValues;

const alphabetical = !!getConfig().alphabetical;
const newImports =
services && typeof services === "object" && alphabetical
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 added all this last time. I could've saved myself a fair amount of pain by making sortObjectAlphabeticallyByKeys handle unexpected data better, which is what this PR does.

@@ -160,10 +158,15 @@ exports.modifyService = function (
exports.getEmptyManifest = getEmptyManifest;

function sortObjectAlphabeticallyByKeys(unordered) {
if (!unordered) {
return unordered;
}
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 opted to have this return the falsey value so that if your source import-map.json doesn't have scopes it doesn't get magically added be defaulting it to an empty object.

@TheMcMurder TheMcMurder merged commit ad02a26 into main Oct 22, 2021
@TheMcMurder TheMcMurder deleted the alphabetical-sort-fix branch October 22, 2021 21:46
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