eyeglass
Version:
Sass modules for npm.
173 lines • 5.5 kB
TypeScript
import * as packageUtils from "../util/package";
import { IEyeglass } from "../IEyeglass";
import { SassImplementation } from "../util/SassImplementation";
import type { FunctionDeclarations } from "node-sass";
import packageJson = require("package-json");
import AssetsCollection from "../assets/AssetsCollection";
import { Dict } from "../util/typescriptUtils";
import { SemVer } from "semver";
declare type PackageJson = packageJson.FullVersion;
export interface DiscoverOptions {
isRoot: boolean;
dir: string;
pkg?: packageUtils.Package;
}
export interface EyeglassModuleExports {
name?: string;
functions?: FunctionDeclarations;
assets?: AssetsCollection;
sassDir?: string;
eyeglass?: {
needs?: string;
};
}
interface EyeglassModuleOptionsFromPackageJSON {
inDevelopment?: boolean;
name?: string;
exports?: string | false;
sassDir?: string;
needs?: string;
}
export declare type EyeglassModuleMain = (eyeglass: IEyeglass, sass: SassImplementation) => EyeglassModuleExports;
export declare type ModuleSpecifier = ModuleReference | ManualModuleOptions;
export interface ModuleReference {
path: string;
/**
* XXX I don't think dependencies are ever actually
* passed along with a path reference but the code allows it.
*/
dependencies?: Array<EyeglassModule>;
isEyeglassModule?: boolean;
}
export interface ManualModuleOptions {
/**
* The name of the module.
*/
name?: string;
/**
* The function that would normally be exported from the
* eyeglass exports file.
*/
main?: EyeglassModuleMain | null;
/**
* If a main function is provided this path to the
* filename where it is defined should be provided
* for better error messages in some situations.
*/
mainPath?: string | undefined;
/**
* The directory where sass files are found for this module.
*/
sassDir?: string;
/**
* A version for this manual module.
*/
version?: string;
eyeglass?: {
/**
* The name of the module for the purpose of importing
* from sass files.
*/
name?: string;
/**
* Alternative way to specify the directory where sass files are found for
* this module.
*/
sassDir?: string;
/**
* The semver dependency on eyeglass's module API.
*/
needs?: string;
};
}
interface IEyeglassModule {
inDevelopment: boolean;
/**
* The resolved name of the eyeglass module.
*/
name: string;
/**
* The name of the package which may be different from the name of the
* eyeglass module.
*/
rawName: string;
/**
* Options for the module that were passed from package.json
*/
eyeglass: EyeglassModuleOptionsFromPackageJSON;
/**
* The absolute path to this module.
*/
path: string;
/**
* The exports function used to help initialize this module.
*/
main?: EyeglassModuleMain | null;
/**
* The path to main/exports function. Used for debugging.
*/
mainPath?: string | null;
/**
* Whether this is an eyeglass module. Manual modules
* and the application itself are modules where this is false.
*/
isEyeglassModule: boolean;
/**
* Whether this is the project root.
*/
isRoot: boolean;
/**
* The version of this module.
*/
version: string | undefined;
/**
* The other modules this module depends on. The dependency tree is
* eventually flattened with a semver resolution to select a single instance
* of shared transitive dependencies.
*/
dependencies: Dict<EyeglassModule>;
/**
* Where the sass files are. `@import "<module name>"` would import the index
* sass file from that directory. Imports of paths relative to the module
* name are imported relative to this directory.
*/
sassDir?: string;
}
export declare function isModuleReference(mod: unknown): mod is ModuleReference;
export default class EyeglassModule implements IEyeglassModule, EyeglassModuleExports {
inDevelopment: boolean;
dependencies: Dict<EyeglassModule>;
eyeglass: EyeglassModuleOptionsFromPackageJSON;
isEyeglassModule: boolean;
isRoot: boolean;
name: string;
path: string;
rawName: string;
version: string | undefined;
sassDir?: string;
main?: EyeglassModuleMain | null;
mainPath?: string | null;
/** only present after calling `init()` */
functions?: FunctionDeclarations;
/** only present after calling `init()` */
assets?: AssetsCollection;
semver: SemVer;
constructor(modArg: ModuleReference | ManualModuleOptions, discoverModules?: (opts: DiscoverOptions) => Dict<EyeglassModule> | null, isRoot?: boolean);
/**
* initializes the module with the given engines
*
* @param {Eyeglass} eyeglass - the eyeglass instance
* @param {Function} sass - the sass engine
*/
init(eyeglass: IEyeglass, sass: SassImplementation): void;
/**
* whether or not the given package is an eyeglass module
*
* @param {Object} pkg - the package.json
* @returns {Boolean} whether or not it is an eyeglass module
*/
static isEyeglassModule(pkg: PackageJson | undefined | null): boolean;
hasModulePath(path: string): boolean;
}
export {};
//# sourceMappingURL=EyeglassModule.d.ts.map