├── LICENSE ├── README.md ├── index.js └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Dan Abramov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This repo is deprecated, please migrate to [babel-plugin-tcomb](https://github.com/gcanti/babel-plugin-tcomb) which is now Flow compatible 2 | 3 | 4 | # flowcheck-loader 5 | 6 | This is a Webpack loader for **[Flowcheck](https://github.com/gcanti/flowcheck)**. 7 | 8 | Flowcheck is a **runtime assertions** library that uses **[Flow](http://flowtype.org)** syntax but is meant to be ran **in development**. 9 | 10 | ```sh 11 | npm install --save-dev flowcheck-loader 12 | ``` 13 | 14 | Chain this loader with **[jsx?stripTypes](https://github.com/petehunt/jsx-loader)** so types are stripped in JS code: 15 | 16 | ```js 17 | // Webpack config 18 | module.exports = { 19 | ... 20 | module: { 21 | loaders: [ 22 | { test: /\.jsx?$/, loaders: ['jsx?harmony&stripTypes', 'flowcheck'], exclude: /node_modules/ } 23 | ] 24 | } 25 | }; 26 | 27 | ``` 28 | 29 | For production builds, just leave `flowcheck` out so `jsx?stripTypes` strips them completely. 30 | 31 | You can use this with *or* without using Flow or TypeScript itself. 32 | It can also be a nice first step towards migrating code to Flow. 33 | 34 | **[Read more about Flowcheck](http://gcanti.github.io/flowcheck/)** 35 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var transformWithDetails = require('flowcheck/transform').transformWithDetails; 2 | var loaderUtils = require('loader-utils'); 3 | 4 | module.exports = function(source) { 5 | this.cacheable && this.cacheable(); 6 | 7 | var sourceFilename = loaderUtils.getRemainingRequest(this); 8 | var current = loaderUtils.getCurrentRequest(this); 9 | 10 | var transform = transformWithDetails(source, { 11 | sourceMap: this.sourceMap, 12 | namespace: "require('flowcheck/assert')" 13 | }); 14 | 15 | if (transform.sourceMap) { 16 | transform.sourceMap.sources = [sourceFilename]; 17 | transform.sourceMap.file = current; 18 | transform.sourceMap.sourcesContent = [source]; 19 | } 20 | 21 | this.callback(null, transform.code, transform.sourceMap); 22 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flowcheck-loader", 3 | "version": "1.0.0", 4 | "description": "A Webpack loader for Flowcheck", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/gaearon/flowcheck-loader.git" 9 | }, 10 | "keywords": [ 11 | "flowcheck", 12 | "flowtype", 13 | "static", 14 | "javascript", 15 | "facebook", 16 | "webpack" 17 | ], 18 | "author": "Dan Abramov (http://github.com/gaearon)", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/gaearon/flowcheck-loader/issues" 22 | }, 23 | "homepage": "https://github.com/gaearon/flowcheck-loader", 24 | "dependencies": { 25 | "loader-utils": "^0.2.2" 26 | }, 27 | "peerDependencies": { 28 | "flowcheck": "^0.2.0" 29 | } 30 | } 31 | --------------------------------------------------------------------------------