Skip to content

Commit c83e885

Browse files
authored
Merge pull request #539 from SergeAstapov/custom-output-paths
Make manifest in package.json respect outputPaths configuration in EmberApp
2 parents 6336e97 + 8633f4f commit c83e885

5 files changed

Lines changed: 22 additions & 22 deletions

File tree

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,13 @@ module.exports = {
180180
registry: this._appRegistry
181181
});
182182

183-
let fileAppName = path.basename(this.app.options.outputPaths.app.js).split('.')[0];
183+
function stripLeadingSlash(filePath) {
184+
return filePath.replace(/^\//, '');
185+
}
186+
187+
let appFilePath = stripLeadingSlash(this.app.options.outputPaths.app.js);
184188
let finalFastbootTree = new Concat(processExtraTree, {
185-
outputFile: 'assets/' + fileAppName + '-fastboot.js'
189+
outputFile: appFilePath.replace(/\.js$/, '-fastboot.js')
186190
});
187191

188192
return finalFastbootTree;

lib/broccoli/fastboot-config.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,13 @@ module.exports = class FastBootConfig extends Plugin {
174174
}
175175

176176
buildManifest() {
177-
let appFilePath = 'assets/' + path.basename(this.outputPaths.app.js);
178-
let appFileName = appFilePath.split('.')[0];
179-
let appFastbootFilePath = appFileName + '-fastboot.js';
180-
let vendorFilePath = 'assets/' + path.basename(this.outputPaths.vendor.js);
177+
function stripLeadingSlash(filePath) {
178+
return filePath.replace(/^\//, '');
179+
}
180+
181+
let appFilePath = stripLeadingSlash(this.outputPaths.app.js);
182+
let appFastbootFilePath = appFilePath.replace(/\.js$/, '') + '-fastboot.js';
183+
let vendorFilePath = stripLeadingSlash(this.outputPaths.vendor.js);
181184

182185
let manifest = {
183186
appFiles: [appFilePath, appFastbootFilePath],
@@ -197,7 +200,6 @@ module.exports = class FastBootConfig extends Plugin {
197200
// update the app files array with fingerprinted files
198201
let rewrittenAppFiles = manifest['appFiles'].map(file => rewrittenAssets.assets[file] || file);
199202
manifest['appFiles'] = rewrittenAppFiles;
200-
201203
}
202204

203205
this.manifest = manifest;
@@ -265,12 +267,3 @@ function getDependencyVersion(pkg, dep) {
265267

266268
return pkg.dependencies[dep];
267269
}
268-
269-
function assetToFastboot(key) {
270-
let parts = key.split('/');
271-
let dir = parts[0];
272-
if (dir === 'assets') {
273-
parts[0] = 'fastboot';
274-
}
275-
return parts.join('/');
276-
}

test/fixtures/customized-outputpaths/ember-cli-build.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ module.exports = function(defaults) {
88
app: {
99
html: 'index.html',
1010
css: {
11-
'app': '/assets/app.css',
11+
'app': '/some-assets/path/app.css',
1212
},
13-
js: '/assets/app.js'
13+
js: '/some-assets/path/app-file.js'
1414
},
1515
vendor: {
16-
js: '/assets/lib.js'
16+
js: '/some-assets/path/lib.js'
1717
}
1818
}
1919
});

test/new-package-json-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('FastbootConfig', function() {
5353
expect(
5454
output.read()
5555
).to.deep.equal({
56-
'package.json': `{"dependencies":{},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["assets/app.js","assets/app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["assets/vendor.js"]},"moduleWhitelist":[],"schemaVersion":3}}`
56+
'package.json': `{"dependencies":{},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleWhitelist":[],"schemaVersion":3}}`
5757
});
5858

5959
yield output.build();
@@ -84,7 +84,7 @@ describe('FastbootConfig', function() {
8484
expect(
8585
output.read()
8686
).to.deep.equal({
87-
'package.json': `{"dependencies":{"apple":"*","orange":"^1.0.0"},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["assets/app.js","assets/app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["assets/vendor.js"]},"moduleWhitelist":["apple","orange"],"schemaVersion":3}}`
87+
'package.json': `{"dependencies":{"apple":"*","orange":"^1.0.0"},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleWhitelist":["apple","orange"],"schemaVersion":3}}`
8888
});
8989

9090
project.pkg.fastbootDependencies = [
@@ -107,7 +107,7 @@ describe('FastbootConfig', function() {
107107
expect(
108108
output.read()
109109
).to.deep.equal({
110-
'package.json': `{"dependencies":{"apple":"^3.0.0","orange":"^1.0.0"},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["assets/app.js","assets/app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["assets/vendor.js"]},"moduleWhitelist":["apple","orange"],"schemaVersion":3}}`
110+
'package.json': `{"dependencies":{"apple":"^3.0.0","orange":"^1.0.0"},"fastboot":{"appName":"app","config":{"app":{"modulePrefix":"app"}},"manifest":{"appFiles":["app.js","app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["vendor.js"]},"moduleWhitelist":["apple","orange"],"schemaVersion":3}}`
111111
});
112112
}));
113113
});

test/package-json-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,13 @@ describe('generating package.json', function() {
237237
let pkg = fs.readJsonSync(customApp.filePath('/dist/package.json'));
238238
let manifest = pkg.fastboot.manifest;
239239

240+
expect(manifest.appFiles).to.include('some-assets/path/app-file.js');
240241
manifest.appFiles.forEach(function(file) {
241242
expect(p(file)).to.be.a.file();
242243
});
243244
expect(p(manifest.htmlFile)).to.be.a.file();
245+
246+
expect(manifest.vendorFiles).to.include('some-assets/path/lib.js');
244247
manifest.vendorFiles.forEach(function(file) {
245248
expect(p(file)).to.be.a.file();
246249
});

0 commit comments

Comments
 (0)