Skip to content

Commit

Permalink
Merge pull request #261 from simonihmig/blacklist-jquery
Browse files Browse the repository at this point in the history
Blacklist jquery if @ember/jquery is present
  • Loading branch information
rwjblue authored Jan 22, 2019
2 parents e31c79e + 5213b29 commit 3c67b5d
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ module.exports = {
];
}

if (this._emberJqueryDependencyPresent()) {
blacklist['jquery'] = ['default'];
}

return blacklist;
},

Expand All @@ -440,6 +444,16 @@ module.exports = {
return checker.exists();
},

_emberJqueryDependencyPresent() {
if (this.project.name && this.project.name() === '@ember/jquery') {
return true;
}

let checker = new VersionChecker(this.parent).for('@ember/jquery', 'npm');

return checker.gte('0.6.0');
},

// detect if running babel would do nothing... and do nothing instead
_shouldDoNothing(options) {
return !options.sourceMaps && !options.plugins.length;
Expand Down
74 changes: 74 additions & 0 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,80 @@ describe('ember-cli-babel', function() {

});

describe('@ember/jquery detection', function() {
beforeEach(function() {
let project = {
root: input.path(),
emberCLIVersion: () => '2.16.2',
addons: []
};

this.addon = new Addon({
project,
parent: project,
ui: this.ui,
});

project.addons.push(this.addon);
});

it('does not transpile the jquery imports when addon is present', co.wrap(function* () {
input.write({
node_modules: {
'@ember': {
'jquery': {
'package.json': JSON.stringify({ name: '@ember/jquery', version: '0.6.0' }),
'index.js': 'module.exports = {};',
},
},
},
app: {
"foo.js": stripIndent`
import $ from 'jquery';
$('.foo').click();
`,
},
});

subject = this.addon.transpileTree(input.path('app'));
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `define("foo", ["jquery"], function (_jquery) {\n "use strict";\n\n (0, _jquery.default)('.foo').click();\n});`
});
}));

it('transpiles the jquery imports when addon is missing', co.wrap(function* () {
input.write({
node_modules: {
},
app: {
"foo.js": stripIndent`
import $ from 'jquery';
$('.foo').click();
`,
},
});

subject = this.addon.transpileTree(input.path('app'));
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `define("foo", [], function () {\n "use strict";\n\n Ember.$('.foo').click();\n});`
});
}));

});


describe('_shouldDoNothing', function() {
it("will no-op if nothing to do", co.wrap(function* () {
input.write({
Expand Down

0 comments on commit 3c67b5d

Please sign in to comment.