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

[RFC 772] Deprecate Bower support #9707

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/broccoli/default-packager.js
Expand Up @@ -12,6 +12,7 @@ const ConfigReplace = require('broccoli-config-replace');
const emberAppUtils = require('../utilities/ember-app-utils');
const funnelReducer = require('broccoli-funnel-reducer');
const addonProcessTree = require('../utilities/addon-process-tree');
const { deprecate } = require('../debug');

const preprocessCss = p.preprocessCss;
const preprocessJs = p.preprocessJs;
Expand Down Expand Up @@ -628,9 +629,21 @@ module.exports = class DefaultPackager {
* @param {String} bowerDirectory Custom path to bower components
*/
packageBower(tree, bowerDirectory) {
let destDir = bowerDirectory || DEFAULT_BOWER_PATH;

deprecate(`Building Bower packages has been deprecated. You have Bower packages in \`${destDir}\`.`, false, {
for: 'ember-cli',
id: 'ember-cli.building-bower-packages',
since: {
available: '4.2.0',
enabled: '4.2.0',
},
until: '5.0.0',
});

if (this._cachedBower === null) {
this._cachedBower = new Funnel(tree, {
destDir: bowerDirectory || DEFAULT_BOWER_PATH,
destDir,
annotation: 'Packaged Bower',
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/broccoli/ember-app.js
Expand Up @@ -108,7 +108,7 @@ class EmberApp {

this.registry = options.registry || p.defaultRegistry(this);

this.bowerDirectory = this.project.bowerDirectory;
this.bowerDirectory = this.project._bowerDirectory;

this._initTestsAndHinting(options);
this._initOptions(options);
Expand Down Expand Up @@ -438,7 +438,7 @@ class EmberApp {
@method _initVendorFiles
*/
_initVendorFiles() {
let bowerDeps = this.project.bowerDependencies();
let bowerDeps = this.project._bowerDependencies();
let ember = this.project.findAddonByName('ember-source');
let addonEmberCliShims = this.project.findAddonByName('ember-cli-shims');
let bowerEmberCliShims = bowerDeps['ember-cli-shims'];
Expand Down
43 changes: 41 additions & 2 deletions lib/models/blueprint.js
Expand Up @@ -24,6 +24,7 @@ const bowEpParser = require('bower-endpoint-parser');
const logger = require('heimdalljs-logger')('ember-cli:blueprint');
const normalizeEntityName = require('ember-cli-normalize-entity-name');
const isAddon = require('../utilities/is-addon');
const { deprecate } = require('../debug');

const initialIgnoredFiles = ['.DS_Store'];

Expand Down Expand Up @@ -1017,10 +1018,29 @@ let Blueprint = CoreObject.extend({
```
*/
addBowerPackageToProject(localPackageName, target, installOptions) {
deprecate(
[
`(Blueprint: \`${this.name}\`) \`addBowerPackageToProject\` has been deprecated.`,
'If the package is also available on the npm registry, please use `addPackageToProject` instead.',
'If not, please install the Bower package manually by running:',
`\`bower install ${localPackageName} --save\``,
].join('\n'),
false,
{
for: 'ember-cli',
id: 'ember-cli.blueprint.add-bower-package-to-project',
since: {
available: '4.2.0',
enabled: '4.2.0',
},
until: '5.0.0',
}
);

let lpn = localPackageName;
let tar = target;
let packageObject = bowEpParser.json2decomposed(lpn, tar);
return this.addBowerPackagesToProject([packageObject], installOptions);
return this.addBowerPackagesToProject([packageObject], installOptions, true);
},

/**
Expand All @@ -1039,7 +1059,7 @@ let Blueprint = CoreObject.extend({
@param {Object} installOptions
@return {Promise}
*/
addBowerPackagesToProject(packages, installOptions) {
addBowerPackagesToProject(packages, installOptions, _deprecationCondition = false) {
let task = this.taskFor('bower-install');
let installText = packages.length > 1 ? 'install bower packages' : 'install bower package';
let packageNames = [];
Expand All @@ -1051,6 +1071,25 @@ let Blueprint = CoreObject.extend({
})
.map(bowEpParser.compose);

deprecate(
[
`(Blueprint: \`${this.name}\`) \`addBowerPackagesToProject\` has been deprecated.`,
'If the packages are also available on the npm registry, please use `addPackagesToProject` instead.',
'If not, please install the Bower packages manually by running:',
`\`bower install ${packageNames.join(' ')} --save\``,
].join('\n'),
_deprecationCondition,
{
for: 'ember-cli',
id: 'ember-cli.blueprint.add-bower-packages-to-project',
since: {
available: '4.2.0',
enabled: '4.2.0',
},
until: '5.0.0',
}
);

this._writeStatusToUI(chalk.green, installText, packageNames.join(', '));

return task.run({
Expand Down
2 changes: 1 addition & 1 deletion lib/models/installation-checker.js
Expand Up @@ -48,7 +48,7 @@ class InstallationChecker {
}

bowerDependenciesNotPresent() {
return !fs.existsSync(this.project.bowerDirectory);
return !fs.existsSync(this.project._bowerDirectory);
}

hasNpmDeps() {
Expand Down
51 changes: 47 additions & 4 deletions lib/models/project.js
Expand Up @@ -18,6 +18,7 @@ const PackageInfoCache = require('./package-info-cache');
const PerBundleAddonCache = require('./per-bundle-addon-cache');
const instantiateAddons = require('./instantiate-addons');
const HostInfoCache = require('./host-info-cache');
const { deprecate } = require('../debug');

let processCwd = process.cwd();

Expand Down Expand Up @@ -117,15 +118,36 @@ class Project {

if (fs.existsSync(bowerrcPath)) {
try {
this.bowerDirectory = fs.readJsonSync(bowerrcPath).directory;
this._bowerDirectory = fs.readJsonSync(bowerrcPath).directory;
} catch (exception) {
logger.info('failed to parse bowerc: %s', exception);
this.bowerDirectory = null;
this._bowerDirectory = null;
}
}

this.bowerDirectory = this.bowerDirectory || 'bower_components';
logger.info('bowerDirectory: %s', this.bowerDirectory);
this._bowerDirectory = this._bowerDirectory || 'bower_components';
logger.info('bowerDirectory: %s', this._bowerDirectory);
}

get bowerDirectory() {
deprecate(
[
'`bowerDirectory` has been deprecated.',
"If you still need access to the project's Bower directory, you will have to manually resolve the project's `.bowerrc` file, and read the `directory` property instead.",
].join('\n'),
false,
{
for: 'ember-cli',
id: 'ember-cli.project.bower-directory',
since: {
available: '4.2.0',
enabled: '4.2.0',
},
until: '5.0.0',
}
);

return this._bowerDirectory;
}

// Checks whether the project's npm dependencies are
Expand Down Expand Up @@ -387,6 +409,27 @@ class Project {
@return {Object} Bower dependencies
*/
bowerDependencies(bower) {
deprecate(
[
'`bowerDependencies` has been deprecated.',
"If you still need access to the project's Bower dependencies, you will have to manually resolve the project's `bower.json` file instead.",
].join('\n'),
false,
{
for: 'ember-cli',
id: 'ember-cli.project.bower-dependencies',
since: {
available: '4.2.0',
enabled: '4.2.0',
},
until: '5.0.0',
}
);

return this._bowerDependencies(bower);
}

_bowerDependencies(bower) {
if (!bower) {
let bowerPath = path.join(this.root, 'bower.json');
bower = fs.existsSync(bowerPath) ? require(bowerPath) : {};
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/broccoli/ember-app-test.js
Expand Up @@ -825,7 +825,7 @@ describe('EmberApp', function () {
});

it('keeps ember-resolver.js in vendorFiles when npm ember-resolver is not installed, but is present in bower.json', function () {
project.bowerDependencies = function () {
project._bowerDependencies = function () {
return { ember: {}, 'ember-resolver': {} };
};
let app = new EmberApp({
Expand All @@ -841,7 +841,7 @@ describe('EmberApp', function () {
});

it('removes ember-resolver.js from vendorFiles when not in bower.json and npm ember-resolver not installed', function () {
project.bowerDependencies = function () {
project._bowerDependencies = function () {
return { ember: {} };
};
let app = new EmberApp({
Expand Down