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 all 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
12 changes: 12 additions & 0 deletions .changeset/gold-readers-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'hn.svelte.dev': patch
'svelte-kit-demo': patch
'@sveltejs/adapter-netlify': patch
'@sveltejs/adapter-node': patch
'@sveltejs/adapter-static': patch
'@sveltejs/app-utils': patch
'@sveltejs/kit': patch
'@sveltejs/snowpack-config': patch
---

Overhaul adapter API - fixes #166
4 changes: 4 additions & 0 deletions examples/hn.svelte.dev/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
command = "npm run build"
publish = "build/"
functions = "functions/"
2 changes: 1 addition & 1 deletion examples/hn.svelte.dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "svelte build"
},
"devDependencies": {
"@sveltejs/adapter-node": "workspace:*",
"@sveltejs/adapter-netlify": "workspace:*",
"@sveltejs/kit": "workspace:*",
"@sveltejs/snowpack-config": "workspace:*",
"svelte": "^3.29.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/hn.svelte.dev/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
// By default, `npm run build` will create a standard Node app.
// You can create optimized builds for different platforms by
// specifying a different adapter
adapter: '@sveltejs/adapter-node'
adapter: '@sveltejs/adapter-netlify'
};
Empty file.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.6.0",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"eslint": "^7.11.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-svelte3": "^2.7.3",
"prettier": "2.1.2",
"rollup": "^2.32.0"
"rollup": "^2.32.0",
"typescript": "^4.1.2"
}
}
4 changes: 1 addition & 3 deletions packages/adapter-netlify/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
.DS_Store
node_modules
/index.js
/render.js
node_modules
45 changes: 45 additions & 0 deletions packages/adapter-netlify/files/render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

const url = require('url');
const app = require('./app.js');

exports.handler = async (event) => {
const {
path,
httpMethod,
headers,
queryStringParameters
// body, // TODO pass this to renderer
// isBase64Encoded // TODO is this useful?
} = event;

const query = new url.URLSearchParams();
for (const k in queryStringParameters) {
const value = queryStringParameters[k];
value.split(', ').forEach((v) => {
query.append(k, v);
});
}

const rendered = await app.render({
host: null, // TODO
method: httpMethod,
headers,
path,
query
});

if (rendered) {
return {
isBase64Encoded: false,
statusCode: rendered.status,
headers: rendered.headers,
body: rendered.body
};
}

return {
statusCode: 404,
body: 'Not found'
};
};
48 changes: 48 additions & 0 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

const fs = require('fs');
const path = require('path');
const toml = require('toml');

module.exports = async function adapter(builder) {
let netlify_config;

if (fs.existsSync('netlify.toml')) {
try {
netlify_config = toml.parse(fs.readFileSync('netlify.toml', 'utf-8'));
} catch (err) {
err.message = `Error parsing netlify.toml: ${err.message}`;
throw err;
}
} else {
// TODO offer to create one?
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) {
throw new Error(
'You must specify build.publish and build.functions in netlify.toml. Consult https://github.com/sveltejs/adapter-netlify#configuration'
);
}

const publish = path.resolve(netlify_config.build.publish);
const functions = path.resolve(netlify_config.build.functions);

builder.copy_static_files(publish);
builder.copy_client_files(`${publish}/_app`);
builder.copy_server_files(`${functions}/render`);

// copy the renderer
fs.copyFileSync(path.resolve(__dirname, 'files/render.js'), `${functions}/render/index.js`);

// create _redirects
fs.writeFileSync(`${publish}/_redirects`, '/* /.netlify/functions/render 200');

// prerender
builder.log.info('Prerendering static pages...');
await builder.prerender({
dest: publish
});
};
15 changes: 2 additions & 13 deletions packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
{
"name": "@sveltejs/adapter-netlify",
"version": "0.0.11",
"devDependencies": {
"@sveltejs/app-utils": "workspace:*",
"@types/aws-lambda": "^8.10.64",
"devalue": "^2.0.1",
"rollup": "^2.32.0"
},
"main": "index.js",
"files": [
"render.js"
"files"
],
"scripts": {
"dev": "rollup -cw",
"build": "rollup -c",
"lint": "eslint --ignore-pattern node_modules/ --ignore-pattern render.js \"**/*.{ts,js,svelte}\" && npm run check-format",
"format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"prepublishOnly": "npm run build"
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
},
"dependencies": {
"kleur": "^4.1.3",
"tiny-glob": "^0.2.8",
"toml": "^3.0.0"
}
}
23 changes: 0 additions & 23 deletions packages/adapter-netlify/rollup.config.js

This file was deleted.

91 changes: 0 additions & 91 deletions packages/adapter-netlify/src/index.js

This file was deleted.

66 changes: 0 additions & 66 deletions packages/adapter-netlify/src/render.js

This file was deleted.

5 changes: 1 addition & 4 deletions packages/adapter-node/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.DS_Store
node_modules
index.js
index.d.ts
server.js
server.d.ts
/files
17 changes: 17 additions & 0 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const fs = require('fs');

module.exports = async function adapter(builder) {
const out = 'build'; // TODO implement adapter options

builder.copy_server_files(out);
builder.copy_client_files(`${out}/assets/_app`);

fs.copyFileSync(`${__dirname}/files/server.js`, `${out}/index.js`);

builder.log.info('Prerendering static pages...');
await builder.prerender({
dest: `${out}/prerendered`
});
};
Loading