Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#166, but javascript #180

Merged
merged 33 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
57a237e
start work on #166
Rich-Harris Nov 25, 2020
87e60e2
remove typescript
Rich-Harris Nov 25, 2020
c3db751
remove ts-node in favour of esm
Rich-Harris Nov 25, 2020
f2476b3
Build kit package with sucrase
benmccann Nov 25, 2020
2053588
Convert tests to use sucrase
benmccann Nov 25, 2020
4532bd5
javascriptify gh-166
Rich-Harris Nov 25, 2020
cd24731
get build working again
Rich-Harris Nov 25, 2020
d258973
fix gitignore files
Rich-Harris Nov 25, 2020
b13560b
add back some missing files
Rich-Harris Nov 25, 2020
bfed3aa
tidy up
Rich-Harris Nov 25, 2020
5a88c5d
bit more tidying
Rich-Harris Nov 26, 2020
8d561c5
merge liberation -> gh-166-js
Rich-Harris Nov 26, 2020
39e7a94
restrict uvu pattern
Rich-Harris Nov 26, 2020
d5d77c4
copy client files, not everything
Rich-Harris Nov 26, 2020
d4eb980
remove generated file
Rich-Harris Nov 26, 2020
a0b8f61
implement adapter-static using builder API
Rich-Harris Nov 26, 2020
0e78455
ignore generated file
Rich-Harris Nov 26, 2020
4c4f9f6
get svelte-kit-demo example working
Rich-Harris Nov 26, 2020
1712fa8
update lockfile
Rich-Harris Nov 26, 2020
702cf69
add back svelte eslint config peer dependencies
Rich-Harris Nov 26, 2020
47b313e
move render logic into kit
Rich-Harris Nov 26, 2020
92523be
merge master -> gh-166-js
Rich-Harris Nov 26, 2020
83b13f5
update test
Rich-Harris Nov 26, 2020
7f52979
update adapter-netlify
Rich-Harris Nov 26, 2020
b9c0b46
fixes
Rich-Harris Nov 26, 2020
5efcdfc
simplify adapter-netlify
Rich-Harris Nov 26, 2020
e4955c0
use netlify in hn example
Rich-Harris Nov 26, 2020
b9791d5
add use strict pragmas
Rich-Harris Nov 26, 2020
df57dd1
remove unused dependency
Rich-Harris Nov 26, 2020
39f3647
update lockfile
Rich-Harris Nov 26, 2020
46fb674
tidy up
Rich-Harris Nov 26, 2020
6a56c16
update snowpack config
Rich-Harris Nov 26, 2020
e644180
add changeset
Rich-Harris Nov 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions packages/adapter-netlify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ import fs from 'fs';
import path from 'path';
import toml from 'toml';
import glob from 'tiny-glob/sync';

import { mkdirp } from '@sveltejs/app-utils/files';
import { prerender, generate_manifest_module } from '@sveltejs/app-utils/renderer';


