diff --git a/dist/getFilepathsFromGlob.js b/dist/getFilepathsFromGlob.js new file mode 100644 index 0000000..3fbea54 --- /dev/null +++ b/dist/getFilepathsFromGlob.js @@ -0,0 +1,22 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = getFilepathsFromGlob; +function getFilepathsFromGlob(baseDir, options) { + const extensions = options.extensions, + include = options.include, + exclude = options.exclude; + + const patterns = include.map(inc => `${inc}/*.+(${extensions.join('|')})`); + + // $FlowFixMe(site=react_native_fb,www) + const glob = require('fast-glob'); + return glob.sync(patterns, { + cwd: baseDir, + bashNative: [], + onlyFiles: true, + ignore: exclude + }); +} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index b73deb8..8ea7802 100644 --- a/dist/index.js +++ b/dist/index.js @@ -22,6 +22,10 @@ var _buildWatchmanExpression = require('./buildWatchmanExpression'); var _buildWatchmanExpression2 = _interopRequireDefault(_buildWatchmanExpression); +var _getFilepathsFromGlob = require('./getFilepathsFromGlob'); + +var _getFilepathsFromGlob2 = _interopRequireDefault(_getFilepathsFromGlob); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } @@ -36,7 +40,8 @@ class RelayCompilerWebpackPlugin { getFileFilter: _getFileFilter2.default, getParser: _relayCompiler.FileIRParser.getParser, getSchema: () => {}, - watchmanExpression: [] + watchmanExpression: null, + filepaths: null } }; this.writerConfigs = { @@ -68,14 +73,18 @@ class RelayCompilerWebpackPlugin { throw new Error('Could not find your `src` path. Have you provided a fully resolved path?'); } - this.parserConfigs.default.baseDir = options.src; - this.parserConfigs.default.schema = options.schema; - this.parserConfigs.default.getSchema = () => (0, _getSchema2.default)(options.schema); - this.parserConfigs.default.watchmanExpression = (0, _buildWatchmanExpression2.default)({ + const watchman = options.watchman !== undefined ? options.watchman : true; + const fileOptions = { extensions: ['js'], include: ['**'], exclude: ['**/node_modules/**', '**/__mocks__/**', '**/__tests__/**', '**/__generated__/**'] - }); + }; + + this.parserConfigs.default.baseDir = options.src; + this.parserConfigs.default.schema = options.schema; + this.parserConfigs.default.getSchema = () => (0, _getSchema2.default)(options.schema); + this.parserConfigs.default.watchmanExpression = options.watchman ? (0, _buildWatchmanExpression2.default)(fileOptions) : null; + this.parserConfigs.default.filepaths = options.watchman ? null : (0, _getFilepathsFromGlob2.default)(options.src, fileOptions); this.writerConfigs.default.getWriter = (0, _getWriter2.default)(options.src); diff --git a/package.json b/package.json index 1075a2f..1297d9c 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "babel-preset-stage-1": "^6.24.1", "flow-bin": "^0.44.2", "graphql": "^0.9.3", - "relay-compiler": "1.1.0", + "relay-compiler": "^1.2.0", "rimraf": "^2.6.1", "webpack": "^2.4.1" }, diff --git a/src/getFilepathsFromGlob.js b/src/getFilepathsFromGlob.js new file mode 100644 index 0000000..6a4fdbd --- /dev/null +++ b/src/getFilepathsFromGlob.js @@ -0,0 +1,20 @@ +export default function getFilepathsFromGlob( + baseDir, + options: { + extensions: Array, + include: Array, + exclude: Array, + }, +): Array { + const {extensions, include, exclude} = options; + const patterns = include.map(inc => `${inc}/*.+(${extensions.join('|')})`); + + // $FlowFixMe(site=react_native_fb,www) + const glob = require('fast-glob'); + return glob.sync(patterns, { + cwd: baseDir, + bashNative: [], + onlyFiles: true, + ignore: exclude, + }); +} diff --git a/src/index.js b/src/index.js index 6002fd2..b386603 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,7 @@ import getSchema from './getSchema' import getFileFilter from './getFileFilter' import getWriter from './getWriter' import buildWatchmanExpression from './buildWatchmanExpression' +import getFilepathsFromGlob from './getFilepathsFromGlob' import type { Compiler } from 'webpack' @@ -18,7 +19,8 @@ class RelayCompilerWebpackPlugin { getFileFilter, getParser: FileIRParser.getParser, getSchema: () => {}, - watchmanExpression: [], + watchmanExpression: null, + filepaths: null, }, } @@ -36,6 +38,7 @@ class RelayCompilerWebpackPlugin { constructor (options: { schema: string, src: string, + watchman: boolean, }) { if (!options) { throw new Error('You must provide options to RelayCompilerWebpackPlugin.') @@ -57,10 +60,8 @@ class RelayCompilerWebpackPlugin { throw new Error('Could not find your `src` path. Have you provided a fully resolved path?') } - this.parserConfigs.default.baseDir = options.src - this.parserConfigs.default.schema = options.schema - this.parserConfigs.default.getSchema = () => getSchema(options.schema) - this.parserConfigs.default.watchmanExpression = buildWatchmanExpression({ + const watchman = options.watchman !== undefined ? options.watchman : true + const fileOptions = { extensions: [ 'js' ], include: [ '**' ], exclude: [ @@ -69,7 +70,13 @@ class RelayCompilerWebpackPlugin { '**/__tests__/**', '**/__generated__/**', ], - }) + } + + this.parserConfigs.default.baseDir = options.src + this.parserConfigs.default.schema = options.schema + this.parserConfigs.default.getSchema = () => getSchema(options.schema) + this.parserConfigs.default.watchmanExpression = options.watchman ? buildWatchmanExpression(fileOptions) : null + this.parserConfigs.default.filepaths = options.watchman ? null : getFilepathsFromGlob(options.src, fileOptions) this.writerConfigs.default.getWriter = getWriter(options.src)