Skip to content

Commit a7e718c

Browse files
committed
avoid mutating original repository files
1 parent 3d859a8 commit a7e718c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,11 @@ export class DataSchemaCompiler {
217217
this.pythonContext = await this.loadPythonContext(files, 'globals.py');
218218
this.yamlCompiler.initFromPythonContext(this.pythonContext);
219219

220-
const toCompile = this.filesToCompile?.length
221-
? files.filter(f => this.filesToCompile.includes(f.fileName))
222-
: files;
220+
// As we mutate files data, we need a copy, not a refs.
221+
// FileContent is a plain object with primitives, so it's enough for a shallow copy.
222+
let toCompile = this.filesToCompile?.length
223+
? files.filter(f => this.filesToCompile.includes(f.fileName)).map(f => ({ ...f }))
224+
: files.map(f => ({ ...f }));
223225

224226
const jinjaTemplatedFiles = toCompile.filter((file) => file.fileName.endsWith('.jinja') ||
225227
(file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml')) && file.content.match(JINJA_SYNTAX));
@@ -436,6 +438,7 @@ export class DataSchemaCompiler {
436438
compiledFiles = {};
437439
asyncModules = [];
438440
transpiledFiles = [];
441+
toCompile = [];
439442

440443
if (transpilationNative) {
441444
// Clean up cache

0 commit comments

Comments
 (0)