Skip to content

Commit ddff73f

Browse files
authored
Merge pull request #329 from sass/merge-main
Merge origin/main into feature.color-4
2 parents 21c99cb + 9f10f60 commit ddff73f

File tree

33 files changed

+223
-130
lines changed

33 files changed

+223
-130
lines changed

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
## 1.78.0
2+
3+
* The `meta.feature-exists` function is now deprecated. This deprecation is
4+
named `feature-exists`.
5+
6+
* Fix a crash when using `@at-root` without any queries or children in the
7+
indented syntax.
8+
9+
### JS API
10+
11+
* Backport the deprecation options (`fatalDeprecations`, `futureDeprecations`,
12+
and `silenceDeprecations`) to the legacy JS API. The legacy JS API is itself
13+
deprecated, and you should move off of it if possible, but this will allow
14+
users of bundlers and other tools that are still using the legacy API to
15+
still control deprecation warnings.
16+
17+
* Fix a bug where accessing `SourceSpan.url` would crash when a relative URL was
18+
passed to the Sass API.
19+
20+
### Embedded Sass
21+
22+
* Explicitly expose a `sass` executable from the `sass-embedded` npm package.
23+
This was intended to be included in 1.63.0, but due to the way
24+
platform-specific dependency executables are installed it did not work as
25+
intended. Now users can run `npx sass` for local installs or just `sass` when
26+
`sass-embedded` is installed globally.
27+
28+
* Add linux-riscv64, linux-musl-riscv64, and android-riscv64 support for the
29+
`sass-embedded` npm package.
30+
31+
* Fix an edge case where the Dart VM could hang when shutting down when requests
32+
were in flight.
33+
34+
* Fix a race condition where the embedded host could fail to shut down if it was
35+
closed around the same time a new compilation was started.
36+
37+
* Fix a bug where parse-time deprecation warnings could not be controlled by
38+
the deprecation options in some circumstances.
39+
140
## 1.77.8
241

342
* No user-visible changes.

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const config = {
2+
roots: ['<rootDir>/lib/', '<rootDir>/test/'],
23
preset: 'ts-jest',
34
testEnvironment: 'node',
45
};

