bun_bun_bundle 0.3.7 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98a722ea47a9c3376749b1db05818efb82f8cba273785d4c44e84a250b7a2b31
4
- data.tar.gz: f6c2344f88eaf01de284d045dc5b8c3c9558c96ebf8b34f87de9c0accab8aef4
3
+ metadata.gz: 4337760da846f05fed302c7aa1da9767ed8f26d0ae1eaabf3f550d79670a0542
4
+ data.tar.gz: f057d109b5f3b89a72b63b4ae0c1022fb9cc71cc4d0aa2a4ba53c03aec9366bf
5
5
  SHA512:
6
- metadata.gz: f4069cbc3d7fb25acba0545c9966d465a3763e472065c34eed0bf2216e75792a2430389ae7a421c1d4caae2fbdb5f10cd07c90fc58b2bb955d99af7cf3418597
7
- data.tar.gz: 48d6a7b3a6bf8628497586a8a985292ea913387974990d8cb10d90e48791e687197d52be8f5c2e6e2de77e59e31139b97b33ff9880478de4cffec65b4cc7c2cb
6
+ metadata.gz: 98d7a220fd690cb23664ff8589c0915bfa31d476e6d864127f4f7ae6a8d9ea9277fdb25b25b8d3c158218125f2c68ac5a10cd9db3e8723b4e92f2c23fa4ad264
7
+ data.tar.gz: a7b2ea22fbe70b7077de804b4bdd597bdabaf53bc730b251d825e0e94d8d67e43799f66ba4e840191532e0a68f4ea64633cee6eec2be8bba86f613d3629664cf
data/README.md CHANGED
@@ -14,6 +14,9 @@ Works with Rails, Hanami, or any Rack app.
14
14
  - **Extensible.** Plugins are simple, tiny JavaScript files.
15
15
  - **One dependency: Bun.** Everything is included, no other dev dependencies.
16
16
 
