| 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: 'profiler/HeapSnapshotModel.js', new: 'heap_snapshot_model'}, |
| 24 {file: 'ui/BezierEditor.js', new: 'inline_editor'}, | 28 // {file: 'module/file.js', existing: 'module'} |
| 25 {file: 'ui/BezierUI.js', new: 'inline_editor'}, | |
| 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 ]; | 29 ]; |
| 48 | 30 |
| 49 const MODULE_MAPPING = { | 31 const MODULE_MAPPING = { |
| 50 cookie_table: { | 32 heap_snapshot_model: { |
| 51 dependencies: ['ui', 'sdk', 'data_grid'], | 33 dependencies: [], |
| 52 dependents: ['resources', 'network'], | 34 dependents: ['heap_snapshot_worker', 'profiler'], |
| 53 applications: ['inspector.json'], | 35 applications: ['inspector.json'], // need to manually add to heap snapshot w
orker b/c it's autostart |
| 54 autostart: false, | |
| 55 }, | |
| 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, | 36 autostart: false, |
| 73 }, | 37 }, |
| 74 }; | 38 }; |
| 75 | 39 |
| 76 const NEW_DEPENDENCIES_BY_EXISTING_MODULES = { | 40 const NEW_DEPENDENCIES_BY_EXISTING_MODULES = { |
| 77 resources: ['components'], | 41 // resources: ['components'], |
| 78 }; | 42 }; |
| 79 | 43 |
| 80 const REMOVE_DEPENDENCIES_BY_EXISTING_MODULES = { | 44 const REMOVE_DEPENDENCIES_BY_EXISTING_MODULES = { |
| 81 }; | 45 }; |
| 82 | 46 |
| 83 const DEPENDENCIES_BY_MODULE = Object.keys(MODULE_MAPPING).reduce((acc, module)
=> { | 47 const DEPENDENCIES_BY_MODULE = Object.keys(MODULE_MAPPING).reduce((acc, module)
=> { |
| 84 acc[module] = MODULE_MAPPING[module].dependencies; | 48 acc[module] = MODULE_MAPPING[module].dependencies; |
| 85 return acc; | 49 return acc; |
| 86 }, {}); | 50 }, {}); |
| 87 | 51 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 105 const targetToOriginalFilesMap = JS_FILES_MAPPING.reduce((acc, f) => { | 69 const targetToOriginalFilesMap = JS_FILES_MAPPING.reduce((acc, f) => { |
| 106 let components = f.file.split('/'); | 70 let components = f.file.split('/'); |
| 107 components[0] = f.new || f.existing; | 71 components[0] = f.new || f.existing; |
| 108 acc.set(components.join('/'), f.file); | 72 acc.set(components.join('/'), f.file); |
| 109 return acc; | 73 return acc; |
| 110 }, new Map()); | 74 }, new Map()); |
| 111 | 75 |
| 112 const cssFilesMapping = findCSSFiles(); | 76 const cssFilesMapping = findCSSFiles(); |
| 113 const identifiersByFile = calculateIdentifiers(); | 77 const identifiersByFile = calculateIdentifiers(); |
| 114 const identifierMap = mapIdentifiers(identifiersByFile, cssFilesMapping); | 78 const identifierMap = mapIdentifiers(identifiersByFile, cssFilesMapping); |
| 79 console.log('identifierMap', identifierMap); |
| 115 const extensionMap = removeFromExistingModuleDescriptors(modules, identifierMa
p, cssFilesMapping); | 80 const extensionMap = removeFromExistingModuleDescriptors(modules, identifierMa
p, cssFilesMapping); |
| 116 | 81 |
| 117 // Find out which files are moving extensions | 82 // Find out which files are moving extensions |
| 118 for (let e of extensionMap.keys()) { | 83 for (let e of extensionMap.keys()) { |
| 119 for (let [f, identifiers] of identifiersByFile) { | 84 for (let [f, identifiers] of identifiersByFile) { |
| 120 if (identifiers.includes(e)) | 85 if (identifiers.includes(e)) |
| 121 console.log(`extension: ${e} in file: ${f}`); | 86 console.log(`extension: ${e} in file: ${f}`); |
| 122 } | 87 } |
| 123 } | 88 } |
| 124 | 89 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 filesToTargetModule.set(fileObj.file, fileObj.existing || fileObj.new); | 295 filesToTargetModule.set(fileObj.file, fileObj.existing || fileObj.new); |
| 331 | 296 |
| 332 | 297 |
| 333 const map = new Map(); | 298 const map = new Map(); |
| 334 for (let [file, identifiers] of identifiersByFile) { | 299 for (let [file, identifiers] of identifiersByFile) { |
| 335 let targetModule = filesToTargetModule.get(file); | 300 let targetModule = filesToTargetModule.get(file); |
| 336 for (let identifier of identifiers) { | 301 for (let identifier of identifiers) { |
| 337 let components = identifier.split('.'); | 302 let components = identifier.split('.'); |
| 338 components[0] = mapModuleToNamespace(targetModule); | 303 components[0] = mapModuleToNamespace(targetModule); |
| 339 let newIdentifier = components.join('.'); | 304 let newIdentifier = components.join('.'); |
| 305 // one-off |
| 306 if (targetModule === 'heap_snapshot_model' && components[1] === 'HeapSnaps
hotCommon') { |
| 307 newIdentifier = [components[0]].concat(components.slice(2)).join('.'); |
| 308 if (newIdentifier === 'HeapSnapshotModel') { |
| 309 identifier = 'Profiler.HeapSnapshotCommon = {};\n\n'; |
| 310 newIdentifier = ''; |
| 311 } |
| 312 } |
| 340 map.set(identifier, newIdentifier); | 313 map.set(identifier, newIdentifier); |
| 341 } | 314 } |
| 342 } | 315 } |
| 343 for (let [jsFile, cssFiles] of cssFilesMapping) { | 316 for (let [jsFile, cssFiles] of cssFilesMapping) { |
| 344 let fileObj = JS_FILES_MAPPING.filter(f => f.file === jsFile)[0]; | 317 let fileObj = JS_FILES_MAPPING.filter(f => f.file === jsFile)[0]; |
| 345 let sourceModule = fileObj.file.split('/')[0]; | 318 let sourceModule = fileObj.file.split('/')[0]; |
| 346 let targetModule = fileObj.existing || fileObj.new; | 319 let targetModule = fileObj.existing || fileObj.new; |
| 347 for (let cssFile of cssFiles) { | 320 for (let cssFile of cssFiles) { |
| 348 let key = `${sourceModule}/${cssFile}`; | 321 let key = `${sourceModule}/${cssFile}`; |
| 349 let value = `${targetModule}/${cssFile}`; | 322 let value = `${targetModule}/${cssFile}`; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 361 } |
| 389 | 362 |
| 390 function write(filePath) { | 363 function write(filePath) { |
| 391 let content = fs.readFileSync(filePath).toString(); | 364 let content = fs.readFileSync(filePath).toString(); |
| 392 let newContent = content; | 365 let newContent = content; |
| 393 for (let key of identifierMap.keys()) { | 366 for (let key of identifierMap.keys()) { |
| 394 let originalIdentifier = key; | 367 let originalIdentifier = key; |
| 395 let newIdentifier = identifierMap.get(key); | 368 let newIdentifier = identifierMap.get(key); |
| 396 newContent = newContent.replaceAll(originalIdentifier, newIdentifier); | 369 newContent = newContent.replaceAll(originalIdentifier, newIdentifier); |
| 397 } | 370 } |
| 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 | 371 |
| 408 if (content !== newContent) | 372 if (content !== newContent) |
| 409 fs.writeFileSync(filePath, newContent); | 373 fs.writeFileSync(filePath, newContent); |
| 410 } | 374 } |
| 411 } | 375 } |
| 412 | 376 |
| 413 function removeFromExistingModuleDescriptors(modules, identifierMap, cssFilesMap
ping) { | 377 function removeFromExistingModuleDescriptors(modules, identifierMap, cssFilesMap
ping) { |
| 414 let extensionMap = new Map(); | 378 let extensionMap = new Map(); |
| 415 let moduleFileMap = new Map(); | 379 let moduleFileMap = new Map(); |
| 416 | 380 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 if (dependents.includes(existingModule)) | 612 if (dependents.includes(existingModule)) |
| 649 newDeps.push(newModule); | 613 newDeps.push(newModule); |
| 650 } | 614 } |
| 651 return newDeps; | 615 return newDeps; |
| 652 } | 616 } |
| 653 } | 617 } |
| 654 | 618 |
| 655 function updateApplicationDescriptor(descriptorFileName, newModuleSet) { | 619 function updateApplicationDescriptor(descriptorFileName, newModuleSet) { |
| 656 let descriptorPath = path.join(FRONTEND_PATH, descriptorFileName); | 620 let descriptorPath = path.join(FRONTEND_PATH, descriptorFileName); |
| 657 let newModules = [...newModuleSet].filter(m => APPLICATIONS_BY_MODULE[m].inclu
des(descriptorFileName)); | 621 let newModules = [...newModuleSet].filter(m => APPLICATIONS_BY_MODULE[m].inclu
des(descriptorFileName)); |
| 622 if (newModules.length === 0) |
| 623 return; |
| 658 let includeNewModules = (acc, line) => { | 624 let includeNewModules = (acc, line) => { |
| 659 if (line.includes('{') && line.endsWith('}')) { | 625 if (line.includes('{') && line.endsWith('}')) { |
| 660 line += ','; | 626 line += ','; |
| 661 acc.push(line); | 627 acc.push(line); |
| 662 return acc.concat(newModules.map((m, i) => { | 628 return acc.concat(newModules.map((m, i) => { |
| 663 // Need spacing to preserve indentation | 629 // Need spacing to preserve indentation |
| 664 let string; | 630 let string; |
| 665 if (MODULE_MAPPING[m].autostart) | 631 if (MODULE_MAPPING[m].autostart) |
| 666 string = ` { "name": "${m}", "type": "autostart"}`; | 632 string = ` { "name": "${m}", "type": "autostart"}`; |
| 667 else | 633 else |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 return string.split("") | 673 return string.split("") |
| 708 .map(function (char) { | 674 .map(function (char) { |
| 709 var charCode = char.charCodeAt(0); | 675 var charCode = char.charCodeAt(0); |
| 710 return charCode > 127 ? unicodeCharEscape(charCode) : char; | 676 return charCode > 127 ? unicodeCharEscape(charCode) : char; |
| 711 }) | 677 }) |
| 712 .join(""); | 678 .join(""); |
| 713 } | 679 } |
| 714 | 680 |
| 715 if (require.main === module) | 681 if (require.main === module) |
| 716 extractModule(); | 682 extractModule(); |
| OLD | NEW |