actionview-svelte-handler 0.5.7 → 0.7.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: 35a9952571d74905f67d9219dd86b759f2ac7b11c42fc68a0817f964247fa0d4
4
- data.tar.gz: be744cb8c46cfaafe8e4d3a707499038eb6f3200f0256cc947d766ed325d0d08
3
+ metadata.gz: 1fcb603925b52a51a8488d83da752370c24135602c464b51993f86b58fedf1af
4
+ data.tar.gz: 7f3e9f80901d4b567758e259ab37e5ed7a315459a3b1b867b9f2f847b1697b29
5
5
  SHA512:
6
- metadata.gz: c7ca8ce660365595737c2f60e04b6c027a11f879e540f3af405d31fe168caf58914cb7b7e1a74c08c4ee74e2c226d01c5cb45b39944d981b5eb564074a25c5b2
7
- data.tar.gz: 28fbb9843d9893b9a92a03c26296e7fe3271548ceea5a5e2a559d578d3ec5ff545a3de7f0076e0c62b7605b9494d9996ef397130186313f70030427a4ff41c7b
6
+ metadata.gz: a4260e66a28e3006940465ef5158f3bdf9cc2559327ca14ca4f4ff7c75d405bf051abc7e95de2452e5083a6ef68d51375735735340039ea4fc54ce1f0a4eb6e8
7
+ data.tar.gz: 0b131aebc945768f2a7bfd0a4d16cddf80e4198a54d59dffa48a4da6b76573bfc5e439a332e5ee3c4189fc2f29bc2f5cde3e3045dc44330482244c0406a90f46
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-svelte-handler (0.5.7)
4
+ actionview-svelte-handler (0.7.0)
5
5
  rails (~> 7.0)
