-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from zonkyio/require-module-path
Allow to require module path from whitelisted dependency
- Loading branch information
Showing
13 changed files
with
84,989 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict'; | ||
|
||
function getPackageName(modulePath) { | ||
let parts = modulePath.split('/'); | ||
|
||
if (modulePath[0] === '@') { | ||
return parts[0] + '/' + parts[1]; | ||
} | ||
return parts[0]; | ||
} | ||
|
||
module.exports = getPackageName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const fixture = require('./helpers/fixture-path'); | ||
const FastBoot = require('./../src/index'); | ||
|
||
describe.only("FastBoot with dependencies", function() { | ||
it("it works with dependencies", function() { | ||
var fastboot = new FastBoot({ | ||
distPath: fixture('app-with-dependencies') | ||
}); | ||
|
||
return fastboot.visit('/') | ||
.then(r => r.html()) | ||
.then(html => { | ||
expect(html).to.match(/https:\/\/emberjs.com/); | ||
expect(html).to.match(/FOO/); | ||
expect(html).to.match(/BAR/); | ||
}); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
test/fixtures/app-with-dependencies/assets/app-with-dependencies-fastboot.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
define('app-with-dependencies/initializers/ajax', ['exports'], function (exports) { | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
|
||
const { get } = Ember; /* globals najax */ | ||
|
||
|
||
var nodeAjax = function (options) { | ||
let httpRegex = /^https?:\/\//; | ||
let protocolRelativeRegex = /^\/\//; | ||
let protocol = get(this, 'fastboot.request.protocol'); | ||
|
||
if (protocolRelativeRegex.test(options.url)) { | ||
options.url = protocol + options.url; | ||
} else if (!httpRegex.test(options.url)) { | ||
try { | ||
options.url = protocol + '//' + get(this, 'fastboot.request.host') + options.url; | ||
} catch (fbError) { | ||
throw new Error('You are using Ember Data with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostWhitelist property for in your environment.js. FastBoot Error: ' + fbError.message); | ||
} | ||
} | ||
|
||
if (najax) { | ||
najax(options); | ||
} else { | ||
throw new Error('najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?'); | ||
} | ||
}; | ||
|
||
exports.default = { | ||
name: 'ajax-service', | ||
|
||
initialize: function (application) { | ||
application.register('ajax:node', nodeAjax, { instantiate: false }); | ||
application.inject('adapter', '_ajaxRequest', 'ajax:node'); | ||
application.inject('adapter', 'fastboot', 'service:fastboot'); | ||
} | ||
}; | ||
}); | ||
define('app-with-dependencies/initializers/error-handler', ['exports'], function (exports) { | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = { | ||
name: 'error-handler', | ||
|
||
initialize: function (application) { | ||
if (!Ember.onerror) { | ||
// if no onerror handler is defined, define one for fastboot environments | ||
Ember.onerror = function (err) { | ||
let errorMessage = `There was an error running your app in fastboot. More info about the error: \n ${err.stack || err}`; | ||
Ember.Logger.error(errorMessage); | ||
}; | ||
} | ||
} | ||
}; | ||
});//# sourceMappingURL=app-with-dependencies-fastboot.map |
Oops, something went wrong.