querysub 0.4.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.4.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.32.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,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
- // NOTE: `--ignore-scripts` to make installing faster, as presently a slow install step will cause functions
151
- // after a new deploy to timeout for a bit.
152
- await executeCommand("yarn", ["install", "--ignore-scripts"], { cwd: repoPath });
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
- // NOTE: The true tells require to not warn about the async loading
184
- await (require as any)(path, true);
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}`);