From e9bbb1137f6d6685975b87a0490d5f838f35dbbc Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Mon, 9 Jan 2023 14:44:23 -0800 Subject: [PATCH] Fix path for require.js (#118120) - Matches new location in the Dart SDK. https://dart-review.googlesource.com/c/sdk/+/275482 - Includes fall back logic so the existing and new locations will work depending on the file that is available. --- .../lib/src/isolated/devfs_web.dart | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index eae1eaef94..6ba31f4b79 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -926,14 +926,31 @@ class WebDevFS implements DevFS { } @visibleForTesting - final File requireJS = globals.fs.file(globals.fs.path.join( - globals.artifacts!.getArtifactPath(Artifact.engineDartSdkPath, platform: TargetPlatform.web_javascript), - 'lib', - 'dev_compiler', - 'kernel', - 'amd', - 'require.js', - )); + final File requireJS = (() { + // TODO(nshahan): Remove the initilizing function once the file location + // change in the Dart SDK has landed and rolled to the engine + // and flutter repos. There is no long-term need for the + // fallback logic. + // See https://github.com/flutter/flutter/issues/118119 + final File oldFile = globals.fs.file(globals.fs.path.join( + globals.artifacts!.getArtifactPath(Artifact.engineDartSdkPath, platform: TargetPlatform.web_javascript), + 'lib', + 'dev_compiler', + 'kernel', + 'amd', + 'require.js', + )); + + return oldFile.existsSync() + ? oldFile + : globals.fs.file(globals.fs.path.join( + globals.artifacts!.getArtifactPath(Artifact.engineDartSdkPath, platform: TargetPlatform.web_javascript), + 'lib', + 'dev_compiler', + 'amd', + 'require.js', + )); + })(); @visibleForTesting final File stackTraceMapper = globals.fs.file(globals.fs.path.join(