@saltcorn/plugins-loader 1.1.1-beta.5 → 1.1.1-beta.7

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.1.1-beta.5",
3
+ "version": "1.1.1-beta.7",
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.1.1-beta.5",
14
+ "@saltcorn/data": "1.1.1-beta.7",
15
15
  "https-proxy-agent": "^7.0.6"
16
16
  },
17
17
  "author": "Christian Hugo",
@@ -9,9 +9,10 @@ const {
9
9
  removeTarball,
10
10
  } = require("./download_utils");
11
11
  const { getState } = require("@saltcorn/data/db/state");
12
- const { rm, rename, cp, readFile } = require("fs").promises;
12
+ const { rm, rename, cp, readFile, readdir } = require("fs").promises;
13
13
  const envPaths = require("env-paths");
14
14
  const semver = require("semver");
15
+ const path = require("path");
15
16
 
16
17
  const staticDeps = ["@saltcorn/markup", "@saltcorn/data", "jest"];
17
18
  const fixedPlugins = ["@saltcorn/base-plugin", "@saltcorn/sbadmin2"];
@@ -89,9 +90,13 @@ class PluginInstaller {
89
90
  }
90
91
 
91
92
  async install(force) {
93
+ getState().log(5, `loading plugin ${this.plugin.name}`);
92
94
  await this.ensurePluginsRootFolders();
93
95
  if (fixedPlugins.includes(this.plugin.location))
94
- return { plugin_module: require(this.plugin.location) };
96
+ return {
97
+ location: path.join(require.resolve(this.plugin.location), ".."),
98
+ plugin_module: require(this.plugin.location),
99
+ };
95
100
  const msgs = [];
96
101
  let pckJSON = await readPackageJson(this.pckJsonPath);
97
102
  const installer = async () => {
@@ -120,12 +125,26 @@ class PluginInstaller {
120
125
  let module = null;
121
126
  let loadedWithReload = false;
122
127
  try {
123
- // try importing it and if it fails, remove and try again
124
- // could happen when there is a directory with a valid package.json
125
- // but without a valid node modules folder
126
128
  module = await this.loadMainFile(pckJSON);
127
129
  } catch (e) {
130
+ if (e.code === "MODULE_NOT_FOUND") {
131
+ getState().log(5, `corrupt plugin dir: ${this.pluginDir}`);
132
+ const files = await readdir(this.pluginDir);
133
+ getState().log(5, `files in plugin dir: ${JSON.stringify(files)}`);
134
+ if (files.includes("node_modules")) {
135
+ const nodeModuleFiles = await readdir(
136
+ join(this.pluginDir, "node_modules")
137
+ );
138
+ getState().log(
139
+ 5,
140
+ `node_modules files: ${JSON.stringify(nodeModuleFiles)}`
141
+ );
142
+ } else getState().log(5, `no node_modules in plugin dir`);
143
+ }
128
144
  if (force) {
145
+ // remove and try again
146
+ // could happen when there is a directory with a package.json
147
+ // but without a valid node modules folder
129
148
  getState().log(
130
149
  2,
131
150
  `Error loading plugin ${this.plugin.name}. Removing and trying again.`
@@ -133,12 +152,13 @@ class PluginInstaller {
133
152
  await this.remove();
134
153
  pckJSON = null;
135
154
  await installer();
136
- } else
155
+ } else {
137
156
  getState().log(
138
157
  2,
139
158
  `Error loading plugin ${this.plugin.name}. Trying again with reload flag. ` +
140
159
  "A server restart may be required."
141
160
  );
161
+ }
142
162
 
143
163
  module = await this.loadMainFile(pckJSON, true);
144
164
  loadedWithReload = true;
@@ -167,6 +187,7 @@ class PluginInstaller {
167
187
  (force && !(await this.versionIsInstalled(pckJSON))) ||
168
188
  !folderExists
169
189
  ) {
190
+ getState().log(6, "downloading from npm");
170
191
  wasLoaded = await downloadFromNpm(
171
192
  this.plugin,
172
193
  this.rootFolder,
@@ -177,12 +198,14 @@ class PluginInstaller {
177
198
  break;
178
199
  case "github":
179
200
  if (force || !folderExists) {
201
+ getState().log(6, "downloading from github");
180
202
  await downloadFromGithub(this.plugin, this.rootFolder, this.tempDir);
181
203
  wasLoaded = true;
182
204
  }
183
205
  break;
184
206
  case "local":
185
207
  if (force || !folderExists) {
208
+ getState().log(6, "copying from local");
186
209
  await copy(this.plugin.location, this.tempDir);
187
210
  // if tempdir has a node_modules folder, remove it
188
211
  if (await pathExists(join(this.tempDir, "node_modules")))
@@ -192,6 +215,7 @@ class PluginInstaller {
192
215
  break;
193
216
  case "git":
194
217
  if (force || !folderExists) {
218
+ getState().log(6, "downloading from git");
195
219
  await gitPullOrClone(this.plugin, this.tempDir);
196
220
  this.pckJsonPath = join(this.pluginDir, "package.json");
197
221
  wasLoaded = true;