Skip to content

Commit

Permalink
Permit plugins to add assets directly to the bundle in Rollup 1.x (#3105
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lukastaegert committed Sep 9, 2019
1 parent 1b72941 commit cb5227c
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/rollup/index.ts
Expand Up @@ -272,6 +272,16 @@ export default async function rollup(rawInputOptions: GenericConfigObject): Prom
throw error;
}
await graph.pluginDriver.hookSeq('generateBundle', [outputOptions, outputBundle, isWrite]);
for (const key of Object.keys(outputBundle)) {
const file = outputBundle[key] as any;
if (!file.type) {
graph.warnDeprecation(
'A plugin is directly adding properties to the bundle object in the "generateBundle" hook. This is deprecated and will be removed in a future Rollup version, please use "this.emitAsset" instead.',
false
);
file.type = 'asset';
}
}
graph.pluginDriver.finaliseAssets();

timeEnd('GENERATE', 1);
Expand Down
16 changes: 16 additions & 0 deletions test/form/samples/deprecated/emit-asset-hacky/_config.js
@@ -0,0 +1,16 @@
module.exports = {
description: 'supports emitting assets in a hacky way by editing the bundle object',
options: {
strictDeprecations: false,
plugins: {
generateBundle(options, outputBundle) {
const file = {
fileName: 'my-hacky-asset.txt',
isAsset: true,
source: 'My Hacky Source'
};
outputBundle[file.fileName] = file;
}
}
}
};
@@ -0,0 +1,5 @@
define(function () { 'use strict';

console.log('main');

});
@@ -0,0 +1,3 @@
'use strict';

console.log('main');
@@ -0,0 +1 @@
console.log('main');
@@ -0,0 +1,6 @@
(function () {
'use strict';

console.log('main');

}());
@@ -0,0 +1 @@
My Hacky Source
10 changes: 10 additions & 0 deletions test/form/samples/deprecated/emit-asset-hacky/_expected/system.js
@@ -0,0 +1,10 @@
System.register([], function () {
'use strict';
return {
execute: function () {

console.log('main');

}
};
});
@@ -0,0 +1,8 @@
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}(function () { 'use strict';

console.log('main');

}));
1 change: 1 addition & 0 deletions test/form/samples/deprecated/emit-asset-hacky/main.js
@@ -0,0 +1 @@
console.log('main');

0 comments on commit cb5227c

Please sign in to comment.