Skip to content

Commit

Permalink
refactor: minor refactor
Browse files Browse the repository at this point in the history
Minor refactor
  • Loading branch information
Masquerade-Circus committed May 6, 2022
1 parent 57ef0d1 commit 38e21ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 1 addition & 3 deletions plugins/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function inline(file, options = {}) {
...(options.esbuild || {})
};

let result = esbuild.buildSync(esbuildOptions);
let result = await esbuild.build(esbuildOptions);

if (options.compact) {
let result2 = await terser.minify(result.outputFiles[1].text, {
Expand Down Expand Up @@ -192,8 +192,6 @@ function icons(source, configuration = {}) {
let { default: favicons } = require("favicons"),
options = Object.assign({}, icons.options, configuration);

console.log(favicons);

if (options.iconsPath) {
options.iconsPath = options.iconsPath.replace(/\/$/gi, "") + "/";
}
Expand Down
24 changes: 21 additions & 3 deletions plugins/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,22 @@ function Request(baseUrl = "", options = {}) {
}

let response = await fetch(parseUrl(url, opts), innerOptions);

let body = null;
if (!response.ok) {
let err = new Error(response.statusText);
err.response = response;
if (/text/gi.test(acceptType)) {
err.body = await response.text();
}

if (/json/gi.test(acceptType)) {
try {
err.body = await response.json();
} catch (error) {
// ignore
}
}

throw err;
}

Expand All @@ -105,11 +117,17 @@ function Request(baseUrl = "", options = {}) {
}

if (/text/gi.test(acceptType)) {
return response.text();
body = await response.text();
return body;
}

if (/json/gi.test(acceptType)) {
return response.json();
try {
body = await response.json();
return body;
} catch (error) {
// ignore
}
}

return response;
Expand Down
3 changes: 2 additions & 1 deletion plugins/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class Router {
window.history.pushState(null, null, path);
}

if (v.current.component === component) {
if (v.isMounted && v.component.component === component) {
return v.update();
}

Expand All @@ -222,6 +222,7 @@ function plugin(vInstance) {

routerOrComponent.container = elementContainer;
routerOrComponent.v = v;
v.redirect = routerOrComponent.go.bind(routerOrComponent);

// Activate the use of the router
if (!v.isNodeJs) {
Expand Down

0 comments on commit 38e21ce

Please sign in to comment.