Skip to content

Commit

Permalink
Merge pull request #325 from runspired/fix-polyfill-again
Browse files Browse the repository at this point in the history
Ensure `ember-data` modules polyfill does not apply to any `@ember-data` packages.
  • Loading branch information
rwjblue authored Feb 6, 2020
2 parents 83971b2 + 5591a9f commit 459a460
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ module.exports = {
let addonOptions = config['ember-cli-babel'] || {};

if (addonOptions.disableEmberDataPackagesPolyfill) { return; }
// Don't convert ember-data itself!
if (this.parent.name === 'ember-data') { return; }
// Don't convert ember-data itself or any @ember-data packages!
if (typeof this.parent.name === 'string' && (this.parent.name === 'ember-data' || this.parent.name.startsWith('@ember-data/'))) { return; }

if (this._emberDataVersionRequiresPackagesPolyfill()) {
return [[require.resolve('babel-plugin-ember-data-packages-polyfill')]];
Expand Down
56 changes: 29 additions & 27 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1572,9 +1572,9 @@ describe('EmberData Packages Polyfill - ember-cli-babel for ember-data', functio

beforeEach(function() {
let self = this;
setupForVersion = co.wrap(function*(v) {
setupForVersion = co.wrap(function*(p, v) {
let fixturifyProject = new FixturifyProject('whatever', '0.0.1');
let emberDataFixture = fixturifyProject.addDependency('ember-data', v, addon => {
let emberDataFixture = fixturifyProject.addDependency(p, v, addon => {
return prepareAddon(addon);
});
emberDataFixture.addDependency('ember-cli-babel', 'babel/ember-cli-babel#master');
Expand All @@ -1584,7 +1584,7 @@ describe('EmberData Packages Polyfill - ember-cli-babel for ember-data', functio
let pkg = JSON.parse(fixturifyProject.toJSON('package.json'));
fixturifyProject.writeSync();

let linkPath = path.join(fixturifyProject.root, '/whatever/node_modules/ember-data/node_modules/ember-cli-babel');
let linkPath = path.join(fixturifyProject.root, `/whatever/node_modules/${p}/node_modules/ember-cli-babel`);
let addonPath = path.resolve(__dirname, '../');
rimraf.sync(linkPath);
fs.symlinkSync(addonPath, linkPath);
Expand All @@ -1597,7 +1597,7 @@ describe('EmberData Packages Polyfill - ember-cli-babel for ember-data', functio
project = new EmberProject(root, pkg, cli.ui, cli);
project.initializeAddons();

self.emberDataAddon = project.addons.find(a => { return a.name === 'ember-data'; });
self.emberDataAddon = project.addons.find(a => { return a.name === p; });
self.emberDataAddon.initializeAddons();
self.addon = self.emberDataAddon.addons.find(a => { return a.name === 'ember-cli-babel'; });

Expand All @@ -1613,34 +1613,36 @@ describe('EmberData Packages Polyfill - ember-cli-babel for ember-data', functio
yield terminateWorkerPool();
}));

it("does not convert when compiling ember-data itself", co.wrap(function*() {
yield setupForVersion('3.10.0');
['ember-data', '@ember-data/store'].forEach(parentDep => {
it(`does not convert when compiling ${parentDep} itself`, co.wrap(function*() {
yield setupForVersion(parentDep, '3.10.0');

input.write({
"foo.js": `export { default } from '@ember-data/store';`,
"bar.js": `import Model, { attr } from '@ember-data/model';\nexport var User = Model;\nexport var name = attr;`,
"bem.js": `export { AdapterError } from 'ember-data/-private';`,
});
input.write({
"foo.js": `export { default } from '@ember-data/store';`,
"bar.js": `import Model, { attr } from '@ember-data/model';\nexport var User = Model;\nexport var name = attr;`,
"bem.js": `export { AdapterError } from 'ember-data/-private';`,
});

subject = this.addon.transpileTree(input.path(), {
'ember-cli-babel': {
compileModules: false,
disableDebugTooling: true,
}
});
subject = this.addon.transpileTree(input.path(), {
'ember-cli-babel': {
compileModules: false,
disableDebugTooling: true,
}
});

output = createBuilder(subject);
output = createBuilder(subject);

yield output.build();
yield output.build();

expect(
output.read()
).to.deep.equal({
"foo.js": `export { default } from '@ember-data/store';`,
"bar.js": `import Model, { attr } from '@ember-data/model';\nexport var User = Model;\nexport var name = attr;`,
"bem.js": `export { AdapterError } from 'ember-data/-private';`,
});
}));
expect(
output.read()
).to.deep.equal({
"foo.js": `export { default } from '@ember-data/store';`,
"bar.js": `import Model, { attr } from '@ember-data/model';\nexport var User = Model;\nexport var name = attr;`,
"bem.js": `export { AdapterError } from 'ember-data/-private';`,
});
}));
});
});

function leftPad(str, num) {
Expand Down

0 comments on commit 459a460

Please sign in to comment.