sass-embedded 1.69.7 → 1.71.0

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.
Files changed (39) hide show
  1. package/dist/lib/index.js +10 -4
  2. package/dist/lib/index.js.map +1 -1
  3. package/dist/lib/index.mjs +25 -0
  4. package/dist/lib/src/compile.js +28 -228
  5. package/dist/lib/src/compile.js.map +1 -1
  6. package/dist/lib/src/compiler/async.js +127 -0
  7. package/dist/lib/src/compiler/async.js.map +1 -0
  8. package/dist/lib/src/compiler/sync.js +146 -0
  9. package/dist/lib/src/compiler/sync.js.map +1 -0
  10. package/dist/lib/src/compiler/utils.js +153 -0
  11. package/dist/lib/src/compiler/utils.js.map +1 -0
  12. package/dist/lib/src/dispatcher.js +23 -5
  13. package/dist/lib/src/dispatcher.js.map +1 -1
  14. package/dist/lib/src/function-registry.js +4 -7
  15. package/dist/lib/src/function-registry.js.map +1 -1
  16. package/dist/lib/src/importer-registry.js +28 -2
  17. package/dist/lib/src/importer-registry.js.map +1 -1
  18. package/dist/lib/src/legacy/index.js +9 -2
  19. package/dist/lib/src/legacy/index.js.map +1 -1
  20. package/dist/lib/src/legacy/utils.js +10 -10
  21. package/dist/lib/src/legacy/utils.js.map +1 -1
  22. package/dist/lib/src/logger.js +10 -0
  23. package/dist/lib/src/logger.js.map +1 -0
  24. package/dist/lib/src/vendor/embedded_sass_pb.js +51 -1
  25. package/dist/lib/src/vendor/embedded_sass_pb.js.map +1 -1
  26. package/dist/package.json +19 -19
  27. package/dist/tool/utils.js +2 -2
  28. package/dist/tool/utils.js.map +1 -1
  29. package/dist/types/compile.d.ts +184 -6
  30. package/dist/types/importer.d.ts +133 -0
  31. package/dist/types/index.d.ts +5 -0
  32. package/dist/types/index.m.d.ts +5 -0
  33. package/dist/types/legacy/options.d.ts +19 -0
  34. package/dist/types/options.d.ts +4 -4
  35. package/package.json +19 -19
  36. package/dist/lib/src/async-compiler.js +0 -42
  37. package/dist/lib/src/async-compiler.js.map +0 -1
  38. package/dist/lib/src/sync-compiler.js +0 -55
  39. package/dist/lib/src/sync-compiler.js.map +0 -1
package/dist/lib/index.js CHANGED
@@ -3,7 +3,7 @@
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.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.SassCalculation = exports.CalculationInterpolation = exports.CalculationOperation = exports.sassNull = exports.Value = exports.SassString = exports.SassNumber = exports.SassMixin = exports.SassMap = exports.SassFunction = exports.SassColor = exports.sassTrue = exports.sassFalse = exports.SassArgumentList = exports.SassList = void 0;
6
+ exports.NULL = exports.FALSE = exports.TRUE = exports.Logger = exports.info = exports.renderSync = exports.render = exports.Compiler = exports.initCompiler = exports.AsyncCompiler = exports.initAsyncCompiler = exports.NodePackageImporter = exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = exports.Exception = exports.types = exports.SassCalculation = exports.CalculationInterpolation = exports.CalculationOperation = exports.sassNull = exports.Value = exports.SassString = exports.SassNumber = exports.SassMixin = exports.SassMap = exports.SassFunction = exports.SassColor = exports.sassTrue = exports.sassFalse = exports.SassArgumentList = exports.SassList = void 0;
7
7
  const pkg = require("../package.json");
8
8
  const boolean_1 = require("./src/value/boolean");
9
9
  const null_1 = require("./src/value/null");
