Skip to content

Commit

Permalink
format/lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 7, 2020
1 parent 2c83f39 commit 442ee4f
Show file tree
Hide file tree
Showing 29 changed files with 258 additions and 328 deletions.
2 changes: 1 addition & 1 deletion packages/adapter-netlify/files/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ exports.handler = async (event) => {
statusCode: 404,
body: 'Not found'
};
};
};
6 changes: 1 addition & 5 deletions packages/adapter-vercel/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ 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
}) {
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
3 changes: 1 addition & 2 deletions packages/adapter-vercel/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export const handler = async (event) => {
client,
root,
setup,
load: (route) =>
require(`./server/routes/${route.name}.js`),
load: (route) => require(`./server/routes/${route.name}.js`),
dev: false,
only_prerender: false
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"clean": "node rimraf.js files http renderer",
"dev": "npm run clean && rollup -cw",
"build": "npm run clean && rollup -c",
"lint": "eslint --ignore-pattern node_modules/ --ignore-pattern files/ --ignore-pattern http/ --ignore-pattern renderer/ \"**/*.{ts,js,svelte}\" && npm run check-format",
"lint": "eslint --ignore-pattern node_modules/ --ignore-pattern dist/ --ignore-pattern files/ --ignore-pattern http/ --ignore-pattern renderer/ \"**/*.{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",
Expand Down
4 changes: 1 addition & 3 deletions packages/app-utils/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export default {
sourcemap: true
}
],
plugins: [
nodeResolve()
],
plugins: [nodeResolve()],
external: [...require('module').builtinModules, ...Object.keys(pkg.dependencies)]
};
6 changes: 1 addition & 5 deletions packages/app-utils/src/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ export function mkdirp(dir) {
}
}

