sass-embedded
Advanced tools
Comparing version 1.70.0 to 1.71.0
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NULL = exports.FALSE = exports.TRUE = exports.Logger = exports.info = exports.renderSync = exports.render = exports.Compiler = exports.initCompiler = exports.AsyncCompiler = exports.initAsyncCompiler = exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = exports.Exception = exports.types = exports.SassCalculation = exports.CalculationInterpolation = exports.CalculationOperation = exports.sassNull = exports.Value = exports.SassString = exports.SassNumber = exports.SassMixin = exports.SassMap = exports.SassFunction = exports.SassColor = exports.sassTrue = exports.sassFalse = exports.SassArgumentList = exports.SassList = void 0; | ||
exports.NULL = exports.FALSE = exports.TRUE = exports.Logger = exports.info = exports.renderSync = exports.render = exports.Compiler = exports.initCompiler = exports.AsyncCompiler = exports.initAsyncCompiler = exports.NodePackageImporter = exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = exports.Exception = exports.types = exports.SassCalculation = exports.CalculationInterpolation = exports.CalculationOperation = exports.sassNull = exports.Value = exports.SassString = exports.SassNumber = exports.SassMixin = exports.SassMap = exports.SassFunction = exports.SassColor = exports.sassTrue = exports.sassFalse = exports.SassArgumentList = exports.SassList = void 0; | ||
const pkg = require("../package.json"); | ||
@@ -46,2 +46,3 @@ const boolean_1 = require("./src/value/boolean"); | ||
Object.defineProperty(exports, "compileStringAsync", { enumerable: true, get: function () { return compile_1.compileStringAsync; } }); | ||
Object.defineProperty(exports, "NodePackageImporter", { enumerable: true, get: function () { return compile_1.NodePackageImporter; } }); | ||
var async_1 = require("./src/compiler/async"); | ||
@@ -48,0 +49,0 @@ Object.defineProperty(exports, "initAsyncCompiler", { enumerable: true, get: function () { return async_1.initAsyncCompiler; } }); |
@@ -6,5 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = void 0; | ||
exports.compileStringAsync = exports.compileAsync = exports.compileString = exports.compile = exports.NodePackageImporter = void 0; | ||
const async_1 = require("./compiler/async"); | ||
const sync_1 = require("./compiler/sync"); | ||
var importer_registry_1 = require("./importer-registry"); | ||
Object.defineProperty(exports, "NodePackageImporter", { enumerable: true, get: function () { return importer_registry_1.NodePackageImporter; } }); | ||
function compile(path, options) { | ||
@@ -11,0 +13,0 @@ const compiler = (0, sync_1.initCompiler)(); |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ImporterRegistry = void 0; | ||
exports.ImporterRegistry = exports.NodePackageImporter = void 0; | ||
const p = require("path"); | ||
@@ -14,2 +14,20 @@ const url_1 = require("url"); | ||
const utils_1 = require("./utils"); | ||
const entryPointDirectoryKey = Symbol(); | ||
class NodePackageImporter { | ||
constructor(entryPointDirectory) { | ||
var _a; | ||
entryPointDirectory = entryPointDirectory | ||
? p.resolve(entryPointDirectory) | ||
: ((_a = require.main) === null || _a === void 0 ? void 0 : _a.filename) | ||
? p.dirname(require.main.filename) | ||
: undefined; | ||
if (!entryPointDirectory) { | ||
throw new Error('The Node package importer cannot determine an entry point ' + | ||
'because `require.main.filename` is not defined. ' + | ||
'Please provide an `entryPointDirectory` to the `NodePackageImporter`.'); | ||
} | ||
this[entryPointDirectoryKey] = entryPointDirectory; | ||
} | ||
} | ||
exports.NodePackageImporter = NodePackageImporter; | ||
/** | ||
@@ -38,3 +56,11 @@ * A registry of importers defined in the host that can be invoked by the | ||
const message = new proto.InboundMessage_CompileRequest_Importer(); | ||
if ('canonicalize' in importer) { | ||
if (importer instanceof NodePackageImporter) { | ||
const importerMessage = new proto.NodePackageImporter(); | ||
importerMessage.entryPointDirectory = importer[entryPointDirectoryKey]; | ||
message.importer = { | ||
case: 'nodePackageImporter', | ||
value: importerMessage, | ||
}; | ||
} | ||
else if ('canonicalize' in importer) { | ||
if ('findFileUrl' in importer) { | ||
@@ -41,0 +67,0 @@ throw new Error('Importer may not contain both canonicalize() and findFileUrl(): ' + |
@@ -10,2 +10,3 @@ "use strict"; | ||
const url_1 = require("url"); | ||
const importer_registry_1 = require("../importer-registry"); | ||
const exception_1 = require("../exception"); | ||
@@ -107,3 +108,5 @@ const compile_1 = require("../compile"); | ||
functions, | ||
importers, | ||
importers: options.pkgImporter instanceof importer_registry_1.NodePackageImporter | ||
? [options.pkgImporter, ...(importers !== null && importers !== void 0 ? importers : [])] | ||
: importers, | ||
sourceMap: wasSourceMapRequested(options), | ||
@@ -122,3 +125,7 @@ sourceMapIncludeSources: options.sourceMapContents, | ||
function convertStringOptions(options, sync) { | ||
var _a; | ||
const modernOptions = convertOptions(options, sync); | ||
// Find the first non-NodePackageImporter to pass as legacy `importer` option. | ||
// NodePackageImporter will be passed in `modernOptions.importers`. | ||
const importer = (_a = modernOptions.importers) === null || _a === void 0 ? void 0 : _a.find(_importer => !(_importer instanceof importer_registry_1.NodePackageImporter)); | ||
return { | ||
@@ -131,3 +138,3 @@ ...modernOptions, | ||
: new url_1.URL(utils_2.legacyImporterProtocol), | ||
importer: modernOptions.importers ? modernOptions.importers[0] : undefined, | ||
importer, | ||
syntax: options.indentedSyntax ? 'indented' : 'scss', | ||
@@ -134,0 +141,0 @@ }; |
{ | ||
"name": "sass-embedded", | ||
"version": "1.70.0", | ||
"protocol-version": "2.4.0", | ||
"compiler-version": "1.70.0", | ||
"version": "1.71.0", | ||
"protocol-version": "2.5.0", | ||
"compiler-version": "1.71.0", | ||
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol", | ||
@@ -38,18 +38,18 @@ "repository": "sass/embedded-host-node", | ||
"optionalDependencies": { | ||
"sass-embedded-android-arm": "1.70.0", | ||
"sass-embedded-android-arm64": "1.70.0", | ||
"sass-embedded-android-ia32": "1.70.0", | ||
"sass-embedded-android-x64": "1.70.0", | ||
"sass-embedded-darwin-arm64": "1.70.0", | ||
"sass-embedded-darwin-x64": "1.70.0", | ||
"sass-embedded-linux-arm": "1.70.0", | ||
"sass-embedded-linux-arm64": "1.70.0", | ||
"sass-embedded-linux-ia32": "1.70.0", | ||
"sass-embedded-linux-x64": "1.70.0", | ||
"sass-embedded-linux-musl-arm": "1.70.0", | ||
"sass-embedded-linux-musl-arm64": "1.70.0", | ||
"sass-embedded-linux-musl-ia32": "1.70.0", | ||
"sass-embedded-linux-musl-x64": "1.70.0", | ||
"sass-embedded-win32-ia32": "1.70.0", | ||
"sass-embedded-win32-x64": "1.70.0" | ||
"sass-embedded-android-arm": "1.71.0", | ||
"sass-embedded-android-arm64": "1.71.0", | ||
"sass-embedded-android-ia32": "1.71.0", | ||
"sass-embedded-android-x64": "1.71.0", | ||
"sass-embedded-darwin-arm64": "1.71.0", | ||
"sass-embedded-darwin-x64": "1.71.0", | ||
"sass-embedded-linux-arm": "1.71.0", | ||
"sass-embedded-linux-arm64": "1.71.0", | ||
"sass-embedded-linux-ia32": "1.71.0", | ||
"sass-embedded-linux-x64": "1.71.0", | ||
"sass-embedded-linux-musl-arm": "1.71.0", | ||
"sass-embedded-linux-musl-arm64": "1.71.0", | ||
"sass-embedded-linux-musl-ia32": "1.71.0", | ||
"sass-embedded-linux-musl-x64": "1.71.0", | ||
"sass-embedded-win32-ia32": "1.71.0", | ||
"sass-embedded-win32-x64": "1.71.0" | ||
}, | ||
@@ -56,0 +56,0 @@ "dependencies": { |
@@ -311,3 +311,136 @@ import {Syntax} from './options'; | ||
declare const nodePackageImporterKey: unique symbol; | ||
/** | ||
* The built-in Node.js package importer. This loads pkg: URLs from node_modules | ||
* according to the standard Node.js resolution algorithm. | ||
* | ||
* A Node.js package importer is exposed as a class that can be added to the | ||
* `importers` option. | ||
* | ||
*```js | ||
* const sass = require('sass'); | ||
* sass.compileString('@use "pkg:vuetify', { | ||
* importers: [new sass.NodePackageImporter()] | ||
* }); | ||
*``` | ||
* | ||
* ## Writing Sass packages | ||
* | ||
* Package authors can control what is exposed to their users through their | ||
* `package.json` manifest. The recommended method is to add a `sass` | ||
* conditional export to `package.json`. | ||
* | ||
* ```json | ||
* // node_modules/uicomponents/package.json | ||
* { | ||
* "exports": { | ||
* ".": { | ||
* "sass": "./src/scss/index.scss", | ||
* "import": "./dist/js/index.mjs", | ||
* "default": "./dist/js/index.js" | ||
* } | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* This allows a package user to write `@use "pkg:uicomponents"` to load the | ||
* file at `node_modules/uicomponents/src/scss/index.scss`. | ||
* | ||
* The Node.js package importer supports the variety of formats supported by | ||
* Node.js [package entry points], allowing authors to expose multiple subpaths. | ||
* | ||
* [package entry points]: | ||
* https://nodejs.org/api/packages.html#package-entry-points | ||
* | ||
* ```json | ||
* // node_modules/uicomponents/package.json | ||
* { | ||
* "exports": { | ||
* ".": { | ||
* "sass": "./src/scss/index.scss", | ||
* }, | ||
* "./colors": { | ||
* "sass": "./src/scss/_colors.scss", | ||
* }, | ||
* "./theme/*": { | ||
* "sass": "./src/scss/theme/*.scss", | ||
* }, | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* This allows a package user to write: | ||
* | ||
* - `@use "pkg:uicomponents";` to import the root export. | ||
* - `@use "pkg:uicomponents/colors";` to import the colors partial. | ||
* - `@use "pkg:uicomponents/theme/purple";` to import a purple theme. | ||
* | ||
* Note that while library users can rely on the importer to resolve | ||
* [partials](https://sass-lang.com/documentation/at-rules/use#partials), [index | ||
* files](https://sass-lang.com/documentation/at-rules/use#index-files), and | ||
* extensions, library authors must specify the entire file path in `exports`. | ||
* | ||
* In addition to the `sass` condition, the `style` condition is also | ||
* acceptable. Sass will match the `default` condition if it's a relevant file | ||
* type, but authors are discouraged from relying on this. Notably, the key | ||
* order matters, and the importer will resolve to the first value with a key | ||
* that is `sass`, `style`, or `default`, so you should always put `default` | ||
* last. | ||
* | ||
* To help package authors who haven't transitioned to package entry points | ||
* using the `exports` field, the Node.js package importer provides several | ||
* fallback options. If the `pkg:` URL does not have a subpath, the Node.js | ||
* package importer will look for a `sass` or `style` key at the root of | ||
* `package.json`. | ||
* | ||
* ```json | ||
* // node_modules/uicomponents/package.json | ||
* { | ||
* "sass": "./src/scss/index.scss", | ||
* } | ||
* ``` | ||
* | ||
* This allows a user to write `@use "pkg:uicomponents";` to import the | ||
* `index.scss` file. | ||
* | ||
* Finally, the Node.js package importer will look for an `index` file at the | ||
* package root, resolving partials and extensions. For example, if the file | ||
* `_index.scss` exists in the package root of `uicomponents`, a user can import | ||
* that with `@use "pkg:uicomponents";`. | ||
* | ||
* If a `pkg:` URL includes a subpath that doesn't have a match in package entry | ||
* points, the Node.js importer will attempt to find that file relative to the | ||
* package root, resolving for file extensions, partials and index files. For | ||
* example, if the file `src/sass/_colors.scss` exists in the `uicomponents` | ||
* package, a user can import that file using `@use | ||
* "pkg:uicomponents/src/sass/colors";`. | ||
* | ||
* @compatibility dart: "2.0", node: false | ||
* @category Importer | ||
*/ | ||
export class NodePackageImporter { | ||
/** Used to distinguish this type from any arbitrary object. */ | ||
private readonly [nodePackageImporterKey]: true; | ||
/** | ||
* The NodePackageImporter has an optional `entryPointDirectory` option, which | ||
* is the directory where the Node Package Importer should start when | ||
* resolving `pkg:` URLs in sources other than files on disk. This will be | ||
* used as the `parentURL` in the [Node Module | ||
* Resolution](https://nodejs.org/api/esm.html#resolution-algorithm-specification) | ||
* algorithm. | ||
* | ||
* In order to be found by the Node Package Importer, a package will need to | ||
* be inside a node_modules folder located in the `entryPointDirectory`, or | ||
* one of its parent directories, up to the filesystem root. | ||
* | ||
* Relative paths will be resolved relative to the current working directory. | ||
* If a path is not provided, the default value of `require.main.filename` | ||
* will be used. | ||
*/ | ||
constructor(entryPointDirectory?: string); | ||
} | ||
/** | ||
* The result of successfully loading a stylesheet with an {@link Importer}. | ||
@@ -314,0 +447,0 @@ * |
@@ -22,2 +22,3 @@ // This is a mirror of the JS API definitions in `spec/js-api`, but with comments | ||
ImporterResult, | ||
NodePackageImporter, | ||
} from './importer'; | ||
@@ -24,0 +25,0 @@ export {Logger, SourceSpan, SourceLocation} from './logger'; |
@@ -22,2 +22,3 @@ // This is a mirror of the JS API definitions in `spec/js-api`, but with comments | ||
ImporterResult, | ||
NodePackageImporter, | ||
} from './importer'; | ||
@@ -24,0 +25,0 @@ export {Logger, SourceSpan, SourceLocation} from './logger'; |
import {Logger} from '../logger'; | ||
import {LegacyImporter} from './importer'; | ||
import {LegacyFunction} from './function'; | ||
import {NodePackageImporter} from '../importer'; | ||
@@ -511,2 +512,20 @@ /** | ||
logger?: Logger; | ||
/** | ||
* If this option is set to an instance of `NodePackageImporter`, Sass will | ||
* use the built-in Node.js package importer to resolve Sass files with a | ||
* `pkg:` URL scheme. Details for library authors and users can be found in | ||
* the {@link NodePackageImporter} documentation. | ||
* | ||
* @example | ||
* ```js | ||
* sass.renderSync({ | ||
* data: '@use "pkg:vuetify";', | ||
* pkgImporter: new sass.NodePackageImporter() | ||
* }); | ||
* ``` | ||
* @category Plugins | ||
* @compatibility dart: "2.0", node: false | ||
*/ | ||
pkgImporter?: NodePackageImporter; | ||
} | ||
@@ -513,0 +532,0 @@ |
@@ -1,2 +0,2 @@ | ||
import {FileImporter, Importer} from './importer'; | ||
import {FileImporter, Importer, NodePackageImporter} from './importer'; | ||
import {Logger} from './logger'; | ||
@@ -211,4 +211,4 @@ import {Value} from './value'; | ||
* | ||
* - Each {@link Importer} or {@link FileImporter} in {@link importers}, in | ||
* order. | ||
* - Each {@link Importer}, {@link FileImporter}, or | ||
* {@link NodePackageImporter} in {@link importers}, in order. | ||
* | ||
@@ -222,3 +222,3 @@ * - Each load path in {@link loadPaths}, in order. | ||
*/ | ||
importers?: (Importer<sync> | FileImporter<sync>)[]; | ||
importers?: (Importer<sync> | FileImporter<sync> | NodePackageImporter)[]; | ||
@@ -225,0 +225,0 @@ /** |
{ | ||
"name": "sass-embedded", | ||
"version": "1.70.0", | ||
"protocol-version": "2.4.0", | ||
"compiler-version": "1.70.0", | ||
"version": "1.71.0", | ||
"protocol-version": "2.5.0", | ||
"compiler-version": "1.71.0", | ||
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol", | ||
@@ -38,18 +38,18 @@ "repository": "sass/embedded-host-node", | ||
"optionalDependencies": { | ||
"sass-embedded-android-arm": "1.70.0", | ||
"sass-embedded-android-arm64": "1.70.0", | ||
"sass-embedded-android-ia32": "1.70.0", | ||
"sass-embedded-android-x64": "1.70.0", | ||
"sass-embedded-darwin-arm64": "1.70.0", | ||
"sass-embedded-darwin-x64": "1.70.0", | ||
"sass-embedded-linux-arm": "1.70.0", | ||
"sass-embedded-linux-arm64": "1.70.0", | ||
"sass-embedded-linux-ia32": "1.70.0", | ||
"sass-embedded-linux-x64": "1.70.0", | ||
"sass-embedded-linux-musl-arm": "1.70.0", | ||
"sass-embedded-linux-musl-arm64": "1.70.0", | ||
"sass-embedded-linux-musl-ia32": "1.70.0", | ||
"sass-embedded-linux-musl-x64": "1.70.0", | ||
"sass-embedded-win32-ia32": "1.70.0", | ||
"sass-embedded-win32-x64": "1.70.0" | ||
"sass-embedded-android-arm": "1.71.0", | ||
"sass-embedded-android-arm64": "1.71.0", | ||
"sass-embedded-android-ia32": "1.71.0", | ||
"sass-embedded-android-x64": "1.71.0", | ||
"sass-embedded-darwin-arm64": "1.71.0", | ||
"sass-embedded-darwin-x64": "1.71.0", | ||
"sass-embedded-linux-arm": "1.71.0", | ||
"sass-embedded-linux-arm64": "1.71.0", | ||
"sass-embedded-linux-ia32": "1.71.0", | ||
"sass-embedded-linux-x64": "1.71.0", | ||
"sass-embedded-linux-musl-arm": "1.71.0", | ||
"sass-embedded-linux-musl-arm64": "1.71.0", | ||
"sass-embedded-linux-musl-ia32": "1.71.0", | ||
"sass-embedded-linux-musl-x64": "1.71.0", | ||
"sass-embedded-win32-ia32": "1.71.0", | ||
"sass-embedded-win32-x64": "1.71.0" | ||
}, | ||
@@ -56,0 +56,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
714031
12502