@joystick.js/cli-canary 0.0.0-canary.99 → 1.0.0-beta.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.
Files changed (37) hide show
  1. package/{_package.json → canary.json} +2 -3
  2. package/dist/functions/index.js +16 -11
  3. package/dist/functions/start/index.js +0 -19
  4. package/dist/functions/test/index.js +2 -1
  5. package/dist/lib/build/browserPathExclusions.js +2 -1
  6. package/dist/lib/build/buildFiles.js +12 -4
  7. package/dist/lib/build/buildPlugins.js +19 -5
  8. package/dist/lib/build/nodePaths.js +1 -0
  9. package/dist/lib/build/replaceExamples.js +13 -0
  10. package/dist/lib/checkIfPortOccupied.js +27 -0
  11. package/dist/lib/dev/getFilesToBuild.js +1 -1
  12. package/dist/lib/dev/hmrServer.js +66 -0
  13. package/dist/lib/dev/index.js +132 -48
  14. package/dist/lib/dev/loadSettings.js +10 -4
  15. package/dist/lib/dev/runTests.js +47 -15
  16. package/dist/lib/dev/startApp.js +6 -4
  17. package/dist/lib/dev/tests.config.js +12 -0
  18. package/dist/lib/regexes.js +2 -0
  19. package/package.json +2 -1
  20. package/src/functions/index.js +15 -10
  21. package/src/functions/start/index.js +0 -656
  22. package/src/functions/test/index.js +1 -0
  23. package/src/lib/build/browserPathExclusions.js +2 -1
  24. package/src/lib/build/buildFiles.js +13 -4
  25. package/src/lib/build/buildPlugins.js +31 -14
  26. package/src/lib/build/nodePaths.js +1 -0
  27. package/src/lib/build/replaceExamples.js +11 -0
  28. package/src/lib/build/setComponentId.js +2 -2
  29. package/src/lib/checkIfPortOccupied.js +29 -0
  30. package/src/lib/dev/getFilesToBuild.js +1 -1
  31. package/src/lib/dev/hmrServer.js +78 -0
  32. package/src/lib/dev/index.js +146 -60
  33. package/src/lib/dev/loadSettings.js +12 -4
  34. package/src/lib/dev/runTests.js +67 -18
  35. package/src/lib/dev/startApp.js +6 -4
  36. package/src/lib/dev/tests.config.js +9 -0
  37. package/src/lib/regexes.js +1 -0
