Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cache:
notifications:
email: false
node_js:
- '9'
- '10'
- '8'
after_success:
- npm run travis-deploy-once "npm run semantic-release"
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ $ npm install babel-plugin-transform-n4js-systemjs-commonjs --save-dev
Using a `.babelrc`:
```
{
"plugins": ["transform-n4js-systemjs-commonjs"]
"plugins": ["babel-plugin-transform-n4js-systemjs-commonjs"]
}
```

or via CLI:
```bash
$ babel --plugins transform-n4js-systemjs-commonjs ...
$ babel --plugins babel-plugin-transform-n4js-systemjs-commonjs ...
```

Plugin Options:
- `verbose: [string]` switches on verbose logging of the used module IDs
- `stripPackageID_re: [string|Regexp]` regex to rewrite/strip parts of the package ID by convention
- `noSourceMap: [boolean]` whether the N4JS source-map reference should be dropped; defaults to `true`

## License

Expand Down
27 changes: 7 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,52 +91,39 @@ module.exports = ({types: t}) => {
let program = path.node,
opts = state.opts || {},
verbose = opts.verbose,
stripPackageID_re = opts.stripPackageID_re,
noSourceMap = opts.noSourceMap;
stripPackageID_re = opts.stripPackageID_re;

if (typeof noSourceMap === "undefined") {
noSourceMap = true;
}
if (stripPackageID_re && !(stripPackageID_re instanceof RegExp)) {
stripPackageID_re = new RegExp(stripPackageID_re);
}

if (n4jsModulePatternMatcher(program)) {
try {
let fnExpr = program.body[0].expression;
const fnExpr = program.body[0].expression;

// reduce ternary footer:
let consequent = fnExpr.arguments[0].consequent;
const consequent = fnExpr.arguments[0].consequent;
consequent.callee.object.arguments = [t.stringLiteral("n4js-node")];
//consequent.arguments[0] = t.nullLiteral();
consequent.callee.property = t.identifier("staticSystem");
fnExpr.arguments = [consequent.callee];

let sysRegExpr = fnExpr.callee.body.body[0].expression;
let sysregDeps = sysRegExpr.arguments[0];
const sysRegExpr = fnExpr.callee.body.body[0].expression;
const sysregDeps = sysRegExpr.arguments[0];
sysregDeps.elements = sysregDeps.elements.map(d => t.callExpression(t.identifier("require"), [buildDep(d, stripPackageID_re)]));

let dynregCallback = sysRegExpr.arguments[2];
const dynregCallback = sysRegExpr.arguments[2];
if (dynregCallback) { // registerDynamic
// Get require symbol out of the way
dynregCallback.params[0] = t.identifier("__require");
}

sysRegExpr.arguments.push(t.identifier("module"));
let filename = state.file.opts.filename;
const filename = state.file.opts.filename;
if (filename !== "unknown") {
sysRegExpr.arguments.push(t.stringLiteral(getModuleIdOf(filename, verbose)));
}

if (noSourceMap) {
let comments = path.container.comments;
comments.forEach(c => {
if (c.value.startsWith("# sourceMappingURL=")) {
c.value = `--${c.value}--`;
}
});
}

// replace all System._nodeRequire calls
path.traverse(_nodeRequireVisitor);

Expand Down
Loading