@deppon/deppon-monitor-webpack-plugin 2.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.
package/LICENSE ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,11 @@
1
+ (function() {
2
+ const env = {};
3
+ try {
4
+ if (process) {
5
+ process.env = Object.assign({}, process.env);
6
+ Object.assign(process.env, env);
7
+ return;
8
+ }
9
+ } catch (e) {} // avoid ReferenceError: process is not defined
10
+ globalThis.process = { env:env };
11
+ })();
package/es/index.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ export interface Options {
2
+ /**
3
+ * 项目唯一标识
4
+ * @default `package.json` name 字段
5
+ */
6
+ appName?: string;
7
+ /**
8
+ * 版本号,不同版本号对应不同的sourcemap
9
+ * @default `package.json` version 字段
10
+ */
11
+ version?: string;
12
+ /**
13
+ * 上传 sourcemap 的目录
14
+ * @default 'dist'
15
+ */
16
+ dir?: string;
17
+ }
18
+ /**
19
+ * @public
20
+ */
21
+ export declare class CBKMonitorSourceMapUploadWebpackPlugin {
22
+ private readonly options;
23
+ private readonly alioss;
24
+ constructor(options?: Options);
25
+ apply(compiler: any): void;
26
+ }
package/es/index.js ADDED
@@ -0,0 +1,138 @@
1
+ import './_virtual/_rollup-plugin-inject-process-env.js';
2
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
3
+ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
4
+ import _createClass from '@babel/runtime/helpers/createClass';
5
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
6
+ import AliOSS from 'ali-oss';
7
+ import fs from './node_modules/rollup-plugin-node-polyfills/polyfills/empty.js';
8
+ import path from './node_modules/rollup-plugin-node-polyfills/polyfills/path.js';
9
+
10
+ var _process$env = process.env,
11
+ ENDPOINT = _process$env.ENDPOINT,
12
+ ACCESSKEYID = _process$env.ACCESSKEYID,
13
+ ACCESSKEYSECRET = _process$env.ACCESSKEYSECRET,
14
+ BUCKET_SOURCEMAP = _process$env.BUCKET_SOURCEMAP;
15
+ var checkOSS = function checkOSS() {
16
+ try {
17
+ var secretPrefix = (ACCESSKEYSECRET === null || ACCESSKEYSECRET === void 0 ? void 0 : ACCESSKEYSECRET.slice(0, 4)) || '';
18
+ var secretSuffix = (ACCESSKEYSECRET === null || ACCESSKEYSECRET === void 0 ? void 0 : ACCESSKEYSECRET.slice(ACCESSKEYSECRET.length - 4, ACCESSKEYSECRET.length)) || '';
19
+ var secretMid = new Array(((ACCESSKEYSECRET === null || ACCESSKEYSECRET === void 0 ? void 0 : ACCESSKEYSECRET.length) || 0) - 8).fill('*').join('').toString();
20
+ } catch (e) {
21
+ }
22
+ if (!ENDPOINT || !ACCESSKEYID || !ACCESSKEYSECRET || !BUCKET_SOURCEMAP) {
23
+ return false;
24
+ }
25
+ return true;
26
+ };
27
+ var NAME = 'CBKMonitorSourceMapUploadWebpackPlugin';
28
+ /**
29
+ * @public
30
+ */
31
+ var CBKMonitorSourceMapUploadWebpackPlugin = /*#__PURE__*/function () {
32
+ function CBKMonitorSourceMapUploadWebpackPlugin() {
33
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
34
+ _classCallCheck(this, CBKMonitorSourceMapUploadWebpackPlugin);
35
+ this.options = options;
36
+ this.alioss = new AliOSS({
37
+ // yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
38
+ endpoint: ENDPOINT,
39
+ accessKeyId: ACCESSKEYID,
40
+ accessKeySecret: ACCESSKEYSECRET,
41
+ bucket: BUCKET_SOURCEMAP
42
+ });
43
+ if (!checkOSS()) return;
44
+ if (!options.appName || !options.version) {
45
+ var appDirectory = fs.realpathSync(process.cwd());
46
+ var monitorConfigPath = path.resolve(appDirectory, '../deppon-monitor-project.config.json');
47
+ if (!fs.existsSync(monitorConfigPath)) return;
48
+ var monitorConfigContent = fs.readFileSync(monitorConfigPath, 'utf-8');
49
+ var configContentJson = JSON.parse(monitorConfigContent);
50
+ var pkgContent = fs.readFileSync(path.resolve(process.cwd(), 'package.json'), 'utf-8');
51
+ var pkgJson = JSON.parse(pkgContent);
52
+ if (!options.appName) {
53
+ this.options.appName = pkgJson.name;
54
+ }
55
+ if (!options.version) {
56
+ this.options.version = configContentJson[pkgJson.name];
57
+ }
58
+ }
59
+ }
60
+ return _createClass(CBKMonitorSourceMapUploadWebpackPlugin, [{
61
+ key: "apply",
62
+ value: function apply(compiler) {
63
+ var _this = this;
64
+ if (!this.options.appName || !this.options.version) return;
65
+ if (process.env.NODE_ENV === 'development') return;
66
+ var callback = function callback(compilation) {
67
+ var dist = Object.keys(compilation.assets).filter(function (file) {
68
+ return file.includes('.js.map');
69
+ });
70
+ upload(dist, _this.options, _this.alioss);
71
+ };
72
+ compiler.hooks.afterEmit.tap(NAME, callback);
73
+ }
74
+ }]);
75
+ }();
76
+
77
+ /**
78
+ *
79
+ * @param dist - sourcemap文件名,如:static/js/xxx.js.map
80
+ * @param options - 配置项
81
+ * @internal
82
+ */
83
+ function upload(_x, _x2, _x3) {
84
+ return _upload.apply(this, arguments);
85
+ }
86
+ function _upload() {
87
+ _upload = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(dists, options, alioss) {
88
+ var appName, version, dir;
89
+ return _regeneratorRuntime.wrap(function (_context2) {
90
+ while (1) switch (_context2.prev = _context2.next) {
91
+ case 0:
92
+ appName = options.appName, version = options.version, dir = options.dir;
93
+ _context2.prev = 1;
94
+ _context2.next = 2;
95
+ return Promise.all(dists.map(/*#__PURE__*/function () {
96
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dist) {
97
+ var realpath, file, r;
98
+ return _regeneratorRuntime.wrap(function (_context) {
99
+ while (1) switch (_context.prev = _context.next) {
100
+ case 0:
101
+ realpath = path.join(process.cwd(), dir || 'dist', dist);
102
+ file = fs.readFileSync(realpath);
103
+ fs.rmSync(realpath);
104
+ _context.next = 1;
105
+ return alioss.put("monitor/sourcemap/".concat(appName, "/").concat(version || '1.0.0', "/").concat(path.basename(realpath)), file, {
106
+ headers: {
107
+ 'Content-type': 'multipart/form-data'
108
+ }
109
+ });
110
+ case 1:
111
+ r = _context.sent;
112
+ return _context.abrupt("return", r);
113
+ case 2:
114
+ case "end":
115
+ return _context.stop();
116
+ }
117
+ }, _callee);
118
+ }));
119
+ return function (_x4) {
120
+ return _ref.apply(this, arguments);
121
+ };
122
+ }()));
123
+ case 2:
124
+ _context2.next = 4;
125
+ break;
126
+ case 3:
127
+ _context2.prev = 3;
128
+ _context2["catch"](1);
129
+ case 4:
130
+ case "end":
131
+ return _context2.stop();
132
+ }
133
+ }, _callee2, null, [[1, 3]]);
134
+ }));
135
+ return _upload.apply(this, arguments);
136
+ }
137
+
138
+ export { CBKMonitorSourceMapUploadWebpackPlugin };
@@ -0,0 +1,5 @@
1
+ import '../../../_virtual/_rollup-plugin-inject-process-env.js';
2
+
3
+ var fs = {};
4
+
5
+ export { fs as default };
@@ -0,0 +1,236 @@
1
+ import '../../../_virtual/_rollup-plugin-inject-process-env.js';
2
+
3
+ // Copyright Joyent, Inc. and other Node contributors.
4
+ //
5
+ // Permission is hereby granted, free of charge, to any person obtaining a
6
+ // copy of this software and associated documentation files (the
7
+ // "Software"), to deal in the Software without restriction, including
8
+ // without limitation the rights to use, copy, modify, merge, publish,
9
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
10
+ // persons to whom the Software is furnished to do so, subject to the
11
+ // following conditions:
12
+ //
13
+ // The above copyright notice and this permission notice shall be included
14
+ // in all copies or substantial portions of the Software.
15
+ //
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ // resolves . and .. elements in a path array with directory names there
25
+ // must be no slashes, empty elements, or device names (c:\) in the array
26
+ // (so also no leading and trailing slashes - it does not distinguish
27
+ // relative and absolute paths)
28
+ function normalizeArray(parts, allowAboveRoot) {
29
+ // if the path tries to go above the root, `up` ends up > 0
30
+ var up = 0;
31
+ for (var i = parts.length - 1; i >= 0; i--) {
32
+ var last = parts[i];
33
+ if (last === '.') {
34
+ parts.splice(i, 1);
35
+ } else if (last === '..') {
36
+ parts.splice(i, 1);
37
+ up++;
38
+ } else if (up) {
39
+ parts.splice(i, 1);
40
+ up--;
41
+ }
42
+ }
43
+
44
+ // if the path is allowed to go above the root, restore leading ..s
45
+ if (allowAboveRoot) {
46
+ for (; up--; up) {
47
+ parts.unshift('..');
48
+ }
49
+ }
50
+
51
+ return parts;
52
+ }
53
+
54
+ // Split a filename into [root, dir, basename, ext], unix version
55
+ // 'root' is just a slash, or nothing.
56
+ var splitPathRe =
57
+ /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
58
+ var splitPath = function(filename) {
59
+ return splitPathRe.exec(filename).slice(1);
60
+ };
61
+
62
+ // path.resolve([from ...], to)
63
+ // posix version
64
+ function resolve() {
65
+ var resolvedPath = '',
66
+ resolvedAbsolute = false;
67
+
68
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
69
+ var path = (i >= 0) ? arguments[i] : '/';
70
+
71
+ // Skip empty and invalid entries
72
+ if (typeof path !== 'string') {
73
+ throw new TypeError('Arguments to path.resolve must be strings');
74
+ } else if (!path) {
75
+ continue;
76
+ }
77
+
78
+ resolvedPath = path + '/' + resolvedPath;
79
+ resolvedAbsolute = path.charAt(0) === '/';
80
+ }
81
+
82
+ // At this point the path should be resolved to a full absolute path, but
83
+ // handle relative paths to be safe (might happen when process.cwd() fails)
84
+
85
+ // Normalize the path
86
+ resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
87
+ return !!p;
88
+ }), !resolvedAbsolute).join('/');
89
+
90
+ return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
91
+ }
92
+ // path.normalize(path)
93
+ // posix version
94
+ function normalize(path) {
95
+ var isPathAbsolute = isAbsolute(path),
96
+ trailingSlash = substr(path, -1) === '/';
97
+
98
+ // Normalize the path
99
+ path = normalizeArray(filter(path.split('/'), function(p) {
100
+ return !!p;
101
+ }), !isPathAbsolute).join('/');
102
+
103
+ if (!path && !isPathAbsolute) {
104
+ path = '.';
105
+ }
106
+ if (path && trailingSlash) {
107
+ path += '/';
108
+ }
109
+
110
+ return (isPathAbsolute ? '/' : '') + path;
111
+ }
112
+ // posix version
113
+ function isAbsolute(path) {
114
+ return path.charAt(0) === '/';
115
+ }
116
+
117
+ // posix version
118
+ function join() {
119
+ var paths = Array.prototype.slice.call(arguments, 0);
120
+ return normalize(filter(paths, function(p, index) {
121
+ if (typeof p !== 'string') {
122
+ throw new TypeError('Arguments to path.join must be strings');
123
+ }
124
+ return p;
125
+ }).join('/'));
126
+ }
127
+
128
+
129
+ // path.relative(from, to)
130
+ // posix version
131
+ function relative(from, to) {
132
+ from = resolve(from).substr(1);
133
+ to = resolve(to).substr(1);
134
+
135
+ function trim(arr) {
136
+ var start = 0;
137
+ for (; start < arr.length; start++) {
138
+ if (arr[start] !== '') break;
139
+ }
140
+
141
+ var end = arr.length - 1;
142
+ for (; end >= 0; end--) {
143
+ if (arr[end] !== '') break;
144
+ }
145
+
146
+ if (start > end) return [];
147
+ return arr.slice(start, end - start + 1);
148
+ }
149
+
150
+ var fromParts = trim(from.split('/'));
151
+ var toParts = trim(to.split('/'));
152
+
153
+ var length = Math.min(fromParts.length, toParts.length);
154
+ var samePartsLength = length;
155
+ for (var i = 0; i < length; i++) {
156
+ if (fromParts[i] !== toParts[i]) {
157
+ samePartsLength = i;
158
+ break;
159
+ }
160
+ }
161
+
162
+ var outputParts = [];
163
+ for (var i = samePartsLength; i < fromParts.length; i++) {
164
+ outputParts.push('..');
165
+ }
166
+
167
+ outputParts = outputParts.concat(toParts.slice(samePartsLength));
168
+
169
+ return outputParts.join('/');
170
+ }
171
+
172
+ var sep = '/';
173
+ var delimiter = ':';
174
+
175
+ function dirname(path) {
176
+ var result = splitPath(path),
177
+ root = result[0],
178
+ dir = result[1];
179
+
180
+ if (!root && !dir) {
181
+ // No dirname whatsoever
182
+ return '.';
183
+ }
184
+
185
+ if (dir) {
186
+ // It has a dirname, strip trailing slash
187
+ dir = dir.substr(0, dir.length - 1);
188
+ }
189
+
190
+ return root + dir;
191
+ }
192
+
193
+ function basename(path, ext) {
194
+ var f = splitPath(path)[2];
195
+ // TODO: make this comparison case-insensitive on windows?
196
+ if (ext && f.substr(-1 * ext.length) === ext) {
197
+ f = f.substr(0, f.length - ext.length);
198
+ }
199
+ return f;
200
+ }
201
+
202
+
203
+ function extname(path) {
204
+ return splitPath(path)[3];
205
+ }
206
+ var path = {
207
+ extname: extname,
208
+ basename: basename,
209
+ dirname: dirname,
210
+ sep: sep,
211
+ delimiter: delimiter,
212
+ relative: relative,
213
+ join: join,
214
+ isAbsolute: isAbsolute,
215
+ normalize: normalize,
216
+ resolve: resolve
217
+ };
218
+ function filter (xs, f) {
219
+ if (xs.filter) return xs.filter(f);
220
+ var res = [];
221
+ for (var i = 0; i < xs.length; i++) {
222
+ if (f(xs[i], i, xs)) res.push(xs[i]);
223
+ }
224
+ return res;
225
+ }
226
+
227
+ // String.prototype.substr - negative index don't work in IE8
228
+ var substr = 'ab'.substr(-1) === 'b' ?
229
+ function (str, start, len) { return str.substr(start, len) } :
230
+ function (str, start, len) {
231
+ if (start < 0) start = str.length + start;
232
+ return str.substr(start, len);
233
+ }
234
+ ;
235
+
236
+ export { basename, path as default, delimiter, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@deppon/deppon-monitor-webpack-plugin",
3
+ "version": "2.1.1",
4
+ "description": "",
5
+ "main": "es/index.js",
6
+ "module": "es/index.js",
7
+ "typings": "es/index.d.ts",
8
+ "files": [
9
+ "es"
10
+ ],
11
+ "publishConfig": {
12
+ "registry": "https://devrepo.devcloud.cn-east-3.huaweicloud.com/artgalaxy/api/npm/cn-east-3_8a2e1f0ee52d4adb9a0a6998d78d0dda_npm_1/"
13
+ },
14
+ "scripts": {
15
+ "dev": "rollup -w -c",
16
+ "build": "rimraf es && rimraf lib && rollup -c && tsc --project tsconfig.json",
17
+ "publish:auto": "npm publish"
18
+ },
19
+ "keywords": [],
20
+ "author": {
21
+ "name": "",
22
+ "email": ""
23
+ },
24
+ "license": "ISC",
25
+ "devDependencies": {
26
+ "@types/ali-oss": "^6.16.7",
27
+ "@types/node": "^18.7.14"
28
+ },
29
+ "peerDependencies": {
30
+ "webpack": ">4.0.0"
31
+ },
32
+ "dependencies": {
33
+ "ali-oss": "^6.17.1",
34
+ "tslib": "^2.4.1"
35
+ },
36
+ "gitHead": "1f329a64567c2e22df7860b0918ebe3427718945"
37
+ }