@joystick.js/cli-canary 0.0.0-canary.60 → 0.0.0-canary.62

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.
@@ -1,4 +1,23 @@
1
1
  import dev from "../../lib/dev/index.js";
2
+ const startHMRProcess = () => {
3
+ const execArgv = ["--no-warnings"];
4
+ if (majorVersion < 19) {
5
+ execArgv.push("--experimental-specifier-resolution=node");
6
+ }
7
+ const hmrProcess = child_process.fork(
8
+ path.resolve(`${__dirname}/hmrServer.js`),
9
+ [],
10
+ {
11
+ execArgv,
12
+ // NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
13
+ // communicate with the child_process.
14
+ silent: true
15
+ }
16
+ );
17
+ process.hmrProcess = hmrProcess;
18
+ handleHMRProcessSTDIO();
19
+ handleHMRProcessMessages();
20
+ };
2
21
  var start_default = async (args = {}, options = {}) => {
3
22
  const port = options?.port ? parseInt(options?.port) : 2600;
4
23
  await dev({
@@ -20,12 +20,6 @@ import { SETTINGS_FILE_NAME_REGEX } from "../regexes.js";
20
20
  import getCodependenciesForFile from "./getCodependenciesForFile.js";
21
21
  import removeDeletedDependenciesFromMap from "../build/removeDeletedDependenciesFromMap.js";
22
22
  import chalk from "chalk";
23
- const nodeMajorVersion = parseInt(
24
- process?.version?.split(".")[0]?.replace("v", ""),
25
- 10
26
- );
27
- const __filename = fileURLToPath(import.meta.url);
28
- const __dirname = dirname(__filename);
29
23
  const getDatabaseProcessIds = () => {
30
24
  try {
31
25
  const databaseProcessIds = [];
@@ -50,7 +44,7 @@ const getDatabaseProcessIds = () => {
50
44
  throw new Error(`[dev.getDatabaseProcessIds] ${exception.message}`);
51
45
  }
52
46
  };
53
- const handleSignalEvents = (processIds = []) => {
47
+ const handleSignalEvents = (processIds = [], nodeMajorVersion = 0, __dirname = "") => {
54
48
  try {
55
49
  const execArgv = ["--no-warnings"];
56
50
  if (nodeMajorVersion < 19) {
@@ -83,6 +77,46 @@ const handleSignalEvents = (processIds = []) => {
83
77
  throw new Error(`[dev.handleSignalEvents] ${exception.message}`);
84
78
  }
85
79
  };
80
+ const handleServerProcessMessages = () => {
81
+ try {
82
+ process.serverProcess.on("message", (message) => {
83
+ const processMessages = ["SERVER_CLOSED"];
84
+ if (!processMessages.includes(message)) {
85
+ process.loader.stable(message);
86
+ }
87
+ });
88
+ } catch (exception) {
89
+ throw new Error(`[dev.handleServerProcessMessages] ${exception.message}`);
90
+ }
91
+ };
92
+ const handleServerProcessSTDIO = () => {
93
+ try {
94
+ if (process.serverProcess) {
95
+ process.serverProcess.on("error", (error) => {
96
+ console.log(error);
97
+ });
98
+ process.serverProcess.stdout.on("data", (data) => {
99
+ const message = data.toString();
100
+ if (message && message.includes("App running at:")) {
101
+ process.loader.stable(message);
102
+ } else {
103
+ if (message && !message.includes("BUILD_ERROR")) {
104
+ console.log(message);
105
+ }
106
+ }
107
+ });
108
+ process.serverProcess.stderr.on("data", (data) => {
109
+ process.loader.stop();
110
+ CLILog(data.toString(), {
111
+ level: "danger",
112
+ docs: "https://cheatcode.co/docs/joystick"
113
+ });
114
+ });
115
+ }
116
+ } catch (exception) {
117
+ throw new Error(`[dev.handleServerProcessSTDIO] ${exception.message}`);
118
+ }
119
+ };
86
120
  const handleAddOrChangeFile = async (context = {}, path2 = "") => {
87
121
  try {
88
122
  if (context.isAddingOrChangingFile) {
@@ -365,11 +399,16 @@ const dev = async (options, { resolve, reject }) => {
365
399
  try {
366
400
  validateOptions(options);
367
401
  initProcess(options);
402
+ const nodeMajorVersion = parseInt(
403
+ process?.version?.split(".")[0]?.replace("v", ""),
404
+ 10
405
+ );
406
+ const __filename = fileURLToPath(import.meta.url);
407
+ const __dirname = dirname(__filename);
368
408
  warnInvalidJoystickEnvironment();
369
409
  checkForRequiredFiles();
370
410
  const settings = await loadSettings({
371
- environment: options.environment,
372
- process: options.process
411
+ environment: options.environment
373
412
  });
374
413
  await startDatabases({
375
414
  environment: options.environment,
@@ -378,7 +417,26 @@ const dev = async (options, { resolve, reject }) => {
378
417
  });
379
418
  await runInitialBuild(settings?.parsed?.config?.build);
380
419
  await startFileWatcher(options);
381
- handleSignalEvents();
420
+ const serverProcess = await startApp({
421
+ nodeMajorVersion,
422
+ port: options?.port
423
+ });
424
+ if (serverProcess) {
425
+ process.serverProcess = serverProcess;
426
+ handleServerProcessSTDIO();
427
+ handleServerProcessMessages();
428
+ }
429
+ let hmrProcess;
430
+ if (options?.environment !== "test") {
431
+ hmrProcess = await startHMR({
432
+ nodeMajorVersion
433
+ });
434
+ }
435
+ handleSignalEvents(
436
+ [serverProcess.pid, hmrProcess.pid],
437
+ nodeMajorVersion,
438
+ __dirname
439
+ );
382
440
  resolve();
383
441
  } catch (exception) {
384
442
  console.warn(exception);
@@ -62,9 +62,7 @@ const loadSettings = (options, { resolve, reject }) => {
62
62
  warnIfSettingsNotFound(settingsPath);
63
63
  const settings = getSettings(settingsPath);
64
64
  warnIfInvalidJSONInSettings(settings);
65
- if (options?.process) {
66
- options.process.env.JOYSTICK_SETTINGS = settings;
67
- }
65
+ process.env.JOYSTICK_SETTINGS = settings;
68
66
  resolve({
69
67
  parsed: JSON.parse(settings),
70
68
  unparsed: settings
@@ -1,13 +1,50 @@
1
- const actionMethod = () => {
1
+ import child_process from "child_process";
2
+ import path from "path";
3
+ const handleStartServerProcess = (execArgv = {}, sessionsBeforeHMRUpdate = {}) => {
2
4
  try {
5
+ return child_process.fork(
6
+ path.resolve(".joystick/build/index.server.js"),
7
+ [],
8
+ {
9
+ execArgv,
10
+ // NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
11
+ // communicate with the child_process.
12
+ silent: true,
13
+ env: {
14
+ FORCE_COLOR: "1",
15
+ LOGS_PATH: process.env.LOGS_PATH,
16
+ NODE_ENV: process.env.NODE_ENV,
17
+ ROOT_URL: process.env.ROOT_URL,
18
+ PORT: process.env.PORT,
19
+ JOYSTICK_SETTINGS: process.env.JOYSTICK_SETTINGS,
20
+ HMR_SESSIONS: sessionsBeforeHMRUpdate
21
+ }
22
+ }
23
+ );
3
24
  } catch (exception) {
4
- throw new Error(`[startApp.actionMethod] ${exception.message}`);
25
+ throw new Error(`[startApp.handleStartServerProcess] ${exception.message}`);
26
+ }
27
+ };
28
+ const getExecArgs = (nodeMajorVersion = 0) => {
29
+ try {
30
+ const execArgv = ["--no-warnings"];
31
+ if (nodeMajorVersion < 19) {
32
+ execArgv.push("--experimental-specifier-resolution=node");
33
+ }
34
+ if (process.env.NODE_ENV === "development" && process.env.IS_DEBUG_MODE === "true") {
35
+ execArgv.push("--inspect");
36
+ }
37
+ return execArgv;
38
+ } catch (exception) {
39
+ throw new Error(`[startApp.getExecArgs] ${exception.message}`);
5
40
  }
6
41
  };
7
42
  const validateOptions = (options) => {
8
43
  try {
9
44
  if (!options)
10
45
  throw new Error("options object is required.");
46
+ if (!options.nodeMajorVersion)
47
+ throw new Error("options.nodeMajorVersion is required.");
11
48
  if (!options.port)
12
49
  throw new Error("options.port is required.");
13
50
  } catch (exception) {
@@ -17,7 +54,9 @@ const validateOptions = (options) => {
17
54
  const startApp = (options, { resolve, reject }) => {
18
55
  try {
19
56
  validateOptions(options);
20
- resolve();
57
+ const execArgv = getExecArgs(options?.nodeMajorVersion);
58
+ const serverProcess = handleStartServerProcess(execArgv);
59
+ return resolve(serverProcess);
21
60
  } catch (exception) {
22
61
  reject(`[startApp] ${exception.message}`);
23
62
  }
@@ -1,15 +1,38 @@
1
- const actionMethod = () => {
1
+ import child_process from "child_process";
2
+ import path from "path";
3
+ const handleStartHMRProcess = (execArgv = {}) => {
2
4
  try {
5
+ return child_process.fork(
6
+ path.resolve(`${__dirname}/hmrServer.js`),
7
+ [],
8
+ {
9
+ execArgv,
10
+ // NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
11
+ // communicate with the child_process.
12
+ silent: true
13
+ }
14
+ );
3
15
  } catch (exception) {
4
- throw new Error(`[startHMR.actionMethod] ${exception.message}`);
16
+ throw new Error(`[startHMR.handleStartHMRProcess] ${exception.message}`);
17
+ }
18
+ };
19
+ const getExecArgs = (nodeMajorVersion = 0) => {
20
+ try {
21
+ const execArgv = ["--no-warnings"];
22
+ if (nodeMajorVersion < 19) {
23
+ execArgv.push("--experimental-specifier-resolution=node");
24
+ }
25
+ return execArgv;
26
+ } catch (exception) {
27
+ throw new Error(`[startHMR.getExecArgs] ${exception.message}`);
5
28
  }
6
29
  };
7
30
  const validateOptions = (options) => {
8
31
  try {
9
32
  if (!options)
10
33
  throw new Error("options object is required.");
11
- if (!options.port)
12
- throw new Error("options.port is required.");
34
+ if (!options.nodeMajorVersion)
35
+ throw new Error("options.nodeMajorVersion is required.");
13
36
  } catch (exception) {
14
37
  throw new Error(`[startHMR.validateOptions] ${exception.message}`);
15
38
  }
@@ -17,7 +40,9 @@ const validateOptions = (options) => {
17
40
  const startHMR = (options, { resolve, reject }) => {
18
41
  try {
19
42
  validateOptions(options);
20
- resolve();
43
+ const execArgv = getExecArgs(options?.nodeMajorVersion);
44
+ const hmrProcess = handleStartHMRProcess(execArgv);
45
+ return resolve(hmrProcess);
21
46
  } catch (exception) {
22
47
  reject(`[startHMR] ${exception.message}`);
23
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joystick.js/cli-canary",
3
- "version": "0.0.0-canary.60",
3
+ "version": "0.0.0-canary.62",
4
4
  "type": "module",
5
5
  "description": "CLI for the Joystick JavaScript framework.",
6
6
  "main": "development.js",
@@ -258,29 +258,29 @@ import dev from "../../lib/dev/index.js";
258
258
  // }
259
259
  //};
260
260
  //
261
- //const startHMRProcess = () => {
262
- // const execArgv = ["--no-warnings"];
263
- //
264
- // if (majorVersion < 19) {
265
- // execArgv.push("--experimental-specifier-resolution=node");
266
- // }
267
- //
268
- // const hmrProcess = child_process.fork(
269
- // path.resolve(`${__dirname}/hmrServer.js`),
270
- // [],
271
- // {
272
- // execArgv,
273
- // // NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
274
- // // communicate with the child_process.
275
- // silent: true,
276
- // }
277
- // );
278
- //
279
- // process.hmrProcess = hmrProcess;
280
- //
281
- // handleHMRProcessSTDIO();
282
- // handleHMRProcessMessages();
283
- //};
261
+ const startHMRProcess = () => {
262
+ const execArgv = ["--no-warnings"];
263
+
264
+ if (majorVersion < 19) {
265
+ execArgv.push("--experimental-specifier-resolution=node");
266
+ }
267
+
268
+ const hmrProcess = child_process.fork(
269
+ path.resolve(`${__dirname}/hmrServer.js`),
270
+ [],
271
+ {
272
+ execArgv,
273
+ // NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
274
+ // communicate with the child_process.
275
+ silent: true,
276
+ }
277
+ );
278
+
279
+ process.hmrProcess = hmrProcess;
280
+
281
+ handleHMRProcessSTDIO();
282
+ handleHMRProcessMessages();
283
+ };
284
284
  //
285
285
  //const notifyHMRClients = (indexHTMLChanged = false) => {
286
286
  // const settings = loadSettings(process.env.NODE_ENV);
@@ -23,14 +23,6 @@ import getCodependenciesForFile from "./getCodependenciesForFile.js";
23
23
  import removeDeletedDependenciesFromMap from "../build/removeDeletedDependenciesFromMap.js";
24
24
  import chalk from "chalk";
25
25
 
26
- const nodeMajorVersion = parseInt(
27
- process?.version?.split(".")[0]?.replace("v", ""),
28
- 10
29
- );
30
-
31
- const __filename = fileURLToPath(import.meta.url);
32
- const __dirname = dirname(__filename);
33
-
34
26
  const getDatabaseProcessIds = () => {
35
27
  try {
36
28
  const databaseProcessIds = [];
@@ -62,7 +54,7 @@ const getDatabaseProcessIds = () => {
62
54
  }
63
55
  };
64
56
 
65
- const handleSignalEvents = (processIds = []) => {
57
+ const handleSignalEvents = (processIds = [], nodeMajorVersion = 0, __dirname = '') => {
66
58
  try {
67
59
  const execArgv = ["--no-warnings"];
68
60
 
@@ -100,6 +92,53 @@ const handleSignalEvents = (processIds = []) => {
100
92
  }
101
93
  };
102
94
 
95
+ const handleServerProcessMessages = () => {
96
+ try {
97
+ process.serverProcess.on("message", (message) => {
98
+ const processMessages = ["SERVER_CLOSED"];
99
+
100
+ if (!processMessages.includes(message)) {
101
+ process.loader.stable(message);
102
+ }
103
+ });
104
+ } catch (exception) {
105
+ throw new Error(`[dev.handleServerProcessMessages] ${exception.message}`);
106
+ }
107
+ };
108
+
109
+ const handleServerProcessSTDIO = () => {
110
+ try {
111
+ if (process.serverProcess) {
112
+ process.serverProcess.on("error", (error) => {
113
+ console.log(error);
114
+ });
115
+
116
+ process.serverProcess.stdout.on("data", (data) => {
117
+ const message = data.toString();
118
+
119
+ if (message && message.includes("App running at:")) {
120
+ process.loader.stable(message);
121
+ } else {
122
+ if (message && !message.includes("BUILD_ERROR")) {
123
+ console.log(message);
124
+ }
125
+ }
126
+ });
127
+
128
+ process.serverProcess.stderr.on("data", (data) => {
129
+ process.loader.stop();
130
+
131
+ CLILog(data.toString(), {
132
+ level: "danger",
133
+ docs: "https://cheatcode.co/docs/joystick",
134
+ });
135
+ });
136
+ }
137
+ } catch (exception) {
138
+ throw new Error(`[dev.handleServerProcessSTDIO] ${exception.message}`);
139
+ }
140
+ };
141
+
103
142
  const handleAddOrChangeFile = async (context = {}, path = '') => {
104
143
  try {
105
144
  if (context.isAddingOrChangingFile) {
@@ -436,12 +475,19 @@ const dev = async (options, { resolve, reject }) => {
436
475
  validateOptions(options);
437
476
  initProcess(options);
438
477
 
478
+ const nodeMajorVersion = parseInt(
479
+ process?.version?.split(".")[0]?.replace("v", ""),
480
+ 10
481
+ );
482
+
483
+ const __filename = fileURLToPath(import.meta.url);
484
+ const __dirname = dirname(__filename);
485
+
439
486
  warnInvalidJoystickEnvironment();
440
487
  checkForRequiredFiles();
441
488
 
442
489
  const settings = await loadSettings({
443
490
  environment: options.environment,
444
- process: options.process,
445
491
  });
446
492
 
447
493
  await startDatabases({
@@ -453,11 +499,31 @@ const dev = async (options, { resolve, reject }) => {
453
499
  await runInitialBuild(settings?.parsed?.config?.build);
454
500
  await startFileWatcher(options);
455
501
 
456
- handleSignalEvents();
502
+ const serverProcess = await startApp({
503
+ nodeMajorVersion,
504
+ port: options?.port,
505
+ });
457
506
 
458
- // if (options?.environment !== 'test') {
459
- // await startHMR();
460
- // }
507
+ if (serverProcess) {
508
+ process.serverProcess = serverProcess;
509
+ handleServerProcessSTDIO();
510
+ handleServerProcessMessages();
511
+ }
512
+
513
+ // NOTE: Scope this out here so we can reference the processId below.
514
+ let hmrProcess;
515
+
516
+ if (options?.environment !== 'test') {
517
+ hmrProcess = await startHMR({
518
+ nodeMajorVersion,
519
+ });
520
+ }
521
+
522
+ handleSignalEvents(
523
+ [serverProcess.pid, hmrProcess.pid],
524
+ nodeMajorVersion,
525
+ __dirname
526
+ );
461
527
  //
462
528
  // if (options?.environment === 'test') {
463
529
  // await runTests(options);
@@ -73,9 +73,7 @@ const loadSettings = (options, { resolve, reject }) => {
73
73
  const settings = getSettings(settingsPath);
74
74
  warnIfInvalidJSONInSettings(settings);
75
75
 
76
- if (options?.process) {
77
- options.process.env.JOYSTICK_SETTINGS = settings;
78
- }
76
+ process.env.JOYSTICK_SETTINGS = settings;
79
77
 
80
78
  resolve({
81
79
  parsed: JSON.parse(settings),
@@ -1,16 +1,57 @@
1
- /* eslint-disable consistent-return */
1
+ import child_process from "child_process";
2
+ import path from "path";
2
3
 
3
- const actionMethod = () => {
4
+ const handleStartServerProcess = (execArgv = {}, sessionsBeforeHMRUpdate = {}) => {
4
5
  try {
5
- // Perform a single step in your action here.
6
+ return child_process.fork(
7
+ path.resolve(".joystick/build/index.server.js"),
8
+ [],
9
+ {
10
+ execArgv,
11
+ // NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
12
+ // communicate with the child_process.
13
+ silent: true,
14
+ env: {
15
+ FORCE_COLOR: "1",
16
+ LOGS_PATH: process.env.LOGS_PATH,
17
+ NODE_ENV: process.env.NODE_ENV,
18
+ ROOT_URL: process.env.ROOT_URL,
19
+ PORT: process.env.PORT,
20
+ JOYSTICK_SETTINGS: process.env.JOYSTICK_SETTINGS,
21
+ HMR_SESSIONS: sessionsBeforeHMRUpdate,
22
+ },
23
+ }
24
+ );
6
25
  } catch (exception) {
7
- throw new Error(`[startApp.actionMethod] ${exception.message}`);
26
+ throw new Error(`[startApp.handleStartServerProcess] ${exception.message}`);
27
+ }
28
+ };
29
+
30
+ const getExecArgs = (nodeMajorVersion = 0) => {
31
+ try {
32
+ const execArgv = ["--no-warnings"];
33
+
34
+ if (nodeMajorVersion < 19) {
35
+ execArgv.push("--experimental-specifier-resolution=node");
36
+ }
37
+
38
+ if (
39
+ process.env.NODE_ENV === "development" &&
40
+ process.env.IS_DEBUG_MODE === "true"
41
+ ) {
42
+ execArgv.push("--inspect");
43
+ }
44
+
45
+ return execArgv;
46
+ } catch (exception) {
47
+ throw new Error(`[startApp.getExecArgs] ${exception.message}`);
8
48
  }
9
49
  };
10
50
 
11
51
  const validateOptions = (options) => {
12
52
  try {
13
53
  if (!options) throw new Error('options object is required.');
54
+ if (!options.nodeMajorVersion) throw new Error('options.nodeMajorVersion is required.');
14
55
  if (!options.port) throw new Error('options.port is required.');
15
56
  } catch (exception) {
16
57
  throw new Error(`[startApp.validateOptions] ${exception.message}`);
@@ -20,8 +61,11 @@ const validateOptions = (options) => {
20
61
  const startApp = (options, { resolve, reject }) => {
21
62
  try {
22
63
  validateOptions(options);
23
- // Call action methods in sequence here.
24
- resolve();
64
+
65
+ const execArgv = getExecArgs(options?.nodeMajorVersion);
66
+ const serverProcess = handleStartServerProcess(execArgv);
67
+
68
+ return resolve(serverProcess);
25
69
  } catch (exception) {
26
70
  reject(`[startApp] ${exception.message}`);
27
71
  }
@@ -1,17 +1,43 @@
1
- /* eslint-disable consistent-return */
1
+ import child_process from "child_process";
2
+ import path from "path";
2
3
 
3
- const actionMethod = () => {
4
+ const handleStartHMRProcess = (execArgv = {}) => {
4
5
  try {
5
- // Perform a single step in your action here.
6
+ // NOTE: Port is automatically pulled via process.env.PORT
7
+ // in the hmrServer.js script.
8
+ return child_process.fork(
9
+ path.resolve(`${__dirname}/hmrServer.js`),
10
+ [],
11
+ {
12
+ execArgv,
13
+ // NOTE: Pipe stdin, stdout, and stderr. IPC establishes a message channel so we
14
+ // communicate with the child_process.
15
+ silent: true,
16
+ }
17
+ );
6
18
  } catch (exception) {
7
- throw new Error(`[startHMR.actionMethod] ${exception.message}`);
19
+ throw new Error(`[startHMR.handleStartHMRProcess] ${exception.message}`);
20
+ }
21
+ };
22
+
23
+ const getExecArgs = (nodeMajorVersion = 0) => {
24
+ try {
25
+ const execArgv = ["--no-warnings"];
26
+
27
+ if (nodeMajorVersion < 19) {
28
+ execArgv.push("--experimental-specifier-resolution=node");
29
+ }
30
+
31
+ return execArgv;
32
+ } catch (exception) {
33
+ throw new Error(`[startHMR.getExecArgs] ${exception.message}`);
8
34
  }
9
35
  };
10
36
 
11
37
  const validateOptions = (options) => {
12
38
  try {
13
39
  if (!options) throw new Error('options object is required.');
14
- if (!options.port) throw new Error('options.port is required.');
40
+ if (!options.nodeMajorVersion) throw new Error('options.nodeMajorVersion is required.');
15
41
  } catch (exception) {
16
42
  throw new Error(`[startHMR.validateOptions] ${exception.message}`);
17
43
  }
@@ -20,8 +46,11 @@ const validateOptions = (options) => {
20
46
  const startHMR = (options, { resolve, reject }) => {
21
47
  try {
22
48
  validateOptions(options);
23
- // Call action methods in sequence here.
24
- resolve();
49
+
50
+ const execArgv = getExecArgs(options?.nodeMajorVersion);
51
+ const hmrProcess = handleStartHMRProcess(execArgv);
52
+
53
+ return resolve(hmrProcess);
25
54
  } catch (exception) {
26
55
  reject(`[startHMR] ${exception.message}`);
27
56
  }