Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source map URLs for the legacy API #113

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/src/legacy/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
load(canonicalUrl: URL): ImporterResult | null {
if (canonicalUrl.protocol === endOfLoadProtocol) {
this.prev.pop();
return {contents: '', syntax: 'scss'};
return {
contents: '',
syntax: 'scss',
sourceMapUrl: new URL(endOfLoadProtocol),
};
}

if (canonicalUrl.protocol === 'file:') {
Expand All @@ -195,7 +199,7 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
this.prev.pop();
}

return {contents, syntax};
return {contents, syntax, sourceMapUrl: canonicalUrl};
}

const lastContents = this.lastContents;
Expand All @@ -204,6 +208,7 @@ export class LegacyImporterWrapper<sync extends 'sync' | 'async'>
return {
contents: lastContents + this.endOfLoadImport,
syntax: 'scss',
sourceMapUrl: canonicalUrl,
};
}

Expand Down
26 changes: 15 additions & 11 deletions lib/src/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,21 @@ function newLegacyResult(
sourceMap.file = 'stdin.css';
}

sourceMap.sources = sourceMap.sources.map(source => {
if (source.startsWith('file://')) {
return pathToUrlString(
p.relative(sourceMapDir, fileUrlToPathCrossPlatform(source))
);
} else if (source.startsWith('data:')) {
return 'stdin';
} else {
return source;
}
});
sourceMap.sources = sourceMap.sources
.filter(source => !source.startsWith(endOfLoadProtocol))
.map(source => {
if (source.startsWith('file://')) {
return pathToUrlString(
p.relative(sourceMapDir, fileUrlToPathCrossPlatform(source))
);
} else if (source.startsWith(legacyImporterProtocol)) {
return source.substring(legacyImporterProtocol.length);
} else if (source.startsWith('data:')) {
return 'stdin';
} else {
return source;
}
});

sourceMapBytes = Buffer.from(JSON.stringify(sourceMap));

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-embedded",
"version": "1.49.7",
"version": "1.49.8-dev",
"protocol-version": "1.0.0",
"compiler-version": "1.49.7",
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol",
Expand Down