Skip to content

Commit 2e115a0

Browse files
authored
🤖 Merge PR DefinitelyTyped#73736 [gulp-sass] Update type declarations for gulp-sass v6 by @stof
1 parent f97479e commit 2e115a0

File tree

5 files changed

+103
-35
lines changed

5 files changed

+103
-35
lines changed
Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
11
import gulp = require("gulp");
22
import gulpSass = require("gulp-sass");
3+
import gulpSassLegacy = require("gulp-sass/legacy");
4+
import * as sass from "sass";
5+
import * as sassEmbedded from "sass-embedded";
36

4-
const sass = gulpSass({}); // compiler
7+
const gulpSassWithSass = gulpSass(sass);
8+
const gulpSassWithSassEmbedded = gulpSass(sassEmbedded);
9+
const gulpSassLegacyWithSass = gulpSassLegacy(sass);
510

611
gulp.task("sass", function() {
712
gulp.src("./scss/*.scss")
8-
.pipe(sass())
13+
.pipe(gulpSassWithSass({ style: "compressed" }))
914
.pipe(gulp.dest("./css"));
1015
});
1116

1217
gulp.task("sass", function() {
1318
gulp.src("./scss/*.scss")
14-
.pipe(sass({ errLogToConsole: true }))
15-
.pipe(sass.sync())
19+
.pipe(gulpSassWithSass({ style: "compressed", importers: [new sass.NodePackageImporter(".")] }))
20+
.pipe(gulp.dest("./css"));
21+
});
22+
23+
gulp.task("sass", function() {
24+
gulp.src("./scss/*.scss")
25+
.pipe(gulpSassWithSassEmbedded({ style: "compressed", importers: [new sassEmbedded.NodePackageImporter(".")] }))
26+
.pipe(gulp.dest("./css"));
27+
});
28+
29+
gulp.task("sass", function() {
30+
gulp.src("./scss/*.scss")
31+
// @ts-expect-error -- The NodePackageImporter must come from the same implementation of Sass
32+
.pipe(gulpSassWithSassEmbedded({ style: "compressed", importers: [new sass.NodePackageImporter(".")] }))
33+
.pipe(gulp.dest("./css"));
34+
});
35+
36+
gulp.task("sass", function() {
37+
gulp.src("./scss/*.scss")
38+
.pipe(gulpSassWithSass.sync())
39+
.pipe(gulp.dest("./css"));
40+
});
41+
42+
gulp.task("sass-legacy", function() {
43+
gulp.src("./scss/*.scss")
44+
.pipe(gulpSassLegacyWithSass({ outputStyle: "compressed" }))
1645
.pipe(gulp.dest("./css"));
1746
});

‎types/gulp-sass/index.d.ts‎

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,34 @@
11
/// <reference types="node"/>
22

3-
import { Options } from "node-sass";
3+
import { CompileResult, FileImporter, Importer, Options } from "@sass/types";
44

