Skip to content

v1.2.0 - findAll, ImportPath class and use of ascii_art_tree. #3

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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8eacba6
v1.2.0 - `findAll`, `ImportPath` class and use of `ascii_art_tree`.
gmpassos Sep 3, 2023
eaba85a
pubspec.yaml: adjusted `dev_dependencies:`
gmpassos Sep 3, 2023
4fb8a35
Clean code
gmpassos Sep 3, 2023
1b686fa
`README.md`: add badges
gmpassos Sep 3, 2023
91f38c8
`README.md`: add badges
gmpassos Sep 3, 2023
a7f54f6
Dart CI: added windows and macos tests
gmpassos Sep 3, 2023
d341af6
`README.md`: update package description
gmpassos Sep 3, 2023
5e80367
ascii_art_tree: ^1.0.4
gmpassos Sep 4, 2023
01b94b0
Using package `args` to resolve command flags and usage.
gmpassos Sep 6, 2023
43e8940
README.md: adjust license link
gmpassos Sep 6, 2023
9fd4252
`ImportPath`: make field `importToFind` final and `Object`.
gmpassos Sep 6, 2023
891a1b5
only show `ImportPath`
gmpassos Sep 6, 2023
359f31f
New class `ImportToFind` for import matching.
gmpassos Sep 6, 2023
cc2a7f1
`ImportPath`: resolve field `searchRoot` during construction.
gmpassos Sep 6, 2023
bed45b8
`ImportPath`: make `_stripSearchRoot` private.
gmpassos Sep 6, 2023
92636b2
Added enum `ImportPathStyle` (dots, elegant, json) ; added JSON output.
gmpassos Sep 6, 2023
1793d72
`ImportPath`: fix `style` parameter documentation.
gmpassos Sep 6, 2023
faeb219
`ImportPath`: fix `style` parameter documentation.
gmpassos Sep 6, 2023
ae1ddb0
`_searchImportPaths`: rename `node` to `currentNode`
gmpassos Sep 7, 2023
955c8c8
- Moved code to class `ImportPath`, `ImportPathScanner` and `ImportPa…
gmpassos Sep 11, 2023
944b3e7
rollback license.
gmpassos Sep 11, 2023
750acb1
Update CHANGELOG.md
gmpassos Sep 12, 2023
6e27209
`ImportParser.importsFor`: added internal cache ; ascii_art_tree: ^1.…
gmpassos Sep 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Dart CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Dart version
run: |
dart --version
uname -a
- name: Install dependencies
run: dart pub get
- name: Upgrade dependencies
run: dart pub upgrade
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary - a get always fetches the latest versions unless there is a pubspec.lock present.

Either way we should only do one of a get or upgrade though.

Copy link
Author

@gmpassos gmpassos Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory I agree with you, until I had some real world issues.

I only have included the upgrade command because in some cases the GitHub workflow has come cached packages and is not getting the last version for some pre-installed packages.

dart pub get only gets the last version if it's downloading the package for the first time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dart pub get

If the system cache doesn’t already contain the dependencies, dart pub get updates the cache, downloading dependencies if necessary.

From:
https://dart.dev/tools/pub/cmd/pub-get

When running dart pub get, if a dependency is already in the cache and matches the constraint, it won't download a newer version.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That isn't my experience with how it works, but I am fine with using dart pub upgrade. We definitely don't need both though (just remove the get then).

- name: dart format
run: dart format -o none --set-exit-if-changed .
- name: dart analyze
run: dart analyze --fatal-infos --fatal-warnings .
- name: dependency_validator
run: dart run dependency_validator
- name: dart pub publish --dry-run
run: dart pub publish --dry-run


test_linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Dart version
run: |
dart --version
uname -a
- name: Install dependencies
run: dart pub get
- name: Upgrade dependencies
run: dart pub upgrade
- name: Run tests
run: dart run test --platform vm --coverage=./coverage
- name: Generate coverage report
run: |
dart pub global activate coverage
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o ./coverage/lcov.info -i ./coverage
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# with:
# directory: ./coverage/
# flags: unittests
# env_vars: OS,DART
# fail_ci_if_error: true
# verbose: true

test_windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Dart version
run: |
dart --version
uname -a
- name: Install dependencies
run: dart pub get
- name: Upgrade dependencies
run: dart pub upgrade
- name: Run tests
run: dart run test --platform vm


test_macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
- name: Dart version
run: |
dart --version
uname -a
- name: Install dependencies
run: dart pub get
- name: Upgrade dependencies
run: dart pub upgrade
- name: Run tests
run: dart run test --platform vm

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

# Coverage files
coverage/

.DS_Store
4 changes: 2 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Below is a list of people and organizations that have contributed
# to the project. Names should be added to the list like so:
#
# Name/Organization <email address>
# Name/Organization <contact>

Jacob MacDonald <[email protected]>
Graciliano M. Passos: gmpassos @ GitHub
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add me back :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was editing other package and edited the wrong file.
Do you want to remove your email? And add just @ GitHub?

16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 1.2.0

- CLI:
- Using `ascii_art_tree` to show the output tree, with styles `dots` (original) and `elegant`.
- Added options:
- `--regexp`: to use `RegExp` to match the target import.
- `--all`: to find all the import paths.
- `--quiet`: for a quiet output (only displays found paths).
- `--strip`: strips the search root directory from displayed import paths.
- `--format`: Defines the style for the output tree (elegant, dots, json).
- `--fast`: to enable a fast import parser.
- Improved help with examples.
- Added support for conditional imports.
- Added public libraries to facilitate integration with other packages.
- Updated `README.md` to show CLI and Library usage.

# 1.1.1

- Add explicit executables config to the pubspec.yaml.
Expand Down
85 changes: 79 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,98 @@
A tool to find the shortest import path from one dart file to another.
# import_path

## Usage
[![pub package](https://img.shields.io/pub/v/import_path.svg?logo=dart&logoColor=00b9fc)](https://pub.dartlang.org/packages/import_path)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Dart CI](https://github.com/jakemac53/import_path/actions/workflows/dart.yml/badge.svg?branch=master)](https://github.com/jakemac53/import_path/actions/workflows/dart.yml)
[![GitHub Tag](https://img.shields.io/github/v/tag/jakemac53/import_path?logo=git&logoColor=white)](https://github.com/jakemac53/import_path/releases)
[![Last Commits](https://img.shields.io/github/last-commit/jakemac53/import_path?logo=git&logoColor=white)](https://github.com/jakemac53/import_path/commits/master)
[![Pull Requests](https://img.shields.io/github/issues-pr/jakemac53/import_path?logo=github&logoColor=white)](https://github.com/jakemac53/import_path/pulls)
[![Code size](https://img.shields.io/github/languages/code-size/jakemac53/import_path?logo=github&logoColor=white)](https://github.com/jakemac53/import_path)
[![License](https://img.shields.io/github/license/jakemac53/import_path?logo=open-source-initiative&logoColor=green)](https://github.com/jakemac53/import_path/blob/master/LICENSE)

A tool to find the shortest import path or listing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A tool to find the shortest import path or listing
A tool to find the shortest import path or list

all import paths between two Dart files.
It also supports the use of `RegExp` to match imports.

## CLI Usage

First, globally activate the package:

`dart pub global activate import_path`
```shell
dart pub global activate import_path
```

Then run it, the first argument is the library or application that you want to
start searching from, and the second argument is the import you want to search
for.

`import_path <entrypoint> <import>`
```shell
import_path <entrypoint> <import>
```

Files should be specified as dart import uris, so relative or absolute file
paths, as well as `package:` and `dart:` uris are supported.

## Example
## Examples

From the root of this package, you can do:

```
```shell
pub global activate import_path

import_path bin/import_path.dart package:analyzer/dart/ast/ast.dart
```

