sass-embedded
Advanced tools
Comparing version 1.66.1 to 1.67.0
@@ -20,3 +20,3 @@ "use strict"; | ||
const deprotofy_span_1 = require("./deprotofy-span"); | ||
const importer_1 = require("./legacy/importer"); | ||
const utils_1 = require("./legacy/utils"); | ||
function compile(path, options) { | ||
@@ -56,3 +56,3 @@ const importers = new importer_registry_1.ImporterRegistry(options); | ||
const url = (_b = options === null || options === void 0 ? void 0 : options.url) === null || _b === void 0 ? void 0 : _b.toString(); | ||
if (url && url !== importer_1.legacyImporterProtocol) { | ||
if (url && url !== utils_1.legacyImporterProtocol) { | ||
input.url = url; | ||
@@ -63,3 +63,3 @@ } | ||
} | ||
else if (url === importer_1.legacyImporterProtocol) { | ||
else if (url === utils_1.legacyImporterProtocol) { | ||
input.importer = new proto.InboundMessage_CompileRequest_Importer({ | ||
@@ -193,10 +193,19 @@ importer: { case: 'path', value: p.resolve('.') }, | ||
var _a, _b; | ||
let span = event.span ? (0, deprotofy_span_1.deprotofySourceSpan)(event.span) : null; | ||
if (span && (options === null || options === void 0 ? void 0 : options.legacy)) | ||
span = (0, utils_1.removeLegacyImporterFromSpan)(span); | ||
let message = event.message; | ||
if (options === null || options === void 0 ? void 0 : options.legacy) | ||
message = (0, utils_1.removeLegacyImporter)(message); | ||
let formatted = event.formatted; | ||
if (options === null || options === void 0 ? void 0 : options.legacy) | ||
formatted = (0, utils_1.removeLegacyImporter)(formatted); | ||
if (event.type === proto.LogEventType.DEBUG) { | ||
if ((_a = options === null || options === void 0 ? void 0 : options.logger) === null || _a === void 0 ? void 0 : _a.debug) { | ||
options.logger.debug(event.message, { | ||
span: (0, deprotofy_span_1.deprotofySourceSpan)(event.span), | ||
options.logger.debug(message, { | ||
span: span, | ||
}); | ||
} | ||
else { | ||
console.error(event.formatted); | ||
console.error(formatted); | ||
} | ||
@@ -209,12 +218,12 @@ } | ||
}; | ||
const spanProto = event.span; | ||
if (spanProto) | ||
params.span = (0, deprotofy_span_1.deprotofySourceSpan)(spanProto); | ||
if (span) | ||
params.span = span; | ||
const stack = event.stackTrace; | ||
if (stack) | ||
params.stack = stack; | ||
options.logger.warn(event.message, params); | ||
if (stack) { | ||
params.stack = (options === null || options === void 0 ? void 0 : options.legacy) ? (0, utils_1.removeLegacyImporter)(stack) : stack; | ||
} | ||
options.logger.warn(message, params); | ||
} | ||
else { | ||
console.error(event.formatted); | ||
console.error(formatted); | ||
} | ||
@@ -221,0 +230,0 @@ } |
@@ -6,5 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LegacyImporterWrapper = exports.legacyImporterProtocol = exports.endOfLoadProtocol = void 0; | ||
exports.LegacyImporterWrapper = exports.legacyImporterFileProtocol = exports.endOfLoadProtocol = void 0; | ||
const assert_1 = require("assert"); | ||
const url_1 = require("url"); | ||
const fs = require("fs"); | ||
@@ -15,2 +14,3 @@ const p = require("path"); | ||
const utils_1 = require("../utils"); | ||
const utils_2 = require("./utils"); | ||
/** | ||
@@ -24,5 +24,5 @@ * A special URL protocol we use to signal when a stylesheet has finished | ||
/** | ||
* The URL protocol to use for URLs canonicalized using `LegacyImporterWrapper`. | ||
* The `file:` URL protocol with [legacyImporterProtocolPrefix] at the beginning. | ||
*/ | ||
exports.legacyImporterProtocol = 'legacy-importer:'; | ||
exports.legacyImporterFileProtocol = 'legacy-importer-file:'; | ||
// A count of `endOfLoadProtocol` imports that have been generated. Each one | ||
@@ -43,6 +43,2 @@ // must be a different URL to ensure that the importer results aren't cached. | ||
this.prev = []; | ||
// Whether we're expecting the next call to `canonicalize()` to be a relative | ||
// load. The legacy importer API doesn't handle these loads in the same way as | ||
// the modern API, so we always return `null` in this case. | ||
this.expectingRelativeLoad = true; | ||
const path = initialPrev !== 'stdin'; | ||
@@ -54,9 +50,14 @@ this.prev.push({ url: path ? p.resolve(initialPrev) : 'stdin', path }); | ||
return new URL(url); | ||
// Since there's only ever one modern importer in legacy mode, we can be | ||
// sure that all normal loads are preceded by exactly one relative load. | ||
if (this.expectingRelativeLoad) { | ||
if (url.startsWith('file:')) { | ||
if (url.startsWith(utils_2.legacyImporterProtocolPrefix) || | ||
url.startsWith(utils_2.legacyImporterProtocol)) { | ||
// A load starts with `legacyImporterProtocolPrefix` if and only if it's a | ||
// relative load for the current importer rather than an absolute load. | ||
// For the most part, we want to ignore these, but for `file:` URLs | ||
// specifically we want to resolve them on the filesystem to ensure | ||
// locality. | ||
const urlWithoutPrefix = url.substring(utils_2.legacyImporterProtocolPrefix.length); | ||
if (urlWithoutPrefix.startsWith('file:')) { | ||
let resolved = null; | ||
try { | ||
const path = (0, utils_1.fileUrlToPathCrossPlatform)(url); | ||
const path = (0, utils_1.fileUrlToPathCrossPlatform)(urlWithoutPrefix); | ||
resolved = (0, resolve_path_1.resolvePath)(path, options.fromImport); | ||
@@ -82,13 +83,7 @@ } | ||
this.prev.push({ url: resolved, path: true }); | ||
return (0, url_1.pathToFileURL)(resolved); | ||
return (0, utils_2.pathToLegacyFileUrl)(resolved); | ||
} | ||
} | ||
this.expectingRelativeLoad = false; | ||
return null; | ||
} | ||
else if (!url.startsWith('file:')) { | ||
// We'll only search for another relative import when the URL isn't | ||
// absolute. | ||
this.expectingRelativeLoad = true; | ||
} | ||
const prev = this.prev[this.prev.length - 1]; | ||
@@ -108,10 +103,10 @@ return (0, utils_1.thenOr)((0, utils_1.thenOr)(this.invokeCallbacks(url, prev.url, options), result => { | ||
if ('file' in result) { | ||
return new URL(exports.legacyImporterProtocol + | ||
return new URL(utils_2.legacyImporterProtocol + | ||
encodeURI(result.file)); | ||
} | ||
else if (/^[A-Za-z+.-]+:/.test(url)) { | ||
return new URL(url); | ||
return new URL(`${utils_2.legacyImporterProtocolPrefix}${url}`); | ||
} | ||
else { | ||
return new URL(exports.legacyImporterProtocol + encodeURI(url)); | ||
return new URL(utils_2.legacyImporterProtocol + encodeURI(url)); | ||
} | ||
@@ -122,3 +117,3 @@ } | ||
const resolved = (0, resolve_path_1.resolvePath)(result.file, options.fromImport); | ||
return resolved ? (0, url_1.pathToFileURL)(resolved) : null; | ||
return resolved ? (0, utils_2.pathToLegacyFileUrl)(resolved) : null; | ||
} | ||
@@ -131,3 +126,3 @@ const prefixes = [...this.loadPaths, '.']; | ||
if (resolved !== null) | ||
return (0, url_1.pathToFileURL)(resolved); | ||
return (0, utils_2.pathToLegacyFileUrl)(resolved); | ||
} | ||
@@ -138,5 +133,5 @@ return null; | ||
if (result !== null) { | ||
const path = result.protocol === 'file:'; | ||
const path = result.protocol === exports.legacyImporterFileProtocol; | ||
this.prev.push({ | ||
url: path ? (0, utils_1.fileUrlToPathCrossPlatform)(result) : url, | ||
url: path ? (0, utils_2.legacyFileUrlToPath)(result) : url, | ||
path, | ||
@@ -150,3 +145,3 @@ }); | ||
if (resolved !== null) | ||
return (0, url_1.pathToFileURL)(resolved); | ||
return (0, utils_2.pathToLegacyFileUrl)(resolved); | ||
} | ||
@@ -167,3 +162,3 @@ return null; | ||
} | ||
if (canonicalUrl.protocol === 'file:') { | ||
if (canonicalUrl.protocol === exports.legacyImporterFileProtocol) { | ||
const syntax = canonicalUrl.pathname.endsWith('.sass') | ||
@@ -174,3 +169,3 @@ ? 'indented' | ||
: 'scss'; | ||
let contents = (_a = this.lastContents) !== null && _a !== void 0 ? _a : fs.readFileSync((0, utils_1.fileUrlToPathCrossPlatform)(canonicalUrl), 'utf-8'); | ||
let contents = (_a = this.lastContents) !== null && _a !== void 0 ? _a : fs.readFileSync((0, utils_2.legacyFileUrlToPath)(canonicalUrl), 'utf-8'); | ||
this.lastContents = undefined; | ||
@@ -177,0 +172,0 @@ if (syntax === 'scss') { |
@@ -15,2 +15,3 @@ "use strict"; | ||
const importer_1 = require("./importer"); | ||
const utils_2 = require("./utils"); | ||
function render(options, callback) { | ||
@@ -46,4 +47,4 @@ try { | ||
exports.renderSync = renderSync; | ||
// Does some initial adjustments of `options` to make it easier to convert pass | ||
// to the new API. | ||
// Does some initial adjustments of `options` to make it easier to pass to the | ||
// new API. | ||
function adjustOptions(options) { | ||
@@ -116,2 +117,3 @@ var _a; | ||
logger: options.logger, | ||
legacy: true, | ||
}; | ||
@@ -125,4 +127,6 @@ } | ||
url: options.file | ||
? (0, url_1.pathToFileURL)(options.file) | ||
: new url_1.URL(importer_1.legacyImporterProtocol), | ||
? options.importer | ||
? (0, utils_2.pathToLegacyFileUrl)(options.file) | ||
: (0, url_1.pathToFileURL)(options.file) | ||
: new url_1.URL(utils_2.legacyImporterProtocol), | ||
importer: modernOptions.importers ? modernOptions.importers[0] : undefined, | ||
@@ -188,8 +192,6 @@ syntax: options.indentedSyntax ? 'indented' : 'scss', | ||
.map(source => { | ||
source = (0, utils_2.removeLegacyImporter)(source); | ||
if (source.startsWith('file://')) { | ||
return (0, utils_1.pathToUrlString)(p.relative(sourceMapDir, (0, utils_1.fileUrlToPathCrossPlatform)(source))); | ||
} | ||
else if (source.startsWith(importer_1.legacyImporterProtocol)) { | ||
return source.substring(importer_1.legacyImporterProtocol.length); | ||
} | ||
else if (source.startsWith('data:')) { | ||
@@ -228,11 +230,9 @@ return 'stdin'; | ||
.map(url => { | ||
if (url.protocol === 'file:') { | ||
return (0, utils_1.fileUrlToPathCrossPlatform)(url); | ||
} | ||
else if (url.protocol === importer_1.legacyImporterProtocol) { | ||
if (url.protocol === utils_2.legacyImporterProtocol) { | ||
return decodeURI(url.pathname); | ||
} | ||
else { | ||
return url.toString(); | ||
} | ||
const urlString = (0, utils_2.removeLegacyImporter)(url.toString()); | ||
return urlString.startsWith('file:') | ||
? (0, utils_1.fileUrlToPathCrossPlatform)(urlString) | ||
: urlString; | ||
}), | ||
@@ -245,3 +245,3 @@ }, | ||
function newLegacyException(error) { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
if (!(error instanceof exception_1.Exception)) { | ||
@@ -253,7 +253,8 @@ return Object.assign(error, { | ||
} | ||
const span = error.span ? (0, utils_2.removeLegacyImporterFromSpan)(error.span) : null; | ||
let file; | ||
if (!((_a = error.span) === null || _a === void 0 ? void 0 : _a.url)) { | ||
if (!(span === null || span === void 0 ? void 0 : span.url)) { | ||
file = 'stdin'; | ||
} | ||
else if (error.span.url.protocol === 'file:') { | ||
else if (span.url.protocol === 'file:') { | ||
// We have to cast to Node's URL type here because the specified type is the | ||
@@ -263,17 +264,18 @@ // standard URL type which is slightly less featureful. `fileURLToPath()` | ||
// generate Node URLs here regardless. | ||
file = (0, utils_1.fileUrlToPathCrossPlatform)(error.span.url); | ||
file = (0, utils_1.fileUrlToPathCrossPlatform)(span.url); | ||
} | ||
else { | ||
file = error.span.url.toString(); | ||
file = span.url.toString(); | ||
} | ||
const errorString = (0, utils_2.removeLegacyImporter)(error.toString()); | ||
return Object.assign(new Error(), { | ||
status: 1, | ||
message: error.toString().replace(/^Error: /, ''), | ||
formatted: error.toString(), | ||
toString: () => error.toString(), | ||
stack: error.stack, | ||
line: (0, utils_1.isNullOrUndefined)((_b = error.span) === null || _b === void 0 ? void 0 : _b.start.line) | ||
message: errorString.replace(/^Error: /, ''), | ||
formatted: errorString, | ||
toString: () => errorString, | ||
stack: error.stack ? (0, utils_2.removeLegacyImporter)(error.stack) : undefined, | ||
line: (0, utils_1.isNullOrUndefined)((_a = error.span) === null || _a === void 0 ? void 0 : _a.start.line) | ||
? undefined | ||
: error.span.start.line + 1, | ||
column: (0, utils_1.isNullOrUndefined)((_c = error.span) === null || _c === void 0 ? void 0 : _c.start.column) | ||
column: (0, utils_1.isNullOrUndefined)((_b = error.span) === null || _b === void 0 ? void 0 : _b.start.column) | ||
? undefined | ||
@@ -280,0 +282,0 @@ : error.span.start.column + 1, |
{ | ||
"name": "sass-embedded", | ||
"version": "1.66.1", | ||
"version": "1.67.0", | ||
"protocol-version": "2.1.0", | ||
"compiler-version": "1.66.1", | ||
"compiler-version": "1.67.0", | ||
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol", | ||
@@ -34,10 +34,10 @@ "repository": "sass/embedded-host-node", | ||
"optionalDependencies": { | ||
"sass-embedded-darwin-arm64": "1.66.1", | ||
"sass-embedded-darwin-x64": "1.66.1", | ||
"sass-embedded-linux-arm": "1.66.1", | ||
"sass-embedded-linux-arm64": "1.66.1", | ||
"sass-embedded-linux-ia32": "1.66.1", | ||
"sass-embedded-linux-x64": "1.66.1", | ||
"sass-embedded-win32-ia32": "1.66.1", | ||
"sass-embedded-win32-x64": "1.66.1" | ||
"sass-embedded-darwin-arm64": "1.67.0", | ||
"sass-embedded-darwin-x64": "1.67.0", | ||
"sass-embedded-linux-arm": "1.67.0", | ||
"sass-embedded-linux-arm64": "1.67.0", | ||
"sass-embedded-linux-ia32": "1.67.0", | ||
"sass-embedded-linux-x64": "1.67.0", | ||
"sass-embedded-win32-ia32": "1.67.0", | ||
"sass-embedded-win32-x64": "1.67.0" | ||
}, | ||
@@ -44,0 +44,0 @@ "dependencies": { |
{ | ||
"name": "sass-embedded", | ||
"version": "1.66.1", | ||
"version": "1.67.0", | ||
"protocol-version": "2.1.0", | ||
"compiler-version": "1.66.1", | ||
"compiler-version": "1.67.0", | ||
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol", | ||
@@ -34,10 +34,10 @@ "repository": "sass/embedded-host-node", | ||
"optionalDependencies": { | ||
"sass-embedded-darwin-arm64": "1.66.1", | ||
"sass-embedded-darwin-x64": "1.66.1", | ||
"sass-embedded-linux-arm": "1.66.1", | ||
"sass-embedded-linux-arm64": "1.66.1", | ||
"sass-embedded-linux-ia32": "1.66.1", | ||
"sass-embedded-linux-x64": "1.66.1", | ||
"sass-embedded-win32-ia32": "1.66.1", | ||
"sass-embedded-win32-x64": "1.66.1" | ||
"sass-embedded-darwin-arm64": "1.67.0", | ||
"sass-embedded-darwin-x64": "1.67.0", | ||
"sass-embedded-linux-arm": "1.67.0", | ||
"sass-embedded-linux-arm64": "1.67.0", | ||
"sass-embedded-linux-ia32": "1.67.0", | ||
"sass-embedded-linux-x64": "1.67.0", | ||
"sass-embedded-win32-ia32": "1.67.0", | ||
"sass-embedded-win32-x64": "1.67.0" | ||
}, | ||
@@ -44,0 +44,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
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
654886
132
11471