Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (source, resourceId) => {
let importPath = TemplateExtensions.normalizePath(resourceId);
if (!path.isAbsolute(importPath)) {
// get full path for importPath relative to path which is doing the import.
importPath = TemplateExtensions.normalizePath(path.join(path.dirname(source), importPath));
}
var targetImportPath = importPath.replace('.lg', `.${locale}.lg`);
// user can do some customized fallback here
if (!fs.existsSync(targetImportPath) || !fs.statSync(targetImportPath).isFile()) {
// fallback to itself
if (!fs.existsSync(importPath) || !fs.statSync(importPath).isFile()) {
throw Error(`Could not find file: ${ importPath }`);
}
} else {
importPath = targetImportPath;
}
const content = fs.readFileSync(importPath, 'utf-8');
return { content, id: importPath };
return (source, resourceId) => {
let importPath = TemplateExtensions.normalizePath(resourceId);
if (!path.isAbsolute(importPath)) {
// get full path for importPath relative to path which is doing the import.
importPath = TemplateExtensions.normalizePath(path.join(path.dirname(source), importPath));
}
var targetImportPath = importPath.replace('.lg', `.${locale}.lg`);
// user can do some customized fallback here
if (!fs.existsSync(targetImportPath) || !fs.statSync(targetImportPath).isFile()) {
// fallback to itself
if (!fs.existsSync(importPath) || !fs.statSync(importPath).isFile()) {
throw Error(`Could not find file: ${ importPath }`);
}
} else {
importPath = targetImportPath;
}