@saltcorn/plugins-loader 0.9.5-beta.19 → 0.9.5-beta.21

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": "0.9.5-beta.19",
3
+ "version": "0.9.5-beta.21",
4
4
  "description": "Saltcorn plugin loader",
5
5
  "homepage": "https://saltcorn.com",
6
6
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "env-paths": "^2.2.0",
13
- "@saltcorn/data": "0.9.5-beta.19"
13
+ "@saltcorn/data": "0.9.5-beta.21"
14
14
  },
15
15
  "author": "Christian Hugo",
16
16
  "license": "MIT",
@@ -25,6 +25,17 @@ const readPackageJson = async (filePath) => {
25
25
  else return null;
26
26
  };
27
27
 
28
+ const npmInstallNeeded = (oldPckJSON, newPckJSON) => {
29
+ const oldDeps = oldPckJSON.dependencies || {};
30
+ const oldDevDeps = oldPckJSON.devDependencies || {};
31
+ const newDeps = newPckJSON.dependencies || {};
32
+ const newDevDeps = newPckJSON.devDependencies || {};
33
+ return (
34
+ JSON.stringify(oldDeps) !== JSON.stringify(newDeps) ||
35
+ JSON.stringify(oldDevDeps) !== JSON.stringify(newDevDeps)
36
+ );
37
+ };
38
+
28
39
  class PluginInstaller {
29
40
  constructor(plugin, opts = {}) {
30
41
  this.plugin = plugin;
@@ -55,9 +66,14 @@ class PluginInstaller {
55
66
  const installer = async () => {
56
67
  if (await this.prepPluginsFolder(force, pckJSON)) {
57
68
  const tmpPckJSON = await this.removeDependencies(
58
- await readPackageJson(this.tempPckJsonPath)
69
+ await readPackageJson(this.tempPckJsonPath),
70
+ true
59
71
  );
60
- await this.npmInstall(tmpPckJSON);
72
+ if (
73
+ !pckJSON ||
74
+ npmInstallNeeded(await this.removeDependencies(pckJSON), tmpPckJSON)
75
+ )
76
+ await this.npmInstall(tmpPckJSON);
61
77
  await this.movePlugin();
62
78
  if (await tarballExists(this.plugin)) await removeTarball(this.plugin);
63
79
  }
@@ -100,29 +116,30 @@ class PluginInstaller {
100
116
 
101
117
  async prepPluginsFolder(force, pckJSON) {
102
118
  let wasLoaded = false;
119
+ const folderExists = await pathExists(this.pluginDir);
103
120
  switch (this.plugin.source) {
104
121
  case "npm":
105
122
  if (
106
123
  (force && !(await this.versionIsInstalled(pckJSON))) ||
107
- !(await pathExists(this.pluginDir))
124
+ !folderExists
108
125
  ) {
109
126
  wasLoaded = await downloadFromNpm(this.plugin, this.tempDir, pckJSON);
110
127
  }
111
128
  break;
112
129
  case "github":
113
- if (force || !(await pathExists(this.pluginDir))) {
130
+ if (force || !folderExists) {
114
131
  await downloadFromGithub(this.plugin, this.tempDir);
115
132
  wasLoaded = true;
116
133
  }
117
134
  break;
118
135
  case "local":
119
- if (force || !(await pathExists(this.pluginDir))) {
136
+ if (force || !folderExists) {
120
137
  await copy(this.plugin.location, this.tempDir);
121
138
  wasLoaded = true;
122
139
  }
123
140
  break;
124
141
  case "git":
125
- if (force || !(await pathExists(this.pluginDir))) {
142
+ if (force || !folderExists) {
126
143
  await gitPullOrClone(this.plugin, this.tempDir);
127
144
  this.pckJsonPath = join(this.pluginDir, "package.json");
128
145
  wasLoaded = true;
@@ -176,7 +193,7 @@ class PluginInstaller {
176
193
  }
177
194
  }
178
195
 
179
- async removeDependencies(tmpPckJSON) {
196
+ async removeDependencies(tmpPckJSON, writeToDisk) {
180
197
  const pckJSON = { ...tmpPckJSON };
181
198
  const oldDepsLength = Object.keys(pckJSON.dependencies || {}).length;
182
199
  const oldDevDepsLength = Object.keys(pckJSON.devDependencies || {}).length;
@@ -188,8 +205,9 @@ class PluginInstaller {
188
205
  if (pckJSON.dependencies) staticsRemover(pckJSON.dependencies);
189
206
  if (pckJSON.devDependencies) staticsRemover(pckJSON.devDependencies);
190
207
  if (
191
- Object.keys(pckJSON.dependencies || {}).length !== oldDepsLength ||
192
- Object.keys(pckJSON.devDependencies || {}).length !== oldDevDepsLength
208
+ writeToDisk &&
209
+ (Object.keys(pckJSON.dependencies || {}).length !== oldDepsLength ||
210
+ Object.keys(pckJSON.devDependencies || {}).length !== oldDevDepsLength)
193
211
  )
194
212
  await writeFile(
195
213
  join(this.tempDir, "package.json"),