lib/src/compiler/utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import * as p from 'path';
66
import * as supportsColor from 'supports-color';
7+
import {create} from '@bufbuild/protobuf';
8+
79
import {Deprecation, deprecations, getDeprecationIds} from '../deprecations';
810
import {deprotofySourceSpan} from '../deprotofy-span';
911
import {Dispatcher, DispatcherHandlers} from '../dispatcher';
@@ -65,7 +67,7 @@ function newCompileRequest(
6567
importers: ImporterRegistry<'sync' | 'async'>,
6668
options?: Options<'sync' | 'async'>
6769
): proto.InboundMessage_CompileRequest {
68-
const request = new proto.InboundMessage_CompileRequest({
70+
const request = create(proto.InboundMessage_CompileRequestSchema, {
6971
importers: importers.importers,
7072
globalFunctions: Object.keys(options?.functions ?? {}),
7173
sourceMap: !!options?.sourceMap,
@@ -115,7 +117,7 @@ export function newCompileStringRequest(
115117
importers: ImporterRegistry<'sync' | 'async'>,
116118
options?: StringOptions<'sync' | 'async'>
117119
): proto.InboundMessage_CompileRequest {
118-
const input = new proto.InboundMessage_CompileRequest_StringInput({
120+
const input = create(proto.InboundMessage_CompileRequest_StringInputSchema, {
119121
source,
120122
syntax: utils.protofySyntax(options?.syntax ?? 'scss'),
121123
});
@@ -128,9 +130,12 @@ export function newCompileStringRequest(
128130
if (options && 'importer' in options && options.importer) {
129131
input.importer = importers.register(options.importer);
130132
} else if (url === legacyImporterProtocol) {
131-
input.importer = new proto.InboundMessage_CompileRequest_Importer({
132-
importer: {case: 'path', value: p.resolve('.')},
133-
});
133+
input.importer = create(
134+
proto.InboundMessage_CompileRequest_ImporterSchema,
135+
{
136+
importer: {case: 'path', value: p.resolve('.')},
137+
}
138+
);
134139
} else {
135140
// When importer is not set on the host, the compiler will set a
136141
// FileSystemImporter if `url` is set to a file: url or a NoOpImporter.

lib/src/dispatcher.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import {Observable, Subject} from 'rxjs';
66
import {filter, map, mergeMap, takeUntil} from 'rxjs/operators';
7+
import {create} from '@bufbuild/protobuf';
78

89
import {OutboundResponse} from './messages';
910
import * as proto from './vendor/embedded_sass_pb';
@@ -144,7 +145,7 @@ export class Dispatcher<sync extends 'sync' | 'async'> {
144145
try {
145146
this.writeInboundMessage([
146147
this.compilationId,
147-
new proto.InboundMessage({
148+
create(proto.InboundMessageSchema, {
148149
message: {value: request, case: 'compileRequest'},
149150
}),
150151
]);
@@ -267,7 +268,7 @@ export class Dispatcher<sync extends 'sync' | 'async'> {
267268

268269
this.writeInboundMessage([
269270
this.compilationId,
270-
new proto.InboundMessage({message}),
271+
create(proto.InboundMessageSchema, {message}),
271272
]);
272273
}
273274
}

lib/src/function-registry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://opensource.org/licenses/MIT.
44

55
import {inspect} from 'util';
6+
import {create} from '@bufbuild/protobuf';
67

78
import * as types from './vendor/sass';
89
import * as utils from './utils';
@@ -74,15 +75,15 @@ export class FunctionRegistry<sync extends 'sync' | 'async'> {
7475
);
7576
}
7677

77-
return new proto.InboundMessage_FunctionCallResponse({
78+
return create(proto.InboundMessage_FunctionCallResponseSchema, {
7879
result: {case: 'success', value: protofier.protofy(result)},
7980
accessedArgumentLists: protofier.accessedArgumentLists,
8081
});
8182
}
8283
);
8384
},
8485
error =>
85-
new proto.InboundMessage_FunctionCallResponse({
86+
create(proto.InboundMessage_FunctionCallResponseSchema, {
8687
result: {case: 'error', value: `${error}`},
8788
})
8889
);

lib/src/importer-registry.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {createRequire} from 'module';
66
import * as p from 'path';
77
import {URL} from 'url';
88
import {inspect} from 'util';
9+
import {create} from '@bufbuild/protobuf';
910

1011
import {CanonicalizeContext} from './canonicalize-context';
1112
import * as utils from './utils';
@@ -64,11 +65,10 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
6465
)
6566
)
6667
.concat(
67-
(options?.loadPaths ?? []).map(
68-
path =>
69-
new proto.InboundMessage_CompileRequest_Importer({
70-
importer: {case: 'path', value: p.resolve(path)},
71-
})
68+
(options?.loadPaths ?? []).map(path =>
69+
create(proto.InboundMessage_CompileRequest_ImporterSchema, {
70+
importer: {case: 'path', value: p.resolve(path)},
71+
})
7272
)
7373
);
7474
}
@@ -77,10 +77,14 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
7777
register(
7878
importer: Importer<sync> | FileImporter<sync> | NodePackageImporter
7979
): proto.InboundMessage_CompileRequest_Importer {
80-
const message = new proto.InboundMessage_CompileRequest_Importer();
80+
const message = create(
81+
proto.InboundMessage_CompileRequest_ImporterSchema,
82+
{}
83+
);
8184
if (importer instanceof NodePackageImporter) {
82-
const importerMessage = new proto.NodePackageImporter();
83-
importerMessage.entryPointDirectory = importer[entryPointDirectoryKey];
85+
const importerMessage = create(proto.NodePackageImporterSchema, {
86+
entryPointDirectory: importer[entryPointDirectoryKey],
87+
});
8488
message.importer = {
8589
case: 'nodePackageImporter',
8690
value: importerMessage,
@@ -126,7 +130,7 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
126130
return thenOr(
127131
importer.canonicalize(request.url, canonicalizeContext),
128132
url =>
129-
new proto.InboundMessage_CanonicalizeResponse({
133+
create(proto.InboundMessage_CanonicalizeResponseSchema, {
130134
result:
131135
url === null
132136
? {case: undefined}
@@ -136,7 +140,7 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
136140
);
137141
},
138142
error =>
139-
new proto.InboundMessage_CanonicalizeResponse({
143+
create(proto.InboundMessage_CanonicalizeResponseSchema, {
140144
result: {case: 'error', value: `${error}`},
141145
})
142146
);
@@ -154,7 +158,8 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
154158
return catchOr(
155159
() => {
156160
return thenOr(importer.load(new URL(request.url)), result => {
157-
if (!result) return new proto.InboundMessage_ImportResponse();
161+
if (!result)
162+
return create(proto.InboundMessage_ImportResponseSchema, {});
158163

159164
if (typeof result.contents !== 'string') {
160165
throw Error(
@@ -171,20 +176,20 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
171176
);
172177
}
173178

174-
return new proto.InboundMessage_ImportResponse({
179+
return create(proto.InboundMessage_ImportResponseSchema, {
175180
result: {
176181
case: 'success',
177-
value: new proto.InboundMessage_ImportResponse_ImportSuccess({
182+
value: {
178183
contents: result.contents,
179184
syntax: utils.protofySyntax(result.syntax),
180185
sourceMapUrl: result.sourceMapUrl?.toString() ?? '',
181-
}),
186+
},
182187
},
183188
});
184189
});
185190
},
186191
error =>
187-
new proto.InboundMessage_ImportResponse({
192+
create(proto.InboundMessage_ImportResponseSchema, {
188193
result: {case: 'error', value: `${error}`},
189194
})
190195
);
@@ -210,7 +215,7 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
210215
importer.findFileUrl(request.url, canonicalizeContext),
211216
url => {
212217
if (!url) {
213-
return new proto.InboundMessage_FileImportResponse({
218+
return create(proto.InboundMessage_FileImportResponseSchema, {
214219
containingUrlUnused: !canonicalizeContext.containingUrlAccessed,
215220
});
216221
}
@@ -220,15 +225,15 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
220225
+`"${url}" for URL "${request.url}".`
221226
);
222227
}
223-
return new proto.InboundMessage_FileImportResponse({
228+
return create(proto.InboundMessage_FileImportResponseSchema, {
224229
result: {case: 'fileUrl', value: url.toString()},
225230
containingUrlUnused: !canonicalizeContext.containingUrlAccessed,
226231
});
227232
}
228233
);
229234
},
230235
error =>
231-
new proto.InboundMessage_FileImportResponse({
236+
create(proto.InboundMessage_FileImportResponseSchema, {
232237
result: {case: 'error', value: `${error}`},
233238
})
234239
);

lib/src/legacy/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ function convertOptions<sync extends 'sync' | 'async'>(
171171
verbose: options.verbose,
172172
charset: options.charset,
173173
logger: options.logger,
174+
fatalDeprecations: options.fatalDeprecations,
175+
futureDeprecations: options.futureDeprecations,
176+
silenceDeprecations: options.silenceDeprecations,
174177
legacy: true,
175178
};
176179
}

lib/src/message-transformer.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import {Observable, Subject} from 'rxjs';
66
import * as varint from 'varint';
7+
import {create, toBinary} from '@bufbuild/protobuf';
78

89
import {expectObservableToError} from '../../test/utils';
910
import {MessageTransformer} from './message-transformer';
@@ -13,17 +14,17 @@ describe('message transformer', () => {
1314
let messages: MessageTransformer;
1415

1516
function validInboundMessage(source: string): proto.InboundMessage {
16-
return new proto.InboundMessage({
17+
return create(proto.InboundMessageSchema, {
1718
message: {
1819
case: 'compileRequest',
19-
value: new proto.InboundMessage_CompileRequest({
20+
value: {
2021
input: {
2122
case: 'string',
22-
value: new proto.InboundMessage_CompileRequest_StringInput({
23+
value: {
2324
source,
24-
}),
25+
},
2526
},
26-
}),
27+
},
2728
},
2829
});
2930
}
@@ -42,7 +43,10 @@ describe('message transformer', () => {
4243
const message = validInboundMessage('a {b: c}');
4344
messages.writeInboundMessage([1234, message]);
4445
expect(encodedProtobufs).toEqual([
45-
Uint8Array.from([...varint.encode(1234), ...message.toBinary()]),
46+
Uint8Array.from([
47+
...varint.encode(1234),
48+
...toBinary(proto.InboundMessageSchema, message),
49+
]),
4650
]);
4751
});
4852
});
@@ -81,7 +85,10 @@ describe('message transformer', () => {
8185
protobufs$.next(
8286
Uint8Array.from([
8387
...varint.encode(1234),
84-
...validInboundMessage('a {b: c}').toBinary(),
88+
...toBinary(
89+
proto.InboundMessageSchema,
90+
validInboundMessage('a {b: c}')
91+
),
8592
])
8693
);
8794
protobufs$.complete();

lib/src/message-transformer.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
import {Observable, Subject} from 'rxjs';
66
import {map} from 'rxjs/operators';
7+
import {fromBinary, toBinary} from '@bufbuild/protobuf';
78
import * as varint from 'varint';
89

910
import {compilerError} from './utils';
10-
import {InboundMessage, OutboundMessage} from './vendor/embedded_sass_pb';
11+
import {
12+
InboundMessage,
13+
InboundMessageSchema,
14+
OutboundMessage,
15+
OutboundMessageSchema,
16+
} from './vendor/embedded_sass_pb';
1117

1218
/**
1319
* Encodes InboundMessages into protocol buffers and decodes protocol buffers
@@ -43,7 +49,7 @@ export class MessageTransformer {
4349
InboundMessage,
4450
]): void {
4551
const compilationIdLength = varint.encodingLength(compilationId);
46-
const encodedMessage = message.toBinary();
52+
const encodedMessage = toBinary(InboundMessageSchema, message);
4753
const buffer = new Uint8Array(compilationIdLength + encodedMessage.length);
4854
varint.encode(compilationId, buffer);
4955
buffer.set(encodedMessage, compilationIdLength);
@@ -71,7 +77,8 @@ function decode(buffer: Uint8Array): [number, OutboundMessage] {
7177
try {
7278
return [
7379
compilationId,
74-
OutboundMessage.fromBinary(
80+
fromBinary(
81+
OutboundMessageSchema,
7582
new Uint8Array(buffer.buffer, varint.decode.bytes)
7683
),
7784
];

0 commit comments

Comments
 (0)