@substrate-system/debug 0.9.32 → 0.9.33

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 (2) hide show
  1. package/README.md +101 -6
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -21,15 +21,10 @@ It's been rewritten to use contemporary JS.
21
21
  In the browser, this uses localStorage key `'DEBUG'`.
22
22
  In Node, it uses the environment variable `DEBUG`.
23
23
 
24
- **Featuring:**
25
- * Use [exports](https://github.com/substrate-system/debug/blob/main/package.json#L31)
26
- field in `package.json` to choose node JS, browser, or cloudflare version
27
- * ESM or common JS
28
-
29
24
  Plus, [see the docs](https://substrate-system.github.io/debug/)
30
25
  generated by typescript.
31
26
 
32
- ## Contents
27
+ <details><summary><h2>Contents</h2></summary>
33
28
 
34
29
  <!-- toc -->
35
30
 
@@ -37,6 +32,7 @@ generated by typescript.
37
32
  - [Browser](#browser)
38
33
  * [Factor out of production](#factor-out-of-production)
39
34
  * [HTML `importmap`](#html-importmap)
35
+ * [Vite Example](#vite-example)
40
36
  - [Cloudflare](#cloudflare)
41
37
  - [Node JS](#node-js)
42
38
  - [Config](#config)
@@ -56,6 +52,8 @@ generated by typescript.
56
52
 
57
53
  <!-- tocstop -->
58
54
 
55
+ </details>
56
+
59
57
  ## Install
60
58
 
61
59
  ```sh
@@ -142,6 +140,103 @@ to your web server.
142
140
  > [!TIP]
143
141
  > Using a `data:` URL means no network request at all for the noop.
144
142
 
143
+
144
+ ### Vite Example
145
+
146
+ In `vite`, you can use the `transformIndexHtml` plugin to swap out the import
147
+ map depending on the environment at build time.
148
+
149
+ ```js
150
+ // vite.config.js
151
+ import { defineConfig } from 'vite'
152
+
153
+ // https://vitejs.dev/config/
154
+ export default defineConfig({
155
+ // ...
156
+ root: 'example',
157
+ plugins: [
158
+ {
159
+ name: 'html-transform',
160
+ transformIndexHtml (html) {
161
+ const isProduction = process.env.NODE_ENV === 'production'
162
+ const map = isProduction ?
163
+ '{ "imports": { "@substrate-system/debug": "data:text/javascript,export default function(){return()=>{}}" } }' :
164
+ '{ "imports": { "@substrate-system/debug": "../node_modules/@substrate-system/debug/dist/index.js" } }'
165
+
166
+ return html.replace('<%- IMPORT_MAP_CONTENT %>', map)
167
+ },
168
+ },
169
+ ],
170
+ // ...
171
+ })
172
+ ```
173
+
174
+ And the HTML:
175
+
176
+ ```html
177
+ <!DOCTYPE html>
178
+ <html lang="en">
179
+ <head>
180
+ <script type="importmap">
181
+ <%- IMPORT_MAP_CONTENT %>
182
+ </script>
183
+ </head>
184
+ ```
185
+
186
+ #### Staging Environment
187
+
188
+ For staging, you do still want the debug logs, but we need to copy the debug
189
+ file into our public directory so it is accessible to the web server.
190
+
191
+ ##### Vite Config
192
+
193
+ ```js
194
+ // vite.config.js
195
+ {
196
+ // ...
197
+ plugins: [
198
+ {
199
+ name: 'html-transform',
200
+ transformIndexHtml (html) {
201
+ const isProduction = process.env.NODE_ENV === 'production'
202
+ const isStaging = process.env.NODE_ENV === 'staging'
203
+
204
+ let map
205
+ if (isProduction && !isStaging) {
206
+ map = '{ "imports": { "@substrate-system/debug": "data:text/javascript,export default function(){return()=>{}}" } }'
207
+ } else if (isStaging) {
208
+ map = '{ "imports": { "@substrate-system/debug": "/vendor/debug.js" } }'
209
+ } else { // is dev
210
+ map = '{ "imports": { "@substrate-system/debug": "../node_modules/@substrate-system/debug/dist/index.js" } }'
211
+ }
212
+
213
+ return html.replace('<%- IMPORT_MAP_CONTENT %>', map)
214
+ },
215
+ },
216
+ ],
217
+ // ...
218
+ build: {
219
+ rollupOptions: {
220
+ external: ['@substrate-system/debug'],
221
+ },
222
+ }
223
+ // ...
224
+ }
225
+ ```
226
+
227
+ ##### Build script
228
+
229
+ Copy the file to the public directory.
230
+
231
+ ```sh
232
+ cp ./node_modules/@substrate-system/debug/dist/index.js ./public/vendor/debug.js
233
+
234
+ # then build
235
+ NODE_ENV=staging vite build
236
+ ```
237
+
238
+ -------------------
239
+
145
240
  ## Cloudflare
146
241
 
147
242
  Either pass in an env record, or will look at `globalThis` for
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@substrate-system/debug",
3
3
  "description": "Debug utility",
4
4
  "type": "module",
5
- "version": "0.9.32",
5
+ "version": "0.9.33",
6
6
  "main": "./dist/node/index.js",
7
7
  "files": [
8
8
  "./dist/*"
@@ -82,14 +82,14 @@
82
82
  "supports-color": "^10.0.0"
83
83
  },
84
84
  "devDependencies": {
85
- "@substrate-system/tapout": "^0.0.28",
85
+ "@substrate-system/tapout": "^0.0.30",
86
86
  "@substrate-system/tapzero": "^0.10.15",
87
87
  "@types/node": "^24.3.0",
88
88
  "@typescript-eslint/eslint-plugin": "^8.0.0",
89
89
  "@typescript-eslint/parser": "^8.0.0",
90
90
  "auto-changelog": "^2.4.0",
91
91
  "dotenv": "^17.2.1",
92
- "esbuild": "^0.25.9",
92
+ "esbuild": "^0.27.0",
93
93
  "eslint-config-standard": "^17.1.0",
94
94
  "http-server": "^14.1.1",
95
95
  "markdown-toc": "^1.2.0",