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

Add "rootURL" setting to deprecate "baseURL" #5792

Merged
merged 8 commits into from Apr 27, 2016
@@ -9,16 +9,16 @@
{{content-for "head"}}
<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/<%= name %>.css">
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/<%= name %>.css">
{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}
<script src="assets/vendor.js"></script>
<script src="assets/<%= name %>.js"></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/<%= name %>.js"></script>
{{content-for "body-footer"}}
</body>
@@ -2,7 +2,8 @@ import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
location: config.locationType,
rootURL: config.rootURL
});
Router.map(function() {
@@ -4,7 +4,7 @@ module.exports = function(environment) {
var ENV = {
modulePrefix: '<%= modulePrefix %>',
environment: environment,
baseURL: '/',
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
@@ -29,7 +29,6 @@ module.exports = function(environment) {
if (environment === 'test') {
// Testem prefers this...
ENV.baseURL = '/';
ENV.locationType = 'none';
// keep test console output quieter
@@ -10,9 +10,9 @@
{{content-for "head"}}
{{content-for "test-head"}}
<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/<%= name %>.css">
<link rel="stylesheet" href="assets/test-support.css">
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/<%= name %>.css">
<link rel="stylesheet" href="{{rootURL}}assets/test-support.css">
{{content-for "head-footer"}}
{{content-for "test-head-footer"}}
@@ -21,12 +21,12 @@
{{content-for "body"}}
{{content-for "test-body"}}
<script src="testem.js" integrity=""></script>
<script src="assets/vendor.js"></script>
<script src="assets/test-support.js"></script>
<script src="assets/<%= name %>.js"></script>
<script src="assets/tests.js"></script>
<script src="assets/test-loader.js"></script>
<script src="{{rootURL}}testem.js" integrity=""></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/test-support.js"></script>
<script src="{{rootURL}}assets/<%= name %>.js"></script>
<script src="{{rootURL}}assets/tests.js"></script>
<script src="{{rootURL}}assets/test-loader.js"></script>
{{content-for "body-footer"}}
{{content-for "test-body-footer"}}
@@ -693,6 +693,9 @@ EmberApp.prototype._templatesTree = function() {
*/
EmberApp.prototype._configReplacePatterns = function() {
return [{
match: /\{\{rootURL\}\}/g,
replacement: calculateRootURL
}, {
match: /\{\{EMBER_ENV\}\}/g,
replacement: calculateEmberENV
}, {
@@ -1711,6 +1714,10 @@ function calculateBaseTag(config) {
}
}
function calculateRootURL(config) {
return cleanBaseURL(config.rootURL) || '';
}
function calculateEmberENV(config) {
return JSON.stringify(config.EmberENV || {});
}
View
@@ -41,8 +41,19 @@ module.exports = Command.extend({
return this._checkExpressPort(commandOptions)
.then(this._autoFindLiveReloadPort.bind(this))
.then(function(commandOptions) {
var config = this.project.config(commandOptions.environment);
this.ui.writeDeprecateLine(
'Using the `baseURL` setting is deprecated, use `rootURL` instead.',
!(!config.rootURL && config.baseURL));
this.ui.writeWarnLine(
'The `baseURL` and `rootURL` settings should not be used at the same time.',
!(config.rootURL && config.baseURL));
commandOptions = assign({}, commandOptions, {
baseURL: this.project.config(commandOptions.environment).baseURL || '/'
rootURL: config.rootURL,
baseURL: config.baseURL || '/'
});
if (commandOptions.proxy) {
View
@@ -338,6 +338,7 @@ Project.prototype.supportedInternalAddonPaths = function() {
var legacyBlueprintsPath = require.resolve('ember-cli-legacy-blueprints');
var emberTryPath = require.resolve('ember-try');
return [
path.join(internalMiddlewarePath, 'testem-url-rewriter'),
path.join(internalMiddlewarePath, 'tests-server'),
path.join(internalMiddlewarePath, 'history-support'),
path.join(internalMiddlewarePath, 'serve-files'),
@@ -144,7 +144,7 @@ module.exports = Task.extend({
return this.startHttpServer()
.then(function () {
var baseURL = cleanBaseURL(options.baseURL);
var baseURL = cleanBaseURL(options.rootURL || options.baseURL);
options.ui.writeLine('Serving on http' + (options.ssl ? 's' : '') +
'://' + this.displayHost(options.host) +
@@ -40,7 +40,7 @@ HistorySupportAddon.prototype.addMiddleware = function(config) {
var options = config.options;
var watcher = options.watcher;
var baseURL = cleanBaseURL(options.baseURL);
var baseURL = cleanBaseURL(options.rootURL || options.baseURL);
var baseURLRegexp = new RegExp('^' + baseURL);
app.use(function(req, res, next) {
@@ -25,7 +25,7 @@ ServeFilesAddon.prototype.serverMiddleware = function(options) {
autoIndex: false // disable directory listings
});
var baseURL = cleanBaseURL(options.baseURL);
var baseURL = cleanBaseURL(options.rootURL || options.baseURL);
debug('serverMiddleware: baseURL: %s', baseURL);
@@ -0,0 +1,42 @@
'use strict';
var cleanBaseURL = require('clean-base-url');
var debug = require('debug')('ember-cli:testem-url-rewriter');
function TestemUrlRewriterAddon(project) {
this.name = 'testem-url-rewriter';
this.project = project;
}
TestemUrlRewriterAddon.prototype.testemMiddleware = function(app) {
var env = process.env.EMBER_ENV;
debug('Reading config for environment "%s"', env);
var config = this.project.config(env);
debug('config.rootURL = %s', config.rootURL);
this.project.ui.writeDeprecateLine(
'Using the `baseURL` setting is deprecated, use `rootURL` instead.',
!(!config.rootURL && config.baseURL));
this.project.ui.writeWarnLine(
'The `baseURL` and `rootURL` settings should not be used at the same time.',
!(config.rootURL && config.baseURL));
var rootURL = cleanBaseURL(config.rootURL) || '/';
debug('rootURL = %s', rootURL);
app.use(function(req, res, next) {
var oldUrl = req.url;
if (rootURL !== '/' && oldUrl.indexOf(rootURL) === 0) {
req.url = '/' + oldUrl.slice(rootURL.length);
debug('Rewriting %s %s -> %s', req.method, oldUrl, req.url);
} else {
debug('Ignoring %s %s', req.method, req.url);
}
next();
});
};
module.exports = TestemUrlRewriterAddon;
@@ -0,0 +1,6 @@
{
"name": "testem-url-rewriter-middleware",
"keywords": [
"ember-addon"
]
}
@@ -23,7 +23,7 @@ TestsServerAddon.prototype.serverMiddleware = function(config) {
var options = config.options;
var watcher = options.watcher;
var baseURL = cleanBaseURL(options.baseURL);
var baseURL = cleanBaseURL(options.rootURL || options.baseURL);
var testsRegexp = new RegExp('^' + baseURL + 'tests');
app.use(function(req, res, next) {
@@ -304,6 +304,13 @@ describe('broccoli/ember-app', function() {
expect(actual).to.not.contain(expected);
});
it('does not include the `base` tag in `head` if baseURL is undefined', function() {
var expected = '<base href=';
var actual = emberApp.contentFor(config, defaultMatch, 'head');
expect(actual).to.not.contain(expected);
});
});
describe('contentFor("config-module")', function() {
@@ -557,7 +564,7 @@ describe('broccoli/ember-app', function() {
emberFooEnvAddonFixture.app = emberApp;
expect(emberApp._addonEnabled(emberFooEnvAddonFixture)).to.be.false;
expect(emberApp.project.addons.length).to.equal(7);
expect(emberApp.project.addons.length).to.equal(8);
});
it('foo', function() {
@@ -567,7 +574,7 @@ describe('broccoli/ember-app', function() {
emberFooEnvAddonFixture.app = emberApp;
expect(emberApp._addonEnabled(emberFooEnvAddonFixture)).to.be.true;
expect(emberApp.project.addons.length).to.equal(8);
expect(emberApp.project.addons.length).to.equal(9);
});
});
});
@@ -584,7 +591,7 @@ describe('broccoli/ember-app', function() {
expect(emberApp._addonDisabledByBlacklist({ name: 'ember-foo-env-addon' })).to.be.true;
expect(emberApp._addonDisabledByBlacklist({ name: 'Ember Random Addon' })).to.be.false;
expect(emberApp.project.addons.length).to.equal(7);
expect(emberApp.project.addons.length).to.equal(8);
});
it('throws if unavailable addon is specified', function() {
@@ -187,6 +187,7 @@ describe('models/project.js', function() {
it('returns a listing of all ember-cli-addons directly depended on by the project', function() {
var expected = [
'testem-url-rewriter-middleware',
'tests-server-middleware',
'history-support-middleware', 'serve-files-middleware',
'proxy-server-middleware', 'ember-cli-legacy-blueprints', 'ember-try',
@@ -201,10 +202,10 @@ describe('models/project.js', function() {
it('returns instances of the addons', function() {
var addons = project.addons;
expect(addons[7].name).to.equal('Ember Non Root Addon');
expect(addons[13].name).to.equal('Ember Super Button');
expect(addons[13].addons[0].name).to.equal('Ember Yagni');
expect(addons[13].addons[1].name).to.equal('Ember Ng');
expect(addons[8].name).to.equal('Ember Non Root Addon');
expect(addons[14].name).to.equal('Ember Super Button');
expect(addons[14].addons[0].name).to.equal('Ember Yagni');
expect(addons[14].addons[1].name).to.equal('Ember Ng');
});
it('addons get passed the project instance', function() {
@@ -216,7 +217,7 @@ describe('models/project.js', function() {
it('returns an instance of an addon that uses `ember-addon-main`', function() {
var addons = project.addons;
expect(addons[9].name).to.equal('Ember Random Addon');
expect(addons[10].name).to.equal('Ember Random Addon');
});
it('returns the default blueprints path', function() {
@@ -279,8 +280,8 @@ describe('models/project.js', function() {
it('returns an instance of an addon with an object export', function() {
var addons = project.addons;
expect(addons[6] instanceof Addon).to.equal(true);
expect(addons[6].name).to.equal('Ember CLI Generated with export');
expect(addons[7] instanceof Addon).to.equal(true);
expect(addons[7].name).to.equal('Ember CLI Generated with export');
});
it('adds the project itself if it is an addon', function() {
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.