Skip to content

Commit

Permalink
Merge branch 'master' into app-util-generate-types
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Nov 8, 2020
2 parents 16d4e92 + 819ea58 commit aab5112
Show file tree
Hide file tree
Showing 24 changed files with 184 additions and 120 deletions.
7 changes: 7 additions & 0 deletions packages/adapter-begin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @sveltejs/adapter-begin

## 0.0.3

### Patch Changes

- Updated dependencies [3bdf33b]
- @sveltejs/app-utils@0.0.17

## 0.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-begin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-begin",
"version": "0.0.2",
"version": "0.0.3",
"main": "index.js",
"scripts": {
"lint": "eslint --ignore-pattern node_modules/ '**/*.{ts,js,svelte}'"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = async function builder({
throw err;
}
} else {
throw new Error('Missing a netlify.toml file. Consult https://github.com/sveltejs/adapter-netlify#configuration');
throw new Error('Missing a netlify.toml file. Consult https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify#configuration');
}

if (!netlify_config.build || !netlify_config.build.publish || !netlify_config.build.functions) {
Expand Down
7 changes: 7 additions & 0 deletions packages/adapter-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @sveltejs/adapter-node

## 0.0.14

### Patch Changes

- Updated dependencies [3bdf33b]
- @sveltejs/app-utils@0.0.17

## 0.0.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-node",
"version": "0.0.13",
"version": "0.0.14",
"main": "index.js",
"files": [
"server.js"
Expand Down
7 changes: 7 additions & 0 deletions packages/adapter-static/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @sveltejs/adapter-static

## 0.0.14

### Patch Changes

- Updated dependencies [3bdf33b]
- @sveltejs/app-utils@0.0.17

## 0.0.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-static/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-static",
"version": "0.0.13",
"version": "0.0.14",
"scripts": {
"lint": "eslint --ignore-pattern node_modules/ '**/*.{ts,js,svelte}'"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = async function builder({ dir, manifest, log }) {
// TODO: Merge this, rather than write it
log.minor('Rewriting vercel configuration...');
writeFileSync(
`vercel.json`,
'vercel.json',
JSON.stringify({
public: true,
build: {
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-vercel/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ exports.handler = async function(event) {
path,
httpMethod,
headers,
queryStringParameters,
body, // TODO pass this to renderer
isBase64Encoded // TODO is this useful?
queryStringParameters
// body, // TODO pass this to renderer
// isBase64Encoded // TODO is this useful?
} = event;

const query = new URLSearchParams();
Expand Down
6 changes: 6 additions & 0 deletions packages/app-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @sveltejs/app-utils

## 0.0.17

### Patch Changes

- 3bdf33b: Fix missing files in published package

## 0.0.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/app-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/app-utils",
"version": "0.0.16",
"version": "0.0.17",
"scripts": {
"clean": "node rimraf.js common files http renderer types build",
"dev": "npm run clean && rollup -cw",
Expand Down
65 changes: 17 additions & 48 deletions packages/app-utils/src/renderer/render/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ type FetchOpts = {
export default async function render_page(
request: IncomingRequest,
context: any,
options: RenderOptions
options: RenderOptions,
status: number = 200,
error: Error | null = null
): Promise<{
status: number,
body: string,
Expand Down Expand Up @@ -192,14 +194,15 @@ export default async function render_page(
});

const props: Record<string, any> = {
status: 200,
error: null,
status,
error,
stores: {
page: readable({
host: request.host,
path: request.path,
query: request.query,
params
params,
error
}, noop),
preloading: readable(null, noop),
session: writable(session)
Expand Down Expand Up @@ -266,8 +269,8 @@ export default async function render_page(
<script>
__SVELTE__ = {
baseUrl: "${baseUrl}",
status: 200,
error: null,
status: ${status},
error: ${serialize_error(error)},
preloaded: ${serialized_preloads},
session: ${serialized_session}
};
Expand All @@ -283,52 +286,18 @@ export default async function render_page(
body: html,
dependencies
};
} catch (error) {
console.error(error.stack);

const status = error.status || 500;

try {
const rendered = options.root.default.render({ status, error });

const head = `${rendered.head}
<script type="module">
import { start } from '/_app/${options.client.entry}';
} catch (thrown) {
console.error(thrown.stack);

start({
target: document.body
});
</script>`.replace(/^\t\t\t/gm, '');

const body = `${rendered.html}
<script>
__SVELTE__ = {
baseUrl: "${baseUrl}",
status: ${status},
error: ${serialize_error(error)},
preloaded: null,
session: ${serialized_session}
};
</script>`.replace(/^\t\t\t/gm, '');

const html = options.template
.replace('%svelte.head%', head)
.replace('%svelte.body%', body);

return {
status,
headers: {
'content-type': 'text/html'
},
body: html,
dependencies: {}
};
} catch (error) {
if (!error) {
const status = thrown.status || 500;
return render_page(request, context, options, status, thrown);
} else {
// oh lawd now you've done it
return {
status: 500,
headers: {},
body: error.stack, // TODO probably not in prod?
body: thrown.stack, // TODO probably not in prod?
dependencies: {}
};
}
Expand All @@ -345,7 +314,7 @@ function try_serialize(data: any, fail?: (err: Error) => void) {
}

// Ensure we return something truthy so the client will not re-render the page over the error
function serialize_error(error: Error) {
function serialize_error(error?: Error) {
if (!error) return null;
let serialized = try_serialize(error);
if (!serialized) {
Expand Down
37 changes: 24 additions & 13 deletions packages/create-svelte/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import path from 'path';
import prompts from 'prompts/lib/index';
import glob from 'tiny-glob/sync';
import gitignore_contents from '../template/.gitignore';
import add_css from './modifications/add_css';
import add_typescript from './modifications/add_typescript';
import versions from './versions';

Expand Down Expand Up @@ -84,19 +85,7 @@ async function main(): Promise<void> {

console.log(bold(green(`✔ Copied project files`)));

// modifications
const modifications = [['Use TypeScript in components?', false, add_typescript]] as const;

for (const [message, initial, fn] of modifications) {
const response = await prompts({
type: 'confirm',
name: 'value',
message,
initial
});

await fn(target, response.value);
}
await prompt_modifications(target);

console.log(`\nNext steps:`);
let i = 1;
Expand All @@ -113,4 +102,26 @@ async function main(): Promise<void> {
console.log('\nStuck? Visit us at https://svelte.dev/chat\n');
}

async function prompt_modifications(target: string) {
const ts_response = await prompts({
type: 'confirm',
name: 'value',
message: 'Use TypeScript in components?',
initial: false
});
await add_typescript(target, ts_response.value);

const css_response = await prompts({
type: 'select',
name: 'value',
message: 'What do you want to use for writing Styles in Svelte components?',
choices: [
{ title: 'CSS', value: 'css' },
{ title: 'Less', value: 'less' },
{ title: 'SCSS', value: 'scss' }
]
});
await add_css(target, css_response.value);
}

main();
42 changes: 42 additions & 0 deletions packages/create-svelte/cli/modifications/add_css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { bold, green } from 'kleur/colors';
import { add_svelte_prepocess_to_config, update_component, update_package_json } from './utils';

export default async function add_css(cwd: string, which: 'css' | 'less' | 'scss'): Promise<void> {
if (which === 'css') {
console.log(`You can add support for CSS preprocessors like SCSS/Less/PostCSS later.`);
} else if (which === 'less') {
update_package_json(cwd, {
less: '^3.0.0',
'svelte-preprocess': '^4.0.0'
});
update_component(cwd, 'src/components/Counter.svelte', [['<style>', '<style lang="less">']]);
update_component(cwd, 'src/routes/index.svelte', [['<style>', '<style lang="less">']]);
add_svelte_prepocess_to_config(cwd);
console.log(
bold(
green(
`✔ Added Less support. ` +
`To use it inside Svelte components, add lang="less" to the attributes of a style tag.`
)
)
);
} else if (which === 'scss') {
update_package_json(cwd, {
sass: '^1.0.0',
'svelte-preprocess': '^4.0.0'
});
update_component(cwd, 'src/components/Counter.svelte', [['<style>', '<style lang="scss">']]);
update_component(cwd, 'src/routes/index.svelte', [['<style>', '<style lang="scss">']]);
add_svelte_prepocess_to_config(cwd);
console.log(
bold(
green(
`✔ Added SCSS support. ` +
`To use it inside Svelte components, add lang="scss" to the attributes of a style tag.`
)
)
);
} else {
console.error(`Unknown CSS option "${which}"`);
}
}
2 changes: 1 addition & 1 deletion packages/create-svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-svelte",
"version": "2.0.0-alpha.16",
"version": "2.0.0-alpha.17",
"bin": "./bin",
"devDependencies": {
"@sveltejs/app-utils": "workspace:*",
Expand Down
7 changes: 7 additions & 0 deletions packages/kit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @sveltejs/kit

## 0.0.25

### Patch Changes

- Updated dependencies [3bdf33b]
- @sveltejs/app-utils@0.0.17

## 0.0.24

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/kit",
"version": "0.0.24",
"version": "0.0.25",
"dependencies": {
"@sveltejs/app-utils": "workspace:*",
"cheap-watch": "^1.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/api/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export async function build(config: SvelteAppConfig) {
fs.writeFileSync(setup_file, '');
}

await exec(`${snowpack_bin} build --out=${unoptimized}/server --ssr`);
await exec(`node ${snowpack_bin} build --out=${unoptimized}/server --ssr`);
log.success('server');
await exec(`${snowpack_bin} build --out=${unoptimized}/client`);
await exec(`node ${snowpack_bin} build --out=${unoptimized}/client`);
log.success('client');
}

Expand Down
Loading

0 comments on commit aab5112

Please sign in to comment.