5-
interface SassResults {
6-
css: string;
7-
map: string;
8-
stats: {
9-
entry: string;
10-
start: Date;
11-
end: Date;
12-
duration: number;
13-
includedFiles: string[];
14-
};
5+
interface GulpSassError extends Error {
6+
messageFormatted: string;
7+
messageOriginal: string;
8+
relativePath: string;
159
}
1610

17-
interface SassOptions extends Options {
18-
success?: ((results: SassResults) => any) | undefined;
19-
error?: ((err: Error) => any) | undefined;
20-
imagePaths?: string[] | undefined;
21-
}
11+
type GulpSassOptions<sync extends "sync" | "async", TNodePackageImporter extends {}> =
12+
& Omit<Options<sync>, "importers">
13+
& {
14+
importers?: (Importer<sync> | FileImporter<sync> | TNodePackageImporter)[];
15+
};
2216

23-
interface GulpSassOptions extends SassOptions {
24-
errLogToConsole?: boolean | undefined;
25-
onSuccess?: ((css: string) => any) | undefined;
26-
onError?: ((err: Error) => any) | undefined;
27-
sync?: boolean | undefined;
17+
interface GulpSass<TNodePackageImporter extends {}> {
18+
(opts?: GulpSassOptions<"async", TNodePackageImporter>): NodeJS.ReadWriteStream;
19+
logError(error?: GulpSassError): void;
20+
sync(options?: GulpSassOptions<"sync", TNodePackageImporter>): NodeJS.ReadWriteStream;
2821
}
2922

30-
interface GulpSass {
31-
(opts?: GulpSassOptions): NodeJS.ReadWriteStream;
32-
logError(error?: string): void;
33-
sync(options?: GulpSassOptions): NodeJS.ReadWriteStream;
23+
interface Compiler<TNodePackageImporter extends {}> {
24+
compile(path: string, options: GulpSassOptions<"sync", TNodePackageImporter>): CompileResult;
25+
compileAsync(path: string, options: GulpSassOptions<"async", TNodePackageImporter>): Promise<CompileResult>;
26+
compileString(source: string, options: GulpSassOptions<"sync", TNodePackageImporter>): CompileResult;
27+
compileStringAsync(source: string, options: GulpSassOptions<"async", TNodePackageImporter>): Promise<CompileResult>;
3428
}
3529

36-
type Compiler = any;
37-
3830
interface GulpSassFactory {
39-
(compiler: Compiler): GulpSass;
31+
<TNodePackageImporter extends {}>(compiler: Compiler<TNodePackageImporter>): GulpSass<TNodePackageImporter>;
4032
}
4133

4234
declare var _tmp: GulpSassFactory;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// <reference types="node"/>
2+
3+
import { LegacyException, LegacyResult, LegacySharedOptions } from "@sass/types";
4+
5+
interface GulpSassError extends Error {
6+
messageFormatted: string;
7+
messageOriginal: string;
8+
relativePath: string;
9+
}
10+
11+
type LegacyGulpSassOptions<sync extends "sync" | "async", TNodePackageImporter extends {}> =
12+
& Omit<LegacySharedOptions<sync>, "pkgImporter">
13+
& {
14+
pkgImporter?: TNodePackageImporter;
15+
};
16+
17+
interface LegacyGulpSass<TNodePackageImporter extends {}> {
18+
(opts?: LegacyGulpSassOptions<"async", TNodePackageImporter>): NodeJS.ReadWriteStream;
19+
logError(error?: GulpSassError): void;
20+
sync(options?: LegacyGulpSassOptions<"sync", TNodePackageImporter>): NodeJS.ReadWriteStream;
21+
}
22+
23+
interface GulpSassInjectedOptions {
24+
data: string;
25+
file?: string;
26+
indentedSyntax?: boolean;
27+
}
28+
29+
interface LegacyCompiler<TNodePackageImporter extends {}> {
30+
render(
31+
options: LegacyGulpSassOptions<"async", TNodePackageImporter> & GulpSassInjectedOptions,
32+
callback: (exception?: LegacyException, result?: LegacyResult) => void,
33+
): void;
34+
renderSync(options: LegacyGulpSassOptions<"sync", TNodePackageImporter> & GulpSassInjectedOptions): LegacyResult;
35+
}
36+
37+
interface LegacyGulpSassFactory {
38+
<TNodePackageImporter extends {}>(
39+
compiler: LegacyCompiler<TNodePackageImporter>,
40+
): LegacyGulpSass<TNodePackageImporter>;
41+
}
42+
43+
declare var _tmp: LegacyGulpSassFactory;
44+
export = _tmp;

‎types/gulp-sass/package.json‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
22
"private": true,
33
"name": "@types/gulp-sass",
4-
"version": "5.0.9999",
4+
"version": "6.0.9999",
55
"projects": [
66
"https://github.com/dlmanning/gulp-sass"
77
],
88
"dependencies": {
9-
"@types/node": "*",
10-
"@types/node-sass": "*"
9+
"@sass/types": "^1.93",
10+
"@types/node": "*"
1111
},
1212
"devDependencies": {
13+
"sass": "^1.93",
14+
"sass-embedded": "^1.93",
1315
"@types/gulp": "*",
1416
"@types/gulp-sass": "workspace:."
1517
},

‎types/gulp-sass/tsconfig.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"files": [
1616
"index.d.ts",
17+
"legacy.d.ts",
1718
"gulp-sass-tests.ts"
1819
]
1920
}

0 commit comments

Comments
 (0)