webpack-dev-service 0.8.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +26 -35
  2. package/{server/cjs → cjs/server}/index.cjs +17 -7
  3. package/package.json +23 -34
  4. package/types/client/client.d.ts +1 -1
  5. package/types/client/events.d.ts +6 -6
  6. package/types/client/message.d.ts +6 -5
  7. package/types/client/ui/overlay.d.ts +1 -1
  8. package/types/server/dev/Service.d.ts +82 -0
  9. package/types/server/dev/index.d.ts +4 -4
  10. package/types/server/dev/interface.d.ts +26 -34
  11. package/types/server/dev/utils/fs.d.ts +27 -0
  12. package/types/server/dev/utils/hash.d.ts +9 -0
  13. package/types/server/dev/utils/http.d.ts +31 -14
  14. package/types/server/dev/utils/path.d.ts +22 -0
  15. package/types/server/dev/utils/paths.d.ts +7 -0
  16. package/types/server/dev/utils/ready.d.ts +2 -2
  17. package/types/server/hot/Socket.d.ts +6 -10
  18. package/types/server/hot/index.d.ts +4 -9
  19. package/types/server/hot/interface.d.ts +20 -0
  20. package/types/server/hot/utils.d.ts +13 -0
  21. package/types/server/index.d.ts +8 -8
  22. package/types/server/interface.d.ts +9 -0
  23. package/types/server/schema.d.ts +7 -0
  24. package/types/server/utils.d.ts +12 -0
  25. package/client/cjs/client.cjs +0 -129
  26. package/client/cjs/events.cjs +0 -64
  27. package/client/cjs/hot.cjs +0 -111
  28. package/client/cjs/index.cjs +0 -15
  29. package/client/cjs/main.cjs +0 -78
  30. package/client/cjs/ui/overlay.cjs +0 -233
  31. package/client/cjs/ui/progress.cjs +0 -92
  32. package/client/cjs/ui/utils.cjs +0 -136
  33. package/client/esm/client.js +0 -127
  34. package/client/esm/events.js +0 -60
  35. package/client/esm/hot.js +0 -106
  36. package/client/esm/index.js +0 -10
  37. package/client/esm/main.js +0 -76
  38. package/client/esm/ui/overlay.js +0 -231
  39. package/client/esm/ui/progress.js +0 -90
  40. package/client/esm/ui/utils.js +0 -123
  41. package/global.d.ts +0 -16
  42. package/server/cjs/dev/Files.cjs +0 -394
  43. package/server/cjs/dev/index.cjs +0 -62
  44. package/server/cjs/dev/middleware.cjs +0 -69
  45. package/server/cjs/dev/utils/boundary.cjs +0 -42
  46. package/server/cjs/dev/utils/common.cjs +0 -98
  47. package/server/cjs/dev/utils/compose.cjs +0 -58
  48. package/server/cjs/dev/utils/getPaths.cjs +0 -71
  49. package/server/cjs/dev/utils/http.cjs +0 -69
  50. package/server/cjs/dev/utils/ready.cjs +0 -26
  51. package/server/cjs/dev/utils/setupHooks.cjs +0 -95
  52. package/server/cjs/dev/utils/setupOutputFileSystem.cjs +0 -64
  53. package/server/cjs/dev/utils/setupWatching.cjs +0 -43
  54. package/server/cjs/dev/utils/setupWriteToDisk.cjs +0 -62
  55. package/server/cjs/hot/Socket.cjs +0 -197
  56. package/server/cjs/hot/index.cjs +0 -36
  57. package/server/esm/dev/Files.js +0 -384
  58. package/server/esm/dev/index.js +0 -60
  59. package/server/esm/dev/middleware.js +0 -67
  60. package/server/esm/dev/utils/boundary.js +0 -40
  61. package/server/esm/dev/utils/common.js +0 -98
  62. package/server/esm/dev/utils/compose.js +0 -56
  63. package/server/esm/dev/utils/getPaths.js +0 -69
  64. package/server/esm/dev/utils/http.js +0 -65
  65. package/server/esm/dev/utils/ready.js +0 -24
  66. package/server/esm/dev/utils/setupHooks.js +0 -87
  67. package/server/esm/dev/utils/setupOutputFileSystem.js +0 -62
  68. package/server/esm/dev/utils/setupWatching.js +0 -41
  69. package/server/esm/dev/utils/setupWriteToDisk.js +0 -60
  70. package/server/esm/hot/Socket.js +0 -188
  71. package/server/esm/hot/index.js +0 -34
  72. package/server/esm/index.js +0 -27
  73. package/types/server/dev/Files.d.ts +0 -83
  74. package/types/server/dev/utils/boundary.d.ts +0 -8
  75. package/types/server/dev/utils/common.d.ts +0 -44
  76. package/types/server/dev/utils/getPaths.d.ts +0 -10
  77. /package/types/server/{dev/utils/compose.d.ts → compose.d.ts} +0 -0
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ### Usage
14
14
 
