Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deps #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[ignore]
<PROJECT_ROOT>/lib
<PROJECT_ROOT>/node_modules/resolve/test

[include]

Expand Down
13 changes: 0 additions & 13 deletions flow-typed/npm/mkdirp_v0.5.x.js

This file was deleted.

25 changes: 25 additions & 0 deletions flow-typed/npm/mkdirp_v1.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// flow-typed signature: 28ddcca31abd597a77830710de25f5fe
// flow-typed version: a75473352d/mkdirp_v1.x.x/flow_>=v0.83.x

declare module 'mkdirp' {
import typeof { mkdir, stat } from 'fs';

declare type FsImplementation = {
+mkdir?: mkdir,
+stat?: stat,
...
};

declare type Options = number | string | {| mode?: number; fs?: FsImplementation |};

declare type Callback = (err: ?Error, path: ?string) => void;

declare module.exports: {|
(path: string, options?: Options | Callback): Promise<string| void>;
sync(path: string, options?: Options): string | void;
manual(path: string, options?: Options | Callback): Promise<string| void>;
manualSync(path: string, options?: Options): string | void;
native(path: string, options?: Options | Callback): Promise<string| void>;
nativeSync(path: string, options?: Options): string | void;
|};
}
19 changes: 8 additions & 11 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,14 @@ function createDirectoryForFile(source, output, filePath, verbose) {
console.info("Making sure directory " + source + " exists\u2026");
}

return new Promise(function (resolve, reject) {
(0, _mkdirp["default"])(outputDirectoryPath, function (err) {
if (err) {
reject(Error("Failed to create directory " + outputDirectoryPath));
}
return (0, _mkdirp["default"])(outputDirectoryPath).then(function () {
var fileName = _path["default"].basename(filePath);

var fileName = _path["default"].basename(filePath);
var outputFilePath = _path["default"].join(outputDirectoryPath, fileName);

var outputFilePath = _path["default"].join(outputDirectoryPath, fileName);

resolve(outputFilePath);
});
return outputFilePath;
})["catch"](function () {
throw Error("Failed to create directory " + outputDirectoryPath);
});
}
/**
Expand Down Expand Up @@ -340,7 +336,8 @@ send) {
*/


function transformJavascriptFile(filePath, outputFilePath, verbose, babelConfig) {
function transformJavascriptFile(filePath, outputFilePath, verbose, babelConfig // eslint-disable-line flowtype/no-weak-types
) {
/* eslint-disable flowtype/generic-spacing */
return getFileContents(filePath, verbose).then(function (contents) {
return new Promise(function (resolve, reject) {
Expand Down
27 changes: 10 additions & 17 deletions lib/worker.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,16 @@ function createDirectoryForFile(
console.info(`Making sure directory ${source} exists…`)
}

return new Promise(
(
resolve: (outputFilePath: string) => void,
reject: (err: Error) => void,
) => {
mkdirp(outputDirectoryPath, (err: ?Error) => {
if (err) {
reject(Error(`Failed to create directory ${outputDirectoryPath}`))
}
return mkdirp(outputDirectoryPath)
.then((): string => {
const fileName = path.basename(filePath)
const outputFilePath = path.join(outputDirectoryPath, fileName)

const fileName = path.basename(filePath)
const outputFilePath = path.join(outputDirectoryPath, fileName)

resolve(outputFilePath)
})
},
)
return outputFilePath
})
.catch(() => {
throw Error(`Failed to create directory ${outputDirectoryPath}`)
})
}

/**
Expand Down Expand Up @@ -435,7 +428,7 @@ function transformJavascriptFile(
transform(
contents,
Object.assign({filename: filePath}, babelConfig),
(err2: ?Error, result: {code: string}) => {
(err2: ?Error, result: {|code: string|}) => {
if (err2) {
if (verbose) {
console.error(`Failed to transform ${filePath}`)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"@babel/core": "^7.0.0",
"flow-bin": "0.116.1",
"glob": "^7.0.0",
"mkdirp": "0.5.1",
"mkdirp": "1.0.4",
"node-watch": "0.6.3",
"yargs": "^15.0.0"
}
}
}
63 changes: 63 additions & 0 deletions src/__tests__/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/** @flow */

/**
* @typedef Resolver
* An object used to control when a Promise is resolved/rejected
* @property {Function} resolve - resolve the promise
* @property {Function} reject - reject the promise
* @property {Promise} promise - the promise to resolve/reject
*/

type RejectFn = (error: any) => void
type ResolveFn<T> = (value: T) => void

function maybeUpdate(wrapper: any) {
if (wrapper) {
wrapper.update()
}
}

/**
* Create a Resolver instance
* @returns {Resolver} - the instance
*/
export default class Resolver<T> {
promise: Promise<T>
rawReject: RejectFn
rawResolve: ResolveFn<T>

constructor() {
this.promise = new Promise((resolve: ResolveFn<T>, reject: RejectFn) => {
this.rawResolve = resolve
this.rawReject = reject
})
}

/**
* Resolve the wrapped promise
* @param {*} resolution - the value to resolve with
* @param {Enzyme.Wrapper} [wrapper] - optional enzyme wrapper to update after resolving
* @returns {Promise} a chained promise from the wrapped one
*/
reject(rejection: any, wrapper: any): Promise<T> {
this.rawReject(rejection)
return this.promise.catch(err => {
maybeUpdate(wrapper)
return err
})
}

/**
* Resolve the wrapped promise
* @param {*} resolution - the value to resolve with
* @param {Enzyme.Wrapper} [wrapper] - optional enzyme wrapper to update after resolving
* @returns {Promise} a chained promise from the wrapped one
*/
resolve(resolution: T, wrapper: any): Promise<T> {
this.rawResolve(resolution)
return this.promise.then(resp => {
maybeUpdate(wrapper)
return resp
})
}
}
65 changes: 19 additions & 46 deletions src/__tests__/worker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import mkdirp from 'mkdirp'
import {Readable, Writable} from 'stream'
import {REMOVE_FILE, TRANSFORM_FILE} from '../actions'
import {worker} from '../worker'
import {Resolver} from './utils'

const TRANSFORM_OPTIONS = Object.freeze({
presets: [
Expand Down Expand Up @@ -160,10 +161,11 @@ function configTests(ctx, description, argv, readConfig, init) {
describe('when master sends message to transform file', () => {
it('functions as expected when it fails to create directory for file', done => {
const error = new Error('foo bar')
const resolver = new Resolver()

mkdirp.mockImplementation((...args) => {
const callback = args[args.length - 1]
callback(error)
mkdirp.mockImplementation(() => {
resolver.reject(error)
return resolver.promise
})

expect(ctx.listeners.message).toHaveLength(1)
Expand All @@ -181,9 +183,10 @@ function configTests(ctx, description, argv, readConfig, init) {

describe('when it successfully creates directory for file', () => {
beforeEach(() => {
mkdirp.mockImplementation((...args) => {
const callback = args[args.length - 1]
callback(null)
mkdirp.mockImplementation(() => {
const resolver = new Resolver()
resolver.resolve('')
return resolver.promise
})
})

Expand Down Expand Up @@ -453,10 +456,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -533,10 +533,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -620,10 +617,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -707,10 +701,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -774,10 +765,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -856,10 +844,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -935,10 +920,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -1021,10 +1003,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -1107,10 +1086,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down Expand Up @@ -1173,10 +1149,7 @@ function configTests(ctx, description, argv, readConfig, init) {

it('should make expected directory', () => {
expect(mkdirp).toHaveBeenCalledTimes(1)
expect(mkdirp).lastCalledWith(
'/bar/alpha',
expect.any(Function),
)
expect(mkdirp).lastCalledWith('/bar/alpha')
})

// TODO: process.on
Expand Down
27 changes: 10 additions & 17 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,16 @@ function createDirectoryForFile(
console.info(`Making sure directory ${source} exists…`)
}

return new Promise(
(
resolve: (outputFilePath: string) => void,
reject: (err: Error) => void,
) => {
mkdirp(outputDirectoryPath, (err: ?Error) => {
if (err) {
reject(Error(`Failed to create directory ${outputDirectoryPath}`))
}
return mkdirp(outputDirectoryPath)
.then((): string => {
const fileName = path.basename(filePath)
const outputFilePath = path.join(outputDirectoryPath, fileName)

const fileName = path.basename(filePath)
const outputFilePath = path.join(outputDirectoryPath, fileName)

resolve(outputFilePath)
})
},
)
return outputFilePath
})
.catch(() => {
throw Error(`Failed to create directory ${outputDirectoryPath}`)
})
}

/**
Expand Down Expand Up @@ -435,7 +428,7 @@ function transformJavascriptFile(
transform(
contents,
Object.assign({filename: filePath}, babelConfig),
(err2: ?Error, result: {code: string}) => {
(err2: ?Error, result: {|code: string|}) => {
if (err2) {
if (verbose) {
console.error(`Failed to transform ${filePath}`)
Expand Down
Loading