actionview-svelte-handler 0.5.7 → 0.6.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 +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
data/lib/ts/builder.ts
CHANGED
@@ -1,10 +1,15 @@
|
|
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';
|
8
13
|
|
9
14
|
export interface BuildSuccess {
|
10
15
|
client: string
|
@@ -40,6 +45,7 @@ class Builder {
|
|
40
45
|
ssr: boolean
|
41
46
|
workingDir: string
|
42
47
|
preprocess: object
|
48
|
+
pathAliases?: object
|
43
49
|
|
44
50
|
constructor (
|
45
51
|
path: string,
|
@@ -49,10 +55,11 @@ class Builder {
|
|
49
55
|
server: string | null,
|
50
56
|
ssr: boolean,
|
51
57
|
workingDir: string,
|
52
|
-
preprocess: object
|
58
|
+
preprocess: object,
|
59
|
+
pathAliases: object
|
53
60
|
) {
|
54
61
|
this.path = path
|
55
|
-
this.props = readable(props)
|
62
|
+
this.props = readable(Object.assign(props, locals, props))
|
56
63
|
this.locals = locals
|
57
64
|
this.compiled = {
|
58
65
|
client,
|
@@ -61,55 +68,70 @@ class Builder {
|
|
61
68
|
this.ssr = ssr
|
62
69
|
this.workingDir = workingDir
|
63
70
|
this.preprocess = preprocess
|
71
|
+
this.pathAliases = pathAliases
|
64
72
|
}
|
65
73
|
|
66
|
-
async bundle (generate: 'ssr' | 'dom'
|
67
|
-
const bundle = await
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
metafile: true,
|
74
|
+
async bundle (generate: 'ssr' | 'dom'): Promise<string> {
|
75
|
+
const bundle = (await (await rollup({
|
76
|
+
input: 'entry',
|
77
|
+
output: {
|
78
|
+
format: "esm",
|
79
|
+
sourcemap: false
|
80
|
+
},
|
81
|
+
watch: {
|
82
|
+
skipWrite: true
|
83
|
+
},
|
77
84
|
plugins: [
|
78
|
-
// @ts-expect-error
|
79
|
-
|
85
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
86
|
+
virtual({
|
87
|
+
entry: `import App from '${this.path}'; export default App`
|
88
|
+
}),
|
89
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
90
|
+
svelte({
|
80
91
|
compilerOptions: {
|
81
92
|
generate,
|
82
93
|
css: 'injected',
|
83
94
|
hydratable: true,
|
84
|
-
sveltePath
|
85
95
|
},
|
96
|
+
emitCss: false,
|
86
97
|
preprocess: sveltePreprocess(this.preprocess),
|
87
|
-
|
98
|
+
onwarn: (warning: Warning, handler: Function) => {
|
88
99
|
if (
|
89
100
|
warning.code === 'missing-declaration' &&
|
90
101
|
warning.message.includes("'props'")
|
91
|
-
)
|
92
|
-
|
102
|
+
) return
|
103
|
+
|
104
|
+
handler(warning)
|
105
|
+
}
|
106
|
+
}),
|
107
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
108
|
+
alias({
|
109
|
+
entries: Object.entries(this.pathAliases || {}).map((k, v) => { return new Object({ find: k, replacement: v }) })
|
110
|
+
}),
|
111
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
112
|
+
commonjs(),
|
113
|
+
nodeResolve({
|
114
|
+
browser: true,
|
115
|
+
exportConditions: ['svelte'],
|
116
|
+
extensions: ['.svelte']
|
117
|
+
}),
|
118
|
+
// @ts-expect-error see https://github.com/rollup/plugins/issues/1662
|
119
|
+
swc({
|
120
|
+
swc: {
|
121
|
+
jsc: {
|
122
|
+
target: "es6"
|
93
123
|
}
|
94
|
-
return true
|
95
124
|
}
|
96
125
|
})
|
97
126
|
]
|
98
|
-
})
|
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
|
127
|
+
})).generate({ format: "esm", sourcemap: "inline" })).output
|
128
|
+
|
129
|
+
return bundle[0].code
|
108
130
|
}
|
109
131
|
|
110
132
|
async client (): Promise<string> {
|
111
133
|
return (
|
112
|
-
this.compiled?.client ||
|
134
|
+
this.compiled?.client || this.standardizeClient(await this.bundle("dom")) // eslint-disable-line
|
113
135
|
)
|
114
136
|
}
|
115
137
|
|
@@ -135,7 +157,7 @@ class Builder {
|
|
135
157
|
return false
|
136
158
|
}
|
137
159
|
})
|
138
|
-
|
160
|
+
|
139
161
|
return recast.print(ast).code
|
140
162
|
}
|
141
163
|
|
data/lib/ts/types/builder.d.ts
CHANGED
@@ -29,8 +29,9 @@ declare class Builder {
|
|
29
29
|
ssr: boolean;
|
30
30
|
workingDir: string;
|
31
31
|
preprocess: object;
|
32
|
-
|
33
|
-
|
32
|
+
pathAliases?: object;
|
33
|
+
constructor(path: string, props: object, locals: object, client: string | null, server: string | null, ssr: boolean, workingDir: string, preprocess: object, pathAliases: object);
|
34
|
+
bundle(generate: 'ssr' | 'dom'): Promise<string>;
|
34
35
|
client(): Promise<string>;
|
35
36
|
standardizeClient(code: string): string;
|
36
37
|
server(): Promise<{
|