15
- ```js
15
+ ```ts
16
16
  /**
17
17
  * @module webpack
18
18
  * @description Webpack config
@@ -22,6 +22,7 @@ import Koa from 'koa';
22
22
  import path from 'path';
23
23
  import memfs from 'memfs';
24
24
  import webpack from 'webpack';
25
+ import compress from 'koa-compress';
25
26
  import dev from 'webpack-dev-service';
26
27
  import HtmlWebpackPlugin from 'html-webpack-plugin';
27
28
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
@@ -39,7 +40,7 @@ const html = {
39
40
  filename: entryHTML,
40
41
  templateParameters: { lang: 'en' },
41
42
  template: path.resolve('index.ejs'),
42
- favicon: path.resolve('src/logo.svg'),
43
+ favicon: path.resolve('src/images/favicon.ico'),
43
44
  meta: { 'theme-color': '#4285f4', viewport: 'width=device-width,initial-scale=1.0' }
44
45
  };
45
46
 
@@ -47,8 +48,6 @@ function createMemfs() {
47
48
  const volume = new memfs.Volume();
48
49
  const fs = memfs.createFsFromVolume(volume);
49
50
 
50
- fs.join = path.join.bind(path);
51
-
52
51
  return fs;
53
52
  }
54
53
 
@@ -60,16 +59,10 @@ const compiler = webpack({
60
59
  name: 'react',
61
60
  mode: 'development',
62
61
  context: path.resolve('src'),
63
- entry: [
64
- // Entry file
65
- path.resolve('src/index.jsx'),
66
- // Hot client
67
- 'webpack-dev-service/client'
68
- ],
62
+ entry: path.resolve('src/index.tsx'),
69
63
  output: {
70
64
  publicPath: '/public/',
71
65
  filename: `js/[name].js`,
72
- hashFunction: 'xxhash64',
73
66
  path: path.resolve('public'),
74
67
  chunkFilename: `js/[name].js`,
75
68
  assetModuleFilename: `[path][name][ext]`
@@ -77,7 +70,7 @@ const compiler = webpack({
77
70
  devtool: 'eval-cheap-module-source-map',
78
71
  resolve: {
79
72
  fallback: { url: false },
80
- extensions: ['.js', '.jsx']
73
+ extensions: ['.ts', '.tsx', '.js', '.jsx']
81
74
  },
82
75
  watchOptions: {
83
76
  aggregateTimeout: 256
@@ -90,20 +83,28 @@ const compiler = webpack({
90
83
  runtimeModules: false,
91
84
  dependentModules: false
92
85
  },
86
+ plugins: [
87
+ new HtmlWebpackPlugin(html),
88
+ new MiniCssExtractPlugin({
89
+ ignoreOrder: true,
90
+ filename: 'css/[name].css',
91
+ chunkFilename: 'css/[name].css'
92
+ }),
93
+ new webpack.ProgressPlugin(progress)
94
+ ],
93
95
  module: {
94
96
  strictExportPresence: true,
95
97
  rules: [
96
98
  {
97
99
  oneOf: [
98
100
  {
99
- test: /\.jsx?$/i,
101
+ test: /\.[jt]sx?$/i,
100
102
  exclude: /[\\/]node_modules[\\/]/,
101
103
  use: [
102
104
  {
103
105
  loader: 'swc-loader',
104
106
  options: {
105
107
  jsc: {
106
- target: 'es2015',
107
108
  externalHelpers: true,
108
109
  parser: {
109
110
  tsx: true,
@@ -113,9 +114,6 @@ const compiler = webpack({
113
114
  react: {
114
115
  runtime: 'automatic'
115
116
  }
116
- },
117
- experimental: {
118
- cacheRoot: path.resolve('node_modules/.cache/swc')
119
117
  }
120
118
  },
121
119
  env: {
@@ -146,40 +144,33 @@ const compiler = webpack({
146
144
  ]
147
145
  },
148
146
  {
149
- test: /\.svg$/i,
147
+ test: /\.(svg|mp4)$/i,
150
148
  type: 'asset/resource',
151
149
  exclude: /[\\/]node_modules[\\/]/
152
150
  }
153
151
  ]
154
152
  }
155
153
  ]
156
- },
157
- plugins: [
158
- new webpack.ProgressPlugin(progress),
159
- new HtmlWebpackPlugin(html),
160
- new MiniCssExtractPlugin({
161
- ignoreOrder: true,
162
- filename: 'css/[name].css',
163
- chunkFilename: 'css/[name].css'
164
- })
165
- ]
154
+ }
166
155
  });
167
156
 
168
157
  const port = 8000;
169
158
  const app = new Koa();
170
159
  const fs = createMemfs();
171
160
  const server = dev(compiler, {
172
- outputFileSystem: fs,
161
+ fs,
173
162
  headers: {
174
- 'Cache-Control': 'no-store',
175
- 'Access-Control-Allow-Origin': '*',
176
- 'Access-Control-Allow-Methods': '*',
177
- 'Access-Control-Allow-Headers': '*',
178
- 'X-Content-Type-Options': 'nosniff',
179
- 'Access-Control-Allow-Credentials': 'true'
163
+ 'Cache-Control': 'no-cache',
164
+ 'X-Content-Type-Options': 'nosniff'
180
165
  }
181
166
  });
182
167
 
168
+ app.use(
169
+ compress({
170
+ br: false
171
+ })
172
+ );
173
+
183
174
  app.use(server);
184
175
 
185
176
  app.use(async ctx => {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package webpack-dev-service
3
3
  * @license MIT
4
- * @version 0.8.1
4
+ * @version 0.10.0
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A koa 2 middleware for webpack development and hot reloading.
7
7
  * @see https://github.com/nuintun/webpack-dev-service#readme
@@ -9,19 +9,29 @@
9
9
 
10
10
  'use strict';
11
11
 
12
- const compose = require('./dev/utils/compose.cjs');
13
- const index = require('./dev/index.cjs');
12
+ const schema = require('./schema.cjs');
13
+ const compose = require('./compose.cjs');
14
+ const utils = require('./utils.cjs');
15
+ const schemaUtils = require('schema-utils');
14
16
  const index$1 = require('./hot/index.cjs');
17
+ const index = require('./dev/index.cjs');
15
18
 
16
19
  /**
17
20
  * @module index
18
21
  */
