Skip to content

Commit fd3d988

Browse files
authored
Adapt paths for different development environments (#336)
* Fix path to adapt cross-platform development * add changes to CHANGELOG.md * remove test changelog in CHANGELOG * remove variable to be wrapped immediately after - remove redundant call `p.context` * add comment for manually modifying the path
1 parent 7f440e4 commit fd3d988

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

web/test/dart_fix_test.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ void main() {
2525

2626
try {
2727
// set up project
28+
// Convert the current path to a POSIX path to avoid 'path_not_posix' lint.
2829
writeFile(tempDir, 'pubspec.yaml', '''
2930
name: test_project
3031
environment:
3132
sdk: '^$sdkVersion'
3233
dependencies:
3334
web:
34-
path: ${Directory.current.path}
35+
path: ${p.current.replaceAll(r'\', '/')}
3536
''');
3637
final sourceFile = File(p.join('test_fixes', 'renames.dart'));
3738
writeFile(

web_generator/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
description.
1010
- Added `--generate-all` option to generate all bindings, including experimental
1111
and non-standard APIs.
12+
- Adapt paths for different development environments.

web_generator/bin/scrape_mdn.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Future<void> main(List<String> args) async {
1414
final offline = args.length == 1 && args.first == '--offline';
1515

1616
// clone the repo
17-
final repoDir =
18-
Directory(Platform.script.resolve('../.dart_tool/mdn_content').path);
17+
final repoPath =
18+
p.fromUri(Platform.script.resolve('../.dart_tool/mdn_content'));
19+
final repoDir = Directory(repoPath);
1920
if (!repoDir.existsSync()) {
2021
await _run(
2122
'git',
@@ -77,9 +78,9 @@ Future<void> main(List<String> args) async {
7778
print('${interfaces.length} items read from $gitUrl.');
7879

7980
const encoder = JsonEncoder.withIndent(' ');
80-
81-
final file =
82-
File(Platform.script.resolve('../../third_party/mdn/mdn.json').path);
81+
final filePath =
82+
p.fromUri(Platform.script.resolve('../../third_party/mdn/mdn.json'));
83+
final file = File(filePath);
8384
final json = {
8485
'__meta__': {
8586
'source': '[MDN Web Docs]($mdnUrl)',

web_generator/bin/update_bindings.dart

+16-15
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $_usage''');
3535
return;
3636
}
3737

38-
assert(p.fromUri(Platform.script).endsWith(_thisScript));
38+
assert(p.fromUri(Platform.script).endsWith(_thisScript.toFilePath()));
3939

4040
// Run `npm install` or `npm update` as needed.
4141
final update = argResult['update'] as bool;
@@ -68,7 +68,7 @@ $_usage''');
6868
}
6969

7070
// Determine the set of previously generated files.
71-
final domDir = Directory(p.join(_webPackagePath, 'lib/src/dom'));
71+
final domDir = Directory(p.join(_webPackagePath, 'lib', 'src', 'dom'));
7272
final existingFiles =
7373
domDir.listSync(recursive: true).whereType<File>().where((file) {
7474
if (!file.path.endsWith('.dart')) return false;
@@ -86,7 +86,7 @@ $_usage''');
8686
'node',
8787
[
8888
'main.mjs',
89-
'--output-directory=${p.join(_webPackagePath, 'lib/src')}',
89+
'--output-directory=${p.join(_webPackagePath, 'lib', 'src')}',
9090
if (generateAll) '--generate-all',
9191
],
9292
workingDirectory: _bindingsGeneratorPath,
@@ -101,9 +101,8 @@ $_usage''');
101101
}
102102

103103
// Update readme.
104-
final readmeFile = File(
105-
p.normalize(Platform.script.resolve('../README.md').path),
106-
);
104+
final readmeFile =
105+
File(p.normalize(p.fromUri(Platform.script.resolve('../README.md'))));
107106

108107
final sourceContent = readmeFile.readAsStringSync();
109108

@@ -148,7 +147,7 @@ Future<String> _webPackageLanguageVersion(String pkgPath) async {
148147
return '$languageVersion.0';
149148
}
150149

151-
final _webPackagePath = Platform.script.resolve('../../web').path;
150+
final _webPackagePath = p.fromUri(Platform.script.resolve('../../web'));
152151

153152
String _packageLockVersion(String package) {
154153
final packageLockData = jsonDecode(
@@ -161,18 +160,19 @@ String _packageLockVersion(String package) {
161160
return webRefIdl['version'] as String;
162161
}
163162

164-
final _bindingsGeneratorPath = Platform.script.resolve('../lib/src').path;
163+
final _bindingsGeneratorPath = p.fromUri(Platform.script.resolve('../lib/src'));
165164

166165
const _webRefCss = '@webref/css';
167166
const _webRefElements = '@webref/elements';
168167
const _webRefIdl = '@webref/idl';
169168

170-
const _thisScript = 'bin/update_bindings.dart';
169+
final _thisScript = Uri.parse('bin/update_bindings.dart');
170+
final _scriptPOSIXPath = _thisScript.toFilePath(windows: false);
171171

172-
const _startComment =
173-
'<!-- START updated by $_thisScript. Do not modify by hand -->';
174-
const _endComment =
175-
'<!-- END updated by $_thisScript. Do not modify by hand -->';
172+
final _startComment =
173+
'<!-- START updated by $_scriptPOSIXPath. Do not modify by hand -->';
174+
final _endComment =
175+
'<!-- END updated by $_scriptPOSIXPath. Do not modify by hand -->';
176176

177177
Future<void> _runProc(
178178
String executable,
@@ -184,6 +184,7 @@ Future<void> _runProc(
184184
executable,
185185
arguments,
186186
mode: ProcessStartMode.inheritStdio,
187+
runInShell: Platform.isWindows,
187188
workingDirectory: workingDirectory,
188189
);
189190
final procExit = await proc.exitCode;
@@ -197,7 +198,7 @@ Future<void> _runProc(
197198
Future<void> _generateJsTypeSupertypes() async {
198199
// Use a file that uses `dart:js_interop` for analysis.
199200
final contextCollection = AnalysisContextCollection(
200-
includedPaths: [p.join(_webPackagePath, 'lib/src/dom.dart')]);
201+
includedPaths: [p.join(_webPackagePath, 'lib', 'src', 'dom.dart')]);
201202
final dartJsInterop = (await contextCollection.contexts.single.currentSession
202203
.getLibraryByUri('dart:js_interop') as LibraryElementResult)
203204
.element;
@@ -240,7 +241,7 @@ Future<void> _generateJsTypeSupertypes() async {
240241
// for details. All rights reserved. Use of this source code is governed by a
241242
// BSD-style license that can be found in the LICENSE file.
242243
243-
// Updated by $_thisScript. Do not modify by hand.
244+
// Updated by $_scriptPOSIXPath. Do not modify by hand.
244245
245246
const Map<String, String?> jsTypeSupertypes = {
246247
${jsTypeSupertypes.entries.map((e) => " ${e.key}: ${e.value},").join('\n')}

0 commit comments

Comments
 (0)