Skip to content

Commit 625e11d

Browse files
authored
Merge pull request #284 from sass/merge-main
Merge main into feature.color-4
2 parents fef63f3 + a843bd5 commit 625e11d

File tree

23 files changed

+345
-40
lines changed

23 files changed

+345
-40
lines changed

CHANGELOG.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,82 @@
1+
## 1.74.1
2+
3+
* No user-visible changes.
4+
5+
## 1.74.0
6+
7+
### JS API
8+
9+
* Add a new top-level `deprecations` object, which contains various
10+
`Deprecation` objects that define the different types of deprecation used by
11+
the Sass compiler and can be passed to the options below.
12+
13+
* Add a new `fatalDeprecations` compiler option that causes the compiler to
14+
error if any deprecation warnings of the provided types are encountered. You
15+
can also pass in a `Version` object to treat all deprecations that were active
16+
in that Dart Sass version as fatal.
17+
18+
* Add a new `futureDeprecations` compiler option that allows you to opt-in to
19+
certain deprecations early (currently just `import`).
20+
21+
* Add a new `silenceDeprecations` compiler option to ignore any deprecation
22+
warnings of the provided types.
23+
24+
### Command-Line Interface
25+
26+
* Add a new `--silence-deprecation` flag, which causes the compiler to ignore
27+
any deprecation warnings of the provided types.
28+
29+
* Previously, if a future deprecation was passed to `--fatal-deprecation` but
30+
not `--future-deprecation`, it would be treated as fatal despite not being
31+
enabled. Both flags are now required to treat a future deprecation as fatal
32+
with a warning emitted if `--fatal-deprecation` is passed without
33+
`--future-deprecation`, matching the JS API's behavior.
34+
35+
### Dart API
36+
37+
* The `compile` methods now take in a `silenceDeprecations` parameter, which
38+
causes the compiler to ignore any deprecation warnings of the provided types.
39+
40+
* Add `Deprecation.obsoleteIn` to match the JS API. This is currently null for
41+
all deprecations, but will be used once some deprecations become obsolete in
42+
Dart Sass 2.0.0.
43+
44+
* **Potentially breaking bug fix:** Fix a bug where `compileStringToResultAsync`
45+
ignored `fatalDeprecations` and `futureDeprecations`.
46+
47+
* The behavior around making future deprecations fatal mentioned in the CLI
48+
section above has also been changed in the Dart API.
49+
50+
## 1.73.0
51+
52+
* Add support for nesting in plain CSS files. This is not processed by Sass at
53+
all; it's emitted exactly as-is in the CSS.
54+
55+
* In certain circumstances, the current working directory was unintentionally
56+
being made available as a load path. This is now deprecated. Anyone relying on
57+
this should explicitly pass in `.` as a load path or `FilesystemImporter('.')`
58+
as the current importer.
59+
60+
* Add linux-riscv64 and windows-arm64 releases.
61+
62+
### Command-Line Interface
63+
64+
* Fix a bug where absolute `file:` URLs weren't loaded for files compiled via
65+
the command line unless an unrelated load path was also passed.
66+
67+
* Fix a bug where `--update` would always update files that were specified via
68+
absolute path unless an unrelated load path was also passed.
69+
70+
### Dart API
71+
72+
* Add `FilesystemImporter.noLoadPath`, which is a `FilesystemImporter` that can
73+
load absolute `file:` URLs and resolve URLs relative to the base file but
74+
doesn't load relative URLs from a load path.
75+
76+
* `FilesystemImporter.cwd` is now deprecated. Either use
77+
`FilesystemImporter.noLoadPath` if you weren't intending to rely on the load
78+
path, or `FilesystemImporter('.')` if you were.
79+
180
## 1.72.0
281

382
* Support adjacent `/`s without whitespace in between when parsing plain CSS

lib/index.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export const AsyncCompiler = sass.AsyncCompiler;
99
export const Compiler = sass.Compiler;
1010
export const initAsyncCompiler = sass.initAsyncCompiler;
1111
export const initCompiler = sass.initCompiler;
12+
export const deprecations = sass.deprecations;
13+
export const Version = sass.Version;
1214
export const Logger = sass.Logger;
1315
export const CalculationInterpolation = sass.CalculationInterpolation;
1416
export const CalculationOperation = sass.CalculationOperation;
@@ -86,6 +88,14 @@ export default {
8688
defaultExportDeprecation();
8789
return sass.Compiler;
8890
},
91+
get deprecations() {
92+
defaultExportDeprecation();
93+
return sass.deprecations;
94+
},
95+
get Version() {
96+
defaultExportDeprecation();
97+
return sass.Version;
98+
},
8999
get Logger() {
90100
defaultExportDeprecation();
91101
return sass.Logger;

lib/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ export {
3535
} from './src/compile';
3636
export {initAsyncCompiler, AsyncCompiler} from './src/compiler/async';
3737
export {initCompiler, Compiler} from './src/compiler/sync';
38+
export {
39+
deprecations,
40+
Deprecation,
41+
DeprecationOrId,
42+
DeprecationStatus,
43+
Version,
44+
} from './src/deprecations';
3845
export {render, renderSync} from './src/legacy';
3946

4047
export const info = `sass-embedded\t${pkg.version}`;

lib/src/compiler/utils.ts

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

55
import * as p from 'path';
66
import * as supportsColor from 'supports-color';
7+
import {deprecations, getDeprecationIds, Deprecation} from '../deprecations';
78
import {deprotofySourceSpan} from '../deprotofy-span';
89
import {Dispatcher, DispatcherHandlers} from '../dispatcher';
910
import {Exception} from '../exception';
@@ -75,6 +76,9 @@ function newCompileRequest(
7576
verbose: !!options?.verbose,
7677
charset: !!(options?.charset ?? true),
7778
silent: options?.logger === Logger.silent,
79+
fatalDeprecation: getDeprecationIds(options?.fatalDeprecations ?? []),
80+
silenceDeprecation: getDeprecationIds(options?.silenceDeprecations ?? []),
81+
futureDeprecation: getDeprecationIds(options?.futureDeprecations ?? []),
7882
});
7983

