rails_node_module_linker 0.1.0 โ 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 +4 -4
- data/.rubocop.yml +8 -2
- data/CHANGELOG.md +11 -1
- data/README.md +2 -1
- data/lib/rails_node_module_linker/config.rb +5 -5
- data/lib/rails_node_module_linker/middleware.rb +6 -4
- data/lib/rails_node_module_linker/railtie.rb +15 -0
- data/lib/rails_node_module_linker/version.rb +1 -1
- data/lib/rails_node_module_linker.rb +2 -0
- data/lib/tasks/rails_node_module_linker/link.rake +15 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a715e5efda2b9c74f8b0148969279ef882137cfbd2099e4c4f8dbab139ad703c
|
4
|
+
data.tar.gz: ec17edf684bc7ee2e471f46cc09c4c14aa1872de15b5ab2eccc69e1ef0a4f41f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35db5fd4280b252f45f8e0e2556d2b0fc37667d9430aec7566a7a42e4b80b6f01bef25f191eb32f3dfd69be30f9a17969919b0f3cf253d6f187882c9afca0015
|
7
|
+
data.tar.gz: a6553ee7db4b1fc3adc47c88936eb2e89ee00a0787b07598c814407a24c9ad578de120cd15a9458634d46782b9b98691e7835618f4b805a654bb38b1c77baa98
|
data/.rubocop.yml
CHANGED
@@ -7,10 +7,14 @@ AllCops:
|
|
7
7
|
SuggestExtensions: true
|
8
8
|
NewCops: 'enable'
|
9
9
|
|
10
|
+
|
11
|
+
# ################################################ * Layout * ################################################# #
|
10
12
|
Layout/LineLength:
|
11
13
|
Enabled: true
|
12
14
|
Max: 250
|
13
15
|
|
16
|
+
|
17
|
+
# ################################################ * Metrics * ################################################# #
|
14
18
|
Metrics/AbcSize:
|
15
19
|
Enabled: false # * Keeping these off due to complexity of refactoring existing code
|
16
20
|
|
@@ -25,9 +29,11 @@ Metrics/MethodLength:
|
|
25
29
|
CountAsOne: ["array", "heredoc", "method_call"]
|
26
30
|
Max: 50
|
27
31
|
|
28
|
-
Style/Documentation:
|
29
|
-
Enabled: false
|
30
32
|
|
33
|
+
# ################################################ * Metrics * ################################################# #
|
31
34
|
Style/ClassAndModuleChildren:
|
32
35
|
Enabled: true
|
33
36
|
EnforcedStyle: 'compact'
|
37
|
+
|
38
|
+
Style/Documentation:
|
39
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [0.
|
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
|
+
|
9
|
+
## [0.1.1] - 2025-05-07
|
10
|
+
|
11
|
+
- Fixes precompile hook
|
12
|
+
|
13
|
+
## [0.1.0] - 2025-05-06
|
4
14
|
|
5
15
|
- Initial release
|
6
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.
|
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 :
|
4
|
+
attr_accessor :symlinked_node_modules_config, :destination_path, :use_emojis
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
# * Default configuration values
|
8
|
-
@
|
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
|
12
|
-
# TODO make
|
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
|
-
|
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(
|
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?(
|
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(
|
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')
|
@@ -6,9 +6,24 @@ require 'rails_node_module_linker'
|
|
6
6
|
class RailsNodeModuleLinker::Railtie < Rails::Railtie
|
7
7
|
railtie_name :rails_node_module_linker
|
8
8
|
|
9
|
+
# TODO: make this changeable via setting
|
10
|
+
# * Hardcoded toggle for before/after
|
11
|
+
PRECOMPILE_HOOK_POSITION = :before # ? or :after
|
12
|
+
|
9
13
|
rake_tasks do
|
10
14
|
path = File.expand_path(__dir__)
|
11
15
|
Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
|
16
|
+
|
17
|
+
Rake::Task.define_task(:environment)
|
18
|
+
|
19
|
+
case PRECOMPILE_HOOK_POSITION
|
20
|
+
when :before
|
21
|
+
Rake::Task['assets:precompile'].enhance(['rails_node_module_linker:precompile_hook'])
|
22
|
+
when :after
|
23
|
+
Rake::Task['assets:precompile'].enhance do
|
24
|
+
Rake::Task['rails_node_module_linker:precompile_hook'].invoke
|
25
|
+
end
|
26
|
+
end
|
12
27
|
end
|
13
28
|
|
14
29
|
initializer 'rails_node_module_linker.insert_middleware' do |app|
|
@@ -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
|
17
|
+
desc "Symlink full packages from node_modules to #{RailsNodeModuleLinker.config.destination_path}"
|
18
18
|
task link: :environment do
|
19
|
-
|
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?(
|
23
|
-
log_with_emoji("๐ Created missing config file at #{
|
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(
|
26
|
-
File.write(
|
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(
|
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
|
-
|
35
|
-
FileUtils.mkdir_p(
|
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(
|
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(
|
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 =
|
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)")
|
@@ -80,5 +82,5 @@ namespace :rails_node_module_linker do
|
|
80
82
|
end
|
81
83
|
|
82
84
|
desc 'Link node module packages before asset precompilation'
|
83
|
-
task
|
85
|
+
task precompile_hook: :link
|
84
86
|
end
|
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.
|
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:
|
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.
|
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: []
|