Skip to content

Commit e2cc49b

Browse files
committed
Duplicate webpack-dev-server types instead of importing them
1 parent 3d007f3 commit e2cc49b

3 files changed

Lines changed: 43 additions & 253 deletions

File tree

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
"path-complete-extname": "^1.0.0"
2828
},
2929
"devDependencies": {
30-
"@types/webpack-dev-middleware": "5.0.2",
31-
"@types/webpack-dev-server": "4.5.1",
3230
"babel-loader": "^8.2.4",
3331
"compression-webpack-plugin": "^9.0.0",
3432
"esbuild-loader": "^2.18.0",
@@ -56,6 +54,7 @@
5654
"@babel/preset-env": "^7.16.11",
5755
"@babel/runtime": "^7.17.9",
5856
"@types/babel__core": "^7.0.0",
57+
"@types/webpack": "^5.0.0",
5958
"babel-loader": "^8.2.4 || ^9.0.0 || ^10.0.0",
6059
"compression-webpack-plugin": "^9.0.0 || ^10.0.0|| ^11.0.0",
6160
"terser-webpack-plugin": "^5.3.1",
@@ -68,6 +67,9 @@
6867
"peerDependenciesMeta": {
6968
"@types/babel__core": {
7069
"optional": true
70+
},
71+
"@types/webpack": {
72+
"optional": true
7173
}
7274
},
7375
"packageManager": "[email protected]",

package/index.d.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare module 'shakapacker' {
22
import { Configuration, RuleSetRule } from 'webpack'
3-
import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server'
3+
import * as https from 'node:https';
44

55
export interface Config {
66
source_path: string
@@ -33,18 +33,40 @@ declare module 'shakapacker' {
3333
runningWebpackDevServer: boolean
3434
}
3535

36-
type CamelToSnakeCase<S extends string> = S extends `${infer First}${infer Rest}`
37-
? Rest extends Uncapitalize<Rest> // Check if `Rest` starts with a lowercase letter
38-
? `${Lowercase<First>}${CamelToSnakeCase<Rest>}`
39-
: `${Lowercase<First>}_${CamelToSnakeCase<Uncapitalize<Rest>>}`
40-
: S
36+
type Header = Array<{ key: string; value: string }> | Record<string, string | string[]>
37+
type ServerType = 'http' | 'https' | 'spdy'
38+
type WebSocketType = 'sockjs' | 'ws'
4139

42-
type SnakeCase<T> = {
43-
[K in keyof T as CamelToSnakeCase<string & K>]: T[K];
44-
}
45-
46-
type DevServerConfig = SnakeCase<Omit<WebpackDevServerConfiguration, 'hot'>> & {
47-
hmr?: boolean
40+
/**
41+
* This has the same keys and behavior as https://webpack.js.org/configuration/dev-server/ except:
42+
* 1. `hot` is replaced by `hmr`;
43+
* 2. Camel-cased properties are replaced by snake-cased ones.
44+
* @see {import('webpack-dev-server').Configuration}
45+
*/
46+
interface DevServerConfig {
47+
allowed_hosts?: 'all' | 'auto' | string | string[]
48+
bonjour?: boolean | Record<string, unknown> // bonjour.BonjourOptions
49+
client?: Record<string, unknown> // Client
50+
compress?: boolean
51+
dev_middleware?: Record<string, unknown> // webpackDevMiddleware.Options
52+
headers?: Header | (() => Header)
53+
history_api_fallback?: boolean | Record<string, unknown> // HistoryApiFallbackOptions
54+
hmr?: 'only' | boolean
55+
host?: 'local-ip' | 'local-ipv4' | 'local-ipv6' | string
56+
http2?: boolean
57+
https?: boolean | https.ServerOptions
58+
ipc?: boolean | string
59+
magic_html?: boolean
60+
live_reload?: boolean
61+
open?: boolean | string | string[] | Record<string, unknown> | Record<string, unknown>[]
62+
port?: 'auto' | string | number
63+
proxy?: unknown // ProxyConfigMap | ProxyConfigArray
64+
setup_exit_signals?: boolean
65+
static?: boolean | string | unknown // Static | Array<string | Static>
66+
watch_files?: string | string[] | unknown // WatchFiles | Array<WatchFiles | string>
67+
web_socket_server?: string | boolean | WebSocketType | { type?: string | boolean | WebSocketType, options?: Record<string, unknown> }
68+
server?: string | boolean | ServerType | { type?: string | boolean | ServerType, options?: https.ServerOptions }
69+
[otherWebpackDevServerConfigKey: string]: unknown
4870
}
4971

5072
export const config: Config

0 commit comments

Comments
 (0)