@@ -42,13 +42,19 @@ Object.defineProperty(exports, "compile", { enumerable: true, get: function () {
42
42
  Object.defineProperty(exports, "compileString", { enumerable: true, get: function () { return compile_1.compileString; } });
43
43
  Object.defineProperty(exports, "compileAsync", { enumerable: true, get: function () { return compile_1.compileAsync; } });
44
44
  Object.defineProperty(exports, "compileStringAsync", { enumerable: true, get: function () { return compile_1.compileStringAsync; } });
45
+ Object.defineProperty(exports, "NodePackageImporter", { enumerable: true, get: function () { return compile_1.NodePackageImporter; } });
46
+ var async_1 = require("./src/compiler/async");
47
+ Object.defineProperty(exports, "initAsyncCompiler", { enumerable: true, get: function () { return async_1.initAsyncCompiler; } });
48
+ Object.defineProperty(exports, "AsyncCompiler", { enumerable: true, get: function () { return async_1.AsyncCompiler; } });
49
+ var sync_1 = require("./src/compiler/sync");
50
+ Object.defineProperty(exports, "initCompiler", { enumerable: true, get: function () { return sync_1.initCompiler; } });
51
+ Object.defineProperty(exports, "Compiler", { enumerable: true, get: function () { return sync_1.Compiler; } });
45
52
  var legacy_1 = require("./src/legacy");
46
53
  Object.defineProperty(exports, "render", { enumerable: true, get: function () { return legacy_1.render; } });
47
54
  Object.defineProperty(exports, "renderSync", { enumerable: true, get: function () { return legacy_1.renderSync; } });
48
55
  exports.info = `sass-embedded\t${pkg.version}`;
49
- exports.Logger = {
50
- silent: { warn() { }, debug() { } },
51
- };
56
+ var logger_1 = require("./src/logger");
57
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
52
58
  // Legacy JS API
53
59
  exports.TRUE = boolean_1.sassTrue;
54
60
  exports.FALSE = boolean_1.sassFalse;
@@ -1 +1 @@
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,2CAA4C;AAApC,kGAAA,SAAS,OAAA;AACjB,6CAA8C;AAAtC,oGAAA,UAAU,OAAA;AAClB,6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,6CAA8C;AAAtC,oGAAA,UAAU,OAAA;AAClB,6CAA8C;AAAtC,oGAAA,UAAU,OAAA;AAClB,qCAAkC;AAA1B,8FAAA,KAAK,OAAA;AACb,yCAA0C;AAAlC,gGAAA,QAAQ,OAAA;AAChB,yDAKkC;AAJhC,oHAAA,oBAAoB,OAAA;AAEpB,wHAAA,wBAAwB,OAAA;AACxB,+GAAA,eAAe,OAAA;AAGjB,8CAA4C;AAC5C,6CAA0C;AAAlC,sGAAA,SAAS,OAAA;AACjB,yCAMuB;AALrB,kGAAA,OAAO,OAAA;AACP,wGAAA,aAAa,OAAA;AACb,uGAAA,YAAY,OAAA;AACZ,6GAAA,kBAAkB,OAAA;AAClB,8GAAA,mBAAmB,OAAA;AAErB,8CAAsE;AAA9D,0GAAA,iBAAiB,OAAA;AAAE,sGAAA,aAAa,OAAA;AACxC,4CAA2D;AAAnD,oGAAA,YAAY,OAAA;AAAE,gGAAA,QAAQ,OAAA;AAC9B,uCAAgD;AAAxC,gGAAA,MAAM,OAAA;AAAE,oGAAA,UAAU,OAAA;AAEb,QAAA,IAAI,GAAG,kBAAkB,GAAG,CAAC,OAAO,EAAE,CAAC;AAEpD,uCAAoC;AAA5B,gGAAA,MAAM,OAAA;AAEd,gBAAgB;AAEH,QAAA,IAAI,GAAG,kBAAQ,CAAC;AAChB,QAAA,KAAK,GAAG,mBAAS,CAAC;AAClB,QAAA,IAAI,GAAG,eAAQ,CAAC"}
@@ -4,6 +4,11 @@ export const compile = sass.compile;
4
4
  export const compileAsync = sass.compileAsync;
5
5
  export const compileString = sass.compileString;
6
6
  export const compileStringAsync = sass.compileStringAsync;
7
+ export const NodePackageImporter = sass.NodePackageImporter;
8
+ export const AsyncCompiler = sass.AsyncCompiler;
9
+ export const Compiler = sass.Compiler;
10
+ export const initAsyncCompiler = sass.initAsyncCompiler;
11
+ export const initCompiler = sass.initCompiler;
7
12
  export const Logger = sass.Logger;
8
13
  export const CalculationInterpolation = sass.CalculationInterpolation;
9
14
  export const CalculationOperation = sass.CalculationOperation;
@@ -61,6 +66,26 @@ export default {
61
66
  defaultExportDeprecation();
62
67
  return sass.compileStringAsync;
63
68
  },
69
+ get NodePackageImporter() {
70
+ defaultExportDeprecation();
71
+ return sass.NodePackageImporter;
72
+ },
73
+ get initAsyncCompiler() {
74
+ defaultExportDeprecation();
75
+ return sass.initAsyncCompiler;
76
+ },
77
+ get initCompiler() {
78
+ defaultExportDeprecation();
79
+ return sass.initCompiler;
80
+ },
81
+ get AsyncCompiler() {
82
+ defaultExportDeprecation();
83
+ return sass.AsyncCompiler;
84
+ },
85
+ get Compiler() {
86
+ defaultExportDeprecation();
87
+ return sass.Compiler;
88
+ },
64
89
  get Logger() {
65
90
  defaultExportDeprecation();
66
91
  return sass.Logger;
@@ -3,249 +3,49 @@
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.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = void 0;
7
- const p = require("path");
8
- const supportsColor = require("supports-color");
9
- const proto = require("./vendor/embedded_sass_pb");
10
- const utils = require("./utils");
11
- const async_compiler_1 = require("./async-compiler");
12
- const dispatcher_1 = require("./dispatcher");
13
- const exception_1 = require("./exception");
14
- const function_registry_1 = require("./function-registry");
15
- const importer_registry_1 = require("./importer-registry");
16
- const message_transformer_1 = require("./message-transformer");
17
- const packet_transformer_1 = require("./packet-transformer");
18
- const sync_compiler_1 = require("./sync-compiler");
19
- const deprotofy_span_1 = require("./deprotofy-span");
20
- const utils_1 = require("./legacy/utils");
6
+ exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = exports.NodePackageImporter = void 0;
7
+ const async_1 = require("./compiler/async");
8
+ const sync_1 = require("./compiler/sync");
9
+ var importer_registry_1 = require("./importer-registry");
10
+ Object.defineProperty(exports, "NodePackageImporter", { enumerable: true, get: function () { return importer_registry_1.NodePackageImporter; } });
21
11
  function compile(path, options) {
22
- const importers = new importer_registry_1.ImporterRegistry(options);
23
- return compileRequestSync(newCompilePathRequest(path, importers, options), importers, options);
24
- }
25
- exports.compile = compile;
26
- function compileString(source, options) {
27
- const importers = new importer_registry_1.ImporterRegistry(options);
28
- return compileRequestSync(newCompileStringRequest(source, importers, options), importers, options);
29
- }
30
- exports.compileString = compileString;
31
- function compileAsync(path, options) {
32
- const importers = new importer_registry_1.ImporterRegistry(options);
33
- return compileRequestAsync(newCompilePathRequest(path, importers, options), importers, options);
34
- }
35
- exports.compileAsync = compileAsync;
36
- function compileStringAsync(source, options) {
37
- const importers = new importer_registry_1.ImporterRegistry(options);
38
- return compileRequestAsync(newCompileStringRequest(source, importers, options), importers, options);
39
- }
40
- exports.compileStringAsync = compileStringAsync;
41
- // Creates a request for compiling a file.
42
- function newCompilePathRequest(path, importers, options) {
43
- const request = newCompileRequest(importers, options);
44
- request.input = { case: 'path', value: path };
45
- return request;
46
- }
47
- // Creates a request for compiling a string.
48
- function newCompileStringRequest(source, importers, options) {
49
- var _a, _b;
50
- const input = new proto.InboundMessage_CompileRequest_StringInput({
51
- source,
52
- syntax: utils.protofySyntax((_a = options === null || options === void 0 ? void 0 : options.syntax) !== null && _a !== void 0 ? _a : 'scss'),
53
- });
54
- const url = (_b = options === null || options === void 0 ? void 0 : options.url) === null || _b === void 0 ? void 0 : _b.toString();
55
- if (url && url !== utils_1.legacyImporterProtocol) {
56
- input.url = url;
57
- }
58
- if (options && 'importer' in options && options.importer) {
59
- input.importer = importers.register(options.importer);
60
- }
61
- else if (url === utils_1.legacyImporterProtocol) {
62
- input.importer = new proto.InboundMessage_CompileRequest_Importer({
63
- importer: { case: 'path', value: p.resolve('.') },
64
- });
65
- }
66
- else {
67
- // When importer is not set on the host, the compiler will set a
68
- // FileSystemImporter if `url` is set to a file: url or a NoOpImporter.
69
- }
70
- const request = newCompileRequest(importers, options);
71
- request.input = { case: 'string', value: input };
72
- return request;
73
- }
74
- // Creates a compilation request for the given `options` without adding any
75
- // input-specific options.
76
- function newCompileRequest(importers, options) {
77
- var _a, _b, _c, _d;
78
- const request = new proto.InboundMessage_CompileRequest({
79
- importers: importers.importers,
80
- globalFunctions: Object.keys((_a = options === null || options === void 0 ? void 0 : options.functions) !== null && _a !== void 0 ? _a : {}),
81
- sourceMap: !!(options === null || options === void 0 ? void 0 : options.sourceMap),
82
- sourceMapIncludeSources: !!(options === null || options === void 0 ? void 0 : options.sourceMapIncludeSources),
83
- alertColor: (_b = options === null || options === void 0 ? void 0 : options.alertColor) !== null && _b !== void 0 ? _b : !!supportsColor.stdout,
84
- alertAscii: !!(options === null || options === void 0 ? void 0 : options.alertAscii),
85
- quietDeps: !!(options === null || options === void 0 ? void 0 : options.quietDeps),
86
- verbose: !!(options === null || options === void 0 ? void 0 : options.verbose),
87
- charset: !!((_c = options === null || options === void 0 ? void 0 : options.charset) !== null && _c !== void 0 ? _c : true),
88
- });
89
- switch ((_d = options === null || options === void 0 ? void 0 : options.style) !== null && _d !== void 0 ? _d : 'expanded') {
90
- case 'expanded':
91
- request.style = proto.OutputStyle.EXPANDED;
92
- break;
93
- case 'compressed':
94
- request.style = proto.OutputStyle.COMPRESSED;
95
- break;
96
- default:
97
- throw new Error(`Unknown options.style: "${options === null || options === void 0 ? void 0 : options.style}"`);
98
- }
99
- return request;
100
- }
101
- // Spins up a compiler, then sends it a compile request. Returns a promise that
102
- // resolves with the CompileResult. Throws if there were any protocol or
103
- // compilation errors. Shuts down the compiler after compilation.
104
- async function compileRequestAsync(request, importers, options) {
105
- const functions = new function_registry_1.FunctionRegistry(options === null || options === void 0 ? void 0 : options.functions);
106
- const embeddedCompiler = new async_compiler_1.AsyncEmbeddedCompiler();
107
- embeddedCompiler.stderr$.subscribe(data => process.stderr.write(data));
12
+ const compiler = (0, sync_1.initCompiler)();
108
13
  try {
109
- const dispatcher = createDispatcher(embeddedCompiler.stdout$, buffer => {
110
- embeddedCompiler.writeStdin(buffer);
111
- }, {
112
- handleImportRequest: request => importers.import(request),
113
- handleFileImportRequest: request => importers.fileImport(request),
114
- handleCanonicalizeRequest: request => importers.canonicalize(request),
115
- handleFunctionCallRequest: request => functions.call(request),
116
- });
117
- dispatcher.logEvents$.subscribe(event => handleLogEvent(options, event));
118
- return handleCompileResponse(await new Promise((resolve, reject) => dispatcher.sendCompileRequest(request, (err, response) => {
119
- if (err) {
120
- reject(err);
121
- }
122
- else {
123
- resolve(response);
124
- }
125
- })));
14
+ return compiler.compile(path, options);
126
15
  }
127
16
  finally {
128
- embeddedCompiler.close();
129
- await embeddedCompiler.exit$;
17
+ compiler.dispose();
130
18
  }
131
19
  }
132
- // Spins up a compiler, then sends it a compile request. Returns a promise that
133
- // resolves with the CompileResult. Throws if there were any protocol or
134
- // compilation errors. Shuts down the compiler after compilation.
135
- function compileRequestSync(request, importers, options) {
136
- const functions = new function_registry_1.FunctionRegistry(options === null || options === void 0 ? void 0 : options.functions);
137
- const embeddedCompiler = new sync_compiler_1.SyncEmbeddedCompiler();
138
- embeddedCompiler.stderr$.subscribe(data => process.stderr.write(data));
20
+ exports.compile = compile;
21
+ function compileString(source, options) {
22
+ const compiler = (0, sync_1.initCompiler)();
139
23
  try {
140
- const dispatcher = createDispatcher(embeddedCompiler.stdout$, buffer => {
141
- embeddedCompiler.writeStdin(buffer);
142
- }, {
143
- handleImportRequest: request => importers.import(request),
144
- handleFileImportRequest: request => importers.fileImport(request),
145
- handleCanonicalizeRequest: request => importers.canonicalize(request),
146
- handleFunctionCallRequest: request => functions.call(request),
147
- });
148
- dispatcher.logEvents$.subscribe(event => handleLogEvent(options, event));
149
- let error;
150
- let response;
151
- dispatcher.sendCompileRequest(request, (error_, response_) => {
152
- if (error_) {
153
- error = error_;
154
- }
155
- else {
156
- response = response_;
157
- }
158
- });
159
- for (;;) {
160
- if (!embeddedCompiler.yield()) {
161
- throw utils.compilerError('Embedded compiler exited unexpectedly.');
162
- }
163
- if (error)
164
- throw error;
165
- if (response)
166
- return handleCompileResponse(response);
167
- }
24
+ return compiler.compileString(source, options);
168
25
  }
169
26
  finally {
170
- embeddedCompiler.close();
171
- embeddedCompiler.yieldUntilExit();
27
+ compiler.dispose();
172
28
  }
173
29
  }
174
- /**
175
- * Creates a dispatcher that dispatches messages from the given `stdout` stream.
176
- */
177
- function createDispatcher(stdout, writeStdin, handlers) {
178
- const packetTransformer = new packet_transformer_1.PacketTransformer(stdout, writeStdin);
179
- const messageTransformer = new message_transformer_1.MessageTransformer(packetTransformer.outboundProtobufs$, packet => packetTransformer.writeInboundProtobuf(packet));
180
- return new dispatcher_1.Dispatcher(
181
- // Since we only use one compilation per process, we can get away with
182
- // hardcoding a compilation ID. Once we support multiple concurrent
183
- // compilations with the same process, we'll need to ensure each one uses a
184
- // unique ID.
185
- 1, messageTransformer.outboundMessages$, message => messageTransformer.writeInboundMessage(message), handlers);
186
- }
187
- /** Handles a log event according to `options`. */
188
- function handleLogEvent(options, event) {
189
- var _a, _b;
190
- let span = event.span ? (0, deprotofy_span_1.deprotofySourceSpan)(event.span) : null;
191
- if (span && (options === null || options === void 0 ? void 0 : options.legacy))
192
- span = (0, utils_1.removeLegacyImporterFromSpan)(span);
193
- let message = event.message;
194
- if (options === null || options === void 0 ? void 0 : options.legacy)
195
- message = (0, utils_1.removeLegacyImporter)(message);
196
- let formatted = event.formatted;
197
- if (options === null || options === void 0 ? void 0 : options.legacy)
198
- formatted = (0, utils_1.removeLegacyImporter)(formatted);
199
- if (event.type === proto.LogEventType.DEBUG) {
200
- if ((_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.debug) {
201
- options.logger.debug(message, {
202
- span: span,
203
- });
204
- }
205
- else {
206
- console.error(formatted);
207
- }
30
+ exports.compileString = compileString;
31
+ async function compileAsync(path, options) {
32
+ const compiler = await (0, async_1.initAsyncCompiler)();
33
+ try {
34
+ return await compiler.compileAsync(path, options);
208
35
  }
209
- else {
210
- if ((_b = options === null || options === void 0 ? void 0 : options.logger) === null || _b === void 0 ? void 0 : _b.warn) {
211
- const params = {
212
- deprecation: event.type === proto.LogEventType.DEPRECATION_WARNING,
213
- };
214
- if (span)
215
- params.span = span;
216
- const stack = event.stackTrace;
217
- if (stack) {
218
- params.stack = (options === null || options === void 0 ? void 0 : options.legacy) ? (0, utils_1.removeLegacyImporter)(stack) : stack;
219
- }
220
- options.logger.warn(message, params);
221
- }
222
- else {
223
- console.error(formatted);
224
- }
36
+ finally {
37
+ await compiler.dispose();
225
38
  }
226
39
  }
227
- /**
228
- * Converts a `CompileResponse` into a `CompileResult`.
229
- *
230
- * Throws a `SassException` if the compilation failed.
231
- */
232
- function handleCompileResponse(response) {
233
- if (response.result.case === 'success') {
234
- const success = response.result.value;
235
- const result = {
236
- css: success.css,
237
- loadedUrls: response.loadedUrls.map(url => new URL(url)),
238
- };
239
- const sourceMap = success.sourceMap;
240
- if (sourceMap)
241
- result.sourceMap = JSON.parse(sourceMap);
242
- return result;
243
- }
244
- else if (response.result.case === 'failure') {
245
- throw new exception_1.Exception(response.result.value);
40
+ exports.compileAsync = compileAsync;
41
+ async function compileStringAsync(source, options) {
42
+ const compiler = await (0, async_1.initAsyncCompiler)();
43
+ try {
44
+ return await compiler.compileStringAsync(source, options);
246
45
  }
247
- else {
248
- throw utils.compilerError('Compiler sent empty CompileResponse.');
46
+ finally {
47
+ await compiler.dispose();
249
48
  }
250
49
  }
50
+ exports.compileStringAsync = compileStringAsync;
251
51
  //# sourceMappingURL=compile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.js","sourceRoot":"","sources":["../../../lib/src/compile.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,0BAA0B;AAE1B,gDAAgD;AAEhD,mDAAmD;AACnD,iCAAiC;AACjC,qDAAuD;AAEvD,6CAA4D;AAC5D,2CAAsC;AACtC,2DAAqD;AACrD,2DAAqD;AACrD,+DAAyD;AACzD,6DAAuD;AACvD,mDAAqD;AACrD,qDAAqD;AACrD,0CAIwB;AAmBxB,SAAgB,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AAM,IAAA,yBAAiB,GAAE,CAAC;IAC3C,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;YAAS,CAAC;QACT,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;AACH,CAAC;AAVD,gDAUC"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ // Copyright 2024 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.initAsyncCompiler = exports.AsyncCompiler = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const rxjs_1 = require("rxjs");
9
+ const operators_1 = require("rxjs/operators");
10
+ const path = require("path");
11
+ const utils_1 = require("./utils");
12
+ const compiler_path_1 = require("../compiler-path");
13
+ const function_registry_1 = require("../function-registry");
14
+ const importer_registry_1 = require("../importer-registry");
15
+ const message_transformer_1 = require("../message-transformer");
16
+ const packet_transformer_1 = require("../packet-transformer");
17
+ const utils = require("../utils");
18
+ /**
19
+ * Flag allowing the constructor passed by `initAsyncCompiler` so we can
20
+ * differentiate and throw an error if the `AsyncCompiler` is constructed via
21
+ * `new AsyncCompiler`.
22
+ */
23
+ const initFlag = Symbol();
24
+ /** An asynchronous wrapper for the embedded Sass compiler */
25
+ class AsyncCompiler {
26
+ /** Writes `buffer` to the child process's stdin. */
27
+ writeStdin(buffer) {
28
+ this.process.stdin.write(buffer);
29
+ }
30
+ /** Guards against using a disposed compiler. */
31
+ throwIfDisposed() {
32
+ if (this.disposed) {
33
+ throw utils.compilerError('Async compiler has already been disposed.');
34
+ }
35
+ }
36
+ /**
37
+ * Sends a compile request to the child process and returns a Promise that
38
+ * resolves with the CompileResult. Rejects the promise if there were any
39
+ * protocol or compilation errors.
40
+ */
41
+ async compileRequestAsync(request, importers, options) {
42
+ const functions = new function_registry_1.FunctionRegistry(options === null || options === void 0 ? void 0 : options.functions);
43
+ const dispatcher = (0, utils_1.createDispatcher)(this.compilationId++, this.messageTransformer, {
44
+ handleImportRequest: request => importers.import(request),
45
+ handleFileImportRequest: request => importers.fileImport(request),
46
+ handleCanonicalizeRequest: request => importers.canonicalize(request),
47
+ handleFunctionCallRequest: request => functions.call(request),
48
+ });
49
+ dispatcher.logEvents$.subscribe(event => (0, utils_1.handleLogEvent)(options, event));
50
+ const compilation = new Promise((resolve, reject) => dispatcher.sendCompileRequest(request, (err, response) => {
51
+ this.compilations.delete(compilation);
52
+ // Reset the compilation ID when the compiler goes idle (no active
53
+ // compilations) to avoid overflowing it.
54
+ // https://github.com/sass/embedded-host-node/pull/261#discussion_r1429266794
55
+ if (this.compilations.size === 0)
56
+ this.compilationId = 1;
57
+ if (err) {
58
+ reject(err);
59
+ }
60
+ else {
61
+ resolve(response);
62
+ }
63
+ }));
64
+ this.compilations.add(compilation);
65
+ return (0, utils_1.handleCompileResponse)(await compilation);
66
+ }
67
+ /** Initialize resources shared across compilations. */
68
+ constructor(flag) {
69
+ /** The underlying process that's being wrapped. */
70
+ this.process = (0, child_process_1.spawn)(compiler_path_1.compilerCommand[0], [...compiler_path_1.compilerCommand.slice(1), '--embedded'], {
71
+ // Use the command's cwd so the compiler survives the removal of the
72
+ // current working directory.
73
+ // https://github.com/sass/embedded-host-node/pull/261#discussion_r1438712923
74
+ cwd: path.dirname(compiler_path_1.compilerCommand[0]),
75
+ windowsHide: true,
76
+ });
77
+ /** The next compilation ID. */
78
+ this.compilationId = 1;
79
+ /** A list of active compilations. */
80
+ this.compilations = new Set();
81
+ /** Whether the underlying compiler has already exited. */
82
+ this.disposed = false;
83
+ /** The child process's exit event. */
84
+ this.exit$ = new Promise(resolve => {
85
+ this.process.on('exit', code => resolve(code));
86
+ });
87
+ /** The buffers emitted by the child process's stdout. */
88
+ this.stdout$ = new rxjs_1.Observable(observer => {
89
+ this.process.stdout.on('data', buffer => observer.next(buffer));
90
+ }).pipe((0, operators_1.takeUntil)(this.exit$));
91
+ /** The buffers emitted by the child process's stderr. */
92
+ this.stderr$ = new rxjs_1.Observable(observer => {
93
+ this.process.stderr.on('data', buffer => observer.next(buffer));
94
+ }).pipe((0, operators_1.takeUntil)(this.exit$));
95
+ if (flag !== initFlag) {
96
+ throw utils.compilerError('AsyncCompiler can not be directly constructed. ' +
97
+ 'Please use `sass.initAsyncCompiler()` instead.');
98
+ }
99
+ this.stderr$.subscribe(data => process.stderr.write(data));
100
+ const packetTransformer = new packet_transformer_1.PacketTransformer(this.stdout$, buffer => {
101
+ this.writeStdin(buffer);
102
+ });
103
+ this.messageTransformer = new message_transformer_1.MessageTransformer(packetTransformer.outboundProtobufs$, packet => packetTransformer.writeInboundProtobuf(packet));
104
+ }
105
+ compileAsync(path, options) {
106
+ this.throwIfDisposed();
107
+ const importers = new importer_registry_1.ImporterRegistry(options);
108
+ return this.compileRequestAsync((0, utils_1.newCompilePathRequest)(path, importers, options), importers, options);
109
+ }
110
+ compileStringAsync(source, options) {
111
+ this.throwIfDisposed();
112
+ const importers = new importer_registry_1.ImporterRegistry(options);
113
+ return this.compileRequestAsync((0, utils_1.newCompileStringRequest)(source, importers, options), importers, options);
114
+ }
115
+ async dispose() {
116
+ this.disposed = true;
117
+ await Promise.all(this.compilations);
118
+ this.process.stdin.end();
119
+ await this.exit$;
120
+ }
121
+ }
122
+ exports.AsyncCompiler = AsyncCompiler;
123
+ async function initAsyncCompiler() {
124
+ return new AsyncCompiler(initFlag);
125
+ }
126
+ exports.initAsyncCompiler = initAsyncCompiler;
127
+ //# sourceMappingURL=async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.js","sourceRoot":"","sources":["../../../../lib/src/compiler/async.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,iDAAoC;AACpC,+BAAgC;AAChC,8CAAyC;AAEzC,6BAA6B;AAC7B,mCAQiB;AACjB,oDAAiD;AACjD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