Skip to content

Commit b8ea58f

Browse files
authored
Merge pull request #123 from brendenpalmer/add-to-manifest-when-necessary
2 parents 87c3225 + 60c6b8b commit b8ea58f

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

lib/asset-manifest-generator.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ var fs = require('fs-extra');
77

88
var DEFAULT_SUPPORTED_TYPES = [ 'js', 'css' ];
99

10+
/**
11+
* Adds a bundle if it doesn't already exist
12+
*
13+
* @name addBundleToManifest
14+
* @param {Object} manifest The existing manifest object
15+
* @param {string} bundleName The bundle to add
16+
*/
17+
function addBundleToManifest(manifest, bundleName) {
18+
manifest.bundles[bundleName] = manifest.bundles[bundleName] || {
19+
assets: []
20+
};
21+
}
22+
1023
/**
1124
* A Broccoli plugin to generate an asset manifest from a given input tree.
1225
* You can also provide a second tree that is a tree containing an existing
@@ -83,19 +96,10 @@ AssetManifestGenerator.prototype.build = function() {
8396
return manifest;
8497
}
8598

86-
if (bundleInfo.isNewBundle) {
87-
if (manifest.bundles[bundleName]) {
88-
throw new Error('Attempting to add bundle "' + bundleName + '" to manifest but a bundle with that name already exists.');
89-
}
90-
91-
manifest.bundles[bundleName] = {
92-
assets: []
93-
};
94-
}
95-
9699
// If the asset is named "dependencies.manifest.json" then we should read
97100
// the json in and set it as "dependencies" on the corresponding bundle.
98101
else if (assetName === 'dependencies.manifest.json') {
102+
addBundleToManifest(manifest, bundleName);
99103
var dependencies = fs.readJsonSync(path.join(inputPath, entry));
100104
manifest.bundles[bundleName].dependencies = dependencies;
101105
}
@@ -109,6 +113,7 @@ AssetManifestGenerator.prototype.build = function() {
109113
let contents = fs.readFileSync(fullPath, 'utf-8');
110114

111115
if (contents.trim() !== '') {
116+
addBundleToManifest(manifest, bundleName);
112117
manifest.bundles[bundleName].assets.push({
113118
uri: generateURI(path.posix.join(prepend, entry)),
114119
type: assetType

node-tests/fixtures/manifests/txt.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
"assets": [
1414
{ "uri": "/bundles/chat/assets/secret.txt", "type": "txt" }
1515
]
16-
},
17-
"shared": {
18-
"assets": []
1916
}
2017
}
2118
}

node-tests/manifest-generator-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('manifest-generator', function() {
151151
yield output.build();
152152
var manifest = fs.readJsonSync(output.path('asset-manifest.json'));
153153

154-
assert.deepEqual(manifest.bundles.chat.assets, []);
154+
assert.strictEqual(manifest.bundles.chat, undefined);
155155
}));
156156
});
157157
})

0 commit comments

Comments
 (0)