Skip to content
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
45 changes: 3 additions & 42 deletions blueprints/component-class/index.js
Original file line number Diff line number Diff line change
@@ -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.',
Expand All @@ -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' },
Expand All @@ -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) {
Expand Down Expand Up @@ -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({});`;
Expand All @@ -141,7 +102,7 @@ module.exports = {
componentSignature,
defaultExport,
path: getPathOption(options),
componentClass,
componentClass: options.componentClass,
};
},
};
56 changes: 7 additions & 49 deletions blueprints/component/index.js
Original file line number Diff line number Diff line change
@@ -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.',
Expand All @@ -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' },
],
},
{
Expand All @@ -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) {
Expand All @@ -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);
},

Expand All @@ -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);
},
Expand All @@ -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';
Expand All @@ -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}`;
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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({});`;
Expand Down
39 changes: 0 additions & 39 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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'
);
Comment on lines -92 to -121
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this change. I think we can simply remove these errors, but we could also keep them around (without the octane check).

}
},

treeForVendor(tree) {
Expand Down
3 changes: 0 additions & 3 deletions node-tests/blueprints/component-class-addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
16 changes: 3 additions & 13 deletions node-tests/blueprints/component-class-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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(() =>
Expand All @@ -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(
[
Expand Down Expand Up @@ -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(() =>
Expand Down Expand Up @@ -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(() =>
Expand Down
16 changes: 3 additions & 13 deletions node-tests/blueprints/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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(() =>
Expand Down Expand Up @@ -63,7 +58,6 @@ describe('Blueprint: component', function () {
});
});

// Octane default
it('component foo --component-structure=flat --component-class=@glimmer/component', function () {
return emberGenerateDestroy(
[
Expand Down Expand Up @@ -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(() =>
Expand Down Expand Up @@ -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(() =>
Expand Down
Loading