Skip to content

Commit e0fe0d7

Browse files
committed
chore: do not support rollup < 1.0.0
1 parent 43f81cf commit e0fe0d7

6 files changed

Lines changed: 44 additions & 532 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"prettier"
2828
],
2929
"peerDependencies": {
30-
"rollup": "<3"
30+
"rollup": "^1.0.0 || ^2.0.0"
3131
},
3232
"dependencies": {
3333
"diff": "4.0.2",

src/index-rollup-legacy.js

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/index-rollup-stable.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/index.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,34 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import * as rollup from 'rollup';
26-
import {rollupPluginPrettierLegacy} from './index-rollup-legacy';
27-
import {rollupPluginPrettierStable} from './index-rollup-stable';
25+
import {RollupPluginPrettier} from './rollup-plugin-prettier.js';
2826

29-
const VERSION = rollup.VERSION || '0';
30-
const MAJOR_VERSION = Number(VERSION.split('.')[0]) || 0;
31-
const IS_ROLLUP_LEGACY = MAJOR_VERSION === 0;
32-
const plugin = IS_ROLLUP_LEGACY ? rollupPluginPrettierLegacy : rollupPluginPrettierStable;
27+
/**
28+
* Create rollup plugin compatible with rollup >= 1.0.0
29+
*
30+
* @param {Object} options Plugin options.
31+
* @return {Object} Plugin instance.
32+
*/
33+
export default function rollupPluginPrettier(options) {
34+
const plugin = new RollupPluginPrettier(options);
35+
36+
return {
37+
/**
38+
* Plugin name (used by rollup for error messages and warnings).
39+
* @type {string}
40+
*/
41+
name: plugin.name,
3342

34-
export default plugin;
43+
/**
44+
* Function called by `rollup` before generating final bundle.
45+
*
46+
* @param {string} source Souce code of the final bundle.
47+
* @param {Object} chunkInfo Chunk info.
48+
* @param {Object} outputOptions Output option.
49+
* @return {Object} The result containing a `code` property and, if a enabled, a `map` property.
50+
*/
51+
renderChunk(source, chunkInfo, outputOptions) {
52+
return plugin.reformat(source, outputOptions.sourcemap);
53+
},
54+
};
55+
}

0 commit comments

Comments
 (0)