diff --git a/.eslintignore b/.eslintignore index 31866eb30a..97eca0cd05 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,5 +3,4 @@ typings/ dist/ dev/ node_modules/ -*.config.* .eslintrc.* diff --git a/dev-tools/dev-server/config.ts b/dev-tools/dev-server/config.ts index 26c1be6465..583054b19a 100644 --- a/dev-tools/dev-server/config.ts +++ b/dev-tools/dev-server/config.ts @@ -4,11 +4,8 @@ interface DevServerConfig { port?: number maxWatchers?: number } -const configFile = (path: string) => () => ( - existsSync(path) - ? JSON.parse(readFileSync(path, { encoding: 'utf-8' })) - : {} -) +const configFile = (path: string) => () => + existsSync(path) ? JSON.parse(readFileSync(path, { encoding: 'utf-8' })) : {} const configSource: (() => DevServerConfig)[] = [ () => ({ port: 23333, @@ -16,6 +13,7 @@ const configSource: (() => DevServerConfig)[] = [ }), configFile('dev/dev-server.json'), ] -export const devServerConfig = configSource.reduce((previous, current) => ( - { ...previous, ...current() } -), {} as DevServerConfig) +export const devServerConfig = configSource.reduce( + (previous, current) => ({ ...previous, ...current() }), + {} as DevServerConfig, +) diff --git a/dev-tools/dev-server/core-watcher.ts b/dev-tools/dev-server/core-watcher.ts index 6d39f253a2..4030b36e34 100644 --- a/dev-tools/dev-server/core-watcher.ts +++ b/dev-tools/dev-server/core-watcher.ts @@ -4,20 +4,26 @@ import webpackConfig from '../../webpack/webpack.dev' import { sendMessage } from './web-socket-server' import { defaultWatcherHandler } from './watcher-common' -export const startCoreWatcher = () => new Promise(resolve => { - const compiler = webpack(webpackConfig as webpack.Configuration) - console.log('本体编译中...') - const instance = compiler.watch({}, defaultWatcherHandler( - () => resolve(), - result => { - console.log('本体已编译:', result.hash) - sendMessage({ - type: 'coreUpdate', - }) - }, - )) - exitHook(exit => instance.close(() => { - console.log('本体编译器已退出') - exit() - })) -}) +export const startCoreWatcher = () => + new Promise(resolve => { + const compiler = webpack(webpackConfig as webpack.Configuration) + console.log('本体编译中...') + const instance = compiler.watch( + {}, + defaultWatcherHandler( + () => resolve(), + result => { + console.log('本体已编译:', result.hash) + sendMessage({ + type: 'coreUpdate', + }) + }, + ), + ) + exitHook(exit => + instance.close(() => { + console.log('本体编译器已退出') + exit() + }), + ) + }) diff --git a/dev-tools/dev-server/payload.ts b/dev-tools/dev-server/payload.ts index d6dba7b7fe..c00372a987 100644 --- a/dev-tools/dev-server/payload.ts +++ b/dev-tools/dev-server/payload.ts @@ -18,14 +18,13 @@ export type QuerySessionsResponsePayload = PayloadBase<'querySessionsResponse'> } export type StopPayload = PayloadBase<'stop'> -export type Payload = ( - StartPayload | - CoreUpdatePayload | - ItemUpdatePayload | - StopPayload | - ItemStopPayload | - QuerySessionsPayload | - QuerySessionsResponsePayload -) +export type Payload = + | StartPayload + | CoreUpdatePayload + | ItemUpdatePayload + | StopPayload + | ItemStopPayload + | QuerySessionsPayload + | QuerySessionsResponsePayload export type MessageHandler

= (payload: P) => void diff --git a/dev-tools/dev-server/registry-watcher.ts b/dev-tools/dev-server/registry-watcher.ts index 1a1e3fba42..45d5e5ca16 100644 --- a/dev-tools/dev-server/registry-watcher.ts +++ b/dev-tools/dev-server/registry-watcher.ts @@ -34,24 +34,27 @@ export const stopInstance = (instance: Watching, onClose: () => void) => { } } -export const startRegistryWatcher = (url: string, config: Configuration) => new Promise( - resolve => { +export const startRegistryWatcher = (url: string, config: Configuration) => + new Promise(resolve => { console.log(`功能编译中... ${url}`) const { maxWatchers } = devServerConfig const watcher = webpack(config) - const instance = watcher.watch({}, defaultWatcherHandler( - () => { - resolve() - }, - result => { - console.log('功能已编译:', result.hash, url) - sendMessage({ - type: 'itemUpdate', - path: url, - sessions: watchers.map(it => it.url), - }) - }, - )) + const instance = watcher.watch( + {}, + defaultWatcherHandler( + () => { + resolve() + }, + result => { + console.log('功能已编译:', result.hash, url) + sendMessage({ + type: 'itemUpdate', + path: url, + sessions: watchers.map(it => it.url), + }) + }, + ), + ) exitHook(exit => { if (!instance.closed) { instance.close(() => { @@ -63,9 +66,10 @@ export const startRegistryWatcher = (url: string, config: Configuration) => new if (watchers.length >= maxWatchers) { const oldInstance = watchers.shift() stopInstance(oldInstance.instance, () => { - console.log(`已达到 maxWatchers 数量 (${maxWatchers}), 退出了功能编译器: ${oldInstance.url}`) + console.log( + `已达到 maxWatchers 数量 (${maxWatchers}), 退出了功能编译器: ${oldInstance.url}`, + ) }) } watchers.push({ url, instance }) - }, -) + }) diff --git a/dev-tools/dev-server/server.ts b/dev-tools/dev-server/server.ts index a67144715f..62aab7d711 100644 --- a/dev-tools/dev-server/server.ts +++ b/dev-tools/dev-server/server.ts @@ -7,57 +7,54 @@ import { buildByEntry } from '../../registry/webpack/config' import { exitWebSocketServer } from './web-socket-server' import { watchers, parseRegistryUrl, startRegistryWatcher } from './registry-watcher' -export const startDevServer = () => new Promise(resolve => { - const { port } = devServerConfig +export const startDevServer = () => + new Promise(resolve => { + const { port } = devServerConfig - const server = createServer((request, response) => { - const { url } = request - console.log('请求:', url) - const callHandler = () => { - handler(request, response, { - public: '.', - directoryListing: [ - '/dist', - '/dist/**', - '/registry/dist', - '/registry/dist/**', - ], - }) - } - if (url.startsWith('/registry')) { - const existingWatcher = watchers.find(w => w.url === url) - const registryInfo = parseRegistryUrl(url) - if (existingWatcher && registryInfo) { - console.log(`已复用功能编译器: ${url}`) + const server = createServer((request, response) => { + const { url } = request + console.log('请求:', url) + const callHandler = () => { + handler(request, response, { + public: '.', + directoryListing: ['/dist', '/dist/**', '/registry/dist', '/registry/dist/**'], + }) } - if (existingWatcher || !registryInfo) { - callHandler() + if (url.startsWith('/registry')) { + const existingWatcher = watchers.find(w => w.url === url) + const registryInfo = parseRegistryUrl(url) + if (existingWatcher && registryInfo) { + console.log(`已复用功能编译器: ${url}`) + } + if (existingWatcher || !registryInfo) { + callHandler() + } else { + startRegistryWatcher( + url, + buildByEntry({ + ...registryInfo, + mode: 'development', + }) as Configuration, + ).then(() => callHandler()) + } } else { - startRegistryWatcher(url, buildByEntry({ - ...registryInfo, - mode: 'development', - }) as Configuration).then( - () => callHandler(), - ) + callHandler() } - } else { - callHandler() - } - }) - exitHook(exit => { - exitWebSocketServer() - server.close(error => { - if (error) { - console.error(error) + }) + exitHook(exit => { + exitWebSocketServer() + server.close(error => { + if (error) { + console.error(error) + exit() + return + } + console.log('DevServer 已退出') exit() - return - } - console.log('DevServer 已退出') - exit() + }) + }) + server.listen(port, () => { + console.log(`DevServer 已启动, 端口: ${port}`) + resolve(server) }) }) - server.listen(port, () => { - console.log(`DevServer 已启动, 端口: ${port}`) - resolve(server) - }) -}) diff --git a/dev-tools/dev-server/watcher-common.ts b/dev-tools/dev-server/watcher-common.ts index e94cfb0e7f..7de70d68af 100644 --- a/dev-tools/dev-server/watcher-common.ts +++ b/dev-tools/dev-server/watcher-common.ts @@ -15,13 +15,15 @@ export const defaultWatcherHandler = ( } const needLogging = result.hasErrors() || result.hasWarnings() if (needLogging) { - console.log(result.toString({ - hash: false, - assets: false, - modules: false, - chunks: false, - color: true, - })) + console.log( + result.toString({ + hash: false, + assets: false, + modules: false, + chunks: false, + color: true, + }), + ) } if (result.hasErrors()) { lastHash = '' diff --git a/dev-tools/dev-server/web-socket-server.ts b/dev-tools/dev-server/web-socket-server.ts index ae6b1594ae..ef94e585df 100644 --- a/dev-tools/dev-server/web-socket-server.ts +++ b/dev-tools/dev-server/web-socket-server.ts @@ -22,45 +22,48 @@ export const exitWebSocketServer = () => { sendMessage({ type: 'stop' }) server.clients.forEach(c => c.close()) } -export const startWebSocketServer = (httpServer: Server) => new Promise(resolve => { - server = new WebSocketServer({ server: httpServer }) - server.on('connection', client => { - sendMessage({ type: 'start', sessions: watchers.map(it => it.url) }) - client.on('message', data => { - try { - const payload: Payload = JSON.parse(data.toString()) - console.log('收到 DevClient 消息:', payload) - switch (payload.type) { - default: { - break - } - case 'itemStop': { - const { path } = payload - const watcherIndex = watchers.findIndex(it => it.url === path) - if (watcherIndex !== -1) { - const [watcher] = watchers.splice(watcherIndex, 1) - stopInstance(watcher.instance, () => { - console.log(`功能编译器已退出: ${watcher.url}`) - }) +export const startWebSocketServer = (httpServer: Server) => + new Promise(resolve => { + server = new WebSocketServer({ server: httpServer }) + server.on('connection', client => { + sendMessage({ type: 'start', sessions: watchers.map(it => it.url) }) + client.on('message', data => { + try { + const payload: Payload = JSON.parse(data.toString()) + console.log('收到 DevClient 消息:', payload) + switch (payload.type) { + default: { + break + } + case 'itemStop': { + const { path } = payload + const watcherIndex = watchers.findIndex(it => it.url === path) + if (watcherIndex !== -1) { + const [watcher] = watchers.splice(watcherIndex, 1) + stopInstance(watcher.instance, () => { + console.log(`功能编译器已退出: ${watcher.url}`) + }) + } + break + } + case 'querySessions': { + sendMessage({ type: 'querySessionsResponse', sessions: watchers.map(it => it.url) }) + break } - break - } - case 'querySessions': { - sendMessage({ type: 'querySessionsResponse', sessions: watchers.map(it => it.url) }) - break } + } catch (error) { + console.error('无效信息', data) } - } catch (error) { - console.error('无效信息', data) - } + }) }) + server.on('error', error => console.error(error)) + exitHook(exit => + server.close(error => { + if (error) { + console.error(error) + } + exit() + }), + ) + resolve() }) - server.on('error', error => console.error(error)) - exitHook(exit => server.close(error => { - if (error) { - console.error(error) - } - exit() - })) - resolve() -}) diff --git a/dev-tools/donate-table/index.ts b/dev-tools/donate-table/index.ts index 288fbd518d..e8d9ee04cd 100644 --- a/dev-tools/donate-table/index.ts +++ b/dev-tools/donate-table/index.ts @@ -11,44 +11,53 @@ const parseAliPay = (csv: Record[]) => { name += `${item.商品名称} ` } name += `${item.对方名称} ${item.付款备注}` - return `| ${item.创建时间.replace(/-/g, '.')} | ${name} | ${item.支付宝交易号.substring(item.支付宝交易号.length - 4)} | ¥${item['订单金额(元)']} |` + return `| ${item.创建时间.replace(/-/g, '.')} | ${name} | ${item.支付宝交易号.substring( + item.支付宝交易号.length - 4, + )} | ¥${item['订单金额(元)']} |` } }) return csv } const parseWeChat = (csv: Record[]) => { - const items = csv.filter(item => item.交易类型 === '赞赏码').map(item => ({ - ...item, - sortKey: Number(new Date(item.交易时间)).toString(), - toString: () => { - let name = item.交易对方 - if (name === '/') { - name = '匿名' - } - const noteMatch = item.商品.match(/付款方留言:(.+)/) - if (noteMatch) { - name += ` ${noteMatch[1]}` - } - if (item.备注.trim() !== '/') { - name += ` ${item.备注}` - } - item.交易单号 = item.交易单号.trim() - console.log(item, item.交易时间) - return `| ${item.交易时间.replace(/-/g, '.')} | ${name} | ${item.交易单号.substring(item.交易单号.length - 4)} | ${item['金额(元)']} |` - }, - })) + const items = csv + .filter(item => item.交易类型 === '赞赏码') + .map(item => ({ + ...item, + sortKey: Number(new Date(item.交易时间)).toString(), + toString: () => { + let name = item.交易对方 + if (name === '/') { + name = '匿名' + } + const noteMatch = item.商品.match(/付款方留言:(.+)/) + if (noteMatch) { + name += ` ${noteMatch[1]}` + } + if (item.备注.trim() !== '/') { + name += ` ${item.备注}` + } + item.交易单号 = item.交易单号.trim() + console.log(item, item.交易时间) + return `| ${item.交易时间.replace(/-/g, '.')} | ${name} | ${item.交易单号.substring( + item.交易单号.length - 4, + )} | ${item['金额(元)']} |` + }, + })) return items } -const items = files.map(file => { - const text = fs.readFileSync(file, { encoding: 'utf-8' }) - const csv = parse(text, { columns: true }) - if (file.includes('支付宝')) { - return parseAliPay(csv) - } - if (file.includes('微信')) { - return parseWeChat(csv) - } - console.warn(`not parse method for ${file}`) - return [] -}).flat().sort((a, b) => parseInt(b.sortKey) - parseInt(a.sortKey)) +const items = files + .map(file => { + const text = fs.readFileSync(file, { encoding: 'utf-8' }) + const csv = parse(text, { columns: true }) + if (file.includes('支付宝')) { + return parseAliPay(csv) + } + if (file.includes('微信')) { + return parseWeChat(csv) + } + console.warn(`not parse method for ${file}`) + return [] + }) + .flat() + .sort((a, b) => parseInt(b.sortKey) - parseInt(a.sortKey)) fs.outputFileSync('dist/output.md', items.join('\n')) diff --git a/registry/webpack/config.ts b/registry/webpack/config.ts index 5fa1faa26d..d52ffb117b 100644 --- a/registry/webpack/config.ts +++ b/registry/webpack/config.ts @@ -4,9 +4,12 @@ import { Configuration } from 'webpack' import { getDefaultConfig } from '../../webpack/webpack.config' import { getId } from '../lib/id' -export const buildByEntry = ( - params: { src: string; type: string; entry: string, mode?: Configuration['mode'] }, -) => { +export const buildByEntry = (params: { + src: string + type: string + entry: string + mode?: Configuration['mode'] +}) => { // const match = entry.match(/\/?registry\/dist\/([^\/]+)\/(.+)\/index\.ts/) // if (!match) { // throw new Error(`Invalid entry path: ${entry}`) @@ -36,12 +39,14 @@ export const buildByEntry = ( const regexMatch = (regex: RegExp, base: string[]) => { const match = request.match(regex) if (match) { - const subModules = match[1] ? match[1].split('/').map(name => { - if (name.match(/\.vue$/)) { - return name.replace(/\.vue$/, '') - } - return lodash.camelCase(name) - }) : [] + const subModules = match[1] + ? match[1].split('/').map(name => { + if (name.match(/\.vue$/)) { + return name.replace(/\.vue$/, '') + } + return lodash.camelCase(name) + }) + : [] return () => (callback as any)(null, ['coreApis', ...base, ...subModules], 'root') } return null diff --git a/webpack/cdn/github.ts b/webpack/cdn/github.ts index 10a0e468c4..af106948e3 100644 --- a/webpack/cdn/github.ts +++ b/webpack/cdn/github.ts @@ -17,5 +17,6 @@ export const github: CdnConfig = { }, smallLogo: `https://${host}/${owner}/Bilibili-Evolved/preview/images/logo-small.png`, logo: `https://${host}/${owner}/Bilibili-Evolved/preview/images/logo.png`, - root: (branch, ownerOverride) => `https://${host}/${ownerOverride || owner}/Bilibili-Evolved/${branch}/`, + root: (branch, ownerOverride) => + `https://${host}/${ownerOverride || owner}/Bilibili-Evolved/${branch}/`, } diff --git a/webpack/cdn/jsdelivr.ts b/webpack/cdn/jsdelivr.ts index b4cfcff29a..e412ffdf3a 100644 --- a/webpack/cdn/jsdelivr.ts +++ b/webpack/cdn/jsdelivr.ts @@ -17,5 +17,6 @@ export const jsDelivr: CdnConfig = { }, smallLogo: `https://${host}/gh/${owner}/Bilibili-Evolved@preview/images/logo-small.png`, logo: `https://${host}/gh/${owner}/Bilibili-Evolved@preview/images/logo.png`, - root: (branch, ownerOverride) => `https://${host}/gh/${ownerOverride || owner}/Bilibili-Evolved@${branch}/`, + root: (branch, ownerOverride) => + `https://${host}/gh/${ownerOverride || owner}/Bilibili-Evolved@${branch}/`, } diff --git a/webpack/cdn/types.ts b/webpack/cdn/types.ts index e7bfc460f9..dcf21365f9 100644 --- a/webpack/cdn/types.ts +++ b/webpack/cdn/types.ts @@ -10,7 +10,7 @@ export interface CdnConfig { jszip: string sortable: string mdi: string - }, + } smallLogo: string logo: string root: (branch: string, ownerOverride: string) => string diff --git a/webpack/compilation-info/git.ts b/webpack/compilation-info/git.ts index 94a439245e..4eedcd6f33 100644 --- a/webpack/compilation-info/git.ts +++ b/webpack/compilation-info/git.ts @@ -1,18 +1,9 @@ import process from 'child_process' -export const commitHash = process - .execSync('git rev-parse HEAD') - .toString() - .trim() -export const branch = process - .execSync('git rev-parse --abbrev-ref HEAD') - .toString() - .trim() +export const commitHash = process.execSync('git rev-parse HEAD').toString().trim() +export const branch = process.execSync('git rev-parse --abbrev-ref HEAD').toString().trim() export const nearestTag = process .execSync('git describe --abbrev=0 --tags --always') .toString() .trim() -export const versionWithTag = process - .execSync('git describe --tags --always') - .toString() - .trim() +export const versionWithTag = process.execSync('git describe --tags --always').toString().trim() diff --git a/webpack/compilation-info/source-diff.ts b/webpack/compilation-info/source-diff.ts index 0d7a000929..21c61f4084 100644 --- a/webpack/compilation-info/source-diff.ts +++ b/webpack/compilation-info/source-diff.ts @@ -14,11 +14,7 @@ const excludePatterns = [ ] export const isSourceChanged = () => { - const lastDiff = process - .execSync('git diff --name-only HEAD^') - .toString() - .trim() - .split('\n') + const lastDiff = process.execSync('git diff --name-only HEAD^').toString().trim().split('\n') const isAllExcluded = lastDiff.every(path => excludePatterns.some(p => p.test(path))) return !isAllExcluded diff --git a/webpack/inject-metadata/core-info.ts b/webpack/inject-metadata/core-info.ts index c33cad8975..78ae188e2c 100644 --- a/webpack/inject-metadata/core-info.ts +++ b/webpack/inject-metadata/core-info.ts @@ -1,19 +1,9 @@ -import { - objectProperty, - identifier, - stringLiteral, -} from '@babel/types' +import { objectProperty, identifier, stringLiteral } from '@babel/types' import { runtimeInfo } from '../compilation-info/runtime' import { commitHash } from '../compilation-info/git' import { InjectMetadataAction } from './types' export const injectCoreInfo: InjectMetadataAction = () => [ - objectProperty( - identifier('commitHash'), - stringLiteral(commitHash), - ), - objectProperty( - identifier('coreVersion'), - stringLiteral(runtimeInfo.version), - ), + objectProperty(identifier('commitHash'), stringLiteral(commitHash)), + objectProperty(identifier('coreVersion'), stringLiteral(runtimeInfo.version)), ] diff --git a/webpack/inject-metadata/description.ts b/webpack/inject-metadata/description.ts index f787f7b182..438451ad3e 100644 --- a/webpack/inject-metadata/description.ts +++ b/webpack/inject-metadata/description.ts @@ -1,9 +1,6 @@ import { existsSync } from 'fs' import { dirname, join } from 'path' -import { - objectProperty, - identifier, -} from '@babel/types' +import { objectProperty, identifier } from '@babel/types' import { parseExpression } from '@babel/parser' import { InjectMetadataAction } from './types' @@ -29,7 +26,8 @@ export const injectDescription: InjectMetadataAction = ({ filename }) => { return [ objectProperty( identifier('description'), - parseExpression(` + parseExpression( + ` (() => { const context = require.context('./', false, ${regex}) return { @@ -43,7 +41,9 @@ export const injectDescription: InjectMetadataAction = ({ filename }) => { 'zh-CN': () => import('./index.md').then(m => m.default), } })() - `, { plugins: ['typescript'] }), + `, + { plugins: ['typescript'] }, + ), ), ] } diff --git a/webpack/inject-metadata/i18n.ts b/webpack/inject-metadata/i18n.ts index dd6bf1927c..ac4f6cefcf 100644 --- a/webpack/inject-metadata/i18n.ts +++ b/webpack/inject-metadata/i18n.ts @@ -1,8 +1,5 @@ import { dirname } from 'path' -import { - objectProperty, - identifier, -} from '@babel/types' +import { objectProperty, identifier } from '@babel/types' import { parseExpression } from '@babel/parser' import { readdirSync } from 'fs' import { InjectMetadataAction } from './types' @@ -28,7 +25,8 @@ export const injectI18n: InjectMetadataAction = ({ filename }) => { return [ objectProperty( identifier('i18n'), - parseExpression(` + parseExpression( + ` (() => { const context = require.context('./', false, ${regex}) return { @@ -41,7 +39,9 @@ export const injectI18n: InjectMetadataAction = ({ filename }) => { })), } })() - `, { plugins: ['typescript'] }), + `, + { plugins: ['typescript'] }, + ), ), ] } diff --git a/webpack/inject-metadata/index.ts b/webpack/inject-metadata/index.ts index 003013cc6e..1fed8c45e5 100644 --- a/webpack/inject-metadata/index.ts +++ b/webpack/inject-metadata/index.ts @@ -5,24 +5,16 @@ import { injectCoreInfo } from './core-info' import { injectDescription } from './description' import { injectI18n } from './i18n' -const injectActions: InjectMetadataAction[] = [ - injectCoreInfo, - injectDescription, - injectI18n, -] +const injectActions: InjectMetadataAction[] = [injectCoreInfo, injectDescription, injectI18n] export const injectMetadata = (): PluginObj => ({ visitor: { ExportNamedDeclaration(path, state) { const { filename } = state.file.opts - const isFromRegistry = filename.startsWith( - nodePath.resolve('./registry'), - ) - const isFromCore = filename.startsWith( - nodePath.resolve('./src/components'), - ) || filename.startsWith( - nodePath.resolve('./src/plugins'), - ) + const isFromRegistry = filename.startsWith(nodePath.resolve('./registry')) + const isFromCore = + filename.startsWith(nodePath.resolve('./src/components')) || + filename.startsWith(nodePath.resolve('./src/plugins')) const isEntryFile = nodePath.basename(filename) === 'index.ts' if (!((isFromRegistry || isFromCore) && isEntryFile)) { return @@ -32,7 +24,8 @@ export const injectMetadata = (): PluginObj => ({ return } node.declaration.declarations?.forEach(d => { - const isNameValid = d.id?.type === 'Identifier' && ['component', 'plugin'].includes(d.id.name) + const isNameValid = + d.id?.type === 'Identifier' && ['component', 'plugin'].includes(d.id.name) if (!isNameValid) { return } @@ -41,10 +34,12 @@ export const injectMetadata = (): PluginObj => ({ return } targetExpression.properties.push( - ...injectActions.flatMap(action => action({ - expression: targetExpression, - filename, - })), + ...injectActions.flatMap(action => + action({ + expression: targetExpression, + filename, + }), + ), ) }) }, diff --git a/webpack/inject-metadata/types.ts b/webpack/inject-metadata/types.ts index 2f04b8fd25..d20c272b35 100644 --- a/webpack/inject-metadata/types.ts +++ b/webpack/inject-metadata/types.ts @@ -1,10 +1,7 @@ -import { - ObjectExpression, - ObjectProperty, -} from '@babel/types' +import { ObjectExpression, ObjectProperty } from '@babel/types' export interface InjectMetadataContext { expression: ObjectExpression filename: string } -export type InjectMetadataAction = ((context: InjectMetadataContext) => ObjectProperty[]) +export type InjectMetadataAction = (context: InjectMetadataContext) => ObjectProperty[] diff --git a/webpack/loaders/style-loaders.ts b/webpack/loaders/style-loaders.ts index 1b624fd289..f0bce981a8 100644 --- a/webpack/loaders/style-loaders.ts +++ b/webpack/loaders/style-loaders.ts @@ -12,10 +12,7 @@ export const postCssLoader: RuleSetUseItem = { loader: 'postcss-loader', options: { postcssOptions: { - plugins: [ - postcssPresetEnv(), - autoPrefixer(), - ], + plugins: [postcssPresetEnv(), autoPrefixer()], }, }, } diff --git a/webpack/loaders/ts-loader.ts b/webpack/loaders/ts-loader.ts index c9d3504fac..e4001a5c96 100644 --- a/webpack/loaders/ts-loader.ts +++ b/webpack/loaders/ts-loader.ts @@ -13,10 +13,7 @@ const babelLoader: RuleSetUseItem = { }, ], ], - plugins: [ - ['@babel/plugin-proposal-class-properties'], - injectMetadata, - ], + plugins: [['@babel/plugin-proposal-class-properties'], injectMetadata], }, } diff --git a/webpack/webpack.config.ts b/webpack/webpack.config.ts index d7cec5ce55..b5fff6ebd0 100644 --- a/webpack/webpack.config.ts +++ b/webpack/webpack.config.ts @@ -7,6 +7,7 @@ import { cssStyleLoaders, sassStyleLoaders } from './loaders/style-loaders' import { tsLoaders } from './loaders/ts-loader' import { runtimeInfo } from './compilation-info/runtime' import commonMeta from '../src/client/common.meta.json' +import * as gitInfo from './compilation-info/git' const relativePath = (p: string) => path.join(process.cwd(), p) export const getDefaultConfig = (src = relativePath('src')): Configuration => { @@ -26,7 +27,7 @@ export const getDefaultConfig = (src = relativePath('src')): Configuration => { alias: { '@': relativePath('src'), 'fuse.js$': 'fuse.js/dist/fuse.basic.esm.min.js', - 'vue$': 'vue/dist/vue.esm.js', + vue$: 'vue/dist/vue.esm.js', }, }, performance: { @@ -58,10 +59,7 @@ export const getDefaultConfig = (src = relativePath('src')): Configuration => { }, { test: /\.css$/, - use: [ - 'style-loader', - ...cssStyleLoaders, - ], + use: ['style-loader', ...cssStyleLoaders], include: /node_modules/, }, { @@ -69,16 +67,10 @@ export const getDefaultConfig = (src = relativePath('src')): Configuration => { oneOf: [ { resourceQuery: /vue/, - use: [ - 'style-loader', - ...cssStyleLoaders, - ], + use: ['style-loader', ...cssStyleLoaders], }, { - use: [ - 'to-string-loader', - ...cssStyleLoaders, - ], + use: ['to-string-loader', ...cssStyleLoaders], }, ], include: [src], @@ -88,30 +80,18 @@ export const getDefaultConfig = (src = relativePath('src')): Configuration => { oneOf: [ { resourceQuery: /vue/, - use: [ - 'style-loader', - ...sassStyleLoaders, - ], + use: ['style-loader', ...sassStyleLoaders], }, { - use: [ - 'to-string-loader', - ...sassStyleLoaders, - ], + use: ['to-string-loader', ...sassStyleLoaders], }, ], include: [src], }, { test: /\.tsx?$/, - use: [ - ...tsLoaders, - ], - include: [ - src, - relativePath('tests'), - relativePath('webpack'), - ], + use: [...tsLoaders], + include: [src, relativePath('tests'), relativePath('webpack')], }, { test: /\.vue$/, @@ -134,7 +114,7 @@ export const getDefaultConfig = (src = relativePath('src')): Configuration => { webpackCompilationInfo: [relativePath('webpack/compilation-info'), 'compilationInfo'], }), new webpack.DefinePlugin({ - webpackGitInfo: JSON.stringify(require('./compilation-info/git')), + webpackGitInfo: JSON.stringify(gitInfo), }), // new WebpackBar(), new webpack.optimize.LimitChunkCountPlugin({ @@ -143,11 +123,11 @@ export const getDefaultConfig = (src = relativePath('src')): Configuration => { // new HardSourcePlugin(), ], cache: { - type: "filesystem", + type: 'filesystem', buildDependencies: { config: [__filename], - } - } + }, + }, } } @@ -160,13 +140,19 @@ const replaceVariables = (text: string) => { return match }) } -export const getBanner = (meta: Record) => `// ==UserScript==\n${Object.entries(Object.assign(meta, commonMeta)).map(([key, value]) => { - if (Array.isArray(value)) { - const lines = [...new Set(value.map(item => `// @${key.padEnd(16, ' ')}${replaceVariables(item)}`))] - return lines.join('\n') - } - return `// @${key.padEnd(16, ' ')}${replaceVariables(value)}` -}).join('\n')} +export const getBanner = ( + meta: Record, +) => `// ==UserScript==\n${Object.entries(Object.assign(meta, commonMeta)) + .map(([key, value]) => { + if (Array.isArray(value)) { + const lines = [ + ...new Set(value.map(item => `// @${key.padEnd(16, ' ')}${replaceVariables(item)}`)), + ] + return lines.join('\n') + } + return `// @${key.padEnd(16, ' ')}${replaceVariables(value)}` + }) + .join('\n')} // ==/UserScript== /* eslint-disable */ /* spell-checker: disable */ // @[ You can find all source codes in GitHub repo ]`