Skip to content

Commit

Permalink
Merge pull request #122 from NullVoxPopuli/make-inert-after-4.4
Browse files Browse the repository at this point in the history
feat: make inert when ember-source supports default helper manager

Closes: #121
  • Loading branch information
NullVoxPopuli authored Apr 14, 2022
2 parents f608409 + 53faa2b commit ee6c9de
Show file tree
Hide file tree
Showing 6 changed files with 1,639 additions and 3,151 deletions.
39 changes: 39 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
'use strict';

const VersionChecker = require('ember-cli-version-checker');

const MINIMUM_VERSION = '4.5.0-alpha.3'

module.exports = {
name: require('./package').name,

_usePolyfill: flag(process.env.USE_DEFAULT_HELPER_MANAGER_POLYFILL),

options: {
'ember-cli-babel': {
enableTypeScriptTransform: true,
},
},

usePolyfill() {
if (this._usePolyfill === undefined) {
let version = new VersionChecker(this.project).for(`ember-source`);
this._usePolyfill = version.lt(MINIMUM_VERSION);
}

return this._usePolyfill;
},

treeForAddon() {
if (this.usePolyfill()) {
return this._super.treeForAddon.apply(this, arguments);
}
},

treeForApp() {
if (this.usePolyfill()) {
return this._super.treeForApp.apply(this, arguments);
}
},
};

const FALSE = ['false', 'disable', 'no', 'off', '0'];

function flag(flag) {
if (flag === undefined) {
return undefined;
} else if (FALSE.includes(flag.toLowerCase())) {
return false;
} else {
return true;
}
}
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
},
"dependencies": {
"ember-cli-babel": "^7.26.11",
"ember-cli-typescript": "^5.0.0"
"ember-cli-typescript": "^5.0.0",
"ember-cli-version-checker": "^5.1.2"
},
"devDependencies": {
"@commitlint/cli": "^16.2.3",
Expand All @@ -44,28 +45,27 @@
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@types/ember-qunit": "^5.0.0",
"@types/ember-resolver": "^5.0.10",
"@types/ember-resolver": "^5.0.11",
"@types/ember__application": "^4.0.0",
"@types/ember__array": "^4.0.1",
"@types/ember__component": "^4.0.4",
"@types/ember__component": "^4.0.8",
"@types/ember__controller": "^4.0.0",
"@types/ember__debug": "^4.0.0",
"@types/ember__debug": "^4.0.1",
"@types/ember__engine": "^4.0.0",
"@types/ember__error": "^4.0.0",
"@types/ember__object": "^4.0.0",
"@types/ember__object": "^4.0.2",
"@types/ember__polyfills": "^4.0.0",
"@types/ember__routing": "^4.0.3",
"@types/ember__runloop": "^4.0.0",
"@types/ember__routing": "^4.0.4",
"@types/ember__runloop": "^4.0.1",
"@types/ember__service": "^4.0.0",
"@types/ember__string": "^3.16.3",
"@types/ember__string": "^3.0.9",
"@types/ember__template": "^4.0.0",
"@types/ember__test": "^4.0.0",
"@types/ember__test-helpers": "^2.6.0",
"@types/ember__test-helpers": "^2.6.1",
"@types/ember__utils": "^4.0.0",
"@types/htmlbars-inline-precompile": "^3.0.0",
"@types/qunit": "^2.11.3",
"@types/rsvp": "^4.0.4",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"babel-eslint": "^10.1.0",
Expand Down Expand Up @@ -102,7 +102,7 @@
"qunit": "^2.18.0",
"qunit-dom": "^2.0.0",
"semantic-release": "^19.0.2",
"typescript": "^4.5.5",
"typescript": "^4.6.3",
"webpack": "^5.68.0"
},
"release": {
Expand Down
3 changes: 2 additions & 1 deletion tests/dummy/app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ declare const config: {
environment: string;
modulePrefix: string;
podModulePrefix: string;
locationType: string;
// Support ember types for v3 and v4
locationType: any;
rootURL: string;
APP: Record<string, unknown>;
};
29 changes: 29 additions & 0 deletions tests/unit/inert-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

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

module('Unit | inert', function (hooks) {
setupTest(hooks);

function hasPolyfill() {
let initializers = ['install-function-helper-manager', 'usable-function-manager'];

return Object.keys(window.requirejs.entries).some(e => initializers.some(name => e.includes(name)))
}

if (macroCondition(dependencySatisfies('ember-source', '^4.5.0-alpha.3 || ^4.5.0'))) {

test('polyfill is inert', function(assert) {
assert.strictEqual(hasPolyfill(), false, 'no polyfill');
});

} else {

test('polyfill is present', function(assert) {
assert.strictEqual(hasPolyfill(), true, 'has polyfill');
});

}

});
9 changes: 0 additions & 9 deletions types/overrides.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import '@ember/component';

/**
* Typed Ember is refraining from adding this because it's not *really* intended for
* mainstream use
*/
declare module '@ember/component' {
// https://github.com/glimmerjs/glimmer-vm/blob/1bc620be641d0748e643ce64592e7442d314e590/packages/%40glimmer/manager/lib/public/template.ts#L9
export function setComponentTemplate(factory: TemplateFactory, obj: object): object;
}

declare module '@ember/modifier' {
export function setModifierManager(manager: unknown, modifier: unknown): void;
export function capabilities(version: string): unknown;
Expand Down
Loading

0 comments on commit ee6c9de

Please sign in to comment.