Skip to content

Commit 6d6a25e

Browse files
committed
Exported objects are now globalized
1 parent c9c8ce4 commit 6d6a25e

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

core/Run.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace Moduless
7777
function getGraphFromDependencies(projectPath: string)
7878
{
7979
const graph = new ProjectGraph(projectPath);
80-
const out: { project: Project; export: object; }[] = [];
80+
const out: { project: Project; exported: object; }[] = [];
8181

8282
for (const project of graph.eachProject())
8383
{
@@ -89,10 +89,9 @@ namespace Moduless
8989

9090
try
9191
{
92-
const exp = require(project.outFile);
93-
94-
if (exp && typeof exp === "object" && !Array.isArray(exp))
95-
out.push({ project, export: exp });
92+
const ex = require(project.outFile);
93+
if (ex && typeof ex === "object" && !Array.isArray(ex))
94+
out.push({ project, exported: ex });
9695
}
9796
catch (e)
9897
{
@@ -116,6 +115,24 @@ namespace Moduless
116115
if (!startingProject)
117116
throw new Error("No projects found at location: " + target.projectPath);
118117

118+
// Globalize the exports of all projects.
119+
for (const { project, exported } of graph)
120+
{
121+
for (const [name, value] of Object.entries(exported))
122+
{
123+
if (name in globalThis)
124+
{
125+
console.warn(
126+
`Skipping adding ${name} from ${project.projectPath} to global scope ` +
127+
`because another member with this name is already defined globally.`);
128+
129+
continue;
130+
}
131+
132+
(globalThis as any)[name] = value;
133+
}
134+
}
135+
119136
const tryResolveNamepace = (root: object) =>
120137
{
121138
let current: any = root;
@@ -132,7 +149,7 @@ namespace Moduless
132149
};
133150

134151
const namespaceObject =
135-
tryResolveNamepace(startingProject.export) ||
152+
tryResolveNamepace(startingProject.exported) ||
136153
globalThis;
137154

138155
const covers = (() =>

0 commit comments

Comments
 (0)