opal-webpack-loader 0.6.4 → 0.6.5

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: c9b54a6d72b3aafc8740ff6fed7e5d45f4c74de4e7dd3ace44cf837049c6c06b
4
- data.tar.gz: a8bdc45777a51e6d3b8f3f973402b2565afe697f587337842ad8189fb576b13f
3
+ metadata.gz: 1b55e893894b05e91eab4ef13fa4a1c9a796e3258505725bdf2a80855639aa5f
4
+ data.tar.gz: cf6b3c096fe6e7cc28364416d3513e02257aa9c6c045bcedaf203f3e12e098d0
5
5
  SHA512:
6
- metadata.gz: 967e207065beb55ff6b556f5654740fc1a5765daaaf30f98d29d9bf7372ecfe0114e5c7e8dcad8d56d045232322bb670b2d2410e744bbac6cc2f787e8d645c58
7
- data.tar.gz: 7c1a492488d09e5846133b0c886c6de73f07da36e8a22702dcc1fe4a54ca48ca45135e361eecffa9c8c1b72cc18aecd7fc8e8035fb25a7a46df6b390e32f942f
6
+ metadata.gz: ad3d491649b5e555cef8260e0ddb3243c6db21a5f1525bdeadbfd6f98147b7108740f13555cd151d949d63a5f2511824d81051aa80462413dcad766c84234758
7
+ data.tar.gz: bfd86eaa367c5f329c8b73f0dbfffc5e9ba5a35d3450c2ad1fe05b0c5167cc461a368cfee9e9e16053be1d38acd156697990999714bc4c9207b85f667fe5c18b
@@ -20,19 +20,31 @@ module OpalWebpackCompileServer
20
20
  OWCS_SOCKET_PATH = OWL_CACHE_DIR + 'owcs_socket'
21
21
 
22
22
  class Compiler < EventMachine::Connection
23
+ def initialize(*args)
24
+ @received_data = ''
25
+ super(*args)
26
+ end
27
+
23
28
  def receive_data(data)
24
- if data.start_with?('command:stop')
29
+ @received_data << data
30
+
31
+ return unless @received_data.end_with?("}\x04")
32
+
33
+ if @received_data.start_with?('command:stop')
25
34
  EventMachine.stop
26
35
  exit(0)
27
36
  end
28
37
 
29
- request_hash = Oj.load(data)
30
- filename = request_hash['filename']
31
- compile_source_map = request_hash['source_map']
38
+ request_json = Oj.load(@received_data.chop!, {})
39
+
40
+ @received_data = ''
41
+
42
+ compile_source_map = request_json["source_map"]
43
+ filename = request_json["filename"]
44
+ source = request_json["source"]
32
45
 
33
46
  operation = proc do
34
47
  begin
35
- source = File.read(filename)
36
48
  c = Opal::Compiler.new(source, file: filename, es6_modules: true)
37
49
  c.compile
38
50
  result = { 'javascript' => c.result }
@@ -45,12 +57,12 @@ module OpalWebpackCompileServer
45
57
  result['required_trees'] = c.required_trees
46
58
  Oj.dump(result, {})
47
59
  rescue Exception => e
48
- Oj.dump({ 'error' => { 'name' => e.class, 'message' => e.message, 'backtrace' => e.backtrace } }, {})
60
+ Oj.dump({ 'error' => { 'name' => e.class, 'message' => e.message, 'backtrace' => e.backtrace.join("\n") } }, {})
49
61
  end
50
62
  end
51
63
 
52
64
  callback = proc do |json|
53
- self.send_data(json + "\n")
65
+ self.send_data(json)
54
66
  close_connection_after_writing
55
67
  end
56
68
 
@@ -33,6 +33,7 @@ module OpalWebpackLoader
33
33
  # +- spec
34
34
  # +- tmp
35
35
  def iso
36
+ @application_css = '../styles/application.css'
36
37
  @asset_output_directory = File.join('public', 'assets')
37
38
  @js_entrypoints_directory = File.join('isomorfeus', 'imports')
38
39
  @conf_rel_prefix = '..'
