actionview-svelte-handler 0.5.7 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/README.md +1 -1
- data/actionview-svelte-handler.gemspec +3 -0
- data/lib/actionview-svelte-handler.rb +1 -0
- data/lib/generators/svelte/install_generator.rb +2 -1
- data/lib/svelte/errors.rb +140 -138
- data/lib/svelte/handler.rb +45 -41
- data/lib/svelte/helpers.rb +1 -1
- data/lib/svelte/js/builder.js +55 -30
- data/lib/svelte/railtie.rb +3 -0
- data/lib/svelte/templates/assembler.js.erb +3 -2
- data/lib/svelte/version.rb +1 -1
- data/lib/svelte.rb +9 -6
- data/lib/ts/builder.ts +56 -34
- data/lib/ts/types/builder.d.ts +3 -2
- data/package-lock.json +960 -124
- data/package.json +14 -2
- data/rbs_collection.lock.yaml +60 -28
- data/sig/lib/svelte/errors.rbs +35 -34
- data/sig/lib/svelte.rbs +1 -1
- data/tmp/.gitkeep +0 -0
- metadata +19 -4
- data/svelte-on-rails.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c662bff173e3c32b2785f35eec52ac42e05abb82e6572c900ecaf86dae1d8ac
|
4
|
+
data.tar.gz: a076f194d83d7742d76483d8ab789f283838589b2fb728386123dd070523592e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83ca34a75800e1eab54d46885932a4a70e2828aec25f2b98177955ac357811f3024516826c438902fa177333b1f1504286f39dd83ffe6f539e54bd2a6d915e94
|
7
|
+
data.tar.gz: 264abb20627100eb9e4ed8f5f2417a752c12a397bc77494f6583a2dceb48aed2bbe5b25eac9d0174787cc7992f9df4dfb5113be06ab274205f21d99b9b3409b0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
<img src="https://codeberg.org/reesericci/actionview-svelte-handler/raw/branch/main/
|
1
|
+
<img src="https://codeberg.org/reesericci/actionview-svelte-handler/raw/branch/main/docs/public/logo.png" width="100px">
|
2
2
|
|
3
3
|
# `actionview-svelte-handler`
|
4
4
|
|
@@ -2,6 +2,7 @@ require_relative "lib/svelte/version"
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "actionview-svelte-handler"
|
5
|
+
spec.autorequire = "svelte"
|
5
6
|
spec.version = Svelte::VERSION
|
6
7
|
spec.authors = ["reesericci"]
|
7
8
|
spec.email = ["me@reeseric.ci"]
|
@@ -18,4 +19,6 @@ Gem::Specification.new do |spec|
|
|
18
19
|
end
|
19
20
|
|
20
21
|
spec.add_runtime_dependency "rails", "~> 7.0"
|
22
|
+
|
23
|
+
spec.add_dependency "zeitwerk", "~> 2"
|
21
24
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "svelte"
|
@@ -9,7 +9,8 @@ module Svelte
|
|
9
9
|
insert_into_file "app/views/layouts/application.html.erb",
|
10
10
|
"\n <%= svelte_tags %>",
|
11
11
|
after: "<head>"
|
12
|
-
`npm
|
12
|
+
`npm link #{Gem::Specification.find_by_name("actionview-svelte-handler").gem_dir} --save`
|
13
|
+
`npm install`
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
data/lib/svelte/errors.rb
CHANGED
@@ -1,148 +1,150 @@
|
|
1
1
|
require "active_support/syntax_error_proxy"
|
2
2
|
require "action_view/template/error"
|
3
3
|
module Svelte
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
def message
|
16
|
-
to_s
|
17
|
-
end
|
18
|
-
|
19
|
-
def backtrace
|
20
|
-
if suggestion
|
21
|
-
["#{Rails.root.join location[:file]}:#{location[:line]}:#{message}, #{suggestion}"] + caller
|
22
|
-
else
|
23
|
-
["#{Rails.root.join location[:file]}:#{location[:line]}:#{message}"] + caller
|
4
|
+
module Errors
|
5
|
+
class CompilerError < ActiveSupport::SyntaxErrorProxy # steep:ignore UnknownConstant
|
6
|
+
attr_accessor :location, :suggestion, :template
|
7
|
+
|
8
|
+
def initialize(message, location)
|
9
|
+
@location = location
|
10
|
+
@sugggestion = @location.dig(:suggestion) || ""
|
11
|
+
# steep:ignore:start
|
12
|
+
super(message) # : self
|
13
|
+
# steep:ignore:end
|
24
14
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
nil
|
29
|
-
end
|
30
|
-
|
31
|
-
def bindings
|
32
|
-
[template.send(:binding)]
|
33
|
-
end
|
34
|
-
|
35
|
-
def backtrace_locations
|
36
|
-
traces = backtrace.map { |trace|
|
37
|
-
file, line = trace.match(/^(.+?):(\d+).*$/, &:captures) || trace
|
38
|
-
ActiveSupport::SyntaxErrorProxy::BacktraceLocation.new(file, line.to_i, trace) # steep:ignore UnknownConstant
|
39
|
-
}
|
40
|
-
|
41
|
-
traces.map { |loc| ActiveSupport::SyntaxErrorProxy::BacktraceLocationProxy.new(loc, self) } # steep:ignore UnknownConstant
|
42
|
-
end
|
43
|
-
|
44
|
-
def annotated_source_code
|
45
|
-
location[:lineText].split("\n").map.with_index(1) { |line, index|
|
46
|
-
indentation = " " * 4
|
47
|
-
"#{index}:#{indentation}#{line}"
|
48
|
-
}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class TemplateError < StandardError
|
53
|
-
attr_reader :cause, :template
|
54
|
-
|
55
|
-
SOURCE_CODE_RADIUS = 3
|
56
|
-
|
57
|
-
def initialize(template, error)
|
58
|
-
raise("Did not provide cause error") unless error
|
59
|
-
@cause = error
|
60
|
-
|
61
|
-
raise("Did not provide template") unless template
|
62
|
-
@template, @sub_templates = template, nil
|
63
|
-
|
64
|
-
raise("Cause error is nil for TemplateError") unless @cause
|
65
|
-
@cause.template = template
|
66
|
-
|
67
|
-
# steep:ignore:start
|
68
|
-
super(@cause.message) # : self
|
69
|
-
# steep:ignore:end
|
70
|
-
end
|
71
|
-
|
72
|
-
def message
|
73
|
-
@cause.message
|
74
|
-
end
|
75
|
-
|
76
|
-
def annotated_source_code
|
77
|
-
@cause.annotated_source_code
|
78
|
-
end
|
79
|
-
|
80
|
-
# Following is copypasta-ed from ActionView::Template::Error
|
81
|
-
def backtrace
|
82
|
-
@cause.backtrace
|
83
|
-
end
|
84
|
-
|
85
|
-
def backtrace_locations
|
86
|
-
@cause.backtrace_locations
|
87
|
-
end
|
88
|
-
|
89
|
-
def file_name
|
90
|
-
@template.identifier
|
91
|
-
end
|
92
|
-
|
93
|
-
def sub_template_message
|
94
|
-
if @sub_templates
|
95
|
-
"Trace of template inclusion: " +
|
96
|
-
@sub_templates.collect(&:inspect).join(", ")
|
97
|
-
else
|
98
|
-
""
|
15
|
+
|
16
|
+
def message
|
17
|
+
to_s
|
99
18
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
source_code = @template.encode!.split("\n")
|
107
|
-
|
108
|
-
start_on_line = [num - SOURCE_CODE_RADIUS - 1, 0].max
|
109
|
-
end_on_line = [num + SOURCE_CODE_RADIUS - 1, source_code.length].min
|
110
|
-
|
111
|
-
indent = end_on_line.to_s.size + indentation
|
112
|
-
return [] unless (source_code = source_code[start_on_line..end_on_line])
|
113
|
-
|
114
|
-
formatted_code_for(source_code, start_on_line, indent)
|
115
|
-
end
|
116
|
-
|
117
|
-
def sub_template_of(template_path)
|
118
|
-
@sub_templates ||= []
|
119
|
-
@sub_templates << template_path
|
120
|
-
end
|
121
|
-
|
122
|
-
def line_number
|
123
|
-
@line_number ||=
|
124
|
-
if file_name
|
125
|
-
regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
|
126
|
-
$1 if message =~ regexp || backtrace.find { |line| line =~ regexp }
|
19
|
+
|
20
|
+
def backtrace
|
21
|
+
if suggestion
|
22
|
+
["#{Rails.root.join location[:file]}:#{location[:line]}:#{message}, #{suggestion}"] + caller
|
23
|
+
else
|
24
|
+
["#{Rails.root.join location[:file]}:#{location[:line]}:#{message}"] + caller
|
127
25
|
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def cause
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def bindings
|
33
|
+
[template.send(:binding)]
|
34
|
+
end
|
35
|
+
|
36
|
+
def backtrace_locations
|
37
|
+
traces = backtrace.map { |trace|
|
38
|
+
file, line = trace.match(/^(.+?):(\d+).*$/, &:captures) || trace
|
39
|
+
ActiveSupport::SyntaxErrorProxy::BacktraceLocation.new(file, line.to_i, trace) # steep:ignore UnknownConstant
|
40
|
+
}
|
41
|
+
|
42
|
+
traces.map { |loc| ActiveSupport::SyntaxErrorProxy::BacktraceLocationProxy.new(loc, self) } # steep:ignore UnknownConstant
|
43
|
+
end
|
44
|
+
|
45
|
+
def annotated_source_code
|
46
|
+
location[:lineText].split("\n").map.with_index(1) { |line, index|
|
47
|
+
indentation = " " * 4
|
48
|
+
"#{index}:#{indentation}#{line}"
|
49
|
+
}
|
50
|
+
end
|
128
51
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
"
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
52
|
+
|
53
|
+
class TemplateError < StandardError
|
54
|
+
attr_reader :cause, :template
|
55
|
+
|
56
|
+
SOURCE_CODE_RADIUS = 3
|
57
|
+
|
58
|
+
def initialize(template, error)
|
59
|
+
raise("Did not provide cause error") unless error
|
60
|
+
@cause = error
|
61
|
+
|
62
|
+
raise("Did not provide template") unless template
|
63
|
+
@template, @sub_templates = template, nil
|
64
|
+
|
65
|
+
raise("Cause error is nil for TemplateError") unless @cause
|
66
|
+
@cause.template = template
|
67
|
+
|
68
|
+
# steep:ignore:start
|
69
|
+
super(@cause.message) # : self
|
70
|
+
# steep:ignore:end
|
71
|
+
end
|
72
|
+
|
73
|
+
def message
|
74
|
+
@cause.message
|
75
|
+
end
|
76
|
+
|
77
|
+
def annotated_source_code
|
78
|
+
@cause.annotated_source_code
|
79
|
+
end
|
80
|
+
|
81
|
+
# Following is copypasta-ed from ActionView::Template::Error
|
82
|
+
def backtrace
|
83
|
+
@cause.backtrace
|
84
|
+
end
|
85
|
+
|
86
|
+
def backtrace_locations
|
87
|
+
@cause.backtrace_locations
|
88
|
+
end
|
89
|
+
|
90
|
+
def file_name
|
91
|
+
@template.identifier
|
92
|
+
end
|
93
|
+
|
94
|
+
def sub_template_message
|
95
|
+
if @sub_templates
|
96
|
+
"Trace of template inclusion: " +
|
97
|
+
@sub_templates.collect(&:inspect).join(", ")
|
98
|
+
else
|
99
|
+
""
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def source_extract(indentation = 0)
|
104
|
+
return [] unless (num = line_number)
|
105
|
+
num = num.to_i
|
106
|
+
|
107
|
+
source_code = @template.encode!.split("\n")
|
108
|
+
|
109
|
+
start_on_line = [num - SOURCE_CODE_RADIUS - 1, 0].max
|
110
|
+
end_on_line = [num + SOURCE_CODE_RADIUS - 1, source_code.length].min
|
111
|
+
|
112
|
+
indent = end_on_line.to_s.size + indentation
|
113
|
+
return [] unless (source_code = source_code[start_on_line..end_on_line])
|
114
|
+
|
115
|
+
formatted_code_for(source_code, start_on_line, indent)
|
116
|
+
end
|
117
|
+
|
118
|
+
def sub_template_of(template_path)
|
119
|
+
@sub_templates ||= []
|
120
|
+
@sub_templates << template_path
|
121
|
+
end
|
122
|
+
|
123
|
+
def line_number
|
124
|
+
@line_number ||=
|
125
|
+
if file_name
|
126
|
+
regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/
|
127
|
+
$1 if message =~ regexp || backtrace.find { |line| line =~ regexp }
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def source_location
|
134
|
+
if line_number
|
135
|
+
"on line ##{line_number} of "
|
136
|
+
else
|
137
|
+
"in "
|
138
|
+
end + file_name
|
139
|
+
end
|
140
|
+
|
141
|
+
def formatted_code_for(source_code, line_counter, indent)
|
142
|
+
raise("line counter is nil") if line_counter.nil?
|
143
|
+
indent_template = "%#{indent}s: %s"
|
144
|
+
source_code.map do |line|
|
145
|
+
line_counter += 1
|
146
|
+
indent_template % [line_counter, line]
|
147
|
+
end
|
146
148
|
end
|
147
149
|
end
|
148
150
|
end
|
data/lib/svelte/handler.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "erb"
|
2
2
|
require "svelte/helpers"
|
3
|
+
require "ostruct"
|
3
4
|
|
4
5
|
module Svelte
|
5
6
|
DISCARD_PROPS = %w[lookup_context view_renderer current_template output_buffer view_flow rendered_format marked_for_same_origin_verification virtual_path]
|
@@ -13,50 +14,53 @@ module Svelte
|
|
13
14
|
digest = Digest::SHA256.base64digest(source)
|
14
15
|
|
15
16
|
<<-RUBY
|
16
|
-
|
17
|
-
|
18
|
-
Svelte.props.merge!(
|
19
|
-
instance_values.reject { |k,v|
|
20
|
-
k.start_with?("_") || Svelte::DISCARD_PROPS.include?(k)
|
21
|
-
}
|
22
|
-
) { |key,old,new| old }
|
23
|
-
|
24
|
-
Svelte.props.deep_symbolize_keys!
|
25
|
-
|
26
|
-
if local_assigns.dig(:svelte) == nil
|
27
|
-
local_assigns[:svelte] = {}
|
28
|
-
end
|
29
|
-
|
30
|
-
assembler = nil
|
31
|
-
|
32
|
-
assembler = Tempfile.new(['assembler', ".mjs"], '#{Svelte.gem_dir}/tmp')
|
17
|
+
Dir.mktmpdir("svelte", Rails.root.join('tmp')) do |dir|
|
18
|
+
template = OpenStruct.new(JSON.parse('#{template.to_json}').deep_symbolize_keys)
|
33
19
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
20
|
+
Svelte.props.merge!(
|
21
|
+
instance_values.reject { |k,v|
|
22
|
+
k.start_with?("_") || Svelte::DISCARD_PROPS.include?(k)
|
23
|
+
}
|
24
|
+
) { |key,old,new| old }
|
25
|
+
|
26
|
+
Svelte.props.deep_symbolize_keys!
|
27
|
+
|
28
|
+
if local_assigns.dig(:svelte) == nil
|
29
|
+
local_assigns[:svelte] = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
assembler = nil
|
33
|
+
|
34
|
+
assembler = Tempfile.new(['assembler', ".mjs"], dir)
|
35
|
+
|
36
|
+
assembler.write(ERB.new(File.read('#{Svelte.gem_dir}/lib/svelte/templates/assembler.js.erb')).result_with_hash({
|
37
|
+
path: '#{Rails.root.join template.identifier}',
|
38
|
+
locals: local_assigns,
|
39
|
+
compiled_client: j(Rails.cache.read('svelte/template/client' + '#{digest}')),
|
40
|
+
compiled_server: j(Rails.cache.read('svelte/template/server' + '#{digest}')),
|
41
|
+
ssr: Svelte.precedence(local_assigns.dig(:svelte, :ssr), template.variant.nil? ? nil : (template.variant == "server"), Svelte.ssr)
|
42
|
+
}))
|
43
|
+
|
44
|
+
assembler.rewind
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
result = JSON.parse(`NODE_PATH=#{Rails.root.join("node_modules")} NODE_NO_WARNINGS=1 node --experimental-vm-modules \#{assembler.path}`).deep_symbolize_keys
|
47
|
+
|
48
|
+
if result[:error]
|
49
|
+
e = Svelte::Errors::CompilerError.new(result.dig(:error, :text), result.dig(:error, :location))
|
50
|
+
raise Svelte::Errors::TemplateError.new(template, e)
|
51
|
+
end
|
52
|
+
|
53
|
+
assembler&.close
|
54
|
+
assembler&.unlink
|
55
|
+
|
56
|
+
Rails.cache.write("svelte/template/client/" + '#{digest}', result[:compiled][:client], expires_in: 14.days)
|
57
|
+
Rails.cache.write("svelte/template/server/" + '#{digest}', result[:compiled][:server], expires_in: 14.days)
|
58
|
+
|
59
|
+
content_for(:head, (result.dig(:server, :head) || "").html_safe)
|
60
|
+
|
61
|
+
ERB.new(File.read("#{Svelte.gem_dir}/lib/svelte/templates/island.html.erb")).result_with_hash({ result:, locals: local_assigns, digest: "#{digest}", bind: binding })
|
62
|
+
|
49
63
|
end
|
50
|
-
|
51
|
-
assembler&.close
|
52
|
-
assembler&.unlink
|
53
|
-
|
54
|
-
Rails.cache.write("svelte/template/client/" + '#{digest}', result[:compiled][:client], expires_in: 14.days)
|
55
|
-
Rails.cache.write("svelte/template/server/" + '#{digest}', result[:compiled][:server], expires_in: 14.days)
|
56
|
-
|
57
|
-
content_for(:head, (result.dig(:server, :head) || "").html_safe)
|
58
|
-
|
59
|
-
ERB.new(File.read("#{Svelte.gem_dir}/lib/svelte/templates/island.html.erb")).result_with_hash({ result:, locals: local_assigns, digest: "#{digest}", bind: binding })
|
60
64
|
RUBY
|
61
65
|
end
|
62
66
|
|
data/lib/svelte/helpers.rb
CHANGED
@@ -9,7 +9,7 @@ module Svelte
|
|
9
9
|
window.props = readable(JSON.parse("#{j(Svelte.props.to_json)}"))
|
10
10
|
JS
|
11
11
|
|
12
|
-
content_for(:head) + "\n" + tag.script(js.html_safe, type: "module") # steep:ignore RequiredBlockMissing
|
12
|
+
((content_for(:head).presence || "") + "\n" + tag.script(js.html_safe, type: "module")).html_safe # steep:ignore RequiredBlockMissing
|
13
13
|
end
|
14
14
|
|
15
15
|
delegate :destructure_attrs, to: :class
|
data/lib/svelte/js/builder.js
CHANGED
@@ -6,10 +6,15 @@
|
|
6
6
|
|
7
7
|
import { readable } from "svelte/store";
|
8
8
|
import { importFromStringSync } from "module-from-string";
|
9
|
-
import * as esbuild from "esbuild";
|
10
|
-
import sveltePlugin from "esbuild-svelte";
|
11
9
|
import { sveltePreprocess } from "svelte-preprocess";
|
12
10
|
import * as recast from "recast";
|
11
|
+
import { rollup } from "rollup";
|
12
|
+
import svelte from "rollup-plugin-svelte";
|
13
|
+
import alias from "@rollup/plugin-alias";
|
14
|
+
import commonjs from "@rollup/plugin-commonjs";
|
15
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
16
|
+
import virtual from "@rollup/plugin-virtual";
|
17
|
+
import swc from "@rollup/plugin-swc";
|
13
18
|
class Builder {
|
14
19
|
path;
|
15
20
|
props;
|
@@ -18,9 +23,10 @@ class Builder {
|
|
18
23
|
ssr;
|
19
24
|
workingDir;
|
20
25
|
preprocess;
|
21
|
-
|
26
|
+
pathAliases;
|
27
|
+
constructor(path, props, locals, client, server, ssr, workingDir, preprocess, pathAliases) {
|
22
28
|
this.path = path;
|
23
|
-
this.props = readable(props);
|
29
|
+
this.props = readable(Object.assign(props, locals, props));
|
24
30
|
this.locals = locals;
|
25
31
|
this.compiled = {
|
26
32
|
client,
|
@@ -29,45 +35,64 @@ class Builder {
|
|
29
35
|
this.ssr = ssr;
|
30
36
|
this.workingDir = workingDir;
|
31
37
|
this.preprocess = preprocess;
|
38
|
+
this.pathAliases = pathAliases;
|
32
39
|
}
|
33
|
-
async bundle(generate
|
34
|
-
const bundle = await
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
metafile: true,
|
40
|
+
async bundle(generate) {
|
41
|
+
const bundle = (await (await rollup({
|
42
|
+
input: "entry",
|
43
|
+
output: {
|
44
|
+
format: "esm",
|
45
|
+
sourcemap: false
|
46
|
+
},
|
47
|
+
watch: {
|
48
|
+
skipWrite: true
|
49
|
+
},
|
44
50
|
plugins: [
|
45
|
-
// @ts-expect-error
|
46
|
-
|
51
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
52
|
+
virtual({
|
53
|
+
entry: `import App from '${this.path}'; export default App`
|
54
|
+
}),
|
55
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
56
|
+
svelte({
|
47
57
|
compilerOptions: {
|
48
58
|
generate,
|
49
59
|
css: "injected",
|
50
|
-
hydratable: true
|
51
|
-
sveltePath
|
60
|
+
hydratable: true
|
52
61
|
},
|
62
|
+
emitCss: false,
|
53
63
|
preprocess: sveltePreprocess(this.preprocess),
|
54
|
-
|
55
|
-
if (warning.code === "missing-declaration" && warning.message.includes("'props'"))
|
56
|
-
|
64
|
+
onwarn: (warning, handler) => {
|
65
|
+
if (warning.code === "missing-declaration" && warning.message.includes("'props'")) return;
|
66
|
+
handler(warning);
|
67
|
+
}
|
68
|
+
}),
|
69
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
70
|
+
alias({
|
71
|
+
entries: Object.entries(this.pathAliases || {}).map((k, v) => {
|
72
|
+
return new Object({ find: k, replacement: v });
|
73
|
+
})
|
74
|
+
}),
|
75
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
76
|
+
commonjs(),
|
77
|
+
nodeResolve({
|
78
|
+
browser: true,
|
79
|
+
exportConditions: ["svelte"],
|
80
|
+
extensions: [".svelte"]
|
81
|
+
}),
|
82
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
83
|
+
swc({
|
84
|
+
swc: {
|
85
|
+
jsc: {
|
86
|
+
target: "es6"
|
57
87
|
}
|
58
|
-
return true;
|
59
88
|
}
|
60
89
|
})
|
61
90
|
]
|
62
|
-
});
|
63
|
-
|
64
|
-
if (throwables.length > 0) {
|
65
|
-
throw throwables[0];
|
66
|
-
}
|
67
|
-
return bundle.outputFiles[0].text;
|
91
|
+
})).generate({ format: "esm", sourcemap: "inline" })).output;
|
92
|
+
return bundle[0].code;
|
68
93
|
}
|
69
94
|
async client() {
|
70
|
-
return this.compiled?.client || this.standardizeClient(await this.bundle("dom"
|
95
|
+
return this.compiled?.client || this.standardizeClient(await this.bundle("dom"));
|
71
96
|
}
|
72
97
|
standardizeClient(code) {
|
73
98
|
const ast = recast.parse(code);
|
data/lib/svelte/railtie.rb
CHANGED
@@ -4,6 +4,9 @@ require "svelte/helpers"
|
|
4
4
|
module Svelte
|
5
5
|
class Railtie < ::Rails::Railtie
|
6
6
|
initializer "svelte" do |app|
|
7
|
+
`npm link #{Gem::Specification.find_by_name("actionview-svelte-handler").gem_dir} --save`
|
8
|
+
`npm install --install-links`
|
9
|
+
|
7
10
|
ActiveSupport.on_load :action_view do
|
8
11
|
ActionView::Template.register_template_handler :svelte, Svelte::Handler
|
9
12
|
ActionView::Base.send :include, Svelte::Helpers
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import Builder from "
|
1
|
+
import Builder from "actionview-svelte-handler";
|
2
2
|
|
3
3
|
const bob = new Builder(
|
4
4
|
'<%= path %>',
|
@@ -8,7 +8,8 @@ const bob = new Builder(
|
|
8
8
|
'<%= compiled_server || "" %>',
|
9
9
|
<%= ssr %>,
|
10
10
|
'<%= Rails.root %>',
|
11
|
-
JSON.parse('<%= Svelte.preprocess.to_json || "{}" %>')
|
11
|
+
JSON.parse('<%= Svelte.preprocess.to_json || "{}" %>'),
|
12
|
+
JSON.parse('<%= Svelte.aliases.to_json || "{}" %>')
|
12
13
|
)
|
13
14
|
|
14
15
|
const built = await bob.build()
|
data/lib/svelte/version.rb
CHANGED
data/lib/svelte.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "active_support/core_ext"
|
2
|
-
require "svelte/variabilization"
|
3
|
-
require "svelte/railtie"
|
4
|
-
require "svelte/errors"
|
5
|
-
require "svelte/helpers"
|
6
|
-
require "svelte/handler"
|
7
|
-
require "svelte/version"
|
8
2
|
require "active_support/isolated_execution_state"
|
3
|
+
require "zeitwerk"
|
4
|
+
|
5
|
+
loader = Zeitwerk::Loader.for_gem
|
6
|
+
loader.ignore("#{__dir__}/generators")
|
7
|
+
loader.ignore("#{__dir__}/actionview-svelte-handler.rb")
|
8
|
+
|
9
|
+
loader.setup
|
9
10
|
|
10
11
|
module Svelte
|
11
12
|
include ActionView::Helpers::JavaScriptHelper
|
@@ -38,3 +39,5 @@ module Svelte
|
|
38
39
|
nil
|
39
40
|
end
|
40
41
|
end
|
42
|
+
|
43
|
+
loader.eager_load
|