querysub 0.7.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
|
@@ -158,10 +158,29 @@ let moduleResolver = async (spec: FunctionSpec) => {
|
|
|
158
158
|
};
|
|
159
159
|
|
|
160
160
|
export function isDynamicModule(module: NodeJS.Module): boolean {
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
return isDynamicModulePath(module.filename);
|
|
162
|
+
}
|
|
163
|
+
export function isDynamicModulePath(path: string): boolean {
|
|
164
|
+
let parts = path.replaceAll("\\", "/").split("/");
|
|
163
165
|
return parts.includes("node_modules") || parts.includes("synced_repos");
|
|
164
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;
|
|
183
|
+
}
|
|
165
184
|
|
|
166
185
|
async function getModuleFromSpecBase(
|
|
167
186
|
spec: FunctionSpec
|
|
@@ -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 { isDynamicModule } from "../3-path-functions/pathFunctionLoader";
|
|
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
|
}
|