@@ -8,8 +8,6 @@ import * as path from 'path';
88import yargs from 'yargs' ;
99import unparse from 'yargs-unparser' ;
1010
11- import { isInChromiumDirectory , nodeModulesPath , rootPath } from './devtools_paths.js' ;
12-
1311const argv = yargs ( process . argv . slice ( 2 ) )
1412 . parserConfiguration ( {
1513 'strip-aliased' : true ,
@@ -26,22 +24,32 @@ let script = argv.script;
2624delete argv . target ;
2725delete argv . script ;
2826
29- const sourceRoot = rootPath ( ) ;
27+ let sourceRoot = path . dirname ( path . dirname ( path . resolve ( argv [ '$0' ] ) ) ) ;
3028
3129// Ensure that we can find the node_modules folder even if the out folder is
3230// not a sibling of the node_modules folder.
3331const env = process . env ;
34- env . NODE_PATH = nodeModulesPath ( ) ;
32+ env . NODE_PATH = path . join ( sourceRoot , 'node_modules' ) ;
3533
36- const cwd = path . join ( sourceRoot , 'out' , target ) ;
34+ let cwd = path . join ( sourceRoot , 'out' , target ) ;
3735
38- if ( isInChromiumDirectory ( ) . isInChromium ) {
39- // Check if we need to change the location of the gen folder.
40- const pathParts = script . split ( path . sep ) ;
41- if ( pathParts [ 0 ] === 'gen' ) {
42- pathParts . shift ( ) ;
43- pathParts . unshift ( 'gen' , 'third_party' , 'devtools-frontend' , 'src' ) ;
44- script = pathParts . join ( path . sep ) ;
36+ if ( ! fs . existsSync ( cwd ) ) {
37+ // Check if we are in a Chromium checkout and look for the out folder there.
38+ const maybeChromiumRoot = path . dirname (
39+ path . dirname ( path . dirname ( sourceRoot ) ) ,
40+ ) ;
41+ if (
42+ sourceRoot ===
43+ path . join ( maybeChromiumRoot , 'third_party' , 'devtools-frontend' , 'src' )
44+ ) {
45+ sourceRoot = maybeChromiumRoot ;
46+ cwd = path . join ( sourceRoot , 'out' , target ) ;
47+ const pathParts = script . split ( path . sep ) ;
48+ if ( pathParts [ 0 ] === 'gen' ) {
49+ pathParts . shift ( ) ;
50+ pathParts . unshift ( 'gen' , 'third_party' , 'devtools-frontend' , 'src' ) ;
51+ script = pathParts . join ( path . sep ) ;
52+ }
4553 }
4654}
4755
0 commit comments