Skip to content

Commit 32af2f1

Browse files
authored
Don't use the glob mechanism to parse pre-glob workspace entries (#4711)
1 parent b8bd825 commit 32af2f1

File tree

2 files changed

+66
-28
lines changed

2 files changed

+66
-28
lines changed

lib/src/package.dart

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -178,37 +178,46 @@ class Package {
178178

179179
final workspacePackages =
180180
pubspec.workspace.expand((workspacePath) {
181-
final Glob glob;
182-
try {
183-
glob = Glob(
184-
pubspec.languageVersion.supportsWorkspaceGlobs
185-
? workspacePath
186-
: Glob.quote(workspacePath),
187-
);
188-
} on FormatException catch (e) {
189-
fail('Failed to parse glob `$workspacePath`. $e');
190-
}
191181
final packages = <Package>[];
192-
for (final globResult in glob.listSync(root: dir)) {
193-
final pubspecPath = p.join(globResult.path, 'pubspec.yaml');
194-
if (!fileExists(pubspecPath)) continue;
195-
packages.add(
196-
Package.load(
197-
globResult.path,
198-
loadPubspec: loadPubspec,
199-
withPubspecOverrides: withPubspecOverrides,
200-
),
201-
);
202-
}
203-
if (packages.isEmpty) {
204-
final globHint =
205-
!pubspec.languageVersion.supportsWorkspaceGlobs &&
206-
_looksLikeGlob(workspacePath)
207-
? '''
182+
var globHint = '';
183+
if (pubspec.languageVersion.supportsWorkspaceGlobs) {
184+
final Glob glob;
185+
try {
186+
glob = Glob(workspacePath);
187+
} on FormatException catch (e) {
188+
fail('Failed to parse glob `$workspacePath`. $e');
189+
}
190+
for (final globResult in glob.listSync(root: dir)) {
191+
final pubspecPath = p.join(globResult.path, 'pubspec.yaml');
192+
if (!fileExists(pubspecPath)) continue;
193+
packages.add(
194+
Package.load(
195+
globResult.path,
196+
loadPubspec: loadPubspec,
197+
withPubspecOverrides: withPubspecOverrides,
198+
),
199+
);
200+
}
201+
} else {
202+
final pubspecPath = p.join(dir, workspacePath, 'pubspec.yaml');
203+
if (!fileExists(pubspecPath)) {
204+
if (_looksLikeGlob(workspacePath)) {
205+
globHint = '''
208206
\n\nGlob syntax is only supported from language version ${LanguageVersion.firstVersionWithWorkspaceGlobs}.
209207
Consider changing the language version of ${p.join(dir, 'pubspec.yaml')} to ${LanguageVersion.firstVersionWithWorkspaceGlobs}.
210-
'''
211-
: '';
208+
''';
209+
}
210+
} else {
211+
packages.add(
212+
Package.load(
213+
p.join(dir, _useBackSlashesOnWindows(workspacePath)),
214+
loadPubspec: loadPubspec,
215+
withPubspecOverrides: withPubspecOverrides,
216+
),
217+
);
218+
}
219+
}
220+
if (packages.isEmpty) {
212221
fail('''
213222
No workspace packages matching `$workspacePath`.
214223
That was included in the workspace of `${p.join(dir, 'pubspec.yaml')}`.$globHint
@@ -574,3 +583,9 @@ See https://dart.dev/go/workspaces-stray-files for details.
574583
}
575584

576585
bool _looksLikeGlob(String s) => Glob.quote(s) != s;
586+
String _useBackSlashesOnWindows(String path) {
587+
if (Platform.isWindows) {
588+
return p.joinAll(p.split(path));
589+
}
590+
return path;
591+
}

test/workspace_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1892,6 +1892,29 @@ Consider changing the language version of .${s}pubspec.yaml to 3.11.'''),
18921892
skip: Platform.isWindows, // Cannot create directory named "*" on Windows.
18931893
);
18941894

1895+
test('preglob workspace entries can use the platform separator', () async {
1896+
await dir(appPath, [
1897+
libPubspec(
1898+
'myapp',
1899+
'1.2.3',
1900+
extras: {
1901+
'workspace': [p.join('pkgs', 'foo')],
1902+
},
1903+
sdk: '^3.6.0',
1904+
),
1905+
dir('pkgs', [
1906+
dir('foo', [libPubspec('foo', '1.1.1', resolutionWorkspace: true)]),
1907+
]),
1908+
]).create();
1909+
await pubGet(environment: {'_PUB_TEST_SDK_VERSION': '3.11.0'});
1910+
await dir(appPath, [
1911+
packageConfigFile([
1912+
packageConfigEntry(name: 'myapp', path: '.'),
1913+
packageConfigEntry(name: 'foo', path: 'pkgs/foo'),
1914+
], generatorVersion: '3.11.0'),
1915+
]).validate();
1916+
});
1917+
18951918
test('globs are resolved with newer language versions', () async {
18961919
await dir(appPath, [
18971920
libPubspec(

0 commit comments

Comments
 (0)