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

chore: eliminate dead build code #8829

Merged
merged 1 commit into from
Sep 4, 2023
Merged
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
21 changes: 1 addition & 20 deletions packages/-ember-data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,9 @@ const version = require('@ember-data/private-build-infra/src/create-version-modu
const addonBaseConfig = addonBuildConfigForDataPackage(require('./package.json'));

module.exports = Object.assign({}, addonBaseConfig, {
shouldRollupPrivate: false,
externalDependenciesForPrivateModule() {
return [
'ember',
'@ember/application/namespace',
'@ember-data/json-api',
'ember-data/version',
'@ember-data/store/-private',
'@ember-data/store',
'@ember-data/model',
'@ember-data/model/-private',
'@ember/array/proxy',
'@ember/object/promise-proxy-mixin',
'@ember/object/proxy',
'@ember-data/tracking',
];
},
treeForAddon(tree) {
// if we don't do this we won't have a super in addonBaseConfig
// as a regex is used to decide if to add one for the method
this._originalSuper = this._super;
tree = merge([tree, version()]);
return addonBaseConfig.treeForAddon.call(this, tree);
return this._super.treeForAddon.call(this, tree);
},
});
5 changes: 1 addition & 4 deletions packages/debug/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ const addonBuildConfigForDataPackage = require('@ember-data/private-build-infra/
const addonBaseConfig = addonBuildConfigForDataPackage(require('./package.json'));

module.exports = Object.assign({}, addonBaseConfig, {
shouldRollupPrivate: false,
__isEnabled: null,
externalDependenciesForPrivateModule() {
return [];
},

treeFor() {
// Nested addons don't call isEnabled automatically,
// So this ensures that we return empty trees whenever
Expand Down
2 changes: 0 additions & 2 deletions packages/private-build-infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"babel6-plugin-strip-class-callcheck": "^6.0.0",
"broccoli-debug": "^0.6.5",
"broccoli-file-creator": "^2.1.1",
"broccoli-funnel": "^3.0.8",
"broccoli-merge-trees": "^4.2.0",
"broccoli-rollup": "^5.0.0",
"calculate-cache-key-for-tree": "^2.0.0",
"chalk": "^4.1.2",
"ember-cli-babel": "^8.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
const calculateCacheKeyForTree = require('calculate-cache-key-for-tree');
const Funnel = require('broccoli-funnel');
const merge = require('broccoli-merge-trees');
const BroccoliDebug = require('broccoli-debug');
const VersionChecker = require('ember-cli-version-checker');

const rollupPrivateModule = require('./utilities/rollup-private-module');
const detectModule = require('./utilities/detect-module');

function isProductionEnv() {
let isProd = /production/.test(process.env.EMBER_ENV);
let isTest = process.env.EMBER_CLI_TEST_COMMAND;

return isProd && !isTest;
}

function addonBuildConfigForDataPackage(pkg) {
return {
name: pkg.name,
Expand All @@ -26,7 +15,6 @@ function addonBuildConfigForDataPackage(pkg) {
// ' for ' +
// (typeof this.parent.name === 'function' ? this.parent.name() : this.parent.name)
// );
this._prodLikeWarning();
this.debugTree = BroccoliDebug.buildDebugCallback(`ember-data:${pkg.name}`);
this.options = this.options || {};
Object.assign(this.options, {
Expand Down Expand Up @@ -54,69 +42,15 @@ function addonBuildConfigForDataPackage(pkg) {
});
},

_prodLikeWarning() {
let emberEnv = process.env.EMBER_ENV;
if (emberEnv !== 'production' && /production/.test(emberEnv)) {
this._warn(
`Production-like values for EMBER_ENV are deprecated (your EMBER_ENV is "${emberEnv}") and support will be removed in Ember Data 4.0.0. If using ember-cli-deploy, please configure your build using 'production'. Otherwise please set your EMBER_ENV to 'production' for production builds.`
);
}
},

isDevelopingAddon() {
if (typeof this.parent.name === 'string' && this.parent.name === 'ember-data') {
return this.parent.isDevelopingAddon();
}
return this._super(...arguments);
},

_warn(message) {
let chalk = require('chalk');
let warning = chalk.yellow('WARNING: ' + message);

if (this.ui && this.ui.writeWarnLine) {
this.ui.writeWarnLine(message);
} else if (this.ui) {
this.ui.writeLine(warning);
} else {
// eslint-disable-next-line no-console
console.log(warning);
}
},

_suppressUneededRollupWarnings(message, next) {
if (message.code === 'CIRCULAR_DEPENDENCY') {
return;
} else if (message.code === 'NON_EXISTENT_EXPORT') {
// ignore type imports
if (message.message.indexOf(`@ember-data/types`) !== -1) {
return;
}
} else if (message.code === 'UNRESOLVED_IMPORT') {
if (!this.isDevelopingAddon()) {
// don't print these for consumers
return;
} else {
const chalk = require('chalk');
// make warning actionable
// eslint-disable-next-line no-console
console.log(
chalk.yellow(
`\n\n⚠️ Add ${chalk.white(
message.source
)} to the array returned by externalDependenciesForPrivateModule in index.js of ${chalk.white(
this.name
)}\n\n`
)
);
throw message.message;
}
}
next(message);
},

shouldIncludeChildAddon(addon) {
if (addon.name.startsWith('@ember-data')) {
if (addon.name.startsWith('@ember-data/')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note this is not the broccoli node issue (see the @) but since it could manifest in a similar incorrect check should someone choose a github/npm org starting with @ember-data* we add the /

if (this.name === 'ember-data' || addon.name === '@ember-data/tracking') {
return true;
}
Expand All @@ -126,16 +60,6 @@ function addonBuildConfigForDataPackage(pkg) {
return true;
},

getOutputDirForVersion() {
let VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let emberCli = checker.for('ember-cli', 'npm');

let requiresModulesDir = emberCli.satisfies('< 3.0.0');

return requiresModulesDir ? 'modules' : '';
},

buildBabelOptions() {
let babelOptions = this.options.babel || {};
let existingPlugins = babelOptions.plugins || [];
Expand Down Expand Up @@ -183,69 +107,6 @@ function addonBuildConfigForDataPackage(pkg) {
return calculateCacheKeyForTree(treeType, this);
},

externalDependenciesForPrivateModule() {
return [];
},

treeForAddon(tree) {
if (process.env.EMBER_DATA_ROLLUP_PRIVATE === 'false' || this.shouldRollupPrivate !== true) {
return this._super.treeForAddon.call(this, tree);
}

tree = this.debugTree(tree, 'input');
this._setupBabelOptions();

let babel = this.addons.find((addon) => addon.name === 'ember-cli-babel');
let externalDeps = this.externalDependenciesForPrivateModule();

const host = this._findHost();

// don't print this for consumers
if (this.isDevelopingAddon()) {
// eslint-disable-next-line no-console
console.log(
`Rolling up ${this.name} private modules with the following external dependencies: ['${externalDeps.join(
"', '"
)}']`
);
}
let checker = new VersionChecker(this.project);
let emberVersion = checker.for('ember-source');
let analyzer = this.registry.load('js').find((plugin) => plugin.name === 'ember-auto-import-analyzer');

let privateTree = rollupPrivateModule(tree, {
packageName: pkg.name,
babelCompiler: babel,
babelOptions: this.options.babel,
emberVersion: emberVersion,
emberCliBabelOptions: host.options && host.options['ember-cli-babel'] ? host.options['ember-cli-babel'] : {},
onWarn: this._suppressUneededRollupWarnings.bind(this),
externalDependencies: this.externalDependenciesForPrivateModule(),
destDir: this.getOutputDirForVersion(),
analyzer,
});

let withoutPrivate = new Funnel(tree, {
exclude: ['-private', isProductionEnv() ? '-debug' : false].filter(Boolean),

destDir: pkg.name,
});

// use the default options
let publicTree = babel.transpileTree(this.debugTree(withoutPrivate, 'babel-public:input'));
publicTree = this.debugTree(publicTree, 'babel-public:output');

if (analyzer) {
publicTree = analyzer.toTree.call(analyzer, publicTree, undefined, undefined, { treeType: 'addon' });
}

let destDir = this.getOutputDirForVersion();

publicTree = new Funnel(publicTree, { destDir });

return this.debugTree(merge([publicTree, privateTree]), 'final');
},

_emberDataConfig: null,
getEmberDataConfig() {
if (this._emberDataConfig) {
Expand Down

This file was deleted.

6 changes: 0 additions & 6 deletions pnpm-lock.yaml

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

Loading