actionview-svelte-handler 0.6.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c662bff173e3c32b2785f35eec52ac42e05abb82e6572c900ecaf86dae1d8ac
4
- data.tar.gz: a076f194d83d7742d76483d8ab789f283838589b2fb728386123dd070523592e
3
+ metadata.gz: 1fcb603925b52a51a8488d83da752370c24135602c464b51993f86b58fedf1af
4
+ data.tar.gz: 7f3e9f80901d4b567758e259ab37e5ed7a315459a3b1b867b9f2f847b1697b29
5
5
  SHA512:
6
- metadata.gz: 83ca34a75800e1eab54d46885932a4a70e2828aec25f2b98177955ac357811f3024516826c438902fa177333b1f1504286f39dd83ffe6f539e54bd2a6d915e94
7
- data.tar.gz: 264abb20627100eb9e4ed8f5f2417a752c12a397bc77494f6583a2dceb48aed2bbe5b25eac9d0174787cc7992f9df4dfb5113be06ab274205f21d99b9b3409b0
6
+ metadata.gz: a4260e66a28e3006940465ef5158f3bdf9cc2559327ca14ca4f4ff7c75d405bf051abc7e95de2452e5083a6ef68d51375735735340039ea4fc54ce1f0a4eb6e8
7
+ data.tar.gz: 0b131aebc945768f2a7bfd0a4d16cddf80e4198a54d59dffa48a4da6b76573bfc5e439a332e5ee3c4189fc2f29bc2f5cde3e3045dc44330482244c0406a90f46
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-svelte-handler (0.6.0)
4
+ actionview-svelte-handler (0.7.0)
5
5
  rails (~> 7.0)
6
6
  zeitwerk (~> 2)
7
7
 
@@ -42,7 +42,7 @@ module Svelte
42
42
  }))
43
43
 
44
44
  assembler.rewind
45
-
45
+
46
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
47
 
48
48
  if result[:error]
@@ -15,6 +15,7 @@ import commonjs from "@rollup/plugin-commonjs";
15
15
  import { nodeResolve } from "@rollup/plugin-node-resolve";
16
16
  import virtual from "@rollup/plugin-virtual";
17
17
  import swc from "@rollup/plugin-swc";
18
+ import path from "node:path";
18
19
  class Builder {
19
20
  path;
20
21
  props;
@@ -24,8 +25,10 @@ class Builder {
24
25
  workingDir;
25
26
  preprocess;
26
27
  pathAliases;
27
- constructor(path, props, locals, client, server, ssr, workingDir, preprocess, pathAliases) {
28
- this.path = path;
28
+ root;
29
+ constructor(path2, root, props, locals, client, server, ssr, workingDir, preprocess, pathAliases) {
30
+ this.path = path2;
31
+ this.root = root;
29
32
  this.props = readable(Object.assign(props, locals, props));
30
33
  this.locals = locals;
31
34
  this.compiled = {
@@ -42,7 +45,7 @@ class Builder {
42
45
  input: "entry",
43
46
  output: {
44
47
  format: "esm",
45
- sourcemap: false
48
+ sourcemap: true
46
49
  },
47
50
  watch: {
48
51
  skipWrite: true
@@ -63,7 +66,7 @@ class Builder {
63
66
  preprocess: sveltePreprocess(this.preprocess),
64
67
  onwarn: (warning, handler) => {
65
68
  if (warning.code === "missing-declaration" && warning.message.includes("'props'")) return;
66
- handler(warning);
69
+ throw new Error(warning.message);
67
70
  }
68
71
  }),
69
72
  // @ts-expect-error see https://github.com/rollup/plugins/issues/1662
@@ -83,13 +86,26 @@ class Builder {
83
86
  swc({
84
87
  swc: {
85
88
  jsc: {
86
- target: "es6"
87
- }
89
+ target: "es6",
90
+ minify: {
91
+ format: {
92
+ comments: "all"
93
+ }
94
+ }
95
+ },
96
+ minify: true,
97
+ sourceMaps: true,
98
+ inlineSourcesContent: true
88
99
  }
89
100
  })
90
101
  ]
91
- })).generate({ format: "esm", sourcemap: "inline" })).output;
92
- return bundle[0].code;
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);
105
+ });
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();
93
109
  }
