Skip to content

Commit

Permalink
Match the rest of the new core compile API
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Dec 15, 2021
1 parent 7692d34 commit e6731ec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
* Expose the `Exception` class and ensure that syntax errors match the official
JS API.

* Add support for the `style`, `alertColor`, `alertAscii`, `quietDeps`, and
`verbose` options in `compile()`, `compileString()`, `compileAsync()`, and
`compileStringAsync()`.

* Add support for `CompileResult.loadedUrls`.

## 1.0.0-beta.6

* Expose (as yet incomplete) `compile()`, `compileString()`, `compileAsync()`,
Expand Down
23 changes: 22 additions & 1 deletion lib/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import * as p from 'path';
import {Observable} from 'rxjs';
import * as supportsColor from 'supports-color';

import * as proto from './vendor/embedded-protocol/embedded_sass_pb';
import {AsyncEmbeddedCompiler} from './async-compiler';
Expand Down Expand Up @@ -80,6 +81,9 @@ function newCompileStringRequest(
case 'css':
input.setSyntax(proto.Syntax.CSS);
break;

default:
throw new Error(`Unknown options.syntax: "${options?.syntax}"`);
}

if (options?.url) input.setUrl(options.url.toString());
Expand All @@ -96,6 +100,23 @@ function newCompileRequest(
): proto.InboundMessage.CompileRequest {
const request = new proto.InboundMessage.CompileRequest();
request.setSourceMap(!!options?.sourceMap);
request.setAlertColor(options?.alertColor ?? !!supportsColor.stdout);
request.setAlertAscii(!!options?.alertAscii);
request.setQuietDeps(!!options?.quietDeps);
request.setVerbose(!!options?.verbose);

switch (options?.style ?? 'expanded') {
case 'expanded':
request.setStyle(proto.OutputStyle.EXPANDED);
break;

case 'compressed':
request.setStyle(proto.OutputStyle.COMPRESSED);
break;

default:
throw new Error(`Unknown options.style: "${options?.style}"`);
}

for (const path of options?.loadPaths ?? []) {
const importer = new proto.InboundMessage.CompileRequest.Importer();
Expand Down Expand Up @@ -250,7 +271,7 @@ function handleCompileResponse(
const success = response.getSuccess()!;
const result: CompileResult = {
css: success.getCss(),
loadedUrls: [], // TODO(nex3): Fill this out
loadedUrls: success.getLoadedUrlsList().map(url => new URL(url)),
};

const sourceMap = success.getSourceMap();
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"rxjs": "^7.4.0",
"semver": "^7.3.5",
"shelljs": "^0.8.4",
"supports-color": "^8.1.1",
"tar": "^6.0.5"
},
"devDependencies": {
Expand All @@ -45,6 +46,7 @@
"@types/node-fetch": "^2.5.7",
"@types/semver": "^7.3.4",
"@types/shelljs": "^0.8.8",
"@types/supports-color": "^8.1.1",
"@types/tar": "^6.1.0",
"@types/yargs": "^17.0.4",
"del": "^6.0.0",
Expand Down

0 comments on commit e6731ec

Please sign in to comment.