actionview-svelte-handler 0.5.7 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +78 -37
- data/lib/svelte/railtie.rb +3 -0
- data/lib/svelte/templates/assembler.js.erb +5 -3
- data/lib/svelte/templates/island.html.erb +7 -9
- data/lib/svelte/version.rb +1 -1
- data/lib/svelte.rb +9 -6
- data/lib/ts/builder.ts +72 -34
- data/lib/ts/types/builder.d.ts +4 -2
- data/package-lock.json +970 -114
- data/package.json +11 -3
- 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
@@ -7,14 +7,12 @@
|
|
7
7
|
<%= result.dig(:server, :css) %>
|
8
8
|
</style>
|
9
9
|
<template data-island>
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
});
|
18
|
-
</script>
|
10
|
+
<script type="module"><%= result.dig(:client).strip %>;
|
11
|
+
new App({
|
12
|
+
target: document.getElementById("hydratee-<%= digest %>"),
|
13
|
+
props: JSON.parse('<%= locals.to_json %>'),
|
14
|
+
hydrate: true
|
15
|
+
});
|
16
|
+
</script>
|
19
17
|
</template>
|
20
18
|
</is-land>
|
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
|
data/lib/ts/builder.ts
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
import { readable, Stores } from 'svelte/store'
|
2
2
|
import { importFromStringSync } from 'module-from-string'
|
3
|
-
import * as esbuild from 'esbuild'
|
4
|
-
import sveltePlugin from 'esbuild-svelte'
|
5
3
|
import { sveltePreprocess } from 'svelte-preprocess'
|
6
4
|
import type { Warning } from 'svelte/types/compiler/interfaces'
|
7
5
|
import * as recast from 'recast'
|
6
|
+
import { rollup } from 'rollup';
|
7
|
+
import svelte from "rollup-plugin-svelte"
|
8
|
+
import alias from '@rollup/plugin-alias';
|
9
|
+
import commonjs from '@rollup/plugin-commonjs';
|
10
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
11
|
+
import virtual from '@rollup/plugin-virtual';
|
12
|
+
import swc from '@rollup/plugin-swc';
|
13
|
+
import path from "node:path"
|
8
14
|
|
9
15
|
export interface BuildSuccess {
|
10
16
|
client: string
|
@@ -40,19 +46,24 @@ class Builder {
|
|
40
46
|
ssr: boolean
|
41
47
|
workingDir: string
|
42
48
|
preprocess: object
|
49
|
+
pathAliases?: object
|
50
|
+
root: string
|
43
51
|
|
44
52
|
constructor (
|
45
53
|
path: string,
|
54
|
+
root: string,
|
46
55
|
props: object,
|
47
56
|
locals: object,
|
48
57
|
client: string | null,
|
49
58
|
server: string | null,
|
50
59
|
ssr: boolean,
|
51
60
|
workingDir: string,
|
52
|
-
preprocess: object
|
61
|
+
preprocess: object,
|
62
|
+
pathAliases: object
|
53
63
|
) {
|
54
64
|
this.path = path
|
55
|
-
this.
|
65
|
+
this.root = root
|
66
|
+
this.props = readable(Object.assign(props, locals, props))
|
56
67
|
this.locals = locals
|
57
68
|
this.compiled = {
|
58
69
|
client,
|
@@ -61,55 +72,82 @@ class Builder {
|
|
61
72
|
this.ssr = ssr
|
62
73
|
this.workingDir = workingDir
|
63
74
|
this.preprocess = preprocess
|
75
|
+
this.pathAliases = pathAliases
|
64
76
|
}
|
65
77
|
|
66
|
-
async bundle (generate: 'ssr' | 'dom'
|
67
|
-
const bundle = await
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
metafile: true,
|
78
|
+
async bundle (generate: 'ssr' | 'dom'): Promise<string> {
|
79
|
+
const bundle = (await (await rollup({
|
80
|
+
input: 'entry',
|
81
|
+
output: {
|
82
|
+
format: "esm",
|
83
|
+
sourcemap: true
|
84
|
+
},
|
85
|
+
watch: {
|
86
|
+
skipWrite: true
|
87
|
+
},
|
77
88
|
plugins: [
|
78
|
-
// @ts-expect-error
|
79
|
-
|
89
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
90
|
+
virtual({
|
91
|
+
entry: `import App from '${this.path}'; export default App`
|
92
|
+
}),
|
93
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
94
|
+
svelte({
|
80
95
|
compilerOptions: {
|
81
96
|
generate,
|
82
97
|
css: 'injected',
|
83
98
|
hydratable: true,
|
84
|
-
sveltePath
|
85
99
|
},
|
100
|
+
emitCss: false,
|
86
101
|
preprocess: sveltePreprocess(this.preprocess),
|
87
|
-
|
102
|
+
onwarn: (warning: Warning, handler: Function) => {
|
88
103
|
if (
|
89
104
|
warning.code === 'missing-declaration' &&
|
90
105
|
warning.message.includes("'props'")
|
91
|
-
)
|
92
|
-
|
93
|
-
|
94
|
-
|
106
|
+
) return
|
107
|
+
|
108
|
+
throw new Error(warning.message);
|
109
|
+
}
|
110
|
+
}),
|
111
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
112
|
+
alias({
|
113
|
+
entries: Object.entries(this.pathAliases || {}).map((k, v) => { return new Object({ find: k, replacement: v }) })
|
114
|
+
}),
|
115
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
116
|
+
commonjs(),
|
117
|
+
nodeResolve({
|
118
|
+
browser: true,
|
119
|
+
exportConditions: ['svelte'],
|
120
|
+
extensions: ['.svelte']
|
121
|
+
}),
|
122
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
123
|
+
swc({
|
124
|
+
swc: {
|
125
|
+
jsc: {
|
126
|
+
target: "es6",
|
127
|
+
minify: {
|
128
|
+
format: {
|
129
|
+
comments: 'all'
|
130
|
+
},
|
131
|
+
}
|
132
|
+
},
|
133
|
+
minify: true,
|
134
|
+
sourceMaps: true,
|
135
|
+
inlineSourcesContent: true
|
95
136
|
}
|
96
137
|
})
|
97
138
|
]
|
139
|
+
})).generate({ format: "esm", sourcemap: true })).output
|
140
|
+
|
141
|
+
bundle[0].map!.sources = bundle[0].map!.sources.map((el) => {
|
142
|
+
return path.relative(this.path, this.root) + "/" + path.relative(this.root, el)
|
98
143
|
})
|
99
|
-
|
100
|
-
|
101
|
-
const throwables = [].concat(bundle.errors, bundle.warnings)
|
102
|
-
|
103
|
-
if (throwables.length > 0) {
|
104
|
-
throw throwables[0] // eslint-disable-line @typescript-eslint/no-throw-literal
|
105
|
-
}
|
106
|
-
|
107
|
-
return bundle.outputFiles[0].text
|
144
|
+
|
145
|
+
return `//# sourceMappingURL=${bundle[0].map!.toUrl()}\n//# sourceURL=${path.relative(this.path, this.root) + "/" + path.relative(this.root, this.path) }\n${bundle[0].code}`.trim()
|
108
146
|
}
|
109
147
|
|
110
148
|
async client (): Promise<string> {
|
111
149
|
return (
|
112
|
-
this.compiled?.client ||
|
150
|
+
this.compiled?.client || this.standardizeClient(await this.bundle("dom")) // eslint-disable-line
|
113
151
|
)
|
114
152
|
}
|
115
153
|
|
@@ -135,7 +173,7 @@ class Builder {
|
|
135
173
|
return false
|
136
174
|
}
|
137
175
|
})
|
138
|
-
|
176
|
+
|
139
177
|
return recast.print(ast).code
|
140
178
|
}
|
141
179
|
|
data/lib/ts/types/builder.d.ts
CHANGED
@@ -29,8 +29,10 @@ declare class Builder {
|
|
29
29
|
ssr: boolean;
|
30
30
|
workingDir: string;
|
31
31
|
preprocess: object;
|
32
|
-
|
33
|
-
|
32
|
+
pathAliases?: object;
|
33
|
+
root: string;
|
34
|
+
constructor(path: string, root: string, props: object, locals: object, client: string | null, server: string | null, ssr: boolean, workingDir: string, preprocess: object, pathAliases: object);
|
35
|
+
bundle(generate: 'ssr' | 'dom'): Promise<string>;
|
34
36
|
client(): Promise<string>;
|
35
37
|
standardizeClient(code: string): string;
|
36
38
|
server(): Promise<{
|