diff --git a/.eslintrc.js b/.eslintrc.js index 686d228..98dfefe 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,7 +26,7 @@ module.exports = { 'new-cap': 0, // 函数首字母不能大写 indent: 0, // prettier 已经处理好了 'object-curly-spacing': 0, // prettier 自动格式化这个部分 - 'max-len': ['error', 120], + 'max-len': 0, 'operator-linebreak': ['error', 'before'], 'quote-props': ['error', 'as-needed'], 'operator-linebreak': 0, diff --git a/FakeServer/FakeServer.drawio b/FakeServer/FakeServer.drawio index 5acf9b4..01cb81a 100644 --- a/FakeServer/FakeServer.drawio +++ b/FakeServer/FakeServer.drawio @@ -1,40 +1,47 @@ - + - + - + - + - + - + - - + + + + + + + + + - + - + - + - + - + @@ -42,9 +49,19 @@ - + + + + + + + + + + + diff --git a/FakeServer/parseURL.js b/FakeServer/parseURL.js index d9104bd..ea87163 100644 --- a/FakeServer/parseURL.js +++ b/FakeServer/parseURL.js @@ -1,4 +1,4 @@ -/* +/** * @license * Copyright 2021 KonghaYao 江夏尧 * SPDX-License-Identifier: Apache-2.0 @@ -11,33 +11,33 @@ * Licensed under an MIT-style license. */ const key = [ - "source", - "protocol", - "authority", - "userInfo", - "user", - "password", - "host", - "port", - "relative", - "path", - "directory", - "file", - "query", - "hash", + 'source', + 'protocol', + 'authority', + 'userInfo', + 'user', + 'password', + 'host', + 'port', + 'relative', + 'path', + 'directory', + 'file', + 'query', + 'hash', ]; // keys available to query const parser = { - //less intuitive, more accurate to the specs + // less intuitive, more accurate to the specs strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, // more intuitive, fails on relative paths and deviates from specs loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, }; function parseUri(url, strictMode = false) { - const res = parser[strictMode ? "strict" : "loose"].exec(decodeURI(url)); + const res = parser[strictMode ? 'strict' : 'loose'].exec(decodeURI(url)); const uri = key.reduce((col, keyName, index) => { - col[keyName] = res[index] || ""; + col[keyName] = res[index] || ''; return col; }, {}); @@ -45,10 +45,9 @@ function parseUri(url, strictMode = false) { uri.queryParams = parseString(uri.query); // compile a 'base' domain attribute - uri["base"] = uri.host - ? (uri.protocol ? uri.protocol + "://" + uri.host : uri.host) + - (uri.port ? ":" + uri.port : "") - : ""; + uri['base'] = uri.host + ? (uri.protocol ? uri.protocol + '://' + uri.host : uri.host) + (uri.port ? ':' + uri.port : '') + : ''; return uri; } @@ -58,11 +57,11 @@ function parseString(queryString) { .split(/&|;/) .reduce(function (collection, pair) { try { - pair = decodeURIComponent(pair.replace(/\+/g, " ")); + pair = decodeURIComponent(pair.replace(/\+/g, ' ')); } catch (e) { // ignore } - let [key, value] = pair.split(/=/g); + const [key, value] = pair.split(/=/g); collection[key] = value; return collection; }, {}); diff --git a/FakeServer/router.js b/FakeServer/router.js index d892e20..4887b09 100644 --- a/FakeServer/router.js +++ b/FakeServer/router.js @@ -1,14 +1,23 @@ import { map } from 'rxjs/operators'; import { of } from 'rxjs'; import { pathToRegexp } from 'path-to-regexp'; +import { parseURL } from './parseURL.js'; function normalizeRouters(Routers) { return Object.entries(Routers); } function createRegexp(path, config = {}) { return pathToRegexp(path, [], config); } +class Response { + constructor(path, options = {}) {} + send() {} +} + +// 每一个 Route 只有一个 main 函数进行数据的返回 class Route { - constructor(path, cb) {} + constructor(pathRegexp, cb) { + this.query = cb; + } use(plugin) {} } class Router { @@ -24,8 +33,21 @@ class Router { this.#RouteMatchers.push(pathRegexp); return route; } - deleteRouter() {} - enableRouter() {} - disableRouter() {} - receiveMessage(path, message) {} + receiveMessage(path, options = {}) { + const req = parseURL(path); + const res = new Response(path, options); + let target; + this.#RouteMatchers.some((i) => { + if (path.match(i)) { + target = this.#RouterMap.get(i); + return true; + } + return false; + }); + + if (target instanceof Router) { + return target.query(req, res); + } else { + } + } } diff --git a/dist/JSpider.esm.min.js b/dist/JSpider.esm.min.js index 6227dcb..d2de567 100644 --- a/dist/JSpider.esm.min.js +++ b/dist/JSpider.esm.min.js @@ -5166,7 +5166,7 @@ class RetryError extends Error { * SPDX-License-Identifier: Apache-2.0 */ -class PLUGIN { +class PLUGIN$1 { constructor({ forceRetry = true, saveResult = false, @@ -5240,14 +5240,14 @@ class PLUGIN { } } -function Plugin(Process) { +function Plugin$1(Process) { if (Process instanceof Function) { - return new PLUGIN({ + return new PLUGIN$1({ main: Process, }); } if (Process instanceof Object) { - return new PLUGIN(Process); + return new PLUGIN$1(Process); } throw new PluginError('Plugin 必须是一个函数或者是 Plugin 描述对象'); } @@ -5392,7 +5392,7 @@ function HandleError(err) { throw err; } function Request(options = {}) { - return Plugin({ + return Plugin$1({ init() {}, // 在所有工作开始前会启动的函数,可以用于 Promise 加载一些 js 插件 main: request, // 功能性的核心函数 options, // 接收所有的参数,提供给所有函数使用 @@ -5443,6 +5443,98 @@ function toFile(data, name) { return new File([JSON.stringify(data)], name); } +/** + * @license + * Copyright 2021 KonghaYao 江夏尧 + * SPDX-License-Identifier: Apache-2.0 + */ + +class PLUGIN { + constructor({ + forceRetry = true, + saveResult = false, + name = null, + main, + init = null, + error = null, + complete = null, + options = {}, + operator, + }) { + const uuid = createUUID(main.toString()); + if (operator) this.operator = operator; + // 写入自身中 + Object.assign(this, { + name: name || uuid, // 名称,一般用作提示标记 + uuid, // 唯一标识 + main, // Plugin 中的功能性函数 + init, // 初始化整个 Plugin 的函数 + error, // 函数错误时的事件 + complete, // 函数完成时的提示事件 + options, // main 函数接收的 options + saveResult, // 是否保存结果到每一个 Task 中 + forceRetry, // 是否强制重新使用 Plugin + }); + } + + // 对 main 函数外包一层,直接启动 main 函数的执行,返回一条流 + TaskStarter(task) { + return of(task).pipe( + // 设置跳过 Plugin 的逻辑 + switchMap((task) => { + if (task.$checkRepeat(this.uuid) || this.forceRetry) { + return of(task).pipe( + map((task) => [task.$commit('start', this.uuid), task._originData]), + + switchMap(([data, originData]) => { + const result = this.main(data, originData); + return result instanceof Promise || result instanceof Observable + ? from(result) + : of(result); + }), + map((result) => { + task.$commit('success', result, this.uuid, this.saveResult); + return task; + }), + ); + } + console.log('跳过一个目标'); + return of(task); + }), + // 捕获到异常 + catchError((...args) => { + if (this.error instanceof Function) { + const afterError = this.error(task, ...args); + if (afterError) throw new PluginError(afterError); + + return EMPTY; + } + throw new PluginError(args[0]); + }), + // 完成 Plugin 时的事件 + tap((task) => this.complete && this.complete(task)), + ); + } + + operator(context) { + // ! 这个是默认的 operator 函数 + // context 为上层的 JSpider 实例 + return pipe(switchMap((task) => this.TaskStarter(task))); + } +} + +function Plugin(Process) { + if (Process instanceof Function) { + return new PLUGIN({ + main: Process, + }); + } + if (Process instanceof Object) { + return new PLUGIN(Process); + } + throw new PluginError('Plugin 必须是一个函数或者是 Plugin 描述对象'); +} + /** * @license * Copyright 2021 KonghaYao 江夏尧 @@ -5742,7 +5834,7 @@ async function zipper(fileArray, zipName) { const ZipFile = function (options = {}) { if (!options.zipFileName) options.zipFileName = new Date().getTime(); - return Plugin({ + return Plugin$1({ init, main(data) { const { zipFileName } = this.options; @@ -6242,6 +6334,80 @@ async function Mock(MockSiteName) { } const $Mock = memoize(Mock); +/* + * @license + * Copyright 2021 KonghaYao 江夏尧 + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * The Regexps were copied from Purl (A JavaScript URL parser) v2.3.1 + * which developed and maintained by Mark Perkins, mark@allmarkedup.com + * Source repository: https://github.com/allmarkedup/jQuery-URL-Parser + * Licensed under an MIT-style license. + */ +const key = [ + "source", + "protocol", + "authority", + "userInfo", + "user", + "password", + "host", + "port", + "relative", + "path", + "directory", + "file", + "query", + "hash", +]; // keys available to query +const parser = { + //less intuitive, more accurate to the specs + strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, + // more intuitive, fails on relative paths and deviates from specs + loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, +}; + +function parseUri(url, strictMode = false) { + const res = parser[strictMode ? "strict" : "loose"].exec(decodeURI(url)); + + const uri = key.reduce((col, keyName, index) => { + col[keyName] = res[index] || ""; + return col; + }, {}); + + // build query and hash parameters + uri.queryParams = parseString(uri.query); + + // compile a 'base' domain attribute + uri["base"] = uri.host + ? (uri.protocol ? uri.protocol + "://" + uri.host : uri.host) + + (uri.port ? ":" + uri.port : "") + : ""; + + return uri; +} + +function parseString(queryString) { + return String(queryString) + .split(/&|;/) + .reduce(function (collection, pair) { + try { + pair = decodeURIComponent(pair.replace(/\+/g, " ")); + } catch (e) { + // ignore + } + let [key, value] = pair.split(/=/g); + collection[key] = value; + return collection; + }, {}); +} + +function parseURL(url, strictMode = false) { + return parseUri(url, strictMode); +} + /** * @license * Copyright 2021 KonghaYao 江夏尧 @@ -6255,7 +6421,8 @@ var tools = /*#__PURE__*/Object.freeze({ $GlobalVars: $GlobalVars, $search: $search, $load: $load, - $Mock: $Mock + $Mock: $Mock, + parseURL: parseURL }); /** @@ -6265,11 +6432,11 @@ var tools = /*#__PURE__*/Object.freeze({ */ var index = Object.assign(Spider, tools, { plugins, - Plugin, + Plugin: Plugin$1, Task, TaskGroup, version: "3.1.8", - buildDate: new Date(1626782541521), + buildDate: new Date(1626863175706), }); export default index; diff --git a/dist/JSpider.min.js b/dist/JSpider.min.js index f1c7ab0..35b417b 100644 --- a/dist/JSpider.min.js +++ b/dist/JSpider.min.js @@ -5169,7 +5169,7 @@ var JSpider = (function () { * SPDX-License-Identifier: Apache-2.0 */ - class PLUGIN { + class PLUGIN$1 { constructor({ forceRetry = true, saveResult = false, @@ -5243,14 +5243,14 @@ var JSpider = (function () { } } - function Plugin(Process) { + function Plugin$1(Process) { if (Process instanceof Function) { - return new PLUGIN({ + return new PLUGIN$1({ main: Process, }); } if (Process instanceof Object) { - return new PLUGIN(Process); + return new PLUGIN$1(Process); } throw new PluginError('Plugin 必须是一个函数或者是 Plugin 描述对象'); } @@ -5395,7 +5395,7 @@ var JSpider = (function () { throw err; } function Request(options = {}) { - return Plugin({ + return Plugin$1({ init() {}, // 在所有工作开始前会启动的函数,可以用于 Promise 加载一些 js 插件 main: request, // 功能性的核心函数 options, // 接收所有的参数,提供给所有函数使用 @@ -5446,6 +5446,98 @@ var JSpider = (function () { return new File([JSON.stringify(data)], name); } + /** + * @license + * Copyright 2021 KonghaYao 江夏尧 + * SPDX-License-Identifier: Apache-2.0 + */ + + class PLUGIN { + constructor({ + forceRetry = true, + saveResult = false, + name = null, + main, + init = null, + error = null, + complete = null, + options = {}, + operator, + }) { + const uuid = createUUID(main.toString()); + if (operator) this.operator = operator; + // 写入自身中 + Object.assign(this, { + name: name || uuid, // 名称,一般用作提示标记 + uuid, // 唯一标识 + main, // Plugin 中的功能性函数 + init, // 初始化整个 Plugin 的函数 + error, // 函数错误时的事件 + complete, // 函数完成时的提示事件 + options, // main 函数接收的 options + saveResult, // 是否保存结果到每一个 Task 中 + forceRetry, // 是否强制重新使用 Plugin + }); + } + + // 对 main 函数外包一层,直接启动 main 函数的执行,返回一条流 + TaskStarter(task) { + return of(task).pipe( + // 设置跳过 Plugin 的逻辑 + switchMap((task) => { + if (task.$checkRepeat(this.uuid) || this.forceRetry) { + return of(task).pipe( + map((task) => [task.$commit('start', this.uuid), task._originData]), + + switchMap(([data, originData]) => { + const result = this.main(data, originData); + return result instanceof Promise || result instanceof Observable + ? from(result) + : of(result); + }), + map((result) => { + task.$commit('success', result, this.uuid, this.saveResult); + return task; + }), + ); + } + console.log('跳过一个目标'); + return of(task); + }), + // 捕获到异常 + catchError((...args) => { + if (this.error instanceof Function) { + const afterError = this.error(task, ...args); + if (afterError) throw new PluginError(afterError); + + return EMPTY; + } + throw new PluginError(args[0]); + }), + // 完成 Plugin 时的事件 + tap((task) => this.complete && this.complete(task)), + ); + } + + operator(context) { + // ! 这个是默认的 operator 函数 + // context 为上层的 JSpider 实例 + return pipe(switchMap((task) => this.TaskStarter(task))); + } + } + + function Plugin(Process) { + if (Process instanceof Function) { + return new PLUGIN({ + main: Process, + }); + } + if (Process instanceof Object) { + return new PLUGIN(Process); + } + throw new PluginError('Plugin 必须是一个函数或者是 Plugin 描述对象'); + } + /** * @license * Copyright 2021 KonghaYao 江夏尧 @@ -5745,7 +5837,7 @@ var JSpider = (function () { const ZipFile = function (options = {}) { if (!options.zipFileName) options.zipFileName = new Date().getTime(); - return Plugin({ + return Plugin$1({ init, main(data) { const { zipFileName } = this.options; @@ -6245,6 +6337,80 @@ var JSpider = (function () { } const $Mock = memoize(Mock); + /* + * @license + * Copyright 2021 KonghaYao 江夏尧 + * SPDX-License-Identifier: Apache-2.0 + */ + + /** + * The Regexps were copied from Purl (A JavaScript URL parser) v2.3.1 + * which developed and maintained by Mark Perkins, mark@allmarkedup.com + * Source repository: https://github.com/allmarkedup/jQuery-URL-Parser + * Licensed under an MIT-style license. + */ + const key = [ + "source", + "protocol", + "authority", + "userInfo", + "user", + "password", + "host", + "port", + "relative", + "path", + "directory", + "file", + "query", + "hash", + ]; // keys available to query + const parser = { + //less intuitive, more accurate to the specs + strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, + // more intuitive, fails on relative paths and deviates from specs + loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/, + }; + + function parseUri(url, strictMode = false) { + const res = parser[strictMode ? "strict" : "loose"].exec(decodeURI(url)); + + const uri = key.reduce((col, keyName, index) => { + col[keyName] = res[index] || ""; + return col; + }, {}); + + // build query and hash parameters + uri.queryParams = parseString(uri.query); + + // compile a 'base' domain attribute + uri["base"] = uri.host + ? (uri.protocol ? uri.protocol + "://" + uri.host : uri.host) + + (uri.port ? ":" + uri.port : "") + : ""; + + return uri; + } + + function parseString(queryString) { + return String(queryString) + .split(/&|;/) + .reduce(function (collection, pair) { + try { + pair = decodeURIComponent(pair.replace(/\+/g, " ")); + } catch (e) { + // ignore + } + let [key, value] = pair.split(/=/g); + collection[key] = value; + return collection; + }, {}); + } + + function parseURL(url, strictMode = false) { + return parseUri(url, strictMode); + } + /** * @license * Copyright 2021 KonghaYao 江夏尧 @@ -6258,7 +6424,8 @@ var JSpider = (function () { $GlobalVars: $GlobalVars, $search: $search, $load: $load, - $Mock: $Mock + $Mock: $Mock, + parseURL: parseURL }); /** @@ -6268,11 +6435,11 @@ var JSpider = (function () { */ var index = Object.assign(Spider, tools, { plugins, - Plugin, + Plugin: Plugin$1, Task, TaskGroup, version: "3.1.8", - buildDate: new Date(1626782541521), + buildDate: new Date(1626863175706), }); return index; diff --git a/package.json b/package.json index fddc106..5b8b6e1 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "dev": "rollup --config rollup.config.dev.js -w", "build": "rollup --config rollup.config.build.js", "lint": "eslint src plugins", - "Lint": "prettier --write src/**/*.{ts,json,md,yml,js} plugins/**/*.{ts,json,md,yml,js} && eslint src plugins", - "prettier": "prettier --write src/**/*.{ts,json,md,yml,js} plugins/**/*.{ts,json,md,yml,js}", + "Lint": "prettier --write src/**/*.{ts,json,md,yml,js} plugins/**/*.{ts,json,md,yml,js} FakeServer/**/*.{ts,json,md,yml,js} && eslint src plugins FakeServer", + "prettier": "prettier --write src/**/*.{ts,json,md,yml,js} plugins/**/*.{ts,json,md,yml,js} FakeServer/**/*.{ts,json,md,yml,js}", "graph": "madge --image docs/assets/dependencies.svg src/index.js", "release": "standard-version", "lint-staged": "lint-staged", @@ -60,6 +60,7 @@ "@babel/core": "^7.14.3", "@babel/eslint-parser": "^7.14.7", "@babel/preset-env": "^7.14.4", + "@rollup/plugin-alias": "^3.1.4", "@rollup/plugin-babel": "^5.3.0", "@rollup/plugin-commonjs": "^19.0.0", "@rollup/plugin-json": "^4.1.0", diff --git a/plugins/Dexie/Dexie.js b/plugins/Dexie/Dexie.js index ada2528..3fc3ae5 100644 --- a/plugins/Dexie/Dexie.js +++ b/plugins/Dexie/Dexie.js @@ -3,7 +3,7 @@ * Copyright 2021 KonghaYao 江夏尧 * SPDX-License-Identifier: Apache-2.0 */ -import { $load } from '../../tools/loader/loader.js'; +import { $load } from '@tools/loader/loader.js'; let Dexie; function init() { diff --git a/plugins/Download.js b/plugins/Download.js index fd153be..8c037cd 100644 --- a/plugins/Download.js +++ b/plugins/Download.js @@ -5,7 +5,7 @@ */ import { toFile } from './utils/toFile.js'; -import { Plugin } from '../src/Pipeline/PluginSystem.js'; +import { Plugin } from '@src/Pipeline/PluginSystem.js'; // 在 浏览器中下载是不能够同时进行的,也就是说,如果前面的没有下载完,后面的又提交 // 会导致后面的全部失效,所以设置 Promise 下载队列 const DownloadQueue = { diff --git a/plugins/ExcelHelper.js b/plugins/ExcelHelper.js index 91a7ee0..2302824 100644 --- a/plugins/ExcelHelper.js +++ b/plugins/ExcelHelper.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ import { createExcelFile } from './ExcelHelper/createExcelFile.js'; -import { Plugin } from '../src/Pipeline/PluginSystem.js'; +import { Plugin } from '@src/Pipeline/PluginSystem.js'; import { init } from './ExcelHelper/xlsx.js'; // 未完成 导入 XLSX 的 Promise 到流的转变 diff --git a/plugins/ExcelHelper/xlsx.js b/plugins/ExcelHelper/xlsx.js index b2a6f38..08217e3 100644 --- a/plugins/ExcelHelper/xlsx.js +++ b/plugins/ExcelHelper/xlsx.js @@ -3,7 +3,7 @@ * Copyright 2021 KonghaYao 江夏尧 * SPDX-License-Identifier: Apache-2.0 */ -import { $load } from '../../src/tools/loader/loader.js'; +import { $load } from '@tools/loader/loader.js'; let XLSX; function init() { diff --git a/plugins/JSzip/JSzip.js b/plugins/JSzip/JSzip.js index 923f8d0..a20d828 100644 --- a/plugins/JSzip/JSzip.js +++ b/plugins/JSzip/JSzip.js @@ -3,7 +3,7 @@ * Copyright 2021 KonghaYao 江夏尧 * SPDX-License-Identifier: Apache-2.0 */ -import { $load } from '../../src/tools/loader/loader.js'; +import { $load } from '@tools/loader/loader.js'; let JSZip; function init() { diff --git a/plugins/Request.js b/plugins/Request.js index 241790f..c5eb255 100644 --- a/plugins/Request.js +++ b/plugins/Request.js @@ -5,8 +5,8 @@ */ /* eslint-disable no-invalid-this */ -import { Plugin } from '../src/Pipeline/PluginSystem.js'; -import { concurrent } from '../src/utils/concurrent.js'; +import { Plugin } from '@src/Pipeline/PluginSystem.js'; +import { concurrent } from '@src/utils/concurrent.js'; // ! 这个 Request 文件是标准的 Plugin 的高级注册示例 diff --git a/plugins/zipFile.js b/plugins/zipFile.js index ed16d5f..84efbe8 100644 --- a/plugins/zipFile.js +++ b/plugins/zipFile.js @@ -5,13 +5,13 @@ */ import { bufferTime, concatMap, filter } from 'rxjs/operators'; -import { Plugin } from '../src/Pipeline/PluginSystem.js'; +import { Plugin } from '@src/Pipeline/PluginSystem.js'; import { init } from './JSzip/JSzip.js'; import { zipper } from './JSzip/zipper.js'; import { toFile } from './utils/toFile.js'; -import { TaskGroup } from '../src/TaskSystem/TaskGroup.js'; +import { TaskGroup } from '@src/TaskSystem/TaskGroup.js'; export const ZipFile = function (options = {}) { if (!options.zipFileName) options.zipFileName = new Date().getTime(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cd0ea23..c4ff2d9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,7 @@ specifiers: '@babel/core': ^7.14.3 '@babel/eslint-parser': ^7.14.7 '@babel/preset-env': ^7.14.4 + '@rollup/plugin-alias': ^3.1.4 '@rollup/plugin-babel': ^5.3.0 '@rollup/plugin-commonjs': ^19.0.0 '@rollup/plugin-json': ^4.1.0 @@ -44,6 +45,7 @@ devDependencies: '@babel/core': 7.14.6 '@babel/eslint-parser': 7.14.7_@babel+core@7.14.6+eslint@7.30.0 '@babel/preset-env': 7.14.7_@babel+core@7.14.6 + '@rollup/plugin-alias': 3.1.4_rollup@2.52.7 '@rollup/plugin-babel': 5.3.0_@babel+core@7.14.6+rollup@2.52.7 '@rollup/plugin-commonjs': 19.0.0_rollup@2.52.7 '@rollup/plugin-json': 4.1.0_rollup@2.52.7 @@ -1287,6 +1289,16 @@ packages: fastq: 1.11.0 dev: true + /@rollup/plugin-alias/3.1.4_rollup@2.52.7: + resolution: {integrity: sha512-9YN5h0bWlYFV0zpXwwAWGPUWh/A+kkoCqwrMb43LnuGfhnQqOjsGR+5uh4LGpAZbBBj8qR1Hno6CZadZs7hyCQ==} + engines: {node: '>=8.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0 + dependencies: + rollup: 2.52.7 + slash: 3.0.0 + dev: true + /@rollup/plugin-babel/5.3.0_@babel+core@7.14.6+rollup@2.52.7: resolution: {integrity: sha512-9uIC8HZOnVLrLHxayq/PTzw+uS25E14KPUBh5ktF+18Mjo5yK0ToMMx6epY0uEgkjwJw0aBW4x2horYXh8juWw==} engines: {node: '>= 10.0.0'} diff --git a/rollup.config.build.js b/rollup.config.build.js index 243ddff..9b3b779 100644 --- a/rollup.config.build.js +++ b/rollup.config.build.js @@ -6,6 +6,7 @@ import del from 'rollup-plugin-delete'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import CONFIG from './package.json'; +import alias from '@rollup/plugin-alias'; const plugins = [ replace({ preventAssignment: true, diff --git a/rollup.config.dev.js b/rollup.config.dev.js index 07de27b..6657248 100644 --- a/rollup.config.dev.js +++ b/rollup.config.dev.js @@ -5,7 +5,7 @@ import replace from '@rollup/plugin-replace'; import CONFIG from './package.json'; import livereload from 'rollup-plugin-livereload'; import serve from 'rollup-plugin-serve'; - +import alias from '@rollup/plugin-alias'; export default { input: 'src/index.js', // 打包入口 output: [ @@ -22,6 +22,14 @@ export default { }, ], plugins: [ + alias({ + entries: { + '@tools': './tools', + '@src': './src', + '@plugins': './plugins', + '@FakeServer':'./FakeServer' + }, + }), replace({ preventAssignment: true, values: { __version__: JSON.stringify(CONFIG.version), __buildDate__: new Date().getTime() }, diff --git a/tools/analysis/Search/searchObj.js b/tools/analysis/Search/searchObj.js index f290fa4..17a3daf 100644 --- a/tools/analysis/Search/searchObj.js +++ b/tools/analysis/Search/searchObj.js @@ -9,7 +9,7 @@ * @Last Modified by: KonghaYao * @Last Modified time: 2021-06-29 16:16:22 */ -import getType from '../../../utils/type.js'; +import getType from '../../../src/utils/type.js'; const TypeMap = { RE: '', diff --git a/tools/index.js b/tools/index.js index d831f8a..13bd48c 100644 --- a/tools/index.js +++ b/tools/index.js @@ -6,4 +6,4 @@ export * from './analysis/index.js'; export * from './loader/loader.js'; export * from './Mock/Mock.js'; -export * from '../FakeServer/parseURL.js'; +export * from '@FakeServer/parseURL.js'; diff --git a/tools/loader/loader.js b/tools/loader/loader.js index d534f45..27b8b55 100644 --- a/tools/loader/loader.js +++ b/tools/loader/loader.js @@ -16,7 +16,7 @@ import { jsdelivr } from './jsDelivr.js'; * @param {String|Object} Module :{} * @returns {Promise} */ -import { type } from '../../utils/type.js'; +import { type } from '@src/utils/type.js'; const URLTest = /(https?|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/;