@@ -1,7 +1,6 @@
1
1
  {
2
- "name": "@joystick.js/cli",
3
- "version": "1.0.0-beta.71",
4
- "developmentVersion": "1.0.0-beta.1695",
2
+ "name": "@joystick.js/cli-canary",
3
+ "version": "0.0.0-canary.239",
5
4
  "type": "module",
6
5
  "description": "CLI for the Joystick JavaScript framework.",
7
6
  "main": "development.js",
@@ -221,21 +221,26 @@ var functions_default = {
221
221
  set: !!rawArgs.includes("test"),
222
222
  description: "Start an existing Joystick app and run its tests.",
223
223
  args: {
224
- w: {
225
- set: !!rawArgs.includes("w") && !!rawArgs[rawArgs.indexOf("w") + 1],
226
- parent: "w",
227
- value: !!rawArgs.includes("w") && rawArgs[rawArgs.indexOf("w") + 1],
228
- description: "Run joystick test in watch mode."
229
- },
230
224
  watch: {
231
- set: !!rawArgs.includes("watch") && !!rawArgs[rawArgs.indexOf("watch") + 1],
232
- parent: "watch",
233
- value: !!rawArgs.includes("watch") && rawArgs[rawArgs.indexOf("watch") + 1],
225
+ set: !!rawArgs.includes("watch"),
226
+ parent: "test",
227
+ value: !!rawArgs.includes("watch"),
234
228
  description: "Run joystick test in watch mode."
235
229
  }
236
230
  },
237
- options: {},
238
- function: test()
231
+ options: {
232
+ watch: {
233
+ flags: {
234
+ "--watch": {
235
+ set: !!rawArgs.includes("--watch"),
236
+ value: !!rawArgs.includes("--watch"),
237
+ parent: "test"
238
+ }
239
+ },
240
+ description: "Environment to set for process.env.NODE_ENV."
241
+ }
242
+ },
243
+ function: test
239
244
  },
240
245
  update: {
241
246
  set: !!rawArgs.includes("update"),
@@ -1,23 +1,4 @@
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
- };
21
2
  var start_default = async (args = {}, options = {}) => {
22
3
  await dev({
23
4
  environment: args?.environment || "development",
@@ -3,7 +3,8 @@ var test_default = async (args = {}, options = {}) => {
3
3
  await dev({
4
4
  environment: "test",
5
5
  process,
6
- port: 1977
6
+ port: 1977,
7
+ watch: options?.watch
7
8
  });
8
9
  };
9
10
  export {
@@ -1,6 +1,7 @@
1
1
  import getPlatformSafePath from "../getPlatformSafePath.js";
2
2
  var browserPathExclusions_default = [
3
- getPlatformSafePath("lib/node")
3
+ getPlatformSafePath("lib/node"),
4
+ getPlatformSafePath("tests/")
4
5
  ];
5
6
  export {
6
7
  browserPathExclusions_default as default
@@ -12,6 +12,10 @@ import getCodeFrame from "./getCodeFrame.js";
12
12
  import onWarn from "./onWarn.js";
13
13
  const handleBuildException = (exception = {}, file = "") => {
14
14
  try {
15
+ console.warn({
16
+ exception,
17
+ file
18
+ });
15
19
  const error = exception?.errors && exception?.errors[0];
16
20
  const snippet = fs.existsSync(file) ? getCodeFrame(file, {
17
21
  line: error?.location?.line,
@@ -28,7 +32,7 @@ const handleBuildException = (exception = {}, file = "") => {
28
32
  });
29
33
  return snippet;
30
34
  } catch (exception2) {
31
- throw new Error(`[actionName.handleBuildException] ${exception2.message}`);
35
+ throw new Error(`[buildFiles.handleBuildException] ${exception2.message}`);
32
36
  }
33
37
  };
34
38
  const handleParseFilePathFromException = (exception = {}) => {
@@ -36,18 +40,20 @@ const handleParseFilePathFromException = (exception = {}) => {
36
40
  const rawErrorMessage = exception?.message?.split(":");
37
41
  return rawErrorMessage[1] && rawErrorMessage[1]?.replace("\n", "") || "";
38
42
  } catch (exception2) {
39
- throw new Error(`[actionName.handleParseFilePathFromException] ${exception2.message}`);
43
+ throw new Error(`[buildFiles.handleParseFilePathFromException] ${exception2.message}`);
40
44
  }
41
45
  };
42
46
  const handleBuildForNode = (nodePaths2 = [], options = {}) => {
43
47
  try {
44
48
  return esbuild.build({
49
+ allowOverwrite: true,
45
50
  platform: "node",
46
51
  format: "esm",
47
52
  bundle: false,
48
53
  entryPoints: nodePaths2?.map((file) => file.path),
49
- // TODO: Make sure we don't need outbase here so the paths map correctly.
54
+ entryNames: "[dir]/[name]",
50
55
  outdir: options?.outputPath || "./.joystick/build",
56
+ outbase: "./",
51
57
  define: {
52
58
  "process.env.NODE_ENV": `'${options?.environment}'`
53
59
  },
@@ -64,11 +70,14 @@ const handleBuildForNode = (nodePaths2 = [], options = {}) => {
64
70
  const handleBuildForBrowser = (browserPaths2 = [], options = {}) => {
65
71
  try {
66
72
  return esbuild.build({
73
+ allowOverwrite: true,
67
74
  target: "es2020",
68
75
  platform: "browser",
69
76
  format: "esm",
70
77
  bundle: true,
71
78
  entryPoints: browserPaths2?.map((file) => file.path),
79
+ entryNames: "[dir]/[name]",
80
+ outbase: "./",
72
81
  // TODO: Make sure we don't need outbase here so the paths map correctly.
73
82
  outdir: options?.outputPath || "./.joystick/build",
74
83
  define: {
@@ -197,7 +206,6 @@ const buildFiles = async (options, { resolve, reject }) => {
197
206
  return { success: true };
198
207
  }).catch((exception) => {
199
208
  const file = handleParseFilePathFromException(exception);
200
- console.log(file, exception);
201
209
  const snippet = handleBuildException(exception, file);
202
210
  return {
203
211
  success: false,
@@ -5,11 +5,13 @@ import {
5
5
  JOYSTICK_UI_REGEX,
6
6
  EXPORT_DEFAULT_REGEX,
7
7
  JOYSTICK_COMPONENT_REGEX,
8
- JOYSTICK_COMMENT_REGEX
8
+ JOYSTICK_COMMENT_REGEX,
9
+ EXAMPLE_CODE_REGEX
9
10
  } from "../regexes.js";
10
11
  import generateId from "../generateId.js";
11
12
  import getPlatformSafePath from "../getPlatformSafePath.js";
12
13
  import setComponentId from "./setComponentId.js";
14
+ import replaceExamples from "./replaceExamples.js";
13
15
  var buildPlugins_default = {
14
16
  bootstrapComponent: {
15
17
  name: "bootstrapComponent",
@@ -17,7 +19,7 @@ var buildPlugins_default = {
17
19
  const ssrId = generateId();
18
20
  build.onLoad({ filter: /\.js$/ }, (args = {}) => {
19
21
  try {
20
- const shouldSetSSRId = [getPlatformSafePath("ui/")].some(
22
+ const shouldSetComponentId = [getPlatformSafePath("ui/")].some(
21
23
  (bootstrapTarget) => {
22
24
  return args.path.includes(bootstrapTarget);
23
25
  }
@@ -37,7 +39,7 @@ var buildPlugins_default = {
37
39
  return args.path.includes(bootstrapTarget);
38
40
  }
39
41
  );
40
- if (shouldSetSSRId || isLayoutComponent || isPageComponent || isEmailComponent) {
42
+ if (shouldSetComponentId || isLayoutComponent || isPageComponent || isEmailComponent) {
41
43
  const code = fs.readFileSync(
42
44
  getPlatformSafePath(args.path),
43
45
  "utf-8"
@@ -56,7 +58,9 @@ var buildPlugins_default = {
56
58
  console.log(" ");
57
59
  return;
58
60
  }
59
- let contents = setComponentId(code)?.replace(
61
+ const examples = code.match(EXAMPLE_CODE_REGEX) || [];
62
+ let contents = replaceExamples(code);
63
+ contents = contents?.replace(
60
64
  /\.component\(\/\*\*\//g,
61
65
  ".component("
62
66
  );
@@ -103,6 +107,10 @@ var buildPlugins_default = {
103
107
  `
104
108
  );
105
109
  }
110
+ for (let i = 0; i < examples?.length; i += 1) {
111
+ const exampleToRestore = examples[i];
112
+ contents = contents.replace(`%example:${i}%`, exampleToRestore);
113
+ }
106
114
  return {
107
115
  contents,
108
116
  loader: "js"
@@ -125,11 +133,17 @@ var buildPlugins_default = {
125
133
  if (shouldSetComponentId) {
126
134
  const file = fs.readFileSync(`${build?.initialOptions?.outdir}/${entryPoint}`, "utf-8");
127
135
  const joystickUIMatches = file?.match(JOYSTICK_COMPONENT_REGEX) || [];
136
+ const examples = file.match(EXAMPLE_CODE_REGEX) || [];
137
+ let contents = replaceExamples(file);
128
138
  if (joystickUIMatches?.length > 0) {
129
- let contents = setComponentId(file)?.replace(
139
+ contents = setComponentId(contents)?.replace(
130
140
  /\.component\(\/\*\*\//g,
131
141
  ".component("
132
142
  );
143
+ for (let i2 = 0; i2 < examples?.length; i2 += 1) {
144
+ const exampleToRestore = examples[i2];
145
+ contents = contents.replace(`%example:${i2}%`, exampleToRestore);
146
+ }
133
147
  fs.writeFileSync(`${build?.initialOptions?.outdir}/${entryPoint}`, contents);
134
148
  }
135
149
  }
@@ -4,6 +4,7 @@ var nodePaths_default = [
4
4
  getPlatformSafePath("routes/"),
5
5
  getPlatformSafePath("fixtures/"),
6
6
  getPlatformSafePath("lib/node"),
7
+ getPlatformSafePath("tests/"),
7
8
  "index.server.js"
8
9
  ];
9
10
  export {
@@ -0,0 +1,13 @@
1
+ import { EXAMPLE_CODE_REGEX } from "../regexes.js";
2
+ var replaceExamples_default = (code = "") => {
3
+ let exampleIndex = 0;
4
+ return code.replace(
5
+ EXAMPLE_CODE_REGEX,
6
+ () => {
7
+ return `%example:${exampleIndex++}%`;
8
+ }
9
+ );
10
+ };
11
+ export {
12
+ replaceExamples_default as default
13
+ };
@@ -0,0 +1,27 @@
1
+ import net from "net";
2
+ const resetClient = (client = {}) => {
3
+ client.end();
4
+ client.destroy();
5
+ client.unref();
6
+ };
7
+ var checkIfPortOccupied_default = (port = 2600) => {
8
+ return new Promise((resolve) => {
9
+ const client = new net.Socket();
10
+ client.once("connect", () => {
11
+ resetClient(client);
12
+ resolve(true);
13
+ });
14
+ client.once("error", () => {
15
+ resetClient(client);
16
+ resolve(false);
17
+ });
18
+ client.connect({
19
+ port,
20
+ host: "127.0.0.1"
21
+ }, function() {
22
+ });
23
+ });
24
+ };
25
+ export {
26
+ checkIfPortOccupied_default as default
27
+ };
@@ -30,7 +30,7 @@ var getFilesToBuild_default = (excludedPaths = [], context = null) => {
30
30
  return path.includes(excludedPath);
31
31
  });
32
32
  }).filter((path) => {
33
- return !fs.lstatSync(path).isDirectory();
33
+ return fs.existsSync(path) && !fs.lstatSync(path).isDirectory();
34
34
  });
35
35
  };
36
36
  export {
@@ -0,0 +1,66 @@
1
+ import fs from "fs";
2
+ import { WebSocketServer } from "ws";
3
+ import generateId from "../generateId.js";
4
+ var hmrServer_default = (() => {
5
+ const websocketServer = new WebSocketServer({
6
+ port: parseInt(process.env.PORT, 10) + 1,
7
+ path: "/_joystick/hmr"
8
+ });
9
+ process.on("message", (message) => {
10
+ if (typeof process.HMR_CONNECTIONS === "object") {
11
+ const parsedMessage = JSON.parse(message);
12
+ const connections = Object.values(process.HMR_CONNECTIONS);
13
+ for (let i = 0; i < connections?.length; i += 1) {
14
+ const connection = connections[i];
15
+ if (connection?.connection?.send) {
16
+ connection.connection.send(
17
+ JSON.stringify({
18
+ type: "FILE_CHANGE",
19
+ settings: {
20
+ global: parsedMessage?.settings?.global,
21
+ public: parsedMessage?.settings?.public
22
+ },
23
+ indexHTMLChanged: parsedMessage?.indexHTMLChanged
24
+ })
25
+ );
26
+ }
27
+ }
28
+ }
29
+ });
30
+ websocketServer.on("connection", function connection(websocketConnection) {
31
+ const connectionId = generateId();
32
+ process.HMR_CONNECTIONS = {
33
+ ...process.HMR_CONNECTIONS || {},
34
+ [connectionId]: {
35
+ connection: websocketConnection,
36
+ watchlist: []
37
+ }
38
+ };
39
+ if (Object.keys(process.HMR_CONNECTIONS || {})?.length > 0) {
40
+ process.send({ type: "HAS_HMR_CONNECTIONS" });
41
+ }
42
+ websocketConnection.on("message", (message) => {
43
+ const parsedMessage = JSON.parse(message);
44
+ if (parsedMessage?.type === "HMR_UPDATE_COMPLETE") {
45
+ process.send({ type: "HMR_UPDATE_COMPLETED", sessions: parsedMessage?.sessions });
46
+ }
47
+ if (parsedMessage?.type === "HMR_WATCHLIST") {
48
+ process.HMR_CONNECTIONS[connectionId]?.watchlist?.push(
49
+ ...parsedMessage?.tags || []
50
+ );
51
+ }
52
+ });
53
+ websocketConnection.on("close", () => {
54
+ if (process.HMR_CONNECTIONS[connectionId]) {
55
+ delete process.HMR_CONNECTIONS[connectionId];
56
+ if (Object.keys(process.HMR_CONNECTIONS || {})?.length === 0) {
57
+ process.send({ type: "HAS_NO_HMR_CONNECTIONS" });
58
+ }
59
+ }
60
+ });
61
+ });
62
+ return true;
63
+ })();
64
+ export {
65
+ hmrServer_default as default
66
+ };