rbpacker 0.1.0 → 0.1.1

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: 410ba7f1086c8d7e44a58175948ac647d37c1216f9bf9ff487c2be39d8e15a8b
4
- data.tar.gz: f4e544f0ba31bbc8a115b7d12709ddf2041316b330c81ecdff1011b2986d46c8
3
+ metadata.gz: f6c38864c269ea044b828995c0da12fa77ad98297717e8e5f2ae3fd80702acd7
4
+ data.tar.gz: fbd666bd4eac674470cfa248961ddfcb4c33c25c21beeabe8b67682e69a0e8dd
5
5
  SHA512:
6
- metadata.gz: a1ca09bd6333ddb5a69bd91add85027b80e2768e5f1ed27cb24ba3f84b8256d86c880c5c32d2506e09be1ae9aaa08816c437efbbb4c10e66d162971f88cfedd6
7
- data.tar.gz: 30bbf1ceb126d5204d941fd077d5aa9849a3b877e7f3332ff4418546b3fbb0d0f30e1eb4b00e15f1dd80d3f736fdcc57248718305a995299be92e528a17b8c69
6
+ metadata.gz: 7235a25b7b59da4b254a4d22b8d1130c2cd3ead1e16f3a9a66364ad94cabc58e639478eca8f7629d6a5001e22a287e96dca976029708e35fac6302974a4209a0
7
+ data.tar.gz: 97e9b455076f32ae0c3a2a71a88ba62413942730ac775b4317afe43069093a796026d989c424dccfc072e2128041a43e55184e6cf150aec5aebb5f50a9e4712c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
- [full changelog](http://github.com/sue445/rbpacker/compare/v0.1.0...main)
2
+ [full changelog](http://github.com/sue445/rbpacker/compare/v0.1.1...main)
3
+
4
+ ## [0.1.1](https://github.com/sue445/rbpacker/releases/tag/v0.1.1) - 2026-09-08
5
+ [full changelog](http://github.com/sue445/rbpacker/compare/v0.1.0...v0.1.1)
6
+
7
+ * Strip leading comments from `require_relative` dependencies
8
+ * https://github.com/sue445/rbpacker/pull/18
3
9
 
4
10
  ## [0.1.0](https://github.com/sue445/rbpacker/releases/tag/v0.1.0) - 2026-09-08
5
11
 
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Rbpacker
2
2
  Bundles and minifies multiple Ruby scripts into a single file
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/rbpacker.svg)](https://badge.fury.io/rb/rbpacker)
4
5
  [![test](https://github.com/sue445/rbpacker/actions/workflows/test.yml/badge.svg)](https://github.com/sue445/rbpacker/actions/workflows/test.yml)
5
6
 
6
7
  ## Example
@@ -22,11 +22,14 @@ module Rbpacker
22
22
  (?=;|\n|\z)
23
23
  /x
24
24
 
25
+ LEADING_COMMENT_LINES_PATTERN = /\A(?<comments>(?:[ \t]*#.*\n)+)(?<blank_lines>(?:[ \t]*\n)*)/
26
+
25
27
  def initialize
26
28
  @loaded_files = Set.new
27
29
  @collected_sources = [] #: Array[String]
28
30
  @depth = 0
29
31
  @original_require_relative = Kernel.instance_method(:require_relative)
32
+ @entrypoint_comments_collected = false
30
33
  end
31
34
 
32
35
  # @param filepath [String]
@@ -96,12 +99,14 @@ module Rbpacker
96
99
  # @private
97
100
  def eval_and_collect_source(code, abs_path)
98
101
  source = strip_require_relative(code)
102
+ source = strip_magic_comment(source)
99
103
 
100
104
  TOPLEVEL_BINDING.eval(code, abs_path)
101
105
  @collected_sources << source unless source.strip.empty?
102
106
  end
103
107
 
104
108
  # @param code [String]
109
+ # @return [String]
105
110
  # @private
106
111
  def strip_require_relative(code)
107
112
  code.gsub(REQUIRE_RELATIVE_PATTERN) do
@@ -111,5 +116,21 @@ module Rbpacker
111
116
  match[:separator] == ";" ? ";" : ""
112
117
  end
113
118
  end
119
+
120
+ # @param code [String]
121
+ # @private
122
+ def strip_magic_comment(code)
123
+ code.sub(LEADING_COMMENT_LINES_PATTERN) do
124
+ match = Regexp.last_match
125
+ raise Error, "regexp match is not found" unless match
126
+
127
+ if @depth == 1 && !@entrypoint_comments_collected
128
+ @entrypoint_comments_collected = true
129
+ @collected_sources << "#{match[:comments]}#{match[:blank_lines]}"
130
+ end
131
+
132
+ ""
133
+ end
134
+ end
114
135
  end
115
136
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rbpacker
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -1,6 +1,7 @@
1
1
  module Rbpacker
2
2
  class SourceBundler
3
3
  REQUIRE_RELATIVE_PATTERN: Regexp
4
+ LEADING_COMMENT_LINES_PATTERN: Regexp
4
5
 
5
6
  def initialize: () -> void
6
7
  def bundle: (String filepath) -> SourceBundler
@@ -13,5 +14,6 @@ module Rbpacker
13
14
  def restore_require_relative: () -> void
14
15
  def eval_and_collect_source: (String code, String abs_path) -> void
15
16
  def strip_require_relative: (String code) -> String
17
+ def strip_magic_comment: (String code) -> String
16
18
  end
17
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbpacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  - !ruby/object:Gem::Version
198
198
  version: '0'
199
199
  requirements: []
200
- rubygems_version: 4.0.17
200
+ rubygems_version: 4.0.16
201
201
  specification_version: 4
202
202
  summary: Bundles and minifies multiple Ruby scripts into a single file
203
203
  test_files: []