1 | import {Deprecation} from '../deprecations';
|
2 | import {SourceSpan} from './source_span';
|
3 |
|
4 | export {SourceLocation} from './source_location';
|
5 | export {SourceSpan} from './source_span';
|
6 |
|
7 | /**
|
8 | * The options passed to {@link Logger.warn}.
|
9 | *
|
10 | * * `deprecation`: Whether this is a deprecation warning.
|
11 | *
|
12 | * * `deprecationType`: The type of deprecation. Only set if `deprecation` is
|
13 | * true.
|
14 | *
|
15 | * * `span`: The location in the Sass source code that generated this warning.
|
16 | * This may be unset if the warning didn't come from Sass source, for
|
17 | * example if it's from a deprecated JavaScript option.
|
18 | *
|
19 | * * `stack`: The Sass stack trace at the point the warning was issued. This may
|
20 | * be unset if the warning didn't come from Sass source, for example if it's
|
21 | * from a deprecated JavaScript option.
|
22 | *
|
23 | * @category Logger
|
24 | */
|
25 | export type LoggerWarnOptions = (
|
26 | | {
|
27 | deprecation: true;
|
28 | deprecationType: Deprecation;
|
29 | }
|
30 | | {deprecation: false}
|
31 | ) & {
|
32 | span?: SourceSpan;
|
33 | stack?: string;
|
34 | };
|
35 |
|
36 | /**
|
37 | * An object that can be passed to {@link LegacySharedOptions.logger} to control
|
38 | * how Sass emits warnings and debug messages.
|
39 | *
|
40 | * @example
|
41 | *
|
42 | * ```js
|
43 | * const fs = require('fs');
|
44 | * const sass = require('sass');
|
45 | *
|
46 | * let log = "";
|
47 | * sass.renderSync({
|
48 | * file: 'input.scss',
|
49 | * logger: {
|
50 | * warn(message, options) {
|
51 | * if (options.span) {
|
52 | * log += `${span.url}:${span.start.line}:${span.start.column}: ` +
|
53 | * `${message}\n`;
|
54 | * } else {
|
55 | * log += `::: ${message}\n`;
|
56 | * }
|
57 | * }
|
58 | * }
|
59 | * });
|
60 | *
|
61 | * fs.writeFileSync('log.txt', log);
|
62 | * ```
|
63 | *
|
64 | * @category Logger
|
65 | */
|
66 | export interface Logger {
|
67 | /**
|
68 | * This method is called when Sass emits a warning, whether due to a [`@warn`
|
69 | * rule](https://sass-lang.com/documentation/at-rules/warn) or a warning
|
70 | * generated by the Sass compiler.
|
71 | *
|
72 | * If this is `undefined`, Sass will print warnings to standard error.
|
73 | *
|
74 | * `options` may contain the following fields:
|
75 | *
|
76 | * @param message - The warning message.
|
77 | */
|
78 | warn?(message: string, options: LoggerWarnOptions): void;
|
79 |
|
80 | /**
|
81 | * This method is called when Sass emits a debug message due to a [`@debug`
|
82 | * rule](https://sass-lang.com/documentation/at-rules/debug).
|
83 | *
|
84 | * If this is `undefined`, Sass will print debug messages to standard error.
|
85 | *
|
86 | * @param message - The debug message.
|
87 | * @param options.span - The location in the Sass source code that generated this
|
88 | * debug message.
|
89 | */
|
90 | debug?(message: string, options: {span: SourceSpan}): void;
|
91 | }
|
92 |
|
93 | /**
|
94 | * A namespace for built-in {@link Logger}s.
|
95 | *
|
96 | * @category Logger
|
97 | * @compatibility dart: "1.43.0", node: false
|
98 | */
|
99 | export namespace Logger {
|
100 | /**
|
101 | * A {@link Logger} that silently ignores all warnings and debug messages.
|
102 | *
|
103 | * @example
|
104 | *
|
105 | * ```js
|
106 | * const sass = require('sass');
|
107 | *
|
108 | * const result = sass.renderSync({
|
109 | * file: 'input.scss',
|
110 | * logger: sass.Logger.silent,
|
111 | * });
|
112 | * ```
|
113 | */
|
114 | export const silent: Logger;
|
115 | }
|