├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.js ├── package.json └── test ├── expected.js ├── rollup.config.js └── source.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "7" 4 | - "6" 5 | - "4" 6 | - "0.12" 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | For rollup-plugin-flow software 4 | 5 | Copyright (c) 2014-2016, Facebook, Inc. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name Facebook nor the names of its contributors may be used to 18 | endorse or promote products derived from this software without specific 19 | prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rollup Flow plugin 2 | ================== 3 | 4 | [![Build Status](https://travis-ci.org/leebyron/rollup-plugin-flow.svg?branch=master)](https://travis-ci.org/leebyron/rollup-plugin-flow) 5 | 6 | This [Rollup](http://rollupjs.org/) plugin will remove [Flow](https://flowtype.org) 7 | type annotations during bundling using [`flow-remove-types`](https://github.com/leebyron/flow-remove-types). 8 | 9 | ## Install 10 | 11 | ``` 12 | npm install --save rollup-plugin-flow 13 | ``` 14 | 15 | ```js 16 | var rollup = require('rollup').rollup; 17 | var flow = require('rollup-plugin-flow'); 18 | 19 | rollup({ 20 | entry: 'main.js', 21 | plugins: [ flow() ] 22 | }).then(...); 23 | ``` 24 | 25 | ## Options 26 | 27 | Provide options as an object argument to `flow()`. 28 | 29 | #### `all` - Transform all files, not just those containing `@flow` comments. 30 | 31 | *Default:* `false` 32 | 33 | ```js 34 | var flow = require('rollup-plugin-flow'); 35 | 36 | module.exports = { 37 | plugins: [ flow({ all: true }) ], 38 | format: 'cjs' 39 | }; 40 | ``` 41 | 42 | #### `pretty` - Remove flow types without replacing them with whitespace. 43 | 44 | *Default:* `false` 45 | 46 | *Note:* Typically source maps are not necessary for this transform, however 47 | source maps are recommended when generating "pretty" results. 48 | 49 | ```js 50 | var flow = require('rollup-plugin-flow'); 51 | 52 | module.exports = { 53 | plugins: [ flow({ pretty: true }) ], 54 | format: 'cjs' 55 | }; 56 | ``` 57 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var flowRemoveTypes = require('flow-remove-types'); 2 | var createFilter = require('rollup-pluginutils').createFilter; 3 | 4 | module.exports = function(options) { 5 | options = options || {}; 6 | var filter = createFilter(options.include, options.exclude); 7 | 8 | return { 9 | name: 'flow-remove-types', 10 | transform: function(code, id) { 11 | if (filter(id)) { 12 | var transformed = flowRemoveTypes(code, options); 13 | return { 14 | code: transformed.toString(), 15 | map: transformed.generateMap() 16 | }; 17 | } 18 | } 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rollup-plugin-flow", 3 | "version": "1.1.1", 4 | "description": "Remove Flow type annotations before bundling.", 5 | "author": "Lee Byron (http://leebyron.com/)", 6 | "license": "BSD-3-Clause", 7 | "main": "index.js", 8 | "files": [ 9 | "index.js", 10 | "LICENSE" 11 | ], 12 | "homepage": "https://github.com/leebyron/rollup-plugin-flow", 13 | "bugs": { 14 | "url": "https://github.com/leebyron/rollup-plugin-flow/issues" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "http://github.com/leebyron/rollup-plugin-flow.git" 19 | }, 20 | "scripts": { 21 | "test": "DIFF=$(rollup -c test/rollup.config.js test/source.js | diff test/expected.js -); if [ -n \"$DIFF\" ]; then echo \"$DIFF\"; exit 1; fi;", 22 | "test-update": "rollup -c test/rollup.config.js test/source.js > test/expected.js" 23 | }, 24 | "keywords": [ 25 | "rollup-plugin", 26 | "flow", 27 | "flowtype", 28 | "strip" 29 | ], 30 | "dependencies": { 31 | "flow-remove-types": "^1.1.0", 32 | "rollup-pluginutils": "^1.5.1" 33 | }, 34 | "devDependencies": { 35 | "rollup": "^0.36.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/expected.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, '__esModule', { value: true }); 4 | 5 | var someModule = require('some-module'); 6 | 7 | /* */ 8 | 9 | class MyClass extends someModule.SomeClass { 10 | 11 | 12 | 13 | constructor(value ) { 14 | this.value = value; 15 | } 16 | 17 | get() { 18 | return this.value 19 | } 20 | 21 | } 22 | 23 | exports.MyClass = MyClass; 24 | -------------------------------------------------------------------------------- /test/rollup.config.js: -------------------------------------------------------------------------------- 1 | var flow = require('../'); 2 | 3 | module.exports = { 4 | plugins: [ flow() ], 5 | format: 'cjs' 6 | }; 7 | -------------------------------------------------------------------------------- /test/source.js: -------------------------------------------------------------------------------- 1 | /* @flow */ 2 | 3 | import { SomeClass } from 'some-module' 4 | import type { SomeInterface } from 'some-module' 5 | 6 | export class MyClass extends SomeClass implements SomeInterface { 7 | 8 | value: T 9 | 10 | constructor(value: T) { 11 | this.value = value 12 | } 13 | 14 | get(): T { 15 | return this.value 16 | } 17 | 18 | } 19 | --------------------------------------------------------------------------------