210 lines
8.0 KiB
JavaScript
210 lines
8.0 KiB
JavaScript
"use strict";
|
||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
};
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
exports.resolveComponentsLibDirs = exports.resolveComponentsLibPath = exports.resolveVueI18nRuntimeAlias = exports.resolvePiniaAlias = exports.resolvePiniaDependencies = exports.resolveProjectPinia = exports.resolvePinia = exports.resolveVueI18nDependencies = exports.resolveProjectVueI18n = exports.resolveVueI18n = exports.resolveVueI18nRuntime = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.resolveMainUtsName = exports.requireResolve = void 0;
|
||
const fs_1 = __importDefault(require("fs"));
|
||
const path_1 = __importDefault(require("path"));
|
||
const debug_1 = __importDefault(require("debug"));
|
||
const resolve_1 = __importDefault(require("resolve"));
|
||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||
const utils_1 = require("./utils");
|
||
const env_1 = require("./hbx/env");
|
||
const constants_1 = require("./constants");
|
||
function requireResolve(filename, basedir) {
|
||
return resolveWithSymlinks(filename, basedir);
|
||
}
|
||
exports.requireResolve = requireResolve;
|
||
function resolveWithSymlinks(id, basedir) {
|
||
return resolve_1.default.sync(id, {
|
||
basedir,
|
||
extensions: process.env.UNI_APP_X === 'true' ? constants_1.uni_app_x_extensions : constants_1.extensions,
|
||
// necessary to work with pnpm
|
||
preserveSymlinks: true,
|
||
});
|
||
}
|
||
function resolveMainUtsName() {
|
||
if (process.env.UNI_COMPILE_TARGET === 'ext-api') {
|
||
return process.env.UNI_COMPILE_EXT_API_UVUE_ENTRY || 'main.uts';
|
||
}
|
||
return 'main.uts';
|
||
}
|
||
exports.resolveMainUtsName = resolveMainUtsName;
|
||
function relativeFile(from, to) {
|
||
const relativePath = (0, utils_1.normalizePath)(path_1.default.relative(path_1.default.dirname(from), to));
|
||
return relativePath.startsWith('.') ? relativePath : './' + relativePath;
|
||
}
|
||
exports.relativeFile = relativeFile;
|
||
exports.resolveMainPathOnce = (0, uni_shared_1.once)((inputDir) => {
|
||
if (process.env.UNI_APP_X === 'true') {
|
||
const mainUTSPath = path_1.default.resolve(inputDir, resolveMainUtsName());
|
||
if (fs_1.default.existsSync(mainUTSPath)) {
|
||
return (0, utils_1.normalizePath)(mainUTSPath);
|
||
}
|
||
}
|
||
const mainTsPath = path_1.default.resolve(inputDir, 'main.ts');
|
||
if (fs_1.default.existsSync(mainTsPath)) {
|
||
return (0, utils_1.normalizePath)(mainTsPath);
|
||
}
|
||
return (0, utils_1.normalizePath)(path_1.default.resolve(inputDir, 'main.js'));
|
||
});
|
||
const ownerModules = [
|
||
'@dcloudio/uni-app',
|
||
'@dcloudio/vite-plugin-uni',
|
||
'@dcloudio/uni-cli-shared',
|
||
];
|
||
const paths = [];
|
||
function resolveNodeModulePath(modulePath) {
|
||
const nodeModulesPaths = [];
|
||
const nodeModulesPath = path_1.default.join(modulePath, 'node_modules');
|
||
if (fs_1.default.existsSync(nodeModulesPath)) {
|
||
nodeModulesPaths.push(nodeModulesPath);
|
||
}
|
||
const index = modulePath.lastIndexOf('node_modules');
|
||
if (index > -1) {
|
||
nodeModulesPaths.push(path_1.default.join(modulePath.slice(0, index), 'node_modules'));
|
||
}
|
||
return nodeModulesPaths;
|
||
}
|
||
function initPaths() {
|
||
const cliContext = process.env.UNI_CLI_CONTEXT || process.cwd();
|
||
if (cliContext) {
|
||
const pathSet = new Set();
|
||
pathSet.add(path_1.default.join(cliContext, 'node_modules'));
|
||
if (!(0, env_1.isInHBuilderX)()) {
|
||
;
|
||
[`@dcloudio/uni-` + process.env.UNI_PLATFORM, ...ownerModules].forEach((ownerModule) => {
|
||
let pkgPath = '';
|
||
try {
|
||
pkgPath = require.resolve(ownerModule + '/package.json', {
|
||
paths: [cliContext],
|
||
});
|
||
}
|
||
catch (e) { }
|
||
if (pkgPath) {
|
||
resolveNodeModulePath(path_1.default.dirname(pkgPath)).forEach((nodeModulePath) => {
|
||
pathSet.add(nodeModulePath);
|
||
});
|
||
}
|
||
});
|
||
}
|
||
paths.push(...pathSet);
|
||
(0, debug_1.default)('uni-paths')(paths);
|
||
}
|
||
}
|
||
function getBuiltInPaths() {
|
||
if (!paths.length) {
|
||
initPaths();
|
||
}
|
||
return paths;
|
||
}
|
||
exports.getBuiltInPaths = getBuiltInPaths;
|
||
function resolveBuiltIn(module) {
|
||
if (process.env.UNI_COMPILE_TARGET === 'ext-api' &&
|
||
process.env.UNI_APP_NEXT_WORKSPACE &&
|
||
module.startsWith('@dcloudio/')) {
|
||
return path_1.default.resolve(process.env.UNI_APP_NEXT_WORKSPACE, 'packages', module.replace('@dcloudio/', ''));
|
||
}
|
||
return require.resolve(module, { paths: getBuiltInPaths() });
|
||
}
|
||
exports.resolveBuiltIn = resolveBuiltIn;
|
||
function resolveVueI18nRuntime() {
|
||
return path_1.default.resolve(__dirname, '../lib/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js');
|
||
}
|
||
exports.resolveVueI18nRuntime = resolveVueI18nRuntime;
|
||
function resolveVueI18n() {
|
||
return path_1.default.resolve(__dirname, '../lib/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js');
|
||
}
|
||
exports.resolveVueI18n = resolveVueI18n;
|
||
function resolveProjectModule(module) {
|
||
const inputDir = process.env.UNI_INPUT_DIR;
|
||
if (!inputDir) {
|
||
return;
|
||
}
|
||
try {
|
||
return resolveWithSymlinks(`${module}/package.json`, inputDir);
|
||
}
|
||
catch (e) { }
|
||
}
|
||
function resolveProjectVueI18n() {
|
||
return resolveProjectModule('vue-i18n');
|
||
}
|
||
exports.resolveProjectVueI18n = resolveProjectVueI18n;
|
||
function resolveDevtoolsApi(libDir) {
|
||
// uni-app x 暂不支持 @vue/devtools-api,统一指向兼容性空实现
|
||
return path_1.default.resolve(libDir, '@vue/devtools-api/dist/index.js');
|
||
}
|
||
function resolveVueI18nDependencies() {
|
||
return {};
|
||
}
|
||
exports.resolveVueI18nDependencies = resolveVueI18nDependencies;
|
||
function resolvePinia() {
|
||
return path_1.default.resolve(__dirname, '../lib/dom2/pinia/dist/pinia.mjs');
|
||
}
|
||
exports.resolvePinia = resolvePinia;
|
||
function resolveProjectPinia() {
|
||
return resolveProjectModule('pinia');
|
||
}
|
||
exports.resolveProjectPinia = resolveProjectPinia;
|
||
function resolvePiniaDependencies() {
|
||
if (process.env.UNI_APP_X !== 'true' || resolveProjectPinia() !== undefined) {
|
||
return {};
|
||
}
|
||
return {
|
||
'@vue/devtools-api': resolveDevtoolsApi(path_1.default.resolve(__dirname, '../lib/dom2')),
|
||
};
|
||
}
|
||
exports.resolvePiniaDependencies = resolvePiniaDependencies;
|
||
function resolvePiniaAlias() {
|
||
if (process.env.UNI_APP_X !== 'true' || resolveProjectPinia() !== undefined) {
|
||
return {};
|
||
}
|
||
return {
|
||
...resolvePiniaDependencies(),
|
||
pinia: resolvePinia(),
|
||
};
|
||
}
|
||
exports.resolvePiniaAlias = resolvePiniaAlias;
|
||
function resolveVueI18nRuntimeAlias() {
|
||
return {
|
||
...resolveVueI18nDependencies(),
|
||
'vue-i18n': resolveVueI18nRuntime(),
|
||
};
|
||
}
|
||
exports.resolveVueI18nRuntimeAlias = resolveVueI18nRuntimeAlias;
|
||
let componentsLibPath = '';
|
||
function resolveComponentsLibPath() {
|
||
if (!componentsLibPath) {
|
||
const dir = process.env.UNI_APP_X_DOM2 === 'true'
|
||
? '../lib-x-vapor'
|
||
: process.env.UNI_APP_X === 'true'
|
||
? '../lib-x'
|
||
: '../lib';
|
||
if ((0, env_1.isInHBuilderX)()) {
|
||
componentsLibPath = path_1.default.join(resolveBuiltIn('@dcloudio/uni-components/package.json'), dir);
|
||
}
|
||
else {
|
||
try {
|
||
componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.env.UNI_INPUT_DIR), dir);
|
||
}
|
||
catch (e) {
|
||
try {
|
||
componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.cwd()), dir);
|
||
}
|
||
catch (e) {
|
||
console.log(e);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return componentsLibPath;
|
||
}
|
||
exports.resolveComponentsLibPath = resolveComponentsLibPath;
|
||
function resolveComponentsLibDirs() {
|
||
return process.env.UNI_COMPILE_TARGET === 'ext-api'
|
||
? []
|
||
: [resolveComponentsLibPath()];
|
||
}
|
||
exports.resolveComponentsLibDirs = resolveComponentsLibDirs;
|