Skip to content
Permalink
Browse files

fix(bundler): avoid appending alias after comment (sourceMap line).

This fixes tracing npm package "noty".
  • Loading branch information...
3cp committed Apr 6, 2019
1 parent 24e2d88 commit 621bda7ae55a52bfaa0b8516df935ef226aff03a
Showing with 6 additions and 6 deletions.
  1. +1 −1 lib/build/amodro-trace/write/defines.js
  2. +5 −5 spec/lib/build/bundled-source.spec.js
@@ -96,7 +96,7 @@ function defines(options) {
if (packageName && namedModule && namedModule !== packageName) {
// for main module, if named module name doesn't match package name
// make an alias from moduleName (not packageName) to namedModule
contents += 'define("' + moduleName + '", ["' + namedModule + '"], function(m){return m;});\n';
contents += '\n;define("' + moduleName + '", ["' + namedModule + '"], function(m){return m;});\n';
}
}
}
@@ -295,7 +295,7 @@ export {t};
it('transforms npm package js file with named AMD module', () => {
let file = {
path: path.resolve(cwd, 'node_modules/foo/index.js'),
contents: "define('M', ['a', 'b'], function(){});\n"
contents: "define('M', ['a', 'b'], function(){});"
};

let bs = new BundledSource(bundler, file);
@@ -321,8 +321,8 @@ export {t};
let deps = bs.transform();
expect(deps).toEqual(['a', 'b']);
expect(bs.requiresTransform).toBe(false);
expect(bs.contents.replace(/\r|\n/g, ''))
.toBe("define('M', ['a', 'b'], function(){});define(\"foo/index\", [\"M\"], function(m){return m;});");
expect(bs.contents)
.toBe("define('M', ['a', 'b'], function(){});\n;define(\"foo/index\", [\"M\"], function(m){return m;});\n");
});

it('transforms npm package js file with more than one named AMD module', () => {
@@ -355,8 +355,8 @@ export {t};
expect(deps).toEqual(['a', 'b', 'c']);
expect(bs.requiresTransform).toBe(false);
// the alias targets first named module 'M'
expect(bs.contents.replace(/\r|\n/g, ''))
.toBe("define('M', ['a', 'b'], function(){});define('N', ['c'], function(){});define(\"foo/index\", [\"M\"], function(m){return m;});");
expect(bs.contents)
.toBe("define('M', ['a', 'b'], function(){});define('N', ['c'], function(){});\n\n;define(\"foo/index\", [\"M\"], function(m){return m;});\n");
});

it('transforms npm package js file by force cjs wrapper', () => {

0 comments on commit 621bda7

Please sign in to comment.
You can’t perform that action at this time.