querysub 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -157,12 +157,29 @@ let moduleResolver = async (spec: FunctionSpec) => {
|
|
|
157
157
|
return repoPath;
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
(globalThis as any)[key] = value;
|
|
160
|
+
export function isDynamicModule(module: NodeJS.Module): boolean {
|
|
161
|
+
return isDynamicModulePath(module.filename);
|
|
163
162
|
}
|
|
164
|
-
export function
|
|
165
|
-
|
|
163
|
+
export function isDynamicModulePath(path: string): boolean {
|
|
164
|
+
let parts = path.replaceAll("\\", "/").split("/");
|
|
165
|
+
return parts.includes("node_modules") || parts.includes("synced_repos");
|
|
166
|
+
}
|
|
167
|
+
/** Annoying, and slower than isDynamicModule, but... necessary. We can't expect the user to call isDynamicModule,
|
|
168
|
+
* and our functions will all resolve to the root on purpose, so... we need to check the callstack!
|
|
169
|
+
*/
|
|
170
|
+
export function isCallerDynamicModule(): boolean {
|
|
171
|
+
return getCallstackFiles().some(isDynamicModulePath);
|
|
172
|
+
}
|
|
173
|
+
function getCallstackFiles(): string[] {
|
|
174
|
+
let stack = new Error().stack;
|
|
175
|
+
if (!stack) return [];
|
|
176
|
+
let lines = stack.split("\n");
|
|
177
|
+
let files = lines.map(line => {
|
|
178
|
+
let match = line.match(/\(([^)]+)\)/);
|
|
179
|
+
if (!match) return "";
|
|
180
|
+
return match[1];
|
|
181
|
+
});
|
|
182
|
+
return files;
|
|
166
183
|
}
|
|
167
184
|
|
|
168
185
|
async function getModuleFromSpecBase(
|
|
@@ -192,7 +209,6 @@ async function getModuleFromSpecBase(
|
|
|
192
209
|
}
|
|
193
210
|
console.log(blue(`require(${JSON.stringify(path)})`));
|
|
194
211
|
try {
|
|
195
|
-
setInNestedImport(true);
|
|
196
212
|
await SocketFunction.ignoreExposeCalls(async () => {
|
|
197
213
|
// Import deploy, which should always exist, and provides a consistent
|
|
198
214
|
// import order, fixing a lot of cyclic / module level code logic issues.
|
|
@@ -204,8 +220,6 @@ async function getModuleFromSpecBase(
|
|
|
204
220
|
});
|
|
205
221
|
} catch (e: any) {
|
|
206
222
|
throw new Error(`Error when loading function for ${JSON.stringify(path)}:${spec.FunctionId}\n${e.stack}`);
|
|
207
|
-
} finally {
|
|
208
|
-
setInNestedImport(false);
|
|
209
223
|
}
|
|
210
224
|
let moduleId = require.resolve(path) || path;
|
|
211
225
|
let module = require.cache[moduleId];
|
|
@@ -49,6 +49,7 @@ import { devDebugbreak, getDomain, isDevDebugbreak, isNoNetwork, isPublic } from
|
|
|
49
49
|
import { hookErrors } from "../diagnostics/errorLogs/hookErrors";
|
|
50
50
|
import { Schema2, Schema2T, t } from "../2-proxy/schema2";
|
|
51
51
|
import { CALL_PERMISSIONS_KEY } from "./permissionsShared";
|
|
52
|
+
import { isDynamicModule } from "../3-path-functions/pathFunctionLoader";
|
|
52
53
|
|
|
53
54
|
export { t };
|
|
54
55
|
|
|
@@ -16,7 +16,7 @@ import { PathValueProxyWatcher } from "../2-proxy/PathValueProxyWatcher";
|
|
|
16
16
|
import { InputLabel, InputLabelURL } from "../library-components/InputLabel";
|
|
17
17
|
import { URLParam } from "../library-components/URLParam";
|
|
18
18
|
import { hotReloadingGuard, isHotReloading, onHotReload } from "socket-function/hot/HotReloadController";
|
|
19
|
-
import {
|
|
19
|
+
import { isCallerDynamicModule, isDynamicModule } from "../3-path-functions/pathFunctionLoader";
|
|
20
20
|
|
|
21
21
|
// Map, so hot reloading doesn't break things
|
|
22
22
|
let componentButtons = new Map<string, { title: string, callback: (component: ExternalRenderClass) => void }>();
|
|
@@ -25,7 +25,7 @@ export function addComponentButton(config: {
|
|
|
25
25
|
title: string;
|
|
26
26
|
callback: (component: ExternalRenderClass) => void;
|
|
27
27
|
}) {
|
|
28
|
-
if (
|
|
28
|
+
if (isCallerDynamicModule(module)) return;
|
|
29
29
|
if (!isHotReloading() && componentButtons.has(config.title)) {
|
|
30
30
|
throw new Error(`Component button with title ${config.title} already exists`);
|
|
31
31
|
}
|