Needle Engine

Changes between version 3.38.0-alpha and 3.38.0-alpha.1
Files changed (1) hide show
  1. plugins/vite/server.js +9 -7
plugins/vite/server.js CHANGED
@@ -1,6 +1,3 @@
1
- import open from 'open'
2
- import { resolveConfig } from 'vite';
3
-
4
1
  /**
5
2
  * Can open the network server in the browser
6
3
  * @param {string} command
@@ -32,7 +29,7 @@
32
29
  /**
33
30
  * @param {import("vite").ViteDevServer} server
34
31
  */
35
- configureServer(server) {
32
+ async configureServer(server) {
36
33
  if (shouldOpenBrowser) {
37
34
  console.log('[needle:server] Waiting for server...')
38
35
  const i = setInterval(() => {
@@ -41,22 +38,27 @@
41
38
  if (resolvedUrls) {
42
39
  // stop trying when the urls are resolved
43
40
  clearInterval(i);
41
+ let urlToOpen = null;
44
42
  // check if the network urls are available and attempt to open the first one
45
43
  const networkUrls = resolvedUrls.network;
46
44
  if (Array.isArray(networkUrls) && networkUrls.length > 0) {
47
45
  const networkUrl = networkUrls[0];
48
46
  // perhaps we can just use the vite code here: https://github.com/vitejs/vite/blob/e861168f476b8cb278f599a0341076b0511c5264/packages/vite/src/node/server/openBrowser.ts#L72
49
47
  console.log('[needle:server] Opening network URL: ' + networkUrl)
50
- open(networkUrl);
48
+ urlToOpen = networkUrl;
51
49
  }
52
50
  else {
53
51
  const local = resolvedUrls.local;
54
52
  if (local?.length) {
55
53
  console.log('[needle:server] Opening local URL: ' + local)
56
- open(local);
54
+ urlToOpen = local;
57
55
  }
58
56
  }
59
-
57
+ import("open")
58
+ .then((mod) => {
59
+ mod.default(urlToOpen);
60
+ })
61
+ .catch((err) => console.error("ERR: [needle:server] 'open' package not found - please make sure to install 'open' in your package.json\n", err));
60
62
  }
61
63
  }, 100)
62
64
  }