Skip to content

Commit

Permalink
Merge pull request #123 from brendenpalmer/add-to-manifest-when-neces…
Browse files Browse the repository at this point in the history
…sary
  • Loading branch information
rwjblue authored Feb 9, 2022
2 parents 87c3225 + 60c6b8b commit b8ea58f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
25 changes: 15 additions & 10 deletions lib/asset-manifest-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ var fs = require('fs-extra');

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

/**
* Adds a bundle if it doesn't already exist
*
* @name addBundleToManifest
* @param {Object} manifest The existing manifest object
* @param {string} bundleName The bundle to add
*/
function addBundleToManifest(manifest, bundleName) {
manifest.bundles[bundleName] = manifest.bundles[bundleName] || {
assets: []
};
}

/**
* A Broccoli plugin to generate an asset manifest from a given input tree.
* You can also provide a second tree that is a tree containing an existing
Expand Down Expand Up @@ -83,19 +96,10 @@ AssetManifestGenerator.prototype.build = function() {
return manifest;
}

if (bundleInfo.isNewBundle) {
if (manifest.bundles[bundleName]) {
throw new Error('Attempting to add bundle "' + bundleName + '" to manifest but a bundle with that name already exists.');
}

manifest.bundles[bundleName] = {
assets: []
};
}

// If the asset is named "dependencies.manifest.json" then we should read
// the json in and set it as "dependencies" on the corresponding bundle.
else if (assetName === 'dependencies.manifest.json') {
addBundleToManifest(manifest, bundleName);
var dependencies = fs.readJsonSync(path.join(inputPath, entry));
manifest.bundles[bundleName].dependencies = dependencies;
}
Expand All @@ -109,6 +113,7 @@ AssetManifestGenerator.prototype.build = function() {
let contents = fs.readFileSync(fullPath, 'utf-8');

if (contents.trim() !== '') {
addBundleToManifest(manifest, bundleName);
manifest.bundles[bundleName].assets.push({
uri: generateURI(path.posix.join(prepend, entry)),
type: assetType
Expand Down
3 changes: 0 additions & 3 deletions node-tests/fixtures/manifests/txt.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"assets": [
{ "uri": "/bundles/chat/assets/secret.txt", "type": "txt" }
]
},
"shared": {
"assets": []
}
}
}
2 changes: 1 addition & 1 deletion node-tests/manifest-generator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('manifest-generator', function() {
yield output.build();
var manifest = fs.readJsonSync(output.path('asset-manifest.json'));

assert.deepEqual(manifest.bundles.chat.assets, []);
assert.strictEqual(manifest.bundles.chat, undefined);
}));
});
})

0 comments on commit b8ea58f

Please sign in to comment.