babel-plugin-wrap-modules-amd
Advanced tools
Comparing version 1.4.2 to 1.5.0
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _pluginLogger = require('liferay-npm-build-tools-common/lib/plugin-logger'); | ||
var _pluginLogger2 = _interopRequireDefault(_pluginLogger); | ||
var _index = require('../index'); | ||
@@ -16,2 +20,19 @@ | ||
var logger = void 0; | ||
beforeEach(function () { | ||
_pluginLogger2.default.set(__filename, logger = new _pluginLogger2.default()); | ||
}); | ||
it('logs results correctly', function () { | ||
var source = '\n\tconsole.log(\'Say something\');\n\tvar a = require(\'a-module\');\n\tvar b = require(\'b-module\');\n\t'; | ||
babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
}); | ||
expect(logger.messages).toMatchSnapshot(); | ||
}); | ||
it('correctly wraps modules', function () { | ||
@@ -21,2 +42,3 @@ var source = '\n\tconsole.log(\'Say something\');\n\tif (1 == 0) {\n\t\tconsole.log(\'Something broke in the Matrix\');\n\t}\n\tmodule.exports = \'All OK\';\n\t'; | ||
var _babel$transform = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
@@ -23,0 +45,0 @@ }), |
@@ -38,8 +38,9 @@ 'use strict'; | ||
}, | ||
exit: function exit(path, _ref3) { | ||
var opts = _ref3.opts, | ||
dependencies = _ref3.dependencies; | ||
exit: function exit(path, state) { | ||
var opts = state.opts, | ||
dependencies = state.dependencies; | ||
// We must traverse the AST again because some plugins emit | ||
// their require() calls after exiting Program node :-( | ||
path.traverse(wrapVisitor, { opts: opts, dependencies: dependencies }); | ||
@@ -50,2 +51,3 @@ | ||
dependencies = Object.keys(dependencies).map(function (dep) { | ||
@@ -61,2 +63,4 @@ return '\'' + dep + '\''; | ||
})]; | ||
_pluginLogger2.default.get(state).info('wrap-modules-amd', 'Detected dependencies:', dependencies.join(', ')); | ||
} | ||
@@ -72,2 +76,6 @@ } | ||
var _pluginLogger = require('liferay-npm-build-tools-common/lib/plugin-logger'); | ||
var _pluginLogger2 = _interopRequireDefault(_pluginLogger); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -74,0 +82,0 @@ |
{ | ||
"name": "babel-plugin-wrap-modules-amd", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "A Babel plugin to wrap package modules inside AMD define() calls.", | ||
@@ -16,4 +16,5 @@ "main": "lib/index.js", | ||
"babel-template": "^6.25.0", | ||
"liferay-npm-build-tools-common": "1.5.0", | ||
"read-json-sync": "^1.1.1" | ||
} | ||
} |
import * as babel from 'babel-core'; | ||
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger'; | ||
import plugin from '../index'; | ||
let logger; | ||
beforeEach(() => { | ||
PluginLogger.set(__filename, (logger = new PluginLogger())); | ||
}); | ||
it('logs results correctly', () => { | ||
const source = ` | ||
console.log('Say something'); | ||
var a = require('a-module'); | ||
var b = require('b-module'); | ||
`; | ||
babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
}); | ||
expect(logger.messages).toMatchSnapshot(); | ||
}); | ||
it('correctly wraps modules', () => { | ||
@@ -14,2 +36,3 @@ const source = ` | ||
const {code} = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
@@ -16,0 +39,0 @@ }); |
import template from 'babel-template'; | ||
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger'; | ||
@@ -43,3 +44,5 @@ const buildDefine = template(` | ||
}, | ||
exit(path, {opts, dependencies}) { | ||
exit(path, state) { | ||
let {opts, dependencies} = state; | ||
// We must traverse the AST again because some plugins emit | ||
@@ -49,4 +52,4 @@ // their require() calls after exiting Program node :-( | ||
const node = path.node; | ||
const body = node.body; | ||
const {node} = path; | ||
const {body} = node; | ||
@@ -69,2 +72,8 @@ dependencies = Object.keys(dependencies).map( | ||
]; | ||
PluginLogger.get(state).info( | ||
'wrap-modules-amd', | ||
'Detected dependencies:', | ||
dependencies.join(', ') | ||
); | ||
}, | ||
@@ -71,0 +80,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14478
189
3
+ Addedliferay-npm-build-tools-common@1.5.0(transitive)