sass-embedded 1.0.0-beta.7 → 1.49.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2386 -33
- package/README.md +95 -9
- package/dist/lib/index.js +25 -10
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/src/compile.js +67 -65
- package/dist/lib/src/compile.js.map +1 -1
- package/dist/lib/src/function-registry.js +16 -5
- package/dist/lib/src/function-registry.js.map +1 -1
- package/dist/lib/src/importer-registry.js +127 -0
- package/dist/lib/src/importer-registry.js.map +1 -0
- package/dist/lib/src/legacy/importer.js +191 -0
- package/dist/lib/src/legacy/importer.js.map +1 -0
- package/dist/lib/src/legacy/index.js +267 -0
- package/dist/lib/src/legacy/index.js.map +1 -0
- package/dist/lib/src/legacy/resolve-path.js +101 -0
- package/dist/lib/src/legacy/resolve-path.js.map +1 -0
- package/dist/lib/src/legacy/value/base.js +17 -0
- package/dist/lib/src/legacy/value/base.js.map +1 -0
- package/dist/lib/src/legacy/value/color.js +64 -0
- package/dist/lib/src/legacy/value/color.js.map +1 -0
- package/dist/lib/src/legacy/value/index.js +23 -0
- package/dist/lib/src/legacy/value/index.js.map +1 -0
- package/dist/lib/src/legacy/value/list.js +50 -0
- package/dist/lib/src/legacy/value/list.js.map +1 -0
- package/dist/lib/src/legacy/value/map.js +74 -0
- package/dist/lib/src/legacy/value/map.js.map +1 -0
- package/dist/lib/src/legacy/value/number.js +60 -0
- package/dist/lib/src/legacy/value/number.js.map +1 -0
- package/dist/lib/src/legacy/value/string.js +27 -0
- package/dist/lib/src/legacy/value/string.js.map +1 -0
- package/dist/lib/src/legacy/value/wrap.js +83 -0
- package/dist/lib/src/legacy/value/wrap.js.map +1 -0
- package/dist/lib/src/protofier.js +67 -0
- package/dist/lib/src/protofier.js.map +1 -1
- package/dist/lib/src/utils.js +37 -1
- package/dist/lib/src/utils.js.map +1 -1
- package/dist/lib/src/value/argument-list.js +31 -0
- package/dist/lib/src/value/argument-list.js.map +1 -0
- package/dist/lib/src/value/boolean.js +17 -1
- package/dist/lib/src/value/boolean.js.map +1 -1
- package/dist/lib/src/value/function.js +34 -0
- package/dist/lib/src/value/function.js.map +1 -0
- package/dist/lib/src/value/null.js +13 -1
- package/dist/lib/src/value/null.js.map +1 -1
- package/dist/lib/src/vendor/embedded-protocol/embedded_sass_pb.js +24 -1
- package/dist/lib/src/vendor/embedded-protocol/embedded_sass_pb.js.map +1 -1
- package/dist/package.json +3 -3
- package/dist/tool/utils.js +13 -7
- package/dist/tool/utils.js.map +1 -1
- package/dist/types/index.d.ts +5 -1
- package/dist/types/legacy/function.d.ts +110 -6
- package/dist/types/legacy/plugin_this.d.ts +7 -4
- package/dist/types/options.d.ts +10 -0
- package/package.json +3 -3
- package/dist/lib/src/legacy.js +0 -133
- package/dist/lib/src/legacy.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,13 +1,99 @@
|
|
|
1
1
|
## Embedded Sass Host
|
|
2
2
|
|
|
3
|
-
This is
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
[
|
|
11
|
-
|
|
3
|
+
This package is an alternative to the [`sass`] package. It supports the same JS
|
|
4
|
+
API as `sass` and is maintained by the same team, but where the `sass` package
|
|
5
|
+
is pure JavaScript, `sass-embedded` is instead a JavaScript wrapper around a
|
|
6
|
+
native Dart executable. This means `sass-embedded` will generally be much faster
|
|
7
|
+
especially for large Sass compilations, but it can only be installed on the
|
|
8
|
+
platforms that Dart supports: Windows, Mac OS, and Linux.
|
|
9
|
+
|
|
10
|
+
[`sass`]: https://www.npmjs.com/package/sass
|
|
11
|
+
|
|
12
|
+
Despite being different packages, both `sass` and `sass-embedded` are considered
|
|
13
|
+
"Dart Sass" since they have the same underlying implementation. Since the first
|
|
14
|
+
stable release of the `sass-embedded` package, both packages are released at the
|
|
15
|
+
same time and share the same version number.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
This package provides the same JavaScript API as the `sass` package, and can be
|
|
20
|
+
used as a drop-in replacement:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
const sass = require('sass-embedded');
|
|
24
|
+
|
|
25
|
+
const result = sass.compile(scssFilename);
|
|
26
|
+
|
|
27
|
+
// OR
|
|
28
|
+
|
|
29
|
+
const result = await sass.compileAsync(scssFilename);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Unlike the `sass` package, the asynchronous API in `sass-embedded` will
|
|
33
|
+
generally be faster than the synchronous API since the Sass compilation logic is
|
|
34
|
+
happening in a different process.
|
|
35
|
+
|
|
36
|
+
See [the Sass website] for full API documentation.
|
|
37
|
+
|
|
38
|
+
[the Sass website]: https://sass-lang.com/documentation/js-api
|
|
39
|
+
|
|
40
|
+
### Legacy API
|
|
41
|
+
|
|
42
|
+
The `sass-embedded` package also supports the older JavaScript API that's fully
|
|
43
|
+
compatible with [Node Sass] (with a few exceptions listed below), with support
|
|
44
|
+
for both the [`render()`] and [`renderSync()`] functions. This API is considered
|
|
45
|
+
deprecated and will be removed in Dart Sass 2.0.0, so it should be avoided in
|
|
46
|
+
new projects.
|
|
47
|
+
|
|
48
|
+
[Node Sass]: https://github.com/sass/node-sass
|
|
49
|
+
[`render()`]: https://sass-lang.com/documentation/js-api/modules#render
|
|
50
|
+
[`renderSync()`]: https://sass-lang.com/documentation/js-api/modules#renderSync
|
|
51
|
+
|
|
52
|
+
Sass's support for the legacy JavaScript API has the following limitations:
|
|
53
|
+
|
|
54
|
+
* Only the `"expanded"` and `"compressed"` values of [`outputStyle`] are
|
|
55
|
+
supported.
|
|
56
|
+
|
|
57
|
+
* The `sass-embedded` package doesn't support the [`precision`] option. Dart
|
|
58
|
+
Sass defaults to a sufficiently high precision for all existing browsers, and
|
|
59
|
+
making this customizable would make the code substantially less efficient.
|
|
60
|
+
|
|
61
|
+
* The `sass-embedded` package doesn't support the [`sourceComments`] option.
|
|
62
|
+
Source maps are the recommended way of locating the origin of generated
|
|
63
|
+
selectors.
|
|
64
|
+
|
|
65
|
+
* The `sass-embedded` package doesn't support the [`indentWidth`],
|
|
66
|
+
[`indentType`], or [`linefeed`] options. It implements the legacy API as a
|
|
67
|
+
wrapper around the new API, and the new API has dropped support for these
|
|
68
|
+
options.
|
|
69
|
+
|
|
70
|
+
[`outputStyle`]: https://sass-lang.com/documentation/js-api/interfaces/LegacySharedOptions#outputStyle
|
|
71
|
+
[`precision`]: https://github.com/sass/node-sass#precision
|
|
72
|
+
[`indentWidth`]: https://sass-lang.com/documentation/js-api/interfaces/LegacySharedOptions#indentWidth
|
|
73
|
+
[`indentType`]: https://sass-lang.com/documentation/js-api/interfaces/LegacySharedOptions#indentType
|
|
74
|
+
[`linefeed`]: https://sass-lang.com/documentation/js-api/interfaces/LegacySharedOptions#linefeed
|
|
75
|
+
|
|
76
|
+
## How Does It Work?
|
|
77
|
+
|
|
78
|
+
The `sass-embedded` runs the Dart Sass [embedded compiler] as a separate
|
|
79
|
+
executable and uses the [Embedded Sass Protocol] to communicate with it over its
|
|
80
|
+
stdin and stdout streams. This protocol is designed to make it possible not only
|
|
81
|
+
to start a Sass compilation, but to control aspects of it that are exposed by an
|
|
82
|
+
API. This includes defining custom importers, functions, and loggers, all of
|
|
83
|
+
which are invoked by messages from the embedded compiler back to the host.
|
|
84
|
+
|
|
85
|
+
[embedded compiler]: https://github.com/sass/dart-sass-embedded
|
|
86
|
+
[Embedded Sass Protocol]: https://github.com/sass/embedded-protocol#readme
|
|
87
|
+
|
|
88
|
+
Although this sort of two-way communication with an embedded process is
|
|
89
|
+
inherently asynchronous in Node.js, this package supports the synchronous
|
|
90
|
+
`compile()` API using a custom [synchronous message-passing library] that's
|
|
91
|
+
implemented with the [`Atomics.wait()`] primitive. We hope to release this
|
|
92
|
+
library as a stand-alone package at some point in the future.
|
|
93
|
+
|
|
94
|
+
[synchronous message-passing library]: https://github.com/sass/embedded-host-node/blob/main/lib/src/sync-process/sync-message-port.ts
|
|
95
|
+
[`Atomics.wait()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait
|
|
96
|
+
|
|
97
|
+
---
|
|
12
98
|
|
|
13
99
|
Disclaimer: this is not an official Google product.
|
package/dist/lib/index.js
CHANGED
|
@@ -3,25 +3,32 @@
|
|
|
3
3
|
// MIT-style license that can be found in the LICENSE file or at
|
|
4
4
|
// https://opensource.org/licenses/MIT.
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.info = exports.render = exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = exports.Exception = exports.
|
|
6
|
+
exports.NULL = exports.FALSE = exports.TRUE = exports.Logger = exports.info = exports.renderSync = exports.render = exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = exports.Exception = exports.types = exports.sassNull = exports.Value = exports.SassString = exports.SassNumber = exports.SassMap = exports.SassFunction = exports.SassColor = exports.sassTrue = exports.sassFalse = exports.SassArgumentList = exports.SassList = void 0;
|
|
7
7
|
const pkg = require("../package.json");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var boolean_1 = require("./src/value/boolean");
|
|
11
|
-
Object.defineProperty(exports, "sassFalse", { enumerable: true, get: function () { return boolean_1.sassFalse; } });
|
|
12
|
-
Object.defineProperty(exports, "sassTrue", { enumerable: true, get: function () { return boolean_1.sassTrue; } });
|
|
13
|
-
var color_1 = require("./src/value/color");
|
|
14
|
-
Object.defineProperty(exports, "SassColor", { enumerable: true, get: function () { return color_1.SassColor; } });
|
|
8
|
+
const boolean_1 = require("./src/value/boolean");
|
|
9
|
+
const null_1 = require("./src/value/null");
|
|
15
10
|
var list_1 = require("./src/value/list");
|
|
16
11
|
Object.defineProperty(exports, "SassList", { enumerable: true, get: function () { return list_1.SassList; } });
|
|
12
|
+
var argument_list_1 = require("./src/value/argument-list");
|
|
13
|
+
Object.defineProperty(exports, "SassArgumentList", { enumerable: true, get: function () { return argument_list_1.SassArgumentList; } });
|
|
14
|
+
var boolean_2 = require("./src/value/boolean");
|
|
15
|
+
Object.defineProperty(exports, "sassFalse", { enumerable: true, get: function () { return boolean_2.sassFalse; } });
|
|
16
|
+
Object.defineProperty(exports, "sassTrue", { enumerable: true, get: function () { return boolean_2.sassTrue; } });
|
|
17
|
+
var color_1 = require("./src/value/color");
|
|
18
|
+
Object.defineProperty(exports, "SassColor", { enumerable: true, get: function () { return color_1.SassColor; } });
|
|
19
|
+
var function_1 = require("./src/value/function");
|
|
20
|
+
Object.defineProperty(exports, "SassFunction", { enumerable: true, get: function () { return function_1.SassFunction; } });
|
|
17
21
|
var map_1 = require("./src/value/map");
|
|
18
22
|
Object.defineProperty(exports, "SassMap", { enumerable: true, get: function () { return map_1.SassMap; } });
|
|
19
|
-
var null_1 = require("./src/value/null");
|
|
20
|
-
Object.defineProperty(exports, "sassNull", { enumerable: true, get: function () { return null_1.sassNull; } });
|
|
21
23
|
var number_1 = require("./src/value/number");
|
|
22
24
|
Object.defineProperty(exports, "SassNumber", { enumerable: true, get: function () { return number_1.SassNumber; } });
|
|
23
25
|
var string_1 = require("./src/value/string");
|
|
24
26
|
Object.defineProperty(exports, "SassString", { enumerable: true, get: function () { return string_1.SassString; } });
|
|
27
|
+
var value_1 = require("./src/value");
|
|
28
|
+
Object.defineProperty(exports, "Value", { enumerable: true, get: function () { return value_1.Value; } });
|
|
29
|
+
var null_2 = require("./src/value/null");
|
|
30
|
+
Object.defineProperty(exports, "sassNull", { enumerable: true, get: function () { return null_2.sassNull; } });
|
|
31
|
+
exports.types = require("./src/legacy/value");
|
|
25
32
|
var exception_1 = require("./src/exception");
|
|
26
33
|
Object.defineProperty(exports, "Exception", { enumerable: true, get: function () { return exception_1.Exception; } });
|
|
27
34
|
var compile_1 = require("./src/compile");
|
|
@@ -31,5 +38,13 @@ Object.defineProperty(exports, "compileAsync", { enumerable: true, get: function
|
|
|
31
38
|
Object.defineProperty(exports, "compileStringAsync", { enumerable: true, get: function () { return compile_1.compileStringAsync; } });
|
|
32
39
|
var legacy_1 = require("./src/legacy");
|
|
33
40
|
Object.defineProperty(exports, "render", { enumerable: true, get: function () { return legacy_1.render; } });
|
|
41
|
+
Object.defineProperty(exports, "renderSync", { enumerable: true, get: function () { return legacy_1.renderSync; } });
|
|
34
42
|
exports.info = `sass-embedded\t${pkg.version}`;
|
|
43
|
+
exports.Logger = {
|
|
44
|
+
silent: { warn() { }, debug() { } },
|
|
45
|
+
};
|
|
46
|
+
// Legacy JS API
|
|
47
|
+
exports.TRUE = boolean_1.sassTrue;
|
|
48
|
+
exports.FALSE = boolean_1.sassFalse;
|
|
49
|
+
exports.NULL = null_1.sassNull;
|
|
35
50
|
//# sourceMappingURL=index.js.map
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,uCAAuC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,uCAAuC;AACvC,iDAAwD;AACxD,2CAA0C;AAE1C,yCAAyD;AAAlC,gGAAA,QAAQ,OAAA;AAC/B,2DAA2D;AAAnD,iHAAA,gBAAgB,OAAA;AACxB,+CAAwD;AAAhD,oGAAA,SAAS,OAAA;AAAE,mGAAA,QAAQ,OAAA;AAC3B,2CAA4C;AAApC,kGAAA,SAAS,OAAA;AACjB,iDAAkD;AAA1C,wGAAA,YAAY,OAAA;AACpB,uCAAwC;AAAhC,8FAAA,OAAO,OAAA;AACf,6CAA8C;AAAtC,oGAAA,UAAU,OAAA;AAClB,6CAA8C;AAAtC,oGAAA,UAAU,OAAA;AAClB,qCAAkC;AAA1B,8FAAA,KAAK,OAAA;AACb,yCAA0C;AAAlC,gGAAA,QAAQ,OAAA;AAEhB,8CAA4C;AAC5C,6CAA0C;AAAlC,sGAAA,SAAS,OAAA;AACjB,yCAKuB;AAJrB,kGAAA,OAAO,OAAA;AACP,wGAAA,aAAa,OAAA;AACb,uGAAA,YAAY,OAAA;AACZ,6GAAA,kBAAkB,OAAA;AAEpB,uCAAgD;AAAxC,gGAAA,MAAM,OAAA;AAAE,oGAAA,UAAU,OAAA;AAEb,QAAA,IAAI,GAAG,kBAAkB,GAAG,CAAC,OAAO,EAAE,CAAC;AAEvC,QAAA,MAAM,GAAG;IACpB,MAAM,EAAE,EAAC,IAAI,KAAI,CAAC,EAAE,KAAK,KAAI,CAAC,EAAC;CAChC,CAAC;AAEF,gBAAgB;AAEH,QAAA,IAAI,GAAG,kBAAQ,CAAC;AAChB,QAAA,KAAK,GAAG,mBAAS,CAAC;AAClB,QAAA,IAAI,GAAG,eAAQ,CAAC"}
|
package/dist/lib/src/compile.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
// https://opensource.org/licenses/MIT.
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = void 0;
|
|
7
|
-
const p = require("path");
|
|
8
7
|
const supportsColor = require("supports-color");
|
|
9
8
|
const proto = require("./vendor/embedded-protocol/embedded_sass_pb");
|
|
10
9
|
const utils = require("./utils");
|
|
@@ -12,68 +11,61 @@ const async_compiler_1 = require("./async-compiler");
|
|
|
12
11
|
const dispatcher_1 = require("./dispatcher");
|
|
13
12
|
const exception_1 = require("./exception");
|
|
14
13
|
const function_registry_1 = require("./function-registry");
|
|
14
|
+
const importer_registry_1 = require("./importer-registry");
|
|
15
15
|
const message_transformer_1 = require("./message-transformer");
|
|
16
16
|
const packet_transformer_1 = require("./packet-transformer");
|
|
17
17
|
const sync_compiler_1 = require("./sync-compiler");
|
|
18
|
+
const deprotofy_span_1 = require("./deprotofy-span");
|
|
18
19
|
function compile(path, options) {
|
|
19
|
-
|
|
20
|
-
return compileRequestSync(newCompilePathRequest(path, options), options);
|
|
20
|
+
const importers = new importer_registry_1.ImporterRegistry(options);
|
|
21
|
+
return compileRequestSync(newCompilePathRequest(path, importers, options), importers, options);
|
|
21
22
|
}
|
|
22
23
|
exports.compile = compile;
|
|
23
24
|
function compileString(source, options) {
|
|
24
|
-
|
|
25
|
-
return compileRequestSync(newCompileStringRequest(source, options), options);
|
|
25
|
+
const importers = new importer_registry_1.ImporterRegistry(options);
|
|
26
|
+
return compileRequestSync(newCompileStringRequest(source, importers, options), importers, options);
|
|
26
27
|
}
|
|
27
28
|
exports.compileString = compileString;
|
|
28
29
|
function compileAsync(path, options) {
|
|
29
|
-
|
|
30
|
-
return compileRequestAsync(newCompilePathRequest(path, options), options);
|
|
30
|
+
const importers = new importer_registry_1.ImporterRegistry(options);
|
|
31
|
+
return compileRequestAsync(newCompilePathRequest(path, importers, options), importers, options);
|
|
31
32
|
}
|
|
32
33
|
exports.compileAsync = compileAsync;
|
|
33
34
|
function compileStringAsync(source, options) {
|
|
34
|
-
|
|
35
|
-
return compileRequestAsync(newCompileStringRequest(source, options), options);
|
|
35
|
+
const importers = new importer_registry_1.ImporterRegistry(options);
|
|
36
|
+
return compileRequestAsync(newCompileStringRequest(source, importers, options), importers, options);
|
|
36
37
|
}
|
|
37
38
|
exports.compileStringAsync = compileStringAsync;
|
|
38
39
|
// Creates a request for compiling a file.
|
|
39
|
-
function newCompilePathRequest(path, options) {
|
|
40
|
-
|
|
41
|
-
const request = newCompileRequest(options);
|
|
40
|
+
function newCompilePathRequest(path, importers, options) {
|
|
41
|
+
const request = newCompileRequest(importers, options);
|
|
42
42
|
request.setPath(path);
|
|
43
43
|
return request;
|
|
44
44
|
}
|
|
45
45
|
// Creates a request for compiling a string.
|
|
46
|
-
function newCompileStringRequest(source, options) {
|
|
47
|
-
// TODO(awjin): Populate request with importer/function IDs.
|
|
46
|
+
function newCompileStringRequest(source, importers, options) {
|
|
48
47
|
var _a;
|
|
49
48
|
const input = new proto.InboundMessage.CompileRequest.StringInput();
|
|
50
49
|
input.setSource(source);
|
|
51
|
-
|
|
52
|
-
case 'scss':
|
|
53
|
-
input.setSyntax(proto.Syntax.SCSS);
|
|
54
|
-
break;
|
|
55
|
-
case 'indented':
|
|
56
|
-
input.setSyntax(proto.Syntax.INDENTED);
|
|
57
|
-
break;
|
|
58
|
-
case 'css':
|
|
59
|
-
input.setSyntax(proto.Syntax.CSS);
|
|
60
|
-
break;
|
|
61
|
-
default:
|
|
62
|
-
throw new Error(`Unknown options.syntax: "${options === null || options === void 0 ? void 0 : options.syntax}"`);
|
|
63
|
-
}
|
|
50
|
+
input.setSyntax(utils.protofySyntax((_a = options === null || options === void 0 ? void 0 : options.syntax) !== null && _a !== void 0 ? _a : 'scss'));
|
|
64
51
|
if (options === null || options === void 0 ? void 0 : options.url)
|
|
65
52
|
input.setUrl(options.url.toString());
|
|
66
|
-
|
|
53
|
+
if (options && 'importer' in options && options.importer) {
|
|
54
|
+
input.setImporter(importers.register(options.importer));
|
|
55
|
+
}
|
|
56
|
+
const request = newCompileRequest(importers, options);
|
|
67
57
|
request.setString(input);
|
|
68
58
|
return request;
|
|
69
59
|
}
|
|
70
60
|
// Creates a compilation request for the given `options` without adding any
|
|
71
61
|
// input-specific options.
|
|
72
|
-
function newCompileRequest(options) {
|
|
73
|
-
var _a, _b, _c
|
|
62
|
+
function newCompileRequest(importers, options) {
|
|
63
|
+
var _a, _b, _c;
|
|
74
64
|
const request = new proto.InboundMessage.CompileRequest();
|
|
65
|
+
request.setImportersList(importers.importers);
|
|
75
66
|
request.setGlobalFunctionsList(Object.keys((_a = options === null || options === void 0 ? void 0 : options.functions) !== null && _a !== void 0 ? _a : {}));
|
|
76
67
|
request.setSourceMap(!!(options === null || options === void 0 ? void 0 : options.sourceMap));
|
|
68
|
+
request.setSourceMapIncludeSources(!!(options === null || options === void 0 ? void 0 : options.sourceMapIncludeSources));
|
|
77
69
|
request.setAlertColor((_b = options === null || options === void 0 ? void 0 : options.alertColor) !== null && _b !== void 0 ? _b : !!supportsColor.stdout);
|
|
78
70
|
request.setAlertAscii(!!(options === null || options === void 0 ? void 0 : options.alertAscii));
|
|
79
71
|
request.setQuietDeps(!!(options === null || options === void 0 ? void 0 : options.quietDeps));
|
|
@@ -88,37 +80,24 @@ function newCompileRequest(options) {
|
|
|
88
80
|
default:
|
|
89
81
|
throw new Error(`Unknown options.style: "${options === null || options === void 0 ? void 0 : options.style}"`);
|
|
90
82
|
}
|
|
91
|
-
for (const path of (_d = options === null || options === void 0 ? void 0 : options.loadPaths) !== null && _d !== void 0 ? _d : []) {
|
|
92
|
-
const importer = new proto.InboundMessage.CompileRequest.Importer();
|
|
93
|
-
importer.setPath(p.resolve(path));
|
|
94
|
-
request.addImporters(importer);
|
|
95
|
-
}
|
|
96
83
|
return request;
|
|
97
84
|
}
|
|
98
85
|
// Spins up a compiler, then sends it a compile request. Returns a promise that
|
|
99
86
|
// resolves with the CompileResult. Throws if there were any protocol or
|
|
100
87
|
// compilation errors. Shuts down the compiler after compilation.
|
|
101
|
-
async function compileRequestAsync(request, options) {
|
|
102
|
-
const
|
|
88
|
+
async function compileRequestAsync(request, importers, options) {
|
|
89
|
+
const functions = new function_registry_1.FunctionRegistry(options === null || options === void 0 ? void 0 : options.functions);
|
|
103
90
|
const embeddedCompiler = new async_compiler_1.AsyncEmbeddedCompiler();
|
|
104
91
|
try {
|
|
105
|
-
// TODO(awjin): Pass import and function registries' handler functions to
|
|
106
|
-
// dispatcher.
|
|
107
92
|
const dispatcher = createDispatcher(embeddedCompiler.stdout$, buffer => {
|
|
108
93
|
embeddedCompiler.writeStdin(buffer);
|
|
109
94
|
}, {
|
|
110
|
-
handleImportRequest:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
throw Error('Custom file importers not yet implemented.');
|
|
115
|
-
},
|
|
116
|
-
handleCanonicalizeRequest: () => {
|
|
117
|
-
throw Error('Canonicalize not yet implemented.');
|
|
118
|
-
},
|
|
119
|
-
handleFunctionCallRequest: request => functionRegistry.call(request),
|
|
95
|
+
handleImportRequest: request => importers.import(request),
|
|
96
|
+
handleFileImportRequest: request => importers.fileImport(request),
|
|
97
|
+
handleCanonicalizeRequest: request => importers.canonicalize(request),
|
|
98
|
+
handleFunctionCallRequest: request => functions.call(request),
|
|
120
99
|
});
|
|
121
|
-
|
|
100
|
+
dispatcher.logEvents$.subscribe(event => handleLogEvent(options, event));
|
|
122
101
|
return handleCompileResponse(await new Promise((resolve, reject) => dispatcher.sendCompileRequest(request, (err, response) => {
|
|
123
102
|
if (err) {
|
|
124
103
|
reject(err);
|
|
@@ -136,27 +115,19 @@ async function compileRequestAsync(request, options) {
|
|
|
136
115
|
// Spins up a compiler, then sends it a compile request. Returns a promise that
|
|
137
116
|
// resolves with the CompileResult. Throws if there were any protocol or
|
|
138
117
|
// compilation errors. Shuts down the compiler after compilation.
|
|
139
|
-
function compileRequestSync(request, options) {
|
|
140
|
-
const
|
|
118
|
+
function compileRequestSync(request, importers, options) {
|
|
119
|
+
const functions = new function_registry_1.FunctionRegistry(options === null || options === void 0 ? void 0 : options.functions);
|
|
141
120
|
const embeddedCompiler = new sync_compiler_1.SyncEmbeddedCompiler();
|
|
142
121
|
try {
|
|
143
|
-
// TODO(awjin): Pass import and function registries' handler functions to
|
|
144
|
-
// dispatcher.
|
|
145
122
|
const dispatcher = createDispatcher(embeddedCompiler.stdout$, buffer => {
|
|
146
123
|
embeddedCompiler.writeStdin(buffer);
|
|
147
124
|
}, {
|
|
148
|
-
handleImportRequest:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
throw Error('Custom file importers not yet implemented.');
|
|
153
|
-
},
|
|
154
|
-
handleCanonicalizeRequest: () => {
|
|
155
|
-
throw Error('Canonicalize not yet implemented.');
|
|
156
|
-
},
|
|
157
|
-
handleFunctionCallRequest: request => functionRegistry.call(request),
|
|
125
|
+
handleImportRequest: request => importers.import(request),
|
|
126
|
+
handleFileImportRequest: request => importers.fileImport(request),
|
|
127
|
+
handleCanonicalizeRequest: request => importers.canonicalize(request),
|
|
128
|
+
handleFunctionCallRequest: request => functions.call(request),
|
|
158
129
|
});
|
|
159
|
-
|
|
130
|
+
dispatcher.logEvents$.subscribe(event => handleLogEvent(options, event));
|
|
160
131
|
let error;
|
|
161
132
|
let response;
|
|
162
133
|
dispatcher.sendCompileRequest(request, (error_, response_) => {
|
|
@@ -190,6 +161,37 @@ function createDispatcher(stdout, writeStdin, handlers) {
|
|
|
190
161
|
const messageTransformer = new message_transformer_1.MessageTransformer(packetTransformer.outboundProtobufs$, packet => packetTransformer.writeInboundProtobuf(packet));
|
|
191
162
|
return new dispatcher_1.Dispatcher(messageTransformer.outboundMessages$, message => messageTransformer.writeInboundMessage(message), handlers);
|
|
192
163
|
}
|
|
164
|
+
/** Handles a log event according to `options`. */
|
|
165
|
+
function handleLogEvent(options, event) {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
if (event.getType() === proto.LogEventType.DEBUG) {
|
|
168
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.debug) {
|
|
169
|
+
options.logger.debug(event.getMessage(), {
|
|
170
|
+
span: (0, deprotofy_span_1.deprotofySourceSpan)(event.getSpan()),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.error(event.getFormatted());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
if ((_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.warn) {
|
|
179
|
+
const params = {
|
|
180
|
+
deprecation: event.getType() === proto.LogEventType.DEPRECATION_WARNING,
|
|
181
|
+
};
|
|
182
|
+
const spanProto = event.getSpan();
|
|
183
|
+
if (spanProto)
|
|
184
|
+
params.span = (0, deprotofy_span_1.deprotofySourceSpan)(spanProto);
|
|
185
|
+
const stack = event.getStackTrace();
|
|
186
|
+
if (stack)
|
|
187
|
+
params.stack = stack;
|
|
188
|
+
options.logger.warn(event.getMessage(), params);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
console.error(event.getFormatted());
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
193
195
|
/**
|
|
194
196
|
* Converts a `CompileResponse` into a `CompileResult`.
|
|
195
197
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../lib/src/compile.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../lib/src/compile.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAGvC,gDAAgD;AAEhD,qEAAqE;AACrE,iCAAiC;AACjC,qDAAuD;AAEvD,6CAA4D;AAC5D,2CAAsC;AACtC,2DAAqD;AACrD,2DAAqD;AACrD,+DAAyD;AACzD,6DAAuD;AACvD,mDAAqD;AACrD,qDAAqD;AAErD,SAAgB,OAAO,CACrB,IAAY,EACZ,OAAyB;IAEzB,MAAM,SAAS,GAAG,IAAI,oCAAgB,CAAC,OAAO,CAAC,CAAC;IAChD,OAAO,kBAAkB,CACvB,qBAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,EAC/C,SAAS,EACT,OAAO,CACR,CAAC;AACJ,CAAC;AAVD,0BAUC;AAED,SAAgB,aAAa,CAC3B,MAAc,EACd,OAA+B;IAE/B,MAAM,SAAS,GAAG,IAAI,oCAAgB,CAAC,OAAO,CAAC,CAAC;IAChD,OAAO,kBAAkB,CACvB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EACnD,SAAS,EACT,OAAO,CACR,CAAC;AACJ,CAAC;AAVD,sCAUC;AAED,SAAgB,YAAY,CAC1B,IAAY,EACZ,OAA0B;IAE1B,MAAM,SAAS,GAAG,IAAI,oCAAgB,CAAC,O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AQ,CAAC,UAAU,EAAG,CAAC;QACvC,MAAM,MAAM,GAAkB;YAC5B,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE;YACrB,UAAU,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;SACjE,CAAC;QAEF,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QACzC,IAAI,SAAS;YAAE,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC;KACf;SAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,EAAE;QAChC,MAAM,IAAI,qBAAS,CAAC,QAAQ,CAAC,UAAU,EAAG,CAAC,CAAC;KAC7C;SAAM;QACL,MAAM,KAAK,CAAC,aAAa,CAAC,sCAAsC,CAAC,CAAC;KACnE;AACH,CAAC"}
|
|
@@ -10,10 +10,19 @@ const embedded_sass_pb_1 = require("./vendor/embedded-protocol/embedded_sass_pb"
|
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
const protofier_1 = require("./protofier");
|
|
12
12
|
const value_1 = require("./value");
|
|
13
|
+
/**
|
|
14
|
+
* The next ID to use for a function. The embedded protocol requires that
|
|
15
|
+
* function IDs be globally unique.
|
|
16
|
+
*/
|
|
17
|
+
let nextFunctionID = 0;
|
|
18
|
+
/**
|
|
19
|
+
* Tracks functions that are defined on the host so that the compiler can
|
|
20
|
+
* execute them.
|
|
21
|
+
*/
|
|
13
22
|
class FunctionRegistry {
|
|
14
23
|
constructor(functionsBySignature) {
|
|
15
24
|
this.functionsByName = new Map();
|
|
16
|
-
this.functionsById = new
|
|
25
|
+
this.functionsById = new Map();
|
|
17
26
|
this.idsByFunction = new Map();
|
|
18
27
|
for (const [signature, fn] of Object.entries(functionsBySignature !== null && functionsBySignature !== void 0 ? functionsBySignature : {})) {
|
|
19
28
|
const openParen = signature.indexOf('(');
|
|
@@ -26,8 +35,9 @@ class FunctionRegistry {
|
|
|
26
35
|
/** Registers `fn` as a function that can be called using the returned ID. */
|
|
27
36
|
register(fn) {
|
|
28
37
|
return utils.putIfAbsent(this.idsByFunction, fn, () => {
|
|
29
|
-
const id =
|
|
30
|
-
|
|
38
|
+
const id = nextFunctionID;
|
|
39
|
+
nextFunctionID += 1;
|
|
40
|
+
this.functionsById.set(id, fn);
|
|
31
41
|
return id;
|
|
32
42
|
});
|
|
33
43
|
}
|
|
@@ -35,7 +45,7 @@ class FunctionRegistry {
|
|
|
35
45
|
* Returns the function to which `request` refers and returns its response.
|
|
36
46
|
*/
|
|
37
47
|
call(request) {
|
|
38
|
-
const protofier = new protofier_1.Protofier();
|
|
48
|
+
const protofier = new protofier_1.Protofier(this);
|
|
39
49
|
const fn = this.get(request);
|
|
40
50
|
return (0, utils_1.catchOr)(() => {
|
|
41
51
|
return (0, utils_1.thenOr)(fn(request
|
|
@@ -50,6 +60,7 @@ class FunctionRegistry {
|
|
|
50
60
|
}
|
|
51
61
|
const response = new embedded_sass_pb_1.InboundMessage.FunctionCallResponse();
|
|
52
62
|
response.setSuccess(protofier.protofy(result));
|
|
63
|
+
response.setAccessedArgumentListsList(protofier.accessedArgumentLists);
|
|
53
64
|
return response;
|
|
54
65
|
});
|
|
55
66
|
}, error => {
|
|
@@ -69,7 +80,7 @@ class FunctionRegistry {
|
|
|
69
80
|
`named "${request.getName()}"`);
|
|
70
81
|
}
|
|
71
82
|
else {
|
|
72
|
-
const fn = this.functionsById
|
|
83
|
+
const fn = this.functionsById.get(request.getFunctionId());
|
|
73
84
|
if (fn)
|
|
74
85
|
return fn;
|
|
75
86
|
throw new Error('Invalid OutboundMessage.FunctionCallRequest: there is no function ' +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-registry.js","sourceRoot":"","sources":["../../../lib/src/function-registry.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AA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YACN,MAAM,QAAQ,GAAG,IAAI,iCAAc,CAAC,oBAAoB,EAAE,CAAC;YAC3D,QAAQ,CAAC,QAAQ,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;YAC9B,OAAO,QAAQ,CAAC;QAClB,CAAC,CACF,CAAC;IACJ,CAAC;IAED,sDAAsD;IAC9C,GAAG,CACT,OAA4C;QAE5C,IACE,OAAO,CAAC,iBAAiB,EAAE;YAC3B,kCAAe,CAAC,mBAAmB,CAAC,cAAc,CAAC,IAAI,EACvD;YACA,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;YACvD,IAAI,EAAE;gBAAE,OAAO,EAAE,CAAC;YAElB,MAAM,IAAI,KAAK,CACb,oEAAoE;gBAClE,UAAU,OAAO,CAAC,OAAO,EAAE,GAAG,CACjC,CAAC;SACH;aAAM;YACL,MAAM,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;YAC3D,IAAI,EAAE;gBAAE,OAAO,EAAE,CAAC;YAElB,MAAM,IAAI,KAAK,CACb,oEAAoE;gBAClE,YAAY,OAAO,CAAC,aAAa,EAAE,GAAG,CACzC,CAAC;SACH;IACH,CAAC;CACF;AAjGD,4CAiGC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 Google LLC. Use of this source code is governed by an
|
|
3
|
+
// MIT-style license that can be found in the LICENSE file or at
|
|
4
|
+
// https://opensource.org/licenses/MIT.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ImporterRegistry = void 0;
|
|
7
|
+
const p = require("path");
|
|
8
|
+
const url_1 = require("url");
|
|
9
|
+
const util_1 = require("util");
|
|
10
|
+
const utils = require("./utils");
|
|
11
|
+
const embedded_sass_pb_1 = require("./vendor/embedded-protocol/embedded_sass_pb");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
/**
|
|
14
|
+
* A registry of importers defined in the host that can be invoked by the
|
|
15
|
+
* compiler.
|
|
16
|
+
*/
|
|
17
|
+
class ImporterRegistry {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
/** A map from importer IDs to their corresponding importers. */
|
|
21
|
+
this.importersById = new Map();
|
|
22
|
+
/** A map from file importer IDs to their corresponding importers. */
|
|
23
|
+
this.fileImportersById = new Map();
|
|
24
|
+
/** The next ID to use for an importer. */
|
|
25
|
+
this.id = 0;
|
|
26
|
+
this.importers = ((_a = options === null || options === void 0 ? void 0 : options.importers) !== null && _a !== void 0 ? _a : [])
|
|
27
|
+
.map(importer => this.register(importer))
|
|
28
|
+
.concat(((_b = options === null || options === void 0 ? void 0 : options.loadPaths) !== null && _b !== void 0 ? _b : []).map(path => {
|
|
29
|
+
const proto = new embedded_sass_pb_1.InboundMessage.CompileRequest.Importer();
|
|
30
|
+
proto.setPath(p.resolve(path));
|
|
31
|
+
return proto;
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
/** Converts an importer to a proto without adding it to `this.importers`. */
|
|
35
|
+
register(importer) {
|
|
36
|
+
const proto = new embedded_sass_pb_1.InboundMessage.CompileRequest.Importer();
|
|
37
|
+
if ('canonicalize' in importer) {
|
|
38
|
+
if ('findFileUrl' in importer) {
|
|
39
|
+
throw new Error('Importer may not contain both canonicalize() and findFileUrl(): ' +
|
|
40
|
+
(0, util_1.inspect)(importer));
|
|
41
|
+
}
|
|
42
|
+
proto.setImporterId(this.id);
|
|
43
|
+
this.importersById.set(this.id, importer);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
proto.setFileImporterId(this.id);
|
|
47
|
+
this.fileImportersById.set(this.id, importer);
|
|
48
|
+
}
|
|
49
|
+
this.id += 1;
|
|
50
|
+
return proto;
|
|
51
|
+
}
|
|
52
|
+
/** Handles a canonicalization request. */
|
|
53
|
+
canonicalize(request) {
|
|
54
|
+
const importer = this.importersById.get(request.getImporterId());
|
|
55
|
+
if (!importer) {
|
|
56
|
+
throw utils.compilerError('Unknown CanonicalizeRequest.importer_id');
|
|
57
|
+
}
|
|
58
|
+
return (0, utils_1.catchOr)(() => {
|
|
59
|
+
return (0, utils_1.thenOr)(importer.canonicalize(request.getUrl(), {
|
|
60
|
+
fromImport: request.getFromImport(),
|
|
61
|
+
}), url => {
|
|
62
|
+
const proto = new embedded_sass_pb_1.InboundMessage.CanonicalizeResponse();
|
|
63
|
+
if (url !== null)
|
|
64
|
+
proto.setUrl(url.toString());
|
|
65
|
+
return proto;
|
|
66
|
+
});
|
|
67
|
+
}, error => {
|
|
68
|
+
const proto = new embedded_sass_pb_1.InboundMessage.CanonicalizeResponse();
|
|
69
|
+
proto.setError(`${error}`);
|
|
70
|
+
return proto;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** Handles an import request. */
|
|
74
|
+
import(request) {
|
|
75
|
+
const importer = this.importersById.get(request.getImporterId());
|
|
76
|
+
if (!importer) {
|
|
77
|
+
throw utils.compilerError('Unknown ImportRequest.importer_id');
|
|
78
|
+
}
|
|
79
|
+
return (0, utils_1.catchOr)(() => {
|
|
80
|
+
return (0, utils_1.thenOr)(importer.load(new url_1.URL(request.getUrl())), result => {
|
|
81
|
+
const proto = new embedded_sass_pb_1.InboundMessage.ImportResponse();
|
|
82
|
+
if (result) {
|
|
83
|
+
const success = new embedded_sass_pb_1.InboundMessage.ImportResponse.ImportSuccess();
|
|
84
|
+
success.setContents(result.contents);
|
|
85
|
+
success.setSyntax(utils.protofySyntax(result.syntax));
|
|
86
|
+
if (result.sourceMapUrl) {
|
|
87
|
+
success.setSourceMapUrl(result.sourceMapUrl.toString());
|
|
88
|
+
}
|
|
89
|
+
proto.setSuccess(success);
|
|
90
|
+
}
|
|
91
|
+
return proto;
|
|
92
|
+
});
|
|
93
|
+
}, error => {
|
|
94
|
+
const proto = new embedded_sass_pb_1.InboundMessage.ImportResponse();
|
|
95
|
+
proto.setError(`${error}`);
|
|
96
|
+
return proto;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/** Handles a file import request. */
|
|
100
|
+
fileImport(request) {
|
|
101
|
+
const importer = this.fileImportersById.get(request.getImporterId());
|
|
102
|
+
if (!importer) {
|
|
103
|
+
throw utils.compilerError('Unknown FileImportRequest.importer_id');
|
|
104
|
+
}
|
|
105
|
+
return (0, utils_1.catchOr)(() => {
|
|
106
|
+
return (0, utils_1.thenOr)(importer.findFileUrl(request.getUrl(), {
|
|
107
|
+
fromImport: request.getFromImport(),
|
|
108
|
+
}), url => {
|
|
109
|
+
const proto = new embedded_sass_pb_1.InboundMessage.FileImportResponse();
|
|
110
|
+
if (url) {
|
|
111
|
+
if (url.protocol !== 'file:') {
|
|
112
|
+
throw (`FileImporter ${(0, util_1.inspect)(importer)} returned non-file: URL ` +
|
|
113
|
+
+`"${url}" for URL "${request.getUrl()}".`);
|
|
114
|
+
}
|
|
115
|
+
proto.setFileUrl(url.toString());
|
|
116
|
+
}
|
|
117
|
+
return proto;
|
|
118
|
+
});
|
|
119
|
+
}, error => {
|
|
120
|
+
const proto = new embedded_sass_pb_1.InboundMessage.FileImportResponse();
|
|
121
|
+
proto.setError(`${error}`);
|
|
122
|
+
return proto;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.ImporterRegistry = ImporterRegistry;
|
|
127
|
+
//# sourceMappingURL=importer-registry.js.map
|