@saltcorn/plugins-loader 1.6.0-beta.4 → 1.6.0-beta.6

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": "@saltcorn/plugins-loader",
3
- "version": "1.6.0-beta.4",
3
+ "version": "1.6.0-beta.6",
4
4
  "description": "Saltcorn plugin loader",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  "clean": "echo 'No TypeScript build'"
10
10
  },
11
11
  "dependencies": {
12
- "@saltcorn/data": "1.6.0-beta.4",
12
+ "@saltcorn/data": "1.6.0-beta.6",
13
13
  "env-paths": "^2.2.1",
14
14
  "npm-registry-fetch": "17.1.0",
15
15
  "https-proxy-agent": "^7.0.6"
@@ -11,7 +11,8 @@ const {
11
11
  } = require("./download_utils");
12
12
  const { getState } = require("@saltcorn/data/db/state");
13
13
  const Plugin = require("@saltcorn/data/models/plugin");
14
- const { rm, rename, cp, readFile, readdir } = require("fs").promises;
14
+ const { rm, rename, cp, readFile, readdir, readlink, unlink } =
15
+ require("fs").promises;
15
16
  const envPaths = require("env-paths");
16
17
  const semver = require("semver");
17
18
  const path = require("path");
@@ -57,9 +58,10 @@ const npmInstallNeeded = (oldPckJSON, newPckJSON) => {
57
58
 
58
59
  const defaultRootFolder = envPaths("saltcorn", { suffix: "plugins" }).data;
59
60
 
60
- // tracks local plugins already copied in this process
61
- // is only checked in the master process
61
+ // tracks plugins already installed in this process (master process only)
62
62
  const installedLocalPlugins = new Set();
63
+ const installedGitPlugins = new Set();
64
+ const installedGithubPlugins = new Set();
63
65
 
64
66
  /**
65
67
  * Find the most recently created localversion_<timestamp> directory for a local plugin.
@@ -266,9 +268,13 @@ class PluginInstaller {
266
268
  }
267
269
  break;
268
270
  case "github":
269
- if (this.force || !folderExists) {
271
+ if (
272
+ (this.force || !folderExists) &&
273
+ (!installedGithubPlugins.has(this.pluginDir) || this.reloadModule)
274
+ ) {
270
275
  getState().log(6, "downloading from github");
271
276
  await downloadFromGithub(this.plugin, this.rootFolder, this.tempDir);
277
+ installedGithubPlugins.add(this.pluginDir);
272
278
  wasLoaded = true;
273
279
  }
274
280
  break;
@@ -287,10 +293,14 @@ class PluginInstaller {
287
293
  }
288
294
  break;
289
295
  case "git":
290
- if (this.force || !folderExists) {
296
+ if (
297
+ (this.force || !folderExists) &&
298
+ (!installedGitPlugins.has(this.pluginDir) || this.reloadModule)
299
+ ) {
291
300
  getState().log(6, "downloading from git");
292
301
  await gitPullOrClone(this.plugin, this.tempDir);
293
302
  this.pckJsonPath = join(this.pluginDir, "package.json");
303
+ installedGitPlugins.add(this.pluginDir);
294
304
  wasLoaded = true;
295
305
  }
296
306
  break;
@@ -308,8 +318,19 @@ class PluginInstaller {
308
318
  const symLinkSrc = (await isGitCheckout())
309
319
  ? join(__dirname, "..", "..", "node_modules")
310
320
  : join(dirname(require.resolve("@saltcorn/cli")), "..", "node_modules");
311
- if (!(await pathExists(symLinkDst)))
321
+ if (await pathExists(symLinkDst)) {
322
+ const currentTarget = await readlink(symLinkDst).catch(() => null);
323
+ if (currentTarget !== symLinkSrc) {
324
+ await unlink(symLinkDst);
325
+ await symlink(
326
+ symLinkSrc,
327
+ symLinkDst,
328
+ !isWindows ? "dir" : "junction"
329
+ );
330
+ }
331
+ } else {
312
332
  await symlink(symLinkSrc, symLinkDst, !isWindows ? "dir" : "junction");
333
+ }
313
334
  };
314
335
  for (const folder of ["plugins_folder", "git_plugins"])
315
336
  await ensureFn(folder);