Skip to content

Commit

Permalink
feat: support migration path for ember-inflector usage (#9479)
Browse files Browse the repository at this point in the history
* feat: support migration path for ember-inflector usage

* cleanup guidance

* update lock

* fix?

* bump?

* fix prepare

* fix lint
  • Loading branch information
runspired authored Jun 15, 2024
1 parent f91c542 commit e5f6285
Show file tree
Hide file tree
Showing 13 changed files with 498 additions and 250 deletions.
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ resolution-mode=highest
dedupe-direct-deps=true
child-concurrency=10
ignore-dep-scripts=true
dedupe-injected-deps=false
hoist-workspace-packages=false
enable-pre-post-scripts=false
2 changes: 2 additions & 0 deletions packages/-ember-data/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '@ember-data/request-utils/deprecation-support';

import JSONAPICache from '@ember-data/json-api';
import {
adapterFor,
Expand Down
64 changes: 45 additions & 19 deletions packages/build-config/src/deprecation-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
* are compatible with on the `emberData` config in your `ember-cli-build.js` file.
*
* ```js
* let app = new EmberApp(defaults, {
* emberData: {
* compatWith: '3.12',
* },
* });
* const { setConfig } = await import('@warp-drive/build-config');
*
* let app = new EmberApp(defaults, {});
*
* setConfig(app, __dirname, { compatWith: '3.12' });
* ```
*
* Alternatively, individual deprecations can be resolved (and thus have its support stripped)
Expand All @@ -59,14 +59,16 @@
* when removing code for only some deprecations associated to a version number.
*
* ```js
* let app = new EmberApp(defaults, {
* emberData: {
* deprecations: {
* DEPRECATE_FOO_BEHAVIOR: false // set to false to strip this code
* DEPRECATE_BAR_BEHAVIOR: true // force to true to not strip this code
* }
* const { setConfig } = await import('@warp-drive/build-config');
*
* let app = new EmberApp(defaults, {});
*
* setConfig(app, __dirname, {
* deprecations: {
* DEPRECATE_FOO_BEHAVIOR: false // set to false to strip this code
* DEPRECATE_BAR_BEHAVIOR: true // force to true to not strip this code
* }
* })
* });
* ```
*
* The complete list of which versions specific deprecations will be removed in
Expand Down Expand Up @@ -280,14 +282,16 @@ export const DEPRECATE_NON_UNIQUE_PAYLOADS = '5.3';
* to `false` in ember-cli-build.js
*
* ```js
* let app = new EmberApp(defaults, {
* emberData: {
* deprecations: {
* // set to false to strip the deprecated code (thereby opting into the new behavior)
* DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: false
* }
* const { setConfig } = await import('@warp-drive/build-config');
*
* let app = new EmberApp(defaults, {});
*
* setConfig(app, __dirname, {
* deprecations: {
* // set to false to strip the deprecated code (thereby opting into the new behavior)
* DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: false
* }
* })
* });
* ```
*
* To resolve this deprecation on an individual relationship, adjust the `options` passed to
Expand Down Expand Up @@ -422,3 +426,25 @@ export const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT = '5.4';
* @public
*/
export const ENABLE_LEGACY_SCHEMA_SERVICE = '5.4';

/**
* **id: warp-drive.ember-inflector**
*
* Deprecates the use of ember-inflector for pluralization and singularization in favor
* of the `@ember-data/request-utils` package.
*
* This deprecation can be resolved by removing usage of ember-inflector or by using
* both ember-inflector and @ember-data/request-utils in parallel and updating your
* EmberData/WarpDrive build config to mark the deprecation as resolved
* in ember-cli-build
*
* ```js
* setConfig(app, __dirname, { deprecations: { DEPRECATE_EMBER_INFLECTOR: false }});
* ```
*
* @property DEPRECATE_EMBER_INFLECTOR
* @since 5.3
* @until 6.0
* @public
*/
export const DEPRECATE_EMBER_INFLECTOR = '5.3';
1 change: 1 addition & 0 deletions packages/build-config/src/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export const DEPRECATE_RELATIONSHIP_REMOTE_UPDATE_CLEARING_LOCAL_STATE: boolean
export const DEPRECATE_MANY_ARRAY_DUPLICATES: boolean = true;
export const DEPRECATE_STORE_EXTENDS_EMBER_OBJECT: boolean = true;
export const ENABLE_LEGACY_SCHEMA_SERVICE: boolean = true;
export const DEPRECATE_EMBER_INFLECTOR: boolean = true;
14 changes: 13 additions & 1 deletion packages/request-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@
"version": 2
},
"peerDependencies": {
"@warp-drive/core-types": "workspace:0.0.0-alpha.70"
"@ember/string": "3.1.1",
"@warp-drive/core-types": "workspace:0.0.0-alpha.70",
"ember-inflector": "4.0.2"
},
"peerDependenciesMeta": {
"ember-inflector": {
"optional": true
},
"@ember/string": {
"optional": true
}
},
"dependencies": {
"@embroider/macros": "^1.16.1",
Expand All @@ -64,9 +74,11 @@
"@babel/preset-env": "^7.24.5",
"@babel/preset-typescript": "^7.24.1",
"@glimmer/component": "^1.1.2",
"@ember/string": "3.1.1",
"@warp-drive/core-types": "workspace:0.0.0-alpha.70",
"@warp-drive/internal-config": "workspace:5.4.0-alpha.84",
"ember-source": "~5.8.0",
"ember-inflector": "4.0.2",
"pnpm-sync-dependencies-meta-injected": "0.0.14",
"typescript": "^5.4.5",
"vite": "^5.2.11"
Expand Down
107 changes: 107 additions & 0 deletions packages/request-utils/src/deprecation-support.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { deprecate } from '@ember/debug';

import { dependencySatisfies, importSync, macroCondition } from '@embroider/macros';

import { DEPRECATE_EMBER_INFLECTOR } from '@warp-drive/build-config/deprecations';

import { irregular, plural, singular, uncountable } from './string';

if (DEPRECATE_EMBER_INFLECTOR) {
if (macroCondition(dependencySatisfies('ember-inflector', '*'))) {
const Inflector = (importSync('ember-inflector') as { default: typeof import('ember-inflector').default }).default;
const { inflector } = Inflector;

// eslint-disable-next-line @typescript-eslint/unbound-method
const originalPlural = inflector.plural;
// eslint-disable-next-line @typescript-eslint/unbound-method
const originalSingular = inflector.singular;
// eslint-disable-next-line @typescript-eslint/unbound-method
const originalIrregular = inflector.irregular;
// eslint-disable-next-line @typescript-eslint/unbound-method
const originalUncountable = inflector.uncountable;

inflector.plural = function (...args: Parameters<typeof originalPlural>) {
plural(...args);

deprecate(
`WarpDrive/EmberData no longer uses ember-inflector for pluralization.\nPlease \`import { plural } from '@warp-drive/request-utils';\` instead to register a custom pluralization rule for use with EmberData.`,
false,
{
id: 'warp-drive.ember-inflector',
until: '6.0.0',
for: 'warp-drive',
since: {
enabled: '5.3.4',
available: '5.3.4',
},
url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',
}
);

return originalPlural.apply(inflector, args);
};

inflector.singular = function (...args: Parameters<typeof originalSingular>) {
singular(...args);

deprecate(
`WarpDrive/EmberData no longer uses ember-inflector for singularization.\nPlease \`import { singular } from '@warp-drive/request-utils';\` instead to register a custom singularization rule for use with EmberData.`,
false,
{
id: 'warp-drive.ember-inflector',
until: '6.0.0',
for: 'warp-drive',
since: {
enabled: '5.3.4',
available: '5.3.4',
},
url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',
}
);

return originalSingular.apply(inflector, args);
};

inflector.irregular = function (...args: Parameters<typeof originalIrregular>) {
irregular(...args);

deprecate(
`WarpDrive/EmberData no longer uses ember-inflector for irregular rules.\nPlease \`import { irregular } from '@warp-drive/request-utils';\` instead to register a custom irregular rule for use with EmberData.`,
false,
{
id: 'warp-drive.ember-inflector',
until: '6.0.0',
for: 'warp-drive',
since: {
enabled: '5.3.4',
available: '5.3.4',
},
url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',
}
);

return originalIrregular.apply(inflector, args);
};

inflector.uncountable = function (...args: Parameters<typeof originalUncountable>) {
uncountable(...args);

deprecate(
`WarpDrive/EmberData no longer uses ember-inflector for uncountable rules.\nPlease \`import { uncountable } from '@warp-drive/request-utils';\` instead to register a custom uncountable rule for use with EmberData.`,
false,
{
id: 'warp-drive.ember-inflector',
until: '6.0.0',
for: 'warp-drive',
since: {
enabled: '5.3.4',
available: '5.3.4',
},
url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',
}
);

return originalUncountable.apply(inflector, args);
};
}
}
4 changes: 2 additions & 2 deletions packages/request-utils/vite.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createConfig } from '@warp-drive/internal-config/vite/config.js';

export const externals = ['@ember/debug'];
export const entryPoints = ['src/index.ts', 'src/string.ts'];
export const externals = ['@ember/debug', 'ember-inflector'];
export const entryPoints = ['src/index.ts', 'src/string.ts', 'src/deprecation-support.ts'];

export default createConfig(
{
Expand Down
Loading

0 comments on commit e5f6285

Please sign in to comment.