querysub 0.4.0 → 0.6.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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "querysub",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node-forge": "https://github.com/sliftist/forge#e618181b469b07bdc70b968b0391beb8ef5fecd6",
|
|
25
25
|
"pako": "^2.1.0",
|
|
26
26
|
"preact": "^10.11.3",
|
|
27
|
-
"socket-function": "^0.
|
|
27
|
+
"socket-function": "^0.33.0",
|
|
28
28
|
"terser": "^5.31.0",
|
|
29
29
|
"typesafecss": "^0.6.3",
|
|
30
30
|
"yaml": "^2.5.0",
|
|
@@ -17,6 +17,7 @@ import { getPathStr2, getPathStr3 } from "../path";
|
|
|
17
17
|
import { consistentHash } from "../misc/hash";
|
|
18
18
|
import { setExternalHotReloading } from "socket-function/hot/HotReloadController";
|
|
19
19
|
import { isPublic } from "../config";
|
|
20
|
+
import { SocketFunction } from "socket-function/SocketFunction";
|
|
20
21
|
|
|
21
22
|
// Get localPathRemappings using yargs, so it is easy to configure in multiple entry points
|
|
22
23
|
let yargObj = isNodeTrue() && yargs(process.argv)
|
|
@@ -119,11 +120,6 @@ export function setGitURLMapping(config: {
|
|
|
119
120
|
|
|
120
121
|
/** spec => path that we can use with require */
|
|
121
122
|
let moduleResolver = async (spec: FunctionSpec) => {
|
|
122
|
-
//todonext;
|
|
123
|
-
// I think the cloning isn't working?
|
|
124
|
-
debugbreak(2);
|
|
125
|
-
debugger;
|
|
126
|
-
|
|
127
123
|
let gitURL = spec.gitURL;
|
|
128
124
|
let urlForPath = gitURL;
|
|
129
125
|
|
|
@@ -141,25 +137,40 @@ let moduleResolver = async (spec: FunctionSpec) => {
|
|
|
141
137
|
if (urlForPath.endsWith(".git")) {
|
|
142
138
|
urlForPath = urlForPath.slice(0, -".git".length);
|
|
143
139
|
}
|
|
144
|
-
let repoPath = getSubFolder("synced_repos") + urlForPath + "/" + spec.gitRef;
|
|
140
|
+
let repoPath = getSubFolder("synced_repos") + urlForPath + "/" + spec.gitRef + "/";
|
|
145
141
|
if (!fs.existsSync(repoPath)) {
|
|
146
142
|
await executeCommand("git", ["clone", gitURL, repoPath]);
|
|
147
143
|
await executeCommand("git", ["reset", "--hard", spec.gitRef], { cwd: repoPath });
|
|
148
144
|
}
|
|
149
145
|
if (!fs.existsSync(repoPath + "node_modules")) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
146
|
+
await executeCommand("yarn", ["install"], { cwd: repoPath });
|
|
147
|
+
}
|
|
148
|
+
let querysubPath = repoPath + "node_modules/querysub";
|
|
149
|
+
if (fs.existsSync(querysubPath)) {
|
|
150
|
+
// By moving querysub, it forces the repo to use the parent querysub. This is nice, as it even
|
|
151
|
+
// works when this code is required clientside!
|
|
152
|
+
// - Recursive deletes are slow, but moving is fast, so just move it. This repos don't update anyways
|
|
153
|
+
// (we have one per hash), so it's not this will fill up with moved files.
|
|
154
|
+
await fs.promises.rename(querysubPath, querysubPath + "_" + Date.now());
|
|
153
155
|
}
|
|
156
|
+
|
|
154
157
|
return repoPath;
|
|
155
158
|
};
|
|
156
159
|
|
|
160
|
+
let key = "isInNestedImport-302fec38-0443-44f7-b31f-1f514900437f";
|
|
161
|
+
function setInNestedImport(value: boolean) {
|
|
162
|
+
(globalThis as any)[key] = value;
|
|
163
|
+
}
|
|
164
|
+
export function isInNestedImport(): boolean {
|
|
165
|
+
return !!(globalThis as any)[key];
|
|
166
|
+
}
|
|
157
167
|
|
|
158
168
|
async function getModuleFromSpecBase(
|
|
159
169
|
spec: FunctionSpec
|
|
160
170
|
): Promise<NodeJS.Module> {
|
|
161
171
|
let hotReloadPackagePath = "";
|
|
162
172
|
let path = gitURLRefMappings.get(getSpecKey(spec));
|
|
173
|
+
let deployPath = "";
|
|
163
174
|
if (!path) {
|
|
164
175
|
// Sync the git repo, `yarn install --ignore-scripts`, require the path, get the export, and then return that function.
|
|
165
176
|
let packagePath = getLocalPathRemapping()[spec.gitURL];
|
|
@@ -177,14 +188,24 @@ async function getModuleFromSpecBase(
|
|
|
177
188
|
specFilePath = specFilePath.slice(1);
|
|
178
189
|
}
|
|
179
190
|
path = packagePath + specFilePath;
|
|
191
|
+
deployPath = packagePath + "deploy.ts";
|
|
180
192
|
}
|
|
181
193
|
console.log(blue(`require(${JSON.stringify(path)})`));
|
|
182
194
|
try {
|
|
183
|
-
|
|
184
|
-
await (
|
|
195
|
+
setInNestedImport(true);
|
|
196
|
+
await SocketFunction.ignoreExposeCalls(async () => {
|
|
197
|
+
// Import deploy, which should always exist, and provides a consistent
|
|
198
|
+
// import order, fixing a lot of cyclic / module level code logic issues.
|
|
199
|
+
if (deployPath) {
|
|
200
|
+
await (require as any)(deployPath, true);
|
|
201
|
+
}
|
|
202
|
+
// NOTE: The true tells require to not warn about the async loading
|
|
203
|
+
await (require as any)(path, true);
|
|
204
|
+
});
|
|
185
205
|
} catch (e: any) {
|
|
186
|
-
|
|
187
206
|
throw new Error(`Error when loading function for ${JSON.stringify(path)}:${spec.FunctionId}\n${e.stack}`);
|
|
207
|
+
} finally {
|
|
208
|
+
setInNestedImport(false);
|
|
188
209
|
}
|
|
189
210
|
let moduleId = require.resolve(path) || path;
|
|
190
211
|
let module = require.cache[moduleId];
|
|
@@ -16,6 +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 { isInNestedImport } from "../3-path-functions/pathFunctionLoader";
|
|
19
20
|
|
|
20
21
|
// Map, so hot reloading doesn't break things
|
|
21
22
|
let componentButtons = new Map<string, { title: string, callback: (component: ExternalRenderClass) => void }>();
|
|
@@ -24,6 +25,7 @@ export function addComponentButton(config: {
|
|
|
24
25
|
title: string;
|
|
25
26
|
callback: (component: ExternalRenderClass) => void;
|
|
26
27
|
}) {
|
|
28
|
+
if (isInNestedImport()) return;
|
|
27
29
|
if (!isHotReloading() && componentButtons.has(config.title)) {
|
|
28
30
|
throw new Error(`Component button with title ${config.title} already exists`);
|
|
29
31
|
}
|