From faffa2421d4f354a5cd375b53d675b3bb4c805ad Mon Sep 17 00:00:00 2001 From: Sam Van Campenhout Date: Mon, 3 Mar 2025 10:42:44 +0100 Subject: [PATCH] Cleanup octane edition code Octane has been the default for multiple major versions, so we can remove and simplify the code. --- blueprints/component-class/index.js | 45 +-------------- blueprints/component/index.js | 56 +++---------------- lib/index.js | 39 ------------- .../blueprints/component-class-addon-test.js | 3 - node-tests/blueprints/component-class-test.js | 16 +----- node-tests/blueprints/component-test.js | 16 +----- node-tests/blueprints/controller-test.js | 13 +---- node-tests/blueprints/route-test.js | 12 +--- node-tests/blueprints/service-test.js | 15 +---- node-tests/helpers/setup-test-environment.js | 15 ----- 10 files changed, 22 insertions(+), 208 deletions(-) delete mode 100644 node-tests/helpers/setup-test-environment.js diff --git a/blueprints/component-class/index.js b/blueprints/component-class/index.js index 08690b9cef9..5b63f270fb3 100644 --- a/blueprints/component-class/index.js +++ b/blueprints/component-class/index.js @@ -1,21 +1,12 @@ 'use strict'; -const SilentError = require('silent-error'); const stringUtil = require('ember-cli-string-utils'); const getPathOption = require('ember-cli-get-component-path-option'); const normalizeEntityName = require('ember-cli-normalize-entity-name'); -const { has } = require('@ember/edition-utils'); const { generateComponentSignature } = require('../-utils'); const typescriptBlueprintPolyfill = require('ember-cli-typescript-blueprint-polyfill'); -const OCTANE = has('octane'); - -// TODO: this should be reading from the @ember/canary-features module -// need to refactor broccoli/features.js to be able to work more similarly -// to https://github.com/emberjs/data/pull/6231 -const EMBER_GLIMMER_SET_COMPONENT_TEMPLATE = true; - // intentionally avoiding use-edition-detector module.exports = { description: 'Generates a component class.', @@ -32,7 +23,7 @@ module.exports = { { name: 'component-class', type: ['@ember/component', '@glimmer/component', '@ember/component/template-only'], - default: OCTANE ? '@glimmer/component' : '@ember/component', + default: '@glimmer/component', aliases: [ { cc: '@ember/component' }, { gc: '@glimmer/component' }, @@ -50,34 +41,6 @@ module.exports = { init() { this._super && this._super.init.apply(this, arguments); typescriptBlueprintPolyfill(this); - - let isOctane = has('octane'); - - this.availableOptions.forEach((option) => { - if (option.name === 'component-class') { - if (isOctane) { - option.default = '@glimmer/component'; - } else { - option.default = '@ember/component'; - } - } else if (option.name === 'component-structure') { - option.type = ['flat', 'nested']; - option.default = 'flat'; - option.aliases = [{ fs: 'flat' }, { ns: 'nested' }]; - } - }); - - this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE = EMBER_GLIMMER_SET_COMPONENT_TEMPLATE || isOctane; - }, - - install() { - if (!this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE) { - throw new SilentError( - 'Usage of `ember generate component-class` is only available on canary' - ); - } - - return this._super.install.apply(this, arguments); }, fileMapTokens(options) { @@ -116,9 +79,7 @@ module.exports = { let defaultExport = ''; let componentSignature = ''; - let componentClass = options.componentClass; - - switch (componentClass) { + switch (options.componentClass) { case '@ember/component': importComponent = `import Component from '@ember/component';`; defaultExport = `Component.extend({});`; @@ -141,7 +102,7 @@ module.exports = { componentSignature, defaultExport, path: getPathOption(options), - componentClass, + componentClass: options.componentClass, }; }, }; diff --git a/blueprints/component/index.js b/blueprints/component/index.js index 65aecf5e90f..1014c6c8261 100644 --- a/blueprints/component/index.js +++ b/blueprints/component/index.js @@ -1,22 +1,13 @@ 'use strict'; const chalk = require('chalk'); -const SilentError = require('silent-error'); const stringUtil = require('ember-cli-string-utils'); const getPathOption = require('ember-cli-get-component-path-option'); const normalizeEntityName = require('ember-cli-normalize-entity-name'); -const { has } = require('@ember/edition-utils'); const { generateComponentSignature } = require('../-utils'); const typescriptBlueprintPolyfill = require('ember-cli-typescript-blueprint-polyfill'); -const OCTANE = has('octane'); - -// TODO: this should be reading from the @ember/canary-features module -// need to refactor broccoli/features.js to be able to work more similarly -// to https://github.com/emberjs/data/pull/6231 -const EMBER_GLIMMER_SET_COMPONENT_TEMPLATE = true; - // intentionally avoiding use-edition-detector module.exports = { description: 'Generates a component.', @@ -33,14 +24,14 @@ module.exports = { { name: 'component-class', type: ['@ember/component', '@glimmer/component', '@ember/component/template-only', ''], - default: OCTANE ? '--no-component-class' : '@ember/component', + default: '--no-component-class', aliases: [ { cc: '@ember/component' }, { gc: '@glimmer/component' }, { tc: '@ember/component/template-only' }, { nc: '' }, { 'no-component-class': '' }, - { 'with-component-class': OCTANE ? '@glimmer/component' : '@ember/component' }, + { 'with-component-class': '@glimmer/component' }, ], }, { @@ -55,26 +46,8 @@ module.exports = { this._super && this._super.init.apply(this, arguments); typescriptBlueprintPolyfill(this); - let isOctane = has('octane'); - - this.availableOptions.forEach((option) => { - if (option.name === 'component-class') { - if (isOctane) { - option.default = '--no-component-class'; - } else { - option.default = '@ember/component'; - } - } else if (option.name === 'component-structure') { - option.type = ['flat', 'nested']; - option.default = 'flat'; - option.aliases = [{ fs: 'flat' }, { ns: 'nested' }]; - } - }); - this.skippedJsFiles = new Set(); this.savedLocals = {}; - - this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE = EMBER_GLIMMER_SET_COMPONENT_TEMPLATE || isOctane; }, install(options) { @@ -85,14 +58,6 @@ module.exports = { options.componentClass = ''; } - if (!this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE) { - if (options.componentClass !== '@ember/component') { - throw new SilentError( - 'Usage of --component-class argument to `ember generate component` is only available on canary' - ); - } - } - return this._super.install.apply(this, arguments); }, @@ -101,7 +66,7 @@ module.exports = { // matter what it is set to. All we want is to delete the optional JS // file if the user had created one (when using this generator, created // manually, added later with component-class generator...). - options.componentClass = '@ember/component'; + options.componentClass = '@glimmer/component'; return this._super.uninstall.apply(this, arguments); }, @@ -127,7 +92,7 @@ module.exports = { fileMapTokens(options) { let commandOptions = this.options; - if (this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE && commandOptions.componentStructure === 'flat') { + if (commandOptions.componentStructure === 'flat') { return { __path__() { return 'components'; @@ -139,10 +104,7 @@ module.exports = { return options.dasherizedModuleName; }, }; - } else if ( - this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE && - commandOptions.componentStructure === 'nested' - ) { + } else if (commandOptions.componentStructure === 'nested') { return { __path__() { return `components/${options.dasherizedModuleName}`; @@ -163,7 +125,7 @@ module.exports = { files() { let files = this._super.files.apply(this, arguments); - if (this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE && this.options.componentClass === '') { + if (this.options.componentClass === '') { files = files.filter((file) => { if (file.endsWith('.js') || file.endsWith('.ts')) { this.skippedJsFiles.add(file); @@ -184,10 +146,6 @@ module.exports = { }, locals(options) { - let componentClass = this.EMBER_GLIMMER_SET_COMPONENT_TEMPLATE - ? options.componentClass - : '@ember/component'; - let sanitizedModuleName = options.entity.name.replace(/\//g, '-'); let classifiedModuleName = stringUtil.classify(sanitizedModuleName); @@ -196,7 +154,7 @@ module.exports = { let defaultExport = ''; let componentSignature = ''; - switch (componentClass) { + switch (options.componentClass) { case '@ember/component': importComponent = `import Component from '@ember/component';`; defaultExport = `Component.extend({});`; diff --git a/lib/index.js b/lib/index.js index 2cdbf4f469f..d1d0ee64426 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,7 +4,6 @@ const MergeTrees = require('broccoli-merge-trees'); const Funnel = require('broccoli-funnel'); const path = require('path'); const Overrides = require('./overrides'); -const SilentError = require('silent-error'); const SupportedBrowsers = require('./browsers'); const paths = {}; @@ -82,44 +81,6 @@ module.exports = { if (overrides.hasBuildTimeWarning) { this.ui.writeWarnLine('[DEPRECATION] ' + overrides.buildTimeWarning); } - - const { has } = require('@ember/edition-utils'); - - let optionalFeatures = this.project.addons.find((a) => a.name === '@ember/optional-features'); - let optionalFeaturesMissing = optionalFeatures === undefined; - - if (has('octane')) { - let message = []; - - if (optionalFeaturesMissing) { - message.push( - `* the @ember/optional-features addon is missing, run \`ember install @ember/optional-features\` to install it` - ); - } - - if (message.length > 0) { - message.unshift( - `You have configured your application to indicate that it is using the 'octane' edition (via \`setEdition('octane')\`), but the appropriate Octane features were not enabled:\n` - ); - - throw new SilentError(message.join('\n\t')); - } - } else { - throw new SilentError( - 'The Ember Classic edition has been removed. Specifying "classic" in your package.json, or not specifying a value at all, is no longer supported. You must explicitly set the "ember.edition" property to "octane". You can also run `npx @ember/octanify` to do this. \n\nFor more information, see the deprecation guide: https://deprecations.emberjs.com/v3.x/#toc_editions-classic' - ); - } - - if ( - !optionalFeaturesMissing && - optionalFeatures.isFeatureEnabled('jquery-integration') && - typeof optionalFeatures.isFeatureExplicitlySet === 'function' && - optionalFeatures.isFeatureExplicitlySet('jquery-integration') - ) { - throw new SilentError( - 'Setting the `jquery-integration` optional feature flag to `true` was deprecated in Ember 3.x and removed in Ember 4.0.0. You must add the `@ember/optional-features` addon and set this feature to `false`.\n\nFor more information, see the deprecation guide: https://deprecations.emberjs.com/v3.x/#toc_optional-feature-jquery-integration' - ); - } }, treeForVendor(tree) { diff --git a/node-tests/blueprints/component-class-addon-test.js b/node-tests/blueprints/component-class-addon-test.js index 19a42c309f3..88df95b8305 100644 --- a/node-tests/blueprints/component-class-addon-test.js +++ b/node-tests/blueprints/component-class-addon-test.js @@ -4,13 +4,10 @@ const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); const setupTestHooks = blueprintHelpers.setupTestHooks; const emberNew = blueprintHelpers.emberNew; const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy; -const setupTestEnvironment = require('../helpers/setup-test-environment'); const chai = require('ember-cli-blueprint-test-helpers/chai'); const expect = chai.expect; -const enableOctane = setupTestEnvironment.enableOctane; describe('Blueprint: component-class-addon', function () { - enableOctane(); setupTestHooks(this); describe('in addon', function () { diff --git a/node-tests/blueprints/component-class-test.js b/node-tests/blueprints/component-class-test.js index f91e49e302c..524294a768d 100644 --- a/node-tests/blueprints/component-class-test.js +++ b/node-tests/blueprints/component-class-test.js @@ -11,9 +11,6 @@ const expect = chai.expect; const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); -const setupTestEnvironment = require('../helpers/setup-test-environment'); -const enableOctane = setupTestEnvironment.enableOctane; - const glimmerComponentContents = `import Component from '@glimmer/component'; export default class Foo extends Component {} @@ -32,9 +29,7 @@ export default templateOnly(); describe('Blueprint: component-class', function () { setupTestHooks(this); - describe('in app - octane', function () { - enableOctane(); - + describe('in app', function () { beforeEach(function () { return emberNew() .then(() => @@ -52,7 +47,6 @@ describe('Blueprint: component-class', function () { }); }); - // Octane default it('component-class foo --component-structure=flat --component-class=@glimmer/component', function () { return emberGenerateDestroy( [ @@ -151,9 +145,7 @@ describe('Blueprint: component-class', function () { }); }); - describe('in addon - octane', function () { - enableOctane(); - + describe('in addon', function () { beforeEach(function () { return emberNew({ target: 'addon' }) .then(() => @@ -215,9 +207,7 @@ describe('Blueprint: component-class', function () { }); }); - describe('in in-repo-addon - octane', function () { - enableOctane(); - + describe('in in-repo-addon', function () { beforeEach(function () { return emberNew({ target: 'in-repo-addon' }) .then(() => diff --git a/node-tests/blueprints/component-test.js b/node-tests/blueprints/component-test.js index d1824ffd727..279792e36e9 100644 --- a/node-tests/blueprints/component-test.js +++ b/node-tests/blueprints/component-test.js @@ -12,9 +12,6 @@ const expect = chai.expect; const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const fixture = require('../helpers/fixture'); -const setupTestEnvironment = require('../helpers/setup-test-environment'); -const enableOctane = setupTestEnvironment.enableOctane; - const glimmerComponentContents = `import Component from '@glimmer/component'; export default class Foo extends Component {} @@ -33,9 +30,7 @@ export default templateOnly(); describe('Blueprint: component', function () { setupTestHooks(this); - describe('in app - octane', function () { - enableOctane(); - + describe('in app', function () { beforeEach(function () { return emberNew() .then(() => @@ -63,7 +58,6 @@ describe('Blueprint: component', function () { }); }); - // Octane default it('component foo --component-structure=flat --component-class=@glimmer/component', function () { return emberGenerateDestroy( [ @@ -278,9 +272,7 @@ describe('Blueprint: component', function () { }); }); - describe('in addon - octane', function () { - enableOctane(); - + describe('in addon', function () { beforeEach(function () { return emberNew({ target: 'addon' }) .then(() => @@ -392,9 +384,7 @@ describe('Blueprint: component', function () { }); }); - describe('in in-repo-addon - octane', function () { - enableOctane(); - + describe('in in-repo-addon', function () { beforeEach(function () { return emberNew({ target: 'in-repo-addon' }) .then(() => diff --git a/node-tests/blueprints/controller-test.js b/node-tests/blueprints/controller-test.js index 854b26f9edc..ff4d615677c 100644 --- a/node-tests/blueprints/controller-test.js +++ b/node-tests/blueprints/controller-test.js @@ -13,15 +13,10 @@ const expect = chai.expect; const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const fixture = require('../helpers/fixture'); -const setupTestEnvironment = require('../helpers/setup-test-environment'); -const enableOctane = setupTestEnvironment.enableOctane; - describe('Blueprint: controller', function () { setupTestHooks(this); - describe('in app - octane', function () { - enableOctane(); - + describe('in app', function () { beforeEach(function () { return emberNew() .then(() => @@ -104,7 +99,6 @@ describe('Blueprint: controller', function () { }); describe('with podModulePrefix', function () { - enableOctane(); beforeEach(function () { setupPodConfig({ podModulePrefix: true }); }); @@ -145,9 +139,7 @@ describe('Blueprint: controller', function () { }); }); - describe('in addon - octane', function () { - enableOctane(); - + describe('in addon', function () { beforeEach(function () { return emberNew({ target: 'addon' }) .then(() => @@ -247,7 +239,6 @@ describe('Blueprint: controller', function () { }); describe('in in-repo-addon', function () { - enableOctane(); beforeEach(function () { return emberNew({ target: 'in-repo-addon' }) .then(() => diff --git a/node-tests/blueprints/route-test.js b/node-tests/blueprints/route-test.js index 40cf0121364..c8b0517c8e9 100644 --- a/node-tests/blueprints/route-test.js +++ b/node-tests/blueprints/route-test.js @@ -17,15 +17,10 @@ const fs = require('fs-extra'); const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const fixture = require('../helpers/fixture'); -const setupTestEnvironment = require('../helpers/setup-test-environment'); -const enableOctane = setupTestEnvironment.enableOctane; - describe('Blueprint: route', function () { setupTestHooks(this); - describe('in app - octane', function () { - enableOctane(); - + describe('in app', function () { beforeEach(function () { return emberNew() .then(() => @@ -329,9 +324,7 @@ describe('Blueprint: route', function () { }); }); - describe('in addon - octane', function () { - enableOctane(); - + describe('in addon', function () { beforeEach(function () { return emberNew({ target: 'addon' }) .then(() => @@ -569,7 +562,6 @@ describe('Blueprint: route', function () { }); describe('in in-repo-addon', function () { - enableOctane(); beforeEach(function () { return emberNew({ target: 'in-repo-addon' }) .then(() => diff --git a/node-tests/blueprints/service-test.js b/node-tests/blueprints/service-test.js index 6ccb39191b3..dfb5896b01e 100644 --- a/node-tests/blueprints/service-test.js +++ b/node-tests/blueprints/service-test.js @@ -13,15 +13,10 @@ const expect = chai.expect; const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const fixture = require('../helpers/fixture'); -const setupTestEnvironment = require('../helpers/setup-test-environment'); -const enableOctane = setupTestEnvironment.enableOctane; - describe('Blueprint: service', function () { setupTestHooks(this); - describe('in app - octane', function () { - enableOctane(); - + describe('in app', function () { beforeEach(function () { return emberNew() .then(() => @@ -100,8 +95,6 @@ describe('Blueprint: service', function () { }); describe('with podModulePrefix', function () { - enableOctane(); - beforeEach(function () { setupPodConfig({ podModulePrefix: true }); }); @@ -143,9 +136,7 @@ describe('Blueprint: service', function () { }); }); - describe('in addon - octane', function () { - enableOctane(); - + describe('in addon', function () { beforeEach(function () { return emberNew({ target: 'addon' }) .then(() => @@ -225,8 +216,6 @@ describe('Blueprint: service', function () { }); describe('in in-repo-addon', function () { - enableOctane(); - beforeEach(function () { return emberNew({ target: 'in-repo-addon' }) .then(() => diff --git a/node-tests/helpers/setup-test-environment.js b/node-tests/helpers/setup-test-environment.js deleted file mode 100644 index 25d9a60deb4..00000000000 --- a/node-tests/helpers/setup-test-environment.js +++ /dev/null @@ -1,15 +0,0 @@ -const { setEdition, clearEdition } = require('@ember/edition-utils'); - -function enableOctane() { - beforeEach(function () { - setEdition('octane'); - }); - - afterEach(function () { - clearEdition(); - }); -} - -module.exports = { - enableOctane, -};