payload 3.28.0-internal.c4e1bed → 3.28.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.
Files changed (73) hide show
  1. package/dist/admin/forms/Description.d.ts +2 -3
  2. package/dist/admin/forms/Description.d.ts.map +1 -1
  3. package/dist/admin/forms/Description.js.map +1 -1
  4. package/dist/admin/forms/Error.d.ts +2 -3
  5. package/dist/admin/forms/Error.d.ts.map +1 -1
  6. package/dist/admin/forms/Error.js.map +1 -1
  7. package/dist/admin/forms/Label.d.ts +3 -3
  8. package/dist/admin/forms/Label.d.ts.map +1 -1
  9. package/dist/admin/forms/Label.js.map +1 -1
  10. package/dist/auth/strategies/local/generatePasswordSaltHash.d.ts.map +1 -1
  11. package/dist/auth/strategies/local/generatePasswordSaltHash.js +3 -0
  12. package/dist/auth/strategies/local/generatePasswordSaltHash.js.map +1 -1
  13. package/dist/bin/generateImportMap/generateImportMap.spec.js +175 -0
  14. package/dist/bin/generateImportMap/generateImportMap.spec.js.map +1 -0
  15. package/dist/bin/generateImportMap/index.d.ts +2 -10
  16. package/dist/bin/generateImportMap/index.d.ts.map +1 -1
  17. package/dist/bin/generateImportMap/index.js +20 -88
  18. package/dist/bin/generateImportMap/index.js.map +1 -1
  19. package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
  20. package/dist/bin/generateImportMap/utilities/addPayloadComponentToImportMap.d.ts +15 -0
  21. package/dist/bin/generateImportMap/utilities/addPayloadComponentToImportMap.d.ts.map +1 -0
  22. package/dist/bin/generateImportMap/utilities/addPayloadComponentToImportMap.js +56 -0
  23. package/dist/bin/generateImportMap/utilities/addPayloadComponentToImportMap.js.map +1 -0
  24. package/dist/bin/generateImportMap/{getFromImportMap.d.ts → utilities/getFromImportMap.d.ts} +2 -2
  25. package/dist/bin/generateImportMap/utilities/getFromImportMap.d.ts.map +1 -0
  26. package/dist/bin/generateImportMap/utilities/getFromImportMap.js.map +1 -0
  27. package/dist/bin/generateImportMap/utilities/getImportMapToBaseDirPath.d.ts +15 -0
  28. package/dist/bin/generateImportMap/utilities/getImportMapToBaseDirPath.d.ts.map +1 -0
  29. package/dist/bin/generateImportMap/utilities/getImportMapToBaseDirPath.js +22 -0
  30. package/dist/bin/generateImportMap/utilities/getImportMapToBaseDirPath.js.map +1 -0
  31. package/dist/bin/generateImportMap/{parsePayloadComponent.d.ts → utilities/parsePayloadComponent.d.ts} +1 -1
  32. package/dist/bin/generateImportMap/utilities/parsePayloadComponent.d.ts.map +1 -0
  33. package/dist/bin/generateImportMap/utilities/parsePayloadComponent.js.map +1 -0
  34. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts +9 -0
  35. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts.map +1 -0
  36. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js +26 -0
  37. package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js.map +1 -0
  38. package/dist/collections/config/types.d.ts +4 -0
  39. package/dist/collections/config/types.d.ts.map +1 -1
  40. package/dist/collections/config/types.js.map +1 -1
  41. package/dist/config/defaults.d.ts.map +1 -1
  42. package/dist/config/defaults.js +2 -0
  43. package/dist/config/defaults.js.map +1 -1
  44. package/dist/config/types.d.ts +14 -50
  45. package/dist/config/types.d.ts.map +1 -1
  46. package/dist/config/types.js.map +1 -1
  47. package/dist/exports/shared.d.ts +2 -2
  48. package/dist/exports/shared.d.ts.map +1 -1
  49. package/dist/exports/shared.js +2 -2
  50. package/dist/exports/shared.js.map +1 -1
  51. package/dist/fields/config/client.js +1 -1
  52. package/dist/fields/config/client.js.map +1 -1
  53. package/dist/fields/config/types.d.ts +4 -0
  54. package/dist/fields/config/types.d.ts.map +1 -1
  55. package/dist/fields/config/types.js.map +1 -1
  56. package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
  57. package/dist/fields/hooks/beforeChange/promise.js +1 -0
  58. package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
  59. package/dist/locked-documents/config.d.ts.map +1 -1
  60. package/dist/locked-documents/config.js +7 -0
  61. package/dist/locked-documents/config.js.map +1 -1
  62. package/dist/uploads/generateFileData.js +1 -1
  63. package/dist/uploads/generateFileData.js.map +1 -1
  64. package/dist/uploads/imageResizer.d.ts.map +1 -1
  65. package/dist/uploads/imageResizer.js +1 -0
  66. package/dist/uploads/imageResizer.js.map +1 -1
  67. package/package.json +3 -3
  68. package/dist/bin/generateImportMap/getFromImportMap.d.ts.map +0 -1
  69. package/dist/bin/generateImportMap/getFromImportMap.js.map +0 -1
  70. package/dist/bin/generateImportMap/parsePayloadComponent.d.ts.map +0 -1
  71. package/dist/bin/generateImportMap/parsePayloadComponent.js.map +0 -1
  72. /package/dist/bin/generateImportMap/{getFromImportMap.js → utilities/getFromImportMap.js} +0 -0
  73. /package/dist/bin/generateImportMap/{parsePayloadComponent.js → utilities/parsePayloadComponent.js} +0 -0
@@ -1,7 +1,6 @@
1
1
  import type { TFunction } from '@payloadcms/translations';
2
- import type { ServerProps } from '../../config/types.js';
3
2
  import type { Field } from '../../fields/config/types.js';
4
- import type { ClientFieldWithOptionalType } from './Field.js';
3
+ import type { ClientFieldWithOptionalType, ServerComponentProps } from './Field.js';
5
4
  export type DescriptionFunction = ({ t }: {
6
5
  t: TFunction;
7
6
  }) => string;
@@ -18,7 +17,7 @@ export type GenericDescriptionProps = {
18
17
  export type FieldDescriptionServerProps<TFieldServer extends Field = Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = {
19
18
  clientField: TFieldClient;
20
19
  readonly field: TFieldServer;
21
- } & GenericDescriptionProps & Partial<ServerProps>;
20
+ } & GenericDescriptionProps & ServerComponentProps;
22
21
  export type FieldDescriptionClientProps<TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = {
23
22
  field: TFieldClient;
24
23
  } & GenericDescriptionProps;
@@ -1 +1 @@
1
- {"version":3,"file":"Description.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Description.ts"],"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Ae,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,2BAA2B,CACrC,YAAY,SAAS,KAAK,GAAG,KAAK,EAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E;IACF,WAAW,EAAE,YAAY,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAC7B,GAAG,uBAAuB,GACzB,oBAAoB,CAAA;AAEtB,MAAM,MAAM,2BAA2B,CACrC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E;IACF,KAAK,EAAE,YAAY,CAAA;CACpB,GAAG,uBAAuB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/forms/Description.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport type { ServerProps } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type DescriptionFunction = ({ t }: { t: TFunction }) => string\n\nexport type FieldDescriptionClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDescriptionClientProps<TFieldClient>>\n\nexport type FieldDescriptionServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDescriptionServerProps<TFieldServer, TFieldClient>>\n\nexport type StaticDescription = Record<string, string> | string\n\nexport type Description = DescriptionFunction | StaticDescription\n\nexport type GenericDescriptionProps = {\n readonly className?: string\n readonly description?: StaticDescription\n readonly marginPlacement?: 'bottom' | 'top'\n readonly path: string\n}\n\nexport type FieldDescriptionServerProps<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericDescriptionProps &\n Partial<ServerProps>\n\nexport type FieldDescriptionClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericDescriptionProps\n"],"names":[],"mappings":"AAqCA,WAI2B"}
1
+ {"version":3,"sources":["../../../src/admin/forms/Description.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport type { Field } from '../../fields/config/types.js'\nimport type { ClientFieldWithOptionalType, ServerComponentProps } from './Field.js'\n\nexport type DescriptionFunction = ({ t }: { t: TFunction }) => string\n\nexport type FieldDescriptionClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDescriptionClientProps<TFieldClient>>\n\nexport type FieldDescriptionServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldDescriptionServerProps<TFieldServer, TFieldClient>>\n\nexport type StaticDescription = Record<string, string> | string\n\nexport type Description = DescriptionFunction | StaticDescription\n\nexport type GenericDescriptionProps = {\n readonly className?: string\n readonly description?: StaticDescription\n readonly marginPlacement?: 'bottom' | 'top'\n readonly path: string\n}\n\nexport type FieldDescriptionServerProps<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericDescriptionProps &\n ServerComponentProps\n\nexport type FieldDescriptionClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericDescriptionProps\n"],"names":[],"mappings":"AAoCA,WAI2B"}
@@ -1,6 +1,5 @@
1
- import type { ServerProps } from '../../config/types.js';
2
1
  import type { Field } from '../../fields/config/types.js';