6
+ zeitwerk (~> 2)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <img src="https://codeberg.org/reesericci/actionview-svelte-handler/raw/branch/main/svelte-on-rails.png" width="100px">
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 install #{Gem::Specification.find_by_name("actionview-svelte-handler").gem_dir} --install-links --save=false`
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
- class CompilerError < ActiveSupport::SyntaxErrorProxy # steep:ignore UnknownConstant
5
- attr_accessor :location, :suggestion, :template
6
-
7
- def initialize(message, location)
8
- @location = location
9
- @sugggestion = @location.dig(:suggestion) || ""
10
- # steep:ignore:start
11
- super(message) # : self
12
- # steep:ignore:end
13
- end
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
- end
26
-
27
- def cause
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
- end
101
-
102
- def source_extract(indentation = 0)
103
- return [] unless (num = line_number)
104
- num = num.to_i
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
- private
131
-
132
- def source_location
133
- if line_number
134
- "on line ##{line_number} of "
135
- else
136
- "in "
137
- end + file_name
138
- end
139
-
140
- def formatted_code_for(source_code, line_counter, indent)
141
- raise("line counter is nil") if line_counter.nil?
142
- indent_template = "%#{indent}s: %s"
143
- source_code.map do |line|
144
- line_counter += 1
145
- indent_template % [line_counter, line]
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
@@ -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
- template = ObjectSpace._id2ref(#{template.object_id})
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
- assembler.write(ERB.new(File.read('#{Svelte.gem_dir}/lib/svelte/templates/assembler.js.erb')).result_with_hash({
35
- path: '#{Rails.root.join template.identifier}',
36
- locals: local_assigns,
37
- compiled_client: j(Rails.cache.read('svelte/template/client' + '#{digest}')),
38
- compiled_server: j(Rails.cache.read('svelte/template/server' + '#{digest}')),
39
- ssr: Svelte.precedence(local_assigns.dig(:svelte, :ssr), template.variant.nil? ? nil : (template.variant == "server"), Svelte.ssr)
40
- }))
41
-
42
- assembler.rewind
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
43
33
 
44
- result = JSON.parse(`NODE_NO_WARNINGS=1 node --experimental-vm-modules \#{assembler.path}`).deep_symbolize_keys
45
-
46
- if result[:error]
47
- e = Svelte::CompilerError.new(result.dig(:error, :text), result.dig(:error, :location))
48
- raise Svelte::TemplateError.new(template, e)
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
45
+
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
 
@@ -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
@@ -6,10 +6,16 @@
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";
18
+ import path from "node:path";
13
19
  class Builder {
14
20
  path;
15
21
  props;
@@ -18,9 +24,12 @@ class Builder {
18
24
  ssr;
19
25
  workingDir;
20
26
  preprocess;
21
- constructor(path, props, locals, client, server, ssr, workingDir, preprocess) {
22
- this.path = path;
23
- this.props = readable(props);
27
+ pathAliases;
28
+ root;
29
+ constructor(path2, root, props, locals, client, server, ssr, workingDir, preprocess, pathAliases) {
30
+ this.path = path2;
31
+ this.root = root;
32
+ this.props = readable(Object.assign(props, locals, props));
24
33
  this.locals = locals;
25
34
  this.compiled = {
26
35
  client,
@@ -29,61 +38,93 @@ class Builder {
29
38
  this.ssr = ssr;
30
39
  this.workingDir = workingDir;
31
40
  this.preprocess = preprocess;
41
+ this.pathAliases = pathAliases;
32
42
  }
33
- async bundle(generate, sveltePath = "svelte") {
34
- const bundle = await esbuild.build({
35
- entryPoints: [this.path],
36
- mainFields: ["svelte", "browser", "module", "main"],
37
- conditions: ["svelte", "browser"],
38
- absWorkingDir: this.workingDir,
39
- write: false,
40
- outfile: "component.js",
41
- bundle: true,
42
- format: "esm",
43
- metafile: true,
43
+ async bundle(generate) {
44
+ const bundle = (await (await rollup({
45
+ input: "entry",
46
+ output: {
47
+ format: "esm",
48
+ sourcemap: true
49
+ },
50
+ watch: {
51
+ skipWrite: true
52
+ },
44
53
  plugins: [
45
- // @ts-expect-error
46
- sveltePlugin({
54
+ // @ts-expect-error see https://github.com/rollup/plugins/issues/1662
55
+ virtual({
56
+ entry: `import App from '${this.path}'; export default App`
57
+ }),
58
+ // @ts-expect-error see https://github.com/rollup/plugins/issues/1662
59
+ svelte({
47
60
  compilerOptions: {
48
61
  generate,
49
62
  css: "injected",
50
- hydratable: true,
51
- sveltePath
63
+ hydratable: true
52
64
  },
65
+ emitCss: false,
53
66
  preprocess: sveltePreprocess(this.preprocess),
54
- filterWarnings: (warning) => {
55
- if (warning.code === "missing-declaration" && warning.message.includes("'props'")) {
56
- return false;
57
- }
58
- return true;
67
+ onwarn: (warning, handler) => {
68
+ if (warning.code === "missing-declaration" && warning.message.includes("'props'")) return;
69
+ throw new Error(warning.message);
70
+ }
71
+ }),
72
+ // @ts-expect-error see https://github.com/rollup/plugins/issues/1662
73
+ alias({
74
+ entries: Object.entries(this.pathAliases || {}).map((k, v) => {
75
+ return new Object({ find: k, replacement: v });
76
+ })
77
+ }),
78
+ // @ts-expect-error see https://github.com/rollup/plugins/issues/1662
79
+ commonjs(),
80
+ nodeResolve({
81
+ browser: true,
82
+ exportConditions: ["svelte"],
83
+ extensions: [".svelte"]
84
+ }),
85
+ // @ts-expect-error see https://github.com/rollup/plugins/issues/1662
86
+ swc({
87
+ swc: {
88
+ jsc: {
89
+ target: "es6",
90
+ minify: {
91
+ format: {
92
+ comments: "all"
93
+ }
94
+ }
95
+ },
96
+ minify: true,
97
+ sourceMaps: true,
98
+ inlineSourcesContent: true
59
99
  }
60
100
  })
61
101
  ]
102
+ })).generate({ format: "esm", sourcemap: true })).output;
103
+ bundle[0].map.sources = bundle[0].map.sources.map((el) => {
104
+ return path.relative(this.path, this.root) + "/" + path.relative(this.root, el);
62
105
  });
63
- const throwables = [].concat(bundle.errors, bundle.warnings);
64
- if (throwables.length > 0) {
65
- throw throwables[0];
66
- }
67
- return bundle.outputFiles[0].text;
106
+ return `//# sourceMappingURL=${bundle[0].map.toUrl()}
107
+ //# sourceURL=${path.relative(this.path, this.root) + "/" + path.relative(this.root, this.path)}
108
+ ${bundle[0].code}`.trim();
68
109
  }
69
110
  async client() {
70
- return this.compiled?.client || this.standardizeClient(await this.bundle("dom", "https://esm.sh/svelte"));
111
+ return this.compiled?.client || this.standardizeClient(await this.bundle("dom"));
71
112
  }
72
113
  standardizeClient(code) {
73
114
  const ast = recast.parse(code);
74
115
  let name;
75
116
  recast.visit(ast, {
76
- visitExportNamedDeclaration: (path) => {
77
- const stagingName = path.node?.specifiers?.[0].local?.name;
117
+ visitExportNamedDeclaration: (path2) => {
118
+ const stagingName = path2.node?.specifiers?.[0].local?.name;
78
119
  name = typeof stagingName !== "string" ? "" : stagingName;
79
- path.prune();
120
+ path2.prune();
80
121
  return false;
81
122
  }
82
123
  });
83
124
  recast.visit(ast, {
84
- visitIdentifier: (path) => {
85
- if (path.node.name === name) {
86
- path.node.name = "App";
125
+ visitIdentifier: (path2) => {
126
+ if (path2.node.name === name) {
127
+ path2.node.name = "App";
87
128
  }
88
129
  return false;
89
130
  }
@@ -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,14 +1,16 @@
1
- import Builder from "<%= "#{Svelte.gem_dir}/lib/svelte/js/builder.js" %>";
1
+ import Builder from "actionview-svelte-handler";
2
2
 
3
3
  const bob = new Builder(
4
- '<%= path %>',
4
+ '<%= path %>',
5
+ '<%= Rails.root %>',
5
6
  JSON.parse('<%= Svelte.props.to_json || "{}" %>'),
6
7
  JSON.parse('<%= locals.to_json || "{}" %>'),
7
8
  '<%= compiled_client || "" %>',
8
9
  '<%= compiled_server || "" %>',
9
10
  <%= ssr %>,
10
11
  '<%= Rails.root %>',
11
- JSON.parse('<%= Svelte.preprocess.to_json || "{}" %>')
12
+ JSON.parse('<%= Svelte.preprocess.to_json || "{}" %>'),
13
+ JSON.parse('<%= Svelte.aliases.to_json || "{}" %>')
12
14
  )
13
15
 
14
16
  const built = await bob.build()