unplugin-dingtalk 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,327 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // node_modules/.pnpm/picocolors@1.0.1/node_modules/picocolors/picocolors.js
34
+ var require_picocolors = __commonJS({
35
+ "node_modules/.pnpm/picocolors@1.0.1/node_modules/picocolors/picocolors.js"(exports2, module2) {
36
+ "use strict";
37
+ var argv = process.argv || [];
38
+ var env = process.env;
39
+ var isColorSupported = !("NO_COLOR" in env || argv.includes("--no-color")) && ("FORCE_COLOR" in env || argv.includes("--color") || process.platform === "win32" || require != null && require("tty").isatty(1) && env.TERM !== "dumb" || "CI" in env);
40
+ var formatter = (open, close, replace = open) => (input) => {
41
+ let string = "" + input;
42
+ let index = string.indexOf(close, open.length);
43
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
44
+ };
45
+ var replaceClose = (string, close, replace, index) => {
46
+ let result = "";
47
+ let cursor = 0;
48
+ do {
49
+ result += string.substring(cursor, index) + replace;
50
+ cursor = index + close.length;
51
+ index = string.indexOf(close, cursor);
52
+ } while (~index);
53
+ return result + string.substring(cursor);
54
+ };
55
+ var createColors = (enabled = isColorSupported) => {
56
+ let init = enabled ? formatter : () => String;
57
+ return {
58
+ isColorSupported: enabled,
59
+ reset: init("\x1B[0m", "\x1B[0m"),
60
+ bold: init("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
61
+ dim: init("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
62
+ italic: init("\x1B[3m", "\x1B[23m"),
63
+ underline: init("\x1B[4m", "\x1B[24m"),
64
+ inverse: init("\x1B[7m", "\x1B[27m"),
65
+ hidden: init("\x1B[8m", "\x1B[28m"),
66
+ strikethrough: init("\x1B[9m", "\x1B[29m"),
67
+ black: init("\x1B[30m", "\x1B[39m"),
68
+ red: init("\x1B[31m", "\x1B[39m"),
69
+ green: init("\x1B[32m", "\x1B[39m"),
70
+ yellow: init("\x1B[33m", "\x1B[39m"),
71
+ blue: init("\x1B[34m", "\x1B[39m"),
72
+ magenta: init("\x1B[35m", "\x1B[39m"),
73
+ cyan: init("\x1B[36m", "\x1B[39m"),
74
+ white: init("\x1B[37m", "\x1B[39m"),
75
+ gray: init("\x1B[90m", "\x1B[39m"),
76
+ bgBlack: init("\x1B[40m", "\x1B[49m"),
77
+ bgRed: init("\x1B[41m", "\x1B[49m"),
78
+ bgGreen: init("\x1B[42m", "\x1B[49m"),
79
+ bgYellow: init("\x1B[43m", "\x1B[49m"),
80
+ bgBlue: init("\x1B[44m", "\x1B[49m"),
81
+ bgMagenta: init("\x1B[45m", "\x1B[49m"),
82
+ bgCyan: init("\x1B[46m", "\x1B[49m"),
83
+ bgWhite: init("\x1B[47m", "\x1B[49m")
84
+ };
85
+ };
86
+ module2.exports = createColors();
87
+ module2.exports.createColors = createColors;
88
+ }
89
+ });
90
+
91
+ // src/webpack.ts
92
+ var webpack_exports = {};
93
+ __export(webpack_exports, {
94
+ default: () => webpack_default
95
+ });
96
+ module.exports = __toCommonJS(webpack_exports);
97
+ var import_unplugin2 = require("unplugin");
98
+
99
+ // src/index.ts
100
+ var import_node_child_process = require("child_process");
101
+ var import_node_process = __toESM(require("process"), 1);
102
+ var import_unplugin = require("unplugin");
103
+ var import_picocolors = __toESM(require_picocolors(), 1);
104
+
105
+ // node_modules/.pnpm/vite-plugin-vconsole@2.1.1/node_modules/vite-plugin-vconsole/dist/main.mjs
106
+ var parseVConsoleOptions = (config2) => Object.keys(config2).reduce((code, key) => {
107
+ const value = config2[key];
108
+ if (typeof value === "function") {
109
+ if (/^[(f]/.test(value.toString())) {
110
+ code += `${key}: ${value},`;
111
+ return code;
112
+ } else {
113
+ code += `${value},`;
114
+ return code;
115
+ }
116
+ }
117
+ code += `${key}: ${JSON.stringify(config2[key])},`;
118
+ return code;
119
+ }, "");
120
+ var getEventItems = (event, id) => {
121
+ return event.map(
122
+ (ele) => `
123
+ ${id}.on('${ele.eventName}', ${ele.callback})
124
+ `
125
+ ).join(";");
126
+ };
127
+ var getDynamicConfig = (dynamicConfig) => {
128
+ let configString = "";
129
+ if (!dynamicConfig) {
130
+ return configString;
131
+ }
132
+ for (const key in dynamicConfig) {
133
+ if (typeof dynamicConfig[key] === "string") {
134
+ configString += `${key}: ${dynamicConfig[key]},`;
135
+ }
136
+ }
137
+ return configString;
138
+ };
139
+ var getPlugins = (plugin) => {
140
+ let plugins = "";
141
+ if (plugin && plugin.length) {
142
+ plugins = plugin.map(
143
+ (e) => `
144
+ const ${e.id} = new VConsole.VConsolePlugin('${e.id}', '${e.name}');
145
+ ${getEventItems(e.event, e.id)}
146
+ vConsole.addPlugin(${e.id})
147
+ `
148
+ ).join(";");
149
+ }
150
+ return plugins;
151
+ };
152
+ function viteVConsole(opt) {
153
+ const {
154
+ entry,
155
+ enabled = true,
156
+ config: config2 = {},
157
+ plugin,
158
+ customHide = false,
159
+ dynamicConfig = {},
160
+ eventListener = ""
161
+ } = opt;
162
+ let entryPath = Array.isArray(entry) ? entry : [entry];
163
+ if (process.platform === "win32")
164
+ entryPath = entryPath.map((item) => item.replace(/\\/g, "/"));
165
+ const enabledTruly = enabled;
166
+ return {
167
+ name: "vite:vconsole",
168
+ enforce: "pre",
169
+ transform(_source, id) {
170
+ if (entryPath.includes(id) && enabledTruly) {
171
+ const code = `/* eslint-disable */;
172
+ import VConsole from 'vconsole';
173
+ // config
174
+ const vConsole = new VConsole({${parseVConsoleOptions(
175
+ config2
176
+ )}});
177
+ window.vConsole = vConsole;
178
+
179
+ // plugins
180
+ ${getPlugins(plugin)}
181
+
182
+ // dynamic config
183
+ window.vConsole.dynamicFunction = function() {
184
+ if (${getDynamicConfig(dynamicConfig).length > 0}) {
185
+ vConsole.setOption({${getDynamicConfig(dynamicConfig)}});
186
+ }
187
+ };
188
+
189
+ window.vConsole.dynamicChange = {
190
+ value: new Date().getTime()
191
+ };
192
+
193
+ window.vConsole.dynamicFunction();
194
+
195
+ if (${customHide}) {
196
+ vConsole.hideSwitch();
197
+ }
198
+
199
+ // In order to be compatible with old equipment, I used defineProperty. In the future, when proxy covers enough devices, proxy will be used.
200
+ Object.defineProperty(window.vConsole.dynamicChange, 'value', {
201
+ get: function() {
202
+ return this._value;
203
+ },
204
+ set: function(newValue) {
205
+ window.vConsole.dynamicFunction();
206
+ this._value = newValue;
207
+ }
208
+ });
209
+
210
+ // eventListener
211
+ ${eventListener}
212
+ /* eslint-enable */${_source}`;
213
+ return {
214
+ code,
215
+ map: null
216
+ // support source map
217
+ };
218
+ }
219
+ return {
220
+ code: _source,
221
+ map: null
222
+ // support source map
223
+ };
224
+ }
225
+ };
226
+ }
227
+
228
+ // src/index.ts
229
+ var config;
230
+ var devtoolsInstance;
231
+ var colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
232
+ var unpluginFactory = (options) => {
233
+ var _a;
234
+ const unpluginDing = {
235
+ name: "unplugin-dingtalk",
236
+ enforce: "pre",
237
+ transformInclude(id) {
238
+ return id.endsWith("main.ts") || id.endsWith("main.js");
239
+ },
240
+ transform(_source) {
241
+ var _a2, _b, _c;
242
+ if ((_a2 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a2.enable) {
243
+ const code = `/* eslint-disable */;
244
+ import { devtools } from '@vue/devtools'
245
+ devtools.connect(${(_b = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _b.host}, ${(_c = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _c.port})
246
+ /* eslint-enable */${_source};
247
+ `;
248
+ return {
249
+ code,
250
+ map: null
251
+ // support source map
252
+ };
253
+ }
254
+ return {
255
+ code: _source,
256
+ map: null
257
+ // support source map
258
+ };
259
+ },
260
+ vite: {
261
+ configResolved(_config) {
262
+ config = _config;
263
+ },
264
+ configureServer(server) {
265
+ var _a2, _b;
266
+ if (!(options == null ? void 0 : options.enable)) {
267
+ return;
268
+ }
269
+ function debug(...args) {
270
+ if (options == null ? void 0 : options.debug) {
271
+ console.log(` ${import_picocolors.default.yellow("DEBUG")} `, ...args);
272
+ }
273
+ }
274
+ const _printUrls = server.printUrls.bind(server);
275
+ let source = `localhost:${config.server.port || 5173}`;
276
+ const url = (_a2 = server.resolvedUrls) == null ? void 0 : _a2.local[0];
277
+ if (url) {
278
+ const u = new URL(url);
279
+ source = u.host;
280
+ }
281
+ const base = server.config.base || "/";
282
+ const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
283
+ server.printUrls = () => {
284
+ var _a3;
285
+ _printUrls();
286
+ console.log(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold(
287
+ `Open in dingtalk${((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) ? " (with vue-devtools)" : ""}`
288
+ )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
289
+ };
290
+ const targetURL = new URL(_targetUrl);
291
+ targetURL.searchParams.append("ddtab", "true");
292
+ if (options == null ? void 0 : options.corpId) {
293
+ targetURL.searchParams.append("corpId", options.corpId);
294
+ }
295
+ server.middlewares.use("/open-dingtalk", (req, res) => {
296
+ var _a3;
297
+ debug(targetURL.toString());
298
+ res.writeHead(302, {
299
+ Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
300
+ });
301
+ if (((_a3 = options == null ? void 0 : options.vueDevtools) == null ? void 0 : _a3.enable) && !devtoolsInstance) {
302
+ devtoolsInstance = (0, import_node_child_process.exec)("npx vue-devtools");
303
+ console.log(` ${import_picocolors.default.green("\u279C")} vue-devtools is running. If the devtools has no data, please refresh the page in dingtalk.`);
304
+ devtoolsInstance.on("exit", () => {
305
+ devtoolsInstance = void 0;
306
+ });
307
+ import_node_process.default.on("exit", () => {
308
+ if (devtoolsInstance) {
309
+ devtoolsInstance.kill();
310
+ }
311
+ });
312
+ }
313
+ res.end();
314
+ });
315
+ }
316
+ }
317
+ };
318
+ if ((options == null ? void 0 : options.enable) && ((_a = options == null ? void 0 : options.vconsole) == null ? void 0 : _a.enabled)) {
319
+ return [viteVConsole(options == null ? void 0 : options.vconsole), unpluginDing];
320
+ } else {
321
+ return unpluginDing;
322
+ }
323
+ };
324
+
325
+ // src/webpack.ts
326
+ var webpack_default = (0, import_unplugin2.createWebpackPlugin)(unpluginFactory);
327
+ exports.default = module.exports;
@@ -0,0 +1,7 @@
1
+ import * as webpack from 'webpack';
2
+ import { Options } from './types.cjs';
3
+ import 'vite-plugin-vconsole';
4
+
5
+ declare const _default: (options?: Options | undefined) => webpack.WebpackPluginInstance;
6
+
7
+ export { _default as default };
@@ -0,0 +1,7 @@
1
+ import * as webpack from 'webpack';
2
+ import { Options } from './types.js';
3
+ import 'vite-plugin-vconsole';
4
+
5
+ declare const _default: (options?: Options | undefined) => webpack.WebpackPluginInstance;
6
+
7
+ export { _default as default };
@@ -0,0 +1,7 @@
1
+ import {
2
+ webpack_default
3
+ } from "./chunk-KYZ5HD2N.js";
4
+ import "./chunk-I4UPMGWK.js";
5
+ export {
6
+ webpack_default as default
7
+ };
package/package.json ADDED
@@ -0,0 +1,155 @@
1
+ {
2
+ "name": "unplugin-dingtalk",
3
+ "type": "module",
4
+ "version": "0.1.1",
5
+ "description": "",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/zcf0508/unplugin-dingtalk#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/zcf0508/unplugin-dingtalk.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/zcf0508/unplugin-dingtalk/issues"
14
+ },
15
+ "keywords": [
16
+ "unplugin",
17
+ "vite",
18
+ "webpack",
19
+ "rollup",
20
+ "transform"
21
+ ],
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.cjs"
27
+ },
28
+ "./astro": {
29
+ "types": "./dist/astro.d.ts",
30
+ "import": "./dist/astro.js",
31
+ "require": "./dist/astro.cjs"
32
+ },
33
+ "./rspack": {
34
+ "types": "./dist/rspack.d.ts",
35
+ "import": "./dist/rspack.js",
36
+ "require": "./dist/rspack.cjs"
37
+ },
38
+ "./vite": {
39
+ "types": "./dist/vite.d.ts",
40
+ "import": "./dist/vite.js",
41
+ "require": "./dist/vite.cjs"
42
+ },
43
+ "./webpack": {
44
+ "types": "./dist/webpack.d.ts",
45
+ "import": "./dist/webpack.js",
46
+ "require": "./dist/webpack.cjs"
47
+ },
48
+ "./rollup": {
49
+ "types": "./dist/rollup.d.ts",
50
+ "import": "./dist/rollup.js",
51
+ "require": "./dist/rollup.cjs"
52
+ },
53
+ "./esbuild": {
54
+ "types": "./dist/esbuild.d.ts",
55
+ "import": "./dist/esbuild.js",
56
+ "require": "./dist/esbuild.cjs"
57
+ },
58
+ "./nuxt": {
59
+ "types": "./dist/nuxt.d.ts",
60
+ "import": "./dist/nuxt.js",
61
+ "require": "./dist/nuxt.cjs"
62
+ },
63
+ "./types": {
64
+ "types": "./dist/types.d.ts",
65
+ "import": "./dist/types.js",
66
+ "require": "./dist/types.cjs"
67
+ },
68
+ "./*": "./*"
69
+ },
70
+ "main": "dist/index.cjs",
71
+ "module": "dist/index.js",
72
+ "types": "dist/index.d.ts",
73
+ "typesVersions": {
74
+ "*": {
75
+ "*": [
76
+ "./dist/*",
77
+ "./*"
78
+ ]
79
+ }
80
+ },
81
+ "files": [
82
+ "dist"
83
+ ],
84
+ "scripts": {
85
+ "build": "tsup",
86
+ "dev": "tsup --watch src",
87
+ "build:fix": "esno scripts/postbuild.ts",
88
+ "lint": "eslint .",
89
+ "play": "npm -C playground run dev",
90
+ "prepublishOnly": "npm run build",
91
+ "release": "bumpp && npm publish",
92
+ "start": "esno src/index.ts",
93
+ "test": "vitest"
94
+ },
95
+ "peerDependencies": {
96
+ "@nuxt/kit": "^3",
97
+ "@nuxt/schema": "^3",
98
+ "@vue/devtools": "^7.2.1",
99
+ "esbuild": "*",
100
+ "rollup": "^3",
101
+ "vconsole": "^3.15.1",
102
+ "vite": ">=3",
103
+ "webpack": "^4 || ^5"
104
+ },
105
+ "peerDependenciesMeta": {
106
+ "@nuxt/kit": {
107
+ "optional": true
108
+ },
109
+ "@nuxt/schema": {
110
+ "optional": true
111
+ },
112
+ "@vue/devtools": {
113
+ "optional": true
114
+ },
115
+ "esbuild": {
116
+ "optional": true
117
+ },
118
+ "rollup": {
119
+ "optional": true
120
+ },
121
+ "vconsole": {
122
+ "optional": true
123
+ },
124
+ "vite": {
125
+ "optional": true
126
+ },
127
+ "webpack": {
128
+ "optional": true
129
+ }
130
+ },
131
+ "dependencies": {
132
+ "@antfu/eslint-config": "^2.18.1",
133
+ "eslint-plugin-security": "^3.0.0",
134
+ "unplugin": "^1.5.1"
135
+ },
136
+ "devDependencies": {
137
+ "@nuxt/kit": "^3.8.2",
138
+ "@nuxt/schema": "^3.8.2",
139
+ "@types/node": "^20.10.3",
140
+ "bumpp": "^9.2.0",
141
+ "chalk": "^5.3.0",
142
+ "eslint": "^8.55.0",
143
+ "esno": "^4.0.0",
144
+ "fast-glob": "^3.3.2",
145
+ "nodemon": "^3.0.2",
146
+ "picocolors": "^1.0.1",
147
+ "rimraf": "^5.0.5",
148
+ "rollup": "^4.6.1",
149
+ "tsup": "^8.0.1",
150
+ "vite": "^5.0.4",
151
+ "vite-plugin-vconsole": "^2.1.1",
152
+ "vitest": "^0.34.6",
153
+ "webpack": "^5.89.0"
154
+ }
155
+ }