diff --git a/packages/private-build-infra/src/transforms/babel-plugin-convert-existence-checks-to-macros/index.js b/packages/private-build-infra/src/transforms/babel-plugin-convert-existence-checks-to-macros/index.js index cfad6bf073c..4a678c55956 100644 --- a/packages/private-build-infra/src/transforms/babel-plugin-convert-existence-checks-to-macros/index.js +++ b/packages/private-build-infra/src/transforms/babel-plugin-convert-existence-checks-to-macros/index.js @@ -1,5 +1,12 @@ const { ImportUtil } = require('babel-import-util'); +function parentIsUnary(node) { + if (node.parent.type === 'UnaryExpression' && node.parent.operator === '!') { + return true; + } + return false; +} + module.exports = function (babel) { const { types: t } = babel; @@ -18,12 +25,22 @@ module.exports = function (babel) { let localBindingName = specifier.node.local.name; let binding = specifier.scope.getBinding(localBindingName); binding.referencePaths.forEach((p) => { - p.replaceWith( - // t.callExpression(state.importer.import(p, '@embroider/macros', 'macroCondition'), [ - t.callExpression(state.importer.import(p, '@embroider/macros', 'moduleExists'), [ - t.stringLiteral(replacements[name]), + let negateStatement = false; + let node = p; + if (parentIsUnary(p)) { + negateStatement = true; + node = p.parentPath; + } + + const exp = t.callExpression(state.importer.import(p, '@embroider/macros', 'dependencySatisfies'), [ + t.stringLiteral(replacements[name]), + t.stringLiteral('*'), + ]); + + node.replaceWith( + t.callExpression(state.importer.import(p, '@embroider/macros', 'macroCondition'), [ + negateStatement ? t.unaryExpression('!', exp) : exp, ]) - // ]) ); }); specifier.scope.removeOwnBinding(localBindingName); diff --git a/packages/private-build-infra/src/transforms/babel-plugin-transform-has-debug-package/index.js b/packages/private-build-infra/src/transforms/babel-plugin-transform-has-debug-package/index.js index 3b30068e84a..4abd10eb752 100644 --- a/packages/private-build-infra/src/transforms/babel-plugin-transform-has-debug-package/index.js +++ b/packages/private-build-infra/src/transforms/babel-plugin-transform-has-debug-package/index.js @@ -41,9 +41,9 @@ module.exports = function (babel) { // if (LOG_FOO) // => // if (macroCondition(getOwnConfig().debug.LOG_FOO)) - //t.callExpression(state.importer.import(p, '@embroider/macros', 'macroCondition'), [ - negateStatement ? t.unaryExpression('!', getConfig) : getConfig - //]) + t.callExpression(state.importer.import(p, '@embroider/macros', 'macroCondition'), [ + negateStatement ? t.unaryExpression('!', getConfig) : getConfig, + ]) ); }); specifier.scope.removeOwnBinding(localBindingName); diff --git a/packages/store/addon/-private/legacy-model-support/schema-definition-service.ts b/packages/store/addon/-private/legacy-model-support/schema-definition-service.ts index 9478dd06314..b8f0fab8564 100644 --- a/packages/store/addon/-private/legacy-model-support/schema-definition-service.ts +++ b/packages/store/addon/-private/legacy-model-support/schema-definition-service.ts @@ -122,9 +122,11 @@ export function getModelFactory(store: Store, cache, normalizedModelName: string let owner: any = getOwner(store); factory = owner.factoryFor(`model:${normalizedModelName}`); - if (!factory && HAS_MODEL_PACKAGE) { - //Support looking up mixins as base types for polymorphic relationships - factory = _modelForMixin(store, normalizedModelName); + if (HAS_MODEL_PACKAGE) { + if (!factory) { + //Support looking up mixins as base types for polymorphic relationships + factory = _modelForMixin(store, normalizedModelName); + } } if (!factory) { diff --git a/packages/store/addon/-private/network/fetch-manager.ts b/packages/store/addon/-private/network/fetch-manager.ts index aa9af2bf52f..cda841ffa13 100644 --- a/packages/store/addon/-private/network/fetch-manager.ts +++ b/packages/store/addon/-private/network/fetch-manager.ts @@ -217,14 +217,16 @@ export default class FetchManager { const recordData = store._instanceCache.peek({ identifier, bucket: 'recordData' }); if (!recordData || recordData.isEmpty(identifier) || isLoading) { let isReleasable = true; - if (!recordData && HAS_RECORD_DATA_PACKAGE) { - const graphFor = ( - importSync('@ember-data/record-data/-private') as typeof import('@ember-data/record-data/-private') - ).graphFor; - const graph = graphFor(store); - isReleasable = graph.isReleasable(identifier); - if (!isReleasable) { - graph.unload(identifier, true); + if (HAS_RECORD_DATA_PACKAGE) { + if (!recordData) { + const graphFor = ( + importSync('@ember-data/record-data/-private') as typeof import('@ember-data/record-data/-private') + ).graphFor; + const graph = graphFor(store); + isReleasable = graph.isReleasable(identifier); + if (!isReleasable) { + graph.unload(identifier, true); + } } } if (recordData || isReleasable) { diff --git a/packages/store/addon/-private/store-service.ts b/packages/store/addon/-private/store-service.ts index bdd68fe05b5..453c4de19c6 100644 --- a/packages/store/addon/-private/store-service.ts +++ b/packages/store/addon/-private/store-service.ts @@ -392,10 +392,12 @@ class Store extends Service { * @public */ getSchemaDefinitionService(): SchemaDefinitionService { - if (HAS_MODEL_PACKAGE && !this._schemaDefinitionService) { - // it is potentially a mistake for the RFC to have not enabled chaining these services, though highlander rule is nice. - // what ember-m3 did via private API to allow both worlds to interop would be much much harder using this. - this._schemaDefinitionService = new DSModelSchemaDefinitionService(this); + if (HAS_MODEL_PACKAGE) { + if (!this._schemaDefinitionService) { + // it is potentially a mistake for the RFC to have not enabled chaining these services, though highlander rule is nice. + // what ember-m3 did via private API to allow both worlds to interop would be much much harder using this. + this._schemaDefinitionService = new DSModelSchemaDefinitionService(this); + } } assert( `You must registerSchemaDefinitionService with the store to use custom model classes`, @@ -2692,13 +2694,10 @@ export function assertIdentifierHasId( } function isDSModel(record: RecordInstance | null): record is DSModel { - return ( - HAS_MODEL_PACKAGE && - !!record && - 'constructor' in record && - 'isModel' in record.constructor && - record.constructor.isModel === true - ); + if (!HAS_MODEL_PACKAGE) { + return false; + } + return !!record && 'constructor' in record && 'isModel' in record.constructor && record.constructor.isModel === true; } type AdapterErrors = Error & { errors?: unknown[]; isAdapterError?: true; code?: string }; diff --git a/tests/embroider-basic-compat/app/models/user.ts b/tests/embroider-basic-compat/app/models/user.ts new file mode 100644 index 00000000000..33d0be8ad43 --- /dev/null +++ b/tests/embroider-basic-compat/app/models/user.ts @@ -0,0 +1,5 @@ +import Model, { attr } from '@ember-data/model'; + +export default class User extends Model { + @attr declare name: string; +} diff --git a/tests/embroider-basic-compat/ember-cli-build.js b/tests/embroider-basic-compat/ember-cli-build.js index 9b3fd539c72..b8c2a8e1c01 100644 --- a/tests/embroider-basic-compat/ember-cli-build.js +++ b/tests/embroider-basic-compat/ember-cli-build.js @@ -32,5 +32,28 @@ module.exports = function (defaults) { package: 'qunit', }, ], + compatAdapters: new Map([ + ['@ember-data/store', null], + ['@ember-data/record-data', null], + ['@ember-data/serializer', null], + ['@ember-data/adapter', null], + ['@ember-data/model', null], + ['@ember-data/debug', null], + ['@ember-data/tracking', null], + ['@ember-data/request', null], + ['@ember-data/private-build-infra', null], + ['@ember-data/canary-features', null], + ['ember-data', null], + ]), + packageRules: [ + { + package: '@ember-data/store', + addonModules: { + '-private.js': { + dependsOnModules: ['@ember-data/json-api/-private'], + }, + }, + }, + ], }); }; diff --git a/tests/embroider-basic-compat/tests/acceptance/visit-test.js b/tests/embroider-basic-compat/tests/acceptance/visit-test.js index 7cfc80cef80..f09ab7273ed 100644 --- a/tests/embroider-basic-compat/tests/acceptance/visit-test.js +++ b/tests/embroider-basic-compat/tests/acceptance/visit-test.js @@ -11,4 +11,13 @@ module('it works', function (hooks) { await visit('/'); assert.ok('it works!'); }); + + test('we can use the store', async function (assert) { + const { owner } = this; + const store = owner.lookup('service:store'); + + const record = store.createRecord('user', { name: 'Chris' }); + + assert.strictEqual(record.name, 'Chris', 'correct name'); + }); });