Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt paths for different development environments #336

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
srujzs marked this conversation as resolved.
Show resolved Hide resolved

## 1.0.0

Expand Down
2 changes: 1 addition & 1 deletion web/test/dart_fix_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ environment:
sdk: '^$sdkVersion'
dependencies:
web:
path: ${Directory.current.path}
path: ${p.current.replaceAll(r'\', '/')}
srujzs marked this conversation as resolved.
Show resolved Hide resolved
''');
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 repoUri = Platform.script.resolve('../.dart_tool/mdn_content');
srujzs marked this conversation as resolved.
Show resolved Hide resolved
final repoPath = p.context.fromUri(repoUri);
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 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)',
Expand Down
33 changes: 18 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 readmeFileUri = Platform.script.resolve('../README.md');
final readmeFile = File(p.normalize(p.context.fromUri(readmeFileUri)));

final sourceContent = readmeFile.readAsStringSync();

Expand Down Expand Up @@ -148,7 +147,8 @@ Future<String> _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(
Expand All @@ -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 =
'<!-- 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 +186,7 @@ Future<void> _runProc(
executable,
arguments,
mode: ProcessStartMode.inheritStdio,
runInShell: Platform.isWindows,
workingDirectory: workingDirectory,
);
final procExit = await proc.exitCode;
Expand All @@ -197,7 +200,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 +243,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
Loading