@saltcorn/plugins-loader 1.0.0-rc.8 → 1.0.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 +2 -2
- package/plugin_installer.js +39 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/plugins-loader",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
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
|
|
14
|
+
"@saltcorn/data": "1.0.0"
|
|
15
15
|
},
|
|
16
16
|
"author": "Christian Hugo",
|
|
17
17
|
"license": "MIT",
|
package/plugin_installer.js
CHANGED
|
@@ -26,6 +26,14 @@ const readPackageJson = async (filePath) => {
|
|
|
26
26
|
else return null;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* install when the new package.json has different dependencies
|
|
31
|
+
* or when the source is local and there are any dependencies
|
|
32
|
+
* @param source
|
|
33
|
+
* @param oldPckJSON
|
|
34
|
+
* @param newPckJSON
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
29
37
|
const npmInstallNeeded = (oldPckJSON, newPckJSON) => {
|
|
30
38
|
const oldDeps = oldPckJSON.dependencies || Object.create(null);
|
|
31
39
|
const oldDevDeps = oldPckJSON.devDependencies || Object.create(null);
|
|
@@ -92,12 +100,15 @@ class PluginInstaller {
|
|
|
92
100
|
await readPackageJson(this.tempPckJsonPath),
|
|
93
101
|
true
|
|
94
102
|
);
|
|
103
|
+
let wasInstalled = false;
|
|
95
104
|
if (
|
|
96
105
|
!pckJSON ||
|
|
97
106
|
npmInstallNeeded(await this.removeDependencies(pckJSON), tmpPckJSON)
|
|
98
|
-
)
|
|
107
|
+
) {
|
|
108
|
+
wasInstalled = true;
|
|
99
109
|
await this.npmInstall(tmpPckJSON);
|
|
100
|
-
|
|
110
|
+
}
|
|
111
|
+
await this.movePlugin(wasInstalled);
|
|
101
112
|
if (await tarballExists(this.rootFolder, this.plugin))
|
|
102
113
|
await removeTarball(this.rootFolder, this.plugin);
|
|
103
114
|
}
|
|
@@ -167,6 +178,9 @@ class PluginInstaller {
|
|
|
167
178
|
case "local":
|
|
168
179
|
if (force || !folderExists) {
|
|
169
180
|
await copy(this.plugin.location, this.tempDir);
|
|
181
|
+
// if tempdir has a node_modules folder, remove it
|
|
182
|
+
if (await pathExists(join(this.tempDir, "node_modules")))
|
|
183
|
+
await rm(join(this.tempDir, "node_modules"), { recursive: true });
|
|
170
184
|
wasLoaded = true;
|
|
171
185
|
}
|
|
172
186
|
break;
|
|
@@ -250,22 +264,31 @@ class PluginInstaller {
|
|
|
250
264
|
}
|
|
251
265
|
|
|
252
266
|
async npmInstall(pckJSON) {
|
|
253
|
-
getState().log(5, `NPM install plugin: ${pckJSON.name}`);
|
|
254
267
|
const isWindows = process.platform === "win32";
|
|
255
268
|
if (
|
|
256
269
|
Object.keys(pckJSON.dependencies || {}).length > 0 ||
|
|
257
270
|
Object.keys(pckJSON.devDependencies || {}).length > 0
|
|
258
271
|
) {
|
|
272
|
+
getState().log(5, `NPM install plugin: ${pckJSON.name}`);
|
|
259
273
|
const child = spawn("npm", ["install"], {
|
|
260
274
|
cwd: this.tempDir,
|
|
261
275
|
env: { ...process.env, ...this.envVars },
|
|
262
276
|
...(isWindows ? { shell: true } : {}),
|
|
263
277
|
});
|
|
264
278
|
return new Promise((resolve, reject) => {
|
|
279
|
+
if (child.stdout) {
|
|
280
|
+
child.stdout.on("data", (data) => {
|
|
281
|
+
getState().log(6, data.toString());
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
if (child.stderr) {
|
|
285
|
+
child.stderr.on("data", (data) => {
|
|
286
|
+
getState().log(6, data.toString());
|
|
287
|
+
});
|
|
288
|
+
}
|
|
265
289
|
child.on("exit", (exitCode, signal) => {
|
|
266
290
|
resolve({ success: exitCode === 0 });
|
|
267
291
|
});
|
|
268
|
-
|
|
269
292
|
child.on("error", (msg) => {
|
|
270
293
|
reject(msg);
|
|
271
294
|
});
|
|
@@ -273,7 +296,7 @@ class PluginInstaller {
|
|
|
273
296
|
}
|
|
274
297
|
}
|
|
275
298
|
|
|
276
|
-
async movePlugin() {
|
|
299
|
+
async movePlugin(wasInstalled) {
|
|
277
300
|
const isWindows = process.platform === "win32";
|
|
278
301
|
const copyMove = async () => {
|
|
279
302
|
await cp(this.tempDir, this.pluginDir, { recursive: true, force: true });
|
|
@@ -283,15 +306,17 @@ class PluginInstaller {
|
|
|
283
306
|
getState().log(2, `Error removing temp folder ${this.tempDir}`);
|
|
284
307
|
}
|
|
285
308
|
};
|
|
286
|
-
if (
|
|
287
|
-
await
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
309
|
+
if (this.plugin.source === "npm" || wasInstalled) {
|
|
310
|
+
if (await pathExists(this.pluginDir))
|
|
311
|
+
await rm(this.pluginDir, { recursive: true });
|
|
312
|
+
await mkdir(this.pluginDir, { recursive: true });
|
|
313
|
+
if (!isWindows) {
|
|
314
|
+
try {
|
|
315
|
+
await rename(this.tempDir, this.pluginDir);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
await copyMove();
|
|
318
|
+
}
|
|
319
|
+
} else await copyMove();
|
|
295
320
|
} else await copyMove();
|
|
296
321
|
}
|
|
297
322
|
}
|