rails_node_module_linker 0.1.1 โ†’ 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e81cd39501cca18b34a32deecb6c8a6f9346cb91a34e79b29fc0dd0dc9aa6238
4
- data.tar.gz: 10bbfa5e7339f9f403815e951303650db51bbce636b3b604c51648651d1dc1dd
3
+ metadata.gz: a715e5efda2b9c74f8b0148969279ef882137cfbd2099e4c4f8dbab139ad703c
4
+ data.tar.gz: ec17edf684bc7ee2e471f46cc09c4c14aa1872de15b5ab2eccc69e1ef0a4f41f
5
5
  SHA512:
6
- metadata.gz: 81610ec9f76d3e431e9ef542cfd6b6c8138b89f4409187042ca25a048b48fbaa03e91e5760d03bae04bda02557efe7d377402a51229d3e91404caa513e8b3e31
7
- data.tar.gz: 94fa8dbfdf2b50255f08a51a9c6488e62775ea2fd6be606b044b0bd94e645c4f12f632711c5ed8f3fd731b729cc9ac8c5072c6aa41c0d259d93addcac5cbd5ad
6
+ metadata.gz: 35db5fd4280b252f45f8e0e2556d2b0fc37667d9430aec7566a7a42e4b80b6f01bef25f191eb32f3dfd69be30f9a17969919b0f3cf253d6f187882c9afca0015
7
+ data.tar.gz: a6553ee7db4b1fc3adc47c88936eb2e89ee00a0787b07598c814407a24c9ad578de120cd15a9458634d46782b9b98691e7835618f4b805a654bb38b1c77baa98
data/CHANGELOG.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.0] - 2025-05-17
4
+
5
+ - Adds ability to change the `destination_path`
6
+ - renames config_file_path to symlinked_node_modules_config
7
+ - BREAKING removes need to add Rails.root.join in the config
8
+
3
9
  ## [0.1.1] - 2025-05-07
4
10
 
5
11
  - Fixes precompile hook
6
12
 
7
- ## [0.1.0] - 2025-04-24
13
+ ## [0.1.0] - 2025-05-06
8
14
 
9
15
  - Initial release
10
16
  - Links selected node_modules to `public/` for use with Propshaft
data/README.md CHANGED
@@ -22,7 +22,8 @@ gem install rails_node_module_linker
22
22
  # config/initializers/rails_node_module_linker.rb
23
23
 
24
24
  Rails.application.config.to_prepare do
25
- RailsNodeModuleLinker.config.config_file_path = Rails.root.join("config/symlinked_node_modules.yml")
25
+ RailsNodeModuleLinker.config.symlinked_node_modules_config = 'config/symlinked_node_modules.yml'
26
+ RailsNodeModuleLinker.config.destination_path = 'public/node_modules'
26
27
  RailsNodeModuleLinker.config.use_emojis = true
27
28
  end
