@zohodesk/codestandard-validator 0.0.4-exp-18 → 0.0.4-exp-19

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.
@@ -10,15 +10,20 @@ const {
10
10
  const {
11
11
  Logger
12
12
  } = require('../Logger/Logger');
13
+ const {
14
+ existsSync
15
+ } = require("fs");
13
16
  function createVersionControlFile(uninstalledPlugins) {
14
17
  Logger.log(Logger.INFO_TYPE, `Rule Plugin Versions are Noted in pluginVersionControl.js`);
15
18
  const versionfilePath = path.join(getNodeModulesPath(), 'node_modules', '@zohodesk', 'codestandard-validator', 'pluginVersionControl.js');
16
- writeFileSync(versionfilePath, `module.exports.plugins = [${uninstalledPlugins.map(plugin => {
17
- return JSON.stringify({
18
- plugin: `${plugin}`,
19
- time: `${new Date()}`
20
- });
21
- }).join(',')}]`);
19
+ if (existsSync(versionfilePath)) {
20
+ writeFileSync(versionfilePath, `module.exports.plugins = [${uninstalledPlugins.map(plugin => {
21
+ return JSON.stringify({
22
+ plugin: `${plugin}`,
23
+ time: `${new Date()}`
24
+ });
25
+ }).join(',')}]`);
26
+ }
22
27
  }
23
28
  module.exports = {
24
29
  createVersionControlFile
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ const {
4
+ Worker
5
+ } = require('worker_threads');
6
+ async function installPluginsByWorker(plugins) {
7
+ try {
8
+ const results = await Promise.all(plugins.map(pkg => runWorker({
9
+ packageName: pkg.packageName,
10
+ version: pkg.version
11
+ })));
12
+ console.log('Package are installed By from workers:', results.join('\n'));
13
+ } catch (error) {
14
+ console.error('Error:', error);
15
+ }
16
+ }
17
+ function runWorker(data) {
18
+ return new Promise((resolve, reject) => {
19
+ const worker = new Worker(`${__dirname}/worker.js`, {
20
+ workerData: data
21
+ });
22
+ worker.on('message', result => {
23
+ resolve(result);
24
+ });
25
+ worker.on('error', error => {
26
+ reject(error);
27
+ });
28
+ worker.on('exit', code => {
29
+ if (code !== 0) {
30
+ reject(new Error(`Worker stopped with exit code ${code}`));
31
+ }
32
+ });
33
+ });
34
+ }
35
+ module.exports = installPluginsByWorker;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ const {
4
+ workerData,
5
+ parentPort
6
+ } = require('worker_threads');
7
+ const {
8
+ spawnSync
9
+ } = require('child_process');
10
+ const {
11
+ getNodeModulesPath
12
+ } = require('../../General/getNodeModulesPath');
13
+ function performanceInstalllation({
14
+ packageName,
15
+ version
16
+ }) {
17
+ const start = performance.now();
18
+ try {
19
+ require.resolve(packageName);
20
+ } catch (err) {
21
+ spawnSync('npm', ['install', `${packageName}@${version}`, '--no-save'], {
22
+ stdio: 'inherit',
23
+ cwd: getNodeModulesPath()
24
+ });
25
+ }
26
+ const end = performance.now();
27
+ return `Package ${packageName}@${version} installed successfully and installed in ${end - start} ms`;
28
+ }
29
+ const result = performanceInstalllation({
30
+ packageName: workerData.packageName,
31
+ version: workerData.version
32
+ });
33
+ parentPort.postMessage(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/codestandard-validator",
3
- "version": "0.0.4-exp-18",
3
+ "version": "0.0.4-exp-19",
4
4
  "description": "library to enforce code standard using eslint",
5
5
  "main": "index.js",
6
6
  "scripts": {