To find all the `dart:io` imports from a `web/main.dart`:

```shell
import_path web/main.dart dart:io --all
```

Search for all the imports for "dart:io" and "dart:html" using `RegExp`:

```shell
import_path web/main.dart "dart:(io|html)" --regexp --all
```
For help or more usage examples:

```shell
import_path --help
```

## Library Usage

You can also use the class `ImportPath` from your code:

```dart
import 'package:import_path/import_path.dart';

void main(List<String> args) async {
var strip = args.any((a) => a == '--strip' || a == '-s');

var importPath = ImportPath(
Uri.base.resolve('bin/import_path.dart'),
'package:analyzer/dart/ast/ast.dart',
strip: strip,
);

await importPath.execute();
}
```

## Features and bugs

Please file feature requests and bugs at the [issue tracker][tracker].

[tracker]: https://github.com/jakemac53/import_path/issues

## Authors

- Jacob MacDonald: [jakemac53][github_jakemac53].
- Graciliano M. Passos: [gmpassos][github_gmpassos].

[github_jakemac53]: https://github.com/jakemac53
[github_gmpassos]: https://github.com/gmpassos

## License

Dart free & open-source [license](https://github.com/jakemac53/import_path/blob/master/LICENSE).
30 changes: 30 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use this one:

Suggested change
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

(will also need to add a dev dependency)


# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
Loading