3
- import type { ClientFieldWithOptionalType } from './Field.js';
2
+ import type { ClientFieldWithOptionalType, ServerComponentProps } from './Field.js';
4
3
  export type GenericErrorProps = {
5
4
  readonly alignCaret?: 'center' | 'left' | 'right';
6
5
  readonly message?: string;
@@ -13,7 +12,7 @@ export type FieldErrorClientProps<TFieldClient extends ClientFieldWithOptionalTy
13
12
  export type FieldErrorServerProps<TFieldServer extends Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = {
14
13
  clientField: TFieldClient;
15
14
  readonly field: TFieldServer;
16
- } & GenericErrorProps & Partial<ServerProps>;
15
+ } & GenericErrorProps & ServerComponentProps;
17
16
  export type FieldErrorClientComponent<TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = React.ComponentType<FieldErrorClientProps<TFieldClient>>;
18
17
  export type FieldErrorServerComponent<TFieldServer extends Field = Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = React.ComponentType<FieldErrorServerProps<TFieldServer, TFieldClient>>;
19
18
  //# sourceMappingURL=Error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Error.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,qBAAqB,CAC/B,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E;IACF,KAAK,EAAE,YAAY,CAAA;CACpB,GAAG,iBAAiB,CAAA;AAErB,MAAM,MAAM,qBAAqB,CAC/B,YAAY,SAAS,KA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,YAAY,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAC7B,GAAG,iBAAiB,GACnB,oBAAoB,CAAA;AAEtB,MAAM,MAAM,yBAAyB,CACnC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAA;AAE5D,MAAM,MAAM,yBAAyB,CACnC,YAAY,SAAS,KAAK,GAAG,KAAK,EAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/forms/Error.ts"],"sourcesContent":["import type { ServerProps } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type GenericErrorProps = {\n readonly alignCaret?: 'center' | 'left' | 'right'\n readonly message?: string\n readonly path?: string\n readonly showError?: boolean\n}\n\nexport type FieldErrorClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericErrorProps\n\nexport type FieldErrorServerProps<\n TFieldServer extends Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericErrorProps &\n Partial<ServerProps>\n\nexport type FieldErrorClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldErrorClientProps<TFieldClient>>\n\nexport type FieldErrorServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldErrorServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AA8BA,WAG0E"}
1
+ {"version":3,"sources":["../../../src/admin/forms/Error.ts"],"sourcesContent":["import type { Field } from '../../fields/config/types.js'\nimport type { ClientFieldWithOptionalType, ServerComponentProps } from './Field.js'\n\nexport type GenericErrorProps = {\n readonly alignCaret?: 'center' | 'left' | 'right'\n readonly message?: string\n readonly path?: string\n readonly showError?: boolean\n}\n\nexport type FieldErrorClientProps<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n field: TFieldClient\n} & GenericErrorProps\n\nexport type FieldErrorServerProps<\n TFieldServer extends Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericErrorProps &\n ServerComponentProps\n\nexport type FieldErrorClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldErrorClientProps<TFieldClient>>\n\nexport type FieldErrorServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldErrorServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AA6BA,WAG0E"}
@@ -1,6 +1,6 @@
1
- import type { ServerProps, StaticLabel } from '../../config/types.js';
1
+ import type { StaticLabel } from '../../config/types.js';
2
2
  import type { Field } from '../../fields/config/types.js';
3
- import type { ClientFieldWithOptionalType } from './Field.js';
3
+ import type { ClientFieldWithOptionalType, ServerComponentProps } from './Field.js';
4
4
  export type GenericLabelProps = {
5
5
  readonly as?: 'label' | 'span';
6
6
  readonly hideLocale?: boolean;
@@ -17,7 +17,7 @@ export type FieldLabelClientProps<TFieldClient extends Partial<ClientFieldWithOp
17
17
  export type FieldLabelServerProps<TFieldServer extends Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = {
18
18
  clientField: TFieldClient;
19
19
  readonly field: TFieldServer;
20
- } & GenericLabelProps & Partial<ServerProps>;
20
+ } & GenericLabelProps & ServerComponentProps;
21
21
  export type SanitizedLabelProps<TFieldClient extends ClientFieldWithOptionalType> = Omit<FieldLabelClientProps<TFieldClient>, 'label' | 'required'>;
22
22
  export type FieldLabelClientComponent<TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = React.ComponentType<FieldLabelClientProps<TFieldClient>>;
23
23
  export type FieldLabelServerComponent<TFieldServer extends Field = Field, TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType> = React.ComponentType<FieldLabelServerProps<TFieldServer, TFieldClient>>;
@@ -1 +1 @@
1
- {"version":3,"file":"Label.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Label.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAA;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,qBAAqB,CAC/B,YAAY,SAAS,OAAO,CAAC,2BAA2B,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC,IAC9F;IACF,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB,GAAG,iBAAiB,CAAA;AAErB,MAAM,MAAM,qBAAqB,CAC/B,YAAY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AAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,qBAAqB,CAC/B,YAAY,SAAS,OAAO,CAAC,2BAA2B,CAAC,GAAG,OAAO,CAAC,2BAA2B,CAAC,IAC9F;IACF,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB,GAAG,iBAAiB,CAAA;AAErB,MAAM,MAAM,qBAAqB,CAC/B,YAAY,SAAS,KAAK,EAC1B,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E;IACF,WAAW,EAAE,YAAY,CAAA;IACzB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;CAC7B,GAAG,iBAAiB,GACnB,oBAAoB,CAAA;AAEtB,MAAM,MAAM,mBAAmB,CAAC,YAAY,SAAS,2BAA2B,IAAI,IAAI,CACtF,qBAAqB,CAAC,YAAY,CAAC,EACnC,OAAO,GAAG,UAAU,CACrB,CAAA;AAED,MAAM,MAAM,yBAAyB,CACnC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC,CAAA;AAE5D,MAAM,MAAM,yBAAyB,CACnC,YAAY,SAAS,KAAK,GAAG,KAAK,EAClC,YAAY,SAAS,2BAA2B,GAAG,2BAA2B,IAC5E,KAAK,CAAC,aAAa,CAAC,qBAAqB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/admin/forms/Label.ts"],"sourcesContent":["import type { ServerProps, StaticLabel } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { ClientFieldWithOptionalType } from './Field.js'\n\nexport type GenericLabelProps = {\n readonly as?: 'label' | 'span'\n readonly hideLocale?: boolean\n readonly htmlFor?: string\n readonly label?: StaticLabel\n readonly localized?: boolean\n readonly path?: string\n readonly required?: boolean\n readonly unstyled?: boolean\n}\n\nexport type FieldLabelClientProps<\n TFieldClient extends Partial<ClientFieldWithOptionalType> = Partial<ClientFieldWithOptionalType>,\n> = {\n field?: TFieldClient\n} & GenericLabelProps\n\nexport type FieldLabelServerProps<\n TFieldServer extends Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericLabelProps &\n Partial<ServerProps>\n\nexport type SanitizedLabelProps<TFieldClient extends ClientFieldWithOptionalType> = Omit<\n FieldLabelClientProps<TFieldClient>,\n 'label' | 'required'\n>\n\nexport type FieldLabelClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldLabelClientProps<TFieldClient>>\n\nexport type FieldLabelServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldLabelServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAuCA,WAG0E"}
1
+ {"version":3,"sources":["../../../src/admin/forms/Label.ts"],"sourcesContent":["import type { StaticLabel } from '../../config/types.js'\nimport type { Field } from '../../fields/config/types.js'\nimport type { ClientFieldWithOptionalType, ServerComponentProps } from './Field.js'\n\nexport type GenericLabelProps = {\n readonly as?: 'label' | 'span'\n readonly hideLocale?: boolean\n readonly htmlFor?: string\n readonly label?: StaticLabel\n readonly localized?: boolean\n readonly path?: string\n readonly required?: boolean\n readonly unstyled?: boolean\n}\n\nexport type FieldLabelClientProps<\n TFieldClient extends Partial<ClientFieldWithOptionalType> = Partial<ClientFieldWithOptionalType>,\n> = {\n field?: TFieldClient\n} & GenericLabelProps\n\nexport type FieldLabelServerProps<\n TFieldServer extends Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n clientField: TFieldClient\n readonly field: TFieldServer\n} & GenericLabelProps &\n ServerComponentProps\n\nexport type SanitizedLabelProps<TFieldClient extends ClientFieldWithOptionalType> = Omit<\n FieldLabelClientProps<TFieldClient>,\n 'label' | 'required'\n>\n\nexport type FieldLabelClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldLabelClientProps<TFieldClient>>\n\nexport type FieldLabelServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = React.ComponentType<FieldLabelServerProps<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAuCA,WAG0E"}
@@ -1 +1 @@
1
- {"version":3,"file":"generatePasswordSaltHash.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/generatePasswordSaltHash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAmB7D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,wBAAwB,kDAIlC,IAAI,KAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA2B/C,CAAA"}
1
+ {"version":3,"file":"generatePasswordSaltHash.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/generatePasswordSaltHash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAmB7D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,wBAAwB,kDAIlC,IAAI,KAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CA4B/C,CAAA"}
@@ -14,6 +14,9 @@ export const generatePasswordSaltHash = async ({ collection, password: passwordT
14
14
  blockData: {},
15
15
  data: {},
16
16
  event: 'submit',
17
+ path: [
18
+ 'password'
19
+ ],
17
20
  preferences: {
18
21
  fields: {}
19
22
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/auth/strategies/local/generatePasswordSaltHash.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { PayloadRequest } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { password } from '../../../fields/validations.js'\n\nfunction randomBytes(): Promise<Buffer> {\n return new Promise((resolve, reject) =>\n crypto.randomBytes(32, (err, saltBuffer) => (err ? reject(err) : resolve(saltBuffer))),\n )\n}\n\nfunction pbkdf2Promisified(password: string, salt: string): Promise<Buffer> {\n return new Promise((resolve, reject) =>\n crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (err, hashRaw) =>\n err ? reject(err) : resolve(hashRaw),\n ),\n )\n}\n\ntype Args = {\n collection: SanitizedCollectionConfig\n password: string\n req: PayloadRequest\n}\n\nexport const generatePasswordSaltHash = async ({\n collection,\n password: passwordToSet,\n req,\n}: Args): Promise<{ hash: string; salt: string }> => {\n const validationResult = password(passwordToSet, {\n name: 'password',\n type: 'text',\n blockData: {},\n data: {},\n event: 'submit',\n preferences: { fields: {} },\n req,\n required: true,\n siblingData: {},\n })\n\n if (typeof validationResult === 'string') {\n throw new ValidationError({\n collection: collection?.slug,\n errors: [{ message: validationResult, path: 'password' }],\n })\n }\n\n const saltBuffer = await randomBytes()\n const salt = saltBuffer.toString('hex')\n\n const hashRaw = await pbkdf2Promisified(passwordToSet, salt)\n const hash = hashRaw.toString('hex')\n\n return { hash, salt }\n}\n"],"names":["crypto","ValidationError","password","randomBytes","Promise","resolve","reject","err","saltBuffer","pbkdf2Promisified","salt","pbkdf2","hashRaw","generatePasswordSaltHash","collection","passwordToSet","req","validationResult","name","type","blockData","data","event","preferences","fields","required","siblingData","slug","errors","message","path","toString","hash"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAK3B,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,QAAQ,QAAQ,iCAAgC;AAEzD,SAASC;IACP,OAAO,IAAIC,QAAQ,CAACC,SAASC,SAC3BN,OAAOG,WAAW,CAAC,IAAI,CAACI,KAAKC,aAAgBD,MAAMD,OAAOC,OAAOF,QAAQG;AAE7E;AAEA,SAASC,kBAAkBP,QAAgB,EAAEQ,IAAY;IACvD,OAAO,IAAIN,QAAQ,CAACC,SAASC,SAC3BN,OAAOW,MAAM,CAACT,UAAUQ,MAAM,OAAO,KAAK,UAAU,CAACH,KAAKK,UACxDL,MAAMD,OAAOC,OAAOF,QAAQO;AAGlC;AAQA,OAAO,MAAMC,2BAA2B,OAAO,EAC7CC,UAAU,EACVZ,UAAUa,aAAa,EACvBC,GAAG,EACE;IACL,MAAMC,mBAAmBf,SAASa,eAAe;QAC/CG,MAAM;QACNC,MAAM;QACNC,WAAW,CAAC;QACZC,MAAM,CAAC;QACPC,OAAO;QACPC,aAAa;YAAEC,QAAQ,CAAC;QAAE;QAC1BR;QACAS,UAAU;QACVC,aAAa,CAAC;IAChB;IAEA,IAAI,OAAOT,qBAAqB,UAAU;QACxC,MAAM,IAAIhB,gBAAgB;YACxBa,YAAYA,YAAYa;YACxBC,QAAQ;gBAAC;oBAAEC,SAASZ;oBAAkBa,MAAM;gBAAW;aAAE;QAC3D;IACF;IAEA,MAAMtB,aAAa,MAAML;IACzB,MAAMO,OAAOF,WAAWuB,QAAQ,CAAC;IAEjC,MAAMnB,UAAU,MAAMH,kBAAkBM,eAAeL;IACvD,MAAMsB,OAAOpB,QAAQmB,QAAQ,CAAC;IAE9B,OAAO;QAAEC;QAAMtB;IAAK;AACtB,EAAC"}
1
+ {"version":3,"sources":["../../../../src/auth/strategies/local/generatePasswordSaltHash.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { PayloadRequest } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { password } from '../../../fields/validations.js'\n\nfunction randomBytes(): Promise<Buffer> {\n return new Promise((resolve, reject) =>\n crypto.randomBytes(32, (err, saltBuffer) => (err ? reject(err) : resolve(saltBuffer))),\n )\n}\n\nfunction pbkdf2Promisified(password: string, salt: string): Promise<Buffer> {\n return new Promise((resolve, reject) =>\n crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (err, hashRaw) =>\n err ? reject(err) : resolve(hashRaw),\n ),\n )\n}\n\ntype Args = {\n collection: SanitizedCollectionConfig\n password: string\n req: PayloadRequest\n}\n\nexport const generatePasswordSaltHash = async ({\n collection,\n password: passwordToSet,\n req,\n}: Args): Promise<{ hash: string; salt: string }> => {\n const validationResult = password(passwordToSet, {\n name: 'password',\n type: 'text',\n blockData: {},\n data: {},\n event: 'submit',\n path: ['password'],\n preferences: { fields: {} },\n req,\n required: true,\n siblingData: {},\n })\n\n if (typeof validationResult === 'string') {\n throw new ValidationError({\n collection: collection?.slug,\n errors: [{ message: validationResult, path: 'password' }],\n })\n }\n\n const saltBuffer = await randomBytes()\n const salt = saltBuffer.toString('hex')\n\n const hashRaw = await pbkdf2Promisified(passwordToSet, salt)\n const hash = hashRaw.toString('hex')\n\n return { hash, salt }\n}\n"],"names":["crypto","ValidationError","password","randomBytes","Promise","resolve","reject","err","saltBuffer","pbkdf2Promisified","salt","pbkdf2","hashRaw","generatePasswordSaltHash","collection","passwordToSet","req","validationResult","name","type","blockData","data","event","path","preferences","fields","required","siblingData","slug","errors","message","toString","hash"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAK3B,SAASC,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,QAAQ,QAAQ,iCAAgC;AAEzD,SAASC;IACP,OAAO,IAAIC,QAAQ,CAACC,SAASC,SAC3BN,OAAOG,WAAW,CAAC,IAAI,CAACI,KAAKC,aAAgBD,MAAMD,OAAOC,OAAOF,QAAQG;AAE7E;AAEA,SAASC,kBAAkBP,QAAgB,EAAEQ,IAAY;IACvD,OAAO,IAAIN,QAAQ,CAACC,SAASC,SAC3BN,OAAOW,MAAM,CAACT,UAAUQ,MAAM,OAAO,KAAK,UAAU,CAACH,KAAKK,UACxDL,MAAMD,OAAOC,OAAOF,QAAQO;AAGlC;AAQA,OAAO,MAAMC,2BAA2B,OAAO,EAC7CC,UAAU,EACVZ,UAAUa,aAAa,EACvBC,GAAG,EACE;IACL,MAAMC,mBAAmBf,SAASa,eAAe;QAC/CG,MAAM;QACNC,MAAM;QACNC,WAAW,CAAC;QACZC,MAAM,CAAC;QACPC,OAAO;QACPC,MAAM;YAAC;SAAW;QAClBC,aAAa;YAAEC,QAAQ,CAAC;QAAE;QAC1BT;QACAU,UAAU;QACVC,aAAa,CAAC;IAChB;IAEA,IAAI,OAAOV,qBAAqB,UAAU;QACxC,MAAM,IAAIhB,gBAAgB;YACxBa,YAAYA,YAAYc;YACxBC,QAAQ;gBAAC;oBAAEC,SAASb;oBAAkBM,MAAM;gBAAW;aAAE;QAC3D;IACF;IAEA,MAAMf,aAAa,MAAML;IACzB,MAAMO,OAAOF,WAAWuB,QAAQ,CAAC;IAEjC,MAAMnB,UAAU,MAAMH,kBAAkBM,eAAeL;IACvD,MAAMsB,OAAOpB,QAAQmB,QAAQ,CAAC;IAE9B,OAAO;QAAEC;QAAMtB;IAAK;AACtB,EAAC"}
@@ -0,0 +1,175 @@
1
+ import { addPayloadComponentToImportMap } from './utilities/addPayloadComponentToImportMap.js';
2
+ import { getImportMapToBaseDirPath } from './utilities/getImportMapToBaseDirPath.js';
3
+ describe('addPayloadComponentToImportMap', ()=>{
4
+ let importMap;
5
+ let imports;
6
+ beforeEach(()=>{
7
+ importMap = {};
8
+ imports = {};
9
+ jest.restoreAllMocks();
10
+ });
11
+ function componentPathTest({ baseDir, importMapFilePath, payloadComponent, expectedPath, expectedSpecifier, expectedImportMapToBaseDirPath }) {
12
+ const importMapToBaseDirPath = getImportMapToBaseDirPath({
13
+ baseDir,
14
+ importMapPath: importMapFilePath
15
+ });
16
+ expect(importMapToBaseDirPath).toBe(expectedImportMapToBaseDirPath);
17
+ const { path, specifier } = addPayloadComponentToImportMap({
18
+ importMapToBaseDirPath,
19
+ importMap,
20
+ imports,
21
+ payloadComponent
22
+ }) ?? {};
23
+ expect(path).toBe(expectedPath);
24
+ expect(specifier).toBe(expectedSpecifier);
25
+ }
26
+ it('relative path with import map partially in base dir', ()=>{
27
+ componentPathTest({
28
+ baseDir: '/myPackage/test/myTest',
29
+ importMapFilePath: '/myPackage/app/(payload)/importMap.js',
30
+ payloadComponent: './MyComponent.js#MyExport',
31
+ expectedImportMapToBaseDirPath: '../../test/myTest/',
32
+ expectedPath: '../../test/myTest/MyComponent.js',
33
+ expectedSpecifier: 'MyExport'
34
+ });
35
+ });
36
+ it('relative path with import map partially in base dir 2', ()=>{
37
+ componentPathTest({
38
+ baseDir: '/myPackage/test/myTest',
39
+ importMapFilePath: '/myPackage/test/prod/app/(payload)/importMap.js',
40
+ payloadComponent: {
41
+ path: './MyComponent.js#MyExport'
42
+ },
43
+ expectedImportMapToBaseDirPath: '../../../myTest/',
44
+ expectedPath: '../../../myTest/MyComponent.js',
45
+ expectedSpecifier: 'MyExport'
46
+ });
47
+ });
48
+ it('relative path with import map partially in base dir 3', ()=>{
49
+ componentPathTest({
50
+ baseDir: '/myPackage/test/myTest',
51
+ importMapFilePath: '/myPackage/test/prod/app/(payload)/importMap.js',
52
+ payloadComponent: {
53
+ path: '../otherTest/MyComponent.js',
54
+ exportName: 'MyExport'
55
+ },
56
+ expectedImportMapToBaseDirPath: '../../../myTest/',
57
+ expectedPath: '../../../otherTest/MyComponent.js',
58
+ expectedSpecifier: 'MyExport'
59
+ });
60
+ });
61
+ it('relative path with import map within base dir', ()=>{
62
+ componentPathTest({
63
+ baseDir: '/myPackage/test/myTest',
64
+ importMapFilePath: '/myPackage/test/myTest/prod/app/(payload)/importMap.js',
65
+ payloadComponent: './MyComponent.js#MyExport',
66
+ expectedImportMapToBaseDirPath: '../../../',
67
+ expectedPath: '../../../MyComponent.js',
68
+ expectedSpecifier: 'MyExport'
69
+ });
70
+ });
71
+ it('relative path with import map not in base dir', ()=>{
72
+ componentPathTest({
73
+ baseDir: '/test/myTest',
74
+ importMapFilePath: '/app/(payload)/importMap.js',
75
+ payloadComponent: './MyComponent.js#MyExport',
76
+ expectedImportMapToBaseDirPath: '../../test/myTest/',
77
+ expectedPath: '../../test/myTest/MyComponent.js',
78
+ expectedSpecifier: 'MyExport'
79
+ });
80
+ });
81
+ it('relative path with import map not in base dir 2', ()=>{
82
+ componentPathTest({
83
+ baseDir: '/test/myTest',
84
+ importMapFilePath: '/app/(payload)/importMap.js',
85
+ payloadComponent: '../myOtherTest/MyComponent.js#MyExport',
86
+ expectedImportMapToBaseDirPath: '../../test/myTest/',
87
+ expectedPath: '../../test/myOtherTest/MyComponent.js',
88
+ expectedSpecifier: 'MyExport'
89
+ });
90
+ });
91
+ it('relative path with import map not in base dir, baseDir ending with slash', ()=>{
92
+ componentPathTest({
93
+ baseDir: '/test/myTest/',
94
+ importMapFilePath: '/app/(payload)/importMap.js',
95
+ payloadComponent: './MyComponent.js#MyExport',
96
+ expectedImportMapToBaseDirPath: '../../test/myTest/',
97
+ expectedPath: '../../test/myTest/MyComponent.js',
98
+ expectedSpecifier: 'MyExport'
99
+ });
100
+ });
101
+ it('relative path with import map not in base dir, component starting with slash', ()=>{
102
+ componentPathTest({
103
+ baseDir: '/test/myTest',
104
+ importMapFilePath: '/app/(payload)/importMap.js',
105
+ payloadComponent: '/MyComponent.js#MyExport',
106
+ expectedImportMapToBaseDirPath: '../../test/myTest/',
107
+ expectedPath: '../../test/myTest/MyComponent.js',
108
+ expectedSpecifier: 'MyExport'
109
+ });
110
+ });
111
+ it('aliased path', ()=>{
112
+ componentPathTest({
113
+ baseDir: '/test/myTest',
114
+ importMapFilePath: '/app/(payload)/importMap.js',
115
+ payloadComponent: '@components/MyComponent.js#MyExport',
116
+ expectedImportMapToBaseDirPath: '../../test/myTest/',
117
+ expectedPath: '@components/MyComponent.js',
118
+ expectedSpecifier: 'MyExport'
119
+ });
120
+ });
121
+ it('aliased path in PayloadComponent object', ()=>{
122
+ componentPathTest({
123
+ baseDir: '/test/',
124
+ importMapFilePath: '/app/(payload)/importMap.js',
125
+ payloadComponent: {
126
+ path: '@components/MyComponent.js'
127
+ },
128
+ expectedImportMapToBaseDirPath: '../../test/',
129
+ expectedPath: '@components/MyComponent.js',
130
+ expectedSpecifier: 'default'
131
+ });
132
+ });
133
+ it('relative path import starting with slash, going up', ()=>{
134
+ componentPathTest({
135
+ baseDir: '/test/myTest',
136
+ importMapFilePath: '/test/myTest/app/importMap.js',
137
+ payloadComponent: '/../MyComponent.js#MyExport',
138
+ expectedImportMapToBaseDirPath: '../',
139
+ expectedPath: '../../MyComponent.js',
140
+ expectedSpecifier: 'MyExport'
141
+ });
142
+ });
143
+ it('relative path import starting with dot-slash, going up', ()=>{
144
+ componentPathTest({
145
+ baseDir: '/test/myTest',
146
+ importMapFilePath: '/test/myTest/app/importMap.js',
147
+ payloadComponent: './../MyComponent.js#MyExport',
148
+ expectedImportMapToBaseDirPath: '../',
149
+ expectedPath: '../../MyComponent.js',
150
+ expectedSpecifier: 'MyExport'
151
+ });
152
+ });
153
+ it('importMap and baseDir in same directory', ()=>{
154
+ componentPathTest({
155
+ baseDir: '/test/myTest',
156
+ importMapFilePath: '/test/myTest/importMap.js',
157
+ payloadComponent: './MyComponent.js#MyExport',
158
+ expectedImportMapToBaseDirPath: './',
159
+ expectedPath: './MyComponent.js',
160
+ expectedSpecifier: 'MyExport'
161
+ });
162
+ });
163
+ it('baseDir within importMap dir', ()=>{
164
+ componentPathTest({
165
+ baseDir: '/test/myTest/components',
166
+ importMapFilePath: '/test/myTest/importMap.js',
167
+ payloadComponent: './MyComponent.js#MyExport',
168
+ expectedImportMapToBaseDirPath: './components/',
169
+ expectedPath: './components/MyComponent.js',
170
+ expectedSpecifier: 'MyExport'
171
+ });
172
+ });
173
+ });
174
+
175
+ //# sourceMappingURL=generateImportMap.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/bin/generateImportMap/generateImportMap.spec.ts"],"sourcesContent":["import type { PayloadComponent } from '../../index.js'\nimport { addPayloadComponentToImportMap } from './utilities/addPayloadComponentToImportMap.js'\nimport { getImportMapToBaseDirPath } from './utilities/getImportMapToBaseDirPath.js'\n\ndescribe('addPayloadComponentToImportMap', () => {\n let importMap: Record<string, string>\n let imports: Record<\n string,\n {\n path: string\n specifier: string\n }\n >\n\n beforeEach(() => {\n importMap = {}\n imports = {}\n jest.restoreAllMocks()\n })\n\n function componentPathTest({\n baseDir,\n importMapFilePath,\n payloadComponent,\n expectedPath,\n expectedSpecifier,\n expectedImportMapToBaseDirPath,\n }: {\n baseDir: string\n importMapFilePath: string\n payloadComponent: PayloadComponent\n expectedPath: string\n expectedImportMapToBaseDirPath: string\n expectedSpecifier: string\n }) {\n const importMapToBaseDirPath = getImportMapToBaseDirPath({\n baseDir,\n importMapPath: importMapFilePath,\n })\n\n expect(importMapToBaseDirPath).toBe(expectedImportMapToBaseDirPath)\n\n const { path, specifier } =\n addPayloadComponentToImportMap({\n importMapToBaseDirPath,\n importMap,\n imports,\n payloadComponent,\n }) ?? {}\n\n expect(path).toBe(expectedPath)\n expect(specifier).toBe(expectedSpecifier)\n }\n\n it('relative path with import map partially in base dir', () => {\n componentPathTest({\n baseDir: '/myPackage/test/myTest',\n importMapFilePath: '/myPackage/app/(payload)/importMap.js',\n payloadComponent: './MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../../test/myTest/',\n expectedPath: '../../test/myTest/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('relative path with import map partially in base dir 2', () => {\n componentPathTest({\n baseDir: '/myPackage/test/myTest',\n importMapFilePath: '/myPackage/test/prod/app/(payload)/importMap.js',\n payloadComponent: {\n path: './MyComponent.js#MyExport',\n },\n expectedImportMapToBaseDirPath: '../../../myTest/',\n expectedPath: '../../../myTest/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('relative path with import map partially in base dir 3', () => {\n componentPathTest({\n baseDir: '/myPackage/test/myTest',\n importMapFilePath: '/myPackage/test/prod/app/(payload)/importMap.js',\n payloadComponent: {\n path: '../otherTest/MyComponent.js',\n exportName: 'MyExport',\n },\n expectedImportMapToBaseDirPath: '../../../myTest/',\n expectedPath: '../../../otherTest/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('relative path with import map within base dir', () => {\n componentPathTest({\n baseDir: '/myPackage/test/myTest',\n importMapFilePath: '/myPackage/test/myTest/prod/app/(payload)/importMap.js',\n payloadComponent: './MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../../../',\n expectedPath: '../../../MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('relative path with import map not in base dir', () => {\n componentPathTest({\n baseDir: '/test/myTest',\n importMapFilePath: '/app/(payload)/importMap.js',\n payloadComponent: './MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../../test/myTest/',\n expectedPath: '../../test/myTest/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('relative path with import map not in base dir 2', () => {\n componentPathTest({\n baseDir: '/test/myTest',\n importMapFilePath: '/app/(payload)/importMap.js',\n payloadComponent: '../myOtherTest/MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../../test/myTest/',\n expectedPath: '../../test/myOtherTest/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('relative path with import map not in base dir, baseDir ending with slash', () => {\n componentPathTest({\n baseDir: '/test/myTest/',\n importMapFilePath: '/app/(payload)/importMap.js',\n payloadComponent: './MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../../test/myTest/',\n expectedPath: '../../test/myTest/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('relative path with import map not in base dir, component starting with slash', () => {\n componentPathTest({\n baseDir: '/test/myTest',\n importMapFilePath: '/app/(payload)/importMap.js',\n payloadComponent: '/MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../../test/myTest/',\n expectedPath: '../../test/myTest/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('aliased path', () => {\n componentPathTest({\n baseDir: '/test/myTest',\n importMapFilePath: '/app/(payload)/importMap.js',\n payloadComponent: '@components/MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../../test/myTest/',\n expectedPath: '@components/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n it('aliased path in PayloadComponent object', () => {\n componentPathTest({\n baseDir: '/test/',\n importMapFilePath: '/app/(payload)/importMap.js',\n payloadComponent: {\n path: '@components/MyComponent.js',\n },\n expectedImportMapToBaseDirPath: '../../test/',\n expectedPath: '@components/MyComponent.js',\n expectedSpecifier: 'default',\n })\n })\n\n it('relative path import starting with slash, going up', () => {\n componentPathTest({\n baseDir: '/test/myTest',\n importMapFilePath: '/test/myTest/app/importMap.js',\n payloadComponent: '/../MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../',\n expectedPath: '../../MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('relative path import starting with dot-slash, going up', () => {\n componentPathTest({\n baseDir: '/test/myTest',\n importMapFilePath: '/test/myTest/app/importMap.js',\n payloadComponent: './../MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: '../',\n expectedPath: '../../MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('importMap and baseDir in same directory', () => {\n componentPathTest({\n baseDir: '/test/myTest',\n importMapFilePath: '/test/myTest/importMap.js',\n payloadComponent: './MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: './',\n expectedPath: './MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n\n it('baseDir within importMap dir', () => {\n componentPathTest({\n baseDir: '/test/myTest/components',\n importMapFilePath: '/test/myTest/importMap.js',\n payloadComponent: './MyComponent.js#MyExport',\n expectedImportMapToBaseDirPath: './components/',\n expectedPath: './components/MyComponent.js',\n expectedSpecifier: 'MyExport',\n })\n })\n})\n"],"names":["addPayloadComponentToImportMap","getImportMapToBaseDirPath","describe","importMap","imports","beforeEach","jest","restoreAllMocks","componentPathTest","baseDir","importMapFilePath","payloadComponent","expectedPath","expectedSpecifier","expectedImportMapToBaseDirPath","importMapToBaseDirPath","importMapPath","expect","toBe","path","specifier","it","exportName"],"mappings":"AACA,SAASA,8BAA8B,QAAQ,gDAA+C;AAC9F,SAASC,yBAAyB,QAAQ,2CAA0C;AAEpFC,SAAS,kCAAkC;IACzC,IAAIC;IACJ,IAAIC;IAQJC,WAAW;QACTF,YAAY,CAAC;QACbC,UAAU,CAAC;QACXE,KAAKC,eAAe;IACtB;IAEA,SAASC,kBAAkB,EACzBC,OAAO,EACPC,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,EACZC,iBAAiB,EACjBC,8BAA8B,EAQ/B;QACC,MAAMC,yBAAyBd,0BAA0B;YACvDQ;YACAO,eAAeN;QACjB;QAEAO,OAAOF,wBAAwBG,IAAI,CAACJ;QAEpC,MAAM,EAAEK,IAAI,EAAEC,SAAS,EAAE,GACvBpB,+BAA+B;YAC7Be;YACAZ;YACAC;YACAO;QACF,MAAM,CAAC;QAETM,OAAOE,MAAMD,IAAI,CAACN;QAClBK,OAAOG,WAAWF,IAAI,CAACL;IACzB;IAEAQ,GAAG,uDAAuD;QACxDb,kBAAkB;YAChBC,SAAS;YACTC,mBAAmB;YACnBC,kBAAkB;YAClBG,gCAAgC;YAChCF,cAAc;YACdC,mBAAmB;QACrB;IACF;IAEAQ,GAAG,yDAAyD;QAC1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;YAChCF,cAAc;YACdC,mBAAmB;QACrB;IACF;IAEAQ,GAAG,sDAAsD;QACvDb,kBAAkB;YAChBC,SAAS;YACTC,mBAAmB;YACnBC,kBAAkB;YAClBG,gCAAgC;YAChCF,cAAc;YACdC,mBAAmB;QACrB;IACF;IAEAQ,GAAG,0DAA0D;QAC3Db,kBAAkB;YAChBC,SAAS;YACTC,mBAAmB;YACnBC,kBAAkB;YAClBG,gCAAgC;YAChCF,cAAc;YACdC,mBAAmB;QACrB;IACF;IAEAQ,GAAG,2CAA2C;QAC5Cb,kBAAkB;YAChBC,SAAS;YACTC,mBAAmB;YACnBC,kBAAkB;YAClBG,gCAAgC;YAChCF,cAAc;YACdC,mBAAmB;QACrB;IACF;IAEAQ,GAAG,gCAAgC;QACjCb,kBAAkB;YAChBC,SAAS;YACTC,mBAAmB;YACnBC,kBAAkB;YAClBG,gCAAgC;YAChCF,cAAc;YACdC,mBAAmB;QACrB;IACF;AACF"}
@@ -24,25 +24,17 @@ export type Imports = {
24
24
  export type ImportMap = {
25
25
  [path: UserImportPath]: any;
26
26
  };
27
- export declare function addPayloadComponentToImportMap({ baseDir, importMap, imports, payloadComponent, }: {
28
- baseDir: string;
29
- importMap: InternalImportMap;
30
- imports: Imports;
31
- payloadComponent: PayloadComponent;
32
- }): void;
33
27
  export type AddToImportMap = (payloadComponent: PayloadComponent | PayloadComponent[]) => void;
34
28
  export declare function generateImportMap(config: SanitizedConfig, options?: {
35
29
  force?: boolean;
36
30
  log: boolean;
37
31
  }): Promise<void>;
38
- export declare function writeImportMap({ componentMap, config, fileName, force, importMap, log, rootDir, }: {
32
+ export declare function writeImportMap({ componentMap, force, importMap, importMapFilePath, log, }: {
39
33
  componentMap: InternalImportMap;
40
- config: SanitizedConfig;
41
- fileName: string;
42
34
  force?: boolean;
43
35
  importMap: Imports;
36
+ importMapFilePath: string;
44
37
  log?: boolean;
45
- rootDir: string;
46
38
  }): Promise<void>;
47
39
  export {};
48
40
  //# sourceMappingURL=index.d.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,CAAA;CAAE,GAC1C,OAAO,CAAC,IAAI,CAAC,CAsEf;AAED,wBAAsB,cAAc,CAAC,EACnC,YAAY,EACZ,KAAK,EACL,SAAS,EACT,iBAAiB,EACjB,GAAG,GACJ,EAAE;IACD,YAAY,EAAE,iBAAiB,CAAA;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,SAAS,EAAE,OAAO,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;IACzB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,iBAmCA"}
@@ -1,36 +1,9 @@
1
- import crypto from 'crypto';
2
- import fs from 'fs';
1
+ /* eslint-disable no-console */ import fs from 'fs';
3
2
  import process from 'node:process';
4
- import path from 'path';
5
3
  import { iterateConfig } from './iterateConfig.js';
6
- import { parsePayloadComponent } from './parsePayloadComponent.js';
7
- export function addPayloadComponentToImportMap({ baseDir, importMap, imports, payloadComponent }) {
8
- if (!payloadComponent) {
9
- return;
10
- }
11
- const { exportName, path: componentPath } = parsePayloadComponent(payloadComponent);
12
- if (importMap[componentPath + '#' + exportName]) {
13
- return;
14
- }
15
- const importIdentifier = exportName + '_' + crypto.createHash('md5').update(componentPath).digest('hex');
16
- // e.g. if baseDir is /test/fields and componentPath is /components/Field.tsx
17
- // then path needs to be /test/fields/components/Field.tsx NOT /users/username/project/test/fields/components/Field.tsx
18
- // so we need to append baseDir to componentPath
19
- if (componentPath.startsWith('.') || componentPath.startsWith('/')) {
20
- const normalizedBaseDir = baseDir.replace(/\\/g, '/');
21
- const finalPath = normalizedBaseDir.startsWith('/../') ? `${normalizedBaseDir}${componentPath.slice(1)}` : path.posix.join(normalizedBaseDir, componentPath.slice(1));
22
- imports[importIdentifier] = {
23
- path: componentPath.startsWith('.') || componentPath.startsWith('/') ? finalPath : componentPath,
24
- specifier: exportName
25
- };
26
- } else {
27
- imports[importIdentifier] = {
28
- path: componentPath,
29
- specifier: exportName
30
- };
31
- }
32
- importMap[componentPath + '#' + exportName] = importIdentifier;
33
- }
4
+ import { addPayloadComponentToImportMap } from './utilities/addPayloadComponentToImportMap.js';
5
+ import { getImportMapToBaseDirPath } from './utilities/getImportMapToBaseDirPath.js';
6
+ import { resolveImportMapFilePath } from './utilities/resolveImportMapFilePath.js';
34
7
  export async function generateImportMap(config, options) {
35
8
  const shouldLog = options?.log ?? true;
36
9
  if (shouldLog) {
@@ -38,40 +11,18 @@ export async function generateImportMap(config, options) {
38
11
  }
39
12
  const importMap = {};
40
13
  const imports = {};
14
+ // Determine the root directory of the project - usually the directory where the src or app folder is located
41
15
  const rootDir = process.env.ROOT_DIR ?? process.cwd();
42
- // get componentsBaseDir.
43
- // E.g.:
44
- // config.admin.importMap.baseDir = /test/fields/
45
- // rootDir: /
46
- // componentsBaseDir = /test/fields/
47
- // or
48
- // E.g.:
49
- // config.admin.importMap.baseDir = /test/fields/
50
- // rootDir: /test
51
- // componentsBaseDir = /fields/
52
- // or
53
- // config.admin.importMap.baseDir = /
54
- // rootDir: /
55
- // componentsBaseDir = /
56
- // E.g.:
57
- // config.admin.importMap.baseDir = /test/fields/
58
- // rootDir: /test/fields/prod
59
- // componentsBaseDir = ../
60
- // Check if rootDir is a subdirectory of baseDir
61
- const baseDir = config.admin.importMap.baseDir;
62
- const isSubdirectory = path.relative(baseDir, rootDir).startsWith('..');
63
- let componentsBaseDir;
64
- if (isSubdirectory) {
65
- // Get the relative path from rootDir to baseDir
66
- componentsBaseDir = path.relative(rootDir, baseDir);
67
- } else {
68
- // If rootDir is not a subdirectory, just return baseDir relative to rootDir
69
- componentsBaseDir = `/${path.relative(rootDir, baseDir)}`;
70
- }
71
- // Ensure result has a trailing slash
72
- if (!componentsBaseDir.endsWith('/')) {
73
- componentsBaseDir += '/';
74
- }
16
+ const baseDir = config.admin.importMap.baseDir ?? process.cwd();
17
+ const importMapFilePath = resolveImportMapFilePath({
18
+ adminRoute: config.routes.admin,
19
+ importMapFile: config?.admin?.importMap?.importMapFile,
20
+ rootDir
21
+ });
22
+ const importMapToBaseDirPath = getImportMapToBaseDirPath({
23
+ baseDir,
24
+ importMapPath: importMapFilePath
25
+ });
75
26
  const addToImportMap = (payloadComponent)=>{
76
27
  if (!payloadComponent) {
77
28
  return;
@@ -83,16 +34,16 @@ export async function generateImportMap(config, options) {
83
34
  if (Array.isArray(payloadComponent)) {
84
35
  for (const component of payloadComponent){
85
36
  addPayloadComponentToImportMap({
86
- baseDir: componentsBaseDir,
87
37
  importMap,
38
+ importMapToBaseDirPath,
88
39
  imports,
89
40
  payloadComponent: component
90
41
  });
91
42
  }
92
43
  } else {
93
44
  addPayloadComponentToImportMap({
94
- baseDir: componentsBaseDir,
95
45
  importMap,
46
+ importMapToBaseDirPath,
96
47
  imports,
97
48
  payloadComponent
98
49
  });
@@ -107,32 +58,13 @@ export async function generateImportMap(config, options) {
107
58
  });
108
59
  await writeImportMap({
109
60
  componentMap: importMap,
110
- config,
111
- fileName: 'importMap.js',
112
61
  force: options?.force,
113
62
  importMap: imports,
114
- log: shouldLog,
115
- rootDir
63
+ importMapFilePath,
64
+ log: shouldLog
116
65
  });
117
66
  }
118
- export async function writeImportMap({ componentMap, config, fileName, force, importMap, log, rootDir }) {
119
- let importMapFilePath = undefined;
120
- if (config?.admin?.importMap?.importMapFile?.length) {
121
- if (!fs.existsSync(config.admin.importMap.importMapFile)) {
122
- throw new Error(`Could not find the import map file at ${config.admin.importMap.importMapFile}`);
123
- }
124
- importMapFilePath = config.admin.importMap.importMapFile;
125
- } else {
126
- const appLocation = path.resolve(rootDir, `app/(payload)${config.routes.admin}/`);
127
- const srcAppLocation = path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`);
128
- if (fs.existsSync(appLocation)) {
129
- importMapFilePath = path.resolve(appLocation, fileName);
130
- } else if (fs.existsSync(srcAppLocation)) {
131
- importMapFilePath = path.resolve(srcAppLocation, fileName);
132
- } else {
133
- throw new Error(`Could not find Payload import map folder. Looked in ${appLocation} and ${srcAppLocation}`);
134
- }
135
- }
67
+ export async function writeImportMap({ componentMap, force, importMap, importMapFilePath, log }) {
136
68
  const imports = [];
137
69
  for (const [identifier, { path, specifier }] of Object.entries(importMap)){
138
70
  imports.push(`import { ${specifier} as ${identifier} } from '${path}'`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/bin/generateImportMap/index.ts"],"sourcesContent":["import crypto from 'crypto'\nimport fs from 'fs'\nimport process from 'node:process'\nimport path from 'path'\n\nimport type { PayloadComponent, SanitizedConfig } from '../../config/types.js'\n\nimport { iterateConfig } from './iterateConfig.js'\nimport { parsePayloadComponent } from './parsePayloadComponent.js'\n\ntype ImportIdentifier = string\ntype ImportSpecifier = string\ntype ImportPath = string\ntype UserImportPath = string\n\n/**\n * Import Map before being written to the file. Only contains all paths\n */\nexport type InternalImportMap = {\n [path: UserImportPath]: ImportIdentifier\n}\n\n/**\n * Imports of the import map.\n */\nexport type Imports = {\n [identifier: ImportIdentifier]: {\n path: ImportPath\n specifier: ImportSpecifier\n }\n}\n\n/**\n * Import Map after being imported from the actual import map. Contains all the actual imported components\n */\nexport type ImportMap = {\n [path: UserImportPath]: any\n}\n\nexport function addPayloadComponentToImportMap({\n baseDir,\n importMap,\n imports,\n payloadComponent,\n}: {\n baseDir: string\n importMap: InternalImportMap\n imports: Imports\n payloadComponent: PayloadComponent\n}) {\n if (!payloadComponent) {\n return\n }\n const { exportName, path: componentPath } = parsePayloadComponent(payloadComponent)\n\n if (importMap[componentPath + '#' + exportName]) {\n return\n }\n\n const importIdentifier =\n exportName + '_' + crypto.createHash('md5').update(componentPath).digest('hex')\n\n // e.g. if baseDir is /test/fields and componentPath is /components/Field.tsx\n // then path needs to be /test/fields/components/Field.tsx NOT /users/username/project/test/fields/components/Field.tsx\n // so we need to append baseDir to componentPath\n\n if (componentPath.startsWith('.') || componentPath.startsWith('/')) {\n const normalizedBaseDir = baseDir.replace(/\\\\/g, '/')\n\n const finalPath = normalizedBaseDir.startsWith('/../')\n ? `${normalizedBaseDir}${componentPath.slice(1)}`\n : path.posix.join(normalizedBaseDir, componentPath.slice(1))\n\n imports[importIdentifier] = {\n path:\n componentPath.startsWith('.') || componentPath.startsWith('/') ? finalPath : componentPath,\n specifier: exportName,\n }\n } else {\n imports[importIdentifier] = {\n path: componentPath,\n specifier: exportName,\n }\n }\n importMap[componentPath + '#' + exportName] = importIdentifier\n}\n\nexport type AddToImportMap = (payloadComponent: PayloadComponent | PayloadComponent[]) => void\n\nexport async function generateImportMap(\n config: SanitizedConfig,\n options?: { force?: boolean; log: boolean },\n): Promise<void> {\n const shouldLog = options?.log ?? true\n\n if (shouldLog) {\n console.log('Generating import map')\n }\n\n const importMap: InternalImportMap = {}\n const imports: Imports = {}\n\n const rootDir = process.env.ROOT_DIR ?? process.cwd()\n\n // get componentsBaseDir.\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /\n // componentsBaseDir = /test/fields/\n\n // or\n\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /test\n // componentsBaseDir = /fields/\n\n // or\n // config.admin.importMap.baseDir = /\n // rootDir: /\n // componentsBaseDir = /\n\n // E.g.:\n // config.admin.importMap.baseDir = /test/fields/\n // rootDir: /test/fields/prod\n // componentsBaseDir = ../\n\n // Check if rootDir is a subdirectory of baseDir\n const baseDir = config.admin.importMap.baseDir\n const isSubdirectory = path.relative(baseDir, rootDir).startsWith('..')\n\n let componentsBaseDir\n\n if (isSubdirectory) {\n // Get the relative path from rootDir to baseDir\n componentsBaseDir = path.relative(rootDir, baseDir)\n } else {\n // If rootDir is not a subdirectory, just return baseDir relative to rootDir\n componentsBaseDir = `/${path.relative(rootDir, baseDir)}`\n }\n\n // Ensure result has a trailing slash\n if (!componentsBaseDir.endsWith('/')) {\n componentsBaseDir += '/'\n }\n\n const addToImportMap: AddToImportMap = (payloadComponent) => {\n if (!payloadComponent) {\n return\n }\n\n if (typeof payloadComponent !== 'object' && typeof payloadComponent !== 'string') {\n console.error(payloadComponent)\n throw new Error('addToImportMap > Payload component must be an object or a string')\n }\n\n if (Array.isArray(payloadComponent)) {\n for (const component of payloadComponent) {\n addPayloadComponentToImportMap({\n baseDir: componentsBaseDir,\n importMap,\n imports,\n payloadComponent: component,\n })\n }\n } else {\n addPayloadComponentToImportMap({\n baseDir: componentsBaseDir,\n importMap,\n imports,\n payloadComponent,\n })\n }\n }\n\n iterateConfig({\n addToImportMap,\n baseDir: config.admin.importMap.baseDir,\n config,\n importMap,\n imports,\n })\n\n await writeImportMap({\n componentMap: importMap,\n config,\n fileName: 'importMap.js',\n force: options?.force,\n importMap: imports,\n log: shouldLog,\n rootDir,\n })\n}\n\nexport async function writeImportMap({\n componentMap,\n config,\n fileName,\n force,\n importMap,\n log,\n rootDir,\n}: {\n componentMap: InternalImportMap\n config: SanitizedConfig\n fileName: string\n force?: boolean\n importMap: Imports\n log?: boolean\n rootDir: string\n}) {\n let importMapFilePath: string | undefined = undefined\n\n if (config?.admin?.importMap?.importMapFile?.length) {\n if (!fs.existsSync(config.admin.importMap.importMapFile)) {\n throw new Error(\n `Could not find the import map file at ${config.admin.importMap.importMapFile}`,\n )\n }\n importMapFilePath = config.admin.importMap.importMapFile\n } else {\n const appLocation = path.resolve(rootDir, `app/(payload)${config.routes.admin}/`)\n const srcAppLocation = path.resolve(rootDir, `src/app/(payload)${config.routes.admin}/`)\n\n if (fs.existsSync(appLocation)) {\n importMapFilePath = path.resolve(appLocation, fileName)\n } else if (fs.existsSync(srcAppLocation)) {\n importMapFilePath = path.resolve(srcAppLocation, fileName)\n } else {\n throw new Error(\n `Could not find Payload import map folder. Looked in ${appLocation} and ${srcAppLocation}`,\n )\n }\n }\n\n const imports: string[] = []\n for (const [identifier, { path, specifier }] of Object.entries(importMap)) {\n imports.push(`import { ${specifier} as ${identifier} } from '${path}'`)\n }\n\n const mapKeys: string[] = []\n for (const [userPath, identifier] of Object.entries(componentMap)) {\n mapKeys.push(` \"${userPath}\": ${identifier}`)\n }\n\n const importMapOutputFile = `${imports.join('\\n')}\n\nexport const importMap = {\n${mapKeys.join(',\\n')}\n}\n`\n\n if (!force) {\n // Read current import map and check in the IMPORTS if there are any new imports. If not, don't write the file.\n const currentImportMap = await fs.promises.readFile(importMapFilePath, 'utf-8')\n\n if (currentImportMap?.trim() === importMapOutputFile?.trim()) {\n if (log) {\n console.log('No new imports found, skipping writing import map')\n }\n return\n }\n }\n\n if (log) {\n console.log('Writing import map to', importMapFilePath)\n }\n\n await fs.promises.writeFile(importMapFilePath, importMapOutputFile)\n}\n"],"names":["crypto","fs","process","path","iterateConfig","parsePayloadComponent","addPayloadComponentToImportMap","baseDir","importMap","imports","payloadComponent","exportName","componentPath","importIdentifier","createHash","update","digest","startsWith","normalizedBaseDir","replace","finalPath","slice","posix","join","specifier","generateImportMap","config","options","shouldLog","log","console","rootDir","env","ROOT_DIR","cwd","admin","isSubdirectory","relative","componentsBaseDir","endsWith","addToImportMap","error","Error","Array","isArray","component","writeImportMap","componentMap","fileName","force","importMapFilePath","undefined","importMapFile","length","existsSync","appLocation","resolve","routes","srcAppLocation","identifier","Object","entries","push","mapKeys","userPath","importMapOutputFile","currentImportMap","promises","readFile","trim","writeFile"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,QAAQ,KAAI;AACnB,OAAOC,aAAa,eAAc;AAClC,OAAOC,UAAU,OAAM;AAIvB,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,qBAAqB,QAAQ,6BAA4B;AA+BlE,OAAO,SAASC,+BAA+B,EAC7CC,OAAO,EACPC,SAAS,EACTC,OAAO,EACPC,gBAAgB,EAMjB;IACC,IAAI,CAACA,kBAAkB;QACrB;IACF;IACA,MAAM,EAAEC,UAAU,EAAER,MAAMS,aAAa,EAAE,GAAGP,sBAAsBK;IAElE,IAAIF,SAAS,CAACI,gBAAgB,MAAMD,WAAW,EAAE;QAC/C;IACF;IAEA,MAAME,mBACJF,aAAa,MAAMX,OAAOc,UAAU,CAAC,OAAOC,MAAM,CAACH,eAAeI,MAAM,CAAC;IAE3E,6EAA6E;IAC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I,CAAC0B,OAAO;QACV,+GAA+G;QAC/G,MAAMiB,mBAAmB,MAAMjE,GAAGkE,QAAQ,CAACC,QAAQ,CAAClB,mBAAmB;QAEvE,IAAIgB,kBAAkBG,WAAWJ,qBAAqBI,QAAQ;YAC5D,IAAIxC,KAAK;gBACPC,QAAQD,GAAG,CAAC;YACd;YACA;QACF;IACF;IAEA,IAAIA,KAAK;QACPC,QAAQD,GAAG,CAAC,yBAAyBqB;IACvC;IAEA,MAAMjD,GAAGkE,QAAQ,CAACG,SAAS,CAACpB,mBAAmBe;AACjD"}
1
+ {"version":3,"sources":["../../../src/bin/generateImportMap/index.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport fs from 'fs'\nimport process from 'node:process'\n\nimport type { PayloadComponent, SanitizedConfig } from '../../config/types.js'\n\nimport { iterateConfig } from './iterateConfig.js'\nimport { addPayloadComponentToImportMap } from './utilities/addPayloadComponentToImportMap.js'\nimport { getImportMapToBaseDirPath } from './utilities/getImportMapToBaseDirPath.js'\nimport { resolveImportMapFilePath } from './utilities/resolveImportMapFilePath.js'\n\ntype ImportIdentifier = string\ntype ImportSpecifier = string\ntype ImportPath = string\ntype UserImportPath = string\n\n/**\n * Import Map before being written to the file. Only contains all paths\n */\nexport type InternalImportMap = {\n [path: UserImportPath]: ImportIdentifier\n}\n\n/**\n * Imports of the import map.\n */\nexport type Imports = {\n [identifier: ImportIdentifier]: {\n path: ImportPath\n specifier: ImportSpecifier\n }\n}\n\n/**\n * Import Map after being imported from the actual import map. Contains all the actual imported components\n */\nexport type ImportMap = {\n [path: UserImportPath]: any\n}\n\nexport type AddToImportMap = (payloadComponent: PayloadComponent | PayloadComponent[]) => void\n\nexport async function generateImportMap(\n config: SanitizedConfig,\n options?: { force?: boolean; log: boolean },\n): Promise<void> {\n const shouldLog = options?.log ?? true\n\n if (shouldLog) {\n console.log('Generating import map')\n }\n\n const importMap: InternalImportMap = {}\n const imports: Imports = {}\n\n // Determine the root directory of the project - usually the directory where the src or app folder is located\n const rootDir = process.env.ROOT_DIR ?? process.cwd()\n\n const baseDir = config.admin.importMap.baseDir ?? process.cwd()\n\n const importMapFilePath = resolveImportMapFilePath({\n adminRoute: config.routes.admin,\n importMapFile: config?.admin?.importMap?.importMapFile,\n rootDir,\n })\n\n const importMapToBaseDirPath = getImportMapToBaseDirPath({\n baseDir,\n importMapPath: importMapFilePath,\n })\n\n const addToImportMap: AddToImportMap = (payloadComponent) => {\n if (!payloadComponent) {\n return\n }\n\n if (typeof payloadComponent !== 'object' && typeof payloadComponent !== 'string') {\n console.error(payloadComponent)\n throw new Error('addToImportMap > Payload component must be an object or a string')\n }\n\n if (Array.isArray(payloadComponent)) {\n for (const component of payloadComponent) {\n addPayloadComponentToImportMap({\n importMap,\n importMapToBaseDirPath,\n imports,\n payloadComponent: component,\n })\n }\n } else {\n addPayloadComponentToImportMap({\n importMap,\n importMapToBaseDirPath,\n imports,\n payloadComponent,\n })\n }\n }\n\n iterateConfig({\n addToImportMap,\n baseDir: config.admin.importMap.baseDir,\n config,\n importMap,\n imports,\n })\n\n await writeImportMap({\n componentMap: importMap,\n force: options?.force,\n importMap: imports,\n importMapFilePath,\n log: shouldLog,\n })\n}\n\nexport async function writeImportMap({\n componentMap,\n force,\n importMap,\n importMapFilePath,\n log,\n}: {\n componentMap: InternalImportMap\n force?: boolean\n importMap: Imports\n importMapFilePath: string\n log?: boolean\n}) {\n const imports: string[] = []\n for (const [identifier, { path, specifier }] of Object.entries(importMap)) {\n imports.push(`import { ${specifier} as ${identifier} } from '${path}'`)\n }\n\n const mapKeys: string[] = []\n for (const [userPath, identifier] of Object.entries(componentMap)) {\n mapKeys.push(` \"${userPath}\": ${identifier}`)\n }\n\n const importMapOutputFile = `${imports.join('\\n')}\n\nexport const importMap = {\n${mapKeys.join(',\\n')}\n}\n`\n\n if (!force) {\n // Read current import map and check in the IMPORTS if there are any new imports. If not, don't write the file.\n const currentImportMap = await fs.promises.readFile(importMapFilePath, 'utf-8')\n\n if (currentImportMap?.trim() === importMapOutputFile?.trim()) {\n if (log) {\n console.log('No new imports found, skipping writing import map')\n }\n return\n }\n }\n\n if (log) {\n console.log('Writing import map to', importMapFilePath)\n }\n\n await fs.promises.writeFile(importMapFilePath, importMapOutputFile)\n}\n"],"names":["fs","process","iterateConfig","addPayloadComponentToImportMap","getImportMapToBaseDirPath","resolveImportMapFilePath","generateImportMap","config","options","shouldLog","log","console","importMap","imports","rootDir","env","ROOT_DIR","cwd","baseDir","admin","importMapFilePath","adminRoute","routes","importMapFile","importMapToBaseDirPath","importMapPath","addToImportMap","payloadComponent","error","Error","Array","isArray","component","writeImportMap","componentMap","force","identifier","path","specifier","Object","entries","push","mapKeys","userPath","importMapOutputFile","join","currentImportMap","promises","readFile","trim","writeFile"],"mappings":"AAAA,6BAA6B,GAC7B,OAAOA,QAAQ,KAAI;AACnB,OAAOC,aAAa,eAAc;AAIlC,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,8BAA8B,QAAQ,gDAA+C;AAC9F,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,wBAAwB,QAAQ,0CAAyC;AAiClF,OAAO,eAAeC,kBACpBC,MAAuB,EACvBC,OAA2C;IAE3C,MAAMC,YAAYD,SAASE,OAAO;IAElC,IAAID,WAAW;QACbE,QAAQD,GAAG,CAAC;IACd;IAEA,MAAME,YAA+B,CAAC;IACtC,MAAMC,UAAmB,CAAC;IAE1B,6GAA6G;IAC7G,MAAMC,UAAUb,QAAQc,GAAG,CAACC,QAAQ,IAAIf,QAAQgB,GAAG;IAEnD,MAAMC,UAAUX,OAAOY,KAAK,CAACP,SAAS,CAACM,OAAO,IAAIjB,QAAQgB,GAAG;IAE7D,MAAMG,oBAAoBf,yBAAyB;QACjDgB,YAAYd,OAAOe,MAAM,CAACH,KAAK;QAC/BI,eAAehB,QAAQY,OAAOP,WAAWW;QACzCT;IACF;IAEA,MAAMU,yBAAyBpB,0BAA0B;QACvDc;QACAO,eAAeL;IACjB;IAEA,MAAMM,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