Skip to content

Commit e122e25

Browse files
authored
🤖 Merge PR DefinitelyTyped#74466 Add types for webpack-log by @gasp
1 parent f0b8edd commit e122e25

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed

types/webpack-log/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*
2+
!**/*.d.ts
3+
!**/*.d.cts
4+
!**/*.d.mts
5+
!**/*.d.*.ts

types/webpack-log/index.d.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Options for creating a webpack logger.
3+
*/
4+
interface WebpackLogOptions {
5+
/**
6+
* Log level. Default: 'info'.
7+
*/
8+
level?: "trace" | "debug" | "info" | "warn" | "error" | "silent";
9+
10+
/**
11+
* Name of the logger. Default: '<webpack-log>'.
12+
*/
13+
name?: string;
14+
15+
/**
16+
* Whether to include timestamp in output. Default: false.
17+
*/
18+
timestamp?: boolean;
19+
20+
/**
21+
* Whether to generate unique logger ID. Default: true.
22+
*/
23+
unique?: boolean;
24+
}
25+
26+
/**
27+
* Logger instance returned by webpack-log.
28+
*/
29+
interface WebpackLogger {
30+
/**
31+
* Log at trace level.
32+
*/
33+
trace(...args: unknown[]): void;
34+
35+
/**
36+
* Log at debug level.
37+
*/
38+
debug(...args: unknown[]): void;
39+
40+
/**
41+
* Log at info level.
42+
*/
43+
info(...args: unknown[]): void;
44+
45+
/**
46+
* Log at warn level.
47+
*/
48+
warn(...args: unknown[]): void;
49+
50+
/**
51+
* Log at error level.
52+
*/
53+
error(...args: unknown[]): void;
54+
}
55+
56+
/**
57+
* Creates a logger for the Webpack ecosystem.
58+
*
59+
* @param options - Logger configuration options
60+
* @returns A logger instance with trace, debug, info, warn, and error methods
61+
*
62+
* @example
63+
* ```javascript
64+
* const getLogger = require('webpack-log');
65+
*
66+
* const log = getLogger({ name: 'my-plugin' });
67+
* log.info('Starting plugin');
68+
* log.error('Something went wrong');
69+
* ```
70+
*/
71+
declare function getLogger(options?: WebpackLogOptions): WebpackLogger;
72+
73+
declare namespace getLogger {
74+
export { WebpackLogger, WebpackLogOptions };
75+
}
76+
77+
export = getLogger;

types/webpack-log/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"name": "@types/webpack-log",
4+
"version": "3.0.9999",
5+
"projects": [
6+
"https://github.com/shellscape/webpack-log"
7+
],
8+
"devDependencies": {
9+
"@types/webpack-log": "workspace:."
10+
},
11+
"owners": [
12+
{
13+
"name": "gaspard",
14+
"githubUsername": "gasp"
15+
}
16+
]
17+
}

types/webpack-log/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictNullChecks": true,
10+
"strictFunctionTypes": true,
11+
"types": [],
12+
"noEmit": true,
13+
"forceConsistentCasingInFileNames": true
14+
},
15+
"files": [
16+
"index.d.ts",
17+
"webpack-log-tests.ts"
18+
]
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import getLogger = require("webpack-log");
2+
3+
// Create logger with default options
4+
const log = getLogger();
5+
6+
// Create logger with name
7+
const namedLog = getLogger({ name: "my-webpack-plugin" });
8+
9+
// Create logger with all options
10+
const fullLog = getLogger({
11+
name: "webpack-plugin",
12+
level: "debug",
13+
timestamp: true,
14+
unique: false,
15+
});
16+
17+
// Test log methods
18+
log.trace("trace message");
19+
log.debug("debug message");
20+
log.info("info message");
21+
log.warn("warning message");
22+
log.error("error message");
23+
24+
// Test with multiple arguments
25+
log.info("message", { data: 123 });
26+
log.error("error", new Error("test"));
27+
28+
// Test log level options
29+
getLogger({ level: "trace" });
30+
getLogger({ level: "debug" });
31+
getLogger({ level: "info" });
32+
getLogger({ level: "warn" });
33+
getLogger({ level: "error" });
34+
getLogger({ level: "silent" });

0 commit comments

Comments
 (0)