更新
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
import type { AssignmentExpression, BaseNode, CallExpression, ExportSpecifier, Identifier, Literal, MemberExpression, MethodDefinition, Property } from 'estree';
|
||||
import { type AttributeNode, type CompoundExpressionNode, type DirectiveNode, type ElementNode, type Node, type SimpleExpressionNode } from '@vue/compiler-core';
|
||||
export declare const isProperty: (node: BaseNode) => node is Property;
|
||||
export declare const isIdentifier: (node: BaseNode) => node is Identifier;
|
||||
export declare const isAssignmentExpression: (node: BaseNode) => node is AssignmentExpression;
|
||||
export declare const isCallExpression: (node: BaseNode) => node is CallExpression;
|
||||
export declare const isMemberExpression: (node: BaseNode) => node is MemberExpression;
|
||||
export declare const isMethodDefinition: (node: BaseNode) => node is MethodDefinition;
|
||||
export declare const isExportSpecifier: (node: BaseNode) => node is ExportSpecifier;
|
||||
export declare const isReference: (node: BaseNode, parent: BaseNode) => boolean;
|
||||
export declare function createLiteral(value: string): Literal;
|
||||
export declare function createIdentifier(name: string): Identifier;
|
||||
export declare function createCallExpression(callee: unknown, args: unknown[]): CallExpression;
|
||||
export declare function parseVue(code: string, errors: SyntaxError[]): import("@vue/compiler-core").RootNode;
|
||||
export declare function isElementNode(node: Node): node is ElementNode;
|
||||
export declare function isAttributeNode(node: Node): node is AttributeNode;
|
||||
export declare function isDirectiveNode(node: Node): node is DirectiveNode;
|
||||
export declare function isSimpleExpressionNode(node: Node): node is SimpleExpressionNode;
|
||||
export declare function isCompoundExpressionNode(node: Node): node is CompoundExpressionNode;
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isCompoundExpressionNode = exports.isSimpleExpressionNode = exports.isDirectiveNode = exports.isAttributeNode = exports.isElementNode = exports.parseVue = exports.createCallExpression = exports.createIdentifier = exports.createLiteral = exports.isReference = exports.isExportSpecifier = exports.isMethodDefinition = exports.isMemberExpression = exports.isCallExpression = exports.isAssignmentExpression = exports.isIdentifier = exports.isProperty = void 0;
|
||||
const compiler_core_1 = require("@vue/compiler-core");
|
||||
const compiler_dom_1 = require("@vue/compiler-dom");
|
||||
const isProperty = (node) => node.type === 'Property';
|
||||
exports.isProperty = isProperty;
|
||||
const isIdentifier = (node) => node.type === 'Identifier';
|
||||
exports.isIdentifier = isIdentifier;
|
||||
const isAssignmentExpression = (node) => node.type === 'AssignmentExpression';
|
||||
exports.isAssignmentExpression = isAssignmentExpression;
|
||||
const isCallExpression = (node) => node.type === 'CallExpression';
|
||||
exports.isCallExpression = isCallExpression;
|
||||
const isMemberExpression = (node) => node.type === 'MemberExpression';
|
||||
exports.isMemberExpression = isMemberExpression;
|
||||
const isMethodDefinition = (node) => node.type === 'MethodDefinition';
|
||||
exports.isMethodDefinition = isMethodDefinition;
|
||||
const isExportSpecifier = (node) => node.type === 'ExportSpecifier';
|
||||
exports.isExportSpecifier = isExportSpecifier;
|
||||
const isReference = (node, parent) => {
|
||||
if ((0, exports.isMemberExpression)(node)) {
|
||||
return !node.computed && (0, exports.isReference)(node.object, node);
|
||||
}
|
||||
if ((0, exports.isIdentifier)(node)) {
|
||||
if ((0, exports.isMemberExpression)(parent))
|
||||
return parent.computed || node === parent.object;
|
||||
// `bar` in { bar: foo }
|
||||
if ((0, exports.isProperty)(parent) && node !== parent.value)
|
||||
return false;
|
||||
// `bar` in `class Foo { bar () {...} }`
|
||||
if ((0, exports.isMethodDefinition)(parent))
|
||||
return false;
|
||||
// `bar` in `export { foo as bar }`
|
||||
if ((0, exports.isExportSpecifier)(parent) && node !== parent.local)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
exports.isReference = isReference;
|
||||
function createLiteral(value) {
|
||||
return {
|
||||
type: 'Literal',
|
||||
value,
|
||||
raw: `'${value}'`,
|
||||
};
|
||||
}
|
||||
exports.createLiteral = createLiteral;
|
||||
function createIdentifier(name) {
|
||||
return {
|
||||
type: 'Identifier',
|
||||
name,
|
||||
};
|
||||
}
|
||||
exports.createIdentifier = createIdentifier;
|
||||
function createCallExpression(callee, args) {
|
||||
return {
|
||||
type: 'CallExpression',
|
||||
callee,
|
||||
arguments: args,
|
||||
};
|
||||
}
|
||||
exports.createCallExpression = createCallExpression;
|
||||
function parseVue(code, errors) {
|
||||
return (0, compiler_dom_1.parse)(code, {
|
||||
isNativeTag: () => true,
|
||||
isPreTag: () => true,
|
||||
parseMode: 'sfc',
|
||||
onError: (e) => {
|
||||
errors.push(e);
|
||||
},
|
||||
});
|
||||
}
|
||||
exports.parseVue = parseVue;
|
||||
function isElementNode(node) {
|
||||
return node.type === compiler_core_1.NodeTypes.ELEMENT;
|
||||
}
|
||||
exports.isElementNode = isElementNode;
|
||||
function isAttributeNode(node) {
|
||||
return node.type === compiler_core_1.NodeTypes.ATTRIBUTE;
|
||||
}
|
||||
exports.isAttributeNode = isAttributeNode;
|
||||
function isDirectiveNode(node) {
|
||||
return node.type === compiler_core_1.NodeTypes.DIRECTIVE;
|
||||
}
|
||||
exports.isDirectiveNode = isDirectiveNode;
|
||||
function isSimpleExpressionNode(node) {
|
||||
return node.type === compiler_core_1.NodeTypes.SIMPLE_EXPRESSION;
|
||||
}
|
||||
exports.isSimpleExpressionNode = isSimpleExpressionNode;
|
||||
function isCompoundExpressionNode(node) {
|
||||
return node.type === compiler_core_1.NodeTypes.COMPOUND_EXPRESSION;
|
||||
}
|
||||
exports.isCompoundExpressionNode = isCompoundExpressionNode;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import type { ResolvedConfig } from 'vite';
|
||||
export * from './ast';
|
||||
export * from './url';
|
||||
export * from './plugin';
|
||||
export * from './utils';
|
||||
export declare const buildInCssSet: Set<string>;
|
||||
export declare function isCombineBuiltInCss(config: ResolvedConfig): boolean;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
"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 });
|
||||
exports.isCombineBuiltInCss = exports.buildInCssSet = void 0;
|
||||
const utils_1 = require("../../utils");
|
||||
__exportStar(require("./ast"), exports);
|
||||
__exportStar(require("./url"), exports);
|
||||
__exportStar(require("./plugin"), exports);
|
||||
__exportStar(require("./utils"), exports);
|
||||
// 内置组件css列表,h5平台需要合并进去首页css中
|
||||
exports.buildInCssSet = new Set();
|
||||
function isCombineBuiltInCss(config) {
|
||||
if (!(0, utils_1.isNormalCompileTarget)()) {
|
||||
return false;
|
||||
}
|
||||
return config.command === 'build' && config.build.cssCodeSplit;
|
||||
}
|
||||
exports.isCombineBuiltInCss = isCombineBuiltInCss;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import type { Plugin, ResolveFn, ResolvedConfig } from 'vite';
|
||||
import { type CssUrlReplacer } from '../plugins/vitejs/plugins/css';
|
||||
export type CreateUniViteFilterPlugin = (opts: UniViteFilterPluginOptions) => Plugin;
|
||||
export interface UniViteFilterPluginOptions {
|
||||
resolvedConfig: ResolvedConfig;
|
||||
filter: (id: string) => boolean;
|
||||
}
|
||||
export declare function injectAssetPlugin(config: ResolvedConfig, options?: {
|
||||
isAndroidX: boolean;
|
||||
}): void;
|
||||
export declare function injectCssPlugin(config: ResolvedConfig, options?: {
|
||||
createUrlReplacer?: (resolve: ResolveFn) => CssUrlReplacer;
|
||||
}): void;
|
||||
export declare function injectCssPostPlugin(config: ResolvedConfig, newCssPostPlugin: Plugin): void;
|
||||
export declare function replacePlugins(plugins: Plugin[], config: ResolvedConfig): void;
|
||||
export declare function removePlugins(plugins: string | string[], config: ResolvedConfig): void;
|
||||
export declare function insertBeforePlugin(plugin: Plugin, before: string, config: ResolvedConfig): void;
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.insertBeforePlugin = exports.removePlugins = exports.replacePlugins = exports.injectCssPostPlugin = exports.injectCssPlugin = exports.injectAssetPlugin = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const asset_1 = require("../plugins/vitejs/plugins/asset");
|
||||
const css_1 = require("../plugins/vitejs/plugins/css");
|
||||
function injectAssetPlugin(config, options) {
|
||||
replacePlugins([(0, asset_1.assetPlugin)(config, options)], config);
|
||||
}
|
||||
exports.injectAssetPlugin = injectAssetPlugin;
|
||||
function injectCssPlugin(config, options) {
|
||||
replacePlugins([
|
||||
(0, css_1.cssPlugin)(config, {
|
||||
isAndroidX: false,
|
||||
...options,
|
||||
}),
|
||||
], config);
|
||||
}
|
||||
exports.injectCssPlugin = injectCssPlugin;
|
||||
function injectCssPostPlugin(config, newCssPostPlugin) {
|
||||
const oldCssPostPlugin = config.plugins.find((p) => p.name === newCssPostPlugin.name);
|
||||
// 直接覆盖原有方法,不能删除,替换,因为 unocss 在 pre 阶段已经获取到了旧的 css-post 插件对象
|
||||
if (oldCssPostPlugin) {
|
||||
(0, shared_1.extend)(oldCssPostPlugin, newCssPostPlugin);
|
||||
}
|
||||
}
|
||||
exports.injectCssPostPlugin = injectCssPostPlugin;
|
||||
function replacePlugins(plugins, config) {
|
||||
plugins.forEach((plugin) => {
|
||||
const index = config.plugins.findIndex((p) => p.name === plugin.name);
|
||||
if (index > -1) {
|
||||
;
|
||||
config.plugins.splice(index, 1, plugin);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.replacePlugins = replacePlugins;
|
||||
function removePlugins(plugins, config) {
|
||||
if (!(0, shared_1.isArray)(plugins)) {
|
||||
plugins = [plugins];
|
||||
}
|
||||
plugins.forEach((name) => {
|
||||
const index = config.plugins.findIndex((p) => p.name === name);
|
||||
if (index > -1) {
|
||||
;
|
||||
config.plugins.splice(index, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.removePlugins = removePlugins;
|
||||
function insertBeforePlugin(plugin, before, config) {
|
||||
const index = config.plugins.findIndex((p) => p.name === before);
|
||||
if (index > -1) {
|
||||
;
|
||||
config.plugins.splice(index, 0, plugin);
|
||||
}
|
||||
}
|
||||
exports.insertBeforePlugin = insertBeforePlugin;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
export interface VueQuery {
|
||||
vue?: boolean;
|
||||
src?: boolean;
|
||||
type?: 'script' | 'template' | 'style' | 'custom' | 'page';
|
||||
index?: number;
|
||||
lang?: string;
|
||||
raw?: boolean;
|
||||
setup?: boolean;
|
||||
'lang.ts'?: string;
|
||||
'lang.js'?: string;
|
||||
}
|
||||
export declare function parseVueRequest(id: string): {
|
||||
filename: string;
|
||||
query: VueQuery;
|
||||
};
|
||||
export declare const isImportRequest: (url: string) => boolean;
|
||||
/**
|
||||
* Prefix for resolved fs paths, since windows paths may not be valid as URLs.
|
||||
*/
|
||||
export declare const FS_PREFIX = "/@fs/";
|
||||
/**
|
||||
* Prefix for resolved Ids that are not valid browser import specifiers
|
||||
*/
|
||||
export declare const VALID_ID_PREFIX = "/@id/";
|
||||
export declare const CLIENT_PUBLIC_PATH = "/@vite/client";
|
||||
export declare const ENV_PUBLIC_PATH = "/@vite/env";
|
||||
export declare const isInternalRequest: (url: string) => boolean;
|
||||
export declare const queryRE: RegExp;
|
||||
export declare const hashRE: RegExp;
|
||||
export declare const cleanUrl: (url: string) => string;
|
||||
export declare function isJsFile(id: string): boolean;
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isJsFile = exports.cleanUrl = exports.hashRE = exports.queryRE = exports.isInternalRequest = exports.ENV_PUBLIC_PATH = exports.CLIENT_PUBLIC_PATH = exports.VALID_ID_PREFIX = exports.FS_PREFIX = exports.isImportRequest = exports.parseVueRequest = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const constants_1 = require("../../constants");
|
||||
function parseVueRequest(id) {
|
||||
const [filename, rawQuery] = id.split(`?`, 2);
|
||||
const query = Object.fromEntries(new URLSearchParams(rawQuery));
|
||||
if (query.vue != null) {
|
||||
query.vue = true;
|
||||
}
|
||||
if (query.src != null) {
|
||||
query.src = true;
|
||||
}
|
||||
if (query.index != null) {
|
||||
query.index = Number(query.index);
|
||||
}
|
||||
if (query.raw != null) {
|
||||
query.raw = true;
|
||||
}
|
||||
return {
|
||||
filename,
|
||||
query,
|
||||
};
|
||||
}
|
||||
exports.parseVueRequest = parseVueRequest;
|
||||
const importQueryRE = /(\?|&)import=?(?:&|$)/;
|
||||
const isImportRequest = (url) => importQueryRE.test(url);
|
||||
exports.isImportRequest = isImportRequest;
|
||||
/**
|
||||
* Prefix for resolved fs paths, since windows paths may not be valid as URLs.
|
||||
*/
|
||||
exports.FS_PREFIX = `/@fs/`;
|
||||
/**
|
||||
* Prefix for resolved Ids that are not valid browser import specifiers
|
||||
*/
|
||||
exports.VALID_ID_PREFIX = `/@id/`;
|
||||
exports.CLIENT_PUBLIC_PATH = `/@vite/client`;
|
||||
exports.ENV_PUBLIC_PATH = `/@vite/env`;
|
||||
const internalPrefixes = [
|
||||
exports.FS_PREFIX,
|
||||
exports.VALID_ID_PREFIX,
|
||||
exports.CLIENT_PUBLIC_PATH,
|
||||
exports.ENV_PUBLIC_PATH,
|
||||
];
|
||||
const InternalPrefixRE = new RegExp(`^(?:${internalPrefixes.join('|')})`);
|
||||
const isInternalRequest = (url) => InternalPrefixRE.test(url);
|
||||
exports.isInternalRequest = isInternalRequest;
|
||||
exports.queryRE = /\?.*$/;
|
||||
exports.hashRE = /#.*$/;
|
||||
const cleanUrl = (url) => url.replace(exports.hashRE, '').replace(exports.queryRE, '');
|
||||
exports.cleanUrl = cleanUrl;
|
||||
function isJsFile(id) {
|
||||
const { filename, query } = parseVueRequest(id);
|
||||
const isJs = constants_1.EXTNAME_JS_RE.test(filename);
|
||||
if (isJs) {
|
||||
return true;
|
||||
}
|
||||
const isVueJs = constants_1.EXTNAME_VUE.includes(path_1.default.extname(filename)) &&
|
||||
(!query.vue ||
|
||||
query.setup ||
|
||||
(0, shared_1.hasOwn)(query, 'lang.ts') ||
|
||||
(0, shared_1.hasOwn)(query, 'lang.js') ||
|
||||
(0, shared_1.hasOwn)(query, 'lang.uts'));
|
||||
if (isVueJs) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isJsFile = isJsFile;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import type { ConfigEnv, ResolvedConfig, UserConfig } from 'vite';
|
||||
import type { RollupError } from 'rollup';
|
||||
import type { CompilerError } from '@vue/compiler-sfc';
|
||||
import { codeFrameColumns } from '@babel/code-frame';
|
||||
export declare function withSourcemap(config: ResolvedConfig): boolean;
|
||||
export declare function isInHybridNVue(config: UserConfig | ResolvedConfig): boolean;
|
||||
export declare function isSsr(command: ConfigEnv['command'], config: UserConfig | ResolvedConfig): boolean;
|
||||
export declare function createRollupError(plugin: string, id: string, error: CompilerError | SyntaxError, source?: string): RollupError;
|
||||
export declare const generateCodeFrameColumns: typeof codeFrameColumns;
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.generateCodeFrameColumns = exports.createRollupError = exports.isSsr = exports.isInHybridNVue = exports.withSourcemap = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const code_frame_1 = require("@babel/code-frame");
|
||||
const utils_1 = require("../plugins/vitejs/utils");
|
||||
const utils_2 = require("../../utils");
|
||||
function withSourcemap(config) {
|
||||
if (!process.env.UNI_APP_SOURCEMAP) {
|
||||
if (config.build && (0, shared_1.hasOwn)(config.build, 'sourcemap')) {
|
||||
if (!!config.build.sourcemap) {
|
||||
process.env.UNI_APP_SOURCEMAP = 'true';
|
||||
}
|
||||
else {
|
||||
// vite 的 build 模式默认是false,而非web端的dev也是用build模式,所以不能这样判断
|
||||
// process.env.UNI_APP_SOURCEMAP = 'false'
|
||||
}
|
||||
}
|
||||
}
|
||||
return (0, utils_2.enableSourceMap)();
|
||||
}
|
||||
exports.withSourcemap = withSourcemap;
|
||||
function isInHybridNVue(config) {
|
||||
return config.nvue && process.env.UNI_RENDERER !== 'native';
|
||||
}
|
||||
exports.isInHybridNVue = isInHybridNVue;
|
||||
function isSsr(command, config) {
|
||||
if (command === 'serve') {
|
||||
return !!(config.server && config.server.middlewareMode);
|
||||
}
|
||||
if (command === 'build') {
|
||||
return !!(config.build && config.build.ssr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isSsr = isSsr;
|
||||
function createRollupError(plugin, id, error, source) {
|
||||
const { message, name, stack } = error;
|
||||
const rollupError = (0, shared_1.extend)(new Error(message), {
|
||||
id,
|
||||
plugin,
|
||||
name,
|
||||
stack,
|
||||
});
|
||||
if ('code' in error && error.loc) {
|
||||
rollupError.loc = {
|
||||
file: id,
|
||||
line: error.loc.start.line,
|
||||
column: error.loc.start.column,
|
||||
};
|
||||
if (source && source.length > 0) {
|
||||
if ('offsetStart' in error && 'offsetEnd' in error) {
|
||||
rollupError.frame = (0, code_frame_1.codeFrameColumns)(source, (0, utils_1.offsetToStartAndEnd)(source, error.offsetStart, error.offsetEnd));
|
||||
}
|
||||
else {
|
||||
rollupError.frame = (0, code_frame_1.codeFrameColumns)(source, error.loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (id) {
|
||||
// 指定了id后,不让后续的rollup重写
|
||||
Object.defineProperty(rollupError, 'id', {
|
||||
get() {
|
||||
return id;
|
||||
},
|
||||
set(_v) { },
|
||||
});
|
||||
}
|
||||
return rollupError;
|
||||
}
|
||||
exports.createRollupError = createRollupError;
|
||||
exports.generateCodeFrameColumns = code_frame_1.codeFrameColumns;
|
||||
Reference in New Issue
Block a user