Skip to content

Commit

Permalink
finalize JS API for startServer
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Oct 17, 2020
1 parent d93aaa1 commit ccc3e2a
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 155 deletions.
14 changes: 6 additions & 8 deletions plugins/web-test-runner-plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,33 @@ To Resolve:
`);
}
const pkgManifest = require(path.join(cwd, 'package.json'));
const config = snowpack.unstable__loadAndValidateConfig(
const config = snowpack.loadAndValidateConfig(
{devOptions: {hmr: false, open: 'none', output: 'stream'}},
pkgManifest,
);
let loadByUrl, shutdownServer;
let server;

return {
name: 'snowpack-plugin',
async serverStart({fileWatcher}) {
fileWatcher.add(Object.keys(config.mount));
const server = await snowpack.unstable__startServer({
server = await snowpack.startServer({
cwd,
config,
lockfile: null,
pkgManifest,
});
loadByUrl = server.loadByUrl;
shutdownServer = server.shutdown;
},
async serverStop() {
return shutdownServer();
return server.shutdown();
},
async serve({request}) {
if (request.url.startsWith('/__web-dev-server')) {
return;
}
const reqPath = request.path;
const result = await loadByUrl(reqPath, {isSSR: false});
return result;
const result = await server.loadUrl(reqPath, {isSSR: false});
return result.contents;
},
transformImport({source}) {
if (!isTestFilePath(source) || source.startsWith('/__web-dev-server')) {
Expand Down
Loading

0 comments on commit ccc3e2a

Please sign in to comment.