From 0bbe426166981e64f12098771f4819a94780e2b0 Mon Sep 17 00:00:00 2001 From: jiangweiye Date: Thu, 14 Mar 2024 17:28:54 +0800 Subject: [PATCH] fix: fix export bug --- dist/index.cjs.js | 243 +--------------------------------------------- dist/index.d.ts | 2 +- tsup.config.ts | 4 +- 3 files changed, 6 insertions(+), 243 deletions(-) diff --git a/dist/index.cjs.js b/dist/index.cjs.js index 361dc7e..c9921c7 100644 --- a/dist/index.cjs.js +++ b/dist/index.cjs.js @@ -1,242 +1,3 @@ -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); +"use strict";Object.defineProperty(exports, "__esModule", {value: true});var v=Object.defineProperty;var n=(t,e)=>v(t,"name",{value:e,configurable:!0});var _path = require('path');var _fs = require('fs');var H=n(t=>_fs.lstatSync.call(void 0, t).isDirectory(),"isDir"),f=n(t=>_fs.existsSync.call(void 0, t),"hasFile"),_=n(t=>_fs.readdirSync.call(void 0, t).reduce((o,s)=>{let r=_path.join.call(void 0, t,s);return H(r)&&o.push({dirName:s,dirPath:r}),o},[]),"getDirs");function g(t,e){let o=n(r=>Object.prototype.toString.call(r)==="[object Object]","isObject"),s=n((r,c)=>o(r)&&Object.prototype.hasOwnProperty.call(r,c),"hasKey");for(let r in e)s(t,r)?o(e[r])&&g(t[r],e[r]):t[r]=e[r];return t}n(g,"mergeConfig");var h=n(t=>Object.prototype.toString.call(t)==="[object Function]","isFunction"),d=class d{static has(e,o){return h(Reflect.has)?Reflect.has(e,o):Object.prototype.hasOwnProperty.call(e,o)}static deleteProperty(e,o){return h(Reflect.deleteProperty)?Reflect.deleteProperty(e,o):delete e[o]}};n(d,"ReflectPolyfill");var u=d,y=class y{static startWith(e,o){return h(String.prototype.startsWith)?e.startsWith(o):e.slice(0,o.length)===o}};n(y,"StringPolyfill");var m=y;function j(t){try{let e=_fs.readFileSync.call(void 0, t,"utf-8");return JSON.parse(e)}catch(e){process.exit(0)}}n(j,"getJson");function N(t,e){var r,c,i,a;let o=(c=(r=t.compilerOptions)==null?void 0:r.paths)!=null?c:{},s=(a=(i=e.compilerOptions)==null?void 0:i.paths)!=null?a:{};for(let p in o)u.has(s,p)||(s[p]=o[p]);return Object.assign({},e,{compilerOptions:Object.assign({},e.compilerOptions,{paths:s})})}n(N,"mergeJson");function k(t,e,o){let{name:s}=_path.parse.call(void 0, e);return{compilerOptions:{paths:Object.keys(t).reduce((c,i)=>{if(m.startWith(i,o)&&i!==o){let{name:a}=_path.parse.call(void 0, t[i]);c["".concat(i,"/*")]=["".concat(s,"/").concat(a,"/*")]}return c["".concat(o,"/*")]=["".concat(s,"/*")],c},{}),baseUrl:"./"}}}n(k,"genJson");function F({aliasPath:t,jsJson:e,tsJson:o,alias:s,prefix:r,root:c,mode:i}){let a=k(s,c,r);if(t&&f(t)&&i==="sync"){let p=j(t),l=N(a,p);f(t)&&_fs.writeFileSync.call(void 0, t,JSON.stringify(l,null,4));return}if(f(e)&&i==="sync"){let p=j(e),l=N(a,p);f(e)&&_fs.writeFileSync.call(void 0, e,JSON.stringify(l,null,4))}if(f(o)&&i==="sync"){let p=j(o),l=N(a,p);f(o)&&_fs.writeFileSync.call(void 0, o,JSON.stringify(l,null,4))}}n(F,"syncJson");var P="vue-cli-plugin-inject-alias",C=n(t=>({root:_path.resolve.call(void 0, t,"src"),prefix:"@",mode:"sync"}),"defaultConfig"),T=n(t=>({ALIAS_JSON_PATH:null,JSON_CONFIG_PATH:_path.resolve.call(void 0, t,"jsconfig.json"),TS_CONFIG_PATH:_path.resolve.call(void 0, t,"tsconfig.json")}),"default");var L=n((t,e)=>({[P]:{root:_path.join.call(void 0, t,"src"),prefix:e.prefix,mode:e.mode}}),"getPluginConfig");function R(t,e){return _(t).reduce((s,r)=>{let c="".concat(e).concat(r.dirName),i=r.dirPath;return s[c]=i,s},{})}n(R,"genAlias");function U(t,e){let{pluginOptions:o={}}=e,s=t.getCwd(),{ALIAS_JSON_PATH:r,JSON_CONFIG_PATH:c,TS_CONFIG_PATH:i}=T(s),{mode:a,prefix:p,root:l}=g(o,L(s,C(s)))[P];f(l)&&t.configureWebpack(O=>{let b={};O.resolve&&O.resolve.alias&&(b=O.resolve.alias);let A=Object.assign({},R(l,p),b);return F({aliasPath:r,jsJson:c,tsJson:i,alias:A,root:l,prefix:p,mode:a}),{resolve:{alias:A}}})}n(U,"alias");var at=U;exports.default = at; -// src/index.ts -var src_exports = {}; -__export(src_exports, { - default: () => src_default -}); -module.exports = __toCommonJS(src_exports); -var import_path4 = require("path"); - -// src/shared.ts -var import_fs = require("fs"); -var import_path = require("path"); -var isDir = /* @__PURE__ */ __name((path) => { - return (0, import_fs.lstatSync)(path).isDirectory(); -}, "isDir"); -var hasFile = /* @__PURE__ */ __name((path) => { - return (0, import_fs.existsSync)(path); -}, "hasFile"); -var getDirs = /* @__PURE__ */ __name((path) => { - const dirs = (0, import_fs.readdirSync)(path); - return dirs.reduce((result, name) => { - const fullPath = (0, import_path.join)(path, name); - isDir(fullPath) && result.push({ - dirName: name, - dirPath: fullPath - }); - return result; - }, []); -}, "getDirs"); -function mergeConfig(source, target) { - const isObject = /* @__PURE__ */ __name((data) => Object.prototype.toString.call(data) === "[object Object]", "isObject"); - const hasKey = /* @__PURE__ */ __name((data, key) => isObject(data) && Object.prototype.hasOwnProperty.call(data, key), "hasKey"); - for (const key in target) { - if (!hasKey(source, key)) { - source[key] = target[key]; - } else { - isObject(target[key]) && mergeConfig(source[key], target[key]); - } - } - return source; -} -__name(mergeConfig, "mergeConfig"); - -// src/sync.ts -var import_fs2 = require("fs"); -var import_path2 = require("path"); - -// src/polyfill.ts -var isFunction = /* @__PURE__ */ __name((d) => Object.prototype.toString.call(d) === "[object Function]", "isFunction"); -var _ReflectPolyfill = class _ReflectPolyfill { - /** - * @description 对象是否存在某个属性 - * @param target source - * @param propertyKey key - * @returns boolean - */ - static has(target, propertyKey) { - return isFunction(Reflect.has) ? Reflect.has(target, propertyKey) : Object.prototype.hasOwnProperty.call(target, propertyKey); - } - /** - * @description 删除某个属性 - * @param target source - * @param propertyKey key - * @returns boolean - */ - static deleteProperty(target, propertyKey) { - return isFunction(Reflect.deleteProperty) ? Reflect.deleteProperty(target, propertyKey) : delete target[propertyKey]; - } -}; -__name(_ReflectPolyfill, "ReflectPolyfill"); -var ReflectPolyfill = _ReflectPolyfill; -var _StringPolyfill = class _StringPolyfill { - /** - * @description 是否以某个字符串开头 - * @param str string - * @param search string - * @returns boolean - */ - static startWith(str, search) { - return isFunction(String.prototype.startsWith) ? str.startsWith(search) : str.slice(0, search.length) === search; - } -}; -__name(_StringPolyfill, "StringPolyfill"); -var StringPolyfill = _StringPolyfill; - -// src/sync.ts -function getJson(jsonPath) { - try { - const jsonText = (0, import_fs2.readFileSync)(jsonPath, "utf-8"); - return JSON.parse(jsonText); - } catch (error) { - process.exit(0); - } -} -__name(getJson, "getJson"); -function mergeJson(target, source) { - var _a, _b, _c, _d; - const targetPaths = (_b = (_a = target.compilerOptions) == null ? void 0 : _a.paths) != null ? _b : {}; - const sourcePaths = (_d = (_c = source.compilerOptions) == null ? void 0 : _c.paths) != null ? _d : {}; - for (const pathKey in targetPaths) { - if (!ReflectPolyfill.has(sourcePaths, pathKey)) { - sourcePaths[pathKey] = targetPaths[pathKey]; - } - } - return Object.assign({}, source, { - compilerOptions: Object.assign({}, source.compilerOptions, { - paths: sourcePaths - }) - }); -} -__name(mergeJson, "mergeJson"); -function genJson(alias2, root, prefix) { - const { name: rootName } = (0, import_path2.parse)(root); - const paths = Object.keys(alias2).reduce((result, pathKey) => { - if (StringPolyfill.startWith(pathKey, prefix) && pathKey !== prefix) { - const { name } = (0, import_path2.parse)(alias2[pathKey]); - result["".concat(pathKey, "/*")] = [ - "".concat(rootName, "/").concat(name, "/*") - ]; - } - result["".concat(prefix, "/*")] = [ - "".concat(rootName, "/*") - ]; - return result; - }, {}); - return { - compilerOptions: { - paths, - baseUrl: "./" - } - }; -} -__name(genJson, "genJson"); -function syncJson({ aliasPath, jsJson, tsJson, alias: alias2, prefix, root, mode }) { - const target = genJson(alias2, root, prefix); - if (aliasPath && hasFile(aliasPath) && mode === "sync") { - const source = getJson(aliasPath); - const newJson = mergeJson(target, source); - hasFile(aliasPath) && (0, import_fs2.writeFileSync)(aliasPath, JSON.stringify(newJson, null, 4)); - return; - } - if (hasFile(jsJson) && mode === "sync") { - const source = getJson(jsJson); - const newJson = mergeJson(target, source); - hasFile(jsJson) && (0, import_fs2.writeFileSync)(jsJson, JSON.stringify(newJson, null, 4)); - } - if (hasFile(tsJson) && mode === "sync") { - const source = getJson(tsJson); - const newJson = mergeJson(target, source); - hasFile(tsJson) && (0, import_fs2.writeFileSync)(tsJson, JSON.stringify(newJson, null, 4)); - } -} -__name(syncJson, "syncJson"); - -// src/const.ts -var import_path3 = require("path"); -var PLUGIN_NAME = "vue-cli-plugin-inject-alias"; -var defaultConfig = /* @__PURE__ */ __name((cwd) => { - return { - root: (0, import_path3.resolve)(cwd, "src"), - prefix: "@", - mode: "sync" - }; -}, "defaultConfig"); -var const_default = /* @__PURE__ */ __name((cwd) => { - return { - ALIAS_JSON_PATH: null, - JSON_CONFIG_PATH: (0, import_path3.resolve)(cwd, "jsconfig.json"), - TS_CONFIG_PATH: (0, import_path3.resolve)(cwd, "tsconfig.json") - }; -}, "default"); - -// src/index.ts -var getPluginConfig = /* @__PURE__ */ __name((root, defaultConfig2) => { - return { - [PLUGIN_NAME]: { - root: (0, import_path4.join)(root, "src"), - prefix: defaultConfig2.prefix, - mode: defaultConfig2.mode - } - }; -}, "getPluginConfig"); -function genAlias(root, prefix) { - const dirs = getDirs(root); - return dirs.reduce((result, item) => { - const key = "".concat(prefix).concat(item.dirName); - const value = item.dirPath; - result[key] = value; - return result; - }, {}); -} -__name(genAlias, "genAlias"); -function alias(api, options) { - const { pluginOptions = {} } = options; - const cwd = api.getCwd(); - const { ALIAS_JSON_PATH, JSON_CONFIG_PATH, TS_CONFIG_PATH } = const_default(cwd); - const { mode, prefix, root } = mergeConfig(pluginOptions, getPluginConfig(cwd, defaultConfig(cwd)))[PLUGIN_NAME]; - if (!hasFile(root)) { - return; - } - api.configureWebpack((config) => { - let baseAlias = {}; - if (config.resolve && config.resolve.alias) { - baseAlias = config.resolve.alias; - } - const _alias = Object.assign({}, genAlias(root, prefix), baseAlias); - syncJson({ - aliasPath: ALIAS_JSON_PATH, - jsJson: JSON_CONFIG_PATH, - tsJson: TS_CONFIG_PATH, - alias: _alias, - root, - prefix, - mode - }); - return { - resolve: { - alias: _alias - } - }; - }); -} -__name(alias, "alias"); -var src_default = alias; +module.exports = exports.default \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 54678b4..ceaa43f 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -2,4 +2,4 @@ import { PluginAPI, ProjectOptions } from '@vue/cli-service'; declare function alias(api: PluginAPI, options: ProjectOptions): void; -export { alias as default }; +export = alias; diff --git a/tsup.config.ts b/tsup.config.ts index 262b81d..aee2279 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -9,10 +9,12 @@ export default defineConfig({ js: `.${format}.js` }; }, + splitting: true, + cjsInterop: true, dts: true, target: ['node8'], format: ['cjs'], - minify: false, + minify: true, clean: true, tsconfig: path.resolve(__dirname, './tsconfig.json') });