Skip to content
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
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,10 @@ If your build is failing on the 'production' suite, you may be relying on a debu

There are helpers for many of these functions, which will resolve this for you: `expectDeprecation`, `expectAssertion`, etc. Please use these helpers when dealing with these functions.

If your tests can't or aren't covered by a helper, one common solution is the use of `DEBUG` flag. Wrapping the debug-only dependent test in a check of this flag will cause that test to not be run in the prod test suite:
If your tests can't or aren't covered by a helper, one common solution is the use of `import.meta.env?.DEV` flag. Wrapping the debug-only dependent test in a check of this flag will cause that test to not be run in the prod test suite:

```javascript
import { DEBUG } from '@glimmer/env';

if (DEBUG) {
if (import.meta.env?.DEV ?? true) {
// Development-only test goes here
}
```
Expand Down
4 changes: 1 addition & 3 deletions babel.test.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import baseConfig from './babel.config.mjs';

// eslint-disable-next-line no-redeclare
const require = createRequire(import.meta.url);
const buildDebugMacroPlugin = require('./broccoli/build-debug-macro-plugin.js');
const isProduction = process.env.EMBER_ENV === 'production';

export default {
...baseConfig,
Expand All @@ -27,5 +25,5 @@ export default {
],
],

plugins: [...baseConfig.plugins, buildDebugMacroPlugin(!isProduction)],
plugins: [...baseConfig.plugins],
};
16 changes: 0 additions & 16 deletions broccoli/build-debug-macro-plugin.js

This file was deleted.

25 changes: 25 additions & 0 deletions broccoli/import-meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function hasDEV(code) {
return code.includes('import.meta.env?.DEV') || code.includes('import.meta.env.DEV');
}
export function importMetaRemoval(debugMacrosMode) {
return {
name: 'define custom import.meta.env',
async transform(code) {
if (debugMacrosMode === true) {
if (hasDEV(code)) {
return code.replace(/import.meta.env\??.DEV/g, 'true');
}

return;
}

if (debugMacrosMode === false) {
if (hasDEV(code)) {
return code.replace(/import.meta.env\??.DEV/g, 'false');
}
}

return undefined;
},
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,4 @@
}
},
"packageManager": "pnpm@10.5.0"
}
}
14 changes: 7 additions & 7 deletions packages/@ember/-internals/container/lib/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
import { setOwner } from '@ember/-internals/owner';
import { dictionary } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { DebugRegistry } from './registry';
import type Registry from './registry';

Expand All @@ -24,7 +24,7 @@ declare const gc: undefined | (() => void);

