sepal 0.1.0-alpha.1 → 0.1.0-alpha.2
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/cli.js +41 -5
- package/package.json +2 -2
- package/src/fetch.js +117 -39
- package/src/index.js +6 -3
- package/types/fetch.d.ts +69 -38
- package/types/vite/sveltekit.d.ts +8 -0
- package/vite/sveltekit.js +16 -2
package/cli.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { spawnSync } from 'node:child_process';
|
|
6
6
|
import { readFileSync } from 'node:fs';
|
|
7
|
+
import { basename, join, resolve } from 'node:path';
|
|
7
8
|
import { find_host, platform_package } from '@ethercorps/calyx';
|
|
8
9
|
|
|
9
10
|
const own = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
|
|
@@ -26,8 +27,8 @@ function fail(message) {
|
|
|
26
27
|
process.exit(1);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
/**
|
|
30
|
-
function
|
|
30
|
+
/** This machine's calyx, once its version is known to fit. @returns {string} */
|
|
31
|
+
function calyx() {
|
|
31
32
|
/** @type {ReturnType<typeof find_host>} */
|
|
32
33
|
let found;
|
|
33
34
|
try {
|
|
@@ -45,18 +46,53 @@ function host(args) {
|
|
|
45
46
|
'again). To run a different calyx on purpose, point SEPAL_HOST at it.'
|
|
46
47
|
);
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
return found.path;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Run a binary with these arguments and exit with its status. @param {string} bin @param {string[]} args @returns {never} */
|
|
53
|
+
function start(bin, args) {
|
|
54
|
+
const { status, error } = spawnSync(bin, args, { stdio: 'inherit' });
|
|
55
|
+
if (error) fail(`sepal: cannot start ${bin}: ${error.message}`);
|
|
50
56
|
process.exit(status ?? 1);
|
|
51
57
|
}
|
|
52
58
|
|
|
59
|
+
/** Run the host with these arguments and exit with its status. @param {string[]} args @returns {never} */
|
|
60
|
+
function host(args) {
|
|
61
|
+
start(calyx(), args);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* macOS takes the name in the Dock, the app switcher and Activity Monitor
|
|
66
|
+
* from the bundle a process runs from; a bare calyx is called "calyx". So on
|
|
67
|
+
* macOS an app with a name runs out of a throwaway bundle in
|
|
68
|
+
* node_modules/.sepal, as it does in dev, and still loads from `dir`.
|
|
69
|
+
* @param {string} bin @param {string} dir
|
|
70
|
+
*/
|
|
71
|
+
function bundled(bin, dir) {
|
|
72
|
+
if (process.platform !== 'darwin') return bin;
|
|
73
|
+
let name;
|
|
74
|
+
try {
|
|
75
|
+
name = JSON.parse(readFileSync(join(dir, 'app.json'), 'utf8')).name;
|
|
76
|
+
} catch {
|
|
77
|
+
return bin;
|
|
78
|
+
}
|
|
79
|
+
if (!name) return bin;
|
|
80
|
+
const made = spawnSync(bin, ['--bundle', dir, resolve('node_modules/.sepal')], { encoding: 'utf8' });
|
|
81
|
+
if (made.status !== 0) {
|
|
82
|
+
console.warn(`sepal: running unbundled: ${made.stderr.trim()}`);
|
|
83
|
+
return bin;
|
|
84
|
+
}
|
|
85
|
+
const bundle = made.stdout.trim();
|
|
86
|
+
return join(bundle, 'Contents/MacOS', basename(bundle, '.app'));
|
|
87
|
+
}
|
|
88
|
+
|
|
53
89
|
const [command, ...args] = process.argv.slice(2);
|
|
54
90
|
// `bundle --sign x` with no directory still means `dist`.
|
|
55
91
|
const dist = args[0] !== undefined && !args[0].startsWith('--') ? args : ['dist', ...args];
|
|
56
92
|
|
|
57
93
|
switch (command) {
|
|
58
94
|
case 'run':
|
|
59
|
-
|
|
95
|
+
start(bundled(calyx(), dist[0]), dist);
|
|
60
96
|
case 'bundle':
|
|
61
97
|
host(['--bundle', ...dist]);
|
|
62
98
|
case 'signer':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sepal",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.2",
|
|
4
4
|
"description": "Native Svelte apps, drawn by Blitz: a Svelte custom renderer for the Blitz HTML/CSS engine, its Vite preset and the sepal command",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"cli.js"
|
|
103
103
|
],
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"@ethercorps/calyx": "0.1.0-alpha.
|
|
105
|
+
"@ethercorps/calyx": "0.1.0-alpha.2"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"svelte": "^5.59.0",
|
package/src/fetch.js
CHANGED
|
@@ -1,57 +1,143 @@
|
|
|
1
|
-
// `fetch`,
|
|
1
|
+
// `fetch`, and the Fetch API classes around it (`Request`, `Headers`,
|
|
2
|
+
// `Response`), installed as globals when the engine has none.
|
|
2
3
|
//
|
|
3
4
|
// The host makes the request, and only to URLs the app's `permissions.http`
|
|
4
5
|
// allows. This is the everyday part of the Fetch API: method, headers, a
|
|
5
6
|
// string or byte body, and `text()`, `json()`, `arrayBuffer()`, `bytes()` on
|
|
6
|
-
// the response. There is no streaming, no `AbortSignal
|
|
7
|
-
//
|
|
7
|
+
// the response. There is no streaming, no `AbortSignal` and no `FormData`.
|
|
8
|
+
// The classes are there because libraries test for them and build them:
|
|
9
|
+
// SvelteKit's client asks `input instanceof Request` on every fetch.
|
|
8
10
|
|
|
9
11
|
import { host_call } from './host-call.js';
|
|
10
12
|
import { decode, encode, to_bytes } from './base64.js';
|
|
11
13
|
|
|
12
|
-
/**
|
|
13
|
-
class
|
|
14
|
-
/** @
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
/** Headers: names are case-insensitive and kept in lower case, as in the Fetch API. */
|
|
15
|
+
export class Headers {
|
|
16
|
+
/** @type {Map<string, string>} */
|
|
17
|
+
#map = new Map();
|
|
18
|
+
|
|
19
|
+
/** @param {unknown} [init] a plain object, a list of pairs, or another `Headers` */
|
|
20
|
+
constructor(init) {
|
|
21
|
+
for (const [name, value] of header_pairs(init)) this.append(name, value);
|
|
22
|
+
}
|
|
23
|
+
/** @param {string} name @param {string} value */
|
|
24
|
+
append(name, value) {
|
|
25
|
+
const key = name.toLowerCase();
|
|
26
|
+
const earlier = this.#map.get(key);
|
|
27
|
+
this.#map.set(key, earlier === undefined ? String(value) : `${earlier}, ${value}`);
|
|
28
|
+
}
|
|
29
|
+
/** @param {string} name @param {string} value */
|
|
30
|
+
set(name, value) {
|
|
31
|
+
this.#map.set(name.toLowerCase(), String(value));
|
|
23
32
|
}
|
|
24
33
|
/** @param {string} name */
|
|
25
34
|
get(name) {
|
|
26
|
-
return this.
|
|
35
|
+
return this.#map.get(name.toLowerCase()) ?? null;
|
|
27
36
|
}
|
|
28
37
|
/** @param {string} name */
|
|
29
38
|
has(name) {
|
|
30
|
-
return this.
|
|
39
|
+
return this.#map.has(name.toLowerCase());
|
|
40
|
+
}
|
|
41
|
+
/** @param {string} name */
|
|
42
|
+
delete(name) {
|
|
43
|
+
this.#map.delete(name.toLowerCase());
|
|
31
44
|
}
|
|
32
|
-
/** @param {(value: string, name: string) => void} callback */
|
|
45
|
+
/** @param {(value: string, name: string, headers: Headers) => void} callback */
|
|
33
46
|
forEach(callback) {
|
|
34
|
-
this.
|
|
47
|
+
this.#map.forEach((value, name) => callback(value, name, this));
|
|
35
48
|
}
|
|
36
49
|
entries() {
|
|
37
|
-
return this.
|
|
50
|
+
return this.#map.entries();
|
|
51
|
+
}
|
|
52
|
+
keys() {
|
|
53
|
+
return this.#map.keys();
|
|
54
|
+
}
|
|
55
|
+
values() {
|
|
56
|
+
return this.#map.values();
|
|
38
57
|
}
|
|
39
58
|
[Symbol.iterator]() {
|
|
40
|
-
return this.
|
|
59
|
+
return this.#map.entries();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const METHODS = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'PATCH'];
|
|
64
|
+
|
|
65
|
+
/** A request to make: what `fetch` takes, as a string, a URL or one of these. */
|
|
66
|
+
export class Request {
|
|
67
|
+
/**
|
|
68
|
+
* @param {string | Request | { url?: string, href?: string }} input
|
|
69
|
+
* @param {{ method?: string, headers?: unknown, body?: string | ArrayBuffer | ArrayBufferView | null }} [init]
|
|
70
|
+
*/
|
|
71
|
+
constructor(input, init = {}) {
|
|
72
|
+
/** @type {Request | null} */
|
|
73
|
+
const from = input instanceof Request ? input : null;
|
|
74
|
+
const target = /** @type {any} */ (input);
|
|
75
|
+
/** @type {string} */
|
|
76
|
+
this.url = from ? from.url : typeof input === 'string' ? input : String(target?.url ?? target?.href ?? input);
|
|
77
|
+
/** @type {string} */
|
|
78
|
+
const method = init.method ?? from?.method ?? 'GET';
|
|
79
|
+
// As the Fetch API does: the standard methods in upper case, any other as written.
|
|
80
|
+
/** @type {string} */
|
|
81
|
+
this.method = METHODS.includes(method.toUpperCase()) ? method.toUpperCase() : method;
|
|
82
|
+
/** @type {Headers} */
|
|
83
|
+
this.headers = new Headers(init.headers ?? from?.headers);
|
|
84
|
+
/** @type {string | ArrayBuffer | ArrayBufferView | null} */
|
|
85
|
+
this.body = init.body ?? from?.body ?? null;
|
|
41
86
|
}
|
|
42
87
|
}
|
|
43
88
|
|
|
44
|
-
|
|
89
|
+
/** A response with its body in hand: what `new Response(body, init)` makes. `fetch` answers with a subclass. */
|
|
90
|
+
export class Response {
|
|
91
|
+
/**
|
|
92
|
+
* @param {string | ArrayBuffer | ArrayBufferView | null} [body]
|
|
93
|
+
* @param {{ status?: number, statusText?: string, headers?: unknown }} [init]
|
|
94
|
+
*/
|
|
95
|
+
constructor(body = null, init = {}) {
|
|
96
|
+
this.status = init.status ?? 200;
|
|
97
|
+
this.statusText = init.statusText ?? '';
|
|
98
|
+
this.ok = this.status >= 200 && this.status < 300;
|
|
99
|
+
this.headers = new Headers(init.headers);
|
|
100
|
+
this.url = '';
|
|
101
|
+
this.redirected = false;
|
|
102
|
+
this.bodyUsed = false;
|
|
103
|
+
/** @type {string | Uint8Array | null} */
|
|
104
|
+
this.held = body == null || typeof body === 'string' ? body : to_bytes(body);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** @returns {string | Uint8Array} */
|
|
108
|
+
take() {
|
|
109
|
+
if (this.bodyUsed) throw new TypeError('the response body was already read');
|
|
110
|
+
this.bodyUsed = true;
|
|
111
|
+
return this.held ?? '';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** @returns {Promise<string>} */
|
|
115
|
+
async text() {
|
|
116
|
+
const body = this.take();
|
|
117
|
+
if (typeof body !== 'string') throw new TypeError('text() of a byte body is not supported; use bytes()');
|
|
118
|
+
return body;
|
|
119
|
+
}
|
|
120
|
+
async json() {
|
|
121
|
+
return JSON.parse(await this.text());
|
|
122
|
+
}
|
|
123
|
+
/** @returns {Promise<Uint8Array>} */
|
|
124
|
+
async bytes() {
|
|
125
|
+
const body = this.take();
|
|
126
|
+
if (typeof body === 'string') throw new TypeError('bytes() of a string body is not supported; use text()');
|
|
127
|
+
return body;
|
|
128
|
+
}
|
|
129
|
+
async arrayBuffer() {
|
|
130
|
+
return /** @type {ArrayBuffer} */ ((await this.bytes()).buffer);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** What `fetch` answers with: the body stays with the host until it is asked for. */
|
|
135
|
+
class FetchResponse extends Response {
|
|
45
136
|
/** @param {{ id: number, status: number, status_text: string, url: string, redirected: boolean, headers: [string, string][] }} head */
|
|
46
137
|
constructor(head) {
|
|
47
|
-
|
|
48
|
-
this.statusText = head.status_text;
|
|
49
|
-
this.ok = head.status >= 200 && head.status < 300;
|
|
138
|
+
super(null, { status: head.status, statusText: head.status_text, headers: head.headers });
|
|
50
139
|
this.url = head.url;
|
|
51
140
|
this.redirected = head.redirected;
|
|
52
|
-
this.headers = new ResponseHeaders(head.headers);
|
|
53
|
-
this.bodyUsed = false;
|
|
54
|
-
/** The body stays with the host until it is asked for. */
|
|
55
141
|
this.body_id = head.id;
|
|
56
142
|
}
|
|
57
143
|
|
|
@@ -65,15 +151,9 @@ class FetchResponse {
|
|
|
65
151
|
text() {
|
|
66
152
|
return this.read('text');
|
|
67
153
|
}
|
|
68
|
-
async json() {
|
|
69
|
-
return JSON.parse(await this.read('text'));
|
|
70
|
-
}
|
|
71
154
|
async bytes() {
|
|
72
155
|
return decode(await this.read('base64'));
|
|
73
156
|
}
|
|
74
|
-
async arrayBuffer() {
|
|
75
|
-
return (await this.bytes()).buffer;
|
|
76
|
-
}
|
|
77
157
|
}
|
|
78
158
|
|
|
79
159
|
/**
|
|
@@ -95,17 +175,15 @@ function header_pairs(headers) {
|
|
|
95
175
|
}
|
|
96
176
|
|
|
97
177
|
/**
|
|
98
|
-
* @param {string | { url
|
|
178
|
+
* @param {string | Request | { url?: string, href?: string }} input
|
|
99
179
|
* @param {{ method?: string, headers?: unknown, body?: string | ArrayBuffer | ArrayBufferView | null }} [init]
|
|
100
|
-
* @returns {Promise<
|
|
180
|
+
* @returns {Promise<Response>}
|
|
101
181
|
*/
|
|
102
182
|
export async function fetch(input, init = {}) {
|
|
103
|
-
const
|
|
104
|
-
const url = typeof input === 'string' ? input : String(target.url ?? target.href ?? input);
|
|
183
|
+
const { url, method, headers, body } = new Request(input, init);
|
|
105
184
|
/** @type {Record<string, unknown>} */
|
|
106
|
-
const request = { url, method
|
|
185
|
+
const request = { url, method, headers: [...headers] };
|
|
107
186
|
|
|
108
|
-
const body = init.body;
|
|
109
187
|
if (typeof body === 'string') request.body = body;
|
|
110
188
|
else if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) request.body_base64 = encode(to_bytes(body));
|
|
111
189
|
else if (body != null) throw new TypeError('fetch: the body must be a string, an ArrayBuffer or a typed array');
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { run_timers, next_timer, track_rejection, report_rejections, rejection_c
|
|
|
3
3
|
import { mount as svelte_mount, unmount } from 'svelte';
|
|
4
4
|
import renderer, { root, dispatch, take_batch, stats, keep_alive, host_hooks } from './renderer.js';
|
|
5
5
|
import { settle_call } from './host-call.js';
|
|
6
|
-
import { fetch } from './fetch.js';
|
|
6
|
+
import { fetch, Headers, Request, Response } from './fetch.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Mount a component into the window.
|
|
@@ -22,8 +22,11 @@ export function mount(component, options = {}) {
|
|
|
22
22
|
|
|
23
23
|
export { unmount, renderer, root };
|
|
24
24
|
|
|
25
|
-
// The engine has no `fetch`. This one asks the host, which checks the app's
|
|
26
|
-
|
|
25
|
+
// The engine has no `fetch`. This one asks the host, which checks the app's
|
|
26
|
+
// permissions. The classes around it come along: libraries test for them.
|
|
27
|
+
for (const [name, value] of Object.entries({ fetch, Headers, Request, Response })) {
|
|
28
|
+
if (typeof (/** @type {any} */ (globalThis)[name]) !== 'function') /** @type {any} */ (globalThis)[name] = value;
|
|
29
|
+
}
|
|
27
30
|
|
|
28
31
|
// The host's entry points into JS. It calls these and nothing else.
|
|
29
32
|
/** @type {any} */ (globalThis).__sb = {
|
package/types/fetch.d.ts
CHANGED
|
@@ -1,56 +1,87 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @param {string | { url
|
|
2
|
+
* @param {string | Request | { url?: string, href?: string }} input
|
|
3
3
|
* @param {{ method?: string, headers?: unknown, body?: string | ArrayBuffer | ArrayBufferView | null }} [init]
|
|
4
|
-
* @returns {Promise<
|
|
4
|
+
* @returns {Promise<Response>}
|
|
5
5
|
*/
|
|
6
|
-
export function fetch(input: string | {
|
|
7
|
-
url
|
|
8
|
-
|
|
9
|
-
href: string;
|
|
6
|
+
export function fetch(input: string | Request | {
|
|
7
|
+
url?: string;
|
|
8
|
+
href?: string;
|
|
10
9
|
}, init?: {
|
|
11
10
|
method?: string;
|
|
12
11
|
headers?: unknown;
|
|
13
12
|
body?: string | ArrayBuffer | ArrayBufferView | null;
|
|
14
|
-
}): Promise<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
}): Promise<Response>;
|
|
14
|
+
/** Headers: names are case-insensitive and kept in lower case, as in the Fetch API. */
|
|
15
|
+
export class Headers {
|
|
16
|
+
/** @param {unknown} [init] a plain object, a list of pairs, or another `Headers` */
|
|
17
|
+
constructor(init?: unknown);
|
|
18
|
+
/** @param {string} name @param {string} value */
|
|
19
|
+
append(name: string, value: string): void;
|
|
20
|
+
/** @param {string} name @param {string} value */
|
|
21
|
+
set(name: string, value: string): void;
|
|
22
|
+
/** @param {string} name */
|
|
23
|
+
get(name: string): string | null;
|
|
24
|
+
/** @param {string} name */
|
|
25
|
+
has(name: string): boolean;
|
|
26
|
+
/** @param {string} name */
|
|
27
|
+
delete(name: string): void;
|
|
28
|
+
/** @param {(value: string, name: string, headers: Headers) => void} callback */
|
|
29
|
+
forEach(callback: (value: string, name: string, headers: Headers) => void): void;
|
|
30
|
+
entries(): MapIterator<[string, string]>;
|
|
31
|
+
keys(): MapIterator<string>;
|
|
32
|
+
values(): MapIterator<string>;
|
|
33
|
+
[Symbol.iterator](): MapIterator<[string, string]>;
|
|
34
|
+
#private;
|
|
35
|
+
}
|
|
36
|
+
/** A request to make: what `fetch` takes, as a string, a URL or one of these. */
|
|
37
|
+
export class Request {
|
|
38
|
+
/**
|
|
39
|
+
* @param {string | Request | { url?: string, href?: string }} input
|
|
40
|
+
* @param {{ method?: string, headers?: unknown, body?: string | ArrayBuffer | ArrayBufferView | null }} [init]
|
|
41
|
+
*/
|
|
42
|
+
constructor(input: string | Request | {
|
|
43
|
+
url?: string;
|
|
44
|
+
href?: string;
|
|
45
|
+
}, init?: {
|
|
46
|
+
method?: string;
|
|
47
|
+
headers?: unknown;
|
|
48
|
+
body?: string | ArrayBuffer | ArrayBufferView | null;
|
|
49
|
+
});
|
|
50
|
+
/** @type {string} */
|
|
51
|
+
url: string;
|
|
52
|
+
/** @type {string} */
|
|
53
|
+
method: string;
|
|
54
|
+
/** @type {Headers} */
|
|
55
|
+
headers: Headers;
|
|
56
|
+
/** @type {string | ArrayBuffer | ArrayBufferView | null} */
|
|
57
|
+
body: string | ArrayBuffer | ArrayBufferView | null;
|
|
58
|
+
}
|
|
59
|
+
/** A response with its body in hand: what `new Response(body, init)` makes. `fetch` answers with a subclass. */
|
|
60
|
+
export class Response {
|
|
61
|
+
/**
|
|
62
|
+
* @param {string | ArrayBuffer | ArrayBufferView | null} [body]
|
|
63
|
+
* @param {{ status?: number, statusText?: string, headers?: unknown }} [init]
|
|
64
|
+
*/
|
|
65
|
+
constructor(body?: string | ArrayBuffer | ArrayBufferView | null, init?: {
|
|
66
|
+
status?: number;
|
|
67
|
+
statusText?: string;
|
|
68
|
+
headers?: unknown;
|
|
24
69
|
});
|
|
25
70
|
status: number;
|
|
26
71
|
statusText: string;
|
|
27
72
|
ok: boolean;
|
|
73
|
+
headers: Headers;
|
|
28
74
|
url: string;
|
|
29
75
|
redirected: boolean;
|
|
30
|
-
headers: ResponseHeaders;
|
|
31
76
|
bodyUsed: boolean;
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
/** @
|
|
35
|
-
|
|
77
|
+
/** @type {string | Uint8Array | null} */
|
|
78
|
+
held: string | Uint8Array | null;
|
|
79
|
+
/** @returns {string | Uint8Array} */
|
|
80
|
+
take(): string | Uint8Array;
|
|
81
|
+
/** @returns {Promise<string>} */
|
|
36
82
|
text(): Promise<string>;
|
|
37
83
|
json(): Promise<any>;
|
|
38
|
-
|
|
84
|
+
/** @returns {Promise<Uint8Array>} */
|
|
85
|
+
bytes(): Promise<Uint8Array>;
|
|
39
86
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
40
87
|
}
|
|
41
|
-
/** Response headers: names are case-insensitive, as in the Fetch API. */
|
|
42
|
-
declare class ResponseHeaders {
|
|
43
|
-
/** @param {[string, string][]} pairs */
|
|
44
|
-
constructor(pairs: [string, string][]);
|
|
45
|
-
/** @type {Map<string, string>} */
|
|
46
|
-
values: Map<string, string>;
|
|
47
|
-
/** @param {string} name */
|
|
48
|
-
get(name: string): string | null;
|
|
49
|
-
/** @param {string} name */
|
|
50
|
-
has(name: string): boolean;
|
|
51
|
-
/** @param {(value: string, name: string) => void} callback */
|
|
52
|
-
forEach(callback: (value: string, name: string) => void): void;
|
|
53
|
-
entries(): MapIterator<[string, string]>;
|
|
54
|
-
[Symbol.iterator](): MapIterator<[string, string]>;
|
|
55
|
-
}
|
|
56
|
-
export {};
|
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
* @param {string} to
|
|
6
6
|
*/
|
|
7
7
|
export function convert(from: string, to: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* A stylesheet moved from `dir` (relative to the build, `/`-separated) to
|
|
10
|
+
* app.css at its root. Its relative `url()`s, such as a font next to it in
|
|
11
|
+
* `_app/immutable/assets`, have to say where they now are from there.
|
|
12
|
+
* @param {string} css
|
|
13
|
+
* @param {string} dir
|
|
14
|
+
*/
|
|
15
|
+
export function rebase_css(css: string, dir: string): string;
|
|
8
16
|
/**
|
|
9
17
|
* @typedef {import('./vite.js').Config & {
|
|
10
18
|
* kit?: import('@sveltejs/kit/vite').Config,
|
package/vite/sveltekit.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// Runs in Node.
|
|
20
20
|
|
|
21
21
|
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
22
|
-
import { dirname, join, relative, resolve } from 'node:path';
|
|
22
|
+
import { dirname, join, posix, relative, resolve } from 'node:path';
|
|
23
23
|
import { dev_window, load_config, manifest } from './app.js';
|
|
24
24
|
import { element_bindings } from './bindings.js';
|
|
25
25
|
import { head } from './head.js';
|
|
@@ -110,7 +110,7 @@ ${start}(element);
|
|
|
110
110
|
);
|
|
111
111
|
|
|
112
112
|
const styles = [...html.matchAll(/<link href="\/([^"]+)" rel="stylesheet">/g)].map((link) => link[1]).filter((file) => files.includes(file));
|
|
113
|
-
writeFileSync(join(to, 'app.css'), styles.map((file) => readFileSync(join(from, file), 'utf8')).join('\n'));
|
|
113
|
+
writeFileSync(join(to, 'app.css'), styles.map((file) => rebase_css(readFileSync(join(from, file), 'utf8'), posix.dirname(file))).join('\n'));
|
|
114
114
|
|
|
115
115
|
// Everything else is for the app to load by its path: static files, and
|
|
116
116
|
// what SvelteKit put in `_app/immutable/assets`.
|
|
@@ -121,6 +121,20 @@ ${start}(element);
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* A stylesheet moved from `dir` (relative to the build, `/`-separated) to
|
|
126
|
+
* app.css at its root. Its relative `url()`s, such as a font next to it in
|
|
127
|
+
* `_app/immutable/assets`, have to say where they now are from there.
|
|
128
|
+
* @param {string} css
|
|
129
|
+
* @param {string} dir
|
|
130
|
+
*/
|
|
131
|
+
export function rebase_css(css, dir) {
|
|
132
|
+
return css.replace(
|
|
133
|
+
/url\(\s*(['"]?)(?![a-z][a-z0-9+.-]*:|\/|#)([^'")]+)\1\s*\)/gi,
|
|
134
|
+
(_, quote, path) => `url(${quote}${posix.join(dir, path)}${quote})`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
124
138
|
/**
|
|
125
139
|
* @typedef {import('./vite.js').Config & {
|
|
126
140
|
* kit?: import('@sveltejs/kit/vite').Config,
|