@saltcorn/plugins-loader 1.0.0-beta.13 → 1.0.0-beta.14

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/download_utils.js CHANGED
@@ -2,7 +2,7 @@ const fs = require("fs");
2
2
  const { rm } = require("fs").promises;
3
3
  const { mkdir, pathExists } = require("fs-extra");
4
4
  const { tmpName } = require("tmp-promise");
5
- const { execSync } = require("child_process");
5
+ const { execFileSync } = require("child_process");
6
6
  const { extract } = require("tar");
7
7
  const { join } = require("path");
8
8
  const { createWriteStream, unlink } = require("fs");
@@ -93,7 +93,10 @@ const loadTarball = (rootFolder, url, name) => {
93
93
  */
94
94
  const gitPullOrClone = async (plugin, pluginDir) => {
95
95
  let keyfnm,
96
- setKey = `-c core.sshCommand="ssh -oBatchMode=yes -o 'StrictHostKeyChecking no'" `;
96
+ setKey = [
97
+ "-c",
98
+ `core.sshCommand="ssh -oBatchMode=yes -o 'StrictHostKeyChecking no'"`,
99
+ ];
97
100
  if (plugin.deploy_private_key) {
98
101
  keyfnm = await tmpName();
99
102
  await fs.promises.writeFile(
@@ -104,12 +107,15 @@ const gitPullOrClone = async (plugin, pluginDir) => {
104
107
  encoding: "ascii",
105
108
  }
106
109
  );
107
- setKey = `-c core.sshCommand="ssh -oBatchMode=yes -o 'StrictHostKeyChecking no' -i ${keyfnm}" `;
110
+ setKey = [
111
+ "-c",
112
+ `core.sshCommand="ssh -oBatchMode=yes -o 'StrictHostKeyChecking no' -i ${keyfnm}"`,
113
+ ];
108
114
  }
109
115
  if (fs.existsSync(pluginDir)) {
110
- execSync(`git ${setKey} -C ${pluginDir} pull`);
116
+ execFileSync("git", [...setKey, "-C", pluginDir, "pull"]);
111
117
  } else {
112
- execSync(`git ${setKey} clone ${plugin.location} ${pluginDir}`);
118
+ execFileSync("git", [...setKey, "clone", plugin.location, pluginDir]);
113
119
  }
114
120
  if (plugin.deploy_private_key && keyfnm) await fs.promises.unlink(keyfnm);
115
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/plugins-loader",
3
- "version": "1.0.0-beta.13",
3
+ "version": "1.0.0-beta.14",
4
4
  "description": "Saltcorn plugin loader",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "env-paths": "^2.2.0",
13
13
  "npm-registry-fetch": "17.1.0",
14
- "@saltcorn/data": "1.0.0-beta.13"
14
+ "@saltcorn/data": "1.0.0-beta.14"
15
15
  },
16
16
  "author": "Christian Hugo",
17
17
  "license": "MIT",
@@ -27,10 +27,10 @@ const readPackageJson = async (filePath) => {
27
27
  };
28
28
 
29
29
  const npmInstallNeeded = (oldPckJSON, newPckJSON) => {
30
- const oldDeps = oldPckJSON.dependencies || {};
31
- const oldDevDeps = oldPckJSON.devDependencies || {};
32
- const newDeps = newPckJSON.dependencies || {};
33
- const newDevDeps = newPckJSON.devDependencies || {};
30
+ const oldDeps = oldPckJSON.dependencies || Object.create(null);
31
+ const oldDevDeps = oldPckJSON.devDependencies || Object.create(null);
32
+ const newDeps = newPckJSON.dependencies || Object.create(null);
33
+ const newDevDeps = newPckJSON.devDependencies || Object.create(null);
34
34
  return (
35
35
  JSON.stringify(oldDeps) !== JSON.stringify(newDeps) ||
36
36
  JSON.stringify(oldDevDeps) !== JSON.stringify(newDevDeps)
@@ -38,7 +38,7 @@ const npmInstallNeeded = (oldPckJSON, newPckJSON) => {
38
38
  };
39
39
 
40
40
  class PluginInstaller {
41
- constructor(plugin, opts = {}) {
41
+ constructor(plugin, opts = Object.create(null)) {
42
42
  this.plugin = plugin;
43
43
  this.rootFolder =
44
44
  opts.rootFolder || envPaths("saltcorn", { suffix: "plugins" }).data;
@@ -22,10 +22,10 @@ const doCheck = (pluginVersion, versionInfos, scVersion) => {
22
22
 
23
23
  /**
24
24
  * check if 'pluginVersion' is supported or find the latest supported version
25
- * @param {*} pluginVersion - wanted version
26
- * @param {*} versionInfos - version infos from the npm registry (resembles the package.json version).
25
+ * @param pluginVersion - wanted version
26
+ * @param versionInfos - version infos from the npm registry (resembles the package.json version).
27
27
  * Here you'll find the engines.saltcorn property.
28
- * @param {*} scVersion - saltcorn version
28
+ * @param scVersion - optional saltcorn version (if not set it will be taken from the state)
29
29
  * @returns
30
30
  */
31
31
  const supportedVersion = (
@@ -35,14 +35,15 @@ const supportedVersion = (
35
35
  ) => {
36
36
  const resolved =
37
37
  pluginVersion === "latest" ? resolveLatest(versionInfos) : pluginVersion;
38
- if (doCheck(resolved, versionInfos, scVersion)) return resolved;
38
+ const safeScVersion = scVersion || getState().scVersion;
39
+ if (doCheck(resolved, versionInfos, safeScVersion)) return resolved;
39
40
  else {
40
41
  const keys = Object.keys(versionInfos);
41
42
  keys.sort((a, b) => semver.rcompare(b, a));
42
43
  // iterate in reverse order to get the latest version
43
44
  for (let i = keys.length - 1; i >= 0; i--) {
44
45
  const version = keys[i];
45
- if (doCheck(version, versionInfos, scVersion)) return version;
46
+ if (doCheck(version, versionInfos, safeScVersion)) return version;
46
47
  }
47
48
  return null;
48
49
  }
@@ -54,21 +55,21 @@ const supportedVersion = (
54
55
  * @param scEngine - version infos from the npm registry (resembles the package.json version)
55
56
  * Here you'll find the engines.saltcorn property.
56
57
  * If versionInfos is a string, it will be treated as the engines.saltcorn property.
57
- * @param scVersion - optional saltcorn version (if not set it will be taken from the package.json)
58
+ * @param scVersion - optional saltcorn version (if not set it will be taken from the state)
58
59
  */
59
60
  const isVersionSupported = (pluginVersion, scEngine, scVersion) => {
60
61
  const safeInfos =
61
62
  typeof scEngine === "string"
62
63
  ? { [pluginVersion]: { engines: scEngine } }
63
64
  : scEngine;
64
- const safeScVersion = scVersion || require("package.json").version;
65
+ const safeScVersion = scVersion || getState().scVersion;
65
66
  return doCheck(pluginVersion, safeInfos, safeScVersion);
66
67
  };
67
68
 
68
69
  /**
69
70
  * check if 'scVersion' fullfilles 'scEngine'
70
71
  * @param scEngine fixed version or range of saltcorn versions (e.g. ">=1.0.0")
71
- * @param scVersion optional saltcorn version (if not set it will be taken from the package.json)
72
+ * @param scVersion optional saltcorn version (if not set it will be taken from the state)
72
73
  * @returns true if the saltcorn version fullfilles scEngine
73
74
  */
74
75
  const isEngineSatisfied = (scEngine, scVersion) => {
@@ -77,7 +78,7 @@ const isEngineSatisfied = (scEngine, scVersion) => {
77
78
  getState().log(4, `invalid engine property: ${scEngine}`);
78
79
  return true;
79
80
  }
80
- const safeScVersion = scVersion || require("package.json").version;
81
+ const safeScVersion = scVersion || getState().scVersion;
81
82
  if (semver.valid(safeScVersion) === null) {
82
83
  getState().log(4, `invalid saltcorn version: ${scVersion}`);
83
84
  return true;
@@ -87,7 +88,7 @@ const isEngineSatisfied = (scEngine, scVersion) => {
87
88
 
88
89
  /**
89
90
  * change latest to the actual version
90
- * @param versionInfos - version infos from the npm registry (resembles the package.json version)
91
+ * @param versionInfos - version infos from the npm registry
91
92
  */
92
93
  const resolveLatest = (versionInfos) => {
93
94
  const keys = Object.keys(versionInfos);