let leakTracking: LeakTracking;
let containers: WeakSet<Container>;
if (DEBUG) {
if (import.meta.env?.DEV) {
// requires v8
// chrome --js-flags="--allow-natives-syntax --expose-gc"
// node --allow-natives-syntax --expose-gc
Expand Down Expand Up @@ -92,7 +92,7 @@ export default class Container {
this.isDestroyed = false;
this.isDestroying = false;

if (DEBUG) {
if (import.meta.env?.DEV) {
this.validationCache = dictionary(options.validationCache || null);
if (containers !== undefined) {
containers.add(this);
Expand Down Expand Up @@ -232,7 +232,7 @@ export default class Container {
}
}

if (DEBUG) {
if (import.meta.env?.DEV) {
Container._leakTracking = leakTracking!;
}

Expand Down Expand Up @@ -312,13 +312,13 @@ function factoryFor(
return;
}

if (DEBUG && factory && typeof factory._onLookup === 'function') {
if (import.meta.env?.DEV && factory && typeof factory._onLookup === 'function') {
factory._onLookup(fullName);
}

let manager = new InternalFactoryManager(container, factory, fullName, normalizedName);

if (DEBUG) {
if (import.meta.env?.DEV) {
manager = wrapManagerInDeprecationProxy(manager);
}

Expand Down Expand Up @@ -541,7 +541,7 @@ export class InternalFactoryManager<
setOwner(props, container.owner!);
setFactoryFor(props, this);

if (DEBUG) {
if (import.meta.env?.DEV) {
let lazyInjections;
let validationCache = this.container.validationCache;
// Ensure that all lazy injections are valid at instantiation time
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/container/lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import { dictionary, intern } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import type { set } from '@ember/object';
import { DEBUG } from '@glimmer/env';

import type { ContainerOptions, LazyInjection } from './container';
import Container from './container';

Expand Down Expand Up @@ -468,7 +468,7 @@ export declare class DebugRegistry extends Registry {
validateInjections(injections: Injection[]): void;
}

if (DEBUG) {
if (import.meta.env?.DEV) {
const proto = Registry.prototype as DebugRegistry;
proto.normalizeInjectionsHash = function (hash: { [key: string]: LazyInjection }) {
let injections: Injection[] = [];
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/container/tests/container_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getOwner } from '@ember/-internals/owner';
import Service from '@ember/service';
import { DEBUG } from '@glimmer/env';

import { Registry } from '..';
import { factory, moduleFor, AbstractTestCase, runTask } from 'internal-test-helpers';

Expand Down Expand Up @@ -447,7 +447,7 @@ moduleFor(
}

['@test Lazy injection validations are cached'](assert) {
if (!DEBUG) {
if (!import.meta.env?.DEV) {
assert.expect(0);
return;
}
Expand Down
5 changes: 2 additions & 3 deletions packages/@ember/-internals/environment/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DEBUG } from '@glimmer/env';
import global from './global';

/**
Expand Down Expand Up @@ -91,7 +90,7 @@ export const ENV = {
@default false
@private
*/
_DEBUG_RENDER_TREE: DEBUG,
_DEBUG_RENDER_TREE: import.meta.env?.DEV,

/**
Whether to force all deprecations to be enabled. This is used internally by
Expand Down Expand Up @@ -200,7 +199,7 @@ export const ENV = {
}
}

if (DEBUG) {
if (import.meta.env?.DEV) {
ENV._DEBUG_RENDER_TREE = true;
}
})(global.EmberENV);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { addChildView, setElementView, setViewElement } from '@ember/-internals/
import type { Nullable } from '@ember/-internals/utility-types';
import { assert, debugFreeze } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
import { DEBUG } from '@glimmer/env';

import type {
Bounds,
CapturedArguments,
Expand Down Expand Up @@ -337,7 +337,7 @@ export default class CurlyComponentManager
bucket.classRef = args.named.get('class');
}

if (DEBUG) {
if (import.meta.env?.DEV) {
processComponentInitializationAssertions(component, props);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getFactoryFor } from '@ember/-internals/container';
import { assert } from '@ember/debug';
import { _instrumentStart } from '@ember/instrumentation';
import { DEBUG } from '@glimmer/env';

import type {
ComponentDefinition,
Environment,
Expand Down Expand Up @@ -57,7 +57,7 @@ class RootComponentManager extends CurlyComponentManager {
}
}

if (DEBUG) {
if (import.meta.env?.DEV) {
processComponentInitializationAssertions(component, {});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
WithCustomDebugRenderTree,
} from '@glimmer/interfaces';
import type { Nullable } from '@ember/-internals/utility-types';
import { DEBUG } from '@glimmer/env';

import { capabilityFlagsFrom } from '@glimmer/manager';
import type { Reference } from '@glimmer/reference';
import { createDebugAliasRef, valueForRef } from '@glimmer/reference';
Expand Down Expand Up @@ -61,7 +61,7 @@ class RouteTemplateManager
): RouteTemplateInstanceState {
let self = args.named.get('controller');

if (DEBUG) {
if (import.meta.env?.DEV) {
self = createDebugAliasRef!('this', self);
}

Expand Down
9 changes: 7 additions & 2 deletions packages/@ember/-internals/glimmer/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '@ember/-internals/views';
import { guidFor } from '@ember/-internals/utils';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { Environment, Template, TemplateFactory } from '@glimmer/interfaces';
import { setInternalComponentManager } from '@glimmer/manager';
import { isUpdatableRef, updateRef } from '@glimmer/reference';
Expand Down Expand Up @@ -939,7 +939,12 @@ class Component<S = unknown>
}
}

if (DEBUG && eventDispatcher && this.renderer._isInteractive && this.tagName === '') {
if (
import.meta.env?.DEV &&
eventDispatcher &&
this.renderer._isInteractive &&
this.tagName === ''
) {
let eventNames = [];
let events = eventDispatcher.finalEventNameMapping;

Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/components/link-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type EngineInstance from '@ember/engine/instance';
import { flaggedInstrument } from '@ember/instrumentation';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { DEBUG } from '@glimmer/env';

import type { Maybe } from '@glimmer/interfaces';
import type { Nullable } from '@ember/-internals/utility-types';
import { consumeTag, createCache, getValue, tagFor, untrack } from '@glimmer/validator';
Expand Down Expand Up @@ -344,7 +344,7 @@ class _LinkTo extends InternalComponent {
// TODO: can we narrow this down to QP changes only?
consumeTag(tagFor(routing, 'currentState'));

if (DEBUG) {
if (import.meta.env?.DEV) {
try {
return routing.generateURL(route, models, query);
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions packages/@ember/-internals/glimmer/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { constructStyleDeprecationMessage } from '@ember/-internals/views';
import { assert, deprecate, warn } from '@ember/debug';
import type { DeprecationOptions } from '@ember/debug';
import { schedule, _backburner } from '@ember/runloop';
import { DEBUG } from '@glimmer/env';

import setGlobalContext from '@glimmer/global-context';
import type { EnvironmentDelegate } from '@glimmer/runtime';
import { debug } from '@glimmer/validator';
Expand Down Expand Up @@ -57,7 +57,7 @@ setGlobalContext({
},

assert(test: unknown, msg: string, options?: { id: string }) {
if (DEBUG) {
if (import.meta.env?.DEV) {
let id = options?.id;

let override = VM_ASSERTION_OVERRIDES.filter((o) => o.id === id)[0];
Expand All @@ -67,7 +67,7 @@ setGlobalContext({
},

deprecate(msg: string, test: unknown, options: { id: string }) {
if (DEBUG) {
if (import.meta.env?.DEV) {
let { id } = options;

if (id === 'argument-less-helper-paren-less-invocation') {
Expand All @@ -91,7 +91,7 @@ setGlobalContext({
},
});

if (DEBUG) {
if (import.meta.env?.DEV) {
debug?.setTrackingTransactionEnv?.({
debugMessage(obj, keyName) {
let dirtyString = keyName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { CapturedArguments, Helper } from '@glimmer/interfaces';
import { createComputeRef, valueForRef } from '@glimmer/reference';
import { internalHelper } from './internal-helper';

let helper: Helper;

if (DEBUG) {
if (import.meta.env?.DEV) {
helper = (args: CapturedArguments) => {
const inner = args.positional[0];
assert('expected at least one positional arg', inner);
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/helpers/-resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import type { FullName, InternalOwner } from '@ember/-internals/owner';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';

import type { CapturedArguments } from '@glimmer/interfaces';
import { createConstRef, isConstRef, valueForRef } from '@glimmer/reference';
import { internalHelper } from './internal-helper';
Expand All @@ -30,7 +30,7 @@ export default internalHelper(
((s: string): s is FullName => s.split(':').length === 2)(fullName)
);

if (DEBUG) {
if (import.meta.env?.DEV) {
let [type, name] = fullName.split(':');

assert(
Expand Down
4 changes: 2 additions & 2 deletions packages/@ember/-internals/glimmer/lib/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isDestroying,
registerDestructor,
} from '@glimmer/destroyable';
import { DEBUG } from '@glimmer/env';

import type {
Bounds,
Cursor,
Expand Down Expand Up @@ -108,7 +108,7 @@ const NO_OP = () => {};
// during render. This prevents infinite revalidation type loops from occuring,
// and ensures that errors are not swallowed by subsequent follow on failures.
function errorLoopTransaction(fn: () => void) {
if (DEBUG) {
if (import.meta.env?.DEV) {
return () => {
let didError = true;

Expand Down
Loading
Loading