| 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 'toolbox.json', |
| 17 'unit_test_runner.json', | 17 'unit_test_runner.json', |
| 18 'formatter_worker.json', | 18 'formatter_worker.json', |
| 19 'heap_snapshot_worker.json', | 19 'heap_snapshot_worker.json', |
| 20 'utility_shared_worker.json', | 20 'utility_shared_worker.json', |
| 21 ]; | 21 ]; |
| 22 | 22 |
| 23 // Replace based on specified transformation | 23 // Replace based on specified transformation |
| 24 const MODULES_TO_REMOVE = []; | 24 const MODULES_TO_REMOVE = []; |
| 25 | 25 |
| 26 const JS_FILES_MAPPING = [ | 26 const JS_FILES_MAPPING = [ |
| 27 {file: 'profiler/HeapSnapshotModel.js', new: 'heap_snapshot_model'}, | 27 {file: 'common/CSSShadowModel.js', existing: 'inline_editor'}, |
| 28 {file: 'common/Geometry.js', existing: 'ui'}, |
| 28 // {file: 'module/file.js', existing: 'module'} | 29 // {file: 'module/file.js', existing: 'module'} |
| 29 ]; | 30 ]; |
| 30 | 31 |
| 31 const MODULE_MAPPING = { | 32 const MODULE_MAPPING = { |
| 32 heap_snapshot_model: { | 33 // heap_snapshot_model: { |
| 33 dependencies: [], | 34 // dependencies: [], |
| 34 dependents: ['heap_snapshot_worker', 'profiler'], | 35 // dependents: ['heap_snapshot_worker', 'profiler'], |
| 35 applications: ['inspector.json'], // need to manually add to heap snapshot w
orker b/c it's autostart | 36 // applications: ['inspector.json'], // need to manually add to heap snapsho
t worker b/c it's autostart |
| 36 autostart: false, | 37 // autostart: false, |
| 37 }, | 38 // }, |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 const NEW_DEPENDENCIES_BY_EXISTING_MODULES = { | 41 const NEW_DEPENDENCIES_BY_EXISTING_MODULES = { |
| 41 // resources: ['components'], | 42 // resources: ['components'], |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 const REMOVE_DEPENDENCIES_BY_EXISTING_MODULES = { | 45 const REMOVE_DEPENDENCIES_BY_EXISTING_MODULES = { |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 const DEPENDENCIES_BY_MODULE = Object.keys(MODULE_MAPPING).reduce((acc, module)
=> { | 48 const DEPENDENCIES_BY_MODULE = Object.keys(MODULE_MAPPING).reduce((acc, module)
=> { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 function scrapeIdentifiers(content, fileObj) { | 160 function scrapeIdentifiers(content, fileObj) { |
| 160 let identifiers = []; | 161 let identifiers = []; |
| 161 let lines = content.split('\n'); | 162 let lines = content.split('\n'); |
| 162 for (let line of lines) { | 163 for (let line of lines) { |
| 163 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\.]+);`)); |
| 164 if (!match) | 165 if (!match) |
| 165 continue; | 166 continue; |
| 166 let name = match[1]; | 167 let name = match[1]; |
| 167 | 168 |
| 168 var currentModule = fileObj.file.split('/')[0]; | 169 var currentModule = fileObj.file.split('/')[0]; |
| 169 if (name.split('.')[0] !== mapModuleToNamespace(currentModule)) | 170 if (name.split('.')[0] !== mapModuleToNamespace(currentModule)) { |
| 170 console.log(`POSSIBLE ISSUE: identifier: ${name} found in ${currentModul
e}`); | 171 console.log(`POSSIBLE ISSUE: identifier: ${name} found in ${currentModul
e}`); |
| 171 else | 172 // one-off |
| 173 if (name.includes('UI.')) { |
| 174 console.log(`including ${name} anyways`); |
| 175 identifiers.push(name) |
| 176 } |
| 177 } else { |
| 172 identifiers.push(name); | 178 identifiers.push(name); |
| 179 } |
| 173 } | 180 } |
| 174 return identifiers; | 181 return identifiers; |
| 175 } | 182 } |
| 176 } | 183 } |
| 177 | 184 |
| 178 function moveFiles(cssFilesMapping) { | 185 function moveFiles(cssFilesMapping) { |
| 179 for (let fileObj of JS_FILES_MAPPING) { | 186 for (let fileObj of JS_FILES_MAPPING) { |
| 180 let sourceFilePath = path.resolve(FRONTEND_PATH, fileObj.file); | 187 let sourceFilePath = path.resolve(FRONTEND_PATH, fileObj.file); |
| 181 let targetFilePath = getMappedFilePath(fileObj); | 188 let targetFilePath = getMappedFilePath(fileObj); |
| 182 let moduleDir = path.resolve(targetFilePath, '..'); | 189 let moduleDir = path.resolve(targetFilePath, '..'); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 263 } |
| 257 } | 264 } |
| 258 return partialPathMapping; | 265 return partialPathMapping; |
| 259 } | 266 } |
| 260 | 267 |
| 261 function top(array) { | 268 function top(array) { |
| 262 return array[array.length - 1]; | 269 return array[array.length - 1]; |
| 263 } | 270 } |
| 264 | 271 |
| 265 function addContentToLinesInSortedOrder({content, startLine, endLine, linesToI
nsert}) { | 272 function addContentToLinesInSortedOrder({content, startLine, endLine, linesToI
nsert}) { |
| 273 if (linesToInsert.length === 0) |
| 274 return content; |
| 266 let lines = content.split('\n'); | 275 let lines = content.split('\n'); |
| 267 let seenStartLine = false; | 276 let seenStartLine = false; |
| 268 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(); |
| 269 for (var i = 0; i < lines.length; i++) { | 278 for (var i = 0; i < lines.length; i++) { |
| 270 let line = lines[i].trim(); | 279 let line = lines[i].trim(); |
| 271 let nextLine = lines[i + 1].trim(); | 280 let nextLine = lines[i + 1].trim(); |
| 272 if (line === startLine) | 281 if (line === startLine) |
| 273 seenStartLine = true; | 282 seenStartLine = true; |
| 274 | 283 |
| 275 if (line === endLine && seenStartLine) | 284 if (line === endLine && seenStartLine) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 295 filesToTargetModule.set(fileObj.file, fileObj.existing || fileObj.new); | 304 filesToTargetModule.set(fileObj.file, fileObj.existing || fileObj.new); |
| 296 | 305 |
| 297 | 306 |
| 298 const map = new Map(); | 307 const map = new Map(); |
| 299 for (let [file, identifiers] of identifiersByFile) { | 308 for (let [file, identifiers] of identifiersByFile) { |
| 300 let targetModule = filesToTargetModule.get(file); | 309 let targetModule = filesToTargetModule.get(file); |
| 301 for (let identifier of identifiers) { | 310 for (let identifier of identifiers) { |
| 302 let components = identifier.split('.'); | 311 let components = identifier.split('.'); |
| 303 components[0] = mapModuleToNamespace(targetModule); | 312 components[0] = mapModuleToNamespace(targetModule); |
| 304 let newIdentifier = components.join('.'); | 313 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 } | |
| 313 map.set(identifier, newIdentifier); | 314 map.set(identifier, newIdentifier); |
| 314 } | 315 } |
| 315 } | 316 } |
| 316 for (let [jsFile, cssFiles] of cssFilesMapping) { | 317 for (let [jsFile, cssFiles] of cssFilesMapping) { |
| 317 let fileObj = JS_FILES_MAPPING.filter(f => f.file === jsFile)[0]; | 318 let fileObj = JS_FILES_MAPPING.filter(f => f.file === jsFile)[0]; |
| 318 let sourceModule = fileObj.file.split('/')[0]; | 319 let sourceModule = fileObj.file.split('/')[0]; |
| 319 let targetModule = fileObj.existing || fileObj.new; | 320 let targetModule = fileObj.existing || fileObj.new; |
| 320 for (let cssFile of cssFiles) { | 321 for (let cssFile of cssFiles) { |
| 321 let key = `${sourceModule}/${cssFile}`; | 322 let key = `${sourceModule}/${cssFile}`; |
| 322 let value = `${targetModule}/${cssFile}`; | 323 let value = `${targetModule}/${cssFile}`; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 return string.split("") | 674 return string.split("") |
| 674 .map(function (char) { | 675 .map(function (char) { |
| 675 var charCode = char.charCodeAt(0); | 676 var charCode = char.charCodeAt(0); |
| 676 return charCode > 127 ? unicodeCharEscape(charCode) : char; | 677 return charCode > 127 ? unicodeCharEscape(charCode) : char; |
| 677 }) | 678 }) |
| 678 .join(""); | 679 .join(""); |
| 679 } | 680 } |
| 680 | 681 |
| 681 if (require.main === module) | 682 if (require.main === module) |
| 682 extractModule(); | 683 extractModule(); |
| OLD | NEW |