@stencil/sass
Advanced tools
Comparing version 2.0.3 to 2.0.4
import { SassException } from 'sass'; | ||
import * as d from './declarations'; | ||
export declare function loadDiagnostic(context: d.PluginCtx, sassError: SassException, filePath: string): d.Diagnostic; | ||
/** | ||
* Generates a diagnostic as a result of an error originating from Sass. | ||
* | ||
* This function mutates the provided context by pushing the generated diagnostic to the context's collection of | ||
* diagnostics. | ||
* | ||
* @param context the compilation context that the plugin has access to | ||
* @param sassError the Sass error to create a diagnostic from | ||
* @param filePath the path of the file that led to an error being raised | ||
* @returns the created diagnostic, or `null` if one could not be generated | ||
*/ | ||
export declare function loadDiagnostic(context: d.PluginCtx, sassError: SassException, filePath: string): d.Diagnostic | null; |
@@ -0,1 +1,12 @@ | ||
/** | ||
* Generates a diagnostic as a result of an error originating from Sass. | ||
* | ||
* This function mutates the provided context by pushing the generated diagnostic to the context's collection of | ||
* diagnostics. | ||
* | ||
* @param context the compilation context that the plugin has access to | ||
* @param sassError the Sass error to create a diagnostic from | ||
* @param filePath the path of the file that led to an error being raised | ||
* @returns the created diagnostic, or `null` if one could not be generated | ||
*/ | ||
export function loadDiagnostic(context, sassError, filePath) { | ||
@@ -84,2 +95,7 @@ if (sassError == null || context == null) { | ||
} | ||
/** | ||
* Helper function for converting a number error code to a string | ||
* @param input the numeric error code to convert | ||
* @returns the stringified error code | ||
*/ | ||
function formatCode(input) { | ||
@@ -92,2 +108,8 @@ let output = ''; | ||
} | ||
/** | ||
* Splits up a message from Sass, returning all input prior to the first '╷' character. | ||
* If no such character exists, the entire original message will be returned. | ||
* @param input the Sass message to split | ||
* @returns the split message | ||
*/ | ||
function formatMessage(input) { | ||
@@ -100,2 +122,9 @@ let output = ''; | ||
} | ||
/** | ||
* Formats the provided filename, by stripping the provided root directory out of the filename, and limiting the | ||
* display string to 80 characters | ||
* @param rootDir the root directory to strip out of the provided filename | ||
* @param fileName the filename to format for pretty printing | ||
* @returns the formatted filename | ||
*/ | ||
function formatFileName(rootDir, fileName) { | ||
@@ -102,0 +131,0 @@ if (!rootDir || !fileName) |
import * as d from './declarations'; | ||
/** | ||
* The entrypoint of the Stencil Sass plugin | ||
* | ||
* This function creates & configures the plugin to be used by consuming Stencil projects | ||
* | ||
* For configuration details, please see the [GitHub README](https://github.com/ionic-team/stencil-sass). | ||
* | ||
* @param opts options to configure the plugin | ||
* @return the configured plugin | ||
*/ | ||
export declare function sass(opts?: d.PluginOptions): d.Plugin; |
import * as d from './declarations'; | ||
/** | ||
* Determine if the Sass plugin should be applied, based on the provided `fileName` | ||
* | ||
* @param fileName the name of a file to potentially transform | ||
* @returns `true` if the name of the file ends with a sass extension (.scss, .sass), case insensitive. `false` | ||
* otherwise | ||
*/ | ||
export declare function usePlugin(fileName: string): boolean; | ||
/** | ||
* Build a list of options to provide to Sass' `render` API. | ||
* @param opts the options provided to the plugin within a Stencil configuration file | ||
* @param sourceText the source text of the file to transform | ||
* @param fileName the name of the file to transform | ||
* @param context the runtime context being used by the plugin | ||
* @returns the generated/normalized plugin options | ||
*/ | ||
export declare function getRenderOptions(opts: d.PluginOptions, sourceText: string, fileName: string, context: d.PluginCtx): d.PluginOptions; | ||
/** | ||
* Replaces the extension with the provided file name with 'css'. | ||
* | ||
* If the file does not have an extension, no transformation will be applied. | ||
* | ||
* @param fileName the name of the file whose extension should be replaced | ||
* @returns the updated filename, using 'css' as the file extension | ||
*/ | ||
export declare function createResultsId(fileName: string): string; | ||
export declare function normalizePath(str: string): string; | ||
/** | ||
* Split an import path into a module ID and file path | ||
* @param orgImport the import path to split | ||
* @returns a module id and the filepath under that module id | ||
*/ | ||
export declare function getModuleId(orgImport: string): { | ||
@@ -7,0 +35,0 @@ moduleId: string; |
import * as path from 'path'; | ||
/** | ||
* Determine if the Sass plugin should be applied, based on the provided `fileName` | ||
* | ||
* @param fileName the name of a file to potentially transform | ||
* @returns `true` if the name of the file ends with a sass extension (.scss, .sass), case insensitive. `false` | ||
* otherwise | ||
*/ | ||
export function usePlugin(fileName) { | ||
@@ -8,12 +15,23 @@ if (typeof fileName === 'string') { | ||
} | ||
/** | ||
* Build a list of options to provide to Sass' `render` API. | ||
* @param opts the options provided to the plugin within a Stencil configuration file | ||
* @param sourceText the source text of the file to transform | ||
* @param fileName the name of the file to transform | ||
* @param context the runtime context being used by the plugin | ||
* @returns the generated/normalized plugin options | ||
*/ | ||
export function getRenderOptions(opts, sourceText, fileName, context) { | ||
// create a copy of the original sass config so we don't change it | ||
// create a copy of the original sass config, so we don't modify the one provided | ||
const renderOpts = Object.assign({}, opts); | ||
// always set "data" from the source text | ||
renderOpts.data = sourceText; | ||
// activate indented syntax if the file extension is .sass | ||
// activate indented syntax if the file extension is .sass. | ||
// this needs to be set prior to injecting global sass (as the syntax affects the import terminator) | ||
renderOpts.indentedSyntax = /(\.sass)$/i.test(fileName); | ||
// create a copy of the original path config, so we don't modify the one provided | ||
renderOpts.includePaths = Array.isArray(opts.includePaths) ? opts.includePaths.slice() : []; | ||
// add the directory of the source file to includePaths | ||
renderOpts.includePaths.push(path.dirname(fileName)); | ||
// ensure each of the includePaths is an absolute path | ||
renderOpts.includePaths = renderOpts.includePaths.map((includePath) => { | ||
@@ -26,5 +44,8 @@ if (path.isAbsolute(includePath)) { | ||
}); | ||
// create a copy of the original global config of paths to inject, so we don't modify the one provided. | ||
// this is a Stencil-specific configuration, and not a part of the Sass API. | ||
const injectGlobalPaths = Array.isArray(opts.injectGlobalPaths) ? opts.injectGlobalPaths.slice() : []; | ||
if (injectGlobalPaths.length > 0) { | ||
// automatically inject each of these paths into the source text | ||
// Automatically inject each of these paths into the source text. | ||
// This is accomplished by prepending the global stylesheets to the file being processed. | ||
const injectText = injectGlobalPaths | ||
@@ -61,2 +82,9 @@ .map((injectGlobalPath) => { | ||
} | ||
/** | ||
* Create a handler for loading files when a `@use` or `@import` rule is encountered for loading a path prefixed | ||
* with a tilde (~). Such imports indicate that the module should be resolved from the `node_modules` directory. | ||
* @param url the path to the module to load | ||
* @param _prev Unused - typically, this is a string identifying the stylesheet that contained the @use or @import. | ||
* @param done a callback to return the path to the resolved path | ||
*/ | ||
const importer = (url, _prev, done) => { | ||
@@ -102,2 +130,10 @@ if (typeof url === 'string') { | ||
} | ||
/** | ||
* Replaces the extension with the provided file name with 'css'. | ||
* | ||
* If the file does not have an extension, no transformation will be applied. | ||
* | ||
* @param fileName the name of the file whose extension should be replaced | ||
* @returns the updated filename, using 'css' as the file extension | ||
*/ | ||
export function createResultsId(fileName) { | ||
@@ -136,2 +172,7 @@ // create what the new path is post transform (.css) | ||
} | ||
/** | ||
* Split an import path into a module ID and file path | ||
* @param orgImport the import path to split | ||
* @returns a module id and the filepath under that module id | ||
*/ | ||
export function getModuleId(orgImport) { | ||
@@ -147,2 +188,3 @@ if (orgImport.startsWith('~')) { | ||
if (orgImport.startsWith('@') && splt.length > 1) { | ||
// we have a scoped package, it's module includes the word following the first slash | ||
m.moduleId = splt.slice(0, 2).join('/'); | ||
@@ -149,0 +191,0 @@ m.filePath = splt.slice(2).join('/'); |
{ | ||
"name": "@stencil/sass", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"license": "MIT", | ||
@@ -31,3 +31,3 @@ "main": "dist/index.js", | ||
"@rollup/plugin-node-resolve": "^15.0.0", | ||
"@stencil/core": "^2.17.3", | ||
"@stencil/core": "^3.0.0", | ||
"@types/jest": "^26.0.15", | ||
@@ -34,0 +34,0 @@ "@types/node": "^16.11.48", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4772403
19595