@qse/edu-scripts 1.14.10 → 1.14.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # 更新日志
2
2
 
3
+ ## 1.14.11 (2025-05-12)
4
+
5
+ - feat: 优化热更新能力,适配 v1 环境
6
+
3
7
  ## 1.14.10 (2025-05-08)
4
8
 
5
9
  - feat: 部署增加文曲智阅(钉钉一方化)
@@ -0,0 +1,118 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/config/plugins/ws-utils-createSocketURL.js
20
+ var ws_utils_createSocketURL_exports = {};
21
+ __export(ws_utils_createSocketURL_exports, {
22
+ default: () => ws_utils_createSocketURL_default
23
+ });
24
+ module.exports = __toCommonJS(ws_utils_createSocketURL_exports);
25
+ function format(objURL) {
26
+ var protocol = objURL.protocol || "";
27
+ if (protocol && protocol.substr(-1) !== ":") {
28
+ protocol += ":";
29
+ }
30
+ var auth = objURL.auth || "";
31
+ if (auth) {
32
+ auth = encodeURIComponent(auth);
33
+ auth = auth.replace(/%3A/i, ":");
34
+ auth += "@";
35
+ }
36
+ var host = "";
37
+ if (objURL.hostname) {
38
+ host = auth + (objURL.hostname.indexOf(":") === -1 ? objURL.hostname : "[".concat(objURL.hostname, "]"));
39
+ if (objURL.port) {
40
+ host += ":".concat(objURL.port);
41
+ }
42
+ }
43
+ var pathname = objURL.pathname || "";
44
+ if (objURL.slashes) {
45
+ host = "//".concat(host || "");
46
+ if (pathname && pathname.charAt(0) !== "/") {
47
+ pathname = "/".concat(pathname);
48
+ }
49
+ } else if (!host) {
50
+ host = "";
51
+ }
52
+ var search = objURL.search || "";
53
+ if (search && search.charAt(0) !== "?") {
54
+ search = "?".concat(search);
55
+ }
56
+ var hash = objURL.hash || "";
57
+ if (hash && hash.charAt(0) !== "#") {
58
+ hash = "#".concat(hash);
59
+ }
60
+ pathname = pathname.replace(
61
+ /[?#]/g,
62
+ /**
63
+ * @param {string} match
64
+ * @returns {string}
65
+ */
66
+ function(match) {
67
+ return encodeURIComponent(match);
68
+ }
69
+ );
70
+ search = search.replace("#", "%23");
71
+ return "".concat(protocol).concat(host).concat(pathname).concat(search).concat(hash);
72
+ }
73
+ function createSocketURL(parsedURL) {
74
+ var hostname = parsedURL.hostname;
75
+ var isInAddrAny = hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]";
76
+ if (isInAddrAny && self.location.hostname && self.location.protocol.indexOf("http") === 0) {
77
+ hostname = self.location.hostname;
78
+ }
79
+ var socketURLProtocol = parsedURL.protocol || self.location.protocol;
80
+ if (socketURLProtocol === "auto:" || hostname && isInAddrAny && self.location.protocol === "https:") {
81
+ socketURLProtocol = self.location.protocol;
82
+ }
83
+ socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, "ws");
84
+ var socketURLAuth = "";
85
+ if (parsedURL.username) {
86
+ socketURLAuth = parsedURL.username;
87
+ if (parsedURL.password) {
88
+ socketURLAuth = socketURLAuth.concat(":", parsedURL.password);
89
+ }
90
+ }
91
+ var socketURLHostname = (hostname || self.location.hostname || "localhost").replace(
92
+ /^\[(.*)\]$/,
93
+ "$1"
94
+ );
95
+ var socketURLPort = parsedURL.port;
96
+ if (!socketURLPort || socketURLPort === "0") {
97
+ socketURLPort = self.location.port;
98
+ }
99
+ var socketURLPathname = "/ws";
100
+ if (parsedURL.pathname && !parsedURL.fromCurrentScript) {
101
+ socketURLPathname = parsedURL.pathname;
102
+ if (hostname.indexOf("zhidianbao.cn") > -1 || hostname.indexOf("qsban.cn") > -1) {
103
+ var ctx = self.location.pathname.split("/")[1];
104
+ if (ctx) {
105
+ socketURLPathname = "/" + ctx + socketURLPathname;
106
+ }
107
+ }
108
+ }
109
+ return format({
110
+ protocol: socketURLProtocol,
111
+ auth: socketURLAuth,
112
+ hostname: socketURLHostname,
113
+ port: socketURLPort,
114
+ pathname: socketURLPathname,
115
+ slashes: true
116
+ });
117
+ }
118
+ var ws_utils_createSocketURL_default = createSocketURL;
@@ -1,3 +1,26 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+
1
24
  // src/config/webpackConfig.js