export function copy(
from,
to,
filter = () => true
) {
export function copy(from, to, filter = () => true) {
if (!filter(path.basename(from))) return [];

const files = [];
Expand Down
5 changes: 2 additions & 3 deletions packages/app-utils/src/http/get_body/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { read_only_form_data } from './read_only_form_data';

export function get_body(req) {
Expand All @@ -10,7 +9,7 @@ export function get_body(req) {

if (!has_body) return Promise.resolve(undefined);

const [type, ...directives] = (headers['content-type'] ).split(/;\s*/);
const [type, ...directives] = headers['content-type'].split(/;\s*/);

switch (type) {
case 'application/octet-stream':
Expand Down Expand Up @@ -70,7 +69,7 @@ async function get_multipart(req, boundary) {
const { data, append } = read_only_form_data();

parts.slice(1, -1).forEach((part) => {
const match = /\s*([\s\S]+?)\r\n\r\n([\s\S]*)\s*/.exec(part) ;
const match = /\s*([\s\S]+?)\r\n\r\n([\s\S]*)\s*/.exec(part);
const raw_headers = match[1];
const body = match[2].trim();

Expand Down
4 changes: 2 additions & 2 deletions packages/app-utils/src/http/get_body/read_only_form_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function read_only_form_data() {
return {
append(key, value) {
if (map.has(key)) {
(map.get(key) ).push(value);
map.get(key).push(value);
} else {
map.set(key, [value]);
}
Expand All @@ -15,7 +15,7 @@ export function read_only_form_data() {
}

class ReadOnlyFormData {
#map
#map;

constructor(map) {
this.#map = map;
Expand Down
6 changes: 1 addition & 5 deletions packages/create-svelte/cli/modifications/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ export function update_package_json(cwd, newDevDeps) {
/**
* Updates a Svelte component, doing all given replacements.
*/
export function update_component(
cwd,
filepath,
replacements
) {
export function update_component(cwd, filepath, replacements) {
const file = path.join(cwd, filepath);

let code = fs.readFileSync(file, 'utf-8');
Expand Down
2 changes: 1 addition & 1 deletion packages/create-svelte/template/snowpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = {
'src/components': '/_components'
},
alias: {
'$components': './src/components'
$components: './src/components'
}
};
2 changes: 1 addition & 1 deletion packages/kit/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"parserOptions": {
"sourceType": "module"
}
}
}
12 changes: 2 additions & 10 deletions packages/kit/src/api/adapt/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ export default class Builder {
#static_files;
#manifest;

constructor({
generated_files,
static_files,
log,
manifest
}) {
constructor({ generated_files, static_files, log, manifest }) {
this.#generated_files = generated_files;
this.#static_files = static_files;
this.#manifest = manifest;
Expand All @@ -31,10 +26,7 @@ export default class Builder {
copy(this.#static_files, dest);
}

async prerender({
force = false,
dest
}) {
async prerender({ force = false, dest }) {
await prerender({
out: dest,
force,
Expand Down
34 changes: 16 additions & 18 deletions packages/kit/src/api/adapt/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,7 @@ function get_srcset_urls(attrs) {
const OK = 2;
const REDIRECT = 3;

export async function prerender({
dir,
out,
manifest,
log,
force
}) {
export async function prerender({ dir, out, manifest, log, force }) {
const seen = new Set();

const server_root = resolve_path(dir);
Expand All @@ -58,16 +52,19 @@ export async function prerender({
if (seen.has(path)) return;
seen.add(path);

const rendered = await app.render({
host: null, // TODO ???
method: 'GET',
headers: {},
path,
body: null,
query: new URLSearchParams()
}, {
only_prerender: !force
});
const rendered = await app.render(
{
host: null, // TODO ???
method: 'GET',
headers: {},
path,
body: null,
query: new URLSearchParams()
},
{
only_prerender: !force
}
);

if (rendered) {
const response_type = Math.floor(rendered.status / 100);
Expand Down Expand Up @@ -162,7 +159,8 @@ export async function prerender({
if (parts[parts.length - 1] === 'index.html') parts.pop();

const file_exists =
(parsed.pathname.startsWith('/_app/') && fs.existsSync(`${dir}/client/${parsed.pathname}`)) ||
(parsed.pathname.startsWith('/_app/') &&
fs.existsSync(`${dir}/client/${parsed.pathname}`)) ||
fs.existsSync(`${out}${parsed.pathname}`) ||
fs.existsSync(`static${parsed.pathname}`) ||
fs.existsSync(`static${parsed.pathname}/index.html`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
42
42
15 changes: 3 additions & 12 deletions packages/kit/src/api/adapt/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,17 @@ suite('copy files', () => {
rimraf.sync(dest);
builder.copy_static_files(dest);

assert.equal(
glob('**', { cwd: static_files }),
glob('**', { cwd: dest })
);
assert.equal(glob('**', { cwd: static_files }), glob('**', { cwd: dest }));

rimraf.sync(dest);
builder.copy_client_files(dest);

assert.equal(
glob('**', { cwd: `${generated_files}/client` }),
glob('**', { cwd: dest })
);
assert.equal(glob('**', { cwd: `${generated_files}/client` }), glob('**', { cwd: dest }));

rimraf.sync(dest);
builder.copy_server_files(dest);

assert.equal(
glob('**', { cwd: `${generated_files}/server` }),
glob('**', { cwd: dest })
);
assert.equal(glob('**', { cwd: `${generated_files}/server` }), glob('**', { cwd: dest }));
});

suite.run();
21 changes: 2 additions & 19 deletions packages/kit/src/api/build/css_injection.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@









const inject_styles = `
export default function(files) {
return Promise.all(files.map(function(file) { return new Promise(function(fulfil, reject) {
Expand Down Expand Up @@ -93,11 +84,7 @@ export const css_injection = {
};
}
},
async generateBundle(

_options,
bundle
) {
async generateBundle(_options, bundle) {
const inject_styles_file = Object.keys(bundle).find((f) => f.startsWith('inject_styles'));

let has_css = false;
Expand All @@ -109,11 +96,7 @@ export const css_injection = {
if (chunk.code) {
chunk.code = chunk.code.replace(/___SVELTE_CSS_INJECTION___([0-9a-f]+)___/g, (_m, id) => {
id = Buffer.from(id, 'hex').toString();
const target = (
Object.values(bundle).find(
(c) => (c).modules && (c).modules[id]
)
);
const target = Object.values(bundle).find((c) => c.modules && c.modules[id]);

if (target) {
const css_files = find_css(target, bundle);
Expand Down
Loading

0 comments on commit 442ee4f

Please sign in to comment.