Skip to content

Commit

Permalink
feat: @ember-data/store as v2-lite addon (#8285)
Browse files Browse the repository at this point in the history
* feat: @ember-data/store as v2-lite addon

* fix config

* fix build path

* fix lint and docs

* fix configs

* cleanup

* fix lint

* fix deps

* make some small size optimizations
  • Loading branch information
runspired authored Dec 8, 2022
1 parent 69a3265 commit fd6d097
Show file tree
Hide file tree
Showing 61 changed files with 417 additions and 196 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**/tmp/
/packages/tracking/addon/
/packages/request/addon/
/packages/store/addon/
/packages/-ember-data/docs/
/packages/tracking/addon/

Expand Down
39 changes: 20 additions & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ module.exports = {
'@types/@ember/runloop/-private/backburner.d.ts',
'@types/@ember/object/compat.d.ts',
'@types/@ember/debug/index.d.ts',
'packages/store/addon/index.ts',
'packages/store/addon/-private/utils/promise-record.ts',
'packages/store/addon/-private/utils/is-non-empty-string.ts',
'packages/store/addon/-private/utils/construct-resource.ts',
'packages/store/src/index.ts',
'packages/store/src/-private/utils/promise-record.ts',
'packages/store/src/-private/utils/is-non-empty-string.ts',
'packages/store/src/-private/utils/construct-resource.ts',
'ember-data-types/q/utils.ts',
'ember-data-types/q/schema-definition-service.ts',
'ember-data-types/q/record-instance.ts',
Expand All @@ -187,21 +187,21 @@ module.exports = {
'ember-data-types/q/fetch-manager.ts',
'ember-data-types/q/ember-data-json-api.ts',
'ember-data-types/q/ds-model.ts',
'packages/store/addon/-private/managers/record-data-store-wrapper.ts',
'packages/store/addon/-private/network/snapshot.ts',
'packages/store/addon/-private/network/snapshot-record-array.ts',
'packages/store/addon/-private/legacy-model-support/schema-definition-service.ts',
'packages/store/addon/-private/network/request-cache.ts',
'packages/store/addon/-private/legacy-model-support/record-reference.ts',
'packages/store/addon/-private/managers/record-notification-manager.ts',
'packages/store/addon/-private/caches/record-data-for.ts',
'packages/store/addon/-private/utils/normalize-model-name.ts',
'packages/store/addon/-private/legacy-model-support/shim-model-class.ts',
'packages/store/addon/-private/network/fetch-manager.ts',
'packages/store/addon/-private/store-service.ts',
'packages/store/addon/-private/utils/coerce-id.ts',
'packages/store/addon/-private/index.ts',
'packages/store/addon/-private/caches/identifier-cache.ts',
'packages/store/src/-private/managers/record-data-store-wrapper.ts',
'packages/store/src/-private/network/snapshot.ts',
'packages/store/src/-private/network/snapshot-record-array.ts',
'packages/store/src/-private/legacy-model-support/schema-definition-service.ts',
'packages/store/src/-private/network/request-cache.ts',
'packages/store/src/-private/legacy-model-support/record-reference.ts',
'packages/store/src/-private/managers/record-notification-manager.ts',
'packages/store/src/-private/caches/record-data-for.ts',
'packages/store/src/-private/utils/normalize-model-name.ts',
'packages/store/src/-private/legacy-model-support/shim-model-class.ts',
'packages/store/src/-private/network/fetch-manager.ts',
'packages/store/src/-private/store-service.ts',
'packages/store/src/-private/utils/coerce-id.ts',
'packages/store/src/-private/index.ts',
'packages/store/src/-private/caches/identifier-cache.ts',
'packages/serializer/addon/index.ts',
'@types/@ember/runloop/index.d.ts',
'@types/@ember/polyfills/index.d.ts',
Expand Down Expand Up @@ -296,6 +296,7 @@ module.exports = {
'packages/private-build-infra/src/**/*.js',
'packages/unpublished-test-infra/src/**/*.js',
'packages/unpublished-eslint-rules/src/**/*.js',
'packages/*/babel.config.js',
'packages/*/.ember-cli.js',
'packages/*/.eslintrc.js',
'packages/*/.template-lintrc.js',
Expand Down
5 changes: 0 additions & 5 deletions .github/actions/prepare-build/action copy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ runs:
restore-keys: |
master
- if: ${{ inputs.build-addons }}
name: Exec Library Prepackage Steps
run: pnpm build-v2-addons

- if: ${{ inputs.restore-lint-caches }}
name: Restore Lint Caches
uses: actions/cache@v3
Expand All @@ -121,4 +117,3 @@ runs:
key: ${{ github.ref }}
restore-keys: |
master
5 changes: 0 additions & 5 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ runs:
broccoli-master
broccoli-
- name: Exec Library Prepackage Steps
if: ${{ inputs.build-addons == 'true' }}
shell: bash
run: pnpm build-v2-addons && pnpm install

- name: Restore Lint Caches
if: ${{ inputs.restore-lint-caches == 'true' }}
uses: actions/cache@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/asset-size-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install dependencies for master
run: pnpm install
- name: Build V2 Addons
run: pnpm run --if-present build-v2-addons && pnpm install
run: pnpm install
- name: Build Production master
run: pnpm --filter "full-data-asset-size-app" exec ember build -e production --output-path dists/control
- name: Checkout ${{github.ref}}
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Install dependencies for ${{github.ref}}
run: pnpm install
- name: Build V2 Addons
run: pnpm run --if-present build-v2-addons && pnpm install
run: pnpm install
- name: Build Production ${{github.ref}}
run: pnpm --filter "full-data-asset-size-app" exec ember build -e production --output-path dists/experiment
- name: Analyze Master Assets
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/compat-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Install dependencies w/o lockfile
run: pnpm install --no-lockfile
- name: Build V2 Addons
run: pnpm build-v2-addons && pnpm install
run: pnpm install
- name: Basic Tests
run: pnpm test
node-version-test:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
cache: 'pnpm'
- name: Install dependencies for master
run: pnpm install
- name: Build V2 Addons
run: pnpm build-v2-addons
- name: Basic Tests
env:
CI: true
Expand All @@ -44,8 +42,6 @@ jobs:
cache: 'pnpm'
- name: Install dependencies for ${{ matrix.scenario }}
run: pnpm install
- name: Build V2 Addons
run: pnpm build-v2-addons
- name: Basic Tests
env:
CI: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/perf-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
cache: 'pnpm'
- uses: tracerbench/tracerbench-compare-action@master
with:
experiment-build-command: npm run --if-present build-v2-addons && pnpm install && pnpm --filter performance-test-app exec ember build -e production --output-path dist-experiment
experiment-build-command: pnpm install && pnpm --filter performance-test-app exec ember build -e production --output-path dist-experiment
experiment-serve-command: pnpm --filter performance-test-app exec ember s --path dist-experiment --port 4201
control-build-command: npm run --if-present build-v2-addons && pnpm install && pnpm --filter performance-test-app exec ember build -e production --output-path dist-control
control-build-command: pnpm install && pnpm --filter performance-test-app exec ember build -e production --output-path dist-control
control-serve-command: pnpm --filter performance-test-app exec ember s --path dist-control
sample-timeout: 60
use-pnpm: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/perf-over-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
cache: 'pnpm'
- uses: tracerbench/tracerbench-compare-action@master
with:
experiment-build-command: npm run --if-present build-v2-addons && pnpm install && pnpm --filter performance-test-app exec ember build -e production --output-path dist-experiment
experiment-build-command: pnpm install && pnpm --filter performance-test-app exec ember build -e production --output-path dist-experiment
experiment-serve-command: pnpm --filter performance-test-app exec ember s --path dist-experiment --port 4201
control-build-command: npm run --if-present build-v2-addons && pnpm install && pnpm --filter performance-test-app exec ember build -e production --output-path dist-control
control-build-command: pnpm install && pnpm --filter performance-test-app exec ember build -e production --output-path dist-control
control-serve-command: pnpm --filter performance-test-app exec ember s --path dist-control
sample-timeout: 60
use-pnpm: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dist
tmp
packages/tracking/addon
packages/request/addon
packages/store/addon

# dependencies
bower_components
Expand Down
2 changes: 1 addition & 1 deletion docs-generator/yuidoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"../packages/adapter/addon",
"../packages/model/addon",
"../packages/serializer/addon",
"../packages/store/addon",
"../packages/store/src",
"../packages/record-data/addon",
"../packages/debug/addon",
"../packages/private-build-infra/addon",
Expand Down
2 changes: 1 addition & 1 deletion ember-data-types/q/identifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {
DEBUG_CLIENT_ORIGINATED,
DEBUG_IDENTIFIER_BUCKET,
} from '@ember-data/store/-private/utils/identifer-debug-consts';
} from '@ember-data/store/-private/utils/identifier-debug-consts';

import type { ExistingResourceObject, ResourceIdentifierObject } from './ember-data-json-api';

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"url": "git+ssh://git@github.com:emberjs/data.git"
},
"scripts": {
"build-v2-addons": "pnpm --filter @ember-data/tracking --filter @ember-data/request build",
"build:docs": "mkdir -p packages/-ember-data/dist && cd ./docs-generator && node ./compile-docs.js",
"lint:js": "eslint --cache --ext=js,ts .",
"preinstall": "npx only-allow pnpm",
Expand Down Expand Up @@ -168,4 +167,4 @@
"@embroider/macros@1.9.0": "patches/@embroider__macros@1.9.0.patch"
}
}
}
}
35 changes: 35 additions & 0 deletions packages/private-build-infra/src/v2-babel-build-pack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const pkg = require('../package.json');

