poops 1.9.1 → 1.9.3

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/README.md CHANGED
@@ -110,6 +110,7 @@ or pass a custom config. This is useful when you have multiple environments:
110
110
  | `--port <number>` | `-p` | Specify the server port, overrides config |
111
111
  | `--livereload-port <number>` | `-l` | Specify the livereload port, overrides config |
112
112
  | `--base-url <path>` | `-u` | Set the base URL prefix for markup, overrides config |
113
+ | `--quiet` | `-q` | Hide the header and the server/livereload info lines |
113
114
 
114
115
  The `--base-url` flag is particularly useful for CI/CD pipelines where the deploy path may differ per environment:
115
116
 
@@ -117,6 +118,14 @@ The `--base-url` flag is particularly useful for CI/CD pipelines where the deplo
117
118
  poops --build --base-url /blog
118
119
  ```
119
120
 
121
+ The `--quiet` flag drops the `💩 Poops — vX.Y.Z` header (and its terminal bell) plus the `Local server` / `Network` / `LiveReload` lines. Handy when you run several Poops instances side by side and only want to see which one is compiling:
122
+
123
+ ```bash
124
+ poops -q & poops -q -c site/poops.json
125
+ ```
126
+
127
+ Build logs, warnings and errors are unaffected — `--quiet` only removes the banner.
128
+
120
129
  If you have installed Poops locally you can run it with `npx poops` or `npx 💩` or add a script to your `package.json`:
121
130
 
122
131
  ```json
package/lib/server.js CHANGED
@@ -63,16 +63,25 @@ export function parseRange(header, size) {
63
63
  }
64
64
 
65
65
  export function createStaticHandler(base) {
66
+ // Drop any trailing separator — `serve.base: "/"` resolves to `<cwd>/`, and the
67
+ // containment check below would then compare against `<cwd>//` and reject everything
68
+ base = path.resolve(base)
66
69
  const notFoundPage = path.join(base, '404.html')
67
70
 
68
71
  const notFound = (res) => {
69
72
  res.statusCode = 404
70
- if (pathExists(notFoundPage)) {
71
- res.setHeader('Content-Type', 'text/html; charset=utf-8')
72
- fs.createReadStream(notFoundPage).on('error', () => res.destroy()).pipe(res)
73
- } else {
74
- res.end('Not Found')
73
+ if (!pathExists(notFoundPage)) return res.end('Not Found')
74
+ res.setHeader('Content-Type', 'text/html; charset=utf-8')
75
+ // 404.html lives at the site root but is served at any depth — its relative
76
+ // asset paths would resolve against /a/ for /a/b, so pin them with <base>
77
+ let html
78
+ try {
79
+ html = fs.readFileSync(notFoundPage, 'utf8')
80
+ } catch {
81
+ return res.end('Not Found')
75
82
  }
83
+ if (!/<base[\s>]/i.test(html)) html = html.replace(/<head([^>]*)>/i, '<head$1><base href="/">')
84
+ res.end(html)
76
85
  }
77
86
 
78
87
  return (req, res) => {
@@ -100,7 +109,13 @@ export function createStaticHandler(base) {
100
109
  try {
101
110
  stat = fs.statSync(filePath)
102
111
  } catch {
103
- return notFound(res)
112
+ // GitHub Pages-style extensionless URLs: /a/b serves a/b.html, URL unchanged
113
+ try {
114
+ stat = fs.statSync(filePath + '.html')
115
+ filePath += '.html'
116
+ } catch {
117
+ return notFound(res)
118
+ }
104
119
  }
105
120
 
106
121
  if (stat.isDirectory()) {
@@ -37,5 +37,7 @@ export default async function minifyToFile({ outfilePath, loader, code, banner,
37
37
  console.error(err)
38
38
  }
39
39
 
40
- if (options.justMinified) fs.unlinkSync(outfilePath)
40
+ // The unminified file only exists on disk when a compiler wrote it there —
41
+ // watch rebuilds pass `code` in memory and there is nothing to delete.
42
+ if (options.justMinified && pathExists(outfilePath)) fs.unlinkSync(outfilePath)
41
43
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "poops",
3
3
  "description": "Straightforward, no-bullshit bundler for the web.",
4
- "version": "1.9.1",
4
+ "version": "1.9.3",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "poops.js",
package/poops.js CHANGED
@@ -30,6 +30,7 @@ const cli = new Argoyle(pkg.version)
30
30
  .option('port', { short: 'p', value: '<number>', description: 'Specify the port for the server, overrides the config file' })
31
31
  .option('livereload-port', { short: 'l', value: '<number>', description: 'Specify the port for the livereload server, overrides the config file' })
32
32
  .option('base-url', { short: 'u', value: '<path>', description: 'Set the base URL prefix for markup, overrides the config file' })
33
+ .option('quiet', { short: 'q', description: 'Hide the header and the server/livereload info lines' })
33
34
 
34
35
  let flags, positionals
35
36
  try {
@@ -44,6 +45,7 @@ const defaultConfigPath = flags.config || positionals[0] || 'poops.json'
44
45
  const overridePort = flags.port
45
46
  const overrideLivereloadPort = flags['livereload-port']
46
47
  const overrideBaseURL = flags['base-url']
48
+ const quiet = flags.quiet // hides the header and the address lines only — build logs, warnings and errors still print
47
49
 
48
50
  let configPath = path.join(cwd, defaultConfigPath)
49
51
  if (!pathExists(configPath)) configPath = path.join(cwd, '💩.json') // the canonical alternative config name
@@ -107,7 +109,7 @@ const hook = (stage) => runExec(config, cwd, stage)
107
109
  function setupLiveReloadServer(config) {
108
110
  if (!config.livereload) return
109
111
  liveReloadServer = livereload.createServer({ port: config.livereload_port })
110
- styledLog(`🔃 {dim}LiveReload :{/} ${liveReloadServer.config.port}`)
112
+ if (!quiet) styledLog(`🔃 {dim}LiveReload :{/} ${liveReloadServer.config.port}`)
111
113
  console.log()
112
114
  }
113
115
 
@@ -296,8 +298,10 @@ async function poops() {
296
298
  }
297
299
 
298
300
  // CLI Header
299
- const title = `💩 Poops — v${pkg.version}`
300
- styledLog(`\n{#8b4513}${title}\n${title.replace(/./g, '-')}{/}{bell}\n`)
301
+ if (!quiet) {
302
+ const title = `💩 Poops — v${pkg.version}`
303
+ styledLog(`\n{#8b4513}${title}\n${title.replace(/./g, '-')}{/}{bell}\n`)
304
+ }
301
305
 
302
306
  // Check if poops.json exists
303
307
  if (!pathExists(configPath)) {
@@ -391,9 +395,11 @@ async function startServer() {
391
395
 
392
396
  // eslint-disable-next-line @stylistic/space-before-function-paren
393
397
  http.createServer(createStaticHandler(base)).listen(parseInt(port), '0.0.0.0', async () => {
394
- console.log()
395
- styledLog(`🏠 {dim}Local server:{/} {underline|http://localhost:${port}}`)
396
- styledLog(`🛜 {dim} Network :{/} {underline|http://${getLocalIP()}:${port}}`)
398
+ if (!quiet) {
399
+ console.log()
400
+ styledLog(`🏠 {dim}Local server:{/} {underline|http://localhost:${port}}`)
401
+ styledLog(`🛜 {dim} Network :{/} {underline|http://${getLocalIP()}:${port}}`)
402
+ }
397
403
  setupLiveReloadServer(config)
398
404
  })
399
405
  }