Skip to content

Commit

Permalink
feat: v2.3.2, sorting & naming fixes (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen-meijer authored Nov 4, 2021
1 parent aec66d3 commit 71f5859
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to the "pubspec-assist" extension will be documented in this
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.3.2 - 2021-11-04

- fix: fix null reference exception when sorting dependencies with unbounded constraints using the legacy sorting system (fixes #97, #95, #89, #88, #76, #74, #73, #63)
- fix: don't display "null" string for dependencies with unbounded constraints

## 2.3.1 - 2021-11-03

- feat: properly handle errors when user's YAML file is not valid (closes #135, #134, #133, #131, #130, #129, #128, #127, #126, #125, #124, #123, #122, #121, #120, #116, #113, #112, #110, #108, #105, #104, #103, #102, #101, #100, #92, #90, #82, #79, #78, #75, #72, #67, #61)
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Jeroen Meijer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pubspec-assist",
"displayName": "Pubspec Assist",
"description": "Easily add and update dependencies to your Dart and Flutter project.",
"version": "2.3.1",
"version": "2.3.2",
"publisher": "jeroen-meijer",
"author": {
"name": "Jeroen Meijer",
Expand Down
25 changes: 23 additions & 2 deletions src/helper/sortDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export function sortDependencies({
};
const pubspecDoc = YAML.parseDocument(pubspecString, options);

// A token used to identify dependencies that are unbounded
// (i.e., have no version constraint), so they can easily be set
// to an empty value later.
const unboundedReplacementToken = "__UNBOUNDED_DEPENDENCY__";

for (const dependencyType of dependencyTypes) {
const dependencyPath = pubspecDoc.get(dependencyType) as
| null
Expand All @@ -33,10 +38,18 @@ export function sortDependencies({
const sortByKey = (a: Pair, b: Pair) =>
(a.key as Scalar).value < (b.key as Scalar).value ? -1 : 1;
const containsKey = (key: string) => (item: Pair) =>
!!item.value &&
item.value.type === "MAP" &&
item.value.items.some((item: Pair) => item.key.value === key);

const baseSortedItems = (dependencyPath.items as Pair[]).sort(sortByKey);
const setNullValuePairsToUnbounded = (item: Pair) =>
!!item.value
? item
: new Pair(item.key, new Scalar(unboundedReplacementToken));

const baseSortedItems = (dependencyPath.items as Pair[])
.sort(sortByKey)
.map(setNullValuePairsToUnbounded);

let sortedDependencies: Pair[] = baseSortedItems;
if (useLegacySorting) {
Expand Down Expand Up @@ -66,7 +79,15 @@ export function sortDependencies({
pubspecDoc.set(dependencyType, newDependencyMap);
}

return pubspecDoc.toString();
const dirtyPubspecString = pubspecDoc.toString();

const cleanPubspecString = dirtyPubspecString
.replace(new RegExp(unboundedReplacementToken, "g"), "")
.split("\n")
.map((line) => line.trimEnd())
.join("\n");

return cleanPubspecString;
}

export default sortDependencies;

0 comments on commit 71f5859

Please sign in to comment.