opal-webpack-loader 0.3.8 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b42dbe838247fa4884f7c83689dcdb82977deb68acee953ee74f66e9ea4d5bd2
4
- data.tar.gz: 88ac81dc363188576833979952bed5e4ed2c8010297c20716d5d262d14331d30
3
+ metadata.gz: 47e3de8dc59fca8c77ec96cce2a2d981360ffc59a1d5b3081d5b38ac9e872abc
4
+ data.tar.gz: 74ee8b8d003d7d4f7da72f2b778a6f6eca2d74188231b56eefdc2de45b1f0bbf
5
5
  SHA512:
6
- metadata.gz: e05bd637ddba7fc0199e2c1eb1baf0b9e63041c6da56ac546bda0e28055a547e045556195c164da3185be4d319ac4dd13579bd0d48d22d80c18c63670e22039d
7
- data.tar.gz: 40002724fdd6ddebaf9081fa1d31ad0df40552e766e5d69d67b18aa69a2c525f7b68cf70fddd9a7dad4638624bff15d69cba559b7613bdf62aaac3b72497d91c
6
+ metadata.gz: 2fe218979c2f394a314e49a5c10beb6fcdd016928eba20fb0f7b5bf50ea6523ecccbbfe98aae2b44b506ab660749843a3c998e7ce70873784f959326e5bd3ef3
7
+ data.tar.gz: e49f7d2c1171b2e0b7c314424706fc020927126a91a69b9472ea13d887b838a308e360a2670ca3eda50605a8d0073709edd7abf3fdb9b7d4e206a363f0da3b0e
@@ -1,8 +1,59 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'opal-webpack-loader/compile_server'
3
+ require 'open3'
4
+
5
+ puts "args: #{ARGV}"
3
6
 
4
7
  if ARGV[0] == 'stop' || ARGV[0] == 'kill'
5
8
  OpalWebpackCompileServer::Exe.stop
6
9
  else
7
- OpalWebpackCompileServer::Exe.run
10
+ if ARGV[0] == 'start'
11
+ OpalWebpackCompileServer::Exe.stop
12
+ runargs = ARGV[1..-1]
13
+ else
14
+ runargs = ARGV
15
+ end
16
+
17
+ fork { OpalWebpackCompileServer::Exe.run }
18
+
19
+ have_socket = false
20
+ start_time = Time.now
21
+ begin
22
+ until have_socket
23
+ if File.exist?(OpalWebpackCompileServer::OWCS_SOCKET_PATH)
24
+ have_socket = true
25
+ else
26
+ if Time.now - start_time > 60
27
+ puts "opal-webpack-compile-server didnt start in time. Exiting"
28
+ OpalWebpackCompileServer::Exe.stop(false)
29
+ exit 1
30
+ end
31
+ end
32
+ end
33
+ rescue Exception => e
34
+ OpalWebpackCompileServer::Exe.stop(false)
35
+ puts "opal-webpack-compile-server couldn't start:"
36
+ puts e.backtrace.join("\n")
37
+ puts e.message
38
+ exit 1
39
+ end
40
+
41
+ begin
42
+ # see: http://stackoverflow.com/a/1162850/83386
43
+ Open3.popen3(*runargs) do |stdin, stdout, stderr, thread|
44
+ # read each stream from a new thread
45
+ { :out => stdout, :err => stderr }.each do |key, stream|
46
+ Thread.new do
47
+ until (raw_line = stream.gets).nil? do
48
+ puts raw_line
49
+ end
50
+ end
51
+ end
52
+
53
+ thread.join # don't exit until the external process is done
54
+ end
55
+ rescue Interrupt => e
56
+ puts "opal-webpack-compile-server got interrupted. Exiting with drama."
57
+ exit 0
58
+ end
8
59
  end
@@ -26,7 +26,9 @@ module OpalWebpackCompileServer
26
26
  exit(0)
27
27
  end
28
28
 
29
- filename = data.chop # remove newline
29
+ request_hash = Oj.load(data)
30
+ filename = request_hash['filename']
31
+ compile_source_map = request_hash['source_map']
30
32
 
31
33
  operation = proc do
32
34
  begin
@@ -34,10 +36,12 @@ module OpalWebpackCompileServer
34
36
  c = Opal::Compiler.new(source, file: filename, es6_modules: true)
35
37
  c.compile
36
38
  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)
39
+ if compile_source_map
40
+ result['source_map'] = c.source_map.as_json
41
+ result['source_map']['sourcesContent'] = [source]
42
+ result['source_map']['file'] = filename
43
+ result['source_map']['names'] = result['source_map']['names'].map(&:to_s)
44
+ end
41
45
  result['required_trees'] = c.required_trees
42
46
  Oj.dump(result)
43
47
  rescue Exception => e
@@ -120,7 +124,7 @@ module OpalWebpackCompileServer
120
124
  @unlink = false
121
125
  end
122
126
 
123
- def self.stop
127
+ def self.stop(do_exit = true)
124
128
  if File.exist?(OWCS_SOCKET_PATH)
125
129
  dont_unlink_on_exit
126
130
  begin
@@ -131,7 +135,7 @@ module OpalWebpackCompileServer
131
135
  # socket cant be reached so owcs is already dead, delete socket
132
136
  unlink_on_exit
133
137
  end
134
- exit(0)
138
+ exit(0) if do_exit
135
139
  end
136
140
  end
137
141
 
@@ -145,7 +149,7 @@ module OpalWebpackCompileServer
145
149
  load_paths = OpalWebpackCompileServer::LoadPathManager.get_load_paths
146
150
  if load_paths
