diff --git a/.travis.yml b/.travis.yml index e848ec6..78a57c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ sudo: false language: node_js node_js: + - "12" - "10" - "8" - "6" diff --git a/LICENSE b/LICENSE index 084338a..03c083c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright (c) Tobias Koppers @sokra +Copyright JS Foundation and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/__tests__/AsyncParallelHooks.js b/lib/__tests__/AsyncParallelHooks.js index c762fad..c1caf95 100644 --- a/lib/__tests__/AsyncParallelHooks.js +++ b/lib/__tests__/AsyncParallelHooks.js @@ -9,29 +9,21 @@ const AsyncParallelHook = require("../AsyncParallelHook"); const AsyncParallelBailHook = require("../AsyncParallelBailHook"); describe("AsyncParallelHook", () => { - it( - "should have to correct behavior", - async () => { - const tester = new HookTester(args => new AsyncParallelHook(args)); + it("should have to correct behavior", async () => { + const tester = new HookTester(args => new AsyncParallelHook(args)); - const result = await tester.run(); + const result = await tester.run(); - expect(result).toMatchSnapshot(); - }, - 15000 - ); + expect(result).toMatchSnapshot(); + }, 15000); }); describe("AsyncParallelBailHook", () => { - it( - "should have to correct behavior", - async () => { - const tester = new HookTester(args => new AsyncParallelBailHook(args)); + it("should have to correct behavior", async () => { + const tester = new HookTester(args => new AsyncParallelBailHook(args)); - const result = await tester.run(); + const result = await tester.run(); - expect(result).toMatchSnapshot(); - }, - 15000 - ); + expect(result).toMatchSnapshot(); + }, 15000); }); diff --git a/lib/__tests__/SyncHooks.js b/lib/__tests__/SyncHooks.js index a5d04b4..cc36387 100644 --- a/lib/__tests__/SyncHooks.js +++ b/lib/__tests__/SyncHooks.js @@ -11,57 +11,41 @@ const SyncWaterfallHook = require("../SyncWaterfallHook"); const SyncLoopHook = require("../SyncLoopHook"); describe("SyncHook", () => { - it( - "should have to correct behavior", - async () => { - const tester = new HookTester(args => new SyncHook(args)); + it("should have to correct behavior", async () => { + const tester = new HookTester(args => new SyncHook(args)); - const result = await tester.run(true); + const result = await tester.run(true); - expect(result).toMatchSnapshot(); - }, - 15000 - ); + expect(result).toMatchSnapshot(); + }, 15000); }); describe("SyncBailHook", () => { - it( - "should have to correct behavior", - async () => { - const tester = new HookTester(args => new SyncBailHook(args)); + it("should have to correct behavior", async () => { + const tester = new HookTester(args => new SyncBailHook(args)); - const result = await tester.run(true); + const result = await tester.run(true); - expect(result).toMatchSnapshot(); - }, - 15000 - ); + expect(result).toMatchSnapshot(); + }, 15000); }); describe("SyncWaterfallHook", () => { - it( - "should have to correct behavior", - async () => { - const tester = new HookTester(args => new SyncWaterfallHook(args)); + it("should have to correct behavior", async () => { + const tester = new HookTester(args => new SyncWaterfallHook(args)); - const result = await tester.run(true); + const result = await tester.run(true); - expect(result).toMatchSnapshot(); - }, - 15000 - ); + expect(result).toMatchSnapshot(); + }, 15000); }); describe("SyncLoopHook", () => { - it( - "should have to correct behavior", - async () => { - const tester = new HookTester(args => new SyncLoopHook(args)); + it("should have to correct behavior", async () => { + const tester = new HookTester(args => new SyncLoopHook(args)); - const result = await tester.runForLoop(true); + const result = await tester.runForLoop(true); - expect(result).toMatchSnapshot(); - }, - 15000 - ); + expect(result).toMatchSnapshot(); + }, 15000); }); diff --git a/package.json b/package.json index d64c4b6..02dd8cd 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,9 @@ "types": "./tapable.d.ts", "scripts": { "test": "jest", - "travis": "jest --coverage && codecov", - "pretty": "prettier --write lib/*.js lib/__tests__/*.js" + "travis": "yarn pretty-lint && jest --coverage && codecov", + "pretty-lint": "prettier --check lib/*.js lib/__tests__/*.js", + "pretty": "prettier --loglevel warn --write lib/*.js lib/__tests__/*.js" }, "jest": { "transform": { diff --git a/tapable.d.ts b/tapable.d.ts index 540de79..57a5246 100644 --- a/tapable.d.ts +++ b/tapable.d.ts @@ -18,6 +18,7 @@ type Append = { 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U]; 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U]; }[Measure]; +type AsArray = T extends any[] ? T : [T]; type Callback = (error?: E, result?: T) => void; @@ -40,44 +41,41 @@ interface HookInterceptor { type ArgumentNames = FixedSizeArray; -declare class Hook { - constructor(args?: ArgumentNames); +declare class Hook { + constructor(args?: ArgumentNames>); intercept(interceptor: HookInterceptor>): void; isUsed(): boolean; - callAsync(...args: Append>): void; - promise(...args: T): Promise; - tap(options: string | Tap, fn: (...args: T) => R): void; + callAsync(...args: Append, Callback>): void; + promise(...args: AsArray): Promise; + tap(options: string | Tap, fn: (...args: AsArray) => R): void; withOptions(options: TapOptions): Hook; } -export class SyncHook extends Hook { - call(...args: T): R; +export class SyncHook extends Hook { + call(...args: AsArray): R; } -export class SyncBailHook extends SyncHook {} -export class SyncLoopHook extends SyncHook {} -export class SyncWaterfallHook extends SyncHook {} +export class SyncBailHook extends SyncHook {} +export class SyncLoopHook extends SyncHook {} +export class SyncWaterfallHook extends SyncHook[0]> {} -declare class AsyncHook extends Hook { +declare class AsyncHook extends Hook { tapAsync( options: string | Tap, - fn: (...args: Append>) => void + fn: (...args: Append, Callback>) => void + ): void; + tapPromise( + options: string | Tap, + fn: (...args: AsArray) => Promise ): void; - tapPromise(options: string | Tap, fn: (...args: T) => Promise): void; } -export class AsyncParallelHook extends AsyncHook {} -export class AsyncParallelBailHook extends AsyncHook< - T, - R -> {} -export class AsyncSeriesHook extends AsyncHook {} -export class AsyncSeriesBailHook extends AsyncHook {} -export class AsyncSeriesLoopHook extends AsyncHook {} -export class AsyncSeriesWaterfallHook extends AsyncHook< - T, - T[0] -> {} +export class AsyncParallelHook extends AsyncHook {} +export class AsyncParallelBailHook extends AsyncHook {} +export class AsyncSeriesHook extends AsyncHook {} +export class AsyncSeriesBailHook extends AsyncHook {} +export class AsyncSeriesLoopHook extends AsyncHook {} +export class AsyncSeriesWaterfallHook extends AsyncHook[0]> {} type HookFactory = (key: any, hook?: H) => H;