Skip to content

Commit c8ee8e8

Browse files
committed
feat(config): re-introduce noSourceMap option, cleanup
1 parent 2072d78 commit c8ee8e8

File tree

6 files changed

+20
-2533
lines changed

6 files changed

+20
-2533
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Daniel Bölzle
3+
Copyright (c) 2018 Daniel Bölzle
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $ babel --plugins babel-plugin-transform-n4js-systemjs-commonjs ...
2626
Plugin Options:
2727
- `verbose: [string]` switches on verbose logging of the used module IDs
2828
- `stripPackageID_re: [string|Regexp]` regex to rewrite/strip parts of the package ID by convention
29+
- `noSourceMap: [boolean]` whether the N4JS source-map reference should be dropped; defaults to `true`
2930

3031
## License
3132

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "babel-plugin-transform-n4js-systemjs-commonjs",
33
"description": "A babel plugin to transform N4JS SystemJS modules into CommonJS, enabling webpack (via babel-loader) or react-native packager.",
4-
"main": "sysreg.js",
4+
"main": "transform-n4js-systemjs-commonjs.js",
55
"scripts": {
66
"test": "eslint . && mocha tests",
77
"semantic-release": "semantic-release",
@@ -11,7 +11,7 @@
1111
"node": ">=6.4.0"
1212
},
1313
"files": [
14-
"index.js"
14+
"transform-n4js-systemjs-commonjs.js"
1515
],
1616
"keywords": [
1717
"n4js",

tests/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const path = p => lib_path.resolve(__dirname, ...p.split("/"));
1111
const read = p => String(lib_fs.readFileSync(path(p)));
1212

1313
const babelOptions = {
14-
plugins: [[path("../index.js"), {
14+
plugins: [[path("../transform-n4js-systemjs-commonjs.js"), {
1515
//verbose: true,
1616
stripPackageID_re: "\\.api$"
1717
}]]
@@ -29,7 +29,7 @@ describe("N4JS SystemJS -> CommonJS", () => {
2929
it("transforms System.registerDynamic", () => fixtureTest("data/dummy/regdyn"));
3030

3131
it("keeps non-N4JS modules as is", () => {
32-
const pluginCode = read("../index.js");
32+
const pluginCode = read("../transform-n4js-systemjs-commonjs.js");
3333
const expected = babel.transformSync(pluginCode).code;
3434
const res = babel.transformSync(pluginCode, babelOptions).code;
3535
assert.equal(res, expected, "should be the same output");

index.js renamed to transform-n4js-systemjs-commonjs.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ module.exports = ({types: t}) => {
9191
let program = path.node,
9292
opts = state.opts || {},
9393
verbose = opts.verbose,
94-
stripPackageID_re = opts.stripPackageID_re;
94+
stripPackageID_re = opts.stripPackageID_re,
95+
noSourceMap = opts.noSourceMap;
9596

97+
if (typeof noSourceMap === "undefined") {
98+
noSourceMap = true;
99+
}
96100
if (stripPackageID_re && !(stripPackageID_re instanceof RegExp)) {
97101
stripPackageID_re = new RegExp(stripPackageID_re);
98102
}
@@ -124,6 +128,15 @@ module.exports = ({types: t}) => {
124128
sysRegExpr.arguments.push(t.stringLiteral(getModuleIdOf(filename, verbose)));
125129
}
126130

131+
if (noSourceMap) {
132+
const comments = path.container.comments;
133+
comments.forEach(c => {
134+
if (c.value.startsWith("# sourceMappingURL=")) {
135+
c.value = `--${c.value}--`;
136+
}
137+
});
138+
}
139+
127140
// replace all System._nodeRequire calls
128141
path.traverse(_nodeRequireVisitor);
129142

0 commit comments

Comments
 (0)