opal-webpack-loader 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/opal-webpack-compile-server +8 -0
- data/lib/opal-webpack-loader.rb +31 -0
- data/lib/opal-webpack-loader/compile_server.rb +156 -0
- data/lib/opal-webpack-loader/version.rb +3 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2ab1db7ec2afae76e40c795592cc6f0aca8d7911651689ccfe9f47b8a344a8d6
|
4
|
+
data.tar.gz: e8d422c05f0cf71aa00063cb1fb5045b7c98e145920907d873bb4de8b1f39c1c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a378b4d9260d76e6b9f8f993afb9e14958376d3b92ca468a9b2d27b37236e49718ccc7cd344b9859517c813001d666124e690a490ac98c2773b6ec38f2c01e4c
|
7
|
+
data.tar.gz: 5d0e069a02d48cda2172cb64e799ce74cd7741cd394d8504a7f9288b809f9d60344fb29b25bd92133081ed21c9a5b4b6b5133da0b0aa0689f9c4b144010d9e83
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# check version of opal-webpack-loader-npm
|
2
|
+
require 'opal-webpack-loader/version'
|
3
|
+
require 'opal-webpack-loader/manifest'
|
4
|
+
if defined? Rails
|
5
|
+
require 'opal-webpack-loader/rails_view_helper'
|
6
|
+
else
|
7
|
+
require 'opal-webpack-loader/view_helper'
|
8
|
+
end
|
9
|
+
|
10
|
+
owl_version = ''
|
11
|
+
npm = `which npm`.chop
|
12
|
+
|
13
|
+
if npm != ''
|
14
|
+
owl_version = `#{npm} view opal-webpack-loader version`
|
15
|
+
else
|
16
|
+
yarn = `which yarn`.chop
|
17
|
+
if yarn != ''
|
18
|
+
owl_version = `#{yarn} -s info opal-webpack-loader version`
|
19
|
+
else
|
20
|
+
raise 'opal-webpack-loader: Could not find npm or yarn! Please install npm or yarn'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
owl_version = owl_version.chop # remove newline at end
|
25
|
+
|
26
|
+
unless owl_version != OpalWebpackLoader::VERSION
|
27
|
+
raise "opal-webpack-loader: Incorrect version of npm package found or npm package not installed.\n" +
|
28
|
+
"Please install the npm package for opal-webpack-loader:\n" +
|
29
|
+
"\twith npm:\tnpm install opal-webpack-loader@#{OpalWebpackLoader::VERSION} --save-dev\n" +
|
30
|
+
"\twith yarn:\tyarn add opal-webpack-loader@#{OpalWebpackLoader::VERSION} --dev\n"
|
31
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'oj'
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'opal/paths'
|
4
|
+
require 'opal/source_map'
|
5
|
+
require 'source_map'
|
6
|
+
require 'opal/compiler'
|
7
|
+
require 'socket'
|
8
|
+
|
9
|
+
at_exit do
|
10
|
+
if OpalWebpackCompileServer::Exe.unlink_socket?
|
11
|
+
if File.exist?(OpalWebpackCompileServer::OWCS_SOCKET_PATH)
|
12
|
+
File.unlink(OpalWebpackCompileServer::OWCS_SOCKET_PATH)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module OpalWebpackCompileServer
|
18
|
+
OWL_CACHE_DIR = './.owl_cache/'
|
19
|
+
OWL_LP_CACHE = OWL_CACHE_DIR + 'load_paths.json'
|
20
|
+
OWCS_SOCKET_PATH = OWL_CACHE_DIR + 'owcs_socket'
|
21
|
+
|
22
|
+
class Compiler < EventMachine::Connection
|
23
|
+
def receive_data(data)
|
24
|
+
if data.start_with?('command:stop')
|
25
|
+
EventMachine.stop
|
26
|
+
exit(0)
|
27
|
+
end
|
28
|
+
|
29
|
+
filename = data.chop # remove newline
|
30
|
+
|
31
|
+
operation = proc do
|
32
|
+
begin
|
33
|
+
source = File.read(filename)
|
34
|
+
c = Opal::Compiler.new(source, file: filename, es6_modules: true)
|
35
|
+
c.compile
|
36
|
+
result = { 'javascript' => c.result }
|
37
|
+
result['source_map'] = c.source_map.as_json
|
38
|
+
result['source_map']['sourcesContent'] = [source]
|
39
|
+
result['source_map']['file'] = filename
|
40
|
+
result['source_map']['names'] = result['source_map']['names'].map(&:to_s)
|
41
|
+
result['required_trees'] = c.required_trees
|
42
|
+
Oj.dump(result)
|
43
|
+
rescue Exception => e
|
44
|
+
Oj.dump({ 'error' => { 'name' => e.class, 'message' => e.message, 'backtrace' => e.backtrace } })
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
callback = proc do |json|
|
49
|
+
self.send_data(json + "\n")
|
50
|
+
close_connection_after_writing
|
51
|
+
end
|
52
|
+
|
53
|
+
EM.defer(operation, callback)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class LoadPathManager
|
58
|
+
def self.get_load_path_entries(path)
|
59
|
+
path_entries = []
|
60
|
+
return [] unless Dir.exist?(path)
|
61
|
+
dir_entries = Dir.entries(path)
|
62
|
+
dir_entries.each do |entry|
|
63
|
+
next if entry == '.'
|
64
|
+
next if entry == '..'
|
65
|
+
absolute_path = File.join(path, entry)
|
66
|
+
if File.directory?(absolute_path)
|
67
|
+
more_path_entries = get_load_path_entries(absolute_path)
|
68
|
+
path_entries.push(*more_path_entries) if more_path_entries.size > 0
|
69
|
+
elsif (absolute_path.end_with?('.rb') || absolute_path.end_with?('.js')) && File.file?(absolute_path)
|
70
|
+
path_entries.push(absolute_path)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
path_entries
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.get_load_paths
|
77
|
+
load_paths = if File.exist?('bin/rails')
|
78
|
+
%x{
|
79
|
+
bundle exec rails runner "puts (Rails.configuration.respond_to?(:assets) ? (Rails.configuration.assets.paths + Opal.paths).uniq : Opal.paths)"
|
80
|
+
}
|
81
|
+
else
|
82
|
+
%x{
|
83
|
+
bundle exec ruby -e 'require "bundler/setup"; Bundler.require; puts Opal.paths'
|
84
|
+
}
|
85
|
+
end
|
86
|
+
if $? == 0
|
87
|
+
load_path_lines = load_paths.split("\n")
|
88
|
+
load_path_lines.pop if load_path_lines.last == ''
|
89
|
+
|
90
|
+
load_path_entries = []
|
91
|
+
|
92
|
+
cwd = Dir.pwd
|
93
|
+
|
94
|
+
load_path_lines.each do |path|
|
95
|
+
next if path.start_with?(cwd)
|
96
|
+
more_path_entries = get_load_path_entries(path)
|
97
|
+
load_path_entries.push(*more_path_entries) if more_path_entries.size > 0
|
98
|
+
end
|
99
|
+
cache_obj = { 'opal_load_paths' => load_path_lines, 'opal_load_path_entries' => load_path_entries }
|
100
|
+
Dir.mkdir(OpalWebpackCompileServer::OWL_CACHE_DIR) unless Dir.exist?(OpalWebpackCompileServer::OWL_CACHE_DIR)
|
101
|
+
File.write(OpalWebpackCompileServer::OWL_LP_CACHE, Oj.dump(cache_obj))
|
102
|
+
load_path_lines
|
103
|
+
else
|
104
|
+
raise 'Error getting load paths!'
|
105
|
+
exit(2)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class Exe
|
111
|
+
def self.unlink_socket?
|
112
|
+
@unlink
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.unlink_on_exit
|
116
|
+
@unlink = true
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.dont_unlink_on_exit
|
120
|
+
@unlink = false
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.stop
|
124
|
+
if File.exist?(OWCS_SOCKET_PATH)
|
125
|
+
dont_unlink_on_exit
|
126
|
+
begin
|
127
|
+
s = UNIXSocket.new(OWCS_SOCKET_PATH)
|
128
|
+
s.send("command:stop\n", 0)
|
129
|
+
s.close
|
130
|
+
rescue
|
131
|
+
# socket cant be reached so owcs is already dead, delete socket
|
132
|
+
unlink_on_exit
|
133
|
+
end
|
134
|
+
exit(0)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.run
|
139
|
+
if File.exist?(OWCS_SOCKET_PATH) # OWCS already running
|
140
|
+
puts 'Another Opal Webpack Compile Server already running, exiting'
|
141
|
+
dont_unlink_on_exit
|
142
|
+
exit(1)
|
143
|
+
else
|
144
|
+
unlink_on_exit
|
145
|
+
load_paths = OpalWebpackCompileServer::LoadPathManager.get_load_paths
|
146
|
+
if load_paths
|
147
|
+
Opal.append_paths(*load_paths)
|
148
|
+
Process.daemon(true)
|
149
|
+
EventMachine.run do
|
150
|
+
EventMachine.start_unix_domain_server(OWCS_SOCKET_PATH, OpalWebpackCompileServer::Compiler)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opal-webpack-loader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Biedermann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: opal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.11.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.11.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eventmachine
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oj
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.6.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.6.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Compile server, loader and resolver for building opal ruby packs with
|
70
|
+
webpack.
|
71
|
+
email: jan@kursator.de
|
72
|
+
executables:
|
73
|
+
- opal-webpack-compile-server
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- bin/opal-webpack-compile-server
|
78
|
+
- lib/opal-webpack-loader.rb
|
79
|
+
- lib/opal-webpack-loader/compile_server.rb
|
80
|
+
- lib/opal-webpack-loader/version.rb
|
81
|
+
homepage: http://hyperstack.org
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.7.6
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Compile server, loader and resolver for building opal ruby packs with webpack.
|
105
|
+
test_files: []
|