Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with ember-data@3.27+ #880

Merged
merged 5 commits into from
Jul 30, 2021
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
1 change: 1 addition & 0 deletions packages/compat/src/compat-adapters/@ember-data/adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EmberDataBase as default } from '../ember-data';
13 changes: 1 addition & 12 deletions packages/compat/src/compat-adapters/@ember-data/model.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
import V1Addon from '../../v1-addon';

export default class EmberDataModel extends V1Addon {
get packageMeta() {
const meta = super.packageMeta;
if (!meta['implicit-modules']) {
meta['implicit-modules'] = [];
}
meta['implicit-modules'].push('./-private.js');
return meta;
}
}
export { EmberDataBase as default } from '../ember-data';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EmberDataBase as default } from '../ember-data';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EmberDataBase as default } from '../ember-data';
1 change: 1 addition & 0 deletions packages/compat/src/compat-adapters/@ember-data/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EmberDataBase as default } from '../ember-data';
39 changes: 9 additions & 30 deletions packages/compat/src/compat-adapters/ember-data.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import V1Addon from '../v1-addon';
import { join } from 'path';
import { Memoize } from 'typescript-memoize';
import cloneDeep from 'lodash/cloneDeep';
import { AddonMeta } from '@embroider/core';
import { Node } from 'broccoli-node-api';
import { sync as resolveSync } from 'resolve';

export default class EmberData extends V1Addon {
// ember-data customizes the addon tree, but we don't want to run that one
// because it breaks when we try to eliminate absolute self-imports. We'll
// take the stock behavior instead.
export class EmberDataBase extends V1Addon {
// May of the ember-data packages use rollup to try to hide their internal
// structure. This is fragile and it breaks under embroider, and they should
// really move this kind of "build-within-a-build" to prepublish time.
//
// This disables any custom implementation of `treeForAddon`. The stock
// behavior is correct.
customizes(...names: string[]) {
return super.customizes(...names.filter(n => n !== 'treeForAddon'));
}
}

export default class EmberData extends EmberDataBase {
// ember-data needs its dynamically generated version module.
@Memoize()
get v2Trees() {
Expand Down Expand Up @@ -44,30 +47,6 @@ export default class EmberData extends V1Addon {
trees.push(versionTree());
return trees;
}

// this is enough to make sure we drop the debug code in prod. This only
// matters when the app is running with staticAddonTrees=false, otherwise this
// kind of optimization is automatic.
get packageMeta(): Partial<AddonMeta> {
let meta = super.packageMeta;
if (isProductionEnv() && !isInstrumentedBuild()) {
meta = cloneDeep(meta);
if (meta['implicit-modules']) {
meta['implicit-modules'] = meta['implicit-modules'].filter(name => !name.startsWith('./-debug/'));
}
}
return meta;
}
}

function isProductionEnv() {
let isProd = /production/.test(process.env.EMBER_ENV!);
let isTest = process.env.EMBER_CLI_TEST_COMMAND;
return isProd && !isTest;
}

function isInstrumentedBuild() {
return process.argv.includes('--instrument');
}

function handleErr(err: any) {
Expand Down
5 changes: 5 additions & 0 deletions tests/scenarios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"license": "MIT",
"devDependencies": {
"@ember/string": "^1.0.0",
"@embroider/macros": "0.43.2",
"bootstrap": "^4.3.1",
"broccoli-funnel": "^3.0.5",
Expand All @@ -29,6 +30,10 @@
"ember-cli-3.20": "npm:ember-cli@~3.20.0",
"ember-cli-3.24": "npm:ember-cli@~3.24.0",
"ember-cli-fastboot": "^2.2.3",
"ember-data-3.16": "npm:ember-data@~3.16.0",
"ember-data-3.20": "npm:ember-data@~3.20.0",
"ember-data-3.24": "npm:ember-data@~3.24.0",
"ember-data-latest": "npm:ember-data@latest",
"ember-source-latest": "npm:ember-source@latest",
"ember-source-beta": "npm:ember-source@beta",
"ember-source-3.16": "npm:ember-source@~3.16.0",
Expand Down
13 changes: 13 additions & 0 deletions tests/scenarios/scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,34 @@ import { dirname, delimiter } from 'path';
async function lts_3_16(project: Project) {
project.linkDevDependency('ember-source', { baseDir: __dirname, resolveName: 'ember-source-3.16' });
project.linkDevDependency('ember-cli', { baseDir: __dirname, resolveName: 'ember-cli-3.16' });
project.linkDevDependency('ember-data', { baseDir: __dirname, resolveName: 'ember-data-3.16' });

// needed because the ember-inflector used by this ember-data version blows up without it
project.linkDevDependency('@ember/string', { baseDir: __dirname });
}

async function lts_3_20(project: Project) {
project.linkDevDependency('ember-source', { baseDir: __dirname, resolveName: 'ember-source-3.20' });
project.linkDevDependency('ember-cli', { baseDir: __dirname, resolveName: 'ember-cli-3.20' });
project.linkDevDependency('ember-data', { baseDir: __dirname, resolveName: 'ember-data-3.20' });

// needed because the ember-inflector used by this ember-data version blows up without it
project.linkDevDependency('@ember/string', { baseDir: __dirname });
}

async function lts_3_24(project: Project) {
project.linkDevDependency('ember-source', { baseDir: __dirname, resolveName: 'ember-source-3.24' });
project.linkDevDependency('ember-cli', { baseDir: __dirname, resolveName: 'ember-cli-3.24' });
project.linkDevDependency('ember-data', { baseDir: __dirname, resolveName: 'ember-data-3.24' });

// needed because the ember-inflector used by this ember-data version blows up without it
project.linkDevDependency('@ember/string', { baseDir: __dirname });
}

async function release(project: Project) {
project.linkDevDependency('ember-source', { baseDir: __dirname, resolveName: 'ember-source-latest' });
project.linkDevDependency('ember-cli', { baseDir: __dirname, resolveName: 'ember-cli-latest' });
project.linkDevDependency('ember-data', { baseDir: __dirname, resolveName: 'ember-data-latest' });
}

export function supportMatrix(scenarios: Scenarios) {
Expand Down
Loading