@asd14/vblocks 6.1.0 → 6.2.0

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.
@@ -4,6 +4,7 @@ import fs from "node:fs"
4
4
  import { createRequire } from "node:module"
5
5
  import path from "node:path"
6
6
  import "webpack-dev-server"
7
+ import { buildLogger } from "@asd14/fancy-logger/node"
7
8
  import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin"
8
9
  import CopyPlugin from "copy-webpack-plugin"
9
10
  import DotenvPlugin from "dotenv-webpack"
@@ -12,6 +13,8 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin"
12
13
  import webpack from "webpack"
13
14
  import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer"
14
15
 
16
+ const logger = buildLogger({ namespace: "vblocks", level: "info" })
17
+
15
18
  /**
16
19
  * Read the SWC config, set the browser targets it lacks, and turn on React
17
20
  * Refresh when `hasReactRefresh` is true
@@ -26,6 +29,10 @@ const loadSwcConfig = (path, { hasReactRefresh }) => {
26
29
 
27
30
  return {
28
31
  ...typedConfig,
32
+ // VBlocks picks one .swcrc, from the app folder or its defaults. Without
33
+ // this, SWC also reads the .swcrc of the folder VBlocks runs in, eg. the
34
+ // package around the app
35
+ swcrc: false,
29
36
  env: {
30
37
  targets: "> 0.25%, not dead",
31
38
  ...typedConfig.env,
@@ -104,17 +111,6 @@ const getCssLoaders = ({ classScope, isProduction, postcssConfigPath }) => [
104
111
  },
105
112
  ]
106
113
 
107
- /**
108
- * Print one line of VBlocks: a verb, then its subject. The `[vblocks]` prefix
109
- * lets the reader tell it apart from the lines of Webpack
110
- *
111
- * @param {string} verb
112
- * @param {string} subject
113
- */
114
- const log = (verb, subject) => {
115
- process.stdout.write(`[vblocks] ${verb.padEnd(7)} ${subject}\n`)
116
- }
117
-
118
114
  /**
119
115
  * Serve prints at most this many files per compile, then a count of the rest
120
116
  */
@@ -130,7 +126,7 @@ const MAX_REPORTED_FILE_EVENTS = 5
130
126
  const reportFileEvents = appDir => compiler => {
131
127
  /** @type {Set<string> | undefined} */
132
128
  let previousFiles
133
- /** @type {Array<[string, string]>} */
129
+ /** @type {Array<["Updated" | "Added" | "Dropped", string]>} */
134
130
  let fileEvents = []
135
131
 
136
132
  // The watcher also reports editor swap files and folders, eg. the src/ that
@@ -142,11 +138,11 @@ const reportFileEvents = appDir => compiler => {
142
138
  previousFiles?.has(file) &&
143
139
  fs.statSync(file, { throwIfNoEntry: false })?.isFile()
144
140
  ) {
145
- fileEvents.push(["update", file])
141
+ fileEvents.push(["Updated", file])
146
142
  }
147
143
  }
148
144
  for (const file of watcher.removedFiles ?? []) {
149
- if (previousFiles?.has(file)) fileEvents.push(["drop", file])
145
+ if (previousFiles?.has(file)) fileEvents.push(["Dropped", file])
150
146
  }
151
147
  })
152
148
 
@@ -161,15 +157,20 @@ const reportFileEvents = appDir => compiler => {
161
157
  .filter(file => !file.includes("/node_modules/"))
162
158
  .toSorted()
163
159
 
164
- for (const file of addedFiles) fileEvents.push(["add", file])
160
+ for (const file of addedFiles) {
161
+ fileEvents.push(["Added", file])
162
+ }
165
163
  }
166
164
  previousFiles = files
167
165
 
168
- for (const [verb, file] of fileEvents.slice(0, MAX_REPORTED_FILE_EVENTS)) {
169
- log(verb, file.replace(appDir, "$APP_DIR"))
166
+ const nextFileEvents = fileEvents.slice(0, MAX_REPORTED_FILE_EVENTS)
167
+ for (const [message, file] of nextFileEvents) {
168
+ logger.info(message, { file: file.replace(appDir, "$APP_DIR") })
170
169
  }
171
170
  if (fileEvents.length > MAX_REPORTED_FILE_EVENTS) {
172
- log("…", `and ${fileEvents.length - MAX_REPORTED_FILE_EVENTS} more`)
171
+ logger.info("More files", {
172
+ count: fileEvents.length - MAX_REPORTED_FILE_EVENTS,
173
+ })
173
174
  }
174
175
  })
175
176
  }
@@ -441,10 +442,14 @@ export default (
441
442
  if (typeof address !== "object" || address === null) return
442
443
 
443
444
  const { port } = address
444
- log("serve", `http://localhost:${port}`)
445
+ logger.info("Started the server", {
446
+ url: `http://localhost:${port}`,
447
+ })
445
448
 
446
449
  if (developmentServer.options.host !== "localhost") {
447
- log("expose", `${developmentServer.options.host}:${port}`)
450
+ logger.info("Exposed the server to the network", {
451
+ address: `${developmentServer.options.host}:${port}`,
452
+ })
448
453
  }
449
454
  },
450
455
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@asd14/vblocks",
4
- "version": "6.1.0",
4
+ "version": "6.2.0",
5
5
  "description": "Zero-config React builds, as a static site or a single HTML file",
6
6
  "keywords": [
7
7
  "react",
@@ -61,22 +61,23 @@
61
61
  "unit-test": "npm run unit-test:template"
62
62
  },
63
63
  "dependencies": {
64
+ "@asd14/fancy-logger": "^2.0.0",
64
65
  "@mdx-js/loader": "^3.1.1",
65
66
  "@pmmmwh/react-refresh-webpack-plugin": "^0.6.3",
66
67
  "@swc/helpers": "^0.5.23",
67
- "browserslist": "^4.29.4",
68
+ "browserslist": "^4.29.5",
68
69
  "copy-webpack-plugin": "^14.0.0",
69
70
  "css-loader": "^7.1.5",
70
71
  "cssnano": "^9.9.0",
71
72
  "dotenv-webpack": "^9.0.0",
72
73
  "html-webpack-plugin": "^5.6.8",
73
74
  "mini-css-extract-plugin": "^2.10.2",
74
- "postcss": "^8.5.31",
75
+ "postcss": "^8.5.32",
75
76
  "postcss-loader": "^8.2.1",
76
77
  "postcss-preset-env": "^11.6.1",
77
78
  "react-refresh": "^0.19.0",
78
79
  "swc-loader": "^0.2.7",
79
- "webpack": "^5.112.1",
80
+ "webpack": "^5.112.2",
80
81
  "webpack-bundle-analyzer": "^5.4.0",
81
82
  "webpack-cli": "^7.2.3",
82
83
  "webpack-dev-server": "^6.1.0"