( config: BuildConfig, entryModulePath: string, external: string[] = [] )
| 215 | } |
| 216 | |
| 217 | async 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 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…