Skip to content

Commit

Permalink
Refactor Overrides infrastructure, add more tests
Browse files Browse the repository at this point in the history
Also fixed a few minor errors in the message (wrong version number etc)

Included a list of hardcoded known dormant addons (polyfills mostly) to make
the suggestions more reliable.
  • Loading branch information
chancancode committed Jun 3, 2021
1 parent fffe619 commit 35689f9
Show file tree
Hide file tree
Showing 13 changed files with 1,527 additions and 597 deletions.
266 changes: 0 additions & 266 deletions lib/global-deprecation-utils.js

This file was deleted.

61 changes: 11 additions & 50 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const buildStripClassCallcheckPlugin = require('./build-strip-class-callcheck-pl
const injectBabelHelpers = require('./transforms/inject-babel-helpers').injectBabelHelpers;
const debugTree = require('broccoli-debug').buildDebugCallback('ember-source:addon');
const vmBabelPlugins = require('@glimmer/vm-babel-plugins');
const globalDeprecationInfo = require('./global-deprecation-utils');
const createFile = require('broccoli-file-creator');
const Overrides = require('./overrides');

const PRE_BUILT_TARGETS = [
'last 1 Chrome versions',
Expand Down Expand Up @@ -67,57 +66,19 @@ module.exports = {
paths,
absolutePaths,
_jqueryIntegrationEnabled: true,
_overrideTree: undefined,

included() {
this._super.included.apply(this, arguments);

let {
hasActionableSuggestions,
globalMessage,
shouldIssueSingleDeprecation,
let overrides = Overrides.for(this.project);

dotAccessOverride,
} = globalDeprecationInfo(this.project);

if (hasActionableSuggestions) {
let shouldIssueSingleDotAccessDeprecation =
hasActionableSuggestions &&
process.env.EMBER_RUNLOOP_AND_COMPUTED_DOT_ACCESS_DEPRECATIONS !== 'all';

this._bootstrapMessageOverrideTree = createFile(
'packages/@ember/-internals/bootstrap/lib/overrides.js',

`export const message = ${JSON.stringify(globalMessage)};
export const deprecateOnce = ${shouldIssueSingleDeprecation};
import { _onDotAccess as runloopDotAccessOverride } from '@ember/runloop';
import { _onDotAccess as objectDotAccessOverride } from '@ember/object';
export function setupDotAccess() {
let disabled = false;
let once = ${shouldIssueSingleDotAccessDeprecation};
function onDotAccess(dotKey, importKey, module) {
if (disabled) {
return null;
} else {
disabled = once;
${dotAccessOverride};
return message;
}
}
runloopDotAccessOverride(onDotAccess);
objectDotAccessOverride(onDotAccess);
}
`
);
if (overrides.hasOverrides) {
this._overrideTree = overrides.toTree();
}

if (hasActionableSuggestions) {
this.ui.writeWarnLine('[DEPRECATION] ' + globalMessage);
if (overrides.hasBuildTimeWarning) {
this.ui.writeWarnLine('[DEPRECATION] ' + overrides.buildTimeWarning);
}

const { has } = require('@ember/edition-utils');
Expand Down Expand Up @@ -260,8 +221,8 @@ module.exports = {
},

buildEmberBundles(tree, isProduction) {
if (this._bootstrapMessageOverrideTree) {
tree = new MergeTrees([tree, this._bootstrapMessageOverrideTree], { overwrite: true });
if (this._overrideTree) {
tree = new MergeTrees([tree, this._overrideTree], { overwrite: true });
}

let packages = this.transpileTree(new Funnel(tree, { srcDir: 'packages' }), isProduction);
Expand Down Expand Up @@ -349,8 +310,8 @@ module.exports = {
targets.length === PRE_BUILT_TARGETS.length &&
// if node is defined in targets we can't reliably use the prebuilt bundles
!targetNode &&
// if we have a custom override for bootstrapping (e.g. for globals deprecations) we can't use the prebuilt bundles
!this._bootstrapMessageOverrideTree
// if we have a custom override (e.g. for globals deprecations) we can't use the prebuilt bundles
!this._overrideTree
) {
ember = new Funnel(tree, {
destDir: 'ember',
Expand Down
Loading

0 comments on commit 35689f9

Please sign in to comment.