1
0
mirror of synced 2025-11-06 04:21:11 +08:00

chore: remove axios and js-beautify

This commit is contained in:
surunzi
2022-11-26 21:04:14 +08:00
parent b02ffee679
commit a989125857
8 changed files with 28 additions and 54 deletions

View File

@@ -41,6 +41,11 @@ module.exports = {
resolve: {
symlinks: false,
},
resolve: {
alias: {
axios: path.resolve(__dirname, '../src/lib/empty.js'),
},
},
devServer: {
static: {
directory: path.join(__dirname, '../test'),

View File

@@ -59,7 +59,6 @@
"jasmine-core": "^2.99.1",
"jasmine-jquery": "^2.1.1",
"jquery": "^3.4.1",
"js-beautify": "^1.10.3",
"karma": "^6.4.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.1",

View File

@@ -11,6 +11,7 @@ import {
lowerCase,
isNull,
} from '../lib/util'
import extend from 'licia/extend'
import evalCss from '../lib/evalCss'
import emitter from '../lib/emitter'
import Settings from '../Settings/Settings'
@@ -139,7 +140,7 @@ export default class Console extends Tool {
const _$input = _$inputContainer.find('textarea')
const _$inputBtns = _$inputContainer.find('.eruda-buttons')
Object.assign(this, {
extend(this, {
_$control: $el.find('.eruda-control'),
_$logs: $el.find('.eruda-logs-container'),
_$inputContainer,

View File

@@ -1,5 +1,4 @@
import Tool from '../DevTools/Tool'
import beautify from 'js-beautify'
import LunaObjectViewer from 'luna-object-viewer'
import Settings from '../Settings/Settings'
import { ajax, escape, trim, isStr, highlight } from '../lib/util'
@@ -13,8 +12,6 @@ export default class Sources extends Tool {
this.name = 'sources'
this._showLineNum = true
this._formatCode = true
this._indentSize = 4
this._loadTpl()
}
@@ -121,34 +118,20 @@ export default class Sources extends Tool {
if (!settings) return
settings
.remove(cfg, 'showLineNum')
.remove(cfg, 'formatCode')
.remove(cfg, 'indentSize')
.remove('Sources')
settings.remove(cfg, 'showLineNum').remove('Sources')
}
_initCfg() {
const cfg = (this.config = Settings.createCfg('sources', {
showLineNum: true,
formatCode: true,
indentSize: 4,
}))
if (!cfg.get('showLineNum')) this._showLineNum = false
if (!cfg.get('formatCode')) this._formatCode = false
this._indentSize = cfg.get('indentSize')
cfg.on('change', (key, val) => {
switch (key) {
case 'showLineNum':
this._showLineNum = val
return
case 'formatCode':
this._formatCode = val
return
case 'indentSize':
this._indentSize = +val
return
}
})
@@ -156,8 +139,6 @@ export default class Sources extends Tool {
settings
.text('Sources')
.switch(cfg, 'showLineNum', 'Show Line Numbers')
.switch(cfg, 'formatCode', 'Beautify Code')
.select(cfg, 'indentSize', 'Indent Size', ['2', '4'])
.separator()
}
_render() {
@@ -185,25 +166,12 @@ export default class Sources extends Tool {
}
_renderCode() {
const data = this._data
const indent_size = this._indentSize
let code = data.val
const len = data.val.length
// If source code too big, don't process it.
if (len < MAX_BEAUTIFY_LEN && this._formatCode) {
switch (data.type) {
case 'html':
code = beautify.html(code, { unformatted: [], indent_size })
break
case 'css':
code = beautify.css(code, { indent_size })
break
case 'js':
code = beautify(code, { indent_size })
break
}
if (len < MAX_BEAUTIFY_LEN) {
const curTheme = evalCss.getCurTheme()
code = highlight(code, data.type, {
keyword: `color:${curTheme.keywordColor}`,

View File

@@ -25,6 +25,7 @@ import {
upperFirst,
nextTick
} from './lib/util'
import extend from 'licia/extend'
import evalCss from './lib/evalCss'
import chobitsu from './lib/chobitsu'
@@ -174,7 +175,7 @@ export default {
}
}
Object.assign(el, {
extend(el, {
id: 'eruda',
className: 'eruda-container',
contentEditable: false

1
src/lib/empty.js Normal file
View File

@@ -0,0 +1 @@
export default {}

View File

@@ -1,9 +1,8 @@
import beautify from 'js-beautify'
import evalCss from './evalCss'
import extend from 'licia/extend'
export default function (util) {
Object.assign(util, {
beautify,
extend(util, {
evalCss,
isErudaEl,
})

View File

@@ -62,8 +62,8 @@
)
}
addClickEvent('issue17', function () {
let B = function () {}
let A = function () {
var B = function () {}
var A = function () {
this._data = 'eruda'
}
A.prototype = Object.create(B.prototype)
@@ -72,7 +72,7 @@
return this._data
},
})
let a = new A()
var a = new A()
console.log(a)
})
addClickEvent('plugin', function () {
@@ -86,7 +86,7 @@
},
}
})
let Tool = eruda.Tool
var Tool = eruda.Tool
eruda.add(
new (Tool.extend({
name: 'test3',
@@ -101,7 +101,7 @@
new Promise(function (resolve, reject) {
resolve()
}).then(function (res) {
let a = res.a
var a = res.a
})
})
addClickEvent('issue31', function () {
@@ -114,8 +114,8 @@
triggerError()
})
addClickEvent('big-array', function () {
let arr = []
for (let i = 0; i < 10000; i++) {
var arr = []
for (var i = 0; i < 10000; i++) {
arr.push(i)
}
console.log(arr)
@@ -123,10 +123,10 @@
addClickEvent('override-style', function () {
util.evalCss('.eruda-nav-bar {background: red !important;}')
})
addClickEvent('log', () => {
addClickEvent('log', function () {
console.clear()
console.log('log')
for (let i = 0; i < 10; i++) {
for (var i = 0; i < 10; i++) {
console.log('repeat log')
}
console.warn('warn')
@@ -142,7 +142,7 @@
var site2 = { name: 'Google', site: 'www.google.com' }
var site3 = { name: 'Taobao', site: 'www.taobao.com' }
console.table([site1, site2, site3], ['site'])
const el = util.toEl(
var el = util.toEl(
'<div class="test"><div class="test-inner"></div></div>'
)
console.log('test dom', el)
@@ -168,13 +168,13 @@
for (var i = 0; i < 10000; i++) arr.push(i)
console.log(arr)
})
addClickEvent('log-10000', () => {
for (let i = 0; i < 10000; i++) {
addClickEvent('log-10000', function () {
for (var i = 0; i < 10000; i++) {
console.log(location, i)
}
})
addClickEvent('log-1000', () => {
for (let i = 0; i < 1000; i++) {
addClickEvent('log-1000', function () {
for (var i = 0; i < 1000; i++) {
console.log(location, i)
}
})