querysub 0.3.0 → 0.5.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.5.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",
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import { getStorageDir, getSubFolder } from "../fs";
|
|
2
2
|
import { Archives } from "./archives";
|
|
3
|
-
import { diskEscapeFileName, getArchivesLocal } from "./archivesDisk";
|
|
4
3
|
import fs from "fs";
|
|
5
4
|
|
|
6
|
-
import
|
|
7
|
-
import { binarySearchBasic, binarySearchIndex, list, nextId, sort, timeInHour, timeInMinute } from "socket-function/src/misc";
|
|
5
|
+
import { list, nextId, timeInHour, timeInMinute } from "socket-function/src/misc";
|
|
8
6
|
import { cache, lazy } from "socket-function/src/caching";
|
|
9
|
-
import {
|
|
7
|
+
import { runInSerial, runInfinitePoll } from "socket-function/src/batching";
|
|
10
8
|
import { sha256 } from "js-sha256";
|
|
11
|
-
import { devDebugbreak } from "../config";
|
|
12
9
|
import child_process from "child_process";
|
|
13
|
-
import os from "os";
|
|
14
|
-
import fsext, { flock } from "fs-ext";
|
|
15
|
-
import debugbreak from "debugbreak";
|
|
16
|
-
import readline from "readline";
|
|
17
10
|
import { getPPID } from "../misc/getParentProcessId";
|
|
18
11
|
import { Args } from "socket-function/src/types";
|
|
19
12
|
import { getArchivesBackblaze } from "./archivesBackBlaze";
|
|
20
|
-
import {
|
|
21
|
-
import { formatNumber, formatTime } from "socket-function/src/formatting/format";
|
|
13
|
+
import { formatNumber } from "socket-function/src/formatting/format";
|
|
22
14
|
import { SizeLimiter } from "../diagnostics/SizeLimiter";
|
|
23
15
|
|
|
24
16
|
const SIZE_LIMIT = new SizeLimiter({
|
|
@@ -702,6 +694,7 @@ async function isLocked(path: string, operation?: {
|
|
|
702
694
|
return await lockRetryLoop(async function isLocked() {
|
|
703
695
|
let handle = await getHandle(lockPath);
|
|
704
696
|
try {
|
|
697
|
+
const { flock } = await import("fs-ext");
|
|
705
698
|
await new Promise<void>((r, e) => flock(handle.fd, "ex", err => err ? e(err) : r()));
|
|
706
699
|
let contents = (await handle.readFile()).toString();
|
|
707
700
|
let locks = contents.toString().replaceAll("\0", "").trim().split("\n").filter(x => x);
|
|
@@ -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,16 +137,23 @@ 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,6 +163,7 @@ async function getModuleFromSpecBase(
|
|
|
160
163
|
): Promise<NodeJS.Module> {
|
|
161
164
|
let hotReloadPackagePath = "";
|
|
162
165
|
let path = gitURLRefMappings.get(getSpecKey(spec));
|
|
166
|
+
let deployPath = "";
|
|
163
167
|
if (!path) {
|
|
164
168
|
// Sync the git repo, `yarn install --ignore-scripts`, require the path, get the export, and then return that function.
|
|
165
169
|
let packagePath = getLocalPathRemapping()[spec.gitURL];
|
|
@@ -177,11 +181,19 @@ async function getModuleFromSpecBase(
|
|
|
177
181
|
specFilePath = specFilePath.slice(1);
|
|
178
182
|
}
|
|
179
183
|
path = packagePath + specFilePath;
|
|
184
|
+
deployPath = packagePath + "deploy.ts";
|
|
180
185
|
}
|
|
181
186
|
console.log(blue(`require(${JSON.stringify(path)})`));
|
|
182
187
|
try {
|
|
183
|
-
|
|
184
|
-
|
|
188
|
+
await SocketFunction.ignoreExposeCalls(async () => {
|
|
189
|
+
// Import deploy, which should always exist, and provides a consistent
|
|
190
|
+
// import order, fixing a lot of cyclic / module level code logic issues.
|
|
191
|
+
if (deployPath) {
|
|
192
|
+
await (require as any)(deployPath, true);
|
|
193
|
+
}
|
|
194
|
+
// NOTE: The true tells require to not warn about the async loading
|
|
195
|
+
await (require as any)(path, true);
|
|
196
|
+
});
|
|
185
197
|
} catch (e: any) {
|
|
186
198
|
|
|
187
199
|
throw new Error(`Error when loading function for ${JSON.stringify(path)}:${spec.FunctionId}\n${e.stack}`);
|