8084
switch (options?.style ?? 'expanded') {
@@ -137,6 +141,13 @@ export function newCompileStringRequest(
137141
return request;
138142
}
139143

144+
/** Type guard to check that `id` is a valid deprecation ID. */
145+
function validDeprecationId(
146+
id: string | number | symbol | undefined
147+
): id is keyof typeof deprecations {
148+
return !!id && id in deprecations;
149+
}
150+
140151
/** Handles a log event according to `options`. */
141152
export function handleLogEvent(
142153
options: OptionsWithLegacy<'sync' | 'async'> | undefined,
@@ -148,6 +159,9 @@ export function handleLogEvent(
148159
if (options?.legacy) message = removeLegacyImporter(message);
149160
let formatted = event.formatted;
150161
if (options?.legacy) formatted = removeLegacyImporter(formatted);
162+
const deprecationType = validDeprecationId(event.deprecationType)
163+
? deprecations[event.deprecationType]
164+
: null;
151165

152166
if (event.type === proto.LogEventType.DEBUG) {
153167
if (options?.logger?.debug) {
@@ -159,10 +173,18 @@ export function handleLogEvent(
159173
}
160174
} else {
161175
if (options?.logger?.warn) {
162-
const params: {deprecation: boolean; span?: SourceSpan; stack?: string} =
163-
{
164-
deprecation: event.type === proto.LogEventType.DEPRECATION_WARNING,
165-
};
176+
const params: (
177+
| {
178+
deprecation: true;
179+
deprecationType: Deprecation;
180+
}
181+
| {deprecation: false}
182+
) & {
183+
span?: SourceSpan;
184+
stack?: string;
185+
} = deprecationType
186+
? {deprecation: true, deprecationType: deprecationType}
187+
: {deprecation: false};
166188
if (span) params.span = span;
167189

168190
const stack = event.stackTrace;

lib/src/deprecations.ts

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
// Copyright 2024 Google LLC. Use of this source code is governed by an
2+
// MIT-style license that can be found in the LICENSE file or at
3+
// https://opensource.org/licenses/MIT.
4+
5+
import * as api from './vendor/sass';
6+
7+
export {Deprecation, DeprecationOrId, DeprecationStatus} from './vendor/sass';
8+
9+
export class Version implements api.Version {
10+
constructor(
11+
readonly major: number,
12+
readonly minor: number,
13+
readonly patch: number
14+
) {}
15+
static parse(version: string): Version {
16+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)$/);
17+
if (match === null) {
18+
throw new Error(`Invalid version ${version}`);
19+
}
20+
return new Version(
21+
parseInt(match[1]),
22+
parseInt(match[2]),
23+
parseInt(match[3])
24+
);
25+
}
26+
}
27+
28+
/**
29+
* Returns whether the given deprecation was active in the given version.
30+
*/
31+
function isActiveIn(deprecation: api.Deprecation, version: Version) {
32+
const deprecatedIn = deprecation.deprecatedIn;
33+
if (deprecation.status !== 'active' || !deprecatedIn) return false;
34+
if (version.major > deprecatedIn.major) return true;
35+
if (version.major < deprecatedIn.major) return false;
36+
if (version.minor > deprecatedIn.minor) return true;
37+
if (version.minor < deprecatedIn.minor) return false;
38+
return version.patch >= deprecatedIn.patch;
39+
}
40+
41+
/**
42+
* Converts a mixed array of deprecations, IDs, and versions to an array of IDs
43+
* that's ready to include in a CompileRequest.
44+
*/
45+
export function getDeprecationIds(
46+
arr: (api.DeprecationOrId | Version)[]
47+
): string[] {
48+
return arr.flatMap(item => {
49+
if (item instanceof Version) {
50+
return Object.values(deprecations)
51+
.filter(deprecation => isActiveIn(deprecation, item))
52+
.map(deprecation => deprecation.id);
53+
} else if (typeof item === 'string') {
54+
return item;
55+
}
56+
return item.id;
57+
});
58+
}
59+
60+
export const deprecations: typeof api.deprecations = {
61+
'call-string': {
62+
id: 'call-string',
63+
status: 'active',
64+
deprecatedIn: new Version(0, 0, 0),
65+
obsoleteIn: null,
66+
description: 'Passing a string directly to meta.call().',
67+
},
68+
elseif: {
69+
id: 'elseif',
70+
status: 'active',
71+
deprecatedIn: new Version(1, 3, 2),
72+
obsoleteIn: null,
73+
description: '@elseif.',
74+
},
75+
'moz-document': {
76+
id: 'moz-document',
77+
status: 'active',
78+
deprecatedIn: new Version(1, 7, 2),
79+
obsoleteIn: null,
80+
description: '@-moz-document.',
81+
},
82+
'relative-canonical': {
83+
id: 'relative-canonical',
84+
status: 'active',
85+
deprecatedIn: new Version(1, 14, 2),
86+
obsoleteIn: null,
87+
},
88+
'new-global': {
89+
id: 'new-global',
90+
status: 'active',
91+
deprecatedIn: new Version(1, 17, 2),
92+
obsoleteIn: null,
93+
description: 'Declaring new variables with !global.',
94+
},
95+
'color-module-compat': {
96+
id: 'color-module-compat',
97+
status: 'active',
98+
deprecatedIn: new Version(1, 23, 0),
99+
obsoleteIn: null,
100+
description:
101+
'Using color module functions in place of plain CSS functions.',
102+
},
103+
'slash-div': {
104+
id: 'slash-div',
105+
status: 'active',
106+
deprecatedIn: new Version(1, 33, 0),
107+
obsoleteIn: null,
108+
description: '/ operator for division.',
109+
},
110+
'bogus-combinators': {
111+
id: 'bogus-combinators',
112+
status: 'active',
113+
deprecatedIn: new Version(1, 54, 0),
114+
obsoleteIn: null,
115+
description: 'Leading, trailing, and repeated combinators.',
116+
},
117+
'strict-unary': {
118+
id: 'strict-unary',
119+
status: 'active',
120+
deprecatedIn: new Version(1, 55, 0),
121+
obsoleteIn: null,
122+
description: 'Ambiguous + and - operators.',
123+
},
124+
'function-units': {
125+
id: 'function-units',
126+
status: 'active',
127+
deprecatedIn: new Version(1, 56, 0),
128+
obsoleteIn: null,
129+
description: 'Passing invalid units to built-in functions.',
130+
},
131+
'duplicate-var-flags': {
132+
id: 'duplicate-var-flags',
133+
status: 'active',
134+
deprecatedIn: new Version(1, 62, 0),
135+
obsoleteIn: null,
136+
description: 'Using !default or !global multiple times for one variable.',
137+
},
138+
'null-alpha': {
139+
id: 'null-alpha',
140+
status: 'active',
141+
deprecatedIn: new Version(1, 62, 3),
142+
obsoleteIn: null,
143+
description: 'Passing null as alpha in the JS API.',
144+
},
145+
'abs-percent': {
146+
id: 'abs-percent',
147+
status: 'active',
148+
deprecatedIn: new Version(1, 65, 0),
149+
obsoleteIn: null,
150+
description: 'Passing percentages to the Sass abs() function.',
151+
},
152+
'fs-importer-cwd': {
153+
id: 'fs-importer-cwd',
154+
status: 'active',
155+
deprecatedIn: new Version(1, 73, 0),
156+
obsoleteIn: null,
157+
description:
158+
'Using the current working directory as an implicit load path.',
159+
},
160+
'color-4-api': {
161+
id: 'color-4-api',
162+
status: 'active',
163+
deprecatedIn: new Version(1, 76, 0),
164+
obsoleteIn: null,
165+
description: 'Methods of interacting with legacy SassColors.',
166+
},
167+
'color-functions': {
168+
id: 'color-functions',
169+
status: 'active',
170+
deprecatedIn: new Version(1, 76, 0),
171+
obsoleteIn: null,
172+
description: 'Using global Sass color functions.',
173+
},
174+
import: {
175+
id: 'import',
176+
status: 'future',
177+
deprecatedIn: null,
178+
obsoleteIn: null,
179+
description: '@import rules.',
180+
},
181+
'user-authored': {
182+
id: 'user-authored',
183+
status: 'user',
184+
deprecatedIn: null,
185+
obsoleteIn: null,
186+
},
187+
};

npm/android-arm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-embedded-android-arm",
3-
"version": "1.72.0",
3+
"version": "1.74.1",
44
"description": "The android-arm binary for sass-embedded",
55
"repository": "sass/embedded-host-node",
66
"author": "Google Inc.",

npm/android-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-embedded-android-arm64",
3-
"version": "1.72.0",
3+
"version": "1.74.1",
44
"description": "The android-arm64 binary for sass-embedded",
55
"repository": "sass/embedded-host-node",
66
"author": "Google Inc.",

npm/android-ia32/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-embedded-android-ia32",
3-
"version": "1.72.0",
3+
"version": "1.74.1",
44
"description": "The android-ia32 binary for sass-embedded",
55
"repository": "sass/embedded-host-node",
66
"author": "Google Inc.",

0 commit comments

Comments
 (0)