MCPcopy Index your code
hub / github.com/QwikDev/qwik / validateModuleTreeshake

Function validateModuleTreeshake

scripts/validate-build.ts:217–264  ·  view source on GitHub ↗
(
  config: BuildConfig,
  entryModulePath: string,
  external: string[] = []
)

Source from the content-addressed store, hash-verified

215}
216
217async function validateModuleTreeshake(
218 config: BuildConfig,
219 entryModulePath: string,
220 external: string[] = []
221): Promise<void> {
222 const virtualInputId = `@index`;
223 const bundle = await rollup({
224 input: virtualInputId,
225 treeshake: {
226 moduleSideEffects: 'no-external',
227 },
228 external: ['@builder.io/qwik/build', '@builder.io/qwik', ...external],
229 plugins: [
230 {
231 name: 'resolver',
232 resolveId(id) {
233 if (id === virtualInputId) {
234 return id;
235 }
236 },
237 load(id) {
238 if (id === virtualInputId) {
239 return `import "${entryModulePath}";`;
240 }
241 },
242 },
243 ],
244 onwarn(warning) {
245 if (warning.code !== 'EMPTY_BUNDLE') {
246 throw warning;
247 }
248 },
249 });
250
251 const o = await bundle.generate({
252 format: 'es',
253 });
254
255 const output = o.output[0];
256 const outputCode = output.code.trim();
257
258 if (outputCode !== '') {
259 console.log(outputCode);
260 throw new Error(`🧨 Unable to treeshake for ${entryModulePath}`);
261 }
262
263 console.log(`🌳 validated treeshake for ${entryModulePath}`);
264}

Callers 1

validateBuildFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…