@@ -43,6 +44,7 @@ module OpalWebpackLoader
43
44
  create_common_directories
44
45
  create_isomorfeus_directories
45
46
  install_webpack_config
47
+ create_file_from_template('application.css.erb', File.join('isomorfeus', 'styles', 'application.css'), {})
46
48
  create_file_from_template('initializer.rb.erb', File.join('config', 'owl_init.rb'), {})
47
49
  add_gem
48
50
  print_message
@@ -70,6 +72,7 @@ module OpalWebpackLoader
70
72
  TEXT
71
73
 
72
74
  def flat
75
+ @application_css = '../styles/application.css'
73
76
  @asset_output_directory = File.join('public', 'assets')
74
77
  @js_entrypoints_directory = File.join('javascripts')
75
78
  @conf_rel_prefix = '..'
@@ -80,11 +83,11 @@ module OpalWebpackLoader
80
83
  create_directory(@styles_directory)
81
84
  create_common_directories
82
85
  install_common_things
86
+ create_file_from_template('application.css.erb', File.join('styles', 'application.css'), {})
83
87
  create_file_from_template('initializer.rb.erb', 'owl_init.rb', { opal_directory: @opal_directory })
84
88
  create_file_from_template('app_loader.rb.erb', 'app_loader.rb', {})
85
89
  add_gem
86
90
  print_message
87
- puts "Make sure to require the owl initializer, e.g. `require './owl_init'`, in your projects startup file."
88
91
  end
89
92
 
90
93
  desc "rails", "Install owl configuration into a existing rails project, execute from the projects root directory."
@@ -113,6 +116,7 @@ module OpalWebpackLoader
113
116
  TEXT
114
117
 
115
118
  def rails
119
+ @application_css = '../stylesheets/application.css'
116
120
  @asset_output_directory = File.join('public', 'assets')
117
121
  @js_entrypoints_directory = File.join('app', 'assets', 'javascripts')
118
122
  @conf_rel_prefix = File.join('..', '..')
@@ -163,7 +167,7 @@ module OpalWebpackLoader
163
167
  end
164
168
 
165
169
  def install_js_entries
166
- erb_hash = { opal_dir: File.join(@js_rel_prefix, @opal_directory), opal_name: options[:opal_name] }
170
+ erb_hash = { opal_dir: File.join(@js_rel_prefix, @opal_directory), opal_name: options[:opal_name], application_css: @application_css }
167
171
  create_file_from_template('application.js.erb', File.join(@js_entrypoints_directory, 'application.js'), erb_hash)
168
172
  create_file_from_template('application_common.js.erb', File.join(@js_entrypoints_directory, 'application_common.js'),erb_hash)
169
173
  create_file_from_template('application_debug.js.erb', File.join(@js_entrypoints_directory, 'application_debug.js'), erb_hash)
@@ -185,13 +189,8 @@ module OpalWebpackLoader
185
189
  package_json["scripts"]["development"] = development_script
186
190
  package_json["scripts"]["production_build"] = production_script
187
191
  package_json["devDependencies"] = {} unless package_json.has_key?("devDependencies")
188
- package_json["devDependencies"]["chokidar"] = gem_package_json["devDependencies"]["chokidar"]
189
- package_json["devDependencies"]["compression-webpack-plugin"] = gem_package_json["devDependencies"]["compression-webpack-plugin"]
190
- package_json["devDependencies"]["opal-webpack-loader"] = OpalWebpackLoader::VERSION
191
- package_json["devDependencies"]["webpack"] = gem_package_json["devDependencies"]["webpack"]
192
- package_json["devDependencies"]["webpack-cli"] = gem_package_json["devDependencies"]["webpack-cli"]
193
- package_json["devDependencies"]["webpack-dev-server"] = gem_package_json["devDependencies"]["webpack-dev-server"]
194
- package_json["devDependencies"]["webpack-manifest-plugin"] = gem_package_json["devDependencies"]["webpack-manifest-plugin"]
192
+ package_json["devDependencies"].merge!(gem_package_json["devDependencies"])
193
+ package_json["devDependencies"]["opal-webpack-loader"] = "^#{OpalWebpackLoader::VERSION}"
195
194
  File.write('package.json', Oj.dump(package_json, mode: :strict))
