@primate/svelte 0.5.2 → 0.6.1

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.
package/package.json CHANGED
@@ -1,20 +1,25 @@
1
1
  {
2
2
  "name": "@primate/svelte",
3
- "version": "0.5.2",
4
- "bugs": "https://github.com/primatejs/svelte/issues",
5
- "repository": "https://github.com/primatejs/svelte",
3
+ "version": "0.6.1",
6
4
  "description": "Primate Svelte module",
5
+ "bugs": "https://github.com/primatejs/packages/issues",
7
6
  "license": "MIT",
7
+ "files": [
8
+ "src/**",
9
+ "!src/**/*.spec.js"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/primatejs/packages",
14
+ "directory": "packages/svelte"
15
+ },
8
16
  "dependencies": {
9
- "runtime-compat": "^0.15.0",
17
+ "runtime-compat": "^0.15.1",
10
18
  "svelte": "^3.58.0"
11
19
  },
12
- "devDependencies": {
13
- "maximin": "^0.1.2"
14
- },
15
20
  "peerDependencies": {
16
21
  "primate": "0.15"
17
22
  },
18
23
  "type": "module",
19
- "exports": "./exports.js"
24
+ "exports": "./src/exports.js"
20
25
  }
package/src/exports.js ADDED
@@ -0,0 +1 @@
1
+ export {default} from "./module.js";
package/src/module.js CHANGED
@@ -9,13 +9,13 @@ const endings = {
9
9
  const type = "module";
10
10
 
11
11
  const handler = path => (component, props = {}, {status = 200} = {}) =>
12
- async (env, headers) => {
12
+ async (app, headers) => {
13
13
  const {html: body} = (await import(`${path.join(`${component}.js`)}`))
14
14
  .default.render(props);
15
15
 
16
16
  const name = component.slice(0, -endings.svelte.length);
17
17
  // create an entry point
18
- const entry = `import {${name} as Component} from "./dist.js";
18
+ const entry = `import {${name} as Component} from "./${app.dist}.js";
19
19
  const props = JSON.parse(${JSON.stringify(JSON.stringify(props))});
20
20
  new Component({
21
21
  target: document.body,
@@ -24,13 +24,13 @@ const handler = path => (component, props = {}, {status = 200} = {}) =>
24
24
  });
25
25
  `;
26
26
  const inline = true;
27
- const integrity = await env.publish({code: entry, type, inline});
27
+ const integrity = await app.publish({code: entry, type, inline});
28
28
  // hacky, CSP should be a map that gets flattened in the end
29
29
  headers["Content-Security-Policy"] = headers["Content-Security-Policy"]
30
30
  .replace("script-src 'self' ", `script-src 'self' '${integrity}' `);
31
31
 
32
32
  // -> spread into new Response()
33
- return [await env.render({body}), {
33
+ return [await app.render({body}), {
34
34
  status,
35
35
  headers: {...headers, "Content-Type": "text/html"},
36
36
  }];
@@ -38,12 +38,12 @@ const handler = path => (component, props = {}, {status = 200} = {}) =>
38
38
 
39
39
  const {svelte, js} = endings;
40
40
  export default ({directory, entryPoints} = {}) => ({
41
- register(env, next) {
42
- env.register("svelte", handler(directory ?? env.paths.components));
43
- return next(env);
41
+ register(app, next) {
42
+ app.register("svelte", handler(directory ?? app.paths.components));
43
+ return next(app);
44
44
  },
45
- async compile(env, next) {
46
- const path = directory ?? env.paths.components;
45
+ async compile(app, next) {
46
+ const path = directory ?? app.paths.components;
47
47
  const options = {generate: "ssr", hydratable: true};
48
48
  const components = await path.list(filename => filename.endsWith(svelte));
49
49
  await Promise.all(components.map(async component => {
@@ -53,38 +53,47 @@ export default ({directory, entryPoints} = {}) => ({
53
53
  await File.write(`${component.path}.js`, compiled);
54
54
  }));
55
55
 
56
- return next(env);
56
+ return next(app);
57
57
  },
58
- async publish(env, next) {
59
- const path = directory ?? env.paths.components;
58
+ async publish(app, next) {
59
+ const path = directory ?? app.paths.components;
60
60
  const options = {
61
61
  generate: "dom",
62
62
  hydratable: true,
63
- css: false,
64
63
  sveltePath: "./svelte",
65
64
  };
66
65
  const components = await path.list(filename => filename.endsWith(svelte));
67
- const scriptPath = ["node_modules", "svelte", "internal", "index.mjs"];
68
- // publish svelte itself
69
- const code = await Path.resolve().join(...scriptPath).file.read();
70
- await env.publish({src: "svelte/internal.js", code, type});
66
+ {
67
+ const scriptPath = ["node_modules", "svelte", "internal", "index.mjs"];
68
+ // import.meta.resolve is more reliable, use it if available
69
+ const _path = import.meta.resolve === undefined
70
+ ? await Path.resolve().join(...scriptPath)
71
+ : new Path(await import.meta.resolve("svelte/internal"));
72
+ // publish svelte itself
73
+ const code = await _path.file.read();
74
+ await app.publish({src: "svelte/internal.js", code, type});
75
+ }
71
76
  await Promise.all(components.map(async component => {
72
77
  const file = await component.file.read();
73
78
  const client = compiler.compile(file, options);
79
+ const css = client.css.code;
74
80
  const compiled = client.js.code
75
81
  .replaceAll(svelte, js)
76
82
  .replace("./svelte/internal", "./svelte/internal.js");
77
- await env.publish({src: `${component.name}.js`, code: compiled, type});
83
+ await app.publish({src: `${component.name}.js`, code: compiled, type});
84
+ if (css !== null) {
85
+ const name = `${component.name}.css`;
86
+ await app.publish({src: name, code: css, type: "style"});
87
+ app.bootstrap({type: "style", code: `import "./${name}";`});
88
+ }
78
89
  }));
79
- // create a pseudo entry to allow bundlers to bundle relevant code until
80
- // proper path-splitting has been implemented
81
90
  if (entryPoints !== undefined) {
82
- const code = entryPoints.map(entry => {
91
+ entryPoints.forEach(entry => {
83
92
  const name = entry.slice(0, -endings.svelte.length);
84
- return `export {default as ${name}} from "./${entry}.js";`
85
- }).join("");
86
- await env.publish({src: "dist.js", code, type, main: true});
93
+ const code = `export {default as ${name}} from "./${entry}.js";`;
94
+ app.bootstrap({type: "script", code});
95
+ });
87
96
  }
88
- return next(env);
97
+ return next(app);
89
98
  },
90
99
  });
package/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) Terrablue <terrablue@proton.me> and contributors.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
- THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
package/eslint.config.js DELETED
@@ -1 +0,0 @@
1
- export {default} from "maximin";
package/exports.js DELETED
@@ -1 +0,0 @@
1
- export {default} from "./src/module.js";