Skip to content

Commit

Permalink
Only blacklist jQuery module when parent depends on @ember/jquery itself
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Jan 28, 2019
1 parent 3130c24 commit 6a40015
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 13 deletions.
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ module.exports = {
];
}

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

Expand All @@ -444,11 +444,15 @@ module.exports = {
return checker.exists();
},

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

if (!('@ember/jquery' in this.parent.dependencies())) {
return false;
}

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

return checker.gte('0.6.0');
Expand Down
104 changes: 93 additions & 11 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('ember-cli-babel', function() {
let project = {
root: __dirname,
emberCLIVersion: () => '2.16.2',
dependencies() { return {}; },
addons: []
};

Expand Down Expand Up @@ -293,6 +294,7 @@ describe('ember-cli-babel', function() {
let project = {
root: input.path(),
emberCLIVersion: () => '2.16.2',
dependencies() { return {}; },
addons: []
};

Expand Down Expand Up @@ -362,10 +364,26 @@ describe('ember-cli-babel', function() {
});

describe('@ember/jquery detection', function() {
function buildEmberJQueryFixture() {
return {
node_modules: {
'@ember': {
'jquery': {
'package.json': JSON.stringify({ name: '@ember/jquery', version: '0.6.0' }),
'index.js': 'module.exports = {};',
},
},
}
};
}

let dependencies;
beforeEach(function() {
dependencies = {};
let project = {
root: input.path(),
emberCLIVersion: () => '2.16.2',
dependencies() { return dependencies; },
addons: []
};

Expand All @@ -378,16 +396,9 @@ describe('ember-cli-babel', function() {
project.addons.push(this.addon);
});

it('does not transpile the jquery imports when addon is present', co.wrap(function* () {
it('does not transpile the jquery imports when addon is present in parent', co.wrap(function* () {
input.write(buildEmberJQueryFixture());
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';
Expand All @@ -396,6 +407,8 @@ describe('ember-cli-babel', function() {
},
});

dependencies['@ember/jquery'] = '0.6.0';

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

Expand Down Expand Up @@ -432,6 +445,64 @@ describe('ember-cli-babel', function() {
});
}));

it('transpiles the jquery imports when addon is not a dependency of the parent', co.wrap(function* () {
let project = {
root: input.path(),
emberCLIVersion: () => '2.16.2',
dependencies() { return dependencies; },
addons: [
]
};
let projectsBabel = new Addon({
project,
parent: project,
ui: this.ui,
});
project.addons.push(projectsBabel);

let parentAddon = {
root: input.path('node_modules/awesome-thang'),
dependencies() { return dependencies; },
project,
addons: []
};
project.addons.push(parentAddon);

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

input.write({
node_modules: {
'awesome-thang': {
addon: {
"foo.js": stripIndent`
import $ from 'jquery';
$('.foo').click();
`,
},
'package.json': JSON.stringify({ name: 'awesome-thang', private: true }),
'index.js': '',
}
}
});

input.write(buildEmberJQueryFixture());

subject = this.addon.transpileTree(input.path('node_modules/awesome-thang/addon'));
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});`
});
}));
});


Expand Down Expand Up @@ -622,6 +693,7 @@ describe('ember-cli-babel', function() {
describe('_shouldCompileModules()', function() {
beforeEach(function() {
this.addon.parent = {
dependencies() { return {}; },
options: {}
};
});
Expand Down Expand Up @@ -673,6 +745,7 @@ describe('ember-cli-babel', function() {
describe('with ember-cli-babel.compileModules = false', function() {
beforeEach(function() {
this.addon.parent = {
dependencies() { return {}; },
options: {
'ember-cli-babel': { compileModules: false }
}
Expand All @@ -699,6 +772,7 @@ describe('ember-cli-babel', function() {
it('does not mutate addonOptions.babel', function() {
let babelOptions = { blah: true };
this.addon.parent = {
dependencies() { return {}; },
options: {
babel: babelOptions,
},
Expand All @@ -722,15 +796,17 @@ describe('ember-cli-babel', function() {

it('provides an annotation including parent name - addon', function() {
this.addon.parent = {
name: 'derpy-herpy'
name: 'derpy-herpy',
dependencies() { return {}; },
};
let result = this.addon.buildBabelOptions();
expect(result.annotation).to.include('derpy-herpy');
});

it('provides an annotation including parent name - project', function() {
this.addon.parent = {
name() { return 'derpy-herpy'; }
name() { return 'derpy-herpy'; },
dependencies() { return {}; },
};
let result = this.addon.buildBabelOptions();
expect(result.annotation).to.include('derpy-herpy');
Expand Down Expand Up @@ -779,6 +855,7 @@ describe('ember-cli-babel', function() {
it('does not include all provided options', function() {
let babelOptions = { blah: true };
this.addon.parent = {
dependencies() { return {}; },
options: {
babel: babelOptions,
},
Expand All @@ -791,6 +868,7 @@ describe('ember-cli-babel', function() {
it('includes user plugins in parent.options.babel.plugins', function() {
let plugin = {};
this.addon.parent = {
dependencies() { return {}; },
options: {
babel: {
plugins: [ plugin ]
Expand All @@ -806,6 +884,7 @@ describe('ember-cli-babel', function() {
let plugin = {};
let pluginAfter = {};
this.addon.parent = {
dependencies() { return {}; },
options: {
babel: {
plugins: [ plugin ],
Expand All @@ -828,6 +907,7 @@ describe('ember-cli-babel', function() {
}
};
this.addon.parent = {
dependencies() { return {}; },
options: {
babel6: {
plugins: [ {} ]
Expand All @@ -842,6 +922,7 @@ describe('ember-cli-babel', function() {
it('user plugins are before preset-env plugins', function() {
let plugin = function Plugin() {};
this.addon.parent = {
dependencies() { return {}; },
options: {
babel: {
plugins: [ plugin ]
Expand Down Expand Up @@ -898,6 +979,7 @@ describe('ember-cli-babel', function() {
it('passes options.babel through to preset-env', function() {
let babelOptions = { loose: true };
this.addon.parent = {
dependencies() { return {}; },
options: {
babel: babelOptions,
},
Expand Down

0 comments on commit 6a40015

Please sign in to comment.