196
195
  puts "Updated package.json, updated scripts and owl dependencies"
197
196
  else
@@ -0,0 +1,4 @@
1
+ /* application stylesheets */
2
+ body {
3
+ color: black;
4
+ }
@@ -1,4 +1,7 @@
1
1
  // entry file for the browser environment
2
+ // import stylesheets here
3
+ import '<%= application_css %>';
4
+
2
5
  // import npm modules that are valid to use only in the browser
3
6
  // for example modules which depend on the window or document objects of the browser
4
7
  //
@@ -3,6 +3,7 @@ const path = require('path');
3
3
  const webpack = require('webpack');
4
4
  const chokidar = require('chokidar');
5
5
  const OwlResolver = require('opal-webpack-loader/resolver'); // to resolve ruby files
6
+ const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin'); // to watch for added ruby files
6
7
 
7
8
  module.exports = {
8
9
  context: path.resolve(__dirname, '<%= opal_directory %>'),
@@ -42,7 +43,11 @@ module.exports = {
42
43
  plugins: [
43
44
  // both for hot reloading
44
45
  new webpack.NamedModulesPlugin(),
45
- new webpack.HotModuleReplacementPlugin()
46
+ new webpack.HotModuleReplacementPlugin(),
47
+ // watch for added files in opal dir
48
+ new ExtraWatchWebpackPlugin({
49
+ dirs: [ path.resolve(__dirname, '<%= opal_directory %>') ]
50
+ })
46
51
  ],
47
52
  module: {
48
53
  rules: [
@@ -60,8 +65,7 @@ module.exports = {
60
65
  {
61
66
  loader: "css-loader",
62
67
  options: {
63
- sourceMap: true, // set to false to speed up hot reloads
64
- minimize: false // set to false to speed up hot reloads
68
+ sourceMap: true // set to false to speed up hot reloads
65
69
  }
66
70
  },
67
71
  {
@@ -86,8 +90,7 @@ module.exports = {
86
90
  {
87
91
  loader: "css-loader",
88
92
  options: {
89
- sourceMap: true, // set to false to speed up hot reloads
90
- minimize: false // set to false to speed up hot reloads
93
+ sourceMap: true // set to false to speed up hot reloads
91
94
  }
92
95
  }
93
96
  ]
@@ -3,6 +3,7 @@ const path = require('path');
3
3
  const webpack = require('webpack');
4
4
  const chokidar = require('chokidar');
5
5
  const OwlResolver = require('opal-webpack-loader/resolver'); // to resolve ruby files
6
+ const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin'); // to watch for added ruby files
6
7
 
7
8
  module.exports = {
8
9
  context: path.resolve(__dirname, '<%= opal_directory %>'),
@@ -33,7 +34,11 @@ module.exports = {
33
34
  plugins: [
34
35
  // both for hot reloading
35
36
  new webpack.NamedModulesPlugin(),
36
- new webpack.HotModuleReplacementPlugin()
37
+ new webpack.HotModuleReplacementPlugin(),
38
+ // watch for added files in opal dir
39
+ new ExtraWatchWebpackPlugin({
40
+ dirs: [ path.resolve(__dirname, '<%= opal_directory %>') ]
41
+ })
37
42
  ],
38
43
  module: {
39
44
  rules: [
@@ -49,10 +54,7 @@ module.exports = {
49
54
  }
50
55
  },
51
56
  {
52
- loader: "css-loader",
53
- options: {
54
- minimize: false // set to false to speed up hot reloads
55
- }
57
+ loader: "css-loader"
56
58
  },
57
59
  {
58
60
  loader: "sass-loader",
@@ -73,10 +75,7 @@ module.exports = {
73
75
  }
74
76
  },
75
77
  {
76
- loader: "css-loader",
77
- options: {
78
- minimize: false // set to false to speed up hot reloads
79
- }
78
+ loader: "css-loader"
80
79
  }
81
80
  ]
82
81
  },
@@ -1,4 +1,5 @@
1
1
  {
2
+ "private": true,
2
3
  "dependencies": {
3
4
  },
4
5
  "scripts": {
@@ -9,7 +10,13 @@
9
10
  "devDependencies": {
10
11
  "chokidar": "^2.1.5",
11
12
  "compression-webpack-plugin": "^2.0.0",
13
+ "css-loader": "^2.1.1",
14
+ "extra-watch-webpack-plugin": "^1.0.3",
15
+ "file-loader": "^1.1.11",
12
16
  "opal-webpack-loader": "^<%= owl_version %>",
17
+ "node-sass": "^4.12.0",
18
+ "sass-loader": "^7.1.0",
19
+ "style-loader": "^0.23.1",
13
20
  "webpack": "^4.30.0",
14
21
  "webpack-cli": "^3.3.0",
15
22
  "webpack-dev-server": "^3.3.1",
@@ -61,21 +61,7 @@ module.exports = {
61
61
  {
62
62
  // loader for .css files
63
63
  test: /.css$/,
64
- use: [
65
- {
66
- loader: "style-loader",
67
- options: {
68
- hmr: false
69
- }
70
- },
71
- {
72
- loader: "css-loader",
73
- options: {
74
- sourceMap: false, // set to false to speed up hot reloads
75
- minimize: true // set to false to speed up hot reloads
76
- }
77
- }
78
- ]
64
+ use: [ "style-loader", "css-loader" ]
79
65
  },
80
66
  {
81
67
  test: /.(png|svg|jpg|gif)$/,
@@ -1,3 +1,3 @@
1
1
  module OpalWebpackLoader
2
- VERSION="0.6.4"
2
+ VERSION="0.6.5"
3
3
  end
@@ -22,7 +22,6 @@ RSpec.describe 'owl installer' do
22
22
  arg_val = %w[rails]
23
23
  expect(Dir.exist?(File.join('railing', 'config', 'webpack'))).to be false
24
24
  OpalWebpackLoader::Installer::CLI.start(arg_val)
25
-
26
25
  expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application.js'))).to be true
27
26
  expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application.js_owl_new'))).to be true
28
27
  expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application_common.js'))).to be true
@@ -44,7 +43,6 @@ RSpec.describe 'owl installer' do
44
43
  arg_val = %w[rails -o hyperhyper]
45
44
  expect(Dir.exist?(File.join('railing', 'config', 'webpack'))).to be false
46
45
  OpalWebpackLoader::Installer::CLI.start(arg_val)
47
-
48
46
  expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application.js'))).to be true
49
47
  expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application.js_owl_new'))).to be true
50
48
  expect(File.exist?(File.join('app', 'assets', 'javascripts', 'application_common.js'))).to be true
@@ -80,12 +78,14 @@ RSpec.describe 'owl installer' do
80
78
  Dir.chdir('flattering')
81
79
  arg_val = %w[flat]
82
80
  OpalWebpackLoader::Installer::CLI.start(arg_val)
81
+ expect(File.exist?(File.join('styles', 'application.css'))).to be true
83
82
  expect(File.exist?(File.join('javascripts', 'application.js'))).to be true
84
83
  expect(File.exist?(File.join('javascripts', 'application_common.js'))).to be true
85
84
  expect(File.exist?(File.join('javascripts', 'application_debug.js'))).to be true
86
85
  expect(File.exist?(File.join('javascripts', 'application_ssr.js'))).to be true
87
86
  expect(File.exist?(File.join('opal', 'opal_loader.rb'))).to be true
88
87
  expect(File.exist?(File.join('owl_init.rb'))).to be true
88
+ expect(File.exist?(File.join('app_loader.rb'))).to be true
89
89
  expect(File.exist?(File.join('webpack', 'debug.js'))).to be true
90
90
  expect(File.exist?(File.join('webpack', 'development.js'))).to be true
91
91
  expect(File.exist?(File.join('webpack', 'production.js'))).to be true
data/spec/owl_spec.rb CHANGED
@@ -2,15 +2,20 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe 'owl' do
4
4
  context 'in a rails app' do
5
+ before :all do
6
+ `npm pack`
7
+ end
8
+
5
9
  before do
6
10
  Dir.chdir('spec')
7
11
  Dir.chdir('test_apps')
8
12
  FileUtils.rm_rf('railing') if Dir.exist?('railing')
13
+ `yarn cache clean`
9
14
  end
10
15
 
11
16
  after do
12
17
  Dir.chdir('..') if Dir.pwd.end_with?('railing')
13
- FileUtils.rm_rf('railing') if Dir.exist?('railing')
18
+ # FileUtils.rm_rf('railing') if Dir.exist?('railing')
14
19
  Dir.chdir('..')
15
20
  Dir.chdir('..')
16
21
  end
@@ -31,6 +36,11 @@ RSpec.describe 'owl' do
31
36
 
32
37
  GEMS
33
38
  File.write('Gemfile', gemfile)
39
+ # add local owl npm package
40
+ package_json = Oj.load(File.read('package.json'), mode: :strict)
41
+ package_json["devDependencies"].delete("opal-webpack-loader")
42
+ File.write('package.json', Oj.dump(package_json, mode: :strict))
43
+ `yarn add file:../../../opal-webpack-loader-#{OpalWebpackLoader::VERSION}.tgz --dev`
34
44
  `yarn install`
35
45
  # bundler set some environment things, but we need a clean environment, so things don't get mixed up, use env
36
46
  `env -i PATH="#{ENV['PATH']}" bundle install`
@@ -44,15 +54,20 @@ RSpec.describe 'owl' do
44
54
  end
45
55
 
46
56
  context 'in a roda app' do
57
+ before :all do
58
+ `npm pack`
59
+ end
60
+
47
61
  before do
48
62
  Dir.chdir('spec')
49
63
  Dir.chdir('test_apps')
50
64
  FileUtils.rm_rf('flattering') if Dir.exist?('flattering')
65
+ `yarn cache clean`
51
66
  end
52
67
 
53
68
  after do
54
69
  Dir.chdir('..') if Dir.pwd.end_with?('flattering')
55
- FileUtils.rm_rf('flattering') if Dir.exist?('flattering')
70
+ #FileUtils.rm_rf('flattering') if Dir.exist?('flattering')
56
71
  Dir.chdir('..')
57
72
  Dir.chdir('..')
58
73
  end
@@ -72,6 +87,11 @@ RSpec.describe 'owl' do
72
87
 
73
88
  GEMS
74
89
  File.write('Gemfile', gemfile)
90
+ # add local owl npm package
91
+ package_json = Oj.load(File.read('package.json'), mode: :strict)
92
+ package_json["devDependencies"].delete("opal-webpack-loader")
93
+ File.write('package.json', Oj.dump(package_json, mode: :strict))
94
+ `yarn add file:../../../opal-webpack-loader-#{OpalWebpackLoader::VERSION}.tgz --dev`
75
95
  `yarn install`
76
96
  # bundler set some environment things, but we need a clean environment, so things don't get mixed up, use env
77
97
  `env -i PATH="#{ENV['PATH']}" bundle install`
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'oj'
3
3
  require 'thor'
4
+ require_relative '../lib/opal-webpack-loader/version'
4
5
  require_relative '../lib/opal-webpack-loader/installer_cli'
5
6
 
6
7
  RSpec.configure do |config|
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.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-26 00:00:00.000000000 Z
11
+ date: 2019-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
@@ -155,6 +155,7 @@ files:
155
155
  - lib/opal-webpack-loader/rails_view_helper.rb
156
156
  - lib/opal-webpack-loader/templates/Procfile.erb
157
157
  - lib/opal-webpack-loader/templates/app_loader.rb.erb
158
+ - lib/opal-webpack-loader/templates/application.css.erb
158
159
  - lib/opal-webpack-loader/templates/application.js.erb
159
160
  - lib/opal-webpack-loader/templates/application_common.js.erb
160
161
  - lib/opal-webpack-loader/templates/application_debug.js.erb