// eslint-disable-next-line import/order
const requireModule = require('./utilities/require-module');

const debugFlags = requireModule('@ember-data/private-build-infra/addon/debugging.ts');
const deprecationFlags = requireModule('@ember-data/private-build-infra/addon/current-deprecations.ts');
const featureFlags = requireModule('@ember-data/canary-features/addon/default-features.ts');

const isCanary = pkg.version.includes('alpha');

const features = {};
Object.keys(featureFlags).forEach((flag) => {
if (isCanary) {
features[flag] = featureFlags[flag];
} else {
const value = featureFlags[flag];

if (value === null) {
features[flag] = false;
} else {
features[flag] = value;
}
}
});

const config = {
debug: Object.assign({}, debugFlags.default),
deprecations: Object.assign({}, deprecationFlags.default),
features,
};

const plugins = require('./debug-macros')(config);

module.exports = plugins;
6 changes: 3 additions & 3 deletions packages/request/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"plugins": [
"@babel/plugin-transform-runtime",
["@babel/plugin-transform-runtime", { "loose": true }],
["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-class-properties"
["@babel/plugin-proposal-decorators", { "legacy": true, "loose": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
}
5 changes: 3 additions & 2 deletions packages/request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"scripts": {
"build": "rollup --config && babel ./addon --out-dir addon --plugins=../private-build-infra/src/transforms/babel-plugin-transform-ext.js",
"start": "rollup --config --watch",
"prepack": "pnpm build"
"prepack": "pnpm build",
"prepare": "pnpm build"
},
"ember-addon": {
"main": "addon-main.js",
Expand Down Expand Up @@ -61,4 +62,4 @@
"ember": {
"edition": "octane"
}
}
}
10 changes: 5 additions & 5 deletions packages/request/src/-private/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export class ContextOwner {
hasSubscribers = false;
stream: Deferred<ReadableStream | null> = createDeferred<ReadableStream | null>();
response: ResponseInfo | null = null;
request: ImmutableRequestInfo;
enhancedRequest: ImmutableRequestInfo;
declare request: ImmutableRequestInfo;
declare enhancedRequest: ImmutableRequestInfo;
nextCalled: number = 0;
god: GodContext;
controller: AbortController;
declare god: GodContext;
declare controller: AbortController;

constructor(request: RequestInfo, god: GodContext) {
this.controller = request.controller || god.controller;
Expand Down Expand Up @@ -126,7 +126,7 @@ export class ContextOwner {

export class Context {
#owner: ContextOwner;
request: ImmutableRequestInfo;
declare request: ImmutableRequestInfo;

constructor(owner: ContextOwner) {
this.#owner = owner;
Expand Down
90 changes: 90 additions & 0 deletions packages/store/addon-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const pkg = require('./package.json');

module.exports = {
name: pkg.name,

options: {
'@embroider/macros': {
setOwnConfig: {},
},
},

_emberDataConfig: null,
configureEmberData() {
if (this._emberDataConfig) {
return this._emberDataConfig;
}
const app = this._findHost();
const isProd = /production/.test(process.env.EMBER_ENV);
const hostOptions = app.options?.emberData || {};
const debugOptions = Object.assign(
{
LOG_PAYLOADS: false,
LOG_OPERATIONS: false,
LOG_MUTATIONS: false,
LOG_NOTIFICATIONS: false,
LOG_REQUEST_STATUS: false,
LOG_IDENTIFIERS: false,
LOG_GRAPH: false,
LOG_INSTANCE_CACHE: false,
},
hostOptions.debug || {}
);
let HAS_DEBUG_PACKAGE, HAS_META_PACKAGE;

try {
// eslint-disable-next-line node/no-missing-require
require.resolve('@ember-data/debug', { paths: [process.cwd(), __dirname] });
HAS_DEBUG_PACKAGE = true;
} catch {
HAS_DEBUG_PACKAGE = false;
}
try {
// eslint-disable-next-line node/no-missing-require
require.resolve('ember-data', { paths: [process.cwd(), __dirname] });
HAS_META_PACKAGE = true;
} catch {
HAS_META_PACKAGE = false;
}
const includeDataAdapterInProduction =
typeof hostOptions.includeDataAdapterInProduction === 'boolean'
? hostOptions.includeDataAdapterInProduction
: HAS_META_PACKAGE;

const includeDataAdapter = HAS_DEBUG_PACKAGE ? (isProd ? includeDataAdapterInProduction : true) : false;
const DEPRECATIONS = require('@ember-data/private-build-infra/src/deprecations')(hostOptions.compatWith || null);
const FEATURES = require('@ember-data/private-build-infra/src/features')(isProd);

// copy configs forward
const ownConfig = this.options['@embroider/macros'].setOwnConfig;
ownConfig.compatWith = hostOptions.compatWith || null;
ownConfig.debug = debugOptions;
ownConfig.deprecations = Object.assign(DEPRECATIONS, ownConfig.deprecations || {});
ownConfig.features = Object.assign({}, FEATURES);
ownConfig.includeDataAdapter = includeDataAdapter;

this._emberDataConfig = ownConfig;
return ownConfig;
},

included() {
this.configureEmberData();
return this._super.included.call(this, ...arguments);
},

treeForVendor() {
return;
},
treeForPublic() {
return;
},
treeForStyles() {
return;
},
treeForAddonStyles() {
return;
},
treeForApp() {
return;
},
};
Loading

0 comments on commit fd6d097

Please sign in to comment.