28
29
  ```
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RailsNodeModuleLinker::Config
4
- attr_accessor :config_file_path, :use_emojis
4
+ attr_accessor :symlinked_node_modules_config, :destination_path, :use_emojis
5
5
 
6
6
  def initialize
7
7
  # * Default configuration values
8
- @config_file_path = Rails.root.join('config/symlinked_node_modules.yml')
8
+ @symlinked_node_modules_config = 'config/symlinked_node_modules.yml'
9
+ @destination_path = 'public/node_modules'
9
10
  @use_emojis = true
10
11
 
11
- # TODO: make desitination folder customizable
12
- # TODO make source folder customizable
13
- # TODO make middleware enablement configurable
12
+ # TODO: make source folder customizable
13
+ # TODO: make middleware enablement configurable
14
14
  end
15
15
  end
@@ -10,7 +10,9 @@ class RailsNodeModuleLinker::Middleware
10
10
  def call(env)
11
11
  path = env['PATH_INFO']
12
12
  Rack::Utils.parse_query(env['QUERY_STRING'])
13
- config_file_path = RailsNodeModuleLinker.config.config_file_path
13
+ symlinked_node_modules_config = Rails.root.join(
14
+ RailsNodeModuleLinker.config.symlinked_node_modules_config
15
+ )
14
16
 
15
17
  if path.start_with?('/node_modules/')
16
18
  status, _headers, _body = @app.call(env)
@@ -18,16 +20,16 @@ class RailsNodeModuleLinker::Middleware
18
20
  package = extract_package(path)
19
21
 
20
22
  # * Ensure the config directory exists
21
- FileUtils.mkdir_p(config_file_path.dirname)
23
+ FileUtils.mkdir_p(symlinked_node_modules_config.dirname)
22
24
 
23
25
  # * Load existing config or initialize a new one
24
- config = File.exist?(config_file_path) ? YAML.load_file(config_file_path) : { 'packages' => [] }
26
+ config = File.exist?(symlinked_node_modules_config) ? YAML.load_file(symlinked_node_modules_config) : { 'packages' => [] }
25
27
 
26
28
  # * Add the package if not already listed
27
29
  config['packages'] = (config['packages'] | [package]).sort
28
30
 
29
31
  # * Save the updated config
30
- File.write(config_file_path, config.to_yaml)
32
+ File.write(symlinked_node_modules_config, config.to_yaml)
31
33
 
32
34
  # * Call the rake task to create the symlink
33
35
  system('bin/rails rails_node_module_linker:link')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsNodeModuleLinker
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -9,6 +9,8 @@ module RailsNodeModuleLinker
9
9
  # * Configuration accessor for users to access and modify settings
10
10
  mattr_accessor :config
11
11
 
12
+ self.config ||= Config.new
13
+
12
14
  class Engine < ::Rails::Engine
13
15
  # * Initialize default configuration
14
16
  initializer 'rails_node_module_linker.config' do
@@ -14,32 +14,34 @@ def log_with_emoji(message)
14
14
  end
15
15
 
16
16
  namespace :rails_node_module_linker do
17
- desc 'Symlink full packages from node_modules to public/node_modules'
17
+ desc "Symlink full packages from node_modules to #{RailsNodeModuleLinker.config.destination_path}"
18
18
  task link: :environment do
19
- config_file_path = RailsNodeModuleLinker.config.config_file_path
19
+ symlinked_node_modules_config = Rails.root.join(
20
+ RailsNodeModuleLinker.config.symlinked_node_modules_config
21
+ )
20
22
 
21
23
  # * Ensure the config file exists with a default structure
22
- unless File.exist?(config_file_path)
23
- log_with_emoji("๐Ÿ†• Created missing config file at #{config_file_path}")
24
+ unless File.exist?(symlinked_node_modules_config)
25
+ log_with_emoji("๐Ÿ†• Created missing config file at #{symlinked_node_modules_config}")
24
26
 
25
- FileUtils.mkdir_p(config_file_path.dirname)
26
- File.write(config_file_path, { 'packages' => [] }.to_yaml)
27
+ FileUtils.mkdir_p(symlinked_node_modules_config.dirname)
28
+ File.write(symlinked_node_modules_config, { 'packages' => [] }.to_yaml)
27
29
  end
28
30
 
29
- config = YAML.load_file(config_file_path)
31
+ config = YAML.load_file(symlinked_node_modules_config)
30
32
  node_modules_to_link = config['packages'] || []
31
33
 
32
34
  log_with_emoji('๐Ÿ“ญ No node modules configured to link.') if node_modules_to_link.empty?
33
35
 
34
- public_node_modules = Rails.root.join('public/node_modules')
35
- FileUtils.mkdir_p(public_node_modules)
36
+ node_modules_destination_path = Rails.root.join(RailsNodeModuleLinker.config.destination_path)
37
+ FileUtils.mkdir_p(node_modules_destination_path)
36
38
 
37
39
  # * Clean up outdated symlinks
38
- existing_symlinks = Dir.glob(public_node_modules.join('**/*'), File::FNM_DOTMATCH).select do |path|
40
+ existing_symlinks = Dir.glob(node_modules_destination_path.join('**/*'), File::FNM_DOTMATCH).select do |path|
39
41
  File.symlink?(path)
40
42
  end
41
43
  existing_symlinks.each do |symlink_path|
42
- relative_path = Pathname.new(symlink_path).relative_path_from(public_node_modules).to_s
44
+ relative_path = Pathname.new(symlink_path).relative_path_from(node_modules_destination_path).to_s
43
45
  next if node_modules_to_link.include?(relative_path)
44
46
 
45
47
  log_with_emoji("๐Ÿงน Removing stale symlink: #{symlink_path}")
@@ -50,7 +52,7 @@ namespace :rails_node_module_linker do
50
52
  # * Add or update symlinks from config
51
53
  node_modules_to_link.each do |package|
52
54
  source = Rails.root.join('node_modules', package)
53
- destination = public_node_modules.join(package)
55
+ destination = node_modules_destination_path.join(package)
54
56
 
55
57
  unless source.exist?
56
58
  log_with_emoji("๐Ÿšซ Source does not exist: #{source} (skipping)")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_node_module_linker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Veaudry
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-05-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Exposees wanted node_modules to the public directory for Rails apps that
13
13
  have transitioned from Sprockets to Propshaft.
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubygems_version: 3.6.5
56
+ rubygems_version: 3.6.8
57
57
  specification_version: 4
58
58
  summary: Link node modules into the public folder of a Rails app using Propshaft
59
59
  test_files: []