From 455069ae90d4b4f0423dbdcd169bbeca015274ec Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Mon, 16 Mar 2020 16:16:53 +0000 Subject: [PATCH] Add karma-sourcemap-loader to node_modules This will be used to load sourcemap files for TypeScript unittests. R=aerotwist@chromium.org,jacktfranklin@chromium.org DISABLE_THIRD_PARTY_CHECK=Add node_module Bug: 1061125 Change-Id: I13cfdbe078402b02563e7843595016a14bf93617 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2105436 Reviewed-by: Jack Franklin Reviewed-by: Paul Lewis Commit-Queue: Tim van der Lippe --- .../karma-sourcemap-loader/.idea/.name | 1 + .../.idea/encodings.xml | 5 + .../.idea/karma-sourcemap-loader.iml | 9 + .../karma-sourcemap-loader/.idea/misc.xml | 5 + .../karma-sourcemap-loader/.idea/modules.xml | 9 + .../.idea/scopes/scope_settings.xml | 5 + .../karma-sourcemap-loader/.idea/vcs.xml | 7 + .../.idea/workspace.xml | 210 ++++++++++++++++++ .../karma-sourcemap-loader/.npmignore | 15 ++ node_modules/karma-sourcemap-loader/LICENSE | 20 ++ node_modules/karma-sourcemap-loader/README.md | 55 +++++ node_modules/karma-sourcemap-loader/index.js | 68 ++++++ .../karma-sourcemap-loader/package.json | 21 ++ package-lock.json | 6 + scripts/deps/manage_node_deps.py | 1 + 15 files changed, 437 insertions(+) create mode 100644 node_modules/karma-sourcemap-loader/.idea/.name create mode 100644 node_modules/karma-sourcemap-loader/.idea/encodings.xml create mode 100644 node_modules/karma-sourcemap-loader/.idea/karma-sourcemap-loader.iml create mode 100644 node_modules/karma-sourcemap-loader/.idea/misc.xml create mode 100644 node_modules/karma-sourcemap-loader/.idea/modules.xml create mode 100644 node_modules/karma-sourcemap-loader/.idea/scopes/scope_settings.xml create mode 100644 node_modules/karma-sourcemap-loader/.idea/vcs.xml create mode 100644 node_modules/karma-sourcemap-loader/.idea/workspace.xml create mode 100644 node_modules/karma-sourcemap-loader/.npmignore create mode 100644 node_modules/karma-sourcemap-loader/LICENSE create mode 100644 node_modules/karma-sourcemap-loader/README.md create mode 100644 node_modules/karma-sourcemap-loader/index.js create mode 100644 node_modules/karma-sourcemap-loader/package.json diff --git a/node_modules/karma-sourcemap-loader/.idea/.name b/node_modules/karma-sourcemap-loader/.idea/.name new file mode 100644 index 0000000000..ad97961a44 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.idea/.name @@ -0,0 +1 @@ +karma-sourcemap-loader \ No newline at end of file diff --git a/node_modules/karma-sourcemap-loader/.idea/encodings.xml b/node_modules/karma-sourcemap-loader/.idea/encodings.xml new file mode 100644 index 0000000000..e206d70d85 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/node_modules/karma-sourcemap-loader/.idea/karma-sourcemap-loader.iml b/node_modules/karma-sourcemap-loader/.idea/karma-sourcemap-loader.iml new file mode 100644 index 0000000000..6b8184f8ef --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.idea/karma-sourcemap-loader.iml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/node_modules/karma-sourcemap-loader/.idea/misc.xml b/node_modules/karma-sourcemap-loader/.idea/misc.xml new file mode 100644 index 0000000000..1162f43828 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/node_modules/karma-sourcemap-loader/.idea/modules.xml b/node_modules/karma-sourcemap-loader/.idea/modules.xml new file mode 100644 index 0000000000..c6c96d1933 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/node_modules/karma-sourcemap-loader/.idea/scopes/scope_settings.xml b/node_modules/karma-sourcemap-loader/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000000..922003b843 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/node_modules/karma-sourcemap-loader/.idea/vcs.xml b/node_modules/karma-sourcemap-loader/.idea/vcs.xml new file mode 100644 index 0000000000..c80f2198b5 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/node_modules/karma-sourcemap-loader/.idea/workspace.xml b/node_modules/karma-sourcemap-loader/.idea/workspace.xml new file mode 100644 index 0000000000..92ff8414db --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.idea/workspace.xml @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1397815966441 + 1397815966441 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/node_modules/karma-sourcemap-loader/.npmignore b/node_modules/karma-sourcemap-loader/.npmignore new file mode 100644 index 0000000000..a72b52ebe8 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/.npmignore @@ -0,0 +1,15 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz + +pids +logs +results + +npm-debug.log +node_modules diff --git a/node_modules/karma-sourcemap-loader/LICENSE b/node_modules/karma-sourcemap-loader/LICENSE new file mode 100644 index 0000000000..5354797ccd --- /dev/null +++ b/node_modules/karma-sourcemap-loader/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Sergey Todyshev + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/karma-sourcemap-loader/README.md b/node_modules/karma-sourcemap-loader/README.md new file mode 100644 index 0000000000..5449d88e1c --- /dev/null +++ b/node_modules/karma-sourcemap-loader/README.md @@ -0,0 +1,55 @@ +# karma-sourcemap-loader + +> Preprocessor that locates and loads existing source maps. + +## Why + +When you use karma not in isolation but as part of a build process (e.g. using grunt +or gulp) it is often the case that the compilation/transpilation is done on a previous +step of the process and not handled by karma preprocessors. In these cases source maps +don't get loaded by karma and you lose the advantages of having them. + +## How it works + +This plug-in supports both inline and external source maps. + +Inline source maps are located by searching "sourceMappingURL=" inside the javascript +file, both plain text and base64-encoded maps are supported. + +External source maps are located by appending ".map" to the javascript file name. +So if for example you have Hello.js, the preprocessor will try to load source map from +Hello.js.map. + +## Installation + +Just write `karma-sourcemap-loader` as a devDependency in your `package.json`. +```json +{ + "devDependencies": { + "karma-sourcemap-loader": "~0.2" + } +} +``` + +Or just issue the following command: +```bash +npm install karma-sourcemap-loader --save-dev +``` + +## Configuration + +The code below shows a sample configuration of the preprocessor. +```js +// karma.conf.js +module.exports = function(config) { + config.set({ + preprocessors: { + '**/*.js': ['sourcemap'] + } + }); +}; +``` + +## Credits + +Thanks to @goldibex for adding inline source maps support. diff --git a/node_modules/karma-sourcemap-loader/index.js b/node_modules/karma-sourcemap-loader/index.js new file mode 100644 index 0000000000..62e92ec7e7 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/index.js @@ -0,0 +1,68 @@ +var fs = require('fs'); +var path = require('path'); + +var createSourceMapLocatorPreprocessor = function(args, logger, helper) { + var log = logger.create('preprocessor.sourcemap'); + + log.debug('loaded'); + + return function(content, file, done) { + function sourceMapData(data){ + file.sourceMap = JSON.parse(data); + done(content); + } + + function inlineMap(inlineData){ + var data; + var b64Match = inlineData.match(/^data:.+\/(.+);base64,(.*)$/); + if (b64Match !== null && b64Match.length == 3) { + // base64-encoded JSON string + log.debug('base64-encoded source map for', file.originalPath); + var buffer = new Buffer(b64Match[2], 'base64'); + sourceMapData(buffer.toString()); + } else { + // straight-up URL-encoded JSON string + log.debug('raw inline source map for', file.originalPath); + sourceMapData(decodeURIComponent(inlineData.slice('data:application/json'.length))); + } + } + + function fileMap(mapPath){ + fs.exists(mapPath, function(exists) { + if (!exists) { + log.debug('sourcemap file does not exist'); + done(content); + return; + } + log.debug('test'); + fs.readFile(mapPath, function(err, data) { + if (err){ throw err; } + + log.debug('external source map exists for', file.originalPath); + sourceMapData(data); + }); + }); + } + + var match = content.match(/#\s*sourceMappingURL=(.+)$/m); + log.debug(match); + if (match !== null && match.length == 2) { + var mapUrl = match[1]; + if( /^data:application\/json/.test(mapUrl) ){ + inlineMap(mapUrl); + } else { + fileMap(path.resolve(path.dirname(file.path), mapUrl)); + } + + } else { + fileMap(file.path + ".map"); + } + }; +}; + +createSourceMapLocatorPreprocessor.$inject = ['args', 'logger', 'helper']; + +// PUBLISH DI MODULE +module.exports = { + 'preprocessor:sourcemap': ['factory', createSourceMapLocatorPreprocessor] +}; diff --git a/node_modules/karma-sourcemap-loader/package.json b/node_modules/karma-sourcemap-loader/package.json new file mode 100644 index 0000000000..3f5312e060 --- /dev/null +++ b/node_modules/karma-sourcemap-loader/package.json @@ -0,0 +1,21 @@ +{ + "author": { + "email": "gabriele.genta@gmail.com", + "name": "Gabriele Genta" + }, + "description": "Karma plugin that locates and loads existing javascript source map files.", + "keywords": [ + "karma-plugin", + "karma-preprocessor", + "source-maps", + "javascript" + ], + "license": "MIT", + "main": "index.js", + "name": "karma-sourcemap-loader", + "repository": { + "type": "git", + "url": "git@github.com:demerzel3/karma-sourcemap-loader.git" + }, + "version": "0.3.0" +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index b8258c7b50..171d9ec93b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2954,6 +2954,12 @@ } } }, + "karma-sourcemap-loader": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.0.tgz", + "integrity": "sha1-oS27WIfZDeeg0ezB2yEKvcsrVnQ=", + "dev": true + }, "karma-typescript": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/karma-typescript/-/karma-typescript-4.1.1.tgz", diff --git a/scripts/deps/manage_node_deps.py b/scripts/deps/manage_node_deps.py index 7fd1d495de..77d510e58f 100644 --- a/scripts/deps/manage_node_deps.py +++ b/scripts/deps/manage_node_deps.py @@ -49,6 +49,7 @@ DEPS = { "karma-coverage-istanbul-instrumenter": "1.0.1", "karma-coverage-istanbul-reporter": "2.1.0", "karma-mocha": "1.3.0", + "karma-sourcemap-loader": "0.3.0", "karma-typescript": "4.1.1", "license-checker": "25.0.1", "mocha": "6.2.0",