19
22
  function server(compiler, options = {}) {
20
- const devMiddleware = index.dev(compiler, options);
21
- if (options.hot === false) {
22
- return devMiddleware;
23
+ schemaUtils.validate(schema.schema, options, {
24
+ name: utils.PLUGIN_NAME,
25
+ baseDataPath: 'options'
26
+ });
27
+ const { hot: hotOptions } = options;
28
+ if (hotOptions === false) {
29
+ return index.dev(compiler, options);
23
30
  }
24
- const hotMiddleware = index$1.hot(compiler, options.hot);
31
+ // All plugins must be initialized before watching.
32
+ // Because dev will start watching, so call hot before dev.
33
+ const hotMiddleware = index$1.hot(compiler, hotOptions);
34
+ const devMiddleware = index.dev(compiler, options);
25
35
  const middleware = compose.compose(devMiddleware, hotMiddleware);
26
36
  return Object.assign(middleware, devMiddleware, hotMiddleware);
27
37
  }
package/package.json CHANGED
@@ -1,46 +1,33 @@
1
1
  {
2
2
  "name": "webpack-dev-service",
3
- "version": "0.8.1",
3
+ "version": "0.10.0",
4
4
  "description": "A koa 2 middleware for webpack development and hot reloading.",
5
5
  "type": "module",
6
6
  "sideEffects": [
7
- "client/esm/main.js",
8
- "client/cjs/main.cjs"
7
+ "esm/client/main.js",
8
+ "cjs/client/main.cjs"
9
9
  ],
10
- "main": "server/cjs/index.cjs",
11
- "module": "server/esm/index.js",
10
+ "main": "cjs/server/index.cjs",
11
+ "module": "esm/server/index.js",
12
12
  "types": "types/server/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
- "import": "./server/esm/index.js",
16
- "require": "./server/cjs/index.cjs",
15
+ "import": "./esm/server/index.js",
16
+ "require": "./cjs/server/index.cjs",
17
17
  "types": "./types/server/index.d.ts"
18
18
  },
19
19
  "./client": {
20
- "import": "./client/esm/main.js",
21
- "require": "./client/cjs/main.cjs",
22
- "types": "./types/client/main.d.ts"
23
- },
24
- "./client?*": {
25
- "import": "./client/esm/main.js?*",
26
- "require": "./client/cjs/main.cjs?*",
27
- "types": "./types/client/main.d.ts"
28
- },
29
- "./events": {
30
- "import": "./client/esm/index.js",
31
- "require": "./client/cjs/index.cjs",
20
+ "import": "./esm/client/index.js",
21
+ "require": "./cjs/client/index.cjs",
32
22
  "types": "./types/client/index.d.ts"
33
23
  }
34
24
  },
