This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 433
Remove use of eval in non-legacy rollup builds #1760
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,58 @@ | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import replace from '@rollup/plugin-replace'; | ||
import svelte from 'rollup-plugin-svelte'; | ||
|
||
const mode = process.env.NODE_ENV; | ||
const dev = mode === 'development'; | ||
|
||
const config = require('../../../config/rollup.js'); | ||
|
||
export default { | ||
client: { | ||
input: config.client.input(), | ||
output: config.client.output(), | ||
plugins: [ | ||
replace({ | ||
'process.browser': true, | ||
'process.env.NODE_ENV': JSON.stringify(mode) | ||
}), | ||
svelte({ | ||
dev, | ||
hydratable: true, | ||
emitCss: true | ||
}), | ||
resolve() | ||
] | ||
}, | ||
|
||
server: { | ||
input: config.server.input(), | ||
output: config.server.output(), | ||
plugins: [ | ||
replace({ | ||
'process.browser': false, | ||
'process.env.NODE_ENV': JSON.stringify(mode) | ||
}), | ||
svelte({ | ||
generate: 'ssr', | ||
dev | ||
}), | ||
resolve({ | ||
preferBuiltins: true | ||
}) | ||
], | ||
external: ['helmet', 'sirv', 'polka'] | ||
}, | ||
|
||
serviceworker: { | ||
input: config.serviceworker.input(), | ||
output: config.serviceworker.output(), | ||
plugins: [ | ||
resolve(), | ||
replace({ | ||
'process.browser': true, | ||
'process.env.NODE_ENV': JSON.stringify(mode) | ||
}) | ||
] | ||
} | ||
}; |
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,9 @@ | ||
import * as sapper from '@sapper/app'; | ||
|
||
window.start = () => sapper.start({ | ||
target: document.querySelector('#sapper') | ||
}); | ||
|
||
window.prefetchRoutes = () => sapper.prefetchRoutes(); | ||
window.prefetch = href => sapper.prefetch(href); | ||
window.goto = href => sapper.goto(href); |
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,8 @@ | ||
<script> | ||
export let status; | ||
export let error; | ||
</script> | ||
|
||
<h1>{status}</h1> | ||
|
||
<p>{error.message}</p> |
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 @@ | ||
<script> | ||
let test = undefined; | ||
</script> | ||
|
||
<input bind:value={test} type=text> | ||
|
||
<span>{test || '-'}</span> |
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,25 @@ | ||
import helmet from 'helmet'; | ||
import polka from 'polka'; | ||
import * as sapper from '@sapper/server'; | ||
|
||
import { start } from '../../common.js'; | ||
|
||
const app = polka() | ||
.use((req, res, next) => { | ||
res.locals = { nonce: 'rAnd0m123' }; | ||
next(); | ||
}) | ||
.use( | ||
helmet({ | ||
contentSecurityPolicy: { | ||
directives: { | ||
defaultSrc: ["'self'"], | ||
scriptSrc: ["blob: 'self'", (_req, res) => `'nonce-${res.locals.nonce}'`], | ||
connectSrc: ["'self'", 'http://localhost:10000'] | ||
} | ||
} | ||
}), | ||
sapper.middleware() | ||
); | ||
|
||
start(app); |
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,82 @@ | ||
import * as sapper from '@sapper/service-worker'; | ||
|
||
const ASSETS = `cache${sapper.timestamp}`; | ||
|
||
// `shell` is an array of all the files generated by webpack, | ||
// `files` is an array of everything in the `static` directory | ||
const to_cache = sapper.shell.concat(sapper.files); | ||
const cached = new Set(to_cache); | ||
|
||
self.addEventListener('install', event => { | ||
event.waitUntil( | ||
caches | ||
.open(ASSETS) | ||
.then(cache => cache.addAll(to_cache)) | ||
.then(() => { | ||
self.skipWaiting(); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('activate', event => { | ||
event.waitUntil( | ||
caches.keys().then(async keys => { | ||
// delete old caches | ||
for (const key of keys) { | ||
if (key !== ASSETS) await caches.delete(key); | ||
} | ||
|
||
self.clients.claim(); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('fetch', event => { | ||
if (event.request.method !== 'GET') return; | ||
|
||
const url = new URL(event.request.url); | ||
|
||
// don't try to handle e.g. data: URIs | ||
if (!url.protocol.startsWith('http')) return; | ||
|
||
// ignore dev server requests | ||
if (url.hostname === self.location.hostname && url.port !== self.location.port) return; | ||
|
||
// always serve assets and webpack-generated files from cache | ||
if (url.host === self.location.host && cached.has(url.pathname)) { | ||
event.respondWith(caches.match(event.request)); | ||
return; | ||
} | ||
|
||
// for pages, you might want to serve a shell `index.html` file, | ||
// which Sapper has generated for you. It's not right for every | ||
// app, but if it's right for yours then uncomment this section | ||
/* | ||
if (url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) { | ||
event.respondWith(caches.match('/index.html')); | ||
return; | ||
} | ||
*/ | ||
|
||
if (event.request.cache === 'only-if-cached') return; | ||
|
||
// for everything else, try the network first, falling back to | ||
// cache if the user is offline. (If the pages never change, you | ||
// might prefer a cache-first approach to a network-first one.) | ||
event.respondWith( | ||
caches | ||
.open(`offline${sapper.timestamp}`) | ||
.then(async cache => { | ||
try { | ||
const response = await fetch(event.request); | ||
cache.put(event.request, response.clone()); | ||
return response; | ||
} catch (err) { | ||
const response = await cache.match(event.request); | ||
if (response) return response; | ||
|
||
throw err; | ||
} | ||
}) | ||
); | ||
}); |
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,14 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset='utf-8'> | ||
|
||
%sapper.base% | ||
%sapper.styles% | ||
%sapper.head% | ||
</head> | ||
<body> | ||
<div id='sapper'>%sapper.html%</div> | ||
%sapper.scripts% | ||
</body> | ||
</html> |
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,30 @@ | ||
import * as assert from 'assert'; | ||
import { build } from '../../../api'; | ||
import { AppRunner } from '../AppRunner'; | ||
|
||
describe('cspnonce-with-helmet', function() { | ||
this.timeout(10000); | ||
|
||
let r: AppRunner; | ||
|
||
// hooks | ||
before('build app', () => build({ cwd: __dirname })); | ||
before('start runner', async () => { | ||
r = await new AppRunner().start(__dirname); | ||
}); | ||
|
||
after(() => r && r.end()); | ||
|
||
// without the fix in runtime/src/server/middleware/get_page_handler.ts | ||
// this will fail as the script to do the updates will be blocked | ||
it('does not prevent bindings from working', async () => { | ||
await r.load('/'); | ||
await r.sapper.start(); | ||
|
||
assert.equal(await r.text('span'), '-'); | ||
|
||
await r.page.type('input[type="text"]', 'text'); | ||
|
||
assert.equal(await r.text('span'), 'text'); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what was this
try
/catch
trying to detect? I feel like it was to see what browser you were using and can't simply be removedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it was trying to detect "import" support to add the module script, otherwise it added "shimport".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a way to detect ESM/
import
/import()
support without a try-catch, then I'd be all for switching to that. Otherwise, as I indicated below, I don't think we can just do this without it being a breaking change. (And it'd be a breaking change that I don't think could be easily worked around for people that need to support these browsers. They'd be stuck on the old version.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Conduitry Agreed. I'll have a look 👍