Skip to content

Commit 3b7c0df

Browse files
committed
Enhance sourceMapIncludeSources option
1 parent 2b514fb commit 3b7c0df

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

lib/src/compiler/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ function newCompileRequest(
7171
importers: importers.importers,
7272
globalFunctions: Object.keys(options?.functions ?? {}),
7373
sourceMap: !!options?.sourceMap,
74-
sourceMapIncludeSources: !!options?.sourceMapIncludeSources,
74+
sourceMapIncludeSources: utils.protofySourceMapIncludeSources(
75+
options?.sourceMapIncludeSources ?? 'auto',
76+
),
7577
alertColor: options?.alertColor ?? !!supportsColor.stdout,
7678
alertAscii: !!options?.alertAscii,
7779
quietDeps: !!options?.quietDeps,

lib/src/legacy/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function newLegacyResult(
303303
return pathToUrlString(
304304
p.relative(sourceMapDir, fileUrlToPathCrossPlatform(source)),
305305
);
306-
} else if (source.startsWith('data:')) {
306+
} else if (source === '') {
307307
return 'stdin';
308308
} else {
309309
return source;

lib/src/utils.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as p from 'path';
77
import * as url from 'url';
88

99
import * as proto from './vendor/embedded_sass_pb';
10-
import {Syntax} from './vendor/sass';
10+
import {SourceMapIncludeSources, Syntax} from './vendor/sass';
1111

1212
export type PromiseOr<
1313
T,
@@ -147,6 +147,31 @@ export function protofySyntax(syntax: Syntax): proto.Syntax {
147147
}
148148
}
149149

150+
/** Converts a JS sourceMapIncludeSources value into a protobuf
151+
* sourceMapIncludeSources enum.
152+
*/
153+
export function protofySourceMapIncludeSources(
154+
sourceMapIncludeSources: SourceMapIncludeSources | boolean,
155+
): proto.SourceMapIncludeSources {
156+
switch (sourceMapIncludeSources) {
157+
case 'auto':
158+
return proto.SourceMapIncludeSources.AUTO;
159+
160+
case 'always':
161+
case true:
162+
return proto.SourceMapIncludeSources.ALWAYS;
163+
164+
case 'never':
165+
case false:
166+
return proto.SourceMapIncludeSources.NEVER;
167+
168+
default:
169+
throw new Error(
170+
`Unknown sourceMapIncludeSources: "${sourceMapIncludeSources}"`,
171+
);
172+
}
173+
}
174+
150175
/** Returns whether `error` is a NodeJS-style exception with an error code. */
151176
export function isErrnoException(
152177
error: unknown,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sass-embedded",
33
"version": "1.97.2",
4-
"protocol-version": "3.2.0",
4+
"protocol-version": "3.3.0",
55
"compiler-version": "1.97.2",
66
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol",
77
"repository": "sass/embedded-host-node",

0 commit comments

Comments
 (0)