Skip to content

Commit

Permalink
Merge pull request #2 from sthomas1618/optional_watchman
Browse files Browse the repository at this point in the history
Optional watchman
  • Loading branch information
danielholmes authored Aug 31, 2017
2 parents 67a794c + 43fb603 commit 85eac1b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 13 deletions.
22 changes: 22 additions & 0 deletions dist/getFilepathsFromGlob.js
Original file line number Diff line number Diff line change
@@ -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
});
}
21 changes: 15 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }); }; }
Expand All @@ -36,7 +40,8 @@ class RelayCompilerWebpackPlugin {
getFileFilter: _getFileFilter2.default,
getParser: _relayCompiler.FileIRParser.getParser,
getSchema: () => {},
watchmanExpression: []
watchmanExpression: null,
filepaths: null
}
};
this.writerConfigs = {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
20 changes: 20 additions & 0 deletions src/getFilepathsFromGlob.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default function getFilepathsFromGlob(
baseDir,
options: {
extensions: Array<string>,
include: Array<string>,
exclude: Array<string>,
},
): Array<string> {
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,
});
}
19 changes: 13 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -18,7 +19,8 @@ class RelayCompilerWebpackPlugin {
getFileFilter,
getParser: FileIRParser.getParser,
getSchema: () => {},
watchmanExpression: [],
watchmanExpression: null,
filepaths: null,
},
}

Expand All @@ -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.')
Expand All @@ -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: [
Expand All @@ -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)

Expand Down

0 comments on commit 85eac1b

Please sign in to comment.