Skip to content

Commit e021241

Browse files
committed
Don't use the glob mechanism to parse pre-glob workspace entries
1 parent b8bd825 commit e021241

File tree

2 files changed

+60
-28
lines changed

2 files changed

+60
-28
lines changed

lib/src/package.dart

Lines changed: 37 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, 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

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)