jialh
2025-01-07 bb59b053247ef82969b64979260e2478bd732e1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveSourceMapPath = exports.pathToGlob = exports.normalizeParsePlugins = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isRunningWithYarnPnp = exports.hash = void 0;
const fs_1 = __importDefault(require("fs"));
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
const shared_1 = require("@vue/shared");
var hash_sum_1 = require("hash-sum");
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return __importDefault(hash_sum_1).default; } });
const constants_1 = require("./constants");
const platform_1 = require("./platform");
try {
    exports.isRunningWithYarnPnp = Boolean(require('pnpapi'));
}
catch (_a) { }
exports.isWindows = os_1.default.platform() === 'win32';
function normalizePath(id) {
    return exports.isWindows ? id.replace(/\\/g, '/') : id;
}
exports.normalizePath = normalizePath;
function checkElementNodeTag(node, tag) {
    return !!node && node.type === 1 /* NodeTypes.ELEMENT */ && node.tag === tag;
}
exports.checkElementNodeTag = checkElementNodeTag;
function normalizeIdentifier(str) {
    return (0, shared_1.capitalize)((0, shared_1.camelize)(str.replace(/\//g, '-')));
}
exports.normalizeIdentifier = normalizeIdentifier;
function normalizePagePath(pagePath, platform) {
    const absoltePagePath = path_1.default.resolve(process.env.UNI_INPUT_DIR, pagePath);
    let extnames = constants_1.PAGE_EXTNAME;
    if (platform === 'app') {
        extnames = constants_1.PAGE_EXTNAME_APP;
    }
    for (let i = 0; i < extnames.length; i++) {
        const extname = extnames[i];
        if (fs_1.default.existsSync(absoltePagePath + extname)) {
            return pagePath + extname;
        }
    }
    console.error(`${pagePath} not found`);
}
exports.normalizePagePath = normalizePagePath;
function removeExt(str) {
    return str.split('?')[0].replace(/\.\w+$/g, '');
}
exports.removeExt = removeExt;
const NODE_MODULES_REGEX = /(\.\.\/)?node_modules/g;
function normalizeNodeModules(str) {
    str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules');
    // HBuilderX 内置模块路径转换
    str = str.replace(/.*\/plugins\/uniapp-cli-vite\/node[-_]modules/, 'node-modules');
    if (process.env.UNI_PLATFORM === 'mp-alipay') {
        str = str.replace('node-modules/@', 'node-modules/npm-scope-');
    }
    return str;
}
exports.normalizeNodeModules = normalizeNodeModules;
function normalizeMiniProgramFilename(filename, inputDir) {
    if (!inputDir || !path_1.default.isAbsolute(filename)) {
        return normalizeNodeModules(filename);
    }
    return normalizeNodeModules(path_1.default.relative(inputDir, filename));
}
exports.normalizeMiniProgramFilename = normalizeMiniProgramFilename;
function normalizeParsePlugins(importer, babelParserPlugins) {
    const isTS = constants_1.EXTNAME_TS_RE.test(importer.split('?')[0]);
    const plugins = [];
    if (isTS) {
        plugins.push('jsx');
    }
    if (babelParserPlugins)
        plugins.push(...babelParserPlugins);
    if (isTS)
        plugins.push('typescript', 'decorators-legacy');
    return plugins;
}
exports.normalizeParsePlugins = normalizeParsePlugins;
function pathToGlob(pathString, glob, options = {}) {
    const isWindows = 'windows' in options ? options.windows : /^win/.test(process.platform);
    const useEscape = options.escape;
    const str = isWindows ? pathString.replace(/\\/g, '/') : pathString;
    let safeStr = str.replace(/[\\*?[\]{}()!]/g, isWindows || !useEscape ? '[$&]' : '\\$&');
    return path_1.default.posix.join(safeStr, glob);
}
exports.pathToGlob = pathToGlob;
function resolveSourceMapPath() {
    return path_1.default.resolve(process.env.UNI_OUTPUT_DIR, '../.sourcemap/' + (0, platform_1.getPlatformDir)());
}
exports.resolveSourceMapPath = resolveSourceMapPath;