diff --git a/.pullapprove.yml b/.pullapprove.yml index 91a503e2d56..09b06186a59 100644 --- a/.pullapprove.yml +++ b/.pullapprove.yml @@ -1132,7 +1132,6 @@ groups: 'tools/rxjs/**', 'tools/saucelabs/**', 'tools/size-tracking/**', - 'tools/source-map-test/**', 'tools/symbol-extractor/**', 'tools/testing/**', 'tools/tslint/**', diff --git a/gulpfile.js b/gulpfile.js index 96c7d95b922..d44578dad04 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,5 +18,4 @@ function loadTask(fileName, taskName) { } -gulp.task('source-map-test', loadTask('source-map-test')); gulp.task('changelog:zonejs', loadTask('changelog-zonejs')); diff --git a/tools/gulp-tasks/source-map-test.js b/tools/gulp-tasks/source-map-test.js deleted file mode 100644 index ff692b61e4a..00000000000 --- a/tools/gulp-tasks/source-map-test.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -const fs = require('fs'); -const path = require('path'); -const sourceMapTest = require('../source-map-test'); - -const excludedPackages = ['bazel', 'benchpress', 'compiler-cli', 'language-service']; - -module.exports = (gulp) => () => { - const packageDir = path.resolve(process.cwd(), 'dist/packages-dist/'); - const packages = - fs.readdirSync(packageDir).filter(package => excludedPackages.indexOf(package) === -1); - - packages.forEach(package => { - if (sourceMapTest(package).length) { - process.exit(1); - } - }); - - if (!packages.length) { - // tslint:disable-next-line:no-console - console.log('No packages found in packages-dist. Unable to run source map test.'); - process.exit(1); - } -}; diff --git a/tools/source-map-test/index.js b/tools/source-map-test/index.js deleted file mode 100644 index e76465c4fe9..00000000000 --- a/tools/source-map-test/index.js +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env node - -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -const path = require('path'); -const getMappings = require('./parseMap'); - -const CLOSURE_REGEX = /tsickle_Closure_declarations\(\)/g; -const VAR_REGEX = /(export )?(var (\S+) =)/g; -const FUNCTION_REGEX = /(export )?function (\S+)\((.*)\) {/g; -const CLASS_REGEX = /var (\S+) = \(function \((\S*)\) {/g; -const PROPERTY_REGEX = /Object.defineProperty\((\S+)\.prototype, "(\S+)", {/g; -const METHOD_REGEX = /(\S+)\.prototype\.(\S+) = function \((\S*)\) {/g; -const GETTER_REGEX = /get_REGEX = function \((\S*)\) {/g; -const TYPE_COMMENT_REGEX = /\/\*\* @type {\?} \*\/ /g; -const AFTER_EQUALS_REGEX = /([^=]+)=(.*)/g; -const EXPORT_REGEX = /export /g; -const TSLIB_REGEX = /tslib_\d\.__/g; -const STRIP_PREFIX_REGEX = /ɵ/g; -const STRIP_SUFFIX_REGEX = /([^$]+)(\$)+\d/g; -const SYNTHETIC_REGEX = /ɵ[0-9]/; - -// tslint:disable:no-console -module.exports = function sourceMapTest(package) { - const mappings = - getMappings(getBundlePath(package)).filter(mapping => shouldCheckMapping(mapping.sourceText)); - - console.log(`Analyzing ${mappings.length} mappings for ${package}...`); - - const failures = mappings.filter(mapping => { - if (SYNTHETIC_REGEX.test(mapping.sourceText)) return false; - if (cleanSource(mapping.sourceText) !== cleanGen(mapping.genText)) { - console.log('source:', cleanSource(mapping.sourceText), 'gen:', cleanGen(mapping.genText)); - } - return cleanSource(mapping.sourceText) !== cleanGen(mapping.genText); - }); - - logResults(failures); - return failures; -}; - -function shouldCheckMapping(text) { - // tsickle closure declaration does not exist in final bundle, so can't be checked - if (CLOSURE_REGEX.test(text)) return false; - return VAR_REGEX.test(text) || FUNCTION_REGEX.test(text) || CLASS_REGEX.test(text) || - PROPERTY_REGEX.test(text) || METHOD_REGEX.test(text) || GETTER_REGEX.test(text); -} - -function cleanSource(source) { - return source.replace(TYPE_COMMENT_REGEX, '') - .replace(EXPORT_REGEX, '') - .replace(STRIP_PREFIX_REGEX, '') - .replace(TSLIB_REGEX, '__') - .replace(AFTER_EQUALS_REGEX, '$1='); -} - -function cleanGen(gen) { - return gen.replace(TYPE_COMMENT_REGEX, '') - .replace(STRIP_PREFIX_REGEX, '') - .replace(STRIP_SUFFIX_REGEX, '$1') - .replace(AFTER_EQUALS_REGEX, '$1='); -} - -// tslint:disable:no-console -function logResults(failures) { - if (failures.length) { - console.error(`... and source maps appear to be broken: ${failures.length} failures.`); - failures.forEach(failure => console.error(failure)); - } else { - console.log('... and source maps look good! 100% match'); - } -} - -function getBundlePath(package) { - return path.resolve(process.cwd(), 'dist/packages-dist/', package, 'esm5/', package + '.js'); -} diff --git a/tools/source-map-test/parseMap.js b/tools/source-map-test/parseMap.js deleted file mode 100644 index 2d323d50f12..00000000000 --- a/tools/source-map-test/parseMap.js +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env node - -/** - * @license - * Copyright Google LLC All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -const vlq = require('vlq'); -const fs = require('fs'); -const path = require('path'); - -module.exports = function getMappings(bundlePath) { - const sourceMap = JSON.parse(getFile(`${bundlePath}.map`)); - const sourcesContent = sourceMap.sourcesContent.map(file => file.split('\n')); - const bundleLines = getFile(bundlePath).split('\n'); - - let sourceLines = sourcesContent[0]; - let sourceFileIndex = 0; - let sourceLineIndex = 0; - let sourceColIndex = 0; - - return decodeLines(sourceMap).reduce((matchData, mapLine, genLineIndex) => { - mapLine.forEach((segment, index) => { - if (segment.length) { - const [genColDiff, sourceFileDiff, sourceLineDiff, sourceColDiff] = segment; - - // if source file changes, grab new file from sourcesContent - if (sourceFileDiff !== 0) { - sourceFileIndex += sourceFileDiff; - sourceLines = sourcesContent[sourceFileIndex]; - } - - const genText = bundleLines[genLineIndex].trim(); - const sourceText = sourceLines[sourceLineIndex + sourceLineDiff].trim(); - - // only record mappings that are long enough to be meaningful - if (index === 0 && genText.length > 15 && sourceText.length > 15) { - matchData.push({ - genLineIndex, - sourceLineIndex, - sourceFile: sourceMap.sources[sourceFileIndex], - genText, - sourceText - }); - } - - sourceLineIndex += sourceLineDiff; - sourceColIndex += sourceColDiff; - } - }); - - return matchData; - }, []); -}; - -function getFile(filePath) { - return fs.readFileSync(path.resolve(process.cwd(), filePath), 'utf-8'); -} - -function decodeLines(sourceMap) { - return sourceMap.mappings.split(';').map(line => { - return line.split(',').map(seg => vlq.decode(seg)); - }); -}