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

Add TypeScript typings for core & webpack #247

Open
wants to merge 3 commits into
base: release-2.0
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
30 changes: 30 additions & 0 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Type definitions for @webpack-blocks/core 1.0.0
// Project: webpack-blocks
// Definitions by: Stephan Schneider <https://github.com/zcei>

import { Configuration as WebpackConfig, Condition, Rule, Plugin } from 'webpack'

export function createConfig(configSetter: Block[]): object
export function group(configSetters: Block[]): Block
export function env(envName: string, configSetters: Block[]): Block
export function match(test: Condition | Condition[], configSetters: Block[]): Block
export function when(condition: boolean, configSetter: Block[]): Block

export interface BlockCreator {
(...args: any[]): Block
}

export interface Block {
(context: Object, util: WebpackBlockUtils): WebpackConfigUpdater
}

export interface WebpackConfigUpdater {
(previousConfig: WebpackConfig): WebpackConfig
}

/*~ You can declare types that are available via importing the module */
export interface WebpackBlockUtils {
merge: (configSnippet: WebpackConfig) => WebpackConfigUpdater
addLoader: (loader: Rule) => WebpackConfigUpdater
addPlugin: (plugin: Plugin) => WebpackConfigUpdater
}
25 changes: 25 additions & 0 deletions packages/tslint/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Type definitions for @webpack-blocks/tslint 1.0.0
// Project: webpack-blocks
// Definitions by: Stephan Schneider <https://github.com/zcei>

import { Block } from '@webpack-blocks/core'
import { Configuration, ILinterOptions } from 'tslint'


type TSLintLoaderOptions = ILinterOptions & {
configuration: Configuration.IConfigurationFile
tsConfigFile: string
typeCheck: boolean
emitErrors: boolean
failOnHint: boolean
fileOutput: {
dir: string
ext: string
clean: boolean
header: string
footer: string
}
}

declare function tslint(options: TSLintLoaderOptions): Block
export = tslint
10 changes: 10 additions & 0 deletions packages/typescript/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Type definitions for @webpack-blocks/typescript 1.0.0
// Project: webpack-blocks
// Definitions by: Stephan Schneider <https://github.com/zcei>

import { Block } from '@webpack-blocks/core'

import { LoaderConfig } from 'awesome-typescript-loader/dist/interfaces'

declare function typescript (options: LoaderConfig): Block
export = typescript
27 changes: 27 additions & 0 deletions packages/webpack/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Type definitions for @webpack-blocks/webpack 1.0.0
// Project: webpack-blocks
// Definitions by: Stephan Schneider <https://github.com/zcei>

import {
createConfig,
group,
env,
match,
Block,
WebpackConfigUpdater
} from '@webpack-blocks/core'
import { Configuration, Plugin, Entry, Options, Resolve, Output } from 'webpack'
export { createConfig, group, env, match }

export function addPlugins(plugins: Plugin[]): Block
export function customConfig(configSnippet: Configuration): Block
export function defineConstants(constants: { [key: string]: any }): Block
export function setEnv(envs: string[] | { [key: string]: any }): Block
// TODO: support EntryFunc
export function entryPoint(entry: string | string[] | Entry): Block
export function performance(perfBudgetOptions: Options.Performance): Block
export function resolve(config: Resolve): Block
export function setContext(path: string): Block
export function setDevTool(devtool: Options.Devtool): Block
export function setOutput(output: string | Output): Block
export function sourceMaps(devtool?: Options.Devtool): Block