94
110
  async client() {
95
111
  return this.compiled?.client || this.standardizeClient(await this.bundle("dom"));
@@ -98,17 +114,17 @@ class Builder {
98
114
  const ast = recast.parse(code);
99
115
  let name;
100
116
  recast.visit(ast, {
101
- visitExportNamedDeclaration: (path) => {
102
- const stagingName = path.node?.specifiers?.[0].local?.name;
117
+ visitExportNamedDeclaration: (path2) => {
118
+ const stagingName = path2.node?.specifiers?.[0].local?.name;
103
119
  name = typeof stagingName !== "string" ? "" : stagingName;
104
- path.prune();
120
+ path2.prune();
105
121
  return false;
106
122
  }
107
123
  });
108
124
  recast.visit(ast, {
109
- visitIdentifier: (path) => {
110
- if (path.node.name === name) {
111
- path.node.name = "App";
125
+ visitIdentifier: (path2) => {
126
+ if (path2.node.name === name) {
127
+ path2.node.name = "App";
112
128
  }
113
129
  return false;
114
130
  }
@@ -1,7 +1,8 @@
1
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 || "" %>',
@@ -7,14 +7,12 @@
7
7
  <%= result.dig(:server, :css) %>
8
8
  </style>
9
9
  <template data-island>
10
- <script type="module">
11
- <%= result.dig(:client) %>
12
-
13
- new App({
14
- target: document.getElementById("hydratee-<%= digest %>"),
15
- props: JSON.parse('<%= locals.to_json %>'),
16
- hydrate: true
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>
@@ -1,3 +1,3 @@
1
1
  module Svelte
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/ts/builder.ts CHANGED
@@ -10,6 +10,7 @@ import commonjs from '@rollup/plugin-commonjs';
10
10
  import { nodeResolve } from '@rollup/plugin-node-resolve';
11
11
  import virtual from '@rollup/plugin-virtual';
12
12
  import swc from '@rollup/plugin-swc';
13
+ import path from "node:path"
13
14
 
14
15
  export interface BuildSuccess {
15
16
  client: string
@@ -46,9 +47,11 @@ class Builder {
46
47
  workingDir: string
47
48
  preprocess: object
48
49
  pathAliases?: object
50
+ root: string
49
51
 
50
52
  constructor (
51
53
  path: string,
54
+ root: string,
52
55
  props: object,
53
56
  locals: object,
54
57
  client: string | null,
@@ -59,6 +62,7 @@ class Builder {
59
62
  pathAliases: object
60
63
  ) {
61
64
  this.path = path
65
+ this.root = root
62
66
  this.props = readable(Object.assign(props, locals, props))
63
67
  this.locals = locals
64
68
  this.compiled = {
@@ -76,7 +80,7 @@ class Builder {
76
80
  input: 'entry',
77
81
  output: {
78
82
  format: "esm",
79
- sourcemap: false
83
+ sourcemap: true
80
84
  },
81
85
  watch: {
82
86
  skipWrite: true
@@ -101,7 +105,7 @@ class Builder {
101
105
  warning.message.includes("'props'")
102
106
  ) return
103
107
 
104
- handler(warning)
108
+ throw new Error(warning.message);
105
109
  }
106
110
  }),
107
111
  // @ts-expect-error see https://github.com/rollup/plugins/issues/1662
@@ -119,14 +123,26 @@ class Builder {
119
123
  swc({
120
124
  swc: {
121
125
  jsc: {
122
- target: "es6"
123
- }
126
+ target: "es6",
127
+ minify: {
128
+ format: {
129
+ comments: 'all'
130
+ },
131
+ }
132
+ },
133
+ minify: true,
134
+ sourceMaps: true,
135
+ inlineSourcesContent: true
124
136
  }
125
137
  })
126
138
  ]
127
- })).generate({ format: "esm", sourcemap: "inline" })).output
128
-
129
- return bundle[0].code
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)
143
+ })
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()
130
146
  }
131
147
 
132
148
  async client (): Promise<string> {
@@ -30,7 +30,8 @@ declare class Builder {
30
30
  workingDir: string;
31
31
  preprocess: object;
32
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);
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);
34
35
  bundle(generate: 'ssr' | 'dom'): Promise<string>;
35
36
  client(): Promise<string>;
36
37
  standardizeClient(code: string): string;
data/package-lock.json CHANGED
@@ -14,6 +14,7 @@
14
14
  "@rollup/plugin-swc": "^0.4.0",
15
15
  "@rollup/plugin-virtual": "^3.0.2",
16
16
  "@swc/core": "^1.7.26",
17
+ "convert-source-map": "^2.0.0",
17
18
  "esbuild-svelte": "^0.8.1",
18
19
  "flat": "^6.0.1",
19
20
  "inflected": "^2.1.0",
@@ -22,10 +23,12 @@
22
23
  "recast": "^0.23.9",
23
24
  "rollup": "^4.22.4",
24
25
  "rollup-plugin-svelte": "^7.2.2",
26
+ "rollup-sourcemap-path-transform": "^1.0.5",
25
27
  "svelte": "^4.2.19",
26
28
  "svelte-preprocess": "^6.0.2"
27
29
  },
28
30
  "devDependencies": {
31
+ "@types/convert-source-map": "^2.0.3",
29
32
  "@types/lodash.merge": "^4.6.9",
30
33
  "surge": "^0.23.1",
31
34
  "ts-standard": "^12.0.2",
@@ -3161,6 +3164,12 @@
3161
3164
  "@swc/counter": "^0.1.3"
3162
3165
  }
3163
3166
  },
3167
+ "node_modules/@types/convert-source-map": {
3168
+ "version": "2.0.3",
3169
+ "resolved": "https://registry.npmjs.org/@types/convert-source-map/-/convert-source-map-2.0.3.tgz",
3170
+ "integrity": "sha512-ag0BfJLZf6CQz8VIuRIEYQ5Ggwk/82uvTQf27RcpyDNbY0Vw49LIPqAxk5tqYfrCs9xDaIMvl4aj7ZopnYL8bA==",
3171
+ "dev": true
3172
+ },
3164
3173
  "node_modules/@types/estree": {
3165
3174
  "version": "1.0.5",
3166
3175
  "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
@@ -8107,6 +8116,17 @@
8107
8116
  "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
8108
8117
  "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w=="
8109
8118
  },
8119
+ "node_modules/rollup-sourcemap-path-transform": {
8120
+ "version": "1.0.5",
8121
+ "resolved": "https://registry.npmjs.org/rollup-sourcemap-path-transform/-/rollup-sourcemap-path-transform-1.0.5.tgz",
8122
+ "integrity": "sha512-i7mcb8heyQcG+76oZrmdrkrtNVIpuefqhHYxdsqWO4wZO/8/BtUoBr2YKy+QyzdTYvR+EKTmoHN4Yg29LYC4Dw==",
8123
+ "engines": {
8124
+ "node": ">= 14.18"
8125
+ },
8126
+ "peerDependencies": {
8127
+ "rollup": "^2 || ^3 || ^4"
8128
+ }
8129
+ },
8110
8130
  "node_modules/run-async": {
8111
8131
  "version": "2.4.1",
8112
8132
  "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz",
data/package.json CHANGED
@@ -23,10 +23,6 @@
23
23
  "@rollup/plugin-swc": "^0.4.0",
24
24
  "@rollup/plugin-virtual": "^3.0.2",
25
25
  "@swc/core": "^1.7.26",
26
- "esbuild-svelte": "^0.8.1",
27
- "flat": "^6.0.1",
28
- "inflected": "^2.1.0",
29
- "lodash.merge": "^4.6.2",
30
26
  "module-from-string": "^3.3.1",
31
27
  "recast": "^0.23.9",
32
28
  "rollup": "^4.22.4",
@@ -48,7 +44,7 @@
48
44
  "docs:deploy": "vitepress build docs && surge docs/.vitepress/dist"
49
45
  },
50
46
  "devDependencies": {
51
- "@types/lodash.merge": "^4.6.9",
47
+ "@types/convert-source-map": "^2.0.3",
52
48
  "surge": "^0.23.1",
53
49
  "ts-standard": "^12.0.2",
54
50
  "typescript": "^5.5.4",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-svelte-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - reesericci
8
8
  autorequire: svelte
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-23 00:00:00.000000000 Z
11
+ date: 2024-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails