| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 'use strict'; | 4 'use strict'; |
| 5 const fs = require('fs'); | 5 const fs = require('fs'); |
| 6 const path = require('path'); | 6 const path = require('path'); |
| 7 | 7 |
| 8 const utils = require('../utils'); | 8 const utils = require('../utils'); |
| 9 | 9 |
| 10 const FRONTEND_PATH = path.resolve(__dirname, '..', '..', 'front_end'); | 10 const FRONTEND_PATH = path.resolve(__dirname, '..', '..', 'front_end'); |
| 11 const BUILD_GN_PATH = path.resolve(__dirname, '..', '..', 'BUILD.gn'); | 11 const BUILD_GN_PATH = path.resolve(__dirname, '..', '..', 'BUILD.gn'); |
| 12 const SPECIAL_CASE_NAMESPACES_PATH = path.resolve(__dirname, '..', 'special_case
_namespaces.json'); | 12 const SPECIAL_CASE_NAMESPACES_PATH = path.resolve(__dirname, '..', 'special_case
_namespaces.json'); |
| 13 | 13 |
| 14 const APPLICATION_DESCRIPTORS = [ | 14 const APPLICATION_DESCRIPTORS = [ |
| 15 'inspector.json', | 15 'inspector.json', |
| 16 'toolbox.json', |
| 16 'unit_test_runner.json', | 17 'unit_test_runner.json', |
| 18 'formatter_worker.json', |
| 19 'heap_snapshot_worker.json', |
| 20 'utility_shared_worker.json', |
| 17 ]; | 21 ]; |
| 18 | 22 |
| 19 // Replace based on specified transformation | 23 // Replace based on specified transformation |
| 20 const MODULES_TO_REMOVE = ['components_lazy', 'ui_lazy']; | 24 const MODULES_TO_REMOVE = []; |
| 21 | 25 |
| 22 const JS_FILES_MAPPING = [ | 26 const JS_FILES_MAPPING = [ |
| 23 {file: 'components_lazy/CookiesTable.js', new: 'cookie_table'}, | 27 {file: 'common/CSSShadowModel.js', existing: 'inline_editor'}, |
| 24 {file: 'ui/BezierEditor.js', new: 'inline_editor'}, | 28 {file: 'common/Geometry.js', existing: 'ui'}, |
| 25 {file: 'ui/BezierUI.js', new: 'inline_editor'}, | 29 // {file: 'module/file.js', existing: 'module'} |
| 26 {file: 'ui/ColorSwatch.js', new: 'inline_editor'}, | |
| 27 {file: 'ui/CSSShadowEditor.js', new: 'inline_editor'}, | |
| 28 {file: 'ui/SwatchPopoverHelper.js', new: 'inline_editor'}, | |
| 29 {file: 'components/Spectrum.js', new: 'color_picker'}, | |
| 30 | |
| 31 // Cannot extract dom_ui because of cyclic dependency with components | |
| 32 // {file: 'components/DOMPresentationUtils.js', new: 'dom_ui'}, | |
| 33 {file: 'components/ExecutionContextSelector.js', existing: 'main'}, | |
| 34 {file: 'components_lazy/FilmStripModel.js', existing: 'sdk'}, | |
| 35 {file: 'components_lazy/FilmStripView.js', existing: 'perf_ui'}, | |
| 36 {file: 'components/ShortcutsScreen.js', existing: 'ui'}, | |
| 37 {file: 'ui_lazy/DataGrid.js', new: 'data_grid'}, | |
| 38 {file: 'ui_lazy/ViewportDataGrid.js', new: 'data_grid'}, | |
| 39 {file: 'ui_lazy/SortableDataGrid.js', new: 'data_grid'}, | |
| 40 {file: 'ui_lazy/ShowMoreDataGridNode.js', new: 'data_grid'}, | |
| 41 {file: 'ui_lazy/ChartViewport.js', existing: 'perf_ui'}, | |
| 42 {file: 'ui_lazy/FlameChart.js', existing: 'perf_ui'}, | |
| 43 {file: 'ui_lazy/OverviewGrid.js', existing: 'perf_ui'}, | |
| 44 {file: 'ui_lazy/PieChart.js', existing: 'perf_ui'}, | |
| 45 {file: 'ui_lazy/TimelineGrid.js', existing: 'perf_ui'}, | |
| 46 {file: 'ui_lazy/TimelineOverviewPane.js', existing: 'perf_ui'}, | |
| 47 ]; | 30 ]; |
| 48 | 31 |
| 49 const MODULE_MAPPING = { | 32 const MODULE_MAPPING = { |
| 50 cookie_table: { | 33 // heap_snapshot_model: { |
| 51 dependencies: ['ui', 'sdk', 'data_grid'], | 34 // dependencies: [], |
| 52 dependents: ['resources', 'network'], | 35 // dependents: ['heap_snapshot_worker', 'profiler'], |
| 53 applications: ['inspector.json'], | 36 // applications: ['inspector.json'], // need to manually add to heap snapsho
t worker b/c it's autostart |
| 54 autostart: false, | 37 // autostart: false, |
| 55 }, | 38 // }, |
| 56 inline_editor: { | |
| 57 dependencies: ['ui'], | |
| 58 dependents: ['sources', 'elements', 'resources'], | |
| 59 applications: ['inspector.json', 'unit_test_runner.json'], | |
| 60 autostart: false, | |
| 61 }, | |
| 62 color_picker: { | |
| 63 dependencies: ['ui', 'sdk'], | |
| 64 dependents: ['sources', 'elements'], | |
| 65 applications: ['inspector.json'], | |
| 66 autostart: false, | |
| 67 }, | |
| 68 data_grid: { | |
| 69 dependencies: ['ui'], | |
| 70 dependents: ['network', 'profiler', 'resources', 'console', 'timeline'], | |
| 71 applications: ['inspector.json', 'unit_test_runner.json'], | |
| 72 autostart: false, | |
| 73 }, | |
| 74 }; | 39 }; |
| 75 | 40 |
| 76 const NEW_DEPENDENCIES_BY_EXISTING_MODULES = { | 41 const NEW_DEPENDENCIES_BY_EXISTING_MODULES = { |
| 77 resources: ['components'], | 42 // resources: ['components'], |
| 78 }; | 43 }; |
| 79 | 44 |
| 80 const REMOVE_DEPENDENCIES_BY_EXISTING_MODULES = { | 45 const REMOVE_DEPENDENCIES_BY_EXISTING_MODULES = { |
| 81 }; | 46 }; |
| 82 | 47 |
| 83 const DEPENDENCIES_BY_MODULE = Object.keys(MODULE_MAPPING).reduce((acc, module)
=> { | 48 const DEPENDENCIES_BY_MODULE = Object.keys(MODULE_MAPPING).reduce((acc, module)
=> { |
| 84 acc[module] = MODULE_MAPPING[module].dependencies; | 49 acc[module] = MODULE_MAPPING[module].dependencies; |
| 85 return acc; | 50 return acc; |
| 86 }, {}); | 51 }, {}); |
| 87 | 52 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 105 const targetToOriginalFilesMap = JS_FILES_MAPPING.reduce((acc, f) => { | 70 const targetToOriginalFilesMap = JS_FILES_MAPPING.reduce((acc, f) => { |
| 106 let components = f.file.split('/'); | 71 let components = f.file.split('/'); |
| 107 components[0] = f.new || f.existing; | 72 components[0] = f.new || f.existing; |
| 108 acc.set(components.join('/'), f.file); | 73 acc.set(components.join('/'), f.file); |
| 109 return acc; | 74 return acc; |
| 110 }, new Map()); | 75 }, new Map()); |
| 111 | 76 |
| 112 const cssFilesMapping = findCSSFiles(); | 77 const cssFilesMapping = findCSSFiles(); |
| 113 const identifiersByFile = calculateIdentifiers(); | 78 const identifiersByFile = calculateIdentifiers(); |
| 114 const identifierMap = mapIdentifiers(identifiersByFile, cssFilesMapping); | 79 const identifierMap = mapIdentifiers(identifiersByFile, cssFilesMapping); |
| 80 console.log('identifierMap', identifierMap); |
| 115 const extensionMap = removeFromExistingModuleDescriptors(modules, identifierMa
p, cssFilesMapping); | 81 const extensionMap = removeFromExistingModuleDescriptors(modules, identifierMa
p, cssFilesMapping); |
| 116 | 82 |
| 117 // Find out which files are moving extensions | 83 // Find out which files are moving extensions |
| 118 for (let e of extensionMap.keys()) { | 84 for (let e of extensionMap.keys()) { |
| 119 for (let [f, identifiers] of identifiersByFile) { | 85 for (let [f, identifiers] of identifiersByFile) { |
| 120 if (identifiers.includes(e)) | 86 if (identifiers.includes(e)) |
| 121 console.log(`extension: ${e} in file: ${f}`); | 87 console.log(`extension: ${e} in file: ${f}`); |
| 122 } | 88 } |
| 123 } | 89 } |
| 124 | 90 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 function scrapeIdentifiers(content, fileObj) { | 160 function scrapeIdentifiers(content, fileObj) { |
| 195 let identifiers = []; | 161 let identifiers = []; |
| 196 let lines = content.split('\n'); | 162 let lines = content.split('\n'); |
| 197 for (let line of lines) { | 163 for (let line of lines) { |
| 198 let match = line.match(new RegExp(`^([a-z_A-Z0-9\.]+)\\s=`)) || line.match
(new RegExp(`^([a-z_A-Z0-9\.]+);`)); | 164 let match = line.match(new RegExp(`^([a-z_A-Z0-9\.]+)\\s=`)) || line.match
(new RegExp(`^([a-z_A-Z0-9\.]+);`)); |
| 199 if (!match) | 165 if (!match) |
| 200 continue; | 166 continue; |
| 201 let name = match[1]; | 167 let name = match[1]; |
| 202 | 168 |
| 203 var currentModule = fileObj.file.split('/')[0]; | 169 var currentModule = fileObj.file.split('/')[0]; |
| 204 if (name.split('.')[0] !== mapModuleToNamespace(currentModule)) | 170 if (name.split('.')[0] !== mapModuleToNamespace(currentModule)) { |
| 205 console.log(`POSSIBLE ISSUE: identifier: ${name} found in ${currentModul
e}`); | 171 console.log(`POSSIBLE ISSUE: identifier: ${name} found in ${currentModul
e}`); |
| 206 else | 172 // one-off |
| 173 if (name.includes('UI.')) { |
| 174 console.log(`including ${name} anyways`); |
| 175 identifiers.push(name) |
| 176 } |
| 177 } else { |
| 207 identifiers.push(name); | 178 identifiers.push(name); |
| 179 } |
| 208 } | 180 } |
| 209 return identifiers; | 181 return identifiers; |
| 210 } | 182 } |
| 211 } | 183 } |
| 212 | 184 |
| 213 function moveFiles(cssFilesMapping) { | 185 function moveFiles(cssFilesMapping) { |
| 214 for (let fileObj of JS_FILES_MAPPING) { | 186 for (let fileObj of JS_FILES_MAPPING) { |
| 215 let sourceFilePath = path.resolve(FRONTEND_PATH, fileObj.file); | 187 let sourceFilePath = path.resolve(FRONTEND_PATH, fileObj.file); |
| 216 let targetFilePath = getMappedFilePath(fileObj); | 188 let targetFilePath = getMappedFilePath(fileObj); |
| 217 let moduleDir = path.resolve(targetFilePath, '..'); | 189 let moduleDir = path.resolve(targetFilePath, '..'); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 linesToInsert: newNonAutostartModules, | 234 linesToInsert: newNonAutostartModules, |
| 263 }); | 235 }); |
| 264 | 236 |
| 265 for (let pair of partialPathMapping.entries()) | 237 for (let pair of partialPathMapping.entries()) |
| 266 newContent = newContent.replace(pair[0], pair[1]); | 238 newContent = newContent.replace(pair[0], pair[1]); |
| 267 | 239 |
| 268 newContent = addContentToLinesInSortedOrder({ | 240 newContent = addContentToLinesInSortedOrder({ |
| 269 content: newContent, | 241 content: newContent, |
| 270 startLine: 'all_devtools_files = [', | 242 startLine: 'all_devtools_files = [', |
| 271 endLine: ']', | 243 endLine: ']', |
| 272 linesToInsert: newSourcesToAdd, | 244 linesToInsert: newSourcesToAdd.concat([...newModuleSet].map(module => `"fron
t_end/${module}/module.json",`)), |
| 273 }); | 245 }); |
| 274 | 246 |
| 275 fs.writeFileSync(BUILD_GN_PATH, newContent); | 247 fs.writeFileSync(BUILD_GN_PATH, newContent); |
| 276 | 248 |
| 277 function calculatePartialPathMapping() { | 249 function calculatePartialPathMapping() { |
| 278 let partialPathMapping = new Map(); | 250 let partialPathMapping = new Map(); |
| 279 for (let fileObj of JS_FILES_MAPPING) { | 251 for (let fileObj of JS_FILES_MAPPING) { |
| 280 let components = fileObj.file.split('/'); | 252 let components = fileObj.file.split('/'); |
| 281 let sourceModule = components[0]; | 253 let sourceModule = components[0]; |
| 282 let targetModule = fileObj.existing || fileObj.new; | 254 let targetModule = fileObj.existing || fileObj.new; |
| 283 components[0] = targetModule; | 255 components[0] = targetModule; |
| 284 partialPathMapping.set(`"front_end/${fileObj.file}",\n`, ''); | 256 partialPathMapping.set(`"front_end/${fileObj.file}",\n`, ''); |
| 285 newSourcesToAdd.push(`"front_end/${components.join('/')}",`); | 257 newSourcesToAdd.push(`"front_end/${components.join('/')}",`); |
| 286 if (cssFilesMapping.has(fileObj.file)) { | 258 if (cssFilesMapping.has(fileObj.file)) { |
| 287 for (let cssFile of cssFilesMapping.get(fileObj.file)) { | 259 for (let cssFile of cssFilesMapping.get(fileObj.file)) { |
| 288 partialPathMapping.set(`"front_end/${sourceModule}/${cssFile}",\n`, ''
); | 260 partialPathMapping.set(`"front_end/${sourceModule}/${cssFile}",\n`, ''
); |
| 289 newSourcesToAdd.push(`"front_end/${targetModule}/${cssFile}",`); | 261 newSourcesToAdd.push(`"front_end/${targetModule}/${cssFile}",`); |
| 290 } | 262 } |
| 291 } | 263 } |
| 292 } | 264 } |
| 293 return partialPathMapping; | 265 return partialPathMapping; |
| 294 } | 266 } |
| 295 | 267 |
| 296 function top(array) { | 268 function top(array) { |
| 297 return array[array.length - 1]; | 269 return array[array.length - 1]; |
| 298 } | 270 } |
| 299 | 271 |
| 300 function addContentToLinesInSortedOrder({content, startLine, endLine, linesToI
nsert}) { | 272 function addContentToLinesInSortedOrder({content, startLine, endLine, linesToI
nsert}) { |
| 273 if (linesToInsert.length === 0) |
| 274 return content; |
| 301 let lines = content.split('\n'); | 275 let lines = content.split('\n'); |
| 302 let seenStartLine = false; | 276 let seenStartLine = false; |
| 303 let contentStack = linesToInsert.sort((a, b) => a.toLowerCase().localeCompar
e(b.toLowerCase())).reverse(); | 277 let contentStack = linesToInsert.sort((a, b) => a.toLowerCase().localeCompar
e(b.toLowerCase())).reverse(); |
| 304 for (var i = 0; i < lines.length; i++) { | 278 for (var i = 0; i < lines.length; i++) { |
| 305 let line = lines[i].trim(); | 279 let line = lines[i].trim(); |
| 306 let nextLine = lines[i + 1].trim(); | 280 let nextLine = lines[i + 1].trim(); |
| 307 if (line === startLine) | 281 if (line === startLine) |
| 308 seenStartLine = true; | 282 seenStartLine = true; |
| 309 | 283 |
| 310 if (line === endLine && seenStartLine) | 284 if (line === endLine && seenStartLine) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 362 } |
| 389 | 363 |
| 390 function write(filePath) { | 364 function write(filePath) { |
| 391 let content = fs.readFileSync(filePath).toString(); | 365 let content = fs.readFileSync(filePath).toString(); |
| 392 let newContent = content; | 366 let newContent = content; |
| 393 for (let key of identifierMap.keys()) { | 367 for (let key of identifierMap.keys()) { |
| 394 let originalIdentifier = key; | 368 let originalIdentifier = key; |
| 395 let newIdentifier = identifierMap.get(key); | 369 let newIdentifier = identifierMap.get(key); |
| 396 newContent = newContent.replaceAll(originalIdentifier, newIdentifier); | 370 newContent = newContent.replaceAll(originalIdentifier, newIdentifier); |
| 397 } | 371 } |
| 398 // one-off | |
| 399 if (filePath.includes('LayoutTests/http/tests/inspector-unit/filtered-item-s
election-dialog-filtering.js')) | |
| 400 newContent = newContent.replaceAll('ui_lazy', 'quick_open'); | |
| 401 if (filePath.includes('LayoutTests/inspector/components/cookies-table.html')
) | |
| 402 newContent = newContent.replaceAll('components_lazy', 'cookie_table'); | |
| 403 if (filePath.includes('LayoutTests/inspector/components/datagrid-autosize.ht
ml')) | |
| 404 newContent = newContent.replaceAll('ui_lazy', 'data_grid'); | |
| 405 if (filePath.includes('LayoutTests/inspector/components/datagrid-test.js')) | |
| 406 newContent = newContent.replaceAll('ui_lazy', 'data_grid'); | |
| 407 | 372 |
| 408 if (content !== newContent) | 373 if (content !== newContent) |
| 409 fs.writeFileSync(filePath, newContent); | 374 fs.writeFileSync(filePath, newContent); |
| 410 } | 375 } |
| 411 } | 376 } |
| 412 | 377 |
| 413 function removeFromExistingModuleDescriptors(modules, identifierMap, cssFilesMap
ping) { | 378 function removeFromExistingModuleDescriptors(modules, identifierMap, cssFilesMap
ping) { |
| 414 let extensionMap = new Map(); | 379 let extensionMap = new Map(); |
| 415 let moduleFileMap = new Map(); | 380 let moduleFileMap = new Map(); |
| 416 | 381 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 if (dependents.includes(existingModule)) | 613 if (dependents.includes(existingModule)) |
| 649 newDeps.push(newModule); | 614 newDeps.push(newModule); |
| 650 } | 615 } |
| 651 return newDeps; | 616 return newDeps; |
| 652 } | 617 } |
| 653 } | 618 } |
| 654 | 619 |
| 655 function updateApplicationDescriptor(descriptorFileName, newModuleSet) { | 620 function updateApplicationDescriptor(descriptorFileName, newModuleSet) { |
| 656 let descriptorPath = path.join(FRONTEND_PATH, descriptorFileName); | 621 let descriptorPath = path.join(FRONTEND_PATH, descriptorFileName); |
| 657 let newModules = [...newModuleSet].filter(m => APPLICATIONS_BY_MODULE[m].inclu
des(descriptorFileName)); | 622 let newModules = [...newModuleSet].filter(m => APPLICATIONS_BY_MODULE[m].inclu
des(descriptorFileName)); |
| 623 if (newModules.length === 0) |
| 624 return; |
| 658 let includeNewModules = (acc, line) => { | 625 let includeNewModules = (acc, line) => { |
| 659 if (line.includes('{') && line.endsWith('}')) { | 626 if (line.includes('{') && line.endsWith('}')) { |
| 660 line += ','; | 627 line += ','; |
| 661 acc.push(line); | 628 acc.push(line); |
| 662 return acc.concat(newModules.map((m, i) => { | 629 return acc.concat(newModules.map((m, i) => { |
| 663 // Need spacing to preserve indentation | 630 // Need spacing to preserve indentation |
| 664 let string; | 631 let string; |
| 665 if (MODULE_MAPPING[m].autostart) | 632 if (MODULE_MAPPING[m].autostart) |
| 666 string = ` { "name": "${m}", "type": "autostart"}`; | 633 string = ` { "name": "${m}", "type": "autostart"}`; |
| 667 else | 634 else |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 return string.split("") | 674 return string.split("") |
| 708 .map(function (char) { | 675 .map(function (char) { |
| 709 var charCode = char.charCodeAt(0); | 676 var charCode = char.charCodeAt(0); |
| 710 return charCode > 127 ? unicodeCharEscape(charCode) : char; | 677 return charCode > 127 ? unicodeCharEscape(charCode) : char; |
| 711 }) | 678 }) |
| 712 .join(""); | 679 .join(""); |
| 713 } | 680 } |
| 714 | 681 |
| 715 if (require.main === module) | 682 if (require.main === module) |
| 716 extractModule(); | 683 extractModule(); |
| OLD | NEW |