diff --git a/web/test/dart_fix_test.dart b/web/test/dart_fix_test.dart index a5059d07..82bc4973 100644 --- a/web/test/dart_fix_test.dart +++ b/web/test/dart_fix_test.dart @@ -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( 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 diff --git a/web_generator/bin/scrape_mdn.dart b/web_generator/bin/scrape_mdn.dart index fc64321d..de78eddd 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 repoPath = + p.fromUri(Platform.script.resolve('../.dart_tool/mdn_content')); + 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 filePath = + p.fromUri(Platform.script.resolve('../../third_party/mdn/mdn.json')); + 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..f7432328 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 readmeFile = + File(p.normalize(p.fromUri(Platform.script.resolve('../README.md')))); final sourceContent = readmeFile.readAsStringSync(); @@ -148,7 +147,7 @@ Future _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( @@ -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 = - ''; -const _endComment = - ''; +final _startComment = + ''; +final _endComment = + ''; Future _runProc( String executable, @@ -184,6 +184,7 @@ Future _runProc( executable, arguments, mode: ProcessStartMode.inheritStdio, + runInShell: Platform.isWindows, workingDirectory: workingDirectory, ); final procExit = await proc.exitCode; @@ -197,7 +198,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 +241,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')}