From 41d2ae72a0acb3c3bce724e134730a0b2fdac0d4 Mon Sep 17 00:00:00 2001 From: "nathan.pham" Date: Mon, 26 Feb 2024 11:06:27 +0700 Subject: [PATCH] fix: the dependencies feature is didn't work fix: you have to provide type for getIt --- .gitignore | 1 + injectable/pubspec.lock | 45 ------------------- injectable/pubspec.yaml | 2 +- .../lib/code_builder/builder_utils.dart | 8 ++-- injectable_generator/pubspec.lock | 34 +++++++------- injectable_generator/pubspec.yaml | 16 +++---- .../test/code_builder/builder_utils_test.dart | 18 ++++++++ 7 files changed, 49 insertions(+), 75 deletions(-) delete mode 100644 injectable/pubspec.lock diff --git a/.gitignore b/.gitignore index 12e3a6e..36f17bc 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ build/ !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +injectable/pubspec.lock diff --git a/injectable/pubspec.lock b/injectable/pubspec.lock deleted file mode 100644 index 320a15d..0000000 --- a/injectable/pubspec.lock +++ /dev/null @@ -1,45 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - collection: - dependency: transitive - description: - name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" - get_it: - dependency: "direct main" - description: - name: get_it - sha256: e6017ce7fdeaf218dc51a100344d8cb70134b80e28b760f8bb23c242437bafd7 - url: "https://pub.dev" - source: hosted - version: "7.6.7" - lints: - dependency: "direct dev" - description: - name: lints - sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 - url: "https://pub.dev" - source: hosted - version: "3.0.0" - meta: - dependency: "direct main" - description: - name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" - url: "https://pub.dev" - source: hosted - version: "1.12.0" -sdks: - dart: ">=3.0.0 <4.0.0" diff --git a/injectable/pubspec.yaml b/injectable/pubspec.yaml index 9fdfca2..1b17923 100644 --- a/injectable/pubspec.yaml +++ b/injectable/pubspec.yaml @@ -8,7 +8,7 @@ environment: dependencies: get_it: ">=7.2.0 <8.0.0" - meta: ^1.12.0 + meta: ^1.11.0 dev_dependencies: lints: ^3.0.0 diff --git a/injectable_generator/lib/code_builder/builder_utils.dart b/injectable_generator/lib/code_builder/builder_utils.dart index 018a69f..91ddd30 100644 --- a/injectable_generator/lib/code_builder/builder_utils.dart +++ b/injectable_generator/lib/code_builder/builder_utils.dart @@ -111,10 +111,10 @@ void _sortByDependents( return true; } // if dep is already in sorted return true - if (lookupDependencyWithNoEnvOrHasAny(iDep, sorted, dep.environments) != - null) { - return true; - } + // if (lookupDependencyWithNoEnvOrHasAny(iDep, sorted, dep.environments) != + // null) { + // return true; + // } // if dep is in unSorted we skip it in this iteration, if not we include it return lookupDependencyWithNoEnvOrHasAny( iDep, unSorted, dep.environments) == diff --git a/injectable_generator/pubspec.lock b/injectable_generator/pubspec.lock index 18830e6..207a701 100644 --- a/injectable_generator/pubspec.lock +++ b/injectable_generator/pubspec.lock @@ -69,18 +69,18 @@ packages: dependency: transitive description: name: build_resolvers - sha256: "6c4dd11d05d056e76320b828a1db0fc01ccd376922526f8e9d6c796a5adbac20" + sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a" url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.4.2" build_runner: dependency: "direct dev" description: name: build_runner - sha256: "10c6bcdbf9d049a0b666702cf1cee4ddfdc38f02a19d35ae392863b47519848b" + sha256: "581bacf68f89ec8792f5e5a0b2c4decd1c948e97ce659dc783688c8a88fbec21" url: "https://pub.dev" source: hosted - version: "2.4.6" + version: "2.4.8" build_runner_core: dependency: transitive description: @@ -93,10 +93,10 @@ packages: dependency: "direct dev" description: name: build_test - sha256: "927ef98b58c5603ec58923c0bb943a74743e58149732665885bb1eb92983befe" + sha256: "260dbba934f41b0a42935e9cae1f5731b94f0c3e489dc97bcf8e281265aaa5ae" url: "https://pub.dev" source: hosted - version: "2.1.7" + version: "2.2.2" built_collection: dependency: transitive description: @@ -255,7 +255,7 @@ packages: path: "../injectable" relative: true source: path - version: "2.3.5" + version: "2.4.0" io: dependency: transitive description: @@ -284,10 +284,10 @@ packages: dependency: "direct dev" description: name: lints - sha256: "6b0206b0bf4f04961fc5438198ccb3a885685cd67d4d4a32cc20ad7f8adbe015" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "3.0.0" logging: dependency: transitive description: @@ -300,10 +300,10 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" meta: dependency: "direct main" description: @@ -484,26 +484,26 @@ packages: dependency: "direct dev" description: name: test - sha256: b9a384c4b9c4966dbf7215e7c033a78db1da7e5dcaf8da9232c5f24735f65652 + sha256: "7ee446762c2c50b3bd4ea96fe13ffac69919352bd3b4b17bac3f3465edc58073" url: "https://pub.dev" source: hosted - version: "1.24.5" + version: "1.25.2" test_api: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" test_core: dependency: transitive description: name: test_core - sha256: c6a536288535efef8526eea8adfa4e25fdd2849fa7f457ecb2a52099998ce8f7 + sha256: "2bc4b4ecddd75309300d8096f781c0e3280ca1ef85beda558d33fcbedc2eead4" url: "https://pub.dev" source: hosted - version: "0.5.5" + version: "0.6.0" timing: dependency: transitive description: diff --git a/injectable_generator/pubspec.yaml b/injectable_generator/pubspec.yaml index 9b82711..61bcabe 100644 --- a/injectable_generator/pubspec.yaml +++ b/injectable_generator/pubspec.yaml @@ -15,13 +15,13 @@ dependencies: code_builder: ^4.10.0 dart_style: ^2.0.3 injectable: - ^2.4.0 -# path: ../injectable - collection: ^1.17.1 +# ^2.4.0 + path: ../injectable + collection: ^1.18.0 recase: ^4.1.0 - meta: ^1.9.1 + meta: ^1.11.0 dev_dependencies: - build_runner: ^2.3.3 - build_test: ^2.1.3 - test: ^1.17.12 - lints: ^2.0.0 + build_runner: ^2.4.8 + build_test: ^2.2.2 + test: ^1.25.2 + lints: ^3.0.0 diff --git a/injectable_generator/test/code_builder/builder_utils_test.dart b/injectable_generator/test/code_builder/builder_utils_test.dart index 7d819d2..94ed5d3 100644 --- a/injectable_generator/test/code_builder/builder_utils_test.dart +++ b/injectable_generator/test/code_builder/builder_utils_test.dart @@ -37,6 +37,24 @@ void main() { expect(sortDependencies(deps).toList(), expectedResult); }); + test( + 'Sorting with environments in mind, should sort as [B{prd},C,B{dev}},A{dev}]', + () { + final deps = [ + DependencyConfig.factory('A', deps: ['B'], envs: ['dev', 'prod']), + DependencyConfig.factory('B', envs: ['prod']), + DependencyConfig.factory('B', envs: ['dev'], deps: ['C']), + DependencyConfig.factory('C'), + ]; + final expectedResult = [ + DependencyConfig.factory('B', envs: ['prod']), + DependencyConfig.factory('C'), + DependencyConfig.factory('B', envs: ['dev'], deps: ['C']), + DependencyConfig.factory('A', deps: ['B'], envs: ['dev', 'prod']), + ]; + expect(sortDependencies(deps).toList(), expectedResult); + }); + test('should sort as [A,B]', () { final deps = [ DependencyConfig.factory('AppServiceUser', deps: ['Service']),