mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-03 02:21:05 +08:00
Since workers do not support modules [1], it is not possible to currently import any ESM DevTools module. To be able to migrate text_utils/ to ESM, we would need to duplicate a large portion of text_utils/, which would be unmaintainable. We already had the same situation when we migrated platform/ to ESM and decided to copy the relevant functions, but this time around that is no longer an option. Thus, the 2 workers (heap_snapshot_worker and formatter_worker) are now being bundled on build time. This means that in a release build, the respective entrypoints are bundled and inserted in the output. To bundle, we use `rollup`, which is a bundler only concerned with rolling up ES modules. All other functionality of rollup (such as tree-shaking) is unused. We can revisit later if we need a bundler for the rest of devtools, but since we are in active migration to ESM that is infeasible at this point in time. As part of this CL, the following folders are migrated to ESM: - cm_headless/ - formatter_worker/ - heap_snapshot_model/ - heap_snapshot_worker/ - text_utils/ Since text_utils is also an autostart module for the shell, this is the only module that is imported from root.js. Some of these modules also include files that are annotated with skip_compilation and thus run with dummy files during Closure compilation. Note that, because of the usages of import-statements in the workers and the blocking bug [1], the workers are generated even when Chromium is built with `debug_devtools=true`. Since heap_snapshot_model/ also used in the profiler, we have to eagerly load this module in root.js. Once all other dependencies of the profiler have been migrated to ESM, we can remove this import-statement. [1]: crbug.com/680046 Bug:1013129,1006759 Change-Id: I4c03c7b8a1f351ae9693cbcd922412083dd34bba Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1883707 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Paul Lewis <aerotwist@chromium.org>
76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
# Copyright 2019 The Chromium Authors. All rights reserved.
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
"""
|
|
Helper to find the path to the correct third_party directory
|
|
"""
|
|
|
|
from os import path
|
|
import sys
|
|
|
|
|
|
# Find the root path of the checkout.
|
|
# In the Chromium repository, this is the src/chromium directory.
|
|
# In the external repository, standalone build, this is the devtools-frontend directory.
|
|
# In the external repository, integrated build, this is the src/chromium directory.
|
|
def root_path():
|
|
SCRIPTS_PATH = path.dirname(path.abspath(__file__))
|
|
ABS_DEVTOOLS_PATH = path.dirname(SCRIPTS_PATH)
|
|
PARENT_PATH = path.dirname(ABS_DEVTOOLS_PATH)
|
|
# TODO(1011259): remove Chromium repository handling
|
|
if path.basename(PARENT_PATH) == 'renderer':
|
|
# Chromium repository
|
|
return path.dirname(path.dirname(path.dirname(PARENT_PATH)))
|
|
elif path.basename(PARENT_PATH) == 'devtools-frontend':
|
|
# External repository, integrated build
|
|
return path.dirname(path.dirname(PARENT_PATH))
|
|
else:
|
|
# External repository, standalone build
|
|
return ABS_DEVTOOLS_PATH
|
|
|
|
|
|
# This is the third_party path relative to the root of the checkout.
|
|
def third_party_path():
|
|
return path.join(root_path(), 'third_party')
|
|
|
|
|
|
# This points to the node binary downloaded as part of the checkout.
|
|
def node_path():
|
|
try:
|
|
old_sys_path = sys.path[:]
|
|
sys.path.append(path.join(third_party_path(), 'node'))
|
|
import node
|
|
finally:
|
|
sys.path = old_sys_path
|
|
return node.GetBinaryPath()
|
|
|
|
|
|
def devtools_root_path():
|
|
return path.dirname((path.dirname(path.abspath(__file__))))
|
|
|
|
|
|
def node_modules_path():
|
|
return path.join(devtools_root_path(), 'node_modules')
|
|
|
|
|
|
def eslint_path():
|
|
return path.join(node_modules_path(), 'eslint', 'bin', 'eslint.js')
|
|
|
|
|
|
def karma_path():
|
|
return path.join(node_modules_path(), 'karma', 'bin', 'karma')
|
|
|
|
|
|
def rollup_path():
|
|
return path.join(
|
|
node_modules_path(),
|
|
'rollup',
|
|
'dist',
|
|
'bin',
|
|
'rollup',
|
|
)
|
|
|
|
|
|
def package_json_path():
|
|
return path.join(devtools_root_path(), 'package.json')
|