Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function tryRequire(tryPath: string) {
try {
// Require from CWD
return importCwd(tryPath);
} catch (error) {
// if we try to actually require npm we will import something that is the actual npm API
// not the plugin that we want
if (tryPath === 'npm') {
return;
}
try {
// Require from __dirname. Needed for npx and global installs
return require(tryPath);
} catch (error) {}
}
}
return new Promise((resolve, reject) => {
const sass = importCwd.silent('node-sass') || importCwd.silent('sass')
if (!sass) {
throw new Error(
`You need to install either node-sass or sass in order to process Sass files`
)
}
const render = pify(sass.render.bind(sass))
return workQueue.add(() =>
render({
...this.options,
file: this.id,
data: `@import "${injectFile.replace(/\\/g, '\\\\')}";` + code,
indentedSyntax: /\.sass$/.test(this.id),
sourceMap: this.sourceMap,
importer: [
(url, importer, done) => {
if (!moduleRe.test(url)) return done({ file: url })
return new Promise((resolve, reject) => {
const sass = importCwd.silent('node-sass') || importCwd.silent('sass')
if (!sass) {
throw new Error(`You need to install either node-sass or sass in order to process Sass files`)
}
const render = pify(sass.render.bind(sass))
return workQueue.add(() =>
render({
...this.options,
file: this.id,
data: code,
indentedSyntax: /\.sass$/.test(this.id),
sourceMap: this.sourceMap,
importer: [
(url, importer, done) => {
if (!moduleRe.test(url)) return done({ file: url })
const moduleUrl = url.slice(1)
const safeGetModule = name => {
let found = importCwd.silent(name);
if (!found) {
try {
found = require(name);
} catch (err) {
found = null;
}
}
return found;
};
function tryRequire(name) {
const found = importCwd.silent(name);
if (!found) {
return require(`${name}`);
}
return found;
}
const safeGetModule = name => {
let found = importCwd.silent(name);
if (!found) {
try {
found = require(name);
} catch (err) {
found = null;
}
}
return found;
};
function ensurePostCSSOption(option) {
return typeof option === 'string' ? importCwd(option) : option
}