35
25
  "typesVersions": {
36
26
  "*": {
37
- "client": [
38
- "./types/client/main.d.ts"
27
+ ".": [
28
+ "./types/server/index.d.ts"
39
29
  ],
40
- "client?*": [
41
- "./types/client/main.d.ts"
42
- ],
43
- "events": [
30
+ "client": [
44
31
  "./types/client/index.d.ts"
45
32
  ]
46
33
  }
@@ -48,11 +35,11 @@
48
35
  "files": [
49
36
  "types",
50
37
  "server",
51
- "client",
52
- "index.d.ts",
53
- "client.d.ts",
54
- "global.d.ts"
38
+ "client"
55
39
  ],
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
+ },
56
43
  "repository": {
57
44
  "type": "git",
58
45
  "url": "git+https://github.com/nuintun/webpack-dev-service.git"
@@ -93,20 +80,22 @@
93
80
  "etag": "^1.8.1",
94
81
  "memfs": "^4.8.0",
95
82
  "range-parser": "^1.2.1",
83
+ "schema-utils": "^4.2.0",
96
84
  "supports-color": "^9.4.0",
97
85
  "tslib": "^2.6.2",
98
86
  "ws": "^8.16.0"
99
87
  },
100
88
  "devDependencies": {
89
+ "@rollup/plugin-replace": "^5.0.5",
101
90
  "@rollup/plugin-typescript": "^11.1.6",
102
- "@swc/core": "^1.4.8",
103
- "@swc/helpers": "^0.5.7",
91
+ "@swc/core": "^1.4.11",
92
+ "@swc/helpers": "^0.5.8",
104
93
  "@types/destroy": "^1.0.3",
105
94
  "@types/etag": "^1.8.3",
106
95
  "@types/koa-compose": "^3.2.8",
107
96
  "@types/node": "^20.11.30",
108
97
  "@types/range-parser": "^1.2.7",
109
- "@types/react": "^18.2.67",
98
+ "@types/react": "^18.2.73",
110
99
  "@types/react-dom": "^18.2.22",
111
100
  "css-loader": "^6.10.0",
112
101
  "html-webpack-plugin": "^5.6.0",
@@ -119,13 +108,13 @@
119
108
  "react": "^18.2.0",
120
109
  "react-dom": "^18.2.0",
121
110
  "rimraf": "^5.0.5",
122
- "rollup": "^4.13.0",
111
+ "rollup": "^4.13.1",
123
112
  "swc-loader": "^0.2.6",
124
113
  "tsc-alias": "^1.8.8",
125
114
  "typescript": "^5.4.3",
126
115
  "webpack": "^5.91.0"
127
116
  },
128
117
  "peerDependencies": {
129
- "webpack": "^5.0.0"
118
+ "webpack": ">=5.20.0"
130
119
  }
131
120
  }
@@ -5,8 +5,8 @@ export interface Options {
5
5
  readonly hmr: boolean;
6
6
  readonly name: string;
7
7
  readonly path: string;
8
- readonly live: boolean;
9
8
  readonly origin: string;
9
+ readonly reload: boolean;
10
10
  readonly overlay: boolean;
11
11
  readonly progress: boolean;
12
12
  }
@@ -6,16 +6,16 @@ import * as Message from './message';
6
6
  interface Messages {
7
7
  ok: Message.OK['payload'];
8
8
  hash: Message.Hash['payload'];
9
+ issues: Message.Issues['payload'];
9
10
  invalid: Message.Invalid['payload'];
10
- problems: Message.Problems['payload'];
11
11
  progress: Message.Progress['payload'];
12
12
  }
13
13
  interface Events {
14
- ok: (message: Messages['ok'], options: Options) => void;
15
- hash: (message: Messages['hash'], options: Options) => void;
16
- invalid: (message: Messages['invalid'], options: Options) => void;
17
- problems: (message: Messages['problems'], options: Options) => void;
18
- progress: (message: Messages['progress'], options: Options) => void;
14
+ ok(message: Messages['ok'], options: Options): void;
15
+ hash(message: Messages['hash'], options: Options): void;
16
+ issues(message: Messages['issues'], options: Options): void;
17
+ invalid(message: Messages['invalid'], options: Options): void;
18
+ progress(message: Messages['progress'], options: Options): void;
19
19
  }
20
20
  /**
21
21
  * @function on
@@ -6,7 +6,7 @@ export interface Invalid {
6
6
  action: 'invalid';
7
7
  payload: {
8
8
  path: string;
9
- builtAt: number;
9
+ timestamp: number;
10
10
  };
11
11
  }
12
12
  export interface Progress {
@@ -21,12 +21,13 @@ export interface Hash {
21
21
  action: 'hash';
22
22
  payload: {
23
23
  hash: string;
24
+ timestamp: number;
24
25
  };
25
26
  }
26
- export interface Problems {
27
- action: 'problems';
27
+ export interface Issues {
28
+ action: 'issues';
28
29
  payload: {
29
- builtAt: number;
30
+ timestamp: number;
30
31
  errors: StatsError[];
31
32
  warnings: StatsError[];
32
33
  };
@@ -34,6 +35,6 @@ export interface Problems {
34
35
  export interface OK {
35
36
  action: 'ok';
36
37
  payload: {
37
- builtAt: number;
38
+ timestamp: number;
38
39
  };
39
40
  }
@@ -13,7 +13,7 @@ export default class Overlay {
13
13
  private readonly warningsList;
14
14
  private readonly warningsTitle;
15
15
  constructor(name: string);
16
- setProblems(type: 'errors' | 'warnings', problems: StatsError[]): void;
16
+ setIssues(type: 'errors' | 'warnings', issues: StatsError[]): void;
17
17
  show(): void;
18
18
  hide(): void;
19
19
  }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @module Service
3
+ */
4
+ /// <reference types="node" />
5
+ import { Stats } from 'fs';
6
+ import { Context } from 'koa';
7
+ import { FileSystem } from './utils/fs';
8
+ interface IgnoreFunction {
9
+ (path: string): boolean;
10
+ }
11
+ interface Headers {
12
+ [key: string]: string | string[];
13
+ }
14
+ type FileStats = Stats | null | undefined;
15
+ interface HeaderFunction {
16
+ (path: string, stats: FileStats): Headers | void;
17
+ }
18
+ export interface Options {
19
+ fs: FileSystem;
20
+ etag?: boolean;
21
+ acceptRanges?: boolean;
22
+ lastModified?: boolean;
23
+ ignore?: IgnoreFunction;
24
+ headers?: Headers | HeaderFunction;
25
+ }
26
+ /**
27
+ * @class Service
28
+ */
29
+ export declare class Service {
30
+ private root;
31
+ private options;
32
+ /**
33
+ * @constructor
34
+ * @description Create file service.
35
+ * @param root File service root.
36
+ * @param options File service options.
37
+ */
38
+ constructor(root: string, options: Options);
39
+ /**
40
+ * @private
41
+ * @method isIgnore
42
+ * @description Check if path is ignore.
43
+ * @param path File path.
44
+ */
45
+ private isIgnore;
46
+ /**
47
+ * @private
48
+ * @method setupHeaders
49
+ * @description Setup headers
50
+ * @param context Koa context
51
+ * @param path File path
52
+ * @param stats File stats
53
+ */
54
+ private setupHeaders;
55
+ /**
56
+ * @private
57
+ * @method write
58
+ * @description Write file to stream.
59
+ * @param stream Destination stream.
60
+ * @param path The file path to read.
61
+ * @param range The range to read.
62
+ * @param end Is destory destination stream after read complete.
63
+ */
64
+ private write;
65
+ /**
66
+ * @private
67
+ * @method send
68
+ * @description Send file.
69
+ * @param context Koa context.
70
+ * @param path File path.
71
+ * @param ranges Read ranges.
72
+ */
73
+ private send;
74
+ /**
75
+ * @public
76
+ * @method response
77
+ * @description Response to koa context.
78
+ * @param context Koa context.
79
+ */
80
+ response(context: Context): Promise<boolean>;
81
+ }
82
+ export {};
@@ -2,7 +2,7 @@
2
2
  * @module index
3
3
  */
4
4
  import { Middleware } from 'koa';
5
- import { Compiler } from 'webpack';
6
- import { AdditionalMethods, Options } from './interface';
7
- export { AdditionalMethods, Options };
8
- export declare function dev(compiler: Compiler, options?: Options): Middleware & AdditionalMethods;
5
+ import { ICompiler } from '../../server/interface';
6
+ import { Expose, Options } from './interface';
7
+ export { Expose, Options };
8
+ export declare function dev(compiler: ICompiler, options: Options): Middleware & Expose;
@@ -1,46 +1,38 @@
1
1
  /**
2
2
  * @module interface
3
3
  */
4
- /// <reference types="node" />
5
- import { createReadStream, Stats as FileStats } from 'fs';
6
- import { Compiler, Configuration, MultiCompiler, MultiStats, Stats, Watching } from 'webpack';
7
- type IOutputFileSystem = NonNullable<Compiler['outputFileSystem']>;
8
- interface HeaderFunction {
9
- (path: string, stats: FileStats): Record<string, string | string[]>;
4
+ import { StatsOptions } from 'webpack';
5
+ import { FileSystem } from './utils/fs';
6
+ import { Options as ServiceOptions, Service } from './Service';
7
+ import { ICompiler, ILogger, IStats, IStatsOptions, IWatching } from '../../server/interface';
8
+ export interface Callback {
9
+ (stats: IStats): void;
10
10
  }
11
- export interface OutputFileSystem extends IOutputFileSystem {
12
- createReadStream: typeof createReadStream;
11
+ export interface ErrorCallback {
12
+ (error?: Error | null): void;
13
13
  }
14
- export type Callback = (stats: Stats | MultiStats | null) => void;
15
- export interface FilesOptions {
16
- etag?: boolean;
17
- fs: OutputFileSystem;
18
- cacheControl?: string;
19
- acceptRanges?: boolean;
20
- lastModified?: boolean;
21
- headers?: HeaderFunction | Record<string, string | string[]>;
14
+ export interface Expose {
15
+ readonly state: boolean;
16
+ readonly logger: ILogger;
17
+ readonly ready: (callback: Callback) => void;
18
+ readonly close: (callback: ErrorCallback) => void;
19
+ readonly invalidate: (callback: ErrorCallback) => void;
22
20
  }
23
- export interface Options extends Omit<FilesOptions, 'fs'> {
24
- stats?: Configuration['stats'];
25
- outputFileSystem?: OutputFileSystem;
21
+ export interface Options extends Omit<ServiceOptions, 'fs'> {
22
+ fs?: FileSystem;
23
+ stats?: IStatsOptions;
26
24
  writeToDisk?: boolean | ((targetPath: string) => boolean);
25
+ onCompilerDone?(stats: IStats, statsOptions: Readonly<StatsOptions>): void;
27
26
  }
27
+ export type FileService = [publicPath: string, service: Service];
28
28
  export interface Context {
29
- state: boolean;
29
+ fs: FileSystem;
30
+ logger: ILogger;
30
31
  options: Options;
32
+ compiler: ICompiler;
33
+ watching: IWatching;
34
+ stats: IStats | null;
31
35
  callbacks: Callback[];
32
- stats: Stats | MultiStats | null;
33
- compiler: Compiler | MultiCompiler;
34
- outputFileSystem: OutputFileSystem;
35
- logger: ReturnType<Compiler['getInfrastructureLogger']>;
36
- watching: Watching | ReturnType<MultiCompiler['watch']>;
36
+ services?: FileService[];
37
37
  }
38
- export interface AdditionalMethods {
39
- isReady(): boolean;
40
- logger: Context['logger'];
41
- ready(callback: Callback): void;
42
- invalidate(callback: Callback): void;
43
- close(callback: (error?: Error | null) => void): void;
44
- }
45
- export type InitialContext = Optional<Context, 'watching' | 'outputFileSystem'>;
46
- export {};
38
+ export type InitialContext = Optional<Context, 'fs' | 'watching'>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @module fs
3
+ */
4
+ /// <reference types="node" />
5
+ /// <reference types="node" />
6
+ import { Compiler } from 'webpack';
7
+ import { ReadStream, Stats } from 'fs';
8
+ type PathLike = string | Buffer | URL;
9
+ type FileStats = Stats | null | undefined;
10
+ type IFileSystem = NonNullable<Compiler['outputFileSystem']>;
11
+ /**
12
+ * @function stat
13
+ * @description Get file stats.
14
+ * @param fs The file system to used.
15
+ * @param path The file path.
16
+ */
17
+ export declare function stat(fs: FileSystem, path: string): Promise<FileStats>;
18
+ export interface FileSystem extends IFileSystem {
19
+ createReadStream(
20
+ path: PathLike,
21
+ options?: {
22
+ start?: number;
23
+ end?: number;
24
+ }
25
+ ): ReadStream;
26
+ }
27
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module hash
3
+ */
4
+ /**
5
+ * @function generate
6
+ * @description Generate a hash.
7
+ * @param length The length of hash.
8
+ */
9
+ export declare function generate(length?: number): string;
@@ -1,22 +1,39 @@
1
1
  /**
2
- * @method http
2
+ * @module http
3
3
  */
4
+ /// <reference types="node" />
5
+ import { Stats } from 'fs';
6
+ import { Context } from 'koa';
7
+ export interface Range {
8
+ start: number;
9
+ end?: number;
10
+ prefix?: string;
11
+ suffix?: string;
12
+ }
13
+ type Ranges = Range[] | -1 | -2;
4
14
  /**
5
- * @function parseTokens
6
- * @description Parse HTTP tokens.
7
- * @param value The tokens value string.
15
+ * @function decodeURI
16
+ * @description Decode URI component.
17
+ * @param URI The URI to decode.
8
18
  */
9
- export declare function parseTokens(value: string): string[];
19
+ export declare function decodeURI(URI: string): string | -1;
10
20
  /**
11
- * @function isETag
12
- * @description Check if etag is valid.
13
- * @param value The value to check.
21
+ * @function isConditionalGET
22
+ * @description Check if request is conditional GET.
23
+ * @param context Koa context.
14
24
  */
15
- export declare function isETag(value: string): boolean;
25
+ export declare function isConditionalGET(context: Context): boolean;
16
26
  /**
17
- * @function isETagFresh
18
- * @description Check if etag is fresh.
19
- * @param match The match value.
20
- * @param etag The etag value.
27
+ * @function isPreconditionFailure
28
+ * @description Check if request precondition failure.
29
+ * @param context Koa context.
21
30
  */
22
- export declare function isETagFresh(match: string, etag: string): boolean;
31
+ export declare function isPreconditionFailure({ request, response }: Context): boolean;
32
+ /**
33
+ * @function parseRanges
34
+ * @description Parse ranges.
35
+ * @param context Koa context.
36
+ * @param stats File stats.
37
+ */
38
+ export declare function parseRanges(context: Context, stats: Stats): Ranges;
39
+ export {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @module path
3
+ */
4
+ /**
5
+ * @function unixify
6
+ * @description Convert path to unix style.
7
+ * @param path The path to convert.
8
+ */
9
+ export declare function unixify(path: string): string;
10
+ /**
11
+ * @function hasTrailingSlash
12
+ * @description Check if path has trailing slash.
13
+ * @param path The path to check.
14
+ */
15
+ export declare function hasTrailingSlash(path: string): boolean;
16
+ /**
17
+ * @function isOutRoot
18
+ * @description Check if path is out of root.
19
+ * @param path The path to check.
20
+ * @param root The root path.
21
+ */
22
+ export declare function isOutRoot(path: string, root: string): boolean;