WMS_PDA/scripts/node-compat.cjs
liufumingren 5ae92e0f63 chore(cli): 由 HBuilderX 工程迁移为 uni-app Vue2 CLI 脚手架工程
- 业务源码统一迁入 src/,H5 模板移到 public/index.html
- 新增 @vue/cli 4.5 + @dcloudio 2.0.2-5020620260917001 全套依赖与 scripts
- 保留 vue.config.js 的 ROUTES 注入(uni-simple-router 运行时依赖)
- 新增 scripts/node-compat.cjs 兼容 Node 23+ 移除的 util.isRegExp 等 API
- README 补充构建/运行/回退说明
2026-10-02 19:45:18 +08:00

53 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Node 兼容 shim(uni-app Vue2 工具链专用)
*
* 背景:Node 23+ 移除了历史遗留的 `util.isArray` / `util.isRegExp` 等 API,
* 而 uni-app Vue2 编译链依赖的 postcss-urlrewrite 等老包仍在调用它们,
* 在 Node 22+ 上执行 app-plus 构建会抛 `util.isRegExp is not a function`。
*
* 用法:通过 NODE_OPTIONS=--require=./scripts/node-compat.cjs 注入(见 package.json scripts)。
* 在 Node 16/18 下运行时所有 API 均存在,本文件自动变成空操作,无副作用。
*/
'use strict'
const util = require('util')
const toString = Object.prototype.toString
const shims = {
isArray: Array.isArray,
isBoolean: (v) => typeof v === 'boolean',
isBuffer: (v) => Buffer.isBuffer(v),
isDate: (v) => v instanceof Date,
isError: (v) => v instanceof Error || toString.call(v) === '[object Error]',
isFunction: (v) => typeof v === 'function',
isNull: (v) => v === null,
isNullOrUndefined: (v) => v === null || v === undefined,
isNumber: (v) => typeof v === 'number',
isObject: (v) => v !== null && typeof v === 'object',
isPrimitive: (v) => v === null || (typeof v !== 'object' && typeof v !== 'function'),
isRegExp: (v) => v instanceof RegExp,
isString: (v) => typeof v === 'string',
isSymbol: (v) => typeof v === 'symbol',
isUndefined: (v) => v === undefined
}
Object.keys(shims).forEach((name) => {
if (typeof util[name] !== 'function') {
util[name] = shims[name]
}
})
if (typeof util._extend !== 'function') {
util._extend = function _extend (target, source) {
if (source) {
for (const key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key]
}
}
}
return target
}
}