broccoli-eyeglass
Version:
Sass compiler for Broccoli with Eyeglass Integration
254 lines • 10.7 kB
TypeScript
import debugGenerator = require("debug");
import BroccoliPlugin = require("broccoli-plugin");
import FSTree = require("fs-tree-diff");
import type * as nodeSass from "node-sass";
import { EventEmitter } from "chained-emitter";
import DiskCache = require("sync-disk-cache");
import heimdall = require("heimdalljs");
export declare type SassImplementation = typeof nodeSass;
interface CachedContents {
contents: Record<string, string>;
urls: Record<string, string>;
}
declare type CachedDependencies = Array<[string, string]>;
declare class Entry {
relativePath: string;
basePath: string;
mode: number;
size: number;
mtime: Date;
constructor(path: string);
isDirectory(): boolean;
}
export interface CompilationDetails {
/**
* The directory to which the sassFilename is relative.
*/
srcPath: string;
/**
* The path of the sass file being compiled (relative to srcPath).
*/
sassFilename: string;
/**
* The absolute path of the Sass file.
*/
fullSassFilename: string;
/**
* The directory where compiled css files are being written.
*/
destDir: string;
/**
* The CSS filename relative to the destDir.
*/
cssFilename: string;
/**
* The absolute path of the CSS file.
* (note: the file is not there yet, obviously)
*/
fullCssFilename: string;
/**
* The options that will be used to compile the file.
*/
options: nodeSass.Options;
}
interface GenericCache {
get(key: string): string | number | undefined;
set(key: string, value: string | number): void;
}
export interface BroccoliSassOptions extends BroccoliPlugin.BroccoliPluginOptions {
/**
* Provide engines to this plugin and descendants of this plugin.
*/
engines?: {
/**
* The sass compiler to be used by this plugin.
* If not provided, this plugin will attempt to require 'node-sass' and
* then 'sass' (in that order, using the first one that it finds).
*/
sass?: typeof nodeSass;
[engine: string]: unknown;
};
/**
* The directory to write css files to. Relative to the build output directory.
*/
cssDir: string;
/**
* When `true`, will discover sass files to compile that are found in the sass
* directory. Defaults to true unless sourceFiles are specified.
* Files beginning with an underscore are called "partials" and are not
* discovered.
*/
discover?: boolean;
/**
* The directory to look for scss files to compile. Defaults to tree root.
*
*/
sassDir?: string;
/**
* Force sass rendering to use node-sass's synchronous rendering.
* Defaults to * `false`.
*
*/
renderSync?: boolean;
/**
* Array of file names or glob patterns (relative to the sass directory) that
* should be compiled. Note that file names must include the file extension
* (unlike @import in Sass). E.g.: ['application.scss']
*
*/
sourceFiles?: Array<string>;
/**
* Set to the name of your application so that your cache is isolated from
* other broccoli-eyeglass based builds. When falsy, persistent caching is
* disabled.
*/
persistentCache?: string;
/**
* Integer. Set to the maximum number of listeners your use of eyeglass
* compiler needs. Defaults to 10. Note: do not set
* eyeglassCompiler.events.setMaxListeners() yourself as eyeglass has its own
* listeners it uses internally.
*
*/
maxListeners?: number;
/**
* @see OptionsGenerator
*/
optionsGenerator?: OptionsGenerator;
/**
* NOT YET IMPLEMENTED
*/
fullException?: boolean;
/**
* When true, console logging will occur for each css file that is built
* along with timing information.
*/
verbose?: boolean;
/**
* This is a cache that can be provided to cache across multiple instances of
* BroccoliSassCompiler. It can be a map, or some other cache store like
* like the memory capped lru-cache. Only strings and numbers will be placed
* as values in the cache.
*
* It is the responsibility of the caller to clear the session cache between
* calls to build(). Failure to do so will cause inconsistent build output.
*
* If a session cache is not provided, a short lived cache will be used locally
* for a single build's duration of one tree.
*/
sessionCache?: GenericCache;
}
declare type OptionsGeneratorCallback = (cssFile: string, options: nodeSass.Options) => void;
/**
* @param sassFile the sass file that will be compiled.
* @param cssFile the default location where the css output will be written.
* This can be overridden by passing a different path to the callback.
* @param options The options that eyeglass will be given. These can be mutated.
* Note: the options `file`, `data`, and `outFile` are not set and cannot be
* set in the options generator.
* @param cb This callback accepts a css filename and options to use for
* compilation. This callback can be invoked 0 or more times. Each time it is
* invoked, the sass file will be compiled to the provided css file name
* (relative to the output directory) and the options provided.
*/
declare type OptionsGenerator = (sassFile: string, cssFile: string, options: nodeSass.Options, cb: OptionsGeneratorCallback) => unknown;
export default class BroccoliSassCompiler extends BroccoliPlugin {
private buildCount;
private colors;
private currentTree;
private dependencies;
private outputURLs;
private outputs;
protected cssDir: string;
protected discover: boolean | undefined;
protected fullException: boolean;
protected maxListeners: number;
protected options: nodeSass.Options;
protected optionsGenerator: OptionsGenerator;
protected persistentCache: DiskCache | undefined;
protected renderSync: boolean;
protected sassDir: string | undefined;
protected sourceFiles: Array<string>;
protected treeName: string | undefined;
protected verbose: boolean;
protected persistentCacheDebug: debugGenerator.Debugger;
protected sessionCache: GenericCache | undefined;
protected buildCache: GenericCache;
protected sass: typeof nodeSass;
events: EventEmitter;
constructor(inputTree: BroccoliPlugin.BroccoliNode | Array<BroccoliPlugin.BroccoliNode>, options: BroccoliSassOptions & nodeSass.Options);
/**
* Wraps the node-style async render method with a promise.
*/
renderSassAsync(options: nodeSass.Options): Promise<nodeSass.Result>;
/**
* Wraps the sync render method with a promise that is either immediately
* resolved or rejected.
*/
renderSassSync(options: nodeSass.SyncOptions): Promise<nodeSass.Result>;
logCompilationSuccess(details: CompilationDetails, result: nodeSass.Result): void;
logCompilationFailure(details: CompilationDetails, error: nodeSass.SassError): void;
compileTree(srcPath: string, files: Array<string>, destDir: string, compilationTimer: heimdall.Cookie<SassRenderSchema>): Promise<void | Array<void | nodeSass.Result>>;
compileSassFile(srcPath: string, sassFilename: string, destDir: string, compilationTimer: heimdall.Cookie<SassRenderSchema>): Array<Promise<void | nodeSass.Result>>;
render(options: nodeSass.Options | nodeSass.SyncOptions): Promise<nodeSass.Result>;
dependencyChanged(srcDir: string, dep: [string, string]): boolean;
getFromCacheOrCompile(details: CompilationDetails, compilationTimer: heimdall.Cookie<SassRenderSchema>): Promise<void>;
hashForFile(absolutePath: string): string;
fileKey(file: string): string;
keyForSourceFile(srcDir: string, relativeFilename: string, _options: nodeSass.Options): string;
dependenciesKey(key: string): string;
outputKey(key: string): string;
handleCacheHit(details: CompilationDetails, inputAndOutputFiles: [Array<string>, CachedContents]): Promise<Array<void>>;
scopedFileName(file: string): string;
relativize(file: string): string;
isOutputInTree(file: string): boolean;
relativizeOutput(file: string): string;
relativizeAll(files: Array<string>): Array<string>;
hasDependenciesSet(file: string): boolean;
dependenciesOf(file: string): Set<string>;
outputsFrom(file: string): Set<string>;
outputURLsFrom(file: string): Map<string, string>;
/**
* Some filenames returned from importers are not really files
* on disk. These three prefixes are used in eyeglass.
* Skipping a read on these files avoids a more expensive fs call
* and exception handling.
* @param filename a filename returned from an importer
*/
isNotFile(filename: string): boolean;
hashDependencies(details: CompilationDetails): CachedDependencies;
readOutputs(details: CompilationDetails): CachedContents;
populateCache(key: string, details: CompilationDetails, _result: nodeSass.Result): void;
handleCacheMiss(details: CompilationDetails, reason: Error | {
message: string;
stack?: Array<string>;
}, key: string, compilationTimer: heimdall.Cookie<SassRenderSchema>): Promise<void>;
compileCssFileMaybe(details: CompilationDetails, compilationTimer: heimdall.Cookie<SassRenderSchema>): Promise<void> | Promise<nodeSass.Result>;
compileCssFile(details: CompilationDetails, compilationTimer: heimdall.Cookie<SassRenderSchema>): Promise<nodeSass.Result>;
handleSuccess(details: CompilationDetails, result: nodeSass.Result): Promise<void>;
handleFailure(details: CompilationDetails, error: nodeSass.SassError | null): Promise<nodeSass.Result>;
filesInTree(srcPath: string): Array<string>;
addSource(sassFilename: string, sourceFilename: string, httpPathToOutput: string): void;
addOutput(sassFilename: string, outputFilename: string): void;
clearOutputs(files: Array<string>): void;
outputsFromOnly(inputs: Array<string>): Set<string>;
addDependency(sassFilename: string, dependencyFilename: string): void;
clearDependencies(files: Array<string>): void;
knownDependencies(): Array<Entry>;
hasKnownDependencies(): boolean;
knownDependenciesTree(inputPath: string): FSTree;
_reset(): void;
_build(): Promise<void | Array<void | nodeSass.Result>>;
build(): Promise<void | Array<void | nodeSass.Result>>;
}
declare class SassRenderSchema {
numSassFiles: number;
nodeSassTime: number;
importCount: number;
uniqueImportCount: number;
cacheMissCount: number;
cacheHitCount: number;
constructor();
}
export {};
//# sourceMappingURL=broccoli_sass_compiler.d.ts.map