From 5573258a105bb22596ab34ae88d19d310174f242 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 30 Sep 2018 11:32:58 -0400 Subject: [PATCH] update tests --- .gitignore | 1 + index.js | 1 + runtime/README.md | 1 - runtime/app.js | 2 -- src/core/create_manifests.ts | 38 ++++++++++++++++++++-------------- test/app/src/client.js | 10 ++++----- test/app/src/routes/about.html | 10 +-------- test/app/src/server.js | 6 ++---- test/app/src/service-worker.js | 4 ++-- test/app/webpack.config.js | 6 ++++++ 10 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 index.js delete mode 100644 runtime/README.md delete mode 100644 runtime/app.js diff --git a/.gitignore b/.gitignore index c80bb4a..3db73ec 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ node_modules cypress/screenshots test/app/.sapper test/app/src/manifest +__sapper__ test/app/export test/app/build sapper diff --git a/index.js b/index.js new file mode 100644 index 0000000..92381ab --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +throw new Error(`As of Sapper 0.22, you should not import 'sapper' directly. See https://sapper.svelte.technology/guide#0-21-to-0-22 for more information`); \ No newline at end of file diff --git a/runtime/README.md b/runtime/README.md deleted file mode 100644 index 7b650d6..0000000 --- a/runtime/README.md +++ /dev/null @@ -1 +0,0 @@ -This directory exists for legacy reasons and should be deleted before releasing version 1. \ No newline at end of file diff --git a/runtime/app.js b/runtime/app.js deleted file mode 100644 index 43ebb81..0000000 --- a/runtime/app.js +++ /dev/null @@ -1,2 +0,0 @@ -console.error('sapper/runtime/app.js has been deprecated in favour of sapper/runtime.js'); -export * from '../runtime.js'; \ No newline at end of file diff --git a/src/core/create_manifests.ts b/src/core/create_manifests.ts index e2035f9..3d315cd 100644 --- a/src/core/create_manifests.ts +++ b/src/core/create_manifests.ts @@ -73,24 +73,30 @@ function generate_client( const server_routes_to_ignore = manifest_data.server_routes.filter(route => !page_ids.has(route.pattern.toString())); + const component_indexes: Record = {}; + let code = ` import root from ${stringify(get_file(path_to_routes, manifest_data.root))}; import error from ${stringify(posixify(`${path_to_routes}/_error.html`))}; const d = decodeURIComponent; - ${manifest_data.components.map(component => { - const annotation = bundler === 'webpack' - ? `/* webpackChunkName: "${component.name}" */ ` - : ''; + const components = [ + ${manifest_data.components.map((component, i) => { + const annotation = bundler === 'webpack' + ? `/* webpackChunkName: "${component.name}" */ ` + : ''; - const source = get_file(path_to_routes, component); + const source = get_file(path_to_routes, component); - return `const ${component.name} = { - js: () => import(${annotation}${stringify(source)}), - css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__" - };`; - }).join('\n')} + component_indexes[component.name] = i; + + return `{ + js: () => import(${annotation}${stringify(source)}), + css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__" + }`; + }).join(',\n\t\t\t')} + ]; const manifest = { ignore: [${server_routes_to_ignore.map(route => route.pattern).join(', ')}], @@ -105,10 +111,10 @@ function generate_client( if (part.params.length > 0) { const props = part.params.map((param, i) => `${param}: d(match[${i + 1}])`); - return `{ component: ${part.component.name}, params: match => ({ ${props.join(', ')} }) }`; + return `{ component: components[${component_indexes[part.component.name]}], params: match => ({ ${props.join(', ')} }) }`; } - return `{ component: ${part.component.name} }`; + return `{ component: components[${component_indexes[part.component.name]}] }`; }).join(',\n\t\t\t\t\t\t')} ] }`).join(',\n\n\t\t\t\t')} @@ -144,9 +150,9 @@ function generate_server( const imports = [].concat( manifest_data.server_routes.map(route => - `import * as ${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`), + `import * as __${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`), manifest_data.components.map(component => - `import ${component.name} from ${stringify(get_file(path_to_routes, component))};`), + `import __${component.name} from ${stringify(get_file(path_to_routes, component))};`), `import root from ${stringify(get_file(path_to_routes, manifest_data.root))};`, `import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};` ); @@ -161,7 +167,7 @@ function generate_server( ${manifest_data.server_routes.map(route => `{ // ${route.file} pattern: ${route.pattern}, - handlers: ${route.name}, + handlers: __${route.name}, params: ${route.params.length > 0 ? `match => ({ ${route.params.map((param, i) => `${param}: d(match[${i + 1}])`).join(', ')} })` : `() => ({})`} @@ -179,7 +185,7 @@ function generate_server( const props = [ `name: "${part.component.name}"`, `file: ${stringify(part.component.file)}`, - `component: ${part.component.name}` + `component: __${part.component.name}` ]; if (part.params.length > 0) { diff --git a/test/app/src/client.js b/test/app/src/client.js index d1c2e96..f5c2d35 100644 --- a/test/app/src/client.js +++ b/test/app/src/client.js @@ -1,14 +1,12 @@ -import { init, goto, prefetchRoutes } from '../../../runtime.js'; import { Store } from 'svelte/store.js'; -import { manifest } from './manifest/client.js'; +import * as sapper from './__sapper__/client.js'; window.init = () => { - return init({ + return sapper.start({ target: document.querySelector('#sapper'), - manifest, store: data => new Store(data) }); }; -window.prefetchRoutes = prefetchRoutes; -window.goto = goto; \ No newline at end of file +window.prefetchRoutes = sapper.prefetchRoutes; +window.goto = sapper.goto; \ No newline at end of file diff --git a/test/app/src/routes/about.html b/test/app/src/routes/about.html index 949ad84..ac346b3 100644 --- a/test/app/src/routes/about.html +++ b/test/app/src/routes/about.html @@ -9,17 +9,9 @@