2
25
  var fs = require("fs");
3
26
  var webpack = require("webpack");
@@ -318,6 +341,11 @@ module.exports = function getWebpackConfig(args, override) {
318
341
  qseCDN.isUseCommon && new webpack.DllReferencePlugin({
319
342
  manifest: require("../asset/dll/libcommon3-manifest.json")
320
343
  }),
344
+ new webpack.NormalModuleReplacementPlugin(/createSocketURL\.js$/, (resource) => {
345
+ if (resource.context.includes("webpack-dev-server")) {
346
+ resource.request = require.resolve("./plugins/ws-utils-createSocketURL");
347
+ }
348
+ }),
321
349
  new webpack.IgnorePlugin({
322
350
  resourceRegExp: /^\.\/locale$/,
323
351
  contextRegExp: /moment$/
@@ -327,8 +355,6 @@ module.exports = function getWebpackConfig(args, override) {
327
355
  "process.env.APP_VERSION": JSON.stringify(appPkg.version),
328
356
  "process.env.BABEL_ENV": JSON.stringify(process.env.BABEL_ENV),
329
357
  "process.env.BROWSERSLIST": JSON.stringify(process.env.BROWSERSLIST),
330
- "process.env.WDS_SOCKET_HOST": JSON.stringify(process.env.WDS_SOCKET_HOST),
331
- "process.env.WDS_SOCKET_PORT": JSON.stringify(process.env.WDS_SOCKET_PORT),
332
358
  ...override.define
333
359
  }),
334
360
  new webpack.ProgressPlugin(),
@@ -3,8 +3,6 @@ var WebpackDevServer = require("webpack-dev-server");
3
3
  var setupMockServer = require("./plugins/mock-server");
4
4
  module.exports = function getWebpackDevServerConfig(args, override) {
5
5
  const host = process.env.HOST || "0.0.0.0";
6
- const sockHost = process.env.WDS_SOCKET_HOST;
7
- const sockPort = process.env.WDS_SOCKET_PORT;
8
6
  const devServer = {
9
7
  hot: true,
10
8
  allowedHosts: "all",
@@ -13,7 +11,7 @@ module.exports = function getWebpackDevServerConfig(args, override) {
13
11
  open: args.open,
14
12
  host,
15
13
  client: {
16
- webSocketURL: { protocol: "auto:", hostname: sockHost, port: sockPort },
14
+ webSocketURL: "auto://0.0.0.0:0/ws",
17
15
  overlay: {
18
16
  runtimeErrors: false,
19
17
  errors: true,
package/lib/start.js CHANGED
@@ -10,14 +10,12 @@ var WebpackDevServer = require("webpack-dev-server");
10
10
  var webpack = require("webpack");
11
11
  var getConfig = require("./utils/getConfig");
12
12
  var chalk = require("chalk");
13
- process.env.WDS_SOCKET_HOST = WebpackDevServer.internalIPSync("v4") || "127.0.0.1";
14
13
  module.exports = async function start(args) {
15
14
  const basePort = process.env.WEBPACK_DEV_SERVER_BASE_PORT;
16
15
  const port = await WebpackDevServer.getFreePort(args.port || process.env.PORT);
17
16
  if (!(args.port || process.env.PORT) && +port !== +basePort) {
18
17
  console.log(chalk.bgYellow(`${basePort} 端口已被占用,现切换到 ${port} 端口运行`));
19
18
  }
20
- process.env.WDS_SOCKET_PORT = port;
21
19
  args.port = port;
22
20
  process.env.PORT = port;
23
21
  const compiler = webpack(getConfig(args));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qse/edu-scripts",
3
- "version": "1.14.10",
3
+ "version": "1.14.11",
4
4
  "author": "Kinoko",
5
5
  "license": "MIT",
6
6
  "description": "教育工程化基础框架",
@@ -0,0 +1,140 @@
1
+ /* eslint-disable no-restricted-globals */
2
+
3
+ /**
4
+ * @param {{ protocol?: string, auth?: string, hostname?: string, port?: string, pathname?: string, search?: string, hash?: string, slashes?: boolean }} objURL
5
+ * @returns {string}
6
+ */
7
+ function format(objURL) {
8
+ var protocol = objURL.protocol || ''
9
+ if (protocol && protocol.substr(-1) !== ':') {
10
+ protocol += ':'
11
+ }
12
+ var auth = objURL.auth || ''
13
+ if (auth) {
14
+ auth = encodeURIComponent(auth)
15
+ auth = auth.replace(/%3A/i, ':')
16
+ auth += '@'
17
+ }
18
+ var host = ''
19
+ if (objURL.hostname) {
20
+ host =
21
+ auth +
22
+ (objURL.hostname.indexOf(':') === -1 ? objURL.hostname : '['.concat(objURL.hostname, ']'))
23
+ if (objURL.port) {
24
+ host += ':'.concat(objURL.port)
25
+ }
26
+ }
27
+ var pathname = objURL.pathname || ''
28
+ if (objURL.slashes) {
29
+ host = '//'.concat(host || '')
30
+ if (pathname && pathname.charAt(0) !== '/') {
31
+ pathname = '/'.concat(pathname)
32
+ }
33
+ } else if (!host) {
34
+ host = ''
35
+ }
36
+ var search = objURL.search || ''
37
+ if (search && search.charAt(0) !== '?') {
38
+ search = '?'.concat(search)
39
+ }
40
+ var hash = objURL.hash || ''
41
+ if (hash && hash.charAt(0) !== '#') {
42
+ hash = '#'.concat(hash)
43
+ }
44
+ pathname = pathname.replace(
45
+ /[?#]/g,
46
+ /**
47
+ * @param {string} match
48
+ * @returns {string}
49
+ */
50
+ function (match) {
51
+ return encodeURIComponent(match)
52
+ }
53
+ )
54
+ search = search.replace('#', '%23')
55
+ return ''.concat(protocol).concat(host).concat(pathname).concat(search).concat(hash)
56
+ }
57
+
58
+ /**
59
+ * @param {URL & { fromCurrentScript?: boolean }} parsedURL
60
+ * @returns {string}
61
+ */
62
+ function createSocketURL(parsedURL) {
63
+ var hostname = parsedURL.hostname
64
+
65
+ // Node.js module parses it as `::`
66
+ // `new URL(urlString, [baseURLString])` parses it as '[::]'
67
+ var isInAddrAny = hostname === '0.0.0.0' || hostname === '::' || hostname === '[::]'
68
+
69
+ // why do we need this check?
70
+ // hostname n/a for file protocol (example, when using electron, ionic)
71
+ // see: https://github.com/webpack/webpack-dev-server/pull/384
72
+ if (isInAddrAny && self.location.hostname && self.location.protocol.indexOf('http') === 0) {
73
+ hostname = self.location.hostname
74
+ }
75
+ var socketURLProtocol = parsedURL.protocol || self.location.protocol
76
+
77
+ // When https is used in the app, secure web sockets are always necessary because the browser doesn't accept non-secure web sockets.
78
+ if (
79
+ socketURLProtocol === 'auto:' ||
80
+ (hostname && isInAddrAny && self.location.protocol === 'https:')
81
+ ) {
82
+ socketURLProtocol = self.location.protocol
83
+ }
84
+ socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, 'ws')
85
+ var socketURLAuth = ''
86
+
87
+ // `new URL(urlString, [baseURLstring])` doesn't have `auth` property
88
+ // Parse authentication credentials in case we need them
89
+ if (parsedURL.username) {
90
+ socketURLAuth = parsedURL.username
91
+
92
+ // Since HTTP basic authentication does not allow empty username,
93
+ // we only include password if the username is not empty.
94
+ if (parsedURL.password) {
95
+ // Result: <username>:<password>
96
+ socketURLAuth = socketURLAuth.concat(':', parsedURL.password)
97
+ }
98
+ }
99
+
100
+ // In case the host is a raw IPv6 address, it can be enclosed in
101
+ // the brackets as the brackets are needed in the final URL string.
102
+ // Need to remove those as url.format blindly adds its own set of brackets
103
+ // if the host string contains colons. That would lead to non-working
104
+ // double brackets (e.g. [[::]]) host
105
+ //
106
+ // All of these web socket url params are optionally passed in through resourceQuery,
107
+ // so we need to fall back to the default if they are not provided
108
+ var socketURLHostname = (hostname || self.location.hostname || 'localhost').replace(
109
+ /^\[(.*)\]$/,
110
+ '$1'
111
+ )
112
+ var socketURLPort = parsedURL.port
113
+ if (!socketURLPort || socketURLPort === '0') {
114
+ socketURLPort = self.location.port
115
+ }
116
+
117
+ // If path is provided it'll be passed in via the resourceQuery as a
118
+ // query param so it has to be parsed out of the querystring in order for the
119
+ // client to open the socket to the correct location.
120
+ var socketURLPathname = '/ws'
121
+ if (parsedURL.pathname && !parsedURL.fromCurrentScript) {
122
+ socketURLPathname = parsedURL.pathname
123
+
124
+ if (hostname.indexOf('zhidianbao.cn') > -1 || hostname.indexOf('qsban.cn') > -1) {
125
+ var ctx = self.location.pathname.split('/')[1]
126
+ if (ctx) {
127
+ socketURLPathname = '/' + ctx + socketURLPathname
128
+ }
129
+ }
130
+ }
131
+ return format({
132
+ protocol: socketURLProtocol,
133
+ auth: socketURLAuth,
134
+ hostname: socketURLHostname,
135
+ port: socketURLPort,
136
+ pathname: socketURLPathname,
137
+ slashes: true,
138
+ })
139
+ }
140
+ export default createSocketURL
@@ -340,6 +340,11 @@ module.exports = function getWebpackConfig(args, override) {
340
340
  new webpack.DllReferencePlugin({
341
341
  manifest: require('../asset/dll/libcommon3-manifest.json'),
342
342
  }),
343
+ new webpack.NormalModuleReplacementPlugin(/createSocketURL\.js$/, (resource) => {
344
+ if (resource.context.includes('webpack-dev-server')) {
345
+ resource.request = require.resolve('./plugins/ws-utils-createSocketURL')
346
+ }
347
+ }),
343
348
  new webpack.IgnorePlugin({
344
349
  resourceRegExp: /^\.\/locale$/,
345
350
  contextRegExp: /moment$/,
@@ -349,8 +354,6 @@ module.exports = function getWebpackConfig(args, override) {
349
354
  'process.env.APP_VERSION': JSON.stringify(appPkg.version),
350
355
  'process.env.BABEL_ENV': JSON.stringify(process.env.BABEL_ENV),
351
356
  'process.env.BROWSERSLIST': JSON.stringify(process.env.BROWSERSLIST),
352
- 'process.env.WDS_SOCKET_HOST': JSON.stringify(process.env.WDS_SOCKET_HOST),
353
- 'process.env.WDS_SOCKET_PORT': JSON.stringify(process.env.WDS_SOCKET_PORT),
354
357
  ...override.define,
355
358
  }),
356
359
  new webpack.ProgressPlugin(),
@@ -7,8 +7,6 @@ const setupMockServer = require('./plugins/mock-server')
7
7
  */
8
8
  module.exports = function getWebpackDevServerConfig(args, override) {
9
9
  const host = process.env.HOST || '0.0.0.0'
10
- const sockHost = process.env.WDS_SOCKET_HOST
11
- const sockPort = process.env.WDS_SOCKET_PORT
12
10
 
13
11
  /** @type {WebpackDevServer.Configuration} */
14
12
  const devServer = {
@@ -19,7 +17,7 @@ module.exports = function getWebpackDevServerConfig(args, override) {
19
17
  open: args.open,
20
18
  host,
21
19
  client: {
22
- webSocketURL: { protocol: 'auto:', hostname: sockHost, port: sockPort },
20
+ webSocketURL: 'auto://0.0.0.0:0/ws',
23
21
  overlay: {
24
22
  runtimeErrors: false,
25
23
  errors: true,
package/src/start.js CHANGED
@@ -15,15 +15,12 @@ const webpack = require('webpack')
15
15
  const getConfig = require('./utils/getConfig')
16
16
  const chalk = require('chalk')
17
17
 
18
- process.env.WDS_SOCKET_HOST = WebpackDevServer.internalIPSync('v4') || '127.0.0.1'
19
-
20
18
  module.exports = async function start(args) {
21
19
  const basePort = process.env.WEBPACK_DEV_SERVER_BASE_PORT
22
20
  const port = await WebpackDevServer.getFreePort(args.port || process.env.PORT)
23
21
  if (!(args.port || process.env.PORT) && +port !== +basePort) {
24
22
  console.log(chalk.bgYellow(`${basePort} 端口已被占用,现切换到 ${port} 端口运行`))
25
23
  }
26
- process.env.WDS_SOCKET_PORT = port
27
24
  args.port = port
28
25
  process.env.PORT = port
29
26