diff --git a/types/circular-dependency-plugin/circular-dependency-plugin-tests.ts b/types/circular-dependency-plugin/circular-dependency-plugin-tests.ts new file mode 100644 index 0000000000..8c627651e7 --- /dev/null +++ b/types/circular-dependency-plugin/circular-dependency-plugin-tests.ts @@ -0,0 +1,29 @@ +import * as CircularDependencyPlugin from 'circular-dependency-plugin'; +import * as webpack from 'webpack'; + +new CircularDependencyPlugin(); +new CircularDependencyPlugin({}); + +const MAX_CYCLES = 5; +let numCyclesDetected = 0; + +new CircularDependencyPlugin({ + allowAsyncCycles: false, + cwd: process.cwd(), + exclude: /a\.js|node_modules/, + failOnError: true, + onDetected({ module: webpackModuleRecord, paths, compilation }) { + numCyclesDetected++; + compilation.warnings.push(new Error(paths.join(' -> '))); + }, + onStart({ compilation }) { + numCyclesDetected = 0; + }, + onEnd({ compilation }) { + if (numCyclesDetected > MAX_CYCLES) { + compilation.errors.push(new Error('Too many cycles')); + } + }, +}); + +webpack({ plugins: [new CircularDependencyPlugin()] }); diff --git a/types/circular-dependency-plugin/index.d.ts b/types/circular-dependency-plugin/index.d.ts new file mode 100644 index 0000000000..89c14b0ec0 --- /dev/null +++ b/types/circular-dependency-plugin/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for circular-dependency-plugin 5.0 +// Project: https://github.com/aackerman/circular-dependency-plugin +// Definitions by: Olegs Jeremejevs +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { Plugin, Module, compilation } from 'webpack'; + +export = CircularDependencyPlugin; + +declare class CircularDependencyPlugin extends Plugin { + constructor(options?: CircularDependencyPlugin.Options); + // Not exposing `isCyclic` because it isn't meant to be public, I believe +} + +declare namespace CircularDependencyPlugin { + interface Options { + allowAsyncCycles?: boolean; + cwd?: string; + exclude?: RegExp; + failOnError?: boolean; + onDetected?: (x: { + module: Module; + paths: string[]; + compilation: compilation.Compilation; + }) => void; + onEnd?: (x: { compilation: compilation.Compilation }) => void; + onStart?: (x: { compilation: compilation.Compilation }) => void; + } +} diff --git a/types/circular-dependency-plugin/tsconfig.json b/types/circular-dependency-plugin/tsconfig.json new file mode 100644 index 0000000000..476eb673dd --- /dev/null +++ b/types/circular-dependency-plugin/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "circular-dependency-plugin-tests.ts" + ] +} diff --git a/types/circular-dependency-plugin/tslint.json b/types/circular-dependency-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/circular-dependency-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }