Skip to content

Commit

Permalink
fix: 解决升级依赖导致服务异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu committed Jan 18, 2024
1 parent b22cd61 commit fb1c34d
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 15 deletions.
4 changes: 2 additions & 2 deletions web/dashboard/src/components/layout/sidebar/SidebarItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</template>

<script>
import path from "path"
import { resolve } from '@/utils/resolve'
import {isExternal} from "@/utils/validate"
import Item from "./Item"
import AppLink from "./Link"
Expand Down Expand Up @@ -99,7 +99,7 @@ export default {
if (isExternal(this.basePath)) {
return this.basePath
}
return path.resolve(this.basePath, routePath)
return resolve(this.basePath, routePath)
}
}
}
Expand Down
106 changes: 106 additions & 0 deletions web/dashboard/src/utils/resolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
export function normalizeStringPosix(path, allowAboveRoot) {
var res = '';
var lastSegmentLength = 0;
var lastSlash = -1;
var dots = 0;
var code;
for (var i = 0; i <= path.length; ++i) {
if (i < path.length)
code = path.charCodeAt(i);
else if (code === 47 /*/*/)
break;
else
code = 47 /*/*/;
if (code === 47 /*/*/) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (lastSlash !== i - 1 && dots === 2) {
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
if (res.length > 2) {
var lastSlashIndex = res.lastIndexOf('/');
if (lastSlashIndex !== res.length - 1) {
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
}
lastSlash = i;
dots = 0;
continue;
}
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSegmentLength = 0;
lastSlash = i;
dots = 0;
continue;
}
}
if (allowAboveRoot) {
if (res.length > 0)
res += '/..';
else
res = '..';
lastSegmentLength = 2;
}
} else {
if (res.length > 0)
res += '/' + path.slice(lastSlash + 1, i);
else
res = path.slice(lastSlash + 1, i);
lastSegmentLength = i - lastSlash - 1;
}
lastSlash = i;
dots = 0;
} else if (code === 46 /*.*/ && dots !== -1) {
++dots;
} else {
dots = -1;
}
}
return res;
}

export function resolve() {
var resolvedPath = '';
var resolvedAbsolute = false;
var cwd;

for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path;
if (i >= 0)
path = arguments[i];
else {
if (cwd === undefined)
// cwd = process.cwd();
path = '';
}

// Skip empty entries
if (path.length === 0) {
continue;
}

resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
}

// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)

// Normalize the path
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);

if (resolvedAbsolute) {
if (resolvedPath.length > 0)
return '/' + resolvedPath;
else
return '/';
} else if (resolvedPath.length > 0) {
return resolvedPath;
} else {
return '.';
}
}
9 changes: 9 additions & 0 deletions web/dashboard/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ module.exports = {
}
},
configureWebpack: {
performance: {
hints: false,
},
optimization: {
minimize: true,
splitChunks: {
chunks: 'all',
}
},
devtool: 'source-map',
resolve: {
alias: {
Expand Down
4 changes: 2 additions & 2 deletions web/kubepi/src/components/layout/sidebar/SidebarItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
</template>

<script>
import path from 'path'
import {isExternal} from '@/utils/validate'
import { resolve } from '@/utils/resolve'
import Item from './Item'
import AppLink from './Link'
import FixOSBug from './FixiOSBug'
Expand Down Expand Up @@ -89,7 +89,7 @@ export default {
if (isExternal(this.basePath)) {
return this.basePath
}
return path.resolve(this.basePath, routePath)
return resolve(this.basePath, routePath)
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions web/kubepi/src/components/layout/sidebar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ export default {
line-height: $menu-height;
}
.el-submenu__title {
//padding-left: 20px !important;
}
.submenu-title-no-dropdown, .el-submenu__title {
max-width: 60px;
text-align: center;
Expand Down
106 changes: 106 additions & 0 deletions web/kubepi/src/utils/resolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
export function normalizeStringPosix(path, allowAboveRoot) {
var res = '';
var lastSegmentLength = 0;
var lastSlash = -1;
var dots = 0;
var code;
for (var i = 0; i <= path.length; ++i) {
if (i < path.length)
code = path.charCodeAt(i);
else if (code === 47 /*/*/)
break;
else
code = 47 /*/*/;
if (code === 47 /*/*/) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (lastSlash !== i - 1 && dots === 2) {
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) {
if (res.length > 2) {
var lastSlashIndex = res.lastIndexOf('/');
if (lastSlashIndex !== res.length - 1) {
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
}
lastSlash = i;
dots = 0;
continue;
}
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSegmentLength = 0;
lastSlash = i;
dots = 0;
continue;
}
}
if (allowAboveRoot) {
if (res.length > 0)
res += '/..';
else
res = '..';
lastSegmentLength = 2;
}
} else {
if (res.length > 0)
res += '/' + path.slice(lastSlash + 1, i);
else
res = path.slice(lastSlash + 1, i);
lastSegmentLength = i - lastSlash - 1;
}
lastSlash = i;
dots = 0;
} else if (code === 46 /*.*/ && dots !== -1) {
++dots;
} else {
dots = -1;
}
}
return res;
}

export function resolve() {
var resolvedPath = '';
var resolvedAbsolute = false;
var cwd;

for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
var path;
if (i >= 0)
path = arguments[i];
else {
if (cwd === undefined)
// cwd = process.cwd();
path = '';
}

// Skip empty entries
if (path.length === 0) {
continue;
}

resolvedPath = path + '/' + resolvedPath;
resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
}

// At this point the path should be resolved to a full absolute path, but
// handle relative paths to be safe (might happen when process.cwd() fails)

// Normalize the path
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);

if (resolvedAbsolute) {
if (resolvedPath.length > 0)
return '/' + resolvedPath;
else
return '/';
} else if (resolvedPath.length > 0) {
return resolvedPath;
} else {
return '.';
}
}
9 changes: 9 additions & 0 deletions web/kubepi/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ module.exports = {
}
},
configureWebpack: {
performance: {
hints: false,
},
optimization: {
minimize: true,
splitChunks: {
chunks: 'all',
}
},
devtool: 'source-map',
resolve: {
alias: {
Expand Down
1 change: 1 addition & 0 deletions web/terminal/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"baseHref": "/kubepi/terminal/",
"outputPath": "../../cmd/server/web/terminal",
"index": "src/index.html",
"main": "src/main.ts",
Expand Down
12 changes: 6 additions & 6 deletions web/terminal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.config.json",
"build": "ng build --prod --aot",
"build": "ng build --configuration production --aot",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
Expand Down

0 comments on commit fb1c34d

Please sign in to comment.