From 69ca4b7a72f6aad4e37f544287677f14b9e02aa7 Mon Sep 17 00:00:00 2001 From: Kenneth Hung Date: Tue, 7 Jan 2025 11:34:11 +0800 Subject: [PATCH 1/5] Fix path to adapt cross-platform development --- web/test/dart_fix_test.dart | 2 +- web_generator/bin/scrape_mdn.dart | 11 +++++---- web_generator/bin/update_bindings.dart | 33 ++++++++++++++------------ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/web/test/dart_fix_test.dart b/web/test/dart_fix_test.dart index a5059d07..83d9dd6f 100644 --- a/web/test/dart_fix_test.dart +++ b/web/test/dart_fix_test.dart @@ -31,7 +31,7 @@ environment: sdk: '^$sdkVersion' dependencies: web: - path: ${Directory.current.path} + path: ${p.current.replaceAll(r'\', '/')} '''); final sourceFile = File(p.join('test_fixes', 'renames.dart')); writeFile( diff --git a/web_generator/bin/scrape_mdn.dart b/web_generator/bin/scrape_mdn.dart index fc64321d..9ce4c8f1 100644 --- a/web_generator/bin/scrape_mdn.dart +++ b/web_generator/bin/scrape_mdn.dart @@ -14,8 +14,9 @@ Future main(List 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 repoUri = Platform.script.resolve('../.dart_tool/mdn_content'); + final repoPath = p.context.fromUri(repoUri); + final repoDir = Directory(repoPath); if (!repoDir.existsSync()) { await _run( 'git', @@ -77,9 +78,9 @@ Future main(List 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 fileUri = Platform.script.resolve('../../third_party/mdn/mdn.json'); + final filePath = p.context.fromUri(fileUri); + final file = File(filePath); final json = { '__meta__': { 'source': '[MDN Web Docs]($mdnUrl)', diff --git a/web_generator/bin/update_bindings.dart b/web_generator/bin/update_bindings.dart index cc4cb2ba..deddc3d5 100644 --- a/web_generator/bin/update_bindings.dart +++ b/web_generator/bin/update_bindings.dart @@ -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; @@ -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().where((file) { if (!file.path.endsWith('.dart')) return false; @@ -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, @@ -101,9 +101,8 @@ $_usage'''); } // Update readme. - final readmeFile = File( - p.normalize(Platform.script.resolve('../README.md').path), - ); + final readmeFileUri = Platform.script.resolve('../README.md'); + final readmeFile = File(p.normalize(p.context.fromUri(readmeFileUri))); final sourceContent = readmeFile.readAsStringSync(); @@ -148,7 +147,8 @@ Future _webPackageLanguageVersion(String pkgPath) async { return '$languageVersion.0'; } -final _webPackagePath = Platform.script.resolve('../../web').path; +final _webPackageUri = Platform.script.resolve('../../web'); +final _webPackagePath = p.context.fromUri(_webPackageUri); String _packageLockVersion(String package) { final packageLockData = jsonDecode( @@ -161,18 +161,20 @@ String _packageLockVersion(String package) { return webRefIdl['version'] as String; } -final _bindingsGeneratorPath = Platform.script.resolve('../lib/src').path; +final _bindingsGeneratorUri = Platform.script.resolve('../lib/src'); +final _bindingsGeneratorPath = p.context.fromUri(_bindingsGeneratorUri); 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 = - ''; -const _endComment = - ''; +final _startComment = + ''; +final _endComment = + ''; Future _runProc( String executable, @@ -184,6 +186,7 @@ Future _runProc( executable, arguments, mode: ProcessStartMode.inheritStdio, + runInShell: Platform.isWindows, workingDirectory: workingDirectory, ); final procExit = await proc.exitCode; @@ -197,7 +200,7 @@ Future _runProc( Future _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; @@ -240,7 +243,7 @@ Future _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 jsTypeSupertypes = { ${jsTypeSupertypes.entries.map((e) => " ${e.key}: ${e.value},").join('\n')} From 40a7284134558896c7f96bbb684ecb1972aa3fba Mon Sep 17 00:00:00 2001 From: Kenneth Hung Date: Tue, 7 Jan 2025 11:58:57 +0800 Subject: [PATCH 2/5] add changes to CHANGELOG.md --- web/CHANGELOG.md | 1 + web_generator/CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/web/CHANGELOG.md b/web/CHANGELOG.md index f49316b8..cde3ff68 100644 --- a/web/CHANGELOG.md +++ b/web/CHANGELOG.md @@ -17,6 +17,7 @@ `HTMLIFrameElement.contentWindowCrossOrigin`, `Window.openCrossOrigin`, `Window.openerCrossOrigin`, `Window.topCrossOrigin`, and `Window.parentCrossOrigin`. +- Forced test `pubspec.yaml` web path to be POSIX-like path. ## 1.0.0 diff --git a/web_generator/CHANGELOG.md b/web_generator/CHANGELOG.md index 0e3110a8..a278ca4d 100644 --- a/web_generator/CHANGELOG.md +++ b/web_generator/CHANGELOG.md @@ -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. \ No newline at end of file From add26cfe61e39ddf90c472b5536f9ee7abc7de88 Mon Sep 17 00:00:00 2001 From: Kenneth Hung Date: Thu, 9 Jan 2025 09:14:51 +0800 Subject: [PATCH 3/5] remove test changelog in CHANGELOG --- web/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/web/CHANGELOG.md b/web/CHANGELOG.md index cde3ff68..f49316b8 100644 --- a/web/CHANGELOG.md +++ b/web/CHANGELOG.md @@ -17,7 +17,6 @@ `HTMLIFrameElement.contentWindowCrossOrigin`, `Window.openCrossOrigin`, `Window.openerCrossOrigin`, `Window.topCrossOrigin`, and `Window.parentCrossOrigin`. -- Forced test `pubspec.yaml` web path to be POSIX-like path. ## 1.0.0 From 3660f6917ff9b46e4a856dc3c438d5796523546d Mon Sep 17 00:00:00 2001 From: Kenneth Hung Date: Thu, 9 Jan 2025 11:35:09 +0800 Subject: [PATCH 4/5] remove variable to be wrapped immediately after - remove redundant call `p.context` --- web_generator/bin/scrape_mdn.dart | 8 ++++---- web_generator/bin/update_bindings.dart | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/web_generator/bin/scrape_mdn.dart b/web_generator/bin/scrape_mdn.dart index 9ce4c8f1..de78eddd 100644 --- a/web_generator/bin/scrape_mdn.dart +++ b/web_generator/bin/scrape_mdn.dart @@ -14,8 +14,8 @@ Future main(List args) async { final offline = args.length == 1 && args.first == '--offline'; // clone the repo - final repoUri = Platform.script.resolve('../.dart_tool/mdn_content'); - final repoPath = p.context.fromUri(repoUri); + final repoPath = + p.fromUri(Platform.script.resolve('../.dart_tool/mdn_content')); final repoDir = Directory(repoPath); if (!repoDir.existsSync()) { await _run( @@ -78,8 +78,8 @@ Future main(List args) async { print('${interfaces.length} items read from $gitUrl.'); const encoder = JsonEncoder.withIndent(' '); - final fileUri = Platform.script.resolve('../../third_party/mdn/mdn.json'); - final filePath = p.context.fromUri(fileUri); + final filePath = + p.fromUri(Platform.script.resolve('../../third_party/mdn/mdn.json')); final file = File(filePath); final json = { '__meta__': { diff --git a/web_generator/bin/update_bindings.dart b/web_generator/bin/update_bindings.dart index deddc3d5..f7432328 100644 --- a/web_generator/bin/update_bindings.dart +++ b/web_generator/bin/update_bindings.dart @@ -101,8 +101,8 @@ $_usage'''); } // Update readme. - final readmeFileUri = Platform.script.resolve('../README.md'); - final readmeFile = File(p.normalize(p.context.fromUri(readmeFileUri))); + final readmeFile = + File(p.normalize(p.fromUri(Platform.script.resolve('../README.md')))); final sourceContent = readmeFile.readAsStringSync(); @@ -147,8 +147,7 @@ Future _webPackageLanguageVersion(String pkgPath) async { return '$languageVersion.0'; } -final _webPackageUri = Platform.script.resolve('../../web'); -final _webPackagePath = p.context.fromUri(_webPackageUri); +final _webPackagePath = p.fromUri(Platform.script.resolve('../../web')); String _packageLockVersion(String package) { final packageLockData = jsonDecode( @@ -161,8 +160,7 @@ String _packageLockVersion(String package) { return webRefIdl['version'] as String; } -final _bindingsGeneratorUri = Platform.script.resolve('../lib/src'); -final _bindingsGeneratorPath = p.context.fromUri(_bindingsGeneratorUri); +final _bindingsGeneratorPath = p.fromUri(Platform.script.resolve('../lib/src')); const _webRefCss = '@webref/css'; const _webRefElements = '@webref/elements'; From 6a4cce8380a2aea1cfe53c81b38dd9ef9c733bfb Mon Sep 17 00:00:00 2001 From: KennethHung Date: Sat, 11 Jan 2025 13:38:38 +0800 Subject: [PATCH 5/5] add comment for manually modifying the path --- web/test/dart_fix_test.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/web/test/dart_fix_test.dart b/web/test/dart_fix_test.dart index 83d9dd6f..82bc4973 100644 --- a/web/test/dart_fix_test.dart +++ b/web/test/dart_fix_test.dart @@ -25,6 +25,7 @@ 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: