-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[ Tool ] Stop generating widget preview scaffold under $TMP #186476
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
408819b
[flutter_tools] Stop generating widget preview scaffold under $TMP
bkonyi 939a5cd
[flutter_tools] Simplify .widget_preview ignore pattern in template
bkonyi 559b863
[flutter_tools] Address review feedback for widget preview
bkonyi 5d915f5
[flutter_tools] Add kProjectRootPath to dtd_connection_info template
bkonyi 3149959
[flutter_tools] Generate kProjectRootPath as a raw string
bkonyi 953a746
Increase delay for waiting for analysis to fix tests
bkonyi 5bcca67
Merge branch 'master' of https://github.com/flutter/flutter into widg…
bkonyi 43dc108
Attempt to fix Windows failures
bkonyi 784c5f5
Fix tests?
bkonyi 8782d46
Cleanly terminate leaked Analysis Server processes on Windows in tear…
bkonyi f69a208
Refactor: surgically kill child processes recursively on Windows in s…
bkonyi 0bdd68d
Cleanup: remove stdin write 'q' and timeout from startWidgetPreview a…
bkonyi 82481bc
Doc: Add documentation for killChildProcesses explaining Windows pare…
bkonyi ba25e9a
Fix: Use taskkill /F /T to recursively and surgically kill process tr…
bkonyi f0bf425
Fix: Add getPreviews helper with Windows-specific delay to avoid anal…
bkonyi 203cfc0
[Tool] Address review feedback for widget preview
bkonyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/flutter_tools/lib/src/migrations/widget_preview_gitignore_migration.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright 2014 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import '../base/file_system.dart'; | ||
| import '../base/project_migrator.dart'; | ||
| import '../project.dart'; | ||
|
|
||
| /// Adds `.widget_preview/` to the .gitignore file. | ||
| class WidgetPreviewGitignoreMigration extends ProjectMigrator { | ||
| WidgetPreviewGitignoreMigration(FlutterProject project, super.logger) | ||
| : _gitignoreFile = project.gitignoreFile; | ||
|
|
||
| final File _gitignoreFile; | ||
|
|
||
| @override | ||
| Future<void> migrate() async { | ||
| if (!_gitignoreFile.existsSync()) { | ||
| logger.printTrace('.gitignore file not found, skipping widget preview .gitignore migration.'); | ||
| return; | ||
| } | ||
|
|
||
| final String originalContent = _gitignoreFile.readAsStringSync(); | ||
|
|
||
| // Skip if .gitignore is already migrated. | ||
| if (originalContent.contains('.widget_preview/')) { | ||
| return; | ||
| } | ||
|
|
||
| logger.printTrace('.gitignore does not ignore .widget_preview/ directory, updating.'); | ||
|
|
||
| final newContent = StringBuffer(originalContent); | ||
| if (!originalContent.endsWith('\n')) { | ||
| newContent.writeln(); | ||
| } | ||
| newContent | ||
| ..writeln('# Widget Preview related') | ||
| ..writeln('.widget_preview/'); | ||
|
|
||
| _gitignoreFile.writeAsStringSync(newContent.toString()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
.../flutter_tools/test/general.shard/migrations/widget_preview_gitignore_migration_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // Copyright 2014 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:file/file.dart'; | ||
| import 'package:file/memory.dart'; | ||
| import 'package:flutter_tools/src/base/logger.dart'; | ||
| import 'package:flutter_tools/src/base/terminal.dart'; | ||
| import 'package:flutter_tools/src/migrations/widget_preview_gitignore_migration.dart'; | ||
| import 'package:flutter_tools/src/project.dart'; | ||
| import 'package:test/fake.dart'; | ||
|
|
||
| import '../../src/common.dart'; | ||
|
|
||
| void main() { | ||
| group('Widget Preview .gitignore migration', () { | ||
| late MemoryFileSystem memoryFileSystem; | ||
| late BufferLogger testLogger; | ||
| late FakeFlutterProject mockProject; | ||
| late File gitignoreFile; | ||
|
|
||
| setUp(() { | ||
| memoryFileSystem = MemoryFileSystem.test(); | ||
| gitignoreFile = memoryFileSystem.file('.gitignore'); | ||
|
|
||
| testLogger = BufferLogger( | ||
| terminal: Terminal.test(), | ||
| outputPreferences: OutputPreferences.test(), | ||
| ); | ||
|
|
||
| mockProject = FakeFlutterProject(fileSystem: memoryFileSystem); | ||
| }); | ||
|
|
||
| testWithoutContext('skipped if .gitignore file is missing', () async { | ||
| final migration = WidgetPreviewGitignoreMigration(mockProject, testLogger); | ||
| await migration.migrate(); | ||
| expect(gitignoreFile.existsSync(), isFalse); | ||
|
|
||
| expect( | ||
| testLogger.traceText, | ||
| contains('.gitignore file not found, skipping widget preview .gitignore migration.'), | ||
| ); | ||
| expect(testLogger.warningText, isEmpty); | ||
| }); | ||
|
|
||
| testWithoutContext('skipped if already migrated', () async { | ||
| const gitignoreFileContents = ''' | ||
| .DS_Store | ||
| .widget_preview/ | ||
| '''; | ||
|
|
||
| gitignoreFile.writeAsStringSync(gitignoreFileContents); | ||
|
|
||
| final DateTime updatedAt = gitignoreFile.lastModifiedSync(); | ||
|
|
||
| final migration = WidgetPreviewGitignoreMigration(mockProject, testLogger); | ||
| await migration.migrate(); | ||
|
|
||
| expect(gitignoreFile.lastModifiedSync(), updatedAt); | ||
| expect(gitignoreFile.readAsStringSync(), gitignoreFileContents); | ||
| expect(testLogger.warningText, isEmpty); | ||
| }); | ||
|
|
||
| testWithoutContext('migrates project to ignore .widget_preview directory', () async { | ||
| gitignoreFile.writeAsStringSync( | ||
| '.DS_Store\n' | ||
| '.atom/\n', | ||
| ); | ||
|
|
||
| final migration = WidgetPreviewGitignoreMigration(mockProject, testLogger); | ||
| await migration.migrate(); | ||
|
|
||
| expect( | ||
| gitignoreFile.readAsStringSync(), | ||
| '.DS_Store\n' | ||
| '.atom/\n' | ||
| '# Widget Preview related\n' | ||
| '.widget_preview/\n', | ||
| ); | ||
|
|
||
| expect( | ||
| testLogger.traceText, | ||
| contains('.gitignore does not ignore .widget_preview/ directory, updating.'), | ||
| ); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| class FakeFlutterProject extends Fake implements FlutterProject { | ||
| FakeFlutterProject({required MemoryFileSystem fileSystem}) | ||
| : gitignoreFile = fileSystem.file('.gitignore'); | ||
|
|
||
| @override | ||
| File gitignoreFile; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.