Skip to content

Commit

Permalink
skip absolute paths in module reading
Browse files Browse the repository at this point in the history
  • Loading branch information
metelkin committed Jan 13, 2025
1 parent 7c210fe commit 70ee9d8
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/module-system/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,28 @@ class ModuleSystem {

// update by abs paths
let absDirPath = path.dirname(filename);
parsed

// push to moduleCollection
let moduleName = [filename, '#', options.sheet || '0'].join('');
this.moduleCollection[moduleName] = parsed;
// set in graph
let includePaths = parsed
.filter((q) => q.action==='include')
.forEach((q) => {
if (typeof q.source !== 'string') {
throw new TypeError(`Property "source" in "${filename}" must be string`);
}
.filter((q) => {
if (path.isAbsolute(q.source)) {
this.logger.error(
`include statement does not suport absolute path in "${filename}", got "${q.source}".`,
{type: 'ModuleError', filename: filename}
);
//throw new HetaLevelError('Absolute path in include statement');
q.source = '';
return false;
}
// update source
q.source = path.join(absDirPath, q.source);
});

// push to moduleCollection
let moduleName = [filename, '#', options.sheet || '0'].join('');
this.moduleCollection[moduleName] = parsed;
// set in graph
let paths = parsed
.filter((q) => q.action==='include')
return true;
})
.map((x) => [x.source, '#', x.sheet || 0].join(''));
this.graph.add(moduleName, paths);
this.graph.add(moduleName, includePaths);

return parsed;
}
Expand All @@ -131,6 +128,11 @@ class ModuleSystem {
let tabNum = options.sheet !== undefined ? ('#' + options.sheet) : ''; // for xlsx only
this.logger.info(`Reading module of type "${type}" from file "${filename}${tabNum}"...`);

if (!filename) { // in case of empty filename or absolute path
//this.logger.error(`No filename set for include of type "${type}"`, {type: 'ModuleError', filename: filename});
return [];
}

// run loader
let loader = moduleLoaders[type];
if (loader === undefined) {
Expand Down Expand Up @@ -193,7 +195,7 @@ class ModuleSystem {
let childIntegrated = this.moduleCollection[moduleName]._integrated;
let composition = compose(current, childIntegrated);
acc = acc.concat(composition);
}else{
} else {
acc.push(current);
}
return acc;
Expand All @@ -211,7 +213,7 @@ class ModuleSystem {
*
* @returns {object} merged Q-array.
*/
function compose(obj, arr) {
function compose(obj, arr = []) {
let {action, id, source, type, sheet, ...cleanedObj} = obj;
delete cleanedObj.class;

Expand Down

0 comments on commit 70ee9d8

Please sign in to comment.