Skip to content

Commit

Permalink
Adapt paths for different development environments (#336)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
maple135790 authored Jan 14, 2025
1 parent 7f440e4 commit fd3d988
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
3 changes: 2 additions & 1 deletion web/test/dart_fix_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ void main() {

try {
// set up project
// Convert the current path to a POSIX path to avoid 'path_not_posix' lint.
writeFile(tempDir, 'pubspec.yaml', '''
name: test_project
environment:
sdk: '^$sdkVersion'
dependencies:
web:
path: ${Directory.current.path}
path: ${p.current.replaceAll(r'\', '/')}
''');
final sourceFile = File(p.join('test_fixes', 'renames.dart'));
writeFile(
Expand Down
1 change: 1 addition & 0 deletions web_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
description.
- Added `--generate-all` option to generate all bindings, including experimental
and non-standard APIs.
- Adapt paths for different development environments.
11 changes: 6 additions & 5 deletions web_generator/bin/scrape_mdn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Future<void> main(List<String> args) async {
final offline = args.length == 1 && args.first == '--offline';

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

const encoder = JsonEncoder.withIndent(' ');

final file =
File(Platform.script.resolve('../../third_party/mdn/mdn.json').path);
final filePath =
p.fromUri(Platform.script.resolve('../../third_party/mdn/mdn.json'));
final file = File(filePath);
final json = {
'__meta__': {
'source': '[MDN Web Docs]($mdnUrl)',
Expand Down
31 changes: 16 additions & 15 deletions web_generator/bin/update_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $_usage''');
return;
}

assert(p.fromUri(Platform.script).endsWith(_thisScript));
assert(p.fromUri(Platform.script).endsWith(_thisScript.toFilePath()));

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

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

// Update readme.
final readmeFile = File(
p.normalize(Platform.script.resolve('../README.md').path),
);
final readmeFile =
File(p.normalize(p.fromUri(Platform.script.resolve('../README.md'))));

final sourceContent = readmeFile.readAsStringSync();

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

final _webPackagePath = Platform.script.resolve('../../web').path;
final _webPackagePath = p.fromUri(Platform.script.resolve('../../web'));

String _packageLockVersion(String package) {
final packageLockData = jsonDecode(
Expand All @@ -161,18 +160,19 @@ String _packageLockVersion(String package) {
return webRefIdl['version'] as String;
}

final _bindingsGeneratorPath = Platform.script.resolve('../lib/src').path;
final _bindingsGeneratorPath = p.fromUri(Platform.script.resolve('../lib/src'));

const _webRefCss = '@webref/css';
const _webRefElements = '@webref/elements';
const _webRefIdl = '@webref/idl';

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

const _startComment =
'<!-- START updated by $_thisScript. Do not modify by hand -->';
const _endComment =
'<!-- END updated by $_thisScript. Do not modify by hand -->';
final _startComment =
'<!-- START updated by $_scriptPOSIXPath. Do not modify by hand -->';
final _endComment =
'<!-- END updated by $_scriptPOSIXPath. Do not modify by hand -->';

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

0 comments on commit fd3d988

Please sign in to comment.