Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve the app's config instead of using ember-get-config #77

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions addon/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import isElementDescriptor from './-private/is-element-descriptor';
import throwConsoleError from './-private/throw-console-error';
import Component from '@glimmer/component';
import PropTypes, { Validator } from 'prop-types';
import config from 'ember-get-config';
import { getOwner } from '@ember/application';
import { isNone } from '@ember/utils';
import { closest } from './-private/closest-string';
import { macroCondition, isDevelopingApp } from '@embroider/macros';

const REGISTERED_ARGS = Symbol('args');
const INTERCEPT_CLASS = 'ForbidExtraArgsIntercept';

function shouldThrowErrors(): boolean {
function shouldThrowErrors(owner: any): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also pass along the actual config instead of the owner, maybe that's less "weird", though that's a bit more work on the invocation side.

const config = owner.resolveRegistration('config:environment');
const throwErrors = config['ember-arg-types']?.throwErrors;
return isNone(throwErrors) ? true : throwErrors;
}
Expand Down Expand Up @@ -41,7 +42,7 @@ function createGetter<T extends Component>(
const returnValue = argValue !== undefined ? argValue : defaultInitializer.call(this);

if (macroCondition(isDevelopingApp())) {
const shouldThrow = shouldThrowErrors();
const shouldThrow = shouldThrowErrors(getOwner(this));
if (validator) {
throwConsoleError(() => {
PropTypes.checkPropTypes({ [key]: validator }, { [key]: returnValue }, 'prop', getClassName(this));
Expand Down Expand Up @@ -75,7 +76,7 @@ export function forbidExtraArgs(target: any) {
returnClass = class ForbidExtraArgsIntercept extends target {
declare [REGISTERED_ARGS]?: Set<string>;

constructor(_owner: unknown, args: Record<string, unknown>) {
constructor(owner: unknown, args: Record<string, unknown>) {
// eslint-disable-next-line prefer-rest-params
super(...arguments);
const component = getClassName(this);
Expand All @@ -90,7 +91,7 @@ export function forbidExtraArgs(target: any) {

const msg = `Failed extra args check: Invalid argument \`@${unRegisteredArg}\` ${suggestion}supplied to \`${component}\`, expected [${expected}]`;

const shouldThrow = shouldThrowErrors();
const shouldThrow = shouldThrowErrors(owner);
if (shouldThrow) {
throw new Error(msg);
} else {
Expand Down
43 changes: 1 addition & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ember-cli-babel": "^7.26.6",
"ember-cli-htmlbars": "^5.7.1",
"ember-cli-typescript": "^4.0.0",
"ember-get-config": "^0.2.4 || ^0.3.0",
"prop-types": "^15.7.2"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/components/args-decorator-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
//@ts-ignore
import { click, render, resetOnerror, setupOnerror, settled } from '@ember/test-helpers';
import config from 'ember-get-config';

module('Integration | Decorator | arg', function (hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -83,6 +82,8 @@ module('Integration | Decorator | arg', function (hooks) {
test('type check errors can be disabled', async function (assert) {
assert.expect(1);

const config = this.owner.resolveRegistration('config:environment');

config['ember-arg-types']!.throwErrors = false;

await render(hbs` <Character @name={{true}}/>`);
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/components/forbid-extra-args-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
//@ts-ignore
import { render, resetOnerror, setupOnerror } from '@ember/test-helpers';
import config from 'ember-get-config';

function forbidArgMessage(arg: string, component: string, expected: string[], guessedArg?: string) {
const expectedArgs = expected.map((arg) => `'${arg}'`).join(',');
Expand Down Expand Up @@ -57,6 +56,8 @@ module('Integration | Decorator | forbidExtraArgs', function (hooks) {
test('extra arg errors can be disabled', async function (assert) {
assert.expect(1);

const config = this.owner.resolveRegistration('config:environment');

config['ember-arg-types']!.throwErrors = false;

await render(hbs`<ExtendedCharacter @name="valid" @fakeArg={{true}}/>`);
Expand Down
11 changes: 0 additions & 11 deletions types/ember-get-config/index.d.ts

This file was deleted.