147
151
  Opal.append_paths(*load_paths)
148
- Process.daemon(true)
152
+ # Process.daemon(true)
149
153
  EventMachine.run do
150
154
  EventMachine.start_unix_domain_server(OWCS_SOCKET_PATH, OpalWebpackCompileServer::Compiler)
151
155
  end
@@ -1,11 +1,11 @@
1
1
  module OpalWebpackLoader
2
2
  class Manifest
3
3
  def self.manifest
4
- @manifest ||= JSON.parse(File.read(File.join(Rails.root, 'public', 'packs', 'manifest.json')))
4
+ @manifest ||= JSON.parse(File.read(OpalWebpackLoader.manifest_path))
5
5
  end
6
6
 
7
7
  def self.lookup_path_for(asset)
8
8
  manifest[asset]
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -2,18 +2,13 @@ module OpalWebpackLoader
2
2
  module RailsViewHelper
3
3
  def owl_include_tag(path)
4
4
  case Rails.env
5
- when 'production'
6
- public, packs, asset = path.split('/')
7
- asset_path = OpalWebpackLoader::Manifest.lookup_path_for(asset)
8
- javascript_include_tag(asset_path)
9
5
  when 'development'
10
- javascript_include_tag('http://localhost:3035' + path[0..-4] + '_development' + path[-3..-1])
11
- when 'test'
12
- real_path = path[0..-4] + '_test' + path[-3..-1]
13
- public, packs, asset = real_path.split('/')
6
+ javascript_include_tag("http://localhost:3035#{OpalWebpackLoader.client_asset_path}/#{path}")
7
+ else
8
+ asset = path.split('/').last
14
9
  asset_path = OpalWebpackLoader::Manifest.lookup_path_for(asset)
15
- javascript_include_tag(asset_path)
10
+ javascript_include_tag("#{OpalWebpackLoader.client_asset_path}/#{asset_path}")
16
11
  end
17
12
  end
18
13
  end
19
- end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module OpalWebpackLoader
2
- VERSION="0.3.8"
2
+ VERSION="0.4.0"
3
3
  end
@@ -1,19 +1,13 @@
1
1
  module OpalWebpackLoader
2
2
  module ViewHelper
3
- def owl_include_tag(path)
4
- case Rails.env
5
- when 'production'
6
- public, packs, asset = path.split('/')
7
- asset_path = OpalWebpackLoader::Manifest.lookup_path_for(asset)
8
- "<script type=\"application/javascript\" src=\"#{asset_path}\"></script>"
3
+ def owl_include_tag(path, env = 'development')
4
+ case env
9
5
  when 'development'
10
- "<script type=\"application/javascript\" src=\"#{'http://localhost:3035' + path[0..-4] + '_development' + path[-3..-1]}\"></script>"
11
- when 'test'
12
- real_path = path[0..-4] + '_test' + path[-3..-1]
13
- public, packs, asset = real_path.split('/')
14
- asset_path = OpalWebpackLoader::Manifest.lookup_path_for(asset)
15
- "<script type=\"application/javascript\" src=\"#{asset_path}\"></script>"
6
+ "<script type=\"application/javascript\" src=\"http://localhost:3035#{OpalWebpackLoader.client_asset_path}/#{path}\"></script>"
7
+ else
8
+ asset_path = OpalWebpackLoader::Manifest.lookup_path_for(path)
9
+ "<script type=\"application/javascript\" src=\"#{OpalWebpackLoader.client_asset_path}/#{asset_path}\"></script>"
16
10
  end
17
11
  end
18
12
  end
19
- end
13
+ end
@@ -1,8 +1,50 @@
1
1
  # check version of opal-webpack-loader-npm
2
2
  require 'opal-webpack-loader/version'
3
3
  require 'opal-webpack-loader/manifest'
4
+
5
+ module OpalWebpackLoader
6
+ def self.manifest_path
7
+ @manifest_path
8
+ end
9
+
10
+ def self.manifest_path=(path)
11
+ @manifest_path = path
12
+ end
13
+
14
+ def self.client_asset_path
15
+ @client_asset_path
16
+ end
17
+
18
+ def self.client_asset_path=(path)
19
+ @client_asset_path = path
20
+ end
21
+ end
22
+
4
23
  if defined? Rails
5
24
  require 'opal-webpack-loader/rails_view_helper'
6
25
  else
7
26
  require 'opal-webpack-loader/view_helper'
8
27
  end
28
+
29
+ OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'manifest.json')
30
+ OpalWebpackLoader.client_asset_path = '/assets'
31
+
32
+ npm = `which npm`.chop
33
+
34
+ if npm != ''
35
+ owl_version = `#{npm} view opal-webpack-loader version`
36
+ else
37
+ yarn = `which yarn`.chop
38
+ if yarn != ''
39
+ owl_version = `#{yarn} -s info opal-webpack-loader version`
40
+ else
41
+ raise 'opal-webpack-loader: Could not find npm or yarn! Please install npm or yarn'
42
+ end
43
+ end
44
+
45
+ if owl_version.chop != OpalWebpackLoader::VERSION
46
+ raise "opal-webpack-loader: Incorrect version of npm package found or npm package not installed.\n" +
47
+ "Please install the npm package for opal-webpack-loader:\n" +
48
+ "\twith npm:\tnpm install opal-webpack-loader@#{OpalWebpackLoader::VERSION} --save-dev\n" +
49
+ "\twith yarn:\tyarn add opal-webpack-loader@#{OpalWebpackLoader::VERSION} --dev\n"
50
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-webpack-loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-20 00:00:00.000000000 Z
11
+ date: 2018-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal