Skip to content

Commit 1caa383

Browse files
authored
fix: reduce import map diff when config changes (#8846)
### What? Reduces difference in the `importMap.js` file when config changes. ### How? Instead of appending the length, appends the hash of the path. #### Before: Example of the diff when 1 component gets removed <img width="374" alt="image" src="https://github.com/user-attachments/assets/7aff02bd-ef55-4e40-963f-1cc3890e5957"> output: ```ts import { TestComponent as TestComponent_84 } from 'test/admin/components/TestComponent.js' ``` #### After: Targets only necessary for this component lines: <img width="359" alt="image" src="https://github.com/user-attachments/assets/99ba0ebd-cff4-4169-9622-e4c491e23eef"> Output: ```ts import { TestComponent as TestComponent_d010fadde249c7cd3feed0eef58fe83c } from 'test/admin/components/TestComponent.js' ``` Fixes #8841
1 parent 03c0702 commit 1caa383

File tree

1 file changed

+3
-1
lines changed
  • packages/payload/src/bin/generateImportMap

1 file changed

+3
-1
lines changed

packages/payload/src/bin/generateImportMap/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import crypto from 'crypto'
12
import fs from 'fs'
23
import process from 'node:process'
34
import path from 'path'
@@ -56,7 +57,8 @@ export function addPayloadComponentToImportMap({
5657
return
5758
}
5859

59-
const importIdentifier = exportName + '_' + Object.keys(imports).length
60+
const importIdentifier =
61+
exportName + '_' + crypto.createHash('md5').update(componentPath).digest('hex')
6062

6163
// e.g. if baseDir is /test/fields and componentPath is /components/Field.tsx
6264
// then path needs to be /test/fields/components/Field.tsx NOT /users/username/project/test/fields/components/Field.tsx

0 commit comments

Comments
 (0)