17
+ [![CI](https://codeberg.org/w0u7/bun_bun_bundle/actions/workflows/test.yml/badge.svg)](https://codeberg.org/w0u7/bun_bun_bundle/actions?workflow=test.yml)
18
+ [![Gem Version](https://badge.fury.io/rb/bun_bun_bundle.svg)](https://rubygems.org/gems/bun_bun_bundle)
19
+
17
20
  > [!Note]
18
21
  > The original repository is hosted at
19
22
  > [Codeberg](https://codeberg.org/w0u7/bun_bun_bundle). The [GitHub
@@ -152,6 +155,15 @@ All tag helpers accept additional HTML attributes:
152
155
  <%= bun_img_tag('images/logo.png', alt: 'My App', class: 'logo') %>
153
156
  ```
154
157
 
158
+ Data and aria attributes can be passed as nested hashes (Rails-style) or with
159
+ underscores (Lucky-style). Underscores are converted to hyphens automatically:
160
+
161
+ ```erb
162
+ <%= bun_js_tag('js/app.js', data: { turbo_track: "reload" }) %>
163
+ <%= bun_js_tag('js/app.js', data_turbo_track: "reload") %>
164
+ <%# Both render: data-turbo-track="reload" %>
165
+ ```
166
+
155
167
  ## CLI
156
168
 
157
169
  Build your assets using the bundled CLI (`bbb` is available as a shorter
@@ -161,11 +173,14 @@ alias):
161
173
  # Development: builds, watches, and starts the live reload server
162
174
  bun_bun_bundle dev
163
175
 
164
- # Production: builds with fingerprinting and minification
176
+ # Build assets
165
177
  bun_bun_bundle build
166
178
 
167
- # Development with a production build (fingerprinting + minification)
168
- bun_bun_bundle dev --prod
179
+ # Build with fingerprinting and minification
180
+ bun_bun_bundle build --prod
181
+
182
+ # Development with verbose WebSocket logging
183
+ bun_bun_bundle dev --debug
169
184
  ```
170
185
 
171
186
  > [!NOTE]
@@ -384,7 +399,7 @@ COPY package.json bun.lock ./
384
399
  RUN bun install --frozen-lockfile
385
400
 
386
401
  COPY . .
387
- RUN bundle exec bun_bun_bundle build
402
+ RUN bundle exec bun_bun_bundle build --prod
388
403
  ```
389
404
 
390
405
  > [!NOTE]
@@ -411,7 +426,9 @@ It's also fast and reliable. We use this setup heavily in two Lucky apps and it
411
426
  is rock solid. It has since been adopted by Lucky as the default builder.
412
427
 
413
428
  This Gem was born because I wanted to have the same setup in my Ruby apps as
414
- well. I hope you enjoy it too!
429
+ well. We now use it for an important Rails app in production.
430
+
431
+ I hope you enjoy it too!
415
432
 
416
433
  ## Contributing
417
434
 
data/exe/bun_bun_bundle CHANGED
@@ -12,23 +12,23 @@ case command
12
12
  when 'dev', 'watch'
13
13
  exec('bun', 'run', bake, '--dev', *flags)
14
14
  when 'build'
15
- exec('bun', 'run', bake, '--prod', *flags)
15
+ exec('bun', 'run', bake, *flags)
16
16
  else
17
17
  puts <<~USAGE
18
18
  Usage: bun_bun_bundle <command> [flags]
19
19
 
20
20
  Commands:
21
21
  dev Start development server with live reload and CSS hot-reloading
22
- build Build assets for production (with fingerprinting)
22
+ build Build assets
23
23
 
24
24
  Flags:
25
- --prod Enable fingerprinting and minification
26
- --dev Enable source maps and watch mode
25
+ --prod Enable minification and fingerprinting
26
+ --debug Enable verbose WebSocket logging
27
27
 
28
28
  Examples:
29
- bun_bun_bundle dev # development with live reload
30
- bun_bun_bundle dev --prod # development with production build
31
- bun_bun_bundle build # production build
29
+ bun_bun_bundle dev # development with live reload
30
+ bun_bun_bundle build # build assets
31
+ bun_bun_bundle build --prod # build with fingerprinting and minification
32
32
 
33
33
  Configuration:
34
34
  Place a config/bun.json in your project root to customize settings.
data/lib/bun/bake.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import BunBunBundle from "./bun_bundle.js";
2
2
 
3
3
  BunBunBundle.flags({
4
+ debug: process.argv.includes("--debug"),
4
5
  dev: process.argv.includes("--dev"),
5
6
  prod: process.argv.includes("--prod"),
6
7
  });
@@ -18,13 +18,15 @@ export default {
18
18
  root: process.cwd(),
19
19
  config: null,
20
20
  manifest: {},
21
+ debug: false,
21
22
  dev: false,
22
23
  prod: false,
23
24
  wsClients: new Set(),
24
25
  watchTimers: new Map(),
25
26
  plugins: [],
26
27
 
27
- flags({dev, prod}) {
28
+ flags({debug, dev, prod}) {
29
+ if (debug != null) this.debug = debug
28
30
  if (dev != null) this.dev = dev
29
31
  if (prod != null) this.prod = prod
30
32
  },
@@ -87,7 +89,8 @@ export default {
87
89
  const outDir = join(this.outDir, type)
88
90
  mkdirSync(outDir, {recursive: true})
89
91
 
90
- const entries = this.config.entryPoints[type]
92
+ const raw = this.config.entryPoints[type]
93
+ const entries = Array.isArray(raw) ? raw : [raw]
91
94
  const ext = `.${type}`
92
95
 
93
96
  for (const entry of entries) {
@@ -266,6 +269,7 @@ export default {
266
269
  await this.watch()
267
270
 
268
271
  const {host, port, secure} = this.config.devServer
272
+ const debug = this.debug
269
273
  const wsClients = this.wsClients
270
274
 
271
275
  Bun.serve({
@@ -278,11 +282,11 @@ export default {
278
282
  websocket: {
279
283
  open(ws) {
280
284
  wsClients.add(ws)
281
- console.log(` ▸ Client connected (${wsClients.size})\n\n`)
285
+ if (debug) console.log(` ▸ Client connected (${wsClients.size})\n\n`)
282
286
  },
283
287
  close(ws) {
284
288
  wsClients.delete(ws)
285
- console.log(` ▸ Client disconnected (${wsClients.size})\n\n`)
289
+ if (debug) console.log(` ▸ Client disconnected (${wsClients.size})\n\n`)
286
290
  },
287
291
  message() {}
288
292
  }
@@ -20,7 +20,8 @@ function transformPipeline(type, transforms) {
20
20
  let content = await Bun.file(args.path).text()
21
21
  for (const transform of transforms)
22
22
  content = await transform(content, args)
23
- return {contents: content, loader: type}
23
+ const ext = args.path.split('.').pop()
24
+ return {contents: content, loader: ext}
24
25
  })
25
26
  }
26
27
  }
@@ -28,8 +28,8 @@ module BunBunBundle
28
28
  attr_reader :js, :css
29
29
 
30
30
  def initialize(data = {})
31
- @js = data.fetch('js', %w[app/assets/js/app.js])
32
- @css = data.fetch('css', %w[app/assets/css/app.css])
31
+ @js = Array(data.fetch('js', %w[app/assets/js/app.js]))
32
+ @css = Array(data.fetch('css', %w[app/assets/css/app.css]))
33
33
  end
34
34
  end
35
35
 
@@ -35,7 +35,7 @@ module BunBunBundle
35
35
  def bun_js_tag(source, **options)
36
36
  src = bun_asset(source)
37
37
  attrs = { type: 'text/javascript' }.merge(options).merge(src: src)
38
- _bun_safe(%(<script #{_bun_html_attrs(attrs)}></script>))
38
+ bun_safe(%(<script #{bun_html_attrs(attrs)}></script>))
39
39
  end
40
40
 
41
41
  # Generates a <link> tag for a CSS entry point.
@@ -46,7 +46,7 @@ module BunBunBundle
46
46
  def bun_css_tag(source, **options)
47
47
  href = bun_asset(source)
48
48
  attrs = { type: 'text/css', rel: 'stylesheet' }.merge(options).merge(href: href)
49
- _bun_safe(%(<link #{_bun_html_attrs(attrs)}>))
49
+ bun_safe(%(<link #{bun_html_attrs(attrs)}>))
50
50
  end
51
51
 
52
52
  # Generates an <img> tag for an image asset.
@@ -58,18 +58,30 @@ module BunBunBundle
58
58
  src = bun_asset(source)
59
59
  alt = options.delete(:alt) || File.basename(source, '.*').tr('-_', ' ').capitalize
60
60
  attrs = { alt: alt }.merge(options).merge(src: src)
61
- _bun_safe(%(<img #{_bun_html_attrs(attrs)}>))
61
+ bun_safe(%(<img #{bun_html_attrs(attrs)}>))
62
62
  end
63
63
 
64
64
  private
65
65
 
66
- def _bun_html_attrs(hash)
67
- hash.compact.map do |k, v|
68
- v == true ? k.to_s : %(#{k}="#{_bun_escape_attr(v)}")
66
+ def bun_html_attrs(hash)
67
+ bun_flatten_attrs(hash).compact.map do |k, v|
68
+ k = k.to_s.tr('_', '-')
69
+ v == true ? k : %(#{k}="#{bun_escape_attr(v)}")
69
70
  end.join(' ')
70
71
  end
71
72
 
72
- def _bun_escape_attr(value)
73
+ def bun_flatten_attrs(hash, prefix: nil)
74
+ hash.each_with_object({}) do |(k, v), flat|
75
+ key = prefix ? :"#{prefix}_#{k}" : k
76
+ if v.is_a?(Hash)
77
+ flat.merge!(bun_flatten_attrs(v, prefix: key))
78
+ else
79
+ flat[key] = v
80
+ end
81
+ end
82
+ end
83
+
84
+ def bun_escape_attr(value)
73
85
  value.to_s.gsub('&', '&amp;').gsub('"', '&quot;').gsub('<', '&lt;').gsub('>', '&gt;')
74
86
  end
75
87
  end
@@ -58,7 +58,7 @@ module BunBunBundle
58
58
  })()
59
59
  </script>
60
60
  HTML
61
- _bun_safe(html)
61
+ bun_safe(html)
62
62
  end
63
63
  end
64
64
  end
@@ -5,9 +5,9 @@ module BunBunBundle
5
5
  private
6
6
 
7
7
  if String.method_defined?(:html_safe)
8
- def _bun_safe(html) = html.html_safe
8
+ def bun_safe(html) = html.html_safe
9
9
  else
10
- def _bun_safe(html) = html
10
+ def bun_safe(html) = html
11
11
  end
12
12
  end
13
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BunBunBundle
4
- VERSION = '0.3.7'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bun_bun_bundle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wout Fierens