更新
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
import type { FSWatcher } from 'chokidar';
|
||||
export declare const initEasycom: (watcher?: FSWatcher) => void;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initEasycom = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const debugEasycom = (0, debug_1.default)('uni:easycom');
|
||||
const initEasycom = (watcher) => {
|
||||
const { filter, refresh, easyComOptions } = (0, uni_cli_shared_1.initEasycomsOnce)(process.env.UNI_INPUT_DIR, {
|
||||
dirs: (0, uni_cli_shared_1.resolveComponentsLibDirs)(),
|
||||
platform: process.env.UNI_PLATFORM,
|
||||
isX: process.env.UNI_APP_X === 'true',
|
||||
});
|
||||
if (!watcher) {
|
||||
// build 模式,手动初始化 watcher
|
||||
const dirs = easyComOptions.dirs.concat([
|
||||
(0, uni_cli_shared_1.normalizePath)(process.env.UNI_INPUT_DIR + '/uni_modules'),
|
||||
]);
|
||||
debugEasycom('initWatch', dirs);
|
||||
watcher = uni_cli_shared_1.chokidar.watch(dirs, {
|
||||
ignored: ['**/node_modules/**', '**/.git/**'],
|
||||
ignoreInitial: true,
|
||||
ignorePermissionErrors: true,
|
||||
disableGlobbing: true,
|
||||
});
|
||||
}
|
||||
const refreshEasycom = (0, uni_shared_1.debounce)(refresh, 100, { setTimeout, clearTimeout });
|
||||
watcher.on('all', (eventName, path) => {
|
||||
if (!['add', 'unlink'].includes(eventName)) {
|
||||
return;
|
||||
}
|
||||
if (filter(path)) {
|
||||
debugEasycom('watch', eventName, path);
|
||||
refreshEasycom();
|
||||
}
|
||||
});
|
||||
};
|
||||
exports.initEasycom = initEasycom;
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare function createPublicFileFilter(base?: string): (id: unknown) => boolean;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createPublicFileFilter = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const pluginutils_1 = require("@rollup/pluginutils");
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
function createPublicFileFilter(base = '/') {
|
||||
const publicDir = (0, uni_cli_shared_1.normalizePath)(path_1.default.join(base, uni_cli_shared_1.PUBLIC_DIR + '/**/*'));
|
||||
const uniModulesDir = (0, uni_cli_shared_1.normalizePath)(path_1.default.join(base, 'uni_modules/*/' + uni_cli_shared_1.PUBLIC_DIR + '/**/*'));
|
||||
return (0, pluginutils_1.createFilter)([publicDir, uniModulesDir]);
|
||||
}
|
||||
exports.createPublicFileFilter = createPublicFileFilter;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export * from './filter';
|
||||
export * from './plugin';
|
||||
export * from './polyfill';
|
||||
export * from './nvue';
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./filter"), exports);
|
||||
__exportStar(require("./plugin"), exports);
|
||||
__exportStar(require("./polyfill"), exports);
|
||||
__exportStar(require("./nvue"), exports);
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* nvue 需要移除 scoped
|
||||
* @param nvuePages
|
||||
*/
|
||||
export declare function createNVueCompiler(): any;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createNVueCompiler = void 0;
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const shared_1 = require("@vue/shared");
|
||||
/**
|
||||
* nvue 需要移除 scoped
|
||||
* @param nvuePages
|
||||
*/
|
||||
function createNVueCompiler() {
|
||||
const compileSfc = require((0, uni_cli_shared_1.resolveBuiltIn)('@vue/compiler-sfc'));
|
||||
const { parse } = compileSfc;
|
||||
return (0, shared_1.extend)({}, compileSfc, {
|
||||
parse(source, options = {}) {
|
||||
const result = parse(source, options);
|
||||
result.descriptor.styles.forEach((style) => {
|
||||
if (style.scoped) {
|
||||
delete style.scoped;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
});
|
||||
}
|
||||
exports.createNVueCompiler = createNVueCompiler;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import type { Plugin } from 'vite';
|
||||
import { type UniViteCopyPluginTarget, type UniVitePlugin } from '@dcloudio/uni-cli-shared';
|
||||
import type { TemplateCompiler } from '@vue/compiler-sfc';
|
||||
import type { VitePluginUniResolvedOptions } from '..';
|
||||
export declare function initPluginUniOptions(UniVitePlugins: UniVitePlugin[]): {
|
||||
compiler?: TemplateCompiler;
|
||||
copyOptions: {
|
||||
assets: string[];
|
||||
targets: UniViteCopyPluginTarget[];
|
||||
};
|
||||
transformEvent: Record<string, string>;
|
||||
compilerOptions: Required<Required<UniVitePlugin>['uni']>['compilerOptions'];
|
||||
jsxOptions: Required<Required<UniVitePlugin>['uni']>['jsxOptions'];
|
||||
styleOptions: Required<Required<UniVitePlugin>['uni']>['styleOptions'];
|
||||
};
|
||||
export declare function initExtraPlugins(cliRoot: string, platform: UniApp.PLATFORM, options: VitePluginUniResolvedOptions): Plugin<any>[];
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initExtraPlugins = exports.initPluginUniOptions = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
function initPluginUniOptions(UniVitePlugins) {
|
||||
const assets = [];
|
||||
const targets = [];
|
||||
const transformEvent = Object.create(null);
|
||||
const compilerOptions = {};
|
||||
const jsxOptions = {};
|
||||
const styleOptions = {};
|
||||
let compiler;
|
||||
UniVitePlugins.forEach((plugin) => {
|
||||
const { compiler: pluginTemplateCompiler, copyOptions: pluginCopyOptions, compilerOptions: pluginCompilerOptions, jsxOptions: pluginJsxOptions, styleOptions: pluginStyleOpitons, } = plugin.uni || {};
|
||||
if (pluginTemplateCompiler) {
|
||||
compiler = pluginTemplateCompiler;
|
||||
}
|
||||
if (pluginCompilerOptions) {
|
||||
(0, shared_1.extend)(compilerOptions, pluginCompilerOptions);
|
||||
}
|
||||
if (pluginJsxOptions) {
|
||||
(0, shared_1.extend)(jsxOptions, pluginJsxOptions);
|
||||
}
|
||||
if (pluginStyleOpitons) {
|
||||
(0, shared_1.extend)(styleOptions, pluginStyleOpitons);
|
||||
}
|
||||
if (pluginCopyOptions) {
|
||||
let copyOptions = pluginCopyOptions;
|
||||
if ((0, shared_1.isFunction)(pluginCopyOptions)) {
|
||||
copyOptions = pluginCopyOptions();
|
||||
}
|
||||
if (copyOptions.assets) {
|
||||
assets.push(...copyOptions.assets);
|
||||
}
|
||||
if (copyOptions.targets) {
|
||||
targets.push(...copyOptions.targets);
|
||||
}
|
||||
}
|
||||
});
|
||||
return {
|
||||
compiler,
|
||||
copyOptions: {
|
||||
assets,
|
||||
targets,
|
||||
},
|
||||
transformEvent,
|
||||
compilerOptions,
|
||||
jsxOptions,
|
||||
styleOptions,
|
||||
};
|
||||
}
|
||||
exports.initPluginUniOptions = initPluginUniOptions;
|
||||
function initExtraPlugins(cliRoot, platform, options) {
|
||||
return initPlugins(cliRoot, process.env.UNI_COMPILE_TARGET === 'ext-api' &&
|
||||
process.env.UNI_APP_NEXT_WORKSPACE
|
||||
? resolvePluginsByWorkSpace(process.env.UNI_APP_NEXT_WORKSPACE, platform, options.uvue)
|
||||
: resolvePluginsByCliRoot(cliRoot, platform, options.uvue), options);
|
||||
}
|
||||
exports.initExtraPlugins = initExtraPlugins;
|
||||
function initPlugin(_cliRoot, { pluginPath, config: { main } }, options) {
|
||||
let plugin = require(path_1.default.join(pluginPath, main || '/lib/uni.plugin.js'));
|
||||
plugin = plugin.default || plugin;
|
||||
if ((0, shared_1.isFunction)(plugin)) {
|
||||
plugin = plugin(options);
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
function initPlugins(cliRoot, plugins, options) {
|
||||
return plugins
|
||||
.map((plugin) => initPlugin(cliRoot, plugin, options))
|
||||
.flat()
|
||||
.filter(Boolean)
|
||||
.map((plugin) => {
|
||||
if ((0, shared_1.isFunction)(plugin)) {
|
||||
return plugin(options);
|
||||
}
|
||||
return plugin;
|
||||
})
|
||||
.flat();
|
||||
}
|
||||
function resolvePluginsByCliRoot(cliRoot, platform, uvue = false) {
|
||||
const pkg = require(path_1.default.join(cliRoot, 'package.json'));
|
||||
return resolvePlugins(Object.keys(pkg.devDependencies || {})
|
||||
.concat(Object.keys(pkg.dependencies || {}))
|
||||
.map((id) => {
|
||||
try {
|
||||
const pkgFileName = require.resolve(id + '/package.json', {
|
||||
paths: [cliRoot],
|
||||
});
|
||||
const pkg = require(pkgFileName);
|
||||
return {
|
||||
...pkg,
|
||||
pluginPath: path_1.default.dirname(pkgFileName),
|
||||
};
|
||||
}
|
||||
catch (e) { }
|
||||
})
|
||||
.filter(Boolean), platform, uvue);
|
||||
}
|
||||
function resolvePluginsByWorkSpace(workspaceFolder, platform, uvue = false) {
|
||||
const pkgDirs = path_1.default.resolve(workspaceFolder, 'packages');
|
||||
return resolvePlugins(fs_extra_1.default
|
||||
.readdirSync(pkgDirs)
|
||||
.map((dir) => {
|
||||
const pluginPath = path_1.default.join(pkgDirs, dir);
|
||||
const pkgFileName = path_1.default.join(pluginPath, 'package.json');
|
||||
if (fs_extra_1.default.existsSync(pkgFileName)) {
|
||||
return {
|
||||
...require(pkgFileName),
|
||||
pluginPath,
|
||||
};
|
||||
}
|
||||
})
|
||||
.filter(Boolean), platform, uvue);
|
||||
}
|
||||
function resolvePlugins(pkgs, platform, uvue = false) {
|
||||
return pkgs
|
||||
.map((pkg) => {
|
||||
try {
|
||||
const config = pkg['uni-app'];
|
||||
if (!config || !config.name) {
|
||||
return;
|
||||
}
|
||||
const { apply } = config;
|
||||
if ((0, shared_1.isArray)(apply)) {
|
||||
// 注册所有平台
|
||||
apply.forEach((p) => (0, uni_cli_shared_1.registerPlatform)(p));
|
||||
if (!apply.includes(platform)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ((0, shared_1.isString)(apply)) {
|
||||
if (!new RegExp(apply).test(platform)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 插件必须支持 uvue
|
||||
if (uvue && !config.uvue) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
id: pkg.name,
|
||||
name: config.name,
|
||||
pluginPath: pkg.pluginPath,
|
||||
config,
|
||||
};
|
||||
}
|
||||
catch (e) { }
|
||||
})
|
||||
.filter(Boolean);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import type { Plugin } from 'vite';
|
||||
/**
|
||||
* TODO 临时重写,解决 @vitejs/plugin-vue 的 Bug
|
||||
*/
|
||||
export declare function rewriteCompilerSfcParse(): void;
|
||||
/**
|
||||
* 已废弃,交由 rewriteExistsSyncHasRootFile 实现,因为新的 vite 版本在 configResolved 中重写已经晚了
|
||||
* 解决 HBuilderX 项目未包含 package.json 时,initTSConfck 可能导致查找过慢,或递归目录时权限不足报错
|
||||
* 即:未包含 package.json 时,直接移除 initTSConfck 相关逻辑
|
||||
* @param inputDir
|
||||
* @returns
|
||||
*/
|
||||
export declare function initFixedEsbuildInitTSConfck(inputDir: string): Plugin[];
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initFixedEsbuildInitTSConfck = exports.rewriteCompilerSfcParse = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||||
const shared_1 = require("@vue/shared");
|
||||
/**
|
||||
* TODO 临时重写,解决 @vitejs/plugin-vue 的 Bug
|
||||
*/
|
||||
function rewriteCompilerSfcParse() {
|
||||
const compilerSfc = require((0, uni_cli_shared_1.resolveBuiltIn)('@vue/compiler-sfc'));
|
||||
const { parse } = compilerSfc;
|
||||
let extname_vue = process.env.UNI_APP_X === 'true' ? uni_cli_shared_1.X_EXTNAME_VUE : uni_cli_shared_1.EXTNAME_VUE;
|
||||
compilerSfc.parse = (source, options) => {
|
||||
if (options?.filename) {
|
||||
const extname = path_1.default.extname(options.filename);
|
||||
// wxs、filter、renderjs
|
||||
if (extname && !extname_vue.includes(extname)) {
|
||||
const tag = extname.slice(1);
|
||||
source = `<${tag}>` + source + `</${tag}>`;
|
||||
}
|
||||
}
|
||||
return parse(source, options);
|
||||
};
|
||||
}
|
||||
exports.rewriteCompilerSfcParse = rewriteCompilerSfcParse;
|
||||
/**
|
||||
* 已废弃,交由 rewriteExistsSyncHasRootFile 实现,因为新的 vite 版本在 configResolved 中重写已经晚了
|
||||
* 解决 HBuilderX 项目未包含 package.json 时,initTSConfck 可能导致查找过慢,或递归目录时权限不足报错
|
||||
* 即:未包含 package.json 时,直接移除 initTSConfck 相关逻辑
|
||||
* @param inputDir
|
||||
* @returns
|
||||
*/
|
||||
function initFixedEsbuildInitTSConfck(inputDir) {
|
||||
if (!(0, uni_cli_shared_1.isInHBuilderX)()) {
|
||||
return [];
|
||||
}
|
||||
if (fs_1.default.existsSync(path_1.default.resolve(inputDir, 'package.json'))) {
|
||||
return [];
|
||||
}
|
||||
// 'vite:esbuild', 'vite:esbuild-transpile' initTSConfck
|
||||
const existsSync = fs_1.default.existsSync;
|
||||
// 根目录 lerna.json 路径
|
||||
const lernaJsonPath = (0, uni_cli_shared_1.normalizePath)(path_1.default.resolve(inputDir, 'lerna.json'));
|
||||
return [
|
||||
{
|
||||
name: 'uni:fixed-HBuilderX-initTSConfck-before',
|
||||
enforce: 'pre',
|
||||
configResolved() {
|
||||
// 在 HBuilderX 项目中,缺少 package.json 时, 确保 searchForWorkspaceRoot 使用项目根目录, 否则 initTSConfck 会查找很费时,且可能访问目录权限报错
|
||||
// https://github.com/vitejs/vite/blob/43b7b78b1834a4c7128d8a5d987f66a4defcbd93/packages/vite/src/node/plugins/esbuild.ts#L407
|
||||
fs_1.default.existsSync = (p) => {
|
||||
if ((0, shared_1.isString)(p)) {
|
||||
// 访问根目录 lerna.json 时,直接返回 true
|
||||
// https://github.com/vitejs/vite/blob/43b7b78b1834a4c7128d8a5d987f66a4defcbd93/packages/vite/src/node/server/searchRoot.ts#L35
|
||||
if (p.endsWith('lerna.json') &&
|
||||
lernaJsonPath === (0, uni_cli_shared_1.normalizePath)(p)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return existsSync(p);
|
||||
};
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
exports.initFixedEsbuildInitTSConfck = initFixedEsbuildInitTSConfck;
|
||||
Reference in New Issue
Block a user