MCPcopy
hub / github.com/zh-lx/code-inspector / ViteCodeInspectorPlugin

Function ViteCodeInspectorPlugin

packages/vite/src/index.ts:103–250  ·  view source on GitHub ↗
(options: Options)

Source from the content-addressed store, hash-verified

101}
102
103export function ViteCodeInspectorPlugin(options: Options) {
104 const record: RecordInfo = {
105 port: 0,
106 entry: '',
107 output: options.output,
108 envDir: '',
109 };
110 return {
111 name: PluginName,
112 ...(options.enforcePre === false ? {} : { enforce: 'pre' as 'pre' }),
113 apply(_, { command }) {
114 return !options.close && isDev(options.dev, command === 'serve');
115 },
116 configResolved(config) {
117 record.envDir = config.envDir || config.root;
118 record.root = config.root;
119 },
120 async load(id: string): Promise<string | null> {
121 if (isExcludedFile(id, options)) {
122 return null;
123 }
124
125 const { completePath, query } = splitId(id);
126 const filePath = normalizePath(completePath);
127 const fileType = getSourceFileType(filePath, query);
128 if (!fileType) {
129 return null;
130 }
131 if (fileType === 'mdx' && !options.mdx) {
132 return null;
133 }
134
135 const mappedFilePath = getMappingFilePath(filePath, options.mappings);
136 if (options.match && !options.match.test(mappedFilePath)) {
137 return null;
138 }
139
140 let content: string;
141 try {
142 content = fs.readFileSync(completePath, 'utf-8');
143 } catch (error) {
144 return null;
145 }
146
147 return await transformCode({
148 content,
149 filePath: mappedFilePath,
150 fileType,
151 escapeTags: options.escapeTags || [],
152 pathType: options.pathType,
153 mdx: options.mdx,
154 });
155 },
156 async transform(code: string, id: string) {
157 if (isExcludedFile(id, options) && !isAstroToolbarFile(id)) {
158 return code;
159 }
160

Callers 2

CodeInspectorPluginFunction · 0.90
index.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected