Skip to content

Commit

Permalink
Run the old preprocessor hack for older versions of embroider
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed May 14, 2023
1 parent 5443885 commit 8c2e737
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
42 changes: 24 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const Funnel = require('broccoli-funnel');
const chalk = require('chalk');
const BroccoliDebug = require('broccoli-debug');
const VersionChecker = require('ember-cli-version-checker');
const camelCase = require('camelcase');
const { createHash } = require('crypto');
const _ = require('lodash');
Expand Down Expand Up @@ -186,36 +187,41 @@ module.exports = {
return tree;
},

checkIfWillProbablyUseEmbroider() {
const pkg = this.project.pkg;
doesNeedEmbroiderHack() {
const checker = new VersionChecker(this.project);
const embroider = checker.for('@embroider/core');
const embroiderTest = checker.for('@embroider/test-setup');

// Extra check for “classic” builds that need to run plugins on `self`. We
// need to know this before `init` and `included` are run, which is
// unfortunate.
if (
pkg &&
pkg.devDependencies &&
'@embroider/core' in pkg.devDependencies
embroider.lt('1.9.0') ||
(embroiderTest.lt('1.9.0') && isForcedEmbroider())
) {
return true;
}

if (isForcedEmbroider()) {
return true;
}

return false;
},

setupPreprocessorRegistry(type, registry) {
// The canvas plugin should run on `self` and `parent`.
this._setupCanvasPlugin(registry);
if (this.doesNeedEmbroiderHack()) {
// `type === 'self'` is broken in older Embroider versions. It doesn’t seem
// to correctly pass the plugins to `broccoli-babel-transpiler`. This works
// for some reason.
if (type === 'parent') {
this._setupCanvasPlugin(registry);
this._setupAddonPlugin(registry);
this._setupTreeshakerPlugin(registry);
}
} else {
// The canvas plugin should run on `self` and `parent`.
this._setupCanvasPlugin(registry);

if (type === 'self') {
// The addon plugin should run on `self`.
this._setupAddonPlugin(registry);
if (type === 'self') {
// The addon plugin should run on `self`.
this._setupAddonPlugin(registry);

this._setupTreeshakerPlugin(registry);
this._setupTreeshakerPlugin(registry);
}
}
},

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"ember-auto-import": "^2.6.3",
"ember-cli-babel": "^7.26.11",
"ember-cli-htmlbars": "^6.2.0",
"ember-cli-version-checker": "^5.1.2",
"ember-concurrency": "^3.0.0",
"ember-modifier": "^3.2.7",
"lodash": "^4.17.21",
Expand Down

0 comments on commit 8c2e737

Please sign in to comment.