[Pkg-javascript-commits] [node-source-map-support] 02/06: New upstream version 0.4.4+ds

Julien Puydt julien.puydt at laposte.net
Tue Oct 18 14:12:54 UTC 2016


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-source-map-support.

commit 2dc30f0a6d103e47bc24a9c22a1faa67b6ac3e80
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Sun Oct 16 16:57:28 2016 +0200

    New upstream version 0.4.4+ds
---
 README.md             | 11 +++++++++++
 package.json          |  2 +-
 source-map-support.js | 18 +++++++++++++++++-
 test.js               | 39 +++++++++++++++++++++++++++++++++++++--
 4 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 57f4d1d..c21cfeb 100644
--- a/README.md
+++ b/README.md
@@ -101,6 +101,17 @@ require('source-map-support').install({
 });
 ```
 
+To support files with inline source maps, the `hookRequire` options can be specified, which will monitor all source files for inline source maps.
+
+
+```js
+require('source-map-support').install({
+  hookRequire: true
+});
+```
+
+This monkey patches the `require` module loading chain, so is not enabled by default and is not recommended for any sort of production usage.
+
 ## Demos
 
 #### Basic Demo
diff --git a/package.json b/package.json
index 7b36c19..e595ad6 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "source-map-support",
   "description": "Fixes stack traces for files with source maps",
-  "version": "0.4.3",
+  "version": "0.4.4",
   "main": "./source-map-support.js",
   "scripts": {
     "build": "node build.js",
diff --git a/source-map-support.js b/source-map-support.js
index 0cfb14d..fe21a9a 100644
--- a/source-map-support.js
+++ b/source-map-support.js
@@ -136,7 +136,7 @@ retrieveMapHandlers.push(function(source) {
     // Support source map URL as a data url
     var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1);
     sourceMapData = new Buffer(rawData, "base64").toString();
-    sourceMappingURL = null;
+    sourceMappingURL = source;
   } else {
     // Support source map URLs relative to the source URL
     sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
@@ -455,6 +455,22 @@ exports.install = function(options) {
     retrieveMapHandlers.unshift(options.retrieveSourceMap);
   }
 
+  // Support runtime transpilers that include inline source maps
+  if (options.hookRequire && !isInBrowser()) {
+    var Module = require('module');
+    var $compile = Module.prototype._compile;
+
+    if (!$compile.__sourceMapSupport) {
+      Module.prototype._compile = function(content, filename) {
+        fileContentsCache[filename] = content;
+        sourceMapCache[filename] = undefined;
+        return $compile.call(this, content, filename);
+      };
+
+      Module.prototype._compile.__sourceMapSupport = true;
+    }
+  }
+
   // Configure options
   if (!emptyCacheBetweenOperations) {
     emptyCacheBetweenOperations = 'emptyCacheBetweenOperations' in options ?
diff --git a/test.js b/test.js
index 72245ec..1179f5e 100644
--- a/test.js
+++ b/test.js
@@ -247,8 +247,6 @@ it('function constructor', function() {
     'throw new Function(")");'
   ], [
     'SyntaxError: Unexpected token )',
-    /^    at (?:Object\.)?Function \((?:unknown source|<anonymous>|native)\)$/,
-    /^    at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/,
   ]);
 });
 
@@ -459,6 +457,43 @@ it('should consult all retrieve source map providers', function(done) {
   ]);
 });
 
+it('should allow for runtime inline source maps', function(done) {
+  var sourceMap = createMultiLineSourceMapWithSourcesContent();
+
+  fs.writeFileSync('.generated.jss', 'foo');
+
+  compareStdout(function(err) {
+    fs.unlinkSync('.generated.jss');
+    done(err);
+  }, createSingleLineSourceMap(), [
+    'require("./source-map-support").install({',
+    '  hookRequire: true',
+    '});',
+    'require.extensions[".jss"] = function(module, filename) {',
+    '  module._compile(',
+        JSON.stringify([
+          '',
+          'var count = 0;',
+          'function foo() {',
+          '  console.log(new Error("this is the error").stack.split("\\n").slice(0, 2).join("\\n"));',
+          '}',
+          'process.nextTick(foo);',
+          'process.nextTick(foo);',
+          'process.nextTick(function() { console.log(count); });',
+          '//@ sourceMappingURL=data:application/json;charset=utf8;base64,' + new Buffer(sourceMap.toString()).toString('base64')
+        ].join('\n')),
+        ', filename);',
+    '};',
+    'require("./.generated.jss");',
+  ], [
+    'Error: this is the error',
+    /^    at foo \(.*\/original.js:1004:5\)$/,
+    'Error: this is the error',
+    /^    at foo \(.*\/original.js:1004:5\)$/,
+    '0', // The retrieval should only be attempted once
+  ]);
+});
+
 /* The following test duplicates some of the code in
  * `compareStackTrace` but appends a charset to the
  * source mapping url.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-source-map-support.git



More information about the Pkg-javascript-commits mailing list