diff --git a/types/gulp-sass/gulp-sass-tests.ts b/types/gulp-sass/gulp-sass-tests.ts index c7013378755363..bb7b25753fb2b0 100644 --- a/types/gulp-sass/gulp-sass-tests.ts +++ b/types/gulp-sass/gulp-sass-tests.ts @@ -1,17 +1,46 @@ import gulp = require("gulp"); import gulpSass = require("gulp-sass"); +import gulpSassLegacy = require("gulp-sass/legacy"); +import * as sass from "sass"; +import * as sassEmbedded from "sass-embedded"; -const sass = gulpSass({}); // compiler +const gulpSassWithSass = gulpSass(sass); +const gulpSassWithSassEmbedded = gulpSass(sassEmbedded); +const gulpSassLegacyWithSass = gulpSassLegacy(sass); gulp.task("sass", function() { gulp.src("./scss/*.scss") - .pipe(sass()) + .pipe(gulpSassWithSass({ style: "compressed" })) .pipe(gulp.dest("./css")); }); gulp.task("sass", function() { gulp.src("./scss/*.scss") - .pipe(sass({ errLogToConsole: true })) - .pipe(sass.sync()) + .pipe(gulpSassWithSass({ style: "compressed", importers: [new sass.NodePackageImporter(".")] })) + .pipe(gulp.dest("./css")); +}); + +gulp.task("sass", function() { + gulp.src("./scss/*.scss") + .pipe(gulpSassWithSassEmbedded({ style: "compressed", importers: [new sassEmbedded.NodePackageImporter(".")] })) + .pipe(gulp.dest("./css")); +}); + +gulp.task("sass", function() { + gulp.src("./scss/*.scss") + // @ts-expect-error -- The NodePackageImporter must come from the same implementation of Sass + .pipe(gulpSassWithSassEmbedded({ style: "compressed", importers: [new sass.NodePackageImporter(".")] })) + .pipe(gulp.dest("./css")); +}); + +gulp.task("sass", function() { + gulp.src("./scss/*.scss") + .pipe(gulpSassWithSass.sync()) + .pipe(gulp.dest("./css")); +}); + +gulp.task("sass-legacy", function() { + gulp.src("./scss/*.scss") + .pipe(gulpSassLegacyWithSass({ outputStyle: "compressed" })) .pipe(gulp.dest("./css")); }); diff --git a/types/gulp-sass/index.d.ts b/types/gulp-sass/index.d.ts index beb32fb0dcd0c0..c1d682eabd8038 100644 --- a/types/gulp-sass/index.d.ts +++ b/types/gulp-sass/index.d.ts @@ -1,42 +1,34 @@ /// -import { Options } from "node-sass"; +import { CompileResult, FileImporter, Importer, Options } from "@sass/types"; -interface SassResults { - css: string; - map: string; - stats: { - entry: string; - start: Date; - end: Date; - duration: number; - includedFiles: string[]; - }; +interface GulpSassError extends Error { + messageFormatted: string; + messageOriginal: string; + relativePath: string; } -interface SassOptions extends Options { - success?: ((results: SassResults) => any) | undefined; - error?: ((err: Error) => any) | undefined; - imagePaths?: string[] | undefined; -} +type GulpSassOptions = + & Omit, "importers"> + & { + importers?: (Importer | FileImporter | TNodePackageImporter)[]; + }; -interface GulpSassOptions extends SassOptions { - errLogToConsole?: boolean | undefined; - onSuccess?: ((css: string) => any) | undefined; - onError?: ((err: Error) => any) | undefined; - sync?: boolean | undefined; +interface GulpSass { + (opts?: GulpSassOptions<"async", TNodePackageImporter>): NodeJS.ReadWriteStream; + logError(error?: GulpSassError): void; + sync(options?: GulpSassOptions<"sync", TNodePackageImporter>): NodeJS.ReadWriteStream; } -interface GulpSass { - (opts?: GulpSassOptions): NodeJS.ReadWriteStream; - logError(error?: string): void; - sync(options?: GulpSassOptions): NodeJS.ReadWriteStream; +interface Compiler { + compile(path: string, options: GulpSassOptions<"sync", TNodePackageImporter>): CompileResult; + compileAsync(path: string, options: GulpSassOptions<"async", TNodePackageImporter>): Promise; + compileString(source: string, options: GulpSassOptions<"sync", TNodePackageImporter>): CompileResult; + compileStringAsync(source: string, options: GulpSassOptions<"async", TNodePackageImporter>): Promise; } -type Compiler = any; - interface GulpSassFactory { - (compiler: Compiler): GulpSass; + (compiler: Compiler): GulpSass; } declare var _tmp: GulpSassFactory; diff --git a/types/gulp-sass/legacy.d.ts b/types/gulp-sass/legacy.d.ts new file mode 100644 index 00000000000000..a65b2171afa540 --- /dev/null +++ b/types/gulp-sass/legacy.d.ts @@ -0,0 +1,44 @@ +/// + +import { LegacyException, LegacyResult, LegacySharedOptions } from "@sass/types"; + +interface GulpSassError extends Error { + messageFormatted: string; + messageOriginal: string; + relativePath: string; +} + +type LegacyGulpSassOptions = + & Omit, "pkgImporter"> + & { + pkgImporter?: TNodePackageImporter; + }; + +interface LegacyGulpSass { + (opts?: LegacyGulpSassOptions<"async", TNodePackageImporter>): NodeJS.ReadWriteStream; + logError(error?: GulpSassError): void; + sync(options?: LegacyGulpSassOptions<"sync", TNodePackageImporter>): NodeJS.ReadWriteStream; +} + +interface GulpSassInjectedOptions { + data: string; + file?: string; + indentedSyntax?: boolean; +} + +interface LegacyCompiler { + render( + options: LegacyGulpSassOptions<"async", TNodePackageImporter> & GulpSassInjectedOptions, + callback: (exception?: LegacyException, result?: LegacyResult) => void, + ): void; + renderSync(options: LegacyGulpSassOptions<"sync", TNodePackageImporter> & GulpSassInjectedOptions): LegacyResult; +} + +interface LegacyGulpSassFactory { + ( + compiler: LegacyCompiler, + ): LegacyGulpSass; +} + +declare var _tmp: LegacyGulpSassFactory; +export = _tmp; diff --git a/types/gulp-sass/package.json b/types/gulp-sass/package.json index 1b20f386cd8a68..ee50ab9ccf903a 100644 --- a/types/gulp-sass/package.json +++ b/types/gulp-sass/package.json @@ -1,15 +1,17 @@ { "private": true, "name": "@types/gulp-sass", - "version": "5.0.9999", + "version": "6.0.9999", "projects": [ "https://github.com/dlmanning/gulp-sass" ], "dependencies": { - "@types/node": "*", - "@types/node-sass": "*" + "@sass/types": "^1.93", + "@types/node": "*" }, "devDependencies": { + "sass": "^1.93", + "sass-embedded": "^1.93", "@types/gulp": "*", "@types/gulp-sass": "workspace:." }, diff --git a/types/gulp-sass/tsconfig.json b/types/gulp-sass/tsconfig.json index f5705d24aef265..4c9c9d88be2045 100644 --- a/types/gulp-sass/tsconfig.json +++ b/types/gulp-sass/tsconfig.json @@ -14,6 +14,7 @@ }, "files": [ "index.d.ts", + "legacy.d.ts", "gulp-sass-tests.ts" ] }