module.exports = async function builder({
dir,
manifest,
log
}



) {
}) {
let netlify_config;

if (fs.existsSync('netlify.toml')) {
Expand Down
4 changes: 1 addition & 3 deletions packages/adapter-netlify/src/render.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import { URLSearchParams } from 'url';
import { render } from '@sveltejs/app-utils/renderer';


const manifest = require('./manifest.js');
const client = require('./client.json');
const root = require('./root.js');
Expand Down Expand Up @@ -33,7 +31,7 @@ export const handler = async (event) => {
const rendered = await render(
{
host: null, // TODO
method: httpMethod ,
method: httpMethod,
headers,
path,
query
Expand Down
8 changes: 1 addition & 7 deletions packages/adapter-node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import fs from 'fs';

import { copy } from '@sveltejs/app-utils/files';
import { prerender } from '@sveltejs/app-utils/renderer';


module.exports = async function adapter({
dir,
manifest,
log
}



) {
}) {
const out = 'build'; // TODO implement adapter options

copy(`${dir}/client`, `${out}/assets/_app`, (file) => !!file && file[0] !== '.');
Expand Down
7 changes: 3 additions & 4 deletions packages/adapter-node/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import sirv from 'sirv';
import { render } from '@sveltejs/app-utils/renderer';
import { get_body } from '@sveltejs/app-utils/http';


const manifest = require('./manifest.js');
const client = require('./client.json');

Expand Down Expand Up @@ -40,9 +39,9 @@ const server = http.createServer((req, res) => {
const rendered = await render(
{
host: null, // TODO
method: req.method ,
headers: req.headers , // TODO: what about repeated headers, i.e. string[]
path: parsed.pathname ,
method: req.method,
headers: req.headers, // TODO: what about repeated headers, i.e. string[]
path: parsed.pathname,
body: await get_body(req),
query: new URLSearchParams(parsed.query || '')
},
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-static/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.DS_Store
node_modules
/server.js
/index.js
7 changes: 1 addition & 6 deletions packages/adapter-static/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@
import { copy } from '@sveltejs/app-utils/files';
import { prerender } from '@sveltejs/app-utils/renderer';


module.exports = async function adapter({
dir,
manifest,
log
}



) {
}) {
const out = 'build'; // TODO implement adapter options

copy('static', out);
Expand Down
8 changes: 1 addition & 7 deletions packages/adapter-vercel/src/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { writeFileSync, readFileSync } from 'fs';
import { resolve, join } from 'path';

import { copy } from '@sveltejs/app-utils/files';
import { prerender, generate_manifest_module } from '@sveltejs/app-utils/renderer';


export async function builder({
dir,
manifest,
log
}



) {
}) {
const lambda_directory = resolve('api');
const static_directory = resolve('public');
const server_directory = resolve(join('api', 'server'));
Expand Down
4 changes: 1 addition & 3 deletions packages/adapter-vercel/src/server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { URLSearchParams } from 'url';
import { render } from '@sveltejs/app-utils/renderer';



const client = require('./server/client.json');
const manifest = require('./server/manifest.js');
const root = require('./server/root.js');
Expand Down Expand Up @@ -32,7 +30,7 @@ export const handler = async (event) => {
const rendered = await render(
{
host: null, // TODO
method: httpMethod ,
method: httpMethod,
headers,
path,
body,
Expand Down
5 changes: 2 additions & 3 deletions packages/app-utils/src/http/get_body/read_only_form_data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }

export function read_only_form_data() {
const map = new Map();

Expand All @@ -24,7 +22,8 @@ class ReadOnlyFormData {
}

get(key) {
return _optionalChain([this, 'access', _ => _.#map, 'access', _2 => _2.get, 'call', _3 => _3(key), 'optionalAccess', _4 => _4[0]]);
const value = this.#map.get(key);
return value && value[0];
}

getAll(key) {
Expand Down
2 changes: 0 additions & 2 deletions packages/app-utils/src/renderer/manifest/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


const array_item_delimiter = ',';

function map_pages(pages) {
Expand Down
2 changes: 0 additions & 2 deletions packages/app-utils/src/renderer/manifest/index.spec.data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


const examplePageComponentManifest = {
default: true,
type: 'foo',
Expand Down
23 changes: 4 additions & 19 deletions packages/app-utils/src/renderer/prerender/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }import fs from 'fs';
import fs from 'fs';
import { dirname, resolve as resolve_path } from 'path';
import { parse, resolve, URLSearchParams } from 'url';
import { mkdirp } from '../../files';
import { render } from '../render';


function clean_html(html) {
return html
.replace(/<!\[CDATA\[[\s\S]*?\]\]>/gm, '')
Expand Down Expand Up @@ -44,29 +43,14 @@ function get_srcset_urls(attrs) {
const OK = 2;
const REDIRECT = 3;









export async function prerender({
dir,
out,
assets,
manifest,
force,
log
}






) {
}) {
const seen = new Set();

const template = fs.readFileSync('src/app.html', 'utf-8');
Expand Down Expand Up @@ -105,7 +89,8 @@ export async function prerender({
if (rendered) {
const response_type = Math.floor(rendered.status / 100);
const headers = rendered.headers;
const is_html = response_type === REDIRECT || _optionalChain([headers, 'optionalAccess', _ => _['content-type']]) === 'text/html';
const type = headers && headers['content-type'];
const is_html = response_type === REDIRECT || type === 'text/html';

const parts = path.split('/');
if (is_html && parts[parts.length - 1] !== 'index.html') {
Expand Down
8 changes: 1 addition & 7 deletions packages/app-utils/src/renderer/render/endpoint.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@


export default function render_route(
request,
context,
options
)



{
) {
const route = options.manifest.endpoints.find((route) =>
route.pattern.test(request.path)
);
Expand Down
1 change: 0 additions & 1 deletion packages/app-utils/src/renderer/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createHash } from 'crypto';
import render_page from './page';
import render_endpoint from './endpoint';


function md5(body) {
return createHash('md5').update(body).digest('hex');
}
Expand Down
35 changes: 3 additions & 32 deletions packages/app-utils/src/renderer/render/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,17 @@ import * as mime from 'mime';
import fetch, { Response } from 'node-fetch';
import { readable, writable } from 'svelte/store';
import { parse, resolve, URLSearchParams } from 'url';











import { render } from './index';

const noop = () => {};







export default async function render_page(
request,
context,
options,
status = 200,
error = null
)







{
) {
let redirected;
let preload_error;

Expand Down Expand Up @@ -82,7 +57,7 @@ export default async function render_page(
redirected &&
(redirected.status !== status || redirected.headers.location !== location)
) {
throw new Error(`Conflicting redirects`);
throw new Error('Conflicting redirects');
}
location = location.replace(/^\//g, ''); // leading slash (only)
redirected = {
Expand Down Expand Up @@ -202,11 +177,7 @@ export default async function render_page(
if (preload_error) throw preload_error;
if (redirected) return redirected;

const branches



= [];
const branches = [];
parts.forEach((part, i) => {
if (part) {
branches.push({
Expand Down
20 changes: 8 additions & 12 deletions packages/kit/src/api/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import colors from 'kleur';
import relative from 'require-relative';
import { mkdirp } from '@sveltejs/app-utils/files';
import create_manifest_data from '../../core/create_manifest_data';
import { rollup, } from 'rollup';
import { rollup } from 'rollup';
import { terser } from 'rollup-plugin-terser';
import css_chunks from 'rollup-plugin-css-chunks';
import { copy_assets } from '../utils';
import { create_app } from '../../core/create_app';

import { css_injection } from './css_injection';
import Builder from './Builder';

Expand Down Expand Up @@ -168,10 +167,7 @@ export async function build(config) {
const reverse_lookup = new Map();

const routes = path.resolve(`${unoptimized}/client/_app/routes`);
const client


= {
const client = {
entry: null,
deps: {}
};
Expand All @@ -181,12 +177,12 @@ export async function build(config) {
for (const key in bundle) {
const chunk = bundle[key];

if ((chunk ).facadeModuleId === entry) {
if (chunk.facadeModuleId === entry) {
client.entry = key;
} else if ((chunk ).facadeModuleId === 'inject_styles.js') {
} else if (chunk.facadeModuleId === 'inject_styles.js') {
inject_styles = key;
} else if ((chunk ).modules) {
for (const id in (chunk ).modules) {
} else if (chunk.modules) {
for (const id in chunk.modules) {
if (id.startsWith(routes) && id.endsWith('.js')) {
const file = id.slice(routes.length + 1);
reverse_lookup.set(file, key);
Expand All @@ -203,7 +199,7 @@ export async function build(config) {
const chunk = bundle[key];

if (chunk) {
const imports = (chunk ).imports;
const imports = chunk.imports;

if (imports) {
imports.forEach((key) => {
Expand Down Expand Up @@ -291,6 +287,6 @@ export async function build(config) {

async function rimraf(path) {
return new Promise((resolve) => {
((fs).rm || fs.rmdir)(path, { recursive: true, force: true }, () => resolve());
(fs.rm || fs.rmdir)(path, { recursive: true, force: true }, () => resolve());
});
}
Loading