packlyze 3.0.9 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -224,9 +224,12 @@ packlyze analyze stats.json
224
224
 
225
225
  **How Packlyze detects entry points:**
226
226
  Packlyze scans your `src` folder for common entry files in this priority order:
227
- - React: `App.tsx`, `App.jsx`, `index.tsx`, `index.jsx`
228
- - Generic: `main.ts`, `main.js`, `main.tsx`, `main.jsx`, `index.ts`, `index.js`
229
- - Vue/Angular: `app.ts`, `app.js`
227
+ 1. **Main entry points** (highest priority): `main.tsx`, `main.ts`, `main.jsx`, `main.js`
228
+ 2. **React App files**: `App.tsx`, `App.jsx`, `app.tsx`, `app.jsx`
229
+ 3. **Index files**: `index.tsx`, `index.ts`, `index.jsx`, `index.js`
230
+ 4. **Vue/Angular**: `app.ts`, `app.js`
231
+
232
+ **Note:** `main.*` files are prioritized because they're typically the actual entry points, while `App.*` files are usually components imported by the entry point.
230
233
 
231
234
  **Example fixes:**
232
235
  ```javascript
@@ -244,6 +247,74 @@ packlyze analyze stats.json
244
247
  **Note for ES Module projects:**
245
248
  If your `package.json` has `"type": "module"`, you need to use `webpack.config.cjs` instead of `webpack.config.js`. Packlyze will automatically detect this and suggest the correct filename.
246
249
 
250
+ ### **TypeScript/Webpack Compatibility Issues**
251
+
252
+ **Important:** TypeScript and Webpack handle path resolution differently. Here are common issues:
253
+
254
+ #### **1. Path Aliases Not Working in Webpack**
255
+ **Problem:** Your code uses `@/hooks/useAuth` which works in TypeScript/your editor, but webpack can't resolve it.
256
+
257
+ **Why:** TypeScript reads path aliases from `tsconfig.json`, but webpack doesn't. Webpack needs its own `resolve.alias` configuration.
258
+
259
+ **Solution:** Packlyze automatically detects path aliases from `tsconfig.json` and adds them to your webpack config. However, make sure:
260
+
261
+ 1. ✅ Your `tsconfig.json` has `compilerOptions.paths` configured
262
+ 2. ✅ Use `moduleResolution: "node"` (not `"bundler"`) for webpack compatibility
263
+ 3. ✅ Path aliases are in the main `tsconfig.json` (not just in extended configs)
264
+
265
+ **Example tsconfig.json:**
266
+ ```json
267
+ {
268
+ "compilerOptions": {
269
+ "baseUrl": ".",
270
+ "moduleResolution": "node", // ✅ Use "node" for webpack
271
+ "paths": {
272
+ "@/*": ["src/*"]
273
+ }
274
+ }
275
+ }
276
+ ```
277
+
278
+ #### **2. moduleResolution: "bundler" Issue**
279
+ **Problem:** `moduleResolution: "bundler"` works with Vite/esbuild but not webpack.
280
+
281
+ **Solution:** Change to `"node"` or `"node16"`:
282
+ ```json
283
+ {
284
+ "compilerOptions": {
285
+ "moduleResolution": "node" // ✅ Works with webpack
286
+ }
287
+ }
288
+ ```
289
+
290
+ Packlyze will warn you if it detects `moduleResolution: "bundler"` in your tsconfig.json.
291
+
292
+ #### **3. ts-loader transpileOnly Mode**
293
+ **Note:** Packlyze generates webpack configs with `transpileOnly: true` for faster builds. This means:
294
+ - ✅ TypeScript is transpiled to JavaScript
295
+ - ✅ Path aliases are resolved by webpack's `resolve.alias` (which packlyze adds automatically)
296
+ - ⚠️ Type checking happens separately (run `tsc --noEmit` for type checking)
297
+
298
+ #### **4. Alternative: tsconfig-paths-webpack-plugin**
299
+ If you prefer automatic synchronization between `tsconfig.json` and webpack:
300
+
301
+ ```bash
302
+ npm install --save-dev tsconfig-paths-webpack-plugin
303
+ ```
304
+
305
+ Then in your webpack config:
306
+ ```javascript
307
+ const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
308
+
309
+ module.exports = {
310
+ resolve: {
311
+ plugins: [new TsconfigPathsPlugin()]
312
+ }
313
+ };
314
+ ```
315
+
316
+ Packlyze uses `resolve.alias` by default, which is simpler and doesn't require additional dependencies.
317
+
247
318
  ---
248
319
 
249
320
  ## 📁 File Structure
@@ -30,6 +30,33 @@ export declare class Packlyze {
30
30
  * Find project root by looking for package.json
31
31
  */
32
32
  private findProjectRoot;
33
+ /**
34
+ * Detect missing file extensions in resolve.extensions
35
+ * Example: Error resolving './App' when App.tsx exists but .tsx not in extensions
36
+ */
37
+ private detectMissingExtensions;
38
+ /**
39
+ * Detect missing CSS/image loaders
40
+ */
41
+ private detectMissingAssetLoaders;
42
+ /**
43
+ * Detect baseUrl usage without proper webpack configuration
44
+ */
45
+ private detectBaseUrlIssues;
46
+ /**
47
+ * Detect case-sensitivity issues
48
+ */
49
+ private detectCaseSensitivityIssues;
50
+ /**
51
+ * Extract alias patterns from error messages
52
+ * Example: "Can't resolve '@/hooks/useAuth'" -> { alias: '@', path: '@/hooks/useAuth' }
53
+ */
54
+ private extractAliasFromErrors;
55
+ /**
56
+ * Infer alias mapping by analyzing project structure
57
+ * Example: '@' -> 'src' (most common convention)
58
+ */
59
+ private inferAliasMapping;
33
60
  /**
34
61
  * Extract TypeScript path aliases from tsconfig.json
35
62
  * Note: Does not handle "extends" - only reads the direct tsconfig.json file
@@ -1 +1 @@
1
- {"version":3,"file":"packlyze.d.ts","sourceRoot":"","sources":["../../src/analyzer/packlyze.ts"],"names":[],"mappings":"AAGA,OAAO,EAUL,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,qBAAa,QAAQ;IACnB,OAAO,CAAC,SAAS,CAcV;IACP,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAC,CAA4B;gBAEnC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI;IASrE,OAAO,CAAC,GAAG;IAMX;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAuGxB;;OAEG;IACU,0BAA0B,CAAC,eAAe,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBpF;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA2DjC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAqD9B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA6B9B;;OAEG;IACH,OAAO,CAAC,eAAe;IAiBvB;;;OAGG;IACH,OAAO,CA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