mapshaper 0.7.3 → 0.7.5

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.
package/bin/mapshaper-gui CHANGED
@@ -16,6 +16,7 @@ var defaultPort = 5555,
16
16
  .option('-t, --target <name>', 'name of layer to select initially')
17
17
  .addOption(new commander.Option('-b, --blurb <text>',
18
18
  'replace the default blurb on the import screen').hideHelp())
19
+ .argument('[file...]', 'data files to load')
19
20
  .helpOption('-h, --help', 'show this help message')
20
21
  .version(require('../package.json').version)
21
22
  .parse(process.argv),
@@ -25,7 +26,6 @@ var defaultPort = 5555,
25
26
  url = require("url"),
26
27
  fs = require("fs"),
27
28
  Cookies = require("cookies"),
28
- opn = require("opn"),
29
29
  webRoot = path.join(__dirname, "../www"),
30
30
  port = parseInt(opts.port, 10) || defaultPort,
31
31
  dataFiles = expandShapefiles(program.args),
@@ -66,10 +66,24 @@ function startServer(port) {
66
66
  // block attempts to load files outside webroot
67
67
  serve404(response);
68
68
  } else if (uri == '/close') {
69
- // end process when page closes, unless page is immediately refreshed
69
+ // End process when page closes, unless page is immediately refreshed.
70
+ // The grace window (1500ms) gives the refreshed page time to send
71
+ // /cancel-close. A short window is not safe here: with sendBeacon,
72
+ // /close frequently arrives at the server *after* the new page's
73
+ // resource fetches have already been served, so we can't rely on
74
+ // those fetches to reset the timer for us.
70
75
  timeout = setTimeout(function() {
71
76
  process.exit(0);
72
- }, 200);
77
+ }, 1500);
78
+ response.writeHead(204); // no content
79
+ response.end();
80
+ } else if (uri == '/cancel-close') {
81
+ // The page-load-time refresh detection in src/gui/gui.mjs sends this
82
+ // when sessionStorage indicates the new page is a refresh of the
83
+ // previous tab incarnation. clearTimeout above already cancelled any
84
+ // pending exit; we just need to acknowledge the request.
85
+ response.writeHead(204);
86
+ response.end();
73
87
  } else if (uri == "/manifest.js") {
74
88
  if (!sessionId && opts.directSave) {
75
89
  // create a session id for authenticating requests to save files
@@ -86,14 +100,24 @@ function startServer(port) {
86
100
  } else if (uri.indexOf('/save') === 0) {
87
101
  saveContent(request, response);
88
102
  } else {
89
- // serve a file from the web root
90
- if (uri == '/') {
91
- uri = '/index.html';
103
+ // serve a file from the web root. Translate directory paths (any URI
104
+ // ending in '/') to their index.html so that links like '/docs/' work
105
+ // the way they do behind a normal static-file host (mapshaper.org).
106
+ if (uri.endsWith('/')) {
107
+ uri += 'index.html';
92
108
  }
93
109
  serveFile(getAssetFilePath(uri), response);
94
110
  }
95
111
  }).listen(port, 'localhost', function() {
96
- opn("http://localhost:" + port);
112
+ // `open` is ESM-only since v9, so import it dynamically from this CJS bin
113
+ // script. Failure to launch a browser is non-fatal: the user can still
114
+ // visit the URL printed (or implied) by the running server.
115
+ import('open').then(function(mod) {
116
+ return mod.default("http://localhost:" + port);
117
+ }).catch(function(err) {
118
+ console.error("Could not open browser automatically; visit http://localhost:" + port + " manually.");
119
+ console.error(err && err.message || err);
120
+ });
97
121
  });
98
122
  }
99
123