payload 3.28.0-internal.c4e1bed → 3.28.0
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/dist/auth/strategies/local/generatePasswordSaltHash.d.ts.map +1 -1
- package/dist/auth/strategies/local/generatePasswordSaltHash.js +3 -0
- package/dist/auth/strategies/local/generatePasswordSaltHash.js.map +1 -1
- package/dist/bin/generateImportMap/generateImportMap.spec.js +175 -0
- package/dist/bin/generateImportMap/generateImportMap.spec.js.map +1 -0
- package/dist/bin/generateImportMap/index.d.ts +2 -10
- package/dist/bin/generateImportMap/index.d.ts.map +1 -1
- package/dist/bin/generateImportMap/index.js +20 -88
- package/dist/bin/generateImportMap/index.js.map +1 -1
- package/dist/bin/generateImportMap/iterateConfig.js.map +1 -1
- package/dist/bin/generateImportMap/utilities/addPayloadComponentToImportMap.d.ts +15 -0
- package/dist/bin/generateImportMap/utilities/addPayloadComponentToImportMap.d.ts.map +1 -0
- package/dist/bin/generateImportMap/utilities/addPayloadComponentToImportMap.js +56 -0
- package/dist/bin/generateImportMap/utilities/addPayloadComponentToImportMap.js.map +1 -0
- package/dist/bin/generateImportMap/{getFromImportMap.d.ts → utilities/getFromImportMap.d.ts} +2 -2
- package/dist/bin/generateImportMap/utilities/getFromImportMap.d.ts.map +1 -0
- package/dist/bin/generateImportMap/utilities/getFromImportMap.js.map +1 -0
- package/dist/bin/generateImportMap/utilities/getImportMapToBaseDirPath.d.ts +15 -0
- package/dist/bin/generateImportMap/utilities/getImportMapToBaseDirPath.d.ts.map +1 -0
- package/dist/bin/generateImportMap/utilities/getImportMapToBaseDirPath.js +22 -0
- package/dist/bin/generateImportMap/utilities/getImportMapToBaseDirPath.js.map +1 -0
- package/dist/bin/generateImportMap/{parsePayloadComponent.d.ts → utilities/parsePayloadComponent.d.ts} +1 -1
- package/dist/bin/generateImportMap/utilities/parsePayloadComponent.d.ts.map +1 -0
- package/dist/bin/generateImportMap/utilities/parsePayloadComponent.js.map +1 -0
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts +9 -0
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts.map +1 -0
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js +26 -0
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js.map +1 -0
- package/dist/collections/config/types.d.ts +4 -0
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +2 -0
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/types.d.ts +14 -50
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/exports/shared.d.ts +2 -2
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +2 -2
- package/dist/exports/shared.js.map +1 -1
- package/dist/fields/config/client.js +1 -1
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/config/types.d.ts +4 -0
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +1 -0
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/locked-documents/config.d.ts.map +1 -1
- package/dist/locked-documents/config.js +7 -0
- package/dist/locked-documents/config.js.map +1 -1
- package/dist/uploads/generateFileData.js +1 -1
- package/dist/uploads/generateFileData.js.map +1 -1
- package/package.json +2 -2
- package/dist/bin/generateImportMap/getFromImportMap.d.ts.map +0 -1
- package/dist/bin/generateImportMap/getFromImportMap.js.map +0 -1
- package/dist/bin/generateImportMap/parsePayloadComponent.d.ts.map +0 -1
- package/dist/bin/generateImportMap/parsePayloadComponent.js.map +0 -1
- /package/dist/bin/generateImportMap/{getFromImportMap.js → utilities/getFromImportMap.js} +0 -0
- /package/dist/bin/generateImportMap/{parsePayloadComponent.js → utilities/parsePayloadComponent.js} +0 -0
|
@@ -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,
|
|
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"}
|
|
@@ -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","
|
|
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;QAC1Db,kBAAkB;YAChBC,SAAS;YACTC,mBAAmB;YACnBC,kBAAkB;gBAChBQ,MAAM;YACR;YACAL,gCAAgC;YAChCF,cAAc;YACdC,mBAAmB;QACrB;IACF;IAEAQ,GAAG,yDAAyD;QAC1Db,kBAAkB;YAChBC,SAAS;YACTC,mBAAmB;YACnBC,kBAAkB;gBAChBQ,MAAM;gBACNG,YAAY;YACd;YACAR,gCAAgC;YAChCF,cAAc;YACdC,mBAAmB;QACrB;IACF;IAEAQ,GAAG,iDAAiD;QAClDb,kBA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A2C;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,
|
|
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.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bin/generateImportMap/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources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
-
import
|
|
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 {
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
115
|
-
|
|
63
|
+
importMapFilePath,
|
|
64
|
+
log: shouldLog
|
|
116
65
|
});
|
|
117
66
|
}
|
|
118
|
-
export async function writeImportMap({ componentMap,
|
|
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,KAA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,EAAExD,IAAI,EAAEqB,SAAS,EAAE,CAAC,IAAIoC,OAAOC,OAAO,CAACrD,WAAY;QACzEC,QAAQqD,IAAI,CAAC,CAAC,SAAS,EAAEtC,UAAU,IAAI,EAAEmC,WAAW,SAAS,EAAExD,KAAK,CAAC,CAAC;IACxE;IAEA,MAAM4D,UAAoB,EAAE;IAC5B,KAAK,MAAM,CAACC,UAAUL,WAAW,IAAIC,OAAOC,OAAO,CAACd,cAAe;QACjEgB,QAAQD,IAAI,CAAC,CAAC,GAAG,EAAEE,SAAS,GAAG,EAAEL,YAAY;IAC/C;IAEA,MAAMM,sBAAsB,GAAGxD,QAAQc,IAAI,CAAC,MAAM;;;AAGpD,EAAEwC,QAAQxC,IAAI,CAAC,OAAO;;AAEtB,CAAC;IAEC,IAAI,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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AAY,EAAEC,IAAI,EAAEC,SAAS,EAAE,CAAC,IAAIC,OAAOC,OAAO,CAAC5B,WAAY;QACzEC,QAAQ4B,IAAI,CAAC,CAAC,SAAS,EAAEH,UAAU,IAAI,EAAEF,WAAW,SAAS,EAAEC,KAAK,CAAC,CAAC;IACxE;IAEA,MAAMK,UAAoB,EAAE;IAC5B,KAAK,MAAM,CAACC,UAAUP,WAAW,IAAIG,OAAOC,OAAO,CAACN,cAAe;QACjEQ,QAAQD,IAAI,CAAC,CAAC,GAAG,EAAEE,SAAS,GAAG,EAAEP,YAAY;IAC/C;IAEA,MAAMQ,sBAAsB,GAAG/B,QAAQgC,IAAI,CAAC,MAAM;;;AAGpD,EAAEH,QAAQG,IAAI,CAAC,OAAO;;AAEtB,CAAC;IAEC,IAAI,CAACV,OAAO;QACV,+GAA+G;QAC/G,MAAMW,mBAAmB,MAAM9C,GAAG+C,QAAQ,CAACC,QAAQ,CAAC5B,mBAAmB;QAEvE,IAAI0B,kBAAkBG,WAAWL,qBAAqBK,QAAQ;YAC5D,IAAIvC,KAAK;gBACPC,QAAQD,GAAG,CAAC;YACd;YACA;QACF;IACF;IAEA,IAAIA,KAAK;QACPC,QAAQD,GAAG,CAAC,yBAAyBU;IACvC;IAEA,MAAMpB,GAAG+C,QAAQ,CAACG,SAAS,CAAC9B,mBAAmBwB;AACjD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/bin/generateImportMap/iterateConfig.ts"],"sourcesContent":["// @ts-strict-ignore\n\nimport type { AdminViewConfig } from '../../admin/views/index.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { AddToImportMap, Imports, InternalImportMap } from './index.js'\n\nimport { iterateCollections } from './iterateCollections.js'\nimport { genImportMapIterateFields } from './iterateFields.js'\nimport { iterateGlobals } from './iterateGlobals.js'\n\nexport function iterateConfig({\n addToImportMap,\n baseDir,\n config,\n importMap,\n imports,\n}: {\n addToImportMap: AddToImportMap\n baseDir: string\n config: SanitizedConfig\n importMap: InternalImportMap\n imports: Imports\n}) {\n iterateCollections({\n addToImportMap,\n baseDir,\n collections: config.collections,\n config,\n importMap,\n imports,\n })\n\n iterateGlobals({\n addToImportMap,\n baseDir,\n config,\n globals: config.globals,\n importMap,\n imports,\n })\n\n if (config?.blocks) {\n const blocks = Object.values(config.blocks)\n if (blocks?.length) {\n genImportMapIterateFields({\n addToImportMap,\n baseDir,\n config,\n fields: blocks,\n importMap,\n imports,\n })\n }\n }\n\n if (typeof config.admin?.avatar === 'object') {\n addToImportMap(config.admin?.avatar?.Component)\n }\n\n addToImportMap(config.admin?.components?.Nav)\n addToImportMap(config.admin?.components?.header)\n addToImportMap(config.admin?.components?.logout?.Button)\n addToImportMap(config.admin?.components?.graphics?.Icon)\n addToImportMap(config.admin?.components?.graphics?.Logo)\n\n addToImportMap(config.admin?.components?.actions)\n addToImportMap(config.admin?.components?.afterDashboard)\n addToImportMap(config.admin?.components?.afterLogin)\n addToImportMap(config.admin?.components?.afterNavLinks)\n addToImportMap(config.admin?.components?.beforeDashboard)\n addToImportMap(config.admin?.components?.beforeLogin)\n addToImportMap(config.admin?.components?.beforeNavLinks)\n\n addToImportMap(config.admin?.components?.providers)\n\n if (config.admin?.components?.views) {\n if (Object.keys(config.admin?.components?.views)?.length) {\n for (const key in config.admin?.components?.views) {\n const adminViewConfig
|
|
1
|
+
{"version":3,"sources":["../../../src/bin/generateImportMap/iterateConfig.ts"],"sourcesContent":["// @ts-strict-ignore\n\nimport type { AdminViewConfig } from '../../admin/views/index.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { AddToImportMap, Imports, InternalImportMap } from './index.js'\n\nimport { iterateCollections } from './iterateCollections.js'\nimport { genImportMapIterateFields } from './iterateFields.js'\nimport { iterateGlobals } from './iterateGlobals.js'\n\nexport function iterateConfig({\n addToImportMap,\n baseDir,\n config,\n importMap,\n imports,\n}: {\n addToImportMap: AddToImportMap\n baseDir: string\n config: SanitizedConfig\n importMap: InternalImportMap\n imports: Imports\n}) {\n iterateCollections({\n addToImportMap,\n baseDir,\n collections: config.collections,\n config,\n importMap,\n imports,\n })\n\n iterateGlobals({\n addToImportMap,\n baseDir,\n config,\n globals: config.globals,\n importMap,\n imports,\n })\n\n if (config?.blocks) {\n const blocks = Object.values(config.blocks)\n if (blocks?.length) {\n genImportMapIterateFields({\n addToImportMap,\n baseDir,\n config,\n fields: blocks,\n importMap,\n imports,\n })\n }\n }\n\n if (typeof config.admin?.avatar === 'object') {\n addToImportMap(config.admin?.avatar?.Component)\n }\n\n addToImportMap(config.admin?.components?.Nav)\n addToImportMap(config.admin?.components?.header)\n addToImportMap(config.admin?.components?.logout?.Button)\n addToImportMap(config.admin?.components?.graphics?.Icon)\n addToImportMap(config.admin?.components?.graphics?.Logo)\n\n addToImportMap(config.admin?.components?.actions)\n addToImportMap(config.admin?.components?.afterDashboard)\n addToImportMap(config.admin?.components?.afterLogin)\n addToImportMap(config.admin?.components?.afterNavLinks)\n addToImportMap(config.admin?.components?.beforeDashboard)\n addToImportMap(config.admin?.components?.beforeLogin)\n addToImportMap(config.admin?.components?.beforeNavLinks)\n\n addToImportMap(config.admin?.components?.providers)\n\n if (config.admin?.components?.views) {\n if (Object.keys(config.admin?.components?.views)?.length) {\n for (const key in config.admin?.components?.views) {\n const adminViewConfig = config.admin?.components?.views[key]\n addToImportMap(adminViewConfig?.Component)\n }\n }\n }\n\n if (config?.admin?.importMap?.generators?.length) {\n for (const generator of config.admin.importMap.generators) {\n generator({\n addToImportMap,\n baseDir,\n config,\n importMap,\n imports,\n })\n }\n }\n\n if (config?.admin?.dependencies) {\n for (const key in config.admin.dependencies) {\n const dependency = config.admin.dependencies[key]\n addToImportMap(dependency.path)\n }\n }\n\n /*\n if (\n config?.editor &&\n typeof config.editor === 'object' &&\n config.editor.generateImportMap &&\n typeof config.editor.generateImportMap === 'function'\n ) {\n config.editor.generateImportMap({\n addToImportMap,\n baseDir,\n componentMap,\n config,\n importMap,\n })\n }*/ // No need to do that here since in the sanitized editor config, this root editor is already added to the field editor - and we already process that in iterateFields\n}\n"],"names":["iterateCollections","genImportMapIterateFields","iterateGlobals","iterateConfig","addToImportMap","baseDir","config","importMap","imports","collections","globals","blocks","Object","values","length","fields","admin","avatar","Component","components","Nav","header","logout","Button","graphics","Icon","Logo","actions","afterDashboard","afterLogin","afterNavLinks","beforeDashboard","beforeLogin","beforeNavLinks","providers","views","keys","key","adminViewConfig","generators","generator","dependencies","dependency","path"],"mappings":"AAAA,oBAAoB;AAMpB,SAASA,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,yBAAyB,QAAQ,qBAAoB;AAC9D,SAASC,cAAc,QAAQ,sBAAqB;AAEpD,OAAO,SAASC,cAAc,EAC5BC,cAAc,EACdC,OAAO,EACPC,MAAM,EACNC,SAAS,EACTC,OAAO,EAOR;IACCR,mBAAmB;QACjBI;QACAC;QACAI,aAAaH,OAAOG,WAAW;QAC/BH;QACAC;QACAC;IACF;IAEAN,eAAe;QACbE;QACAC;QACAC;QACAI,SAASJ,OAAOI,OAAO;QACvBH;QACAC;IACF;IAEA,IAAIF,QAAQK,QAAQ;QAClB,MAAMA,SAASC,OAAOC,MAAM,CAACP,OAAOK,MAAM;QAC1C,IAAIA,QAAQG,QAAQ;YAClBb,0BAA0B;gBACxBG;gBACAC;gBACAC;gBACAS,QAAQJ;gBACRJ;gBACAC;YACF;QACF;IACF;IAEA,IAAI,OAAOF,OAAOU,KAAK,EAAEC,WAAW,UAAU;QAC5Cb,eAAeE,OAAOU,KAAK,EAAEC,QAAQC;IACvC;IAEAd,eAAeE,OAAOU,KAAK,EAAEG,YAAYC;IACzChB,eAAeE,OAAOU,KAAK,EAAEG,YAAYE;IACzCjB,eAAeE,OAAOU,KAAK,EAAEG,YAAYG,QAAQC;IACjDnB,eAAeE,OAAOU,KAAK,EAAEG,YAAYK,UAAUC;IACnDrB,eAAeE,OAAOU,KAAK,EAAEG,YAAYK,UAAUE;IAEnDtB,eAAeE,OAAOU,KAAK,EAAEG,YAAYQ;IACzCvB,eAAeE,OAAOU,KAAK,EAAEG,YAAYS;IACzCxB,eAAeE,OAAOU,KAAK,EAAEG,YAAYU;IACzCzB,eAAeE,OAAOU,KAAK,EAAEG,YAAYW;IACzC1B,eAAeE,OAAOU,KAAK,EAAEG,YAAYY;IACzC3B,eAAeE,OAAOU,KAAK,EAAEG,YAAYa;IACzC5B,eAAeE,OAAOU,KAAK,EAAEG,YAAYc;IAEzC7B,eAAeE,OAAOU,KAAK,EAAEG,YAAYe;IAEzC,IAAI5B,OAAOU,KAAK,EAAEG,YAAYgB,OAAO;QACnC,IAAIvB,OAAOwB,IAAI,CAAC9B,OAAOU,KAAK,EAAEG,YAAYgB,QAAQrB,QAAQ;YACxD,IAAK,MAAMuB,OAAO/B,OAAOU,KAAK,EAAEG,YAAYgB,MAAO;gBACjD,MAAMG,kBAAkBhC,OAAOU,KAAK,EAAEG,YAAYgB,KAAK,CAACE,IAAI;gBAC5DjC,eAAekC,iBAAiBpB;YAClC;QACF;IACF;IAEA,IAAIZ,QAAQU,OAAOT,WAAWgC,YAAYzB,QAAQ;QAChD,KAAK,MAAM0B,aAAalC,OAAOU,KAAK,CAACT,SAAS,CAACgC,UAAU,CAAE;YACzDC,UAAU;gBACRpC;gBACAC;gBACAC;gBACAC;gBACAC;YACF;QACF;IACF;IAEA,IAAIF,QAAQU,OAAOyB,cAAc;QAC/B,IAAK,MAAMJ,OAAO/B,OAAOU,KAAK,CAACyB,YAAY,CAAE;YAC3C,MAAMC,aAAapC,OAAOU,KAAK,CAACyB,YAAY,CAACJ,IAAI;YACjDjC,eAAesC,WAAWC,IAAI;QAChC;IACF;AAEA;;;;;;;;;;;;;;GAcC,GAAG,qKAAqK;AAC3K"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PayloadComponent } from '../../../config/types.js';
|
|
2
|
+
import type { Imports, InternalImportMap } from '../index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Adds a payload component to the import map.
|
|
5
|
+
*/
|
|
6
|
+
export declare function addPayloadComponentToImportMap({ importMap, importMapToBaseDirPath, imports, payloadComponent, }: {
|
|
7
|
+
importMap: InternalImportMap;
|
|
8
|
+
importMapToBaseDirPath: string;
|
|
9
|
+
imports: Imports;
|
|
10
|
+
payloadComponent: PayloadComponent;
|
|
11
|
+
}): {
|
|
12
|
+
path: string;
|
|
13
|
+
specifier: string;
|
|
14
|
+
} | null;
|
|
15
|
+
//# sourceMappingURL=addPayloadComponentToImportMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addPayloadComponentToImportMap.d.ts","sourceRoot":"","sources":["../../../../src/bin/generateImportMap/utilities/addPayloadComponentToImportMap.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AA2B7D;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,SAAS,EACT,sBAAsB,EACtB,OAAO,EACP,gBAAgB,GACjB,EAAE;IACD,SAAS,EAAE,iBAAiB,CAAA;IAC5B,sBAAsB,EAAE,MAAM,CAAA;IAC9B,OAAO,EAAE,OAAO,CAAA;IAChB,gBAAgB,EAAE,gBAAgB,CAAA;CACnC,GAAG;IACF,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,IAAI,CAuCP"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { parsePayloadComponent } from './parsePayloadComponent.js';
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes the component path based on the import map's base directory path.
|
|
6
|
+
*/ function getAdjustedComponentPath(importMapToBaseDirPath, componentPath) {
|
|
7
|
+
// Normalize input paths to use forward slashes
|
|
8
|
+
const normalizedBasePath = importMapToBaseDirPath.replace(/\\/g, '/');
|
|
9
|
+
const normalizedComponentPath = componentPath.replace(/\\/g, '/');
|
|
10
|
+
// Base path starts with './' - preserve the './' prefix
|
|
11
|
+
// => import map is in a subdirectory of the base directory, or in the same directory as the base directory
|
|
12
|
+
if (normalizedBasePath.startsWith('./')) {
|
|
13
|
+
// Remove './' from component path if it exists
|
|
14
|
+
const cleanComponentPath = normalizedComponentPath.startsWith('./') ? normalizedComponentPath.substring(2) : normalizedComponentPath;
|
|
15
|
+
// Join the paths to preserve the './' prefix
|
|
16
|
+
return `${normalizedBasePath}${cleanComponentPath}`;
|
|
17
|
+
}
|
|
18
|
+
return path.posix.join(normalizedBasePath, normalizedComponentPath);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Adds a payload component to the import map.
|
|
22
|
+
*/ export function addPayloadComponentToImportMap({ importMap, importMapToBaseDirPath, imports, payloadComponent }) {
|
|
23
|
+
if (!payloadComponent) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const { exportName, path: componentPath } = parsePayloadComponent(payloadComponent);
|
|
27
|
+
if (importMap[componentPath + '#' + exportName]) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const importIdentifier = exportName + '_' + crypto.createHash('md5').update(componentPath).digest('hex');
|
|
31
|
+
importMap[componentPath + '#' + exportName] = importIdentifier;
|
|
32
|
+
const isRelativePath = componentPath.startsWith('.') || componentPath.startsWith('/');
|
|
33
|
+
if (isRelativePath) {
|
|
34
|
+
const adjustedComponentPath = getAdjustedComponentPath(importMapToBaseDirPath, componentPath);
|
|
35
|
+
imports[importIdentifier] = {
|
|
36
|
+
path: adjustedComponentPath,
|
|
37
|
+
specifier: exportName
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
path: adjustedComponentPath,
|
|
41
|
+
specifier: exportName
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
// Tsconfig alias or package import, e.g. '@payloadcms/ui' or '@/components/MyComponent'
|
|
45
|
+
imports[importIdentifier] = {
|
|
46
|
+
path: componentPath,
|
|
47
|
+
specifier: exportName
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
path: componentPath,
|
|
51
|
+
specifier: exportName
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=addPayloadComponentToImportMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/bin/generateImportMap/utilities/addPayloadComponentToImportMap.ts"],"sourcesContent":["import crypto from 'crypto'\nimport path from 'path'\n\nimport type { PayloadComponent } from '../../../config/types.js'\nimport type { Imports, InternalImportMap } from '../index.js'\n\nimport { parsePayloadComponent } from './parsePayloadComponent.js'\n\n/**\n * Normalizes the component path based on the import map's base directory path.\n */\nfunction getAdjustedComponentPath(importMapToBaseDirPath: string, componentPath: string): string {\n // Normalize input paths to use forward slashes\n const normalizedBasePath = importMapToBaseDirPath.replace(/\\\\/g, '/')\n const normalizedComponentPath = componentPath.replace(/\\\\/g, '/')\n\n // Base path starts with './' - preserve the './' prefix\n // => import map is in a subdirectory of the base directory, or in the same directory as the base directory\n if (normalizedBasePath.startsWith('./')) {\n // Remove './' from component path if it exists\n const cleanComponentPath = normalizedComponentPath.startsWith('./')\n ? normalizedComponentPath.substring(2)\n : normalizedComponentPath\n\n // Join the paths to preserve the './' prefix\n return `${normalizedBasePath}${cleanComponentPath}`\n }\n\n return path.posix.join(normalizedBasePath, normalizedComponentPath)\n}\n\n/**\n * Adds a payload component to the import map.\n */\nexport function addPayloadComponentToImportMap({\n importMap,\n importMapToBaseDirPath,\n imports,\n payloadComponent,\n}: {\n importMap: InternalImportMap\n importMapToBaseDirPath: string\n imports: Imports\n payloadComponent: PayloadComponent\n}): {\n path: string\n specifier: string\n} | null {\n if (!payloadComponent) {\n return null\n }\n const { exportName, path: componentPath } = parsePayloadComponent(payloadComponent)\n\n if (importMap[componentPath + '#' + exportName]) {\n return null\n }\n\n const importIdentifier =\n exportName + '_' + crypto.createHash('md5').update(componentPath).digest('hex')\n\n importMap[componentPath + '#' + exportName] = importIdentifier\n\n const isRelativePath = componentPath.startsWith('.') || componentPath.startsWith('/')\n\n if (isRelativePath) {\n const adjustedComponentPath = getAdjustedComponentPath(importMapToBaseDirPath, componentPath)\n\n imports[importIdentifier] = {\n path: adjustedComponentPath,\n specifier: exportName,\n }\n return {\n path: adjustedComponentPath,\n specifier: exportName,\n }\n } else {\n // Tsconfig alias or package import, e.g. '@payloadcms/ui' or '@/components/MyComponent'\n imports[importIdentifier] = {\n path: componentPath,\n specifier: exportName,\n }\n return {\n path: componentPath,\n specifier: exportName,\n }\n }\n}\n"],"names":["crypto","path","parsePayloadComponent","getAdjustedComponentPath","importMapToBaseDirPath","componentPath","normalizedBasePath","replace","normalizedComponentPath","startsWith","cleanComponentPath","substring","posix","join","addPayloadComponentToImportMap","importMap","imports","payloadComponent","exportName","importIdentifier","createHash","update","digest","isRelativePath","adjustedComponentPath","specifier"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AAKvB,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE;;CAEC,GACD,SAASC,yBAAyBC,sBAA8B,EAAEC,aAAqB;IACrF,+CAA+C;IAC/C,MAAMC,qBAAqBF,uBAAuBG,OAAO,CAAC,OAAO;IACjE,MAAMC,0BAA0BH,cAAcE,OAAO,CAAC,OAAO;IAE7D,wDAAwD;IACxD,2GAA2G;IAC3G,IAAID,mBAAmBG,UAAU,CAAC,OAAO;QACvC,+CAA+C;QAC/C,MAAMC,qBAAqBF,wBAAwBC,UAAU,CAAC,QAC1DD,wBAAwBG,SAAS,CAAC,KAClCH;QAEJ,6CAA6C;QAC7C,OAAO,GAAGF,qBAAqBI,oBAAoB;IACrD;IAEA,OAAOT,KAAKW,KAAK,CAACC,IAAI,CAACP,oBAAoBE;AAC7C;AAEA;;CAEC,GACD,OAAO,SAASM,+BAA+B,EAC7CC,SAAS,EACTX,sBAAsB,EACtBY,OAAO,EACPC,gBAAgB,EAMjB;IAIC,IAAI,CAACA,kBAAkB;QACrB,OAAO;IACT;IACA,MAAM,EAAEC,UAAU,EAAEjB,MAAMI,aAAa,EAAE,GAAGH,sBAAsBe;IAElE,IAAIF,SAAS,CAACV,gBAAgB,MAAMa,WAAW,EAAE;QAC/C,OAAO;IACT;IAEA,MAAMC,mBACJD,aAAa,MAAMlB,OAAOoB,UAAU,CAAC,OAAOC,MAAM,CAAChB,eAAeiB,MAAM,CAAC;IAE3EP,SAAS,CAACV,gBAAgB,MAAMa,WAAW,GAAGC;IAE9C,MAAMI,iBAAiBlB,cAAcI,UAAU,CAAC,QAAQJ,cAAcI,UAAU,CAAC;IAEjF,IAAIc,gBAAgB;QAClB,MAAMC,wBAAwBrB,yBAAyBC,wBAAwBC;QAE/EW,OAAO,CAACG,iBAAiB,GAAG;YAC1BlB,MAAMuB;YACNC,WAAWP;QACb;QACA,OAAO;YACLjB,MAAMuB;YACNC,WAAWP;QACb;IACF,OAAO;QACL,wFAAwF;QACxFF,OAAO,CAACG,iBAAiB,GAAG;YAC1BlB,MAAMI;YACNoB,WAAWP;QACb;QACA,OAAO;YACLjB,MAAMI;YACNoB,WAAWP;QACb;IACF;AACF"}
|
package/dist/bin/generateImportMap/{getFromImportMap.d.ts → utilities/getFromImportMap.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PayloadComponent } from '
|
|
2
|
-
import type { ImportMap } from '
|
|
1
|
+
import type { PayloadComponent } from '../../../config/types.js';
|
|
2
|
+
import type { ImportMap } from '../index.js';
|
|
3
3
|
export declare const getFromImportMap: <TOutput>(args: {
|
|
4
4
|
importMap: ImportMap;
|
|
5
5
|
PayloadComponent: PayloadComponent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFromImportMap.d.ts","sourceRoot":"","sources":["../../../../src/bin/generateImportMap/utilities/getFromImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C,eAAO,MAAM,gBAAgB,GAAI,OAAO,QAAQ;IAC9C,SAAS,EAAE,SAAS,CAAA;IACpB,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,KAAG,OAuBH,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/bin/generateImportMap/utilities/getFromImportMap.ts"],"sourcesContent":["import type { PayloadComponent } from '../../../config/types.js'\nimport type { ImportMap } from '../index.js'\nimport { parsePayloadComponent } from './parsePayloadComponent.js'\n\nexport const getFromImportMap = <TOutput>(args: {\n importMap: ImportMap\n PayloadComponent: PayloadComponent\n schemaPath?: string\n silent?: boolean\n}): TOutput => {\n const { importMap, PayloadComponent, schemaPath, silent } = args\n\n const { exportName, path } = parsePayloadComponent(PayloadComponent)\n\n const key = path + '#' + exportName\n\n const importMapEntry = importMap[key]\n\n if (!importMapEntry && !silent) {\n // eslint-disable-next-line no-console\n console.error(\n `getFromImportMap: PayloadComponent not found in importMap`,\n {\n key,\n PayloadComponent,\n schemaPath,\n },\n 'You may need to run the `payload generate:importmap` command to generate the importMap ahead of runtime.',\n )\n }\n\n return importMapEntry\n}\n"],"names":["parsePayloadComponent","getFromImportMap","args","importMap","PayloadComponent","schemaPath","silent","exportName","path","key","importMapEntry","console","error"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,6BAA4B;AAElE,OAAO,MAAMC,mBAAmB,CAAUC;IAMxC,MAAM,EAAEC,SAAS,EAAEC,gBAAgB,EAAEC,UAAU,EAAEC,MAAM,EAAE,GAAGJ;IAE5D,MAAM,EAAEK,UAAU,EAAEC,IAAI,EAAE,GAAGR,sBAAsBI;IAEnD,MAAMK,MAAMD,OAAO,MAAMD;IAEzB,MAAMG,iBAAiBP,SAAS,CAACM,IAAI;IAErC,IAAI,CAACC,kBAAkB,CAACJ,QAAQ;QAC9B,sCAAsC;QACtCK,QAAQC,KAAK,CACX,CAAC,yDAAyD,CAAC,EAC3D;YACEH;YACAL;YACAC;QACF,GACA;IAEJ;IAEA,OAAOK;AACT,EAAC"}
|