@sveltejs/kit 1.0.0-next.494 → 1.0.0-next.496
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 +3 -2
- package/postinstall.js +37 -0
- package/src/cli.js +0 -4
- package/src/runtime/app/forms.js +7 -1
- package/src/runtime/client/client.js +66 -75
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.496",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"!src/core/**/test",
|
|
55
55
|
"types",
|
|
56
56
|
"svelte-kit.js",
|
|
57
|
+
"postinstall.js",
|
|
57
58
|
"scripts/special-types"
|
|
58
59
|
],
|
|
59
60
|
"exports": {
|
|
@@ -89,6 +90,6 @@
|
|
|
89
90
|
"test:integration": "pnpm run -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
90
91
|
"test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
|
|
91
92
|
"types": "node scripts/extract-types.js",
|
|
92
|
-
"postinstall": "node
|
|
93
|
+
"postinstall": "node postinstall.js"
|
|
93
94
|
}
|
|
94
95
|
}
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import glob from 'tiny-glob/sync.js';
|
|
4
|
+
import { load_config } from './src/core/config/index.js';
|
|
5
|
+
import * as sync from './src/core/sync/sync.js';
|
|
6
|
+
|
|
7
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
8
|
+
|
|
9
|
+
const directories = [];
|
|
10
|
+
|
|
11
|
+
const cwd = process.env.INIT_CWD ?? process.cwd();
|
|
12
|
+
|
|
13
|
+
if (pkg.workspaces) {
|
|
14
|
+
for (const directory of pkg.workspaces) {
|
|
15
|
+
directories.push(...glob(directory, { cwd }).map((dir) => path.resolve(cwd, dir)));
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
directories.push(cwd);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (const cwd of directories) {
|
|
22
|
+
process.chdir(cwd);
|
|
23
|
+
|
|
24
|
+
if (!fs.existsSync('package.json')) continue;
|
|
25
|
+
if (!fs.existsSync('svelte.config.js')) continue;
|
|
26
|
+
|
|
27
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
28
|
+
if (!pkg.dependencies?.['@sveltejs/kit'] && !pkg.devDependencies?.['@sveltejs/kit']) continue;
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const config = await load_config();
|
|
32
|
+
await sync.all(config, 'development');
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.log('Error while trying to sync SvelteKit config');
|
|
35
|
+
console.log(e);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -41,10 +41,6 @@ prog
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
if (event === 'postinstall' && process.env.INIT_CWD) {
|
|
45
|
-
process.chdir(process.env.INIT_CWD);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
44
|
if (!fs.existsSync('svelte.config.js')) {
|
|
49
45
|
console.warn(`Missing ${path.resolve('svelte.config.js')} — skipping`);
|
|
50
46
|
return;
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -28,7 +28,13 @@ export function enhance(form, submit = () => {}) {
|
|
|
28
28
|
await invalidateAll();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// For success/invalid results, only apply action if it belongs to the
|
|
32
|
+
// current page, otherwise `form` will be updated erroneously
|
|
33
|
+
if (
|
|
34
|
+
location.origin + location.pathname === action.origin + action.pathname ||
|
|
35
|
+
result.type === 'redirect' ||
|
|
36
|
+
result.type === 'error'
|
|
37
|
+
) {
|
|
32
38
|
applyAction(result);
|
|
33
39
|
}
|
|
34
40
|
};
|
|
@@ -814,40 +814,22 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
814
814
|
error = handle_error(err, { params, url, routeId: route.id });
|
|
815
815
|
}
|
|
816
816
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
return await get_navigation_result_from_branch({
|
|
834
|
-
url,
|
|
835
|
-
params,
|
|
836
|
-
branch: branch.slice(0, j + 1).concat(error_loaded),
|
|
837
|
-
status,
|
|
838
|
-
error,
|
|
839
|
-
route
|
|
840
|
-
});
|
|
841
|
-
} catch (e) {
|
|
842
|
-
continue;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
817
|
+
const error_load = await load_nearest_error_page(i, branch, errors);
|
|
818
|
+
if (error_load) {
|
|
819
|
+
return await get_navigation_result_from_branch({
|
|
820
|
+
url,
|
|
821
|
+
params,
|
|
822
|
+
branch: branch.slice(0, error_load.idx).concat(error_load.node),
|
|
823
|
+
status,
|
|
824
|
+
error,
|
|
825
|
+
route
|
|
826
|
+
});
|
|
827
|
+
} else {
|
|
828
|
+
// if we get here, it's because the root `load` function failed,
|
|
829
|
+
// and we need to fall back to the server
|
|
830
|
+
await native_navigation(url);
|
|
831
|
+
return;
|
|
845
832
|
}
|
|
846
|
-
|
|
847
|
-
// if we get here, it's because the root `load` function failed,
|
|
848
|
-
// and we need to fall back to the server
|
|
849
|
-
await native_navigation(url);
|
|
850
|
-
return;
|
|
851
833
|
}
|
|
852
834
|
} else {
|
|
853
835
|
// push an empty slot so we can rewind past gaps to the
|
|
@@ -868,6 +850,35 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
868
850
|
});
|
|
869
851
|
}
|
|
870
852
|
|
|
853
|
+
/**
|
|
854
|
+
* @param {number} i Start index to backtrack from
|
|
855
|
+
* @param {Array<import('./types').BranchNode | undefined>} branch Branch to backtrack
|
|
856
|
+
* @param {Array<import('types').CSRPageNodeLoader | undefined>} errors All error pages for this branch
|
|
857
|
+
* @returns {Promise<{idx: number; node: import('./types').BranchNode} | undefined>}
|
|
858
|
+
*/
|
|
859
|
+
async function load_nearest_error_page(i, branch, errors) {
|
|
860
|
+
while (i--) {
|
|
861
|
+
if (errors[i]) {
|
|
862
|
+
let j = i;
|
|
863
|
+
while (!branch[j]) j -= 1;
|
|
864
|
+
try {
|
|
865
|
+
return {
|
|
866
|
+
idx: j + 1,
|
|
867
|
+
node: {
|
|
868
|
+
node: await /** @type {import('types').CSRPageNodeLoader } */ (errors[i])(),
|
|
869
|
+
loader: /** @type {import('types').CSRPageNodeLoader } */ (errors[i]),
|
|
870
|
+
data: {},
|
|
871
|
+
server: null,
|
|
872
|
+
shared: null
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
} catch (e) {
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
871
882
|
/**
|
|
872
883
|
* @param {{
|
|
873
884
|
* status: number;
|
|
@@ -1160,44 +1171,26 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1160
1171
|
const { branch, route } = current;
|
|
1161
1172
|
if (!route) return;
|
|
1162
1173
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
params: current.params,
|
|
1184
|
-
branch: branch.slice(0, j + 1).concat(error_loaded),
|
|
1185
|
-
status: 500, // TODO might not be 500?
|
|
1186
|
-
error: result.error,
|
|
1187
|
-
route
|
|
1188
|
-
});
|
|
1189
|
-
|
|
1190
|
-
current = navigation_result.state;
|
|
1191
|
-
|
|
1192
|
-
const post_update = pre_update();
|
|
1193
|
-
root.$set(navigation_result.props);
|
|
1194
|
-
post_update();
|
|
1195
|
-
|
|
1196
|
-
return;
|
|
1197
|
-
} catch (e) {
|
|
1198
|
-
continue;
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1174
|
+
const error_load = await load_nearest_error_page(
|
|
1175
|
+
current.branch.length,
|
|
1176
|
+
branch,
|
|
1177
|
+
route.errors
|
|
1178
|
+
);
|
|
1179
|
+
if (error_load) {
|
|
1180
|
+
const navigation_result = await get_navigation_result_from_branch({
|
|
1181
|
+
url,
|
|
1182
|
+
params: current.params,
|
|
1183
|
+
branch: branch.slice(0, error_load.idx).concat(error_load.node),
|
|
1184
|
+
status: 500, // TODO might not be 500?
|
|
1185
|
+
error: result.error,
|
|
1186
|
+
route
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1189
|
+
current = navigation_result.state;
|
|
1190
|
+
|
|
1191
|
+
const post_update = pre_update();
|
|
1192
|
+
root.$set(navigation_result.props);
|
|
1193
|
+
post_update();
|
|
1201
1194
|
}
|
|
1202
1195
|
} else if (result.type === 'redirect') {
|
|
1203
1196
|
goto(result.location, {}, []);
|
|
@@ -1206,10 +1199,8 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1206
1199
|
const props = { form: result.data };
|
|
1207
1200
|
|
|
1208
1201
|
if (result.status !== page.status) {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
status: result.status
|
|
1212
|
-
};
|
|
1202
|
+
page = { ...page, status: result.status };
|
|
1203
|
+
props.page = page;
|
|
1213
1204
|
}
|
|
1214
1205
|
|
|
1215
1206
|
const post_update = pre_update();
|