Skip to content

Commit

Permalink
Add new "pr" query parameter (#224)
Browse files Browse the repository at this point in the history
* Update dependencies

* Fix service worker asset caching

* Handle pr= queries

* Add better error message

* Add better error message
  • Loading branch information
lukastaegert committed Apr 14, 2021
1 parent 3b6f69f commit 4f8ff65
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 336 deletions.
616 changes: 310 additions & 306 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions package.json
Expand Up @@ -3,26 +3,26 @@
"author": "Rich Harris",
"version": "1.0.0",
"devDependencies": {
"@babel/core": "^7.13.1",
"@babel/core": "^7.13.15",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.13.7",
"@babel/preset-env": "^7.13.5",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^18.0.0-1",
"@rollup/plugin-node-resolve": "^11.2.0",
"@rollup/plugin-replace": "^2.4.1",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-replace": "^2.4.2",
"@rollup/plugin-url": "^6.0.0",
"husky": "^5.1.1",
"husky": "^6.0.0",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"prettier-plugin-svelte": "^2.1.6",
"rollup": "^2.39.1",
"prettier-plugin-svelte": "^2.2.0",
"rollup": "^2.45.2",
"rollup-plugin-svelte": "^7.1.0",
"rollup-plugin-terser": "^7.0.2",
"sapper": "^0.29.1",
"shx": "^0.3.3",
"sirv-cli": "^1.0.11",
"svelte": "^3.34.0"
"svelte": "^3.37.0"
},
"scripts": {
"dev": "sapper dev",
Expand All @@ -40,11 +40,11 @@
"postinstall": "husky install"
},
"dependencies": {
"@babel/runtime": "^7.13.7",
"codemirror": "^5.59.4",
"@babel/runtime": "^7.13.10",
"codemirror": "^5.60.0",
"compression": "^1.7.4",
"highlight.js": "^10.6.0",
"marked": "^2.0.0",
"highlight.js": "^10.7.2",
"marked": "^2.0.3",
"polka": "^0.5.2",
"sirv": "^1.0.11"
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/createGuide.js
Expand Up @@ -40,7 +40,7 @@ function create_guide(lang) {

content = content.replace(/```([\w-]+)?\n([\s\S]+?)```/g, (match, lang, code) => {
// TODO add bash everywhere and change default to text
const { value } = hljs.highlight(lang || 'bash', code);
const { value } = hljs.highlight(code, { language: lang || 'bash' });
highlighted[++uid] = value;

return `@@${uid}`;
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/query.js
Expand Up @@ -45,6 +45,8 @@ export async function updateStoresFromQuery(query, hasModules) {

if (query.circleci) {
rollupRequest.requestCircleCI(query.circleci);
} else if (query.pr) {
rollupRequest.requestPr(query.pr);
} else {
rollupRequest.requestVersion(query.version);
}
Expand All @@ -55,6 +57,8 @@ export function updateQuery($modules, $options, $selectedExample, $rollupRequest
const params = {};
if ($rollupRequest.type === 'circleci') {
params.circleci = $rollupRequest.version;
} else if ($rollupRequest.type === 'pr') {
params.pr = $rollupRequest.version;
} else {
const version = $rollupRequest.version || rollupVersion;
if (version) {
Expand Down
14 changes: 2 additions & 12 deletions src/service-worker.js
Expand Up @@ -44,21 +44,11 @@ self.addEventListener('fetch', event => {
if (url.hostname === self.location.hostname && url.port !== self.location.port) return;

// always serve static files and bundler-generated assets from cache
if (url.host === self.location.host && cached.has(url.pathname.slice(1))) {
event.respondWith(caches.match(url.pathname.slice(1)));
if (url.host === self.location.host && cached.has(url.pathname)) {
event.respondWith(caches.match(url.pathname));
return;
}

// for pages, you might want to serve a shell `service-worker-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('/service-worker-index.html'));
return;
}
*/

if (event.request.cache === 'only-if-cached') return;

// for everything else, try the network first, falling back to
Expand Down
11 changes: 10 additions & 1 deletion src/stores/rollup.js
Expand Up @@ -14,6 +14,8 @@ async function getRollupUrl({ type, version }) {
throw new Error('Invalid CircleCI build number.');
}
return artifact.url;
} else if (type === 'pr') {
return `https://rollup-ci-artefacts.s3.amazonaws.com/${version}/rollup.browser.js`;
} else {
return version
? `https://unpkg.com/rollup@${version}/dist/rollup.browser.js`
Expand All @@ -29,7 +31,14 @@ async function loadRollup($rollupRequest) {
script.onload = () => {
fulfil(window.rollup);
};
script.onerror = () => reject(new Error(`Could not load Rollup from ${url}`));
script.onerror = () =>
reject(
new Error(
$rollupRequest.type === 'pr'
? `Could not load Rollup from PR #${$rollupRequest.version}.`
: `Could not load Rollup from ${url}.`
)
);
document.querySelector('head').appendChild(script);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/rollupOutput.js
Expand Up @@ -82,7 +82,7 @@ async function bundle({
resolved += '.js';
if (resolved in moduleById) return resolved;

throw new Error(`Could not resolve '${importee}' from '${importer}'`);
throw new Error(`Could not resolve '${importee}' from '${importer}'.`);
},
load: function (id) {
return moduleById[id].code;
Expand Down
3 changes: 2 additions & 1 deletion src/stores/rollupRequest.js
Expand Up @@ -5,5 +5,6 @@ const { subscribe, set } = writable({ version: null, type: null });
export default {
subscribe,
requestVersion: version => set({ version, type: 'version' }),
requestCircleCI: version => set({ version, type: 'circleci' })
requestCircleCI: version => set({ version, type: 'circleci' }),
requestPr: version => set({ version, type: 'pr' })
};

0 comments on commit 4f8ff65

Please sign in to comment.