ember-cli / ember-cli-deprecation-workflow

MIT License
165 stars 43 forks source link

Is there additional configuration required to get this to work in an addon dummy app and tests? #157

Closed adc-mhaugen closed 1 year ago

adc-mhaugen commented 1 year ago

I'm successfully using this addon in several projects (it's great thanks!) but struggling to get it working in my addons.

Currently on these versions (in a monorepo):

To get the deprecation workflow to work in the projects I have:

  1. Installed the addon
  2. Enabled ember-cli-deprecation-workflow in ember-cli-build.js
  3. Generated config/deprecation-workflow.js

This is my deprecation configuration:

self.deprecationWorkflow = self.deprecationWorkflow || {};
self.deprecationWorkflow.config = {
    throwOnUnhandled: true
};

I've done the same in my addon, and created several deprecations, but I don't see any exceptions thrown in tests or the dummy app. There is only one ember-cli-build.js in the root of the addon, so I've enabled the addon there. I see three different config directories (config, tests/dummy/config, and tests/dummy/app/config) so I've added the deprecation-workflow.js file in all three?

I'm probably doing something wrong, but I don't know what it is. Any advice would be appreciated.

joshuabremerdexcom commented 1 year ago

Ha, we JUST ran into this yesterday and opened a PR into our own repo to fix this.

I moved all the files into the following directory and they worked:

tests/dummy/config/deprecation-workflow.js

adc-mhaugen commented 1 year ago

Thanks @joshuabremerdexcom, so you moved the deprecation-workflow.js and then copied the ember-cli-build.js into the tests/dummy/config folder?

joshuabremerdexcom commented 1 year ago

To be honest, i put it in there and it worked. I didn't touch the ember-cli-build.js. I'll try to be as specific as possible.

Here's my ./ember-cli-build.js:

'use strict';

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function (defaults) {
  let app = new EmberAddon(defaults, {
    // Add options here
    'ember-cli-babel': {
      includePolyfill: true,
    },
  });

  /*
    This build file specifies the options for the dummy test app of this
    addon, located in `/tests/dummy`
    This build file does *not* influence how the addon or the app using it
    behave. You most likely want to be modifying `./index.js` or app's build file
  */

  const { maybeEmbroider } = require('@embroider/test-setup');
  return maybeEmbroider(app, {
    skipBabel: [
      {
        package: 'qunit',
      },
    ],
  });
};

Here's my index.js:

'use strict';

module.exports = {
  name: 'project-name',
  // keeps live reload going
  isDevelopingAddon: function () {
    return true;
  },

  options: {
    autoImport: {
      exclude: [
        /*'lodash-es'*/
      ],
      webpack: {
        resolve: {
          fallback: {
            util: false,
          },
        },
      },
    },
  },
};

Here is a snippet of my package.json:

  "devDependencies": {
    "ember-cli-deprecation-workflow": "^2.1.0",
    }

Here is my tests/dummy/config/deprecation-workflow.jsdeprecation-workflow.js:

/* eslint-disable no-undef */
window.deprecationWorkflow = window.deprecationWorkflow || {};

// silence: Keeps this deprecation from spewing all over the console
// log:     Normal deprecation behavior runs for this deprecation and messages are logged to the console
// throw:   The error is thrown instead of allowing the deprecated behavior to run. WARNING: APPLICATION MAY GO 💥

window.deprecationWorkflow.config = {
  workflow: [
    // Ember 3.x deprecations (breaking changes for Ember 4.x)
    { handler: 'throw', matchId: 'computed-property.override' },
    { handler: 'throw', matchId: 'ember-views.curly-components.jquery-element' },
    { handler: 'throw', matchId: 'this-property-fallback' },
    { handler: 'silence', matchId: 'ember-global' },
  ],
};

The way I populated my deprecation workflow was by running deprecationWorkflow.flushDeprecations() in the console after running all my tests.

adc-mhaugen commented 1 year ago

Thanks for such detailed instructions @joshuabremerdexcom, I'll give it a try.

adc-mhaugen commented 1 year ago

Hmmm, I've tried all these suggestions and every other configuration I can think of, but it doesn't seem to work for me. The good news is that we are finding deprecations in the addons via project code and tests, so I will close this ticket. Thanks all.