esbuild-sass-plugin
Advanced tools
Comparing version 1.4.4 to 1.4.5
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createSassImporter = void 0; | ||
const resolve_1 = __importDefault(require("resolve")); | ||
const utils_1 = require("./utils"); | ||
const path_1 = require("path"); | ||
const fs_1 = require("fs"); | ||
const utils_1 = require("./utils"); | ||
function findModuleDirectory(basedir) { | ||
const root = path_1.parse(basedir).root; | ||
do { | ||
const path = path_1.join(basedir, "node_modules"); | ||
if (fs_1.existsSync(path)) { | ||
return path; | ||
function createSassImporter({ basedir = process.cwd() }) { | ||
const opts = { basedir, extensions: [".scss", ".sass", ".css"] }; | ||
return function importer(url, prev) { | ||
if (url.startsWith("~")) { | ||
const pathname = resolve_1.default.sync(url.slice(1), opts); | ||
return { file: utils_1.moduleRelativeUrl(path_1.posix.dirname(prev), pathname) }; | ||
} | ||
else { | ||
basedir = path_1.dirname(basedir); | ||
return { file: url }; | ||
} | ||
} while (basedir !== root); | ||
} | ||
function createSassImporter({ basedir = process.cwd() }) { | ||
const moduleDirectory = findModuleDirectory(basedir); | ||
if (!moduleDirectory) { | ||
console.log("unable to find 'node_modules' in: " + basedir); | ||
} | ||
return function importer(url, prev) { | ||
const relativeBaseUrl = utils_1.moduleRelativeUrl(path_1.posix.dirname(prev), moduleDirectory); | ||
return { file: url.replace(/^~/, relativeBaseUrl) }; | ||
}; | ||
@@ -28,0 +21,0 @@ } |
@@ -17,5 +17,5 @@ "use strict"; | ||
let url = path_1.relative(basedir, pathname).replace(/\\/g, "/"); | ||
return /^\.\.?\//.test(url) ? `${url}/` : `./${url}/`; | ||
return /^\.\.?\//.test(url) ? url : `./${url}`; | ||
} | ||
exports.moduleRelativeUrl = moduleRelativeUrl; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "esbuild-sass-plugin", | ||
"version": "1.4.4", | ||
"version": "1.4.5", | ||
"description": "esbuild plugin for sass/scss files supporting both css loader and css result import (lit-element)", | ||
@@ -57,2 +57,3 @@ "main": "lib/index.js", | ||
"picomatch": "^2.3.0", | ||
"resolve": "^1.20.0", | ||
"sass": "^1.34.0" | ||
@@ -65,2 +66,3 @@ }, | ||
"@types/node": "^15.6.1", | ||
"@types/resolve": "^1.20.0", | ||
"@types/sass": "^1.16.0", | ||
@@ -67,0 +69,0 @@ "chai": "^4.3.4", |
import {SassPluginOptions} from "./index"; | ||
import {dirname, join, parse, posix} from "path"; | ||
import {existsSync} from "fs"; | ||
import resolve from "resolve"; | ||
import {moduleRelativeUrl} from "./utils"; | ||
import {posix} from "path"; | ||
function findModuleDirectory(basedir: string) { | ||
const root = parse(basedir).root; | ||
do { | ||
const path = join(basedir, "node_modules"); | ||
if (existsSync(path)) { | ||
return path; | ||
} else { | ||
basedir = dirname(basedir); | ||
} | ||
} while (basedir !== root); | ||
} | ||
export function createSassImporter({basedir = process.cwd()}: SassPluginOptions) { | ||
const moduleDirectory = findModuleDirectory(basedir); | ||
if (!moduleDirectory) { | ||
console.log("unable to find 'node_modules' in: " + basedir); | ||
} | ||
const opts = {basedir, extensions: [".scss", ".sass", ".css"]}; | ||
return function importer(url, prev) { | ||
const relativeBaseUrl = moduleRelativeUrl(posix.dirname(prev), moduleDirectory); | ||
return {file: url.replace(/^~/, relativeBaseUrl!)}; | ||
if (url.startsWith("~")) { | ||
const pathname = resolve.sync(url.slice(1), opts); | ||
return {file: moduleRelativeUrl(posix.dirname(prev), pathname)}; | ||
} else { | ||
return {file: url}; | ||
} | ||
} | ||
} |
@@ -15,4 +15,4 @@ import {relative} from "path"; | ||
let url = relative(basedir, pathname).replace(/\\/g, "/"); | ||
return /^\.\.?\//.test(url) ? `${url}/` : `./${url}/`; | ||
return /^\.\.?\//.test(url) ? url : `./${url}`; | ||
} | ||
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
4
41894
4
12
19
612
+ Addedresolve@^1.20.0
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)