Skip to content

Commit

Permalink
fix: add deprecation and avoid breaking configs (#9477)
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired authored Jun 14, 2024
1 parent d550310 commit 5dd9e37
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
15 changes: 15 additions & 0 deletions packages/-ember-data/addon-main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,19 @@ if (pkg['ember-addon'].version === 1) {
delete addon.treeForApp;
}

const included = addon.included;
addon.included = function includedIntercept() {
// we access this as a side-effect to ember-cli will give us a super call
const sup = this._super.included;
if (this.hasBeenCalled) {
return included?.apply(this, arguments);
}
this.hasBeenCalled = true;
const app = this.app;
const dirname = app.project.root;
const { setConfig } = require('@warp-drive/build-config/cjs-set-config.cjs');
setConfig(app, dirname, Object.assign({}, app.options?.emberData, { ___legacy_support: true }));
return included?.apply(this, arguments);
};

module.exports = addon;
1 change: 1 addition & 0 deletions packages/build-config/src/cjs-set-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { setConfig } from './index.ts';
27 changes: 26 additions & 1 deletion packages/build-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,36 @@ function recastMacrosConfig(macros: object): MacrosWithGlobalConfig {

export function setConfig(context: object, appRoot: string, config: WarpDriveConfig) {
const macros = recastMacrosConfig(_MacrosConfig.for(context, appRoot));
const isLegacySupport = (config as unknown as { ___legacy_support?: boolean }).___legacy_support;
const hasDeprecatedConfig = isLegacySupport && Object.keys(config).length > 1;
const hasInitiatedConfig = macros.globalConfig['WarpDrive'];

if (macros.globalConfig['WarpDrive']) {
// setConfig called by user prior to legacy support called
if (isLegacySupport && hasInitiatedConfig) {
if (hasDeprecatedConfig) {
throw new Error(
'You have provided a config object to setConfig, but are also using the legacy emberData options key in ember-cli-build. Please remove the emberData key from options.'
);
}
return;
}

// legacy support called prior to user setConfig
if (isLegacySupport && hasDeprecatedConfig) {
console.warn(
`You are using the legacy emberData key in your ember-cli-build.js file. This key is deprecated and will be removed in the next major version of EmberData/WarpDrive. Please use \`import { setConfig } from '@warp-drive/build-config';\` instead.`
);
}

// included hooks run during class initialization of the EmberApp instance
// so our hook will run before the user has a chance to call setConfig
// else we could print a useful message here
// else if (isLegacySupport) {
// console.warn(
// `WarpDrive requires your ember-cli-build file to set a base configuration for the project.\n\nUsage:\n\t\`import { setConfig } from '@warp-drive/build-config';\n\tsetConfig(app, __dirname, {});\``
// );
// }

const debugOptions: InternalWarpDriveConfig['debug'] = Object.assign({}, LOGGING, config.debug);

const env = getEnv();
Expand Down
3 changes: 2 additions & 1 deletion packages/build-config/vite.config-cjs.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { createConfig } from '@warp-drive/internal-config/vite/config.js';

export const externals = ['babel-import-util', 'fs'];
export const externals = ['babel-import-util', 'fs', 'path'];

export const entryPoints = [
'./cjs-src/transforms/babel-plugin-transform-asserts.js',
'./cjs-src/transforms/babel-plugin-transform-deprecations.js',
'./cjs-src/transforms/babel-plugin-transform-features.js',
'./cjs-src/transforms/babel-plugin-transform-logging.js',
'./cjs-src/addon-shim.js',
'./src/cjs-set-config.ts',
];

export default createConfig(
Expand Down

0 comments on commit 5dd9e37

Please sign in to comment.