-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: restart server when svelte config file changes (fixes #63) * fix: make sure the absolute path of the loaded svelte config file is kept in resolvedOptions * refactor: use package.json scripts and execa to start servers for e2e-tests; add tests for svelte config watching * fix: remove syntax not supported by node12 from e2e script * fix: use writeFileSync instead of fs/promises for node12 * chore: remove debugging screenshots * chore: update dependencies * test: move to lower portrange and archive dist on failure * test: fix e2e-server script. correct error output and don't throw if closing server wasn't graceful * fix: really bad c&p err * test: increase sleep time on windows to account for slower devserver restart * fix invalid doc * chore: update changeset
- Loading branch information
Showing
42 changed files
with
1,059 additions
and
850 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@sveltejs/vite-plugin-svelte': minor | ||
--- | ||
|
||
- Restart dev server when svelte config file changes | ||
- Refactored e2e-tests to use package.json scripts | ||
- Updated dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 12 additions & 3 deletions
15
packages/e2e-tests/autoprefixer-browerslist/vite.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
const { svelte } = require('@sveltejs/vite-plugin-svelte'); | ||
const { defineConfig } = require('vite'); | ||
|
||
module.exports = defineConfig(({ command, mode }) => { | ||
const isProduction = mode === 'production'; | ||
module.exports = defineConfig(() => { | ||
return { | ||
plugins: [svelte()], | ||
build: { | ||
minify: isProduction | ||
// make build faster by skipping transforms and minification | ||
target: 'esnext', | ||
minify: false | ||
}, | ||
server: { | ||
watch: { | ||
// During tests we edit the files too fast and sometimes chokidar | ||
// misses change events, so enforce polling for consistency | ||
usePolling: true, | ||
interval: 100 | ||
} | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const sveltePreprocess = require('svelte-preprocess'); | ||
|
||
module.exports = { | ||
preprocess: sveltePreprocess() | ||
emitCss: false | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
/* | ||
const sveltePreprocess = require('svelte-preprocess'); | ||
module.exports = { | ||
preprocess: sveltePreprocess() | ||
}; | ||
*/ | ||
export default { | ||
emitCss: true | ||
emitCss: false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
const { svelte } = require('@sveltejs/vite-plugin-svelte'); | ||
const { defineConfig } = require('vite'); | ||
|
||
module.exports = defineConfig(({ command, mode }) => { | ||
const isProduction = mode === 'production'; | ||
module.exports = defineConfig(() => { | ||
return { | ||
plugins: [svelte({ configFile: 'svelte.config.custom.cjs' })], | ||
build: { | ||
minify: isProduction | ||
// make build faster by skipping transforms and minification | ||
target: 'esnext', | ||
minify: false | ||
}, | ||
server: { | ||
watch: { | ||
// During tests we edit the files too fast and sometimes chokidar | ||
// misses change events, so enforce polling for consistency | ||
usePolling: true, | ||
interval: 100 | ||
} | ||
} | ||
}; | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// script to start package.json dev/build/preview scripts with execa for e2e tests | ||
const execa = require('execa'); | ||
const treeKill = require('tree-kill'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const isWin = process.platform === 'win32'; | ||
async function startedOnPort(serverProcess, port, timeout) { | ||
let id; | ||
let stdoutListener; | ||
const timerPromise = new Promise( | ||
(_, reject) => | ||
(id = setTimeout(() => { | ||
reject(`timeout for server start after ${timeout}`); | ||
}, timeout)) | ||
); | ||
const startedPromise = new Promise((resolve, reject) => { | ||
stdoutListener = (data) => { | ||
const str = data.toString(); | ||
// hack, console output may contain color code gibberish | ||
// skip gibberish between localhost: and port number | ||
const match = str.match(/(http:\/\/localhost:)(?:.*)(\d{4})/); | ||
if (match) { | ||
const startedPort = parseInt(match[2], 10); | ||
if (startedPort === port) { | ||
resolve(); | ||
} else { | ||
const msg = `test server started on ${startedPort} instead of ${port}`; | ||
console.log(msg); | ||
reject(msg); | ||
} | ||
} | ||
}; | ||
|
||
serverProcess.stdout.on('data', stdoutListener); | ||
}); | ||
|
||
return Promise.race([timerPromise, startedPromise]).finally(() => { | ||
serverProcess.stdout.off('data', stdoutListener); | ||
clearTimeout(id); | ||
}); | ||
} | ||
|
||
exports.serve = async function serve(root, isBuild, port) { | ||
const logDir = path.join(root, 'logs'); | ||
const logs = { | ||
server: null, | ||
build: null | ||
}; | ||
const writeLogs = async (name, result) => { | ||
try { | ||
if (result.out && result.out.length > 0) { | ||
fs.writeFileSync(path.join(logDir, `${name}.log`), result.out.join(''), 'utf-8'); | ||
} | ||
if (result.err && result.err.length > 0) { | ||
fs.writeFileSync(path.join(logDir, `${name}.err.log`), result.err.join(''), 'utf-8'); | ||
} | ||
} catch (e1) { | ||
console.error(`failed to write ${name} logs in ${logDir}`, e1); | ||
} | ||
}; | ||
|
||
if (isBuild) { | ||
let buildResult; | ||
let hasErr = false; | ||
let out = []; | ||
let err = []; | ||
|
||
try { | ||
const buildProcess = execa('pnpm', ['build'], { | ||
preferLocal: true, | ||
cwd: root, | ||
stdio: 'pipe' | ||
}); | ||
logs.build = { out, err }; | ||
buildProcess.stdout.on('data', (d) => out.push(d.toString())); | ||
buildProcess.stderr.on('data', (d) => err.push(d.toString())); | ||
await buildProcess; | ||
} catch (e) { | ||
buildResult = e; | ||
if (buildResult.stdout) { | ||
out.push(buildResult.stdout); | ||
} | ||
if (buildResult.stderr) { | ||
err.push(buildResult.stderr); | ||
} | ||
hasErr = true; | ||
} | ||
await writeLogs('build', logs.build); | ||
if (hasErr) { | ||
throw buildResult; | ||
} | ||
} | ||
|
||
const serverProcess = execa('pnpm', [isBuild ? 'preview' : 'dev', '--', '--port', port], { | ||
preferLocal: true, | ||
cwd: root, | ||
stdio: 'pipe' | ||
}); | ||
const out = [], | ||
err = []; | ||
logs.server = { out, err }; | ||
serverProcess.stdout.on('data', (d) => out.push(d.toString())); | ||
serverProcess.stderr.on('data', (d) => err.push(d.toString())); | ||
|
||
const closeServer = async () => { | ||
if (serverProcess) { | ||
if (serverProcess.pid) { | ||
await new Promise((resolve) => { | ||
treeKill(serverProcess.pid, (err) => { | ||
if (err) { | ||
console.error(`failed to treekill serverprocess ${serverProcess.pid}`, err); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} else { | ||
serverProcess.cancel(); | ||
} | ||
|
||
try { | ||
await serverProcess; | ||
} catch (e) { | ||
if (e.stdout) { | ||
out.push(e.stdout); | ||
} | ||
if (e.stderr) { | ||
err.push(e.stderr); | ||
} | ||
if (!isWin) { | ||
// treekill on windows uses taskkill and that ends up here always | ||
console.error(`server process did not exit gracefully. dir: ${root}`, e); | ||
} | ||
} | ||
} | ||
await writeLogs('server', logs.server); | ||
}; | ||
try { | ||
await startedOnPort(serverProcess, port, 20000); | ||
return { | ||
port, | ||
logs, | ||
close: closeServer | ||
}; | ||
} catch (e) { | ||
try { | ||
await closeServer(); | ||
} catch (e1) { | ||
console.error('failed to close server process', e1); | ||
} | ||
} | ||
}; |
Oops, something went wrong.