@joystick.js/cli-canary 0.0.0-canary.73 → 0.0.0-canary.75

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.
@@ -102,7 +102,7 @@ const handleCopyFiles = (files = [], outputPath = "") => {
102
102
  };
103
103
  const isNodePath = (path = "") => {
104
104
  try {
105
- return nodePaths.some((nodePath) => {
105
+ return !isNotJavaScript(path) && nodePaths.some((nodePath) => {
106
106
  return path.includes(nodePath);
107
107
  }) && !nodePathExclusions.some((nodeExclusionPath) => {
108
108
  return path.includes(nodeExclusionPath);
@@ -113,7 +113,7 @@ const isNodePath = (path = "") => {
113
113
  };
114
114
  const isBrowserPath = (path = "") => {
115
115
  try {
116
- return browserPaths.some((browserPath) => {
116
+ return !isNotJavaScript(path) && browserPaths.some((browserPath) => {
117
117
  return path.includes(browserPath);
118
118
  }) && !browserPathExclusions.some((browserExclusionPath) => {
119
119
  return path.includes(browserExclusionPath);
@@ -149,10 +149,10 @@ const getFilePlatform = (path = "") => {
149
149
  if (isCopy) {
150
150
  platform = "copy";
151
151
  }
152
- if (isBrowser && !isCopy) {
152
+ if (isBrowser) {
153
153
  platform = "browser";
154
154
  }
155
- if (isNode && !isCopy) {
155
+ if (isNode) {
156
156
  platform = "node";
157
157
  }
158
158
  return platform;
@@ -1,7 +1,28 @@
1
- const actionMethod = () => {
1
+ import ps from "ps-node";
2
+ const killProcess = (pid = 0) => {
2
3
  try {
4
+ return new Promise((resolve) => {
5
+ ps.kill(pid, () => {
6
+ resolve();
7
+ });
8
+ });
3
9
  } catch (exception) {
4
- throw new Error(`[cleanup.actionMethod] ${exception.message}`);
10
+ throw new Error(`[cleanup.killProcess] ${exception.message}`);
11
+ }
12
+ };
13
+ const handleCLIProcessMessages = () => {
14
+ try {
15
+ process.on("message", async (message = "{}") => {
16
+ const parsedMessage = JSON.parse(message);
17
+ const processIds = parsedMessage?.processIds;
18
+ for (let i = 0; i < processIds?.length; i += 1) {
19
+ const processId = processIds[i];
20
+ await killProcess(processId);
21
+ }
22
+ process.exit();
23
+ });
24
+ } catch (exception) {
25
+ throw new Error(`[cleanup.handleCLIProcessMessages] ${exception.message}`);
5
26
  }
6
27
  };
7
28
  const validateOptions = (options) => {
@@ -17,14 +38,18 @@ const validateOptions = (options) => {
17
38
  const cleanup = (options, { resolve, reject }) => {
18
39
  try {
19
40
  validateOptions(options);
41
+ process.title = "joystick_cleanup";
42
+ handleCLIProcessMessages();
20
43
  resolve();
21
44
  } catch (exception) {
22
45
  reject(`[cleanup] ${exception.message}`);
23
46
  }
24
47
  };
25
- var cleanup_default = (options) => new Promise((resolve, reject) => {
26
- cleanup(options, { resolve, reject });
27
- });
48
+ var cleanup_default = (async (options) => {
49
+ await new Promise((resolve, reject) => {
50
+ cleanup(options, { resolve, reject });
51
+ });
52
+ })();
28
53
  export {
29
54
  cleanup_default as default
30
55
  };
@@ -438,6 +438,7 @@ const dev = async (options, { resolve, reject }) => {
438
438
  nodeMajorVersion,
439
439
  __dirname
440
440
  );
441
+ await cleanup();
441
442
  resolve();
442
443
  } catch (exception) {
443
444
  console.warn(exception);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/cli-canary",
3
- "version": "0.0.0-canary.73",
3
+ "version": "0.0.0-canary.75",
4
4
  "type": "module",
5
5
  "description": "CLI for the Joystick JavaScript framework.",
6
6
  "main": "development.js",
@@ -115,7 +115,7 @@ const handleCopyFiles = (files = [], outputPath = '') => {
115
115
 
116
116
  const isNodePath = (path = '') => {
117
117
  try {
118
- return nodePaths.some((nodePath) => {
118
+ return !isNotJavaScript(path) && nodePaths.some((nodePath) => {
119
119
  return path.includes(nodePath);
120
120
  }) &&
121
121
  !nodePathExclusions.some((nodeExclusionPath) => {
@@ -128,7 +128,7 @@ const isNodePath = (path = '') => {
128
128
 
129
129
  const isBrowserPath = (path = '') => {
130
130
  try {
131
- return browserPaths.some((browserPath) => {
131
+ return !isNotJavaScript(path) && browserPaths.some((browserPath) => {
132
132
  return path.includes(browserPath);
133
133
  }) &&
134
134
  !browserPathExclusions.some((browserExclusionPath) => {
@@ -172,11 +172,11 @@ const getFilePlatform = (path = '') => {
172
172
  platform = "copy";
173
173
  }
174
174
 
175
- if (isBrowser && !isCopy) {
175
+ if (isBrowser) {
176
176
  platform = "browser";
177
177
  }
178
178
 
179
- if (isNode && !isCopy) {
179
+ if (isNode) {
180
180
  platform = "node";
181
181
  }
182
182
 
@@ -1,10 +1,32 @@
1
- /* eslint-disable consistent-return */
1
+ import ps from "ps-node";
2
2
 
3
- const actionMethod = () => {
3
+ const killProcess = (pid = 0) => {
4
4
  try {
5
- // Perform a single step in your action here.
5
+ return new Promise((resolve) => {
6
+ ps.kill(pid, () => {
7
+ resolve();
8
+ });
9
+ });
6
10
  } catch (exception) {
7
- throw new Error(`[cleanup.actionMethod] ${exception.message}`);
11
+ throw new Error(`[cleanup.killProcess] ${exception.message}`);
12
+ }
13
+ };
14
+
15
+ const handleCLIProcessMessages = () => {
16
+ try {
17
+ process.on('message', async (message = '{}') => {
18
+ const parsedMessage = JSON.parse(message);
19
+ const processIds = parsedMessage?.processIds;
20
+
21
+ for (let i = 0; i < processIds?.length; i += 1) {
22
+ const processId = processIds[i];
23
+ await killProcess(processId);
24
+ }
25
+
26
+ process.exit();
27
+ });
28
+ } catch (exception) {
29
+ throw new Error(`[cleanup.handleCLIProcessMessages] ${exception.message}`);
8
30
  }
9
31
  };
10
32
 
@@ -20,15 +42,23 @@ const validateOptions = (options) => {
20
42
  const cleanup = (options, { resolve, reject }) => {
21
43
  try {
22
44
  validateOptions(options);
23
- // Call action methods in sequence here.
45
+
46
+ process.title = "joystick_cleanup";
47
+
48
+ handleCLIProcessMessages();
49
+
24
50
  resolve();
25
51
  } catch (exception) {
26
52
  reject(`[cleanup] ${exception.message}`);
27
53
  }
28
54
  };
29
55
 
30
- export default (options) =>
31
- new Promise((resolve, reject) => {
32
- cleanup(options, { resolve, reject });
33
- });
56
+ // NOTE: Use an async iife because this module is called via child_process.fork();
57
+ export default (
58
+ async (options) => {
59
+ await new Promise((resolve, reject) => {
60
+ cleanup(options, { resolve, reject });
61
+ });
62
+ }
63
+ )();
34
64
 
@@ -525,6 +525,8 @@ const dev = async (options, { resolve, reject }) => {
525
525
  nodeMajorVersion,
526
526
  __dirname
527
527
  );
528
+
529
+ await cleanup();
528
530
  //
529
531
  // if (options?.environment === 'test') {
530
532
  // await runTests(options);