Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.0

* Removes `path_to_regexp` from the dependencies.

## 2.2.2

* Bumps example go_router version and migrate example code.
Expand Down
6 changes: 3 additions & 3 deletions packages/go_router_builder/lib/src/route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import 'package:analyzer/dart/element/type.dart';
import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:path_to_regexp/path_to_regexp.dart';
import 'package:source_gen/source_gen.dart';
import 'package:source_helper/source_helper.dart';

import 'type_helpers.dart';
import 'utils/path_token.dart';

/// Custom [Iterable] implementation with extra info.
class InfoIterable extends IterableBase<String> {
Expand Down Expand Up @@ -84,7 +84,7 @@ class GoRouteConfig extends RouteBaseConfig {
.map((ParameterToken e) => e.name));

late final List<Token> _parsedPath =
List<Token>.unmodifiable(parse(_rawJoinedPath));
List<Token>.unmodifiable(Token.parse(_rawJoinedPath));

String get _rawJoinedPath {
final List<String> pathSegments = <String>[];
Expand All @@ -111,7 +111,7 @@ class GoRouteConfig extends RouteBaseConfig {
return '\${Uri.encodeComponent(${_encodeFor(e.name)}${type?.isEnum ?? false ? '!' : ''})}';
}
if (e is PathToken) {
return e.value;
return e.name;
}
throw UnsupportedError(
'$likelyIssueMessage '
Expand Down
61 changes: 61 additions & 0 deletions packages/go_router_builder/lib/src/utils/path_token.dart
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is very much inspired by path_to_regexp library, I don't know if I'm allowed to do that

Copy link
Collaborator

Choose a reason for hiding this comment

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

What does "inspired by" mean? If you read the source of that package as part of writing this implementation, then no, that would disqualify you from contributing an implementation (in which case this PR should be closed).

Copy link
Contributor Author

@ValentinVignal ValentinVignal Jul 19, 2023

Choose a reason for hiding this comment

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

I did read the package source code to understand what was actually happening and how go_router_builder was using it.

I guess the PR cannot be merged as it is right now. Before closing it, let me try to clean it out and re-write something else.
But go_router_builder already has its methods built around it so it might end up looking similar anyway

Copy link
Collaborator

Choose a reason for hiding this comment

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

Before closing it, let me try to clean it out and re-write something else.

You cannot unsee the implementation, so any implementation you write will not be a clean room implementation, and would not satisfy licensing requirements.

Someone else will need to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I cannot work on this issue anymore? 😕

What if I find another way to code it that is not similar to the package? Would that work?

Copy link
Collaborator

Choose a reason for hiding this comment

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

So I cannot work on this issue anymore? 😕

That is correct. We need a clean room implementation of the functionality this package needs, and you cannot provide that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is correct. We need a clean room implementation of the functionality this package needs, and you cannot provide that.

Even if as I suggested the implementation's logic is completely different? What would be the issue with that since it would explicitly not be inspired by the package?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if as I suggested the implementation's logic is completely different? What would be the issue with that since it would explicitly not be inspired by the package?

I'm not a lawyer, and I have no interest in unnecessarily involving lawyers in the process of fixing the referenced issue.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// The base type of all tokens produced by a path specification.
abstract class Token {
/// The name of the parameter.
String get name;

/// Parses a [path] specification.
static List<Token> parse(String path) => _parse(path);
}

/// Corresponds to a parameter of a path specification.
class ParameterToken implements Token {
/// Creates a parameter token for [name].
ParameterToken(this.name);

/// The parameter name.
@override
final String name;
}

/// Corresponds to a non-parameterized section of a path specification.
class PathToken implements Token {
/// Creates a path token with [name].
PathToken(this.name);

/// A substring of the path specification.
@override
final String name;
}

/// The regular expression used to extract parameters from a path specification.
///
/// Capture groups:
/// 1. The parameter name.
/// 2. An optional pattern.
final RegExp _parameterRegExp = RegExp(
/* (1) */ r':(\w+)'
/* (2) */ r'(\((?:\\.|[^\\()])+\))?',
);

/// Parses a [path] specification.
List<Token> _parse(String path) {
final Iterable<RegExpMatch> matches = _parameterRegExp.allMatches(path);
final List<Token> tokens = <Token>[];
int start = 0;
for (final RegExpMatch match in matches) {
if (match.start > start) {
tokens.add(PathToken(path.substring(start, match.start)));
}
final String name = match[1]!;
tokens.add(ParameterToken(name));
start = match.end;
}
if (start < path.length) {
tokens.add(PathToken(path.substring(start)));
}
return tokens;
}
3 changes: 1 addition & 2 deletions packages/go_router_builder/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: go_router_builder
description: >-
A builder that supports generated strongly-typed route helpers for
package:go_router
version: 2.2.2
version: 2.3.0
repository: https://github.com/flutter/packages/tree/main/packages/go_router_builder
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router_builder%22

Expand All @@ -17,7 +17,6 @@ dependencies:
collection: ^1.14.0
meta: ^1.7.0
path: ^1.8.0
path_to_regexp: ^0.4.0
source_gen: ^1.0.0
source_helper: ^1.3.0

Expand Down