diff --git a/src/api/build.ts b/src/api/build.ts index d589da4be..8999f186e 100644 --- a/src/api/build.ts +++ b/src/api/build.ts @@ -20,7 +20,7 @@ type Opts = { legacy?: boolean; bundler?: 'rollup' | 'webpack'; ext?: string; - oncompile?: ({ type, result }: { type: string, result: CompileResult }) => void; + oncompile?: ({ type, result }: { type: string; result: CompileResult }) => void; }; export async function build({ diff --git a/src/api/dev.ts b/src/api/dev.ts index 0ca56a5ee..7429f6a04 100644 --- a/src/api/dev.ts +++ b/src/api/dev.ts @@ -16,19 +16,19 @@ import { copy_runtime } from './utils/copy_runtime'; import { rimraf, mkdirp } from './utils/fs_utils'; type Opts = { - cwd?: string, - src?: string, - dest?: string, - routes?: string, - output?: string, - static?: string, - 'dev-port'?: number, - live?: boolean, - hot?: boolean, - 'devtools-port'?: number, - bundler?: 'rollup' | 'webpack', - port?: number, - ext: string + cwd?: string; + src?: string; + dest?: string; + routes?: string; + output?: string; + static?: string; + 'dev-port'?: number; + live?: boolean; + hot?: boolean; + 'devtools-port'?: number; + bundler?: 'rollup' | 'webpack'; + port?: number; + ext: string; }; export function dev(opts: Opts) { @@ -128,9 +128,9 @@ class Watcher extends EventEmitter { async init() { if (this.port) { if (!await ports.check(this.port)) { - this.emit('fatal', { + this.emit('fatal', { message: `Port ${this.port} is unavailable` - }); + } as FatalEvent); return; } } else { @@ -164,9 +164,9 @@ class Watcher extends EventEmitter { cwd, src, dest, routes, output }); } catch (err) { - this.emit('fatal', { + this.emit('fatal', { message: err.message - }); + } as FatalEvent); return; } @@ -192,10 +192,10 @@ class Watcher extends EventEmitter { cwd, src, dest, routes, output }); } catch (error) { - this.emit('error', { + this.emit('error', { type: 'manifest', error - }); + } as ErrorEvent); } } ) @@ -217,9 +217,9 @@ class Watcher extends EventEmitter { const compilers: Compilers = await create_compilers(this.bundler, cwd, src, dest, true); const emitFatal = () => { - this.emit('fatal', { + this.emit('fatal', { message: `Server crashed` - }); + } as FatalEvent); this.crashed = true; this.proc = null; @@ -239,10 +239,10 @@ class Watcher extends EventEmitter { return ports.wait(this.port) .then((() => { - this.emit('ready', { + this.emit('ready', { port: this.port, process: this.proc - }); + } as ReadyEvent); if (this.hot && this.bundler === 'webpack') { this.dev_server.send({ @@ -257,9 +257,9 @@ class Watcher extends EventEmitter { .catch(err => { if (this.crashed) return; - this.emit('fatal', { + this.emit('fatal', { message: `Server is not listening on port ${this.port}` - }); + } as FatalEvent); }); }; @@ -393,14 +393,14 @@ class Watcher extends EventEmitter { }; process.nextTick(() => { - this.emit('invalid', { + this.emit('invalid', { changed: Array.from(this.current_build.changed), invalid: { server: this.current_build.rebuilding.has('server'), client: this.current_build.rebuilding.has('client'), serviceworker: this.current_build.rebuilding.has('serviceworker'), } - }); + } as InvalidEvent); this.restarting = false; }); @@ -408,7 +408,7 @@ class Watcher extends EventEmitter { } watch(compiler: Compiler, { name, invalid = noop, handle_result = noop }: { - name: string, + name: string; invalid?: (filename: string) => void; handle_result?: (result: CompileResult) => void; }) { @@ -416,10 +416,10 @@ class Watcher extends EventEmitter { compiler.watch((error?: Error, result?: CompileResult) => { if (error) { - this.emit('error', { + this.emit('error', { type: name, error - }); + } as ErrorEvent); } else { this.emit('build', { type: name, @@ -489,7 +489,7 @@ class DevServer { function watch_dir( dir: string, - filter: ({ path, stats }: { path: string, stats: fs.Stats }) => boolean, + filter: ({ path, stats }: { path: string; stats: fs.Stats }) => boolean, callback: () => void ) { let watch: any; diff --git a/src/api/export.ts b/src/api/export.ts index 441a5dbc1..2d88f2d24 100644 --- a/src/api/export.ts +++ b/src/api/export.ts @@ -13,26 +13,26 @@ import { noop } from './utils/noop'; import { parse as parseLinkHeader } from 'http-link-header'; import { rimraf, copy, mkdirp } from './utils/fs_utils'; -const writeFile = promisify(fs.writeFile) +const writeFile = promisify(fs.writeFile); type Opts = { - build_dir?: string, - export_dir?: string, - cwd?: string, - static?: string, - basepath?: string, - host_header?: string, - timeout?: number | false, - concurrent?: number, + build_dir?: string; + export_dir?: string; + cwd?: string; + static?: string; + basepath?: string; + host_header?: string; + timeout?: number | false; + concurrent?: number; oninfo?: ({ message }: { message: string }) => void; onfile?: ({ file, size, status }: { file: string, size: number, status: number }) => void; entry?: string; }; type Ref = { - uri: string, - rel: string, - as: string + uri: string; + rel: string; + as: string; }; type URL = url.UrlWithStringQuery; @@ -42,7 +42,7 @@ function resolve(from: string, to: string) { } function cleanPath(path: string) { - return path.replace(/^\/|\/$|\/*index(.html)*$|.html$/g, '') + return path.replace(/^\/|\/$|\/*index(.html)*$|.html$/g, ''); } function get_href(attrs: string) { @@ -110,7 +110,7 @@ async function _export({ const saved = new Set(); function save(url: string, status: number, type: string, body: string) { - let { pathname } = resolve(origin, url); + const { pathname } = resolve(origin, url); let file = decodeURIComponent(pathname.slice(1)); if (saved.has(file)) return; @@ -141,7 +141,7 @@ async function _export({ function handle(url: URL, fetchOpts: FetchOpts, addCallback: Function) { let pathname = url.pathname; if (pathname !== '/service-worker-index.html') { - pathname = pathname.replace(fetchOpts.root.pathname, '') || '/' + pathname = pathname.replace(fetchOpts.root.pathname, '') || '/'; } if (seen.has(pathname)) return; @@ -190,11 +190,11 @@ async function _export({ if (range === 2 && type === 'text/html') { // parse link rel=preload headers and embed them in the HTML - let link = parseLinkHeader(response.headers.get('Link') || ''); + const link = parseLinkHeader(response.headers.get('Link') || ''); link.refs.forEach((ref: Ref) => { if (ref.rel === 'preload') { body = body.replace('', - ``) + ``); } }); @@ -206,7 +206,7 @@ async function _export({ const base = resolve(url.href, base_href); let match; - let pattern = //gm; + const pattern = //gm; while (match = pattern.exec(cleaned)) { const attrs = match[1]; @@ -216,7 +216,7 @@ async function _export({ const url = resolve(base.href, href); if (url.protocol === protocol && url.host === host) { - handle(url, fetchOpts, queue.add) + handle(url, fetchOpts, queue.add); } } } diff --git a/src/api/utils/export_queue.ts b/src/api/utils/export_queue.ts index fbc3b84eb..100c789ec 100644 --- a/src/api/utils/export_queue.ts +++ b/src/api/utils/export_queue.ts @@ -25,23 +25,23 @@ type QueueOpts = { callbacks?: { onDone?: () => void; [key: string]: Function; - } + }; }; // determines current state of a promise function promiseState(p: Promise) { - const t = {} + const t = {}; return Promise.race([p, t]).then(v => (v === t) ? "pending" : "fulfilled", () => "rejected"); } // finds first non-pending promise in a list of promises -async function findNotPendingIndex(list: Promise[]) { +async function findNotPendingIndex(list: Array>) { const states = await Promise.all(list.map(p => promiseState(p))); return states.findIndex(state => state !== 'pending'); } // filters any non-pending promises out of a list of promises -async function filterNotPending(list: Promise[]) { +async function filterNotPending(list: Array>) { const states = await Promise.all(list.map(p => promiseState(p))); return states.reduce((acc, curr, index) => { if (curr === 'pending') { @@ -56,12 +56,12 @@ async function filterNotPending(list: Promise[]) { // url array can contain any number of urls found during export process // fetching array can contain a number of fetch api returns equal to the concurrent option // saving array can contain a number of promisified writeFile returns equal to the concurrent option -function exportQueue({ concurrent, handleFetch, handleResponse, fetchOpts, callbacks } : QueueOpts) { +function exportQueue({ concurrent, handleFetch, handleResponse, fetchOpts, callbacks }: QueueOpts) { const urls: URL[] = []; - let fetching : Promise[] = []; - let saving : Promise[] = []; + const fetching: Array> = []; + let saving: Array> = []; - function addToQueue(p: Promise, queue: Promise[]) { + function addToQueue(p: Promise, queue: Array>) { const queuePromise = new Promise((res, rej) => { p.then((ret?: any) => { res(ret); @@ -113,6 +113,6 @@ function exportQueue({ concurrent, handleFetch, handleResponse, fetchOpts, callb callbacks[event] = fn; } }; -}; +} export { exportQueue, FetchOpts, FetchRet }; diff --git a/src/cli.ts b/src/cli.ts index 8af53a858..d8593b9bb 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -33,19 +33,19 @@ prog.command('dev') .option('--build-dir', 'Development build directory', '__sapper__/dev') .option('--ext', 'Custom Route Extension', '.svelte .html') .action(async (opts: { - port: number, - open: boolean, - 'dev-port': number, - live: boolean, - hot: boolean, - bundler?: 'rollup' | 'webpack', - cwd: string, - src: string, - routes: string, - static: string, - output: string, - 'build-dir': string, - ext: string + port: number; + open: boolean; + 'dev-port': number; + live: boolean; + hot: boolean; + bundler?: 'rollup' | 'webpack'; + cwd: string; + src: string; + routes: string; + static: string; + output: string; + 'build-dir': string; + ext: string; }) => { const { dev } = await import('./api/dev'); @@ -157,14 +157,14 @@ prog.command('build [dest]') .option('--ext', 'Custom page route extensions (space separated)', '.svelte .html') .example(`build custom-dir -p 4567`) .action(async (dest = '__sapper__/build', opts: { - port: string, - legacy: boolean, - bundler?: 'rollup' | 'webpack', - cwd: string, - src: string, - routes: string, - output: string, - ext: string + port: string; + legacy: boolean; + bundler?: 'rollup' | 'webpack'; + cwd: string; + src: string; + routes: string; + output: string; + ext: string; }) => { console.log(`> Building...`); @@ -208,21 +208,21 @@ prog.command('export [dest]') .option('--ext', 'Custom page route extensions (space separated)', '.svelte .html') .option('--entry', 'Custom entry points (space separated)', '/') .action(async (dest = '__sapper__/export', opts: { - build: boolean, - legacy: boolean, - bundler?: 'rollup' | 'webpack', - basepath?: string, - host?: string, - concurrent: number, - timeout: number | false, - cwd: string, - src: string, - routes: string, - static: string, - output: string, - 'build-dir': string, - ext: string - entry: string + build: boolean; + legacy: boolean; + bundler?: 'rollup' | 'webpack'; + basepath?: string; + host?: string; + concurrent: number; + timeout: number | false; + cwd: string; + src: string; + routes: string; + static: string; + output: string; + 'build-dir': string; + ext: string; + entry: string; }) => { try { if (opts.build) { diff --git a/src/config/rollup.ts b/src/config/rollup.ts index bb04b6334..8735b94bf 100644 --- a/src/config/rollup.ts +++ b/src/config/rollup.ts @@ -8,7 +8,7 @@ export default { client: { input: (): InputOption => { - return `${src}/client.js` + return `${src}/client.js`; }, output: (): OutputOptions => { @@ -51,7 +51,7 @@ export default { file: `${dest}/service-worker.js`, format: 'iife', sourcemap - } + }; } } }; \ No newline at end of file diff --git a/src/config/webpack.ts b/src/config/webpack.ts index 78a753584..0dc748c1d 100644 --- a/src/config/webpack.ts +++ b/src/config/webpack.ts @@ -50,7 +50,7 @@ export default { path: dest, filename: '[name].js', chunkFilename: '[name].[id].[hash].js' - } + }; } } }; \ No newline at end of file diff --git a/src/core/create_app.ts b/src/core/create_app.ts index 7dcd7f03c..680c6dd98 100644 --- a/src/core/create_app.ts +++ b/src/core/create_app.ts @@ -14,7 +14,7 @@ export function create_app({ routes, output }: { - bundler: string, + bundler: string; manifest_data: ManifestData; dev_port?: number; dev: boolean; @@ -22,7 +22,7 @@ export function create_app({ src: string; dest: string; routes: string; - output: string + output: string; }) { if (!fs.existsSync(output)) fs.mkdirSync(output); @@ -55,7 +55,7 @@ export function create_serviceworker_manifest({ manifest_data, output, client_fi } } - let code = ` + const code = ` // This file is generated by Sapper — do not edit it! export const timestamp = ${Date.now()}; @@ -73,7 +73,7 @@ export function create_serviceworker_manifest({ manifest_data, output, client_fi function create_param_match(param: string, i: number) { return /^\.{3}.+$/.test(param) ? `${param.replace(/.{3}/, '')}: d(match[${i + 1}]).split('/')` - : `${param}: d(match[${i + 1}])` + : `${param}: d(match[${i + 1}])`; } function generate_client_manifest( @@ -132,7 +132,7 @@ function generate_client_manifest( ]`.replace(/^\t/gm, ''); if (needs_decode) { - routes = `(d => ${routes})(decodeURIComponent)` + routes = `(d => ${routes})(decodeURIComponent)`; } return ` @@ -178,7 +178,7 @@ function generate_server_manifest( component_lookup[component.name] = i; }); - let code = ` + const code = ` `.replace(/^\t\t/gm, '').trim(); const build_dir = posixify(path.normalize(path.relative(cwd, dest))); diff --git a/src/core/create_compilers/RollupCompiler.ts b/src/core/create_compilers/RollupCompiler.ts index 6822abadc..c755ae858 100644 --- a/src/core/create_compilers/RollupCompiler.ts +++ b/src/core/create_compilers/RollupCompiler.ts @@ -17,7 +17,7 @@ export default class RollupCompiler { warnings: any[]; errors: any[]; chunks: any[]; - css_files: Array<{ id: string, code: string }>; + css_files: Array<{ id: string; code: string }>; constructor(config: any) { this._ = this.get_config(config); @@ -191,7 +191,7 @@ export function handleError(err: RollupError, recover = false) { } if (err.loc) { - stderr(`${(err.loc.file || err.id)!} (${err.loc.line}:${err.loc.column})`); + stderr(`${err.loc.file || err.id} (${err.loc.line}:${err.loc.column})`); } else if (err.id) { stderr(err.id); } diff --git a/src/core/create_compilers/RollupResult.ts b/src/core/create_compilers/RollupResult.ts index f3d33b844..5eb43fab6 100644 --- a/src/core/create_compilers/RollupResult.ts +++ b/src/core/create_compilers/RollupResult.ts @@ -17,15 +17,15 @@ export default class RollupResult implements CompileResult { dependencies: Record; css_files: CssFile[]; css: { - main: string, - chunks: Record + main: string; + chunks: Record; }; sourcemap: boolean | 'inline'; summary: string; constructor(duration: number, compiler: RollupCompiler, sourcemap: boolean | 'inline') { this.duration = duration; - this.sourcemap = sourcemap + this.sourcemap = sourcemap; this.errors = compiler.errors.map(munge_warning_or_error); this.warnings = compiler.warnings.map(munge_warning_or_error); diff --git a/src/core/create_compilers/extract_css.ts b/src/core/create_compilers/extract_css.ts index 57fc48067..5bec128c0 100644 --- a/src/core/create_compilers/extract_css.ts +++ b/src/core/create_compilers/extract_css.ts @@ -4,7 +4,7 @@ import hash from 'string-hash'; import * as codec from 'sourcemap-codec'; import { PageComponent, Dirs } from '../../interfaces'; import { CompileResult, Chunk } from './interfaces'; -import { normalize_path, posixify } from '../../utils' +import { normalize_path, posixify } from '../../utils'; const inline_sourcemap_header = 'data:application/json;charset=utf-8;base64,'; @@ -111,7 +111,7 @@ export default function extract_css( ) { const result: { main: string | null; - chunks: Record + chunks: Record; } = { main: null, chunks: {} @@ -155,7 +155,7 @@ export default function extract_css( } if (sourcemap === 'inline') { - const base64 = Buffer.from(JSON.stringify(map), 'utf8').toString('base64') + const base64 = Buffer.from(JSON.stringify(map), 'utf8').toString('base64'); code += `\n/*# sourceMappingURL=${inline_sourcemap_header}${base64} */`; } @@ -270,7 +270,7 @@ export default function extract_css( } if (sourcemap === 'inline') { - const base64 = Buffer.from(JSON.stringify(map), 'utf8').toString('base64') + const base64 = Buffer.from(JSON.stringify(map), 'utf8').toString('base64'); code += `\n/*# sourceMappingURL=${inline_sourcemap_header}${base64} */`; } diff --git a/src/core/create_compilers/interfaces.ts b/src/core/create_compilers/interfaces.ts index b7afb604d..afe22ed0b 100644 --- a/src/core/create_compilers/interfaces.ts +++ b/src/core/create_compilers/interfaces.ts @@ -25,7 +25,7 @@ export interface CompileResult { css_files: CssFile[]; print: () => void; - to_json: (manifest_data: ManifestData, dirs: Dirs) => BuildInfo + to_json: (manifest_data: ManifestData, dirs: Dirs) => BuildInfo; } export type BuildInfo = { @@ -35,7 +35,7 @@ export type BuildInfo = { dependencies?: Record; legacy_assets?: Record; css: { - main: string | null, - chunks: Record - } + main: string | null; + chunks: Record; + }; } diff --git a/src/core/create_manifest_data.ts b/src/core/create_manifest_data.ts index 3d720bd3b..99aa3e758 100644 --- a/src/core/create_manifest_data.ts +++ b/src/core/create_manifest_data.ts @@ -19,7 +19,7 @@ export default function create_manifest_data(cwd: string, extensions: string = ' return ext ? { name: component_name, - file: file + file } : null; } @@ -47,8 +47,8 @@ export default function create_manifest_data(cwd: string, extensions: string = ' parent_segments: Part[][], parent_params: string[], stack: Array<{ - component: PageComponent, - params: string[] + component: PageComponent; + params: string[]; }> ) { const items = fs.readdirSync(dir) @@ -151,7 +151,7 @@ export default function create_manifest_data(cwd: string, extensions: string = ' const parts = (item.is_index && stack[stack.length - 1] === null) ? stack.slice(0, -1).concat({ component, params }) - : stack.concat({ component, params }) + : stack.concat({ component, params }); pages.push({ pattern: get_pattern(segments, true), @@ -223,8 +223,8 @@ function is_spread(path: string) { } function comparator( - a: { basename: string, parts: Part[], file: string, is_index: boolean }, - b: { basename: string, parts: Part[], file: string, is_index: boolean } + a: { basename: string; parts: Part[]; file: string; is_index: boolean; }, + b: { basename: string; parts: Part[]; file: string; is_index: boolean; } ) { if (a.is_index !== b.is_index) { if (a.is_index) return is_spread(a.file) ? 1 : -1; @@ -243,7 +243,7 @@ function comparator( // if spread && index, order later if (a_sub_part.spread && b_sub_part.spread) { - return a.is_index ? 1 : -1 + return a.is_index ? 1 : -1; } // If one is ...spread order it later @@ -287,7 +287,7 @@ function get_parts(part: string): Part[] { const [, content, qualifier] = dynamic ? /([^(]+)(\(.+\))?$/.exec(str) - : [, str, null]; + : [null, str, null]; return { content, @@ -301,12 +301,12 @@ function get_parts(part: string): Part[] { function get_slug(file: string) { let name = file - .replace(/[\\\/]index/, '') - .replace(/[\/\\]/g, '_') + .replace(/[\\/]index/, '') + .replace(/[/\\]/g, '_') .replace(/\.\w+$/, '') .replace(/\[([^(]+)(?:\([^(]+\))?\]/, '$$$1') .replace(/[^a-zA-Z0-9_$]/g, c => { - return c === '.' ? '_' : `$${c.charCodeAt(0)}` + return c === '.' ? '_' : `$${c.charCodeAt(0)}`; }); if (reserved_words.has(name)) name += '_'; diff --git a/src/interfaces.ts b/src/interfaces.ts index 1f124b357..631ac997f 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -3,10 +3,10 @@ import { CompileResult } from './core/create_compilers/interfaces'; export type Route = { id: string; - handlers: { + handlers: Array<{ type: 'page' | 'route'; file: string; - }[]; + }>; pattern: RegExp; test: (url: string) => boolean; exec: (url: string) => Record; @@ -37,7 +37,7 @@ export type Page = { parts: Array<{ component: PageComponent; params: string[]; - }> + }>; }; export type ServerRoute = { @@ -48,9 +48,9 @@ export type ServerRoute = { }; export type Dirs = { - dest: string, - src: string, - routes: string + dest: string; + src: string; + routes: string; }; export type ManifestData = { @@ -89,13 +89,13 @@ export type InvalidEvent = { client: boolean; server: boolean; serviceworker: boolean; - } + }; }; export type BuildEvent = { type: string; - errors: Array<{ file: string, message: string, duplicate: boolean }>; - warnings: Array<{ file: string, message: string, duplicate: boolean }>; + errors: Array<{ file: string; message: string; duplicate: boolean }>; + warnings: Array<{ file: string; message: string; duplicate: boolean }>; duration: number; result: CompileResult; };