@sitecore-content-sdk/core 1.3.0-canary.9 → 1.4.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/cjs/cache-client.js +55 -54
- package/dist/cjs/client/constants.js +7 -7
- package/dist/cjs/client/edge-proxy.js +24 -22
- package/dist/cjs/client/index.js +15 -15
- package/dist/cjs/client/models.js +2 -2
- package/dist/cjs/client/sitecore-client.js +421 -419
- package/dist/cjs/client/utils.js +47 -46
- package/dist/cjs/config/define-config.js +194 -193
- package/dist/cjs/config/index.js +7 -7
- package/dist/cjs/config/models.js +12 -11
- package/dist/cjs/config-cli/define-cli-config.js +23 -22
- package/dist/cjs/config-cli/index.js +7 -7
- package/dist/cjs/config-cli/models.js +8 -7
- package/dist/cjs/constants.js +49 -17
- package/dist/cjs/debug.js +48 -46
- package/dist/cjs/editing/codegen/index.js +14 -9
- package/dist/cjs/editing/codegen/preview.js +277 -193
- package/dist/cjs/editing/component-layout-service.js +62 -61
- package/dist/cjs/editing/design-library.js +183 -126
- package/dist/cjs/editing/editing-service.js +75 -74
- package/dist/cjs/editing/index.js +33 -27
- package/dist/cjs/editing/metadata.js +42 -42
- package/dist/cjs/editing/models.js +44 -38
- package/dist/cjs/editing/utils.js +108 -90
- package/dist/cjs/form/form.js +81 -78
- package/dist/cjs/form/index.js +7 -7
- package/dist/cjs/graphql-request-client.js +108 -107
- package/dist/cjs/i18n/dictionary-service.js +122 -121
- package/dist/cjs/i18n/index.js +7 -7
- package/dist/cjs/i18n/utils.js +16 -15
- package/dist/cjs/index.js +60 -60
- package/dist/cjs/layout/content-styles.js +72 -71
- package/dist/cjs/layout/index.js +24 -24
- package/dist/cjs/layout/layout-service.js +62 -57
- package/dist/cjs/layout/models.js +39 -34
- package/dist/cjs/layout/themes.js +76 -75
- package/dist/cjs/layout/utils.js +117 -110
- package/dist/cjs/media/index.js +38 -38
- package/dist/cjs/media/media-api.js +100 -96
- package/dist/cjs/models.js +2 -2
- package/dist/cjs/native-fetcher.js +194 -179
- package/dist/cjs/personalize/index.js +15 -15
- package/dist/cjs/personalize/layout-personalizer.js +98 -97
- package/dist/cjs/personalize/personalize-service.js +98 -94
- package/dist/cjs/personalize/utils.js +143 -136
- package/dist/cjs/retries.js +43 -42
- package/dist/cjs/site/error-pages-service.js +65 -64
- package/dist/cjs/site/index.js +26 -26
- package/dist/cjs/site/models.js +2 -2
- package/dist/cjs/site/redirects-service.js +94 -81
- package/dist/cjs/site/robots-service.js +66 -65
- package/dist/cjs/site/site-resolver.js +73 -72
- package/dist/cjs/site/siteinfo-service.js +84 -80
- package/dist/cjs/site/sitemap-xml-service.js +84 -83
- package/dist/cjs/site/sitepath-service.js +165 -164
- package/dist/cjs/site/utils.js +55 -47
- package/dist/cjs/sitecore-service-base.js +36 -36
- package/dist/cjs/tools/auth/flow.js +65 -64
- package/dist/cjs/tools/auth/index.js +5 -5
- package/dist/cjs/tools/auth/models.js +2 -2
- package/dist/cjs/tools/auth/tenant-store.js +38 -38
- package/dist/cjs/tools/codegen/component-generation.js +52 -50
- package/dist/cjs/tools/codegen/extract-files.js +105 -107
- package/dist/cjs/tools/codegen/import-map.js +401 -349
- package/dist/cjs/tools/codegen/utils.js +418 -418
- package/dist/cjs/tools/generate-map.js +2 -2
- package/dist/cjs/tools/generateMetadata.js +36 -35
- package/dist/cjs/tools/generateSites.js +59 -58
- package/dist/cjs/tools/index.js +75 -73
- package/dist/cjs/tools/scaffold.js +60 -59
- package/dist/cjs/tools/templating/components.js +96 -266
- package/dist/cjs/tools/templating/index.js +11 -14
- package/dist/cjs/tools/templating/plugins.js +80 -78
- package/dist/cjs/tools/templating/utils.js +67 -66
- package/dist/cjs/utils/ensurePath.js +20 -20
- package/dist/cjs/utils/env.js +28 -27
- package/dist/cjs/utils/globalCache.js +55 -0
- package/dist/cjs/utils/index.js +26 -21
- package/dist/cjs/utils/is-server.js +11 -10
- package/dist/cjs/utils/normalize-url.js +5 -5
- package/dist/cjs/utils/timeout-promise.js +31 -31
- package/dist/cjs/utils/utils.js +254 -229
- package/dist/esm/cache-client.js +51 -50
- package/dist/esm/client/constants.js +4 -4
- package/dist/esm/client/edge-proxy.js +19 -17
- package/dist/esm/client/index.js +5 -5
- package/dist/esm/client/models.js +1 -1
- package/dist/esm/client/sitecore-client.js +414 -412
- package/dist/esm/client/utils.js +43 -42
- package/dist/esm/config/define-config.js +188 -187
- package/dist/esm/config/index.js +2 -2
- package/dist/esm/config/models.js +9 -8
- package/dist/esm/config-cli/define-cli-config.js +19 -18
- package/dist/esm/config-cli/index.js +2 -2
- package/dist/esm/config-cli/models.js +5 -4
- package/dist/esm/constants.js +46 -14
- package/dist/esm/debug.js +41 -39
- package/dist/esm/editing/codegen/index.js +1 -1
- package/dist/esm/editing/codegen/preview.js +263 -185
- package/dist/esm/editing/component-layout-service.js +55 -54
- package/dist/esm/editing/design-library.js +171 -117
- package/dist/esm/editing/editing-service.js +68 -67
- package/dist/esm/editing/index.js +6 -5
- package/dist/esm/editing/metadata.js +39 -39
- package/dist/esm/editing/models.js +41 -35
- package/dist/esm/editing/utils.js +98 -80
- package/dist/esm/form/form.js +72 -69
- package/dist/esm/form/index.js +1 -1
- package/dist/esm/graphql-request-client.js +101 -100
- package/dist/esm/i18n/dictionary-service.js +115 -114
- package/dist/esm/i18n/index.js +2 -2
- package/dist/esm/i18n/utils.js +13 -12
- package/dist/esm/index.js +13 -13
- package/dist/esm/layout/content-styles.js +64 -63
- package/dist/esm/layout/index.js +6 -6
- package/dist/esm/layout/layout-service.js +55 -50
- package/dist/esm/layout/models.js +36 -31
- package/dist/esm/layout/themes.js +71 -70
- package/dist/esm/layout/utils.js +109 -102
- package/dist/esm/media/index.js +2 -2
- package/dist/esm/media/media-api.js +90 -86
- package/dist/esm/models.js +1 -1
- package/dist/esm/native-fetcher.js +187 -172
- package/dist/esm/personalize/index.js +3 -3
- package/dist/esm/personalize/layout-personalizer.js +93 -92
- package/dist/esm/personalize/personalize-service.js +91 -87
- package/dist/esm/personalize/utils.js +135 -128
- package/dist/esm/retries.js +39 -38
- package/dist/esm/site/error-pages-service.js +58 -57
- package/dist/esm/site/index.js +8 -8
- package/dist/esm/site/models.js +1 -1
- package/dist/esm/site/redirects-service.js +87 -74
- package/dist/esm/site/robots-service.js +59 -58
- package/dist/esm/site/site-resolver.js +69 -68
- package/dist/esm/site/siteinfo-service.js +77 -73
- package/dist/esm/site/sitemap-xml-service.js +77 -76
- package/dist/esm/site/sitepath-service.js +157 -156
- package/dist/esm/site/utils.js +49 -41
- package/dist/esm/sitecore-service-base.js +29 -29
- package/dist/esm/tools/auth/flow.js +62 -61
- package/dist/esm/tools/auth/index.js +1 -1
- package/dist/esm/tools/auth/models.js +1 -1
- package/dist/esm/tools/auth/tenant-store.js +35 -35
- package/dist/esm/tools/codegen/component-generation.js +44 -42
- package/dist/esm/tools/codegen/extract-files.js +99 -101
- package/dist/esm/tools/codegen/import-map.js +358 -306
- package/dist/esm/tools/codegen/utils.js +373 -373
- package/dist/esm/tools/generate-map.js +1 -1
- package/dist/esm/tools/generateMetadata.js +29 -28
- package/dist/esm/tools/generateSites.js +52 -51
- package/dist/esm/tools/index.js +28 -27
- package/dist/esm/tools/scaffold.js +52 -51
- package/dist/esm/tools/templating/components.js +59 -223
- package/dist/esm/tools/templating/index.js +3 -3
- package/dist/esm/tools/templating/plugins.js +72 -70
- package/dist/esm/tools/templating/utils.js +59 -58
- package/dist/esm/utils/ensurePath.js +13 -13
- package/dist/esm/utils/env.js +24 -23
- package/dist/esm/utils/globalCache.js +49 -0
- package/dist/esm/utils/index.js +4 -3
- package/dist/esm/utils/is-server.js +9 -8
- package/dist/esm/utils/normalize-url.js +1 -1
- package/dist/esm/utils/timeout-promise.js +28 -28
- package/dist/esm/utils/utils.js +238 -213
- package/package.json +73 -5
- package/types/cache-client.d.ts +68 -64
- package/types/cache-client.d.ts.map +1 -0
- package/types/client/constants.d.ts +5 -4
- package/types/client/constants.d.ts.map +1 -0
- package/types/client/edge-proxy.d.ts +18 -15
- package/types/client/edge-proxy.d.ts.map +1 -0
- package/types/client/index.d.ts +8 -7
- package/types/client/index.d.ts.map +1 -0
- package/types/client/models.d.ts +21 -19
- package/types/client/models.d.ts.map +1 -0
- package/types/client/sitecore-client.d.ts +338 -327
- package/types/client/sitecore-client.d.ts.map +1 -0
- package/types/client/utils.d.ts +15 -9
- package/types/client/utils.d.ts.map +1 -0
- package/types/config/define-config.d.ts +20 -18
- package/types/config/define-config.d.ts.map +1 -0
- package/types/config/index.d.ts +3 -2
- package/types/config/index.d.ts.map +1 -0
- package/types/config/models.d.ts +287 -268
- package/types/config/models.d.ts.map +1 -0
- package/types/config-cli/define-cli-config.d.ts +9 -7
- package/types/config-cli/define-cli-config.d.ts.map +1 -0
- package/types/config-cli/index.d.ts +3 -2
- package/types/config-cli/index.d.ts.map +1 -0
- package/types/config-cli/models.d.ts +6 -4
- package/types/config-cli/models.d.ts.map +1 -0
- package/types/constants.d.ts +44 -11
- package/types/constants.d.ts.map +1 -0
- package/types/debug.d.ts +35 -28
- package/types/debug.d.ts.map +1 -0
- package/types/editing/codegen/index.d.ts +2 -1
- package/types/editing/codegen/index.d.ts.map +1 -0
- package/types/editing/codegen/preview.d.ts +256 -195
- package/types/editing/codegen/preview.d.ts.map +1 -0
- package/types/editing/component-layout-service.d.ts +84 -80
- package/types/editing/component-layout-service.d.ts.map +1 -0
- package/types/editing/design-library.d.ts +111 -63
- package/types/editing/design-library.d.ts.map +1 -0
- package/types/editing/editing-service.d.ts +72 -62
- package/types/editing/editing-service.d.ts.map +1 -0
- package/types/editing/index.d.ts +7 -6
- package/types/editing/index.d.ts.map +1 -0
- package/types/editing/metadata.d.ts +8 -7
- package/types/editing/metadata.d.ts.map +1 -0
- package/types/editing/models.d.ts +103 -92
- package/types/editing/models.d.ts.map +1 -0
- package/types/editing/utils.d.ts +91 -74
- package/types/editing/utils.d.ts.map +1 -0
- package/types/form/form.d.ts +25 -21
- package/types/form/form.d.ts.map +1 -0
- package/types/form/index.d.ts +2 -1
- package/types/form/index.d.ts.map +1 -0
- package/types/graphql-request-client.d.ts +112 -105
- package/types/graphql-request-client.d.ts.map +1 -0
- package/types/i18n/dictionary-service.d.ts +135 -131
- package/types/i18n/dictionary-service.d.ts.map +1 -0
- package/types/i18n/index.d.ts +3 -2
- package/types/i18n/index.d.ts.map +1 -0
- package/types/i18n/utils.d.ts +9 -7
- package/types/i18n/utils.d.ts.map +1 -0
- package/types/index.d.ts +13 -12
- package/types/index.d.ts.map +1 -0
- package/types/layout/content-styles.d.ts +20 -18
- package/types/layout/content-styles.d.ts.map +1 -0
- package/types/layout/index.d.ts +6 -5
- package/types/layout/index.d.ts.map +1 -0
- package/types/layout/layout-service.d.ts +45 -35
- package/types/layout/layout-service.d.ts.map +1 -0
- package/types/layout/models.d.ts +174 -151
- package/types/layout/models.d.ts.map +1 -0
- package/types/layout/themes.d.ts +13 -11
- package/types/layout/themes.d.ts.map +1 -0
- package/types/layout/utils.d.ts +56 -41
- package/types/layout/utils.d.ts.map +1 -0
- package/types/media/index.d.ts +3 -2
- package/types/media/index.d.ts.map +1 -0
- package/types/media/media-api.d.ts +60 -55
- package/types/media/media-api.d.ts.map +1 -0
- package/types/models.d.ts +94 -84
- package/types/models.d.ts.map +1 -0
- package/types/native-fetcher.d.ts +124 -114
- package/types/native-fetcher.d.ts.map +1 -0
- package/types/personalize/index.d.ts +4 -3
- package/types/personalize/index.d.ts.map +1 -0
- package/types/personalize/layout-personalizer.d.ts +29 -27
- package/types/personalize/layout-personalizer.d.ts.map +1 -0
- package/types/personalize/personalize-service.d.ts +90 -80
- package/types/personalize/personalize-service.d.ts.map +1 -0
- package/types/personalize/utils.d.ts +78 -69
- package/types/personalize/utils.d.ts.map +1 -0
- package/types/retries.d.ts +26 -24
- package/types/retries.d.ts.map +1 -0
- package/types/site/error-pages-service.d.ts +64 -57
- package/types/site/error-pages-service.d.ts.map +1 -0
- package/types/site/index.d.ts +10 -9
- package/types/site/index.d.ts.map +1 -0
- package/types/site/models.d.ts +23 -18
- package/types/site/models.d.ts.map +1 -0
- package/types/site/redirects-service.d.ts +92 -69
- package/types/site/redirects-service.d.ts.map +1 -0
- package/types/site/robots-service.d.ts +57 -50
- package/types/site/robots-service.d.ts.map +1 -0
- package/types/site/site-resolver.d.ts +28 -26
- package/types/site/site-resolver.d.ts.map +1 -0
- package/types/site/siteinfo-service.d.ts +65 -52
- package/types/site/siteinfo-service.d.ts.map +1 -0
- package/types/site/sitemap-xml-service.d.ts +63 -56
- package/types/site/sitemap-xml-service.d.ts.map +1 -0
- package/types/site/sitepath-service.d.ts +137 -134
- package/types/site/sitepath-service.d.ts.map +1 -0
- package/types/site/utils.d.ts +41 -28
- package/types/site/utils.d.ts.map +1 -0
- package/types/sitecore-service-base.d.ts +31 -30
- package/types/sitecore-service-base.d.ts.map +1 -0
- package/types/tools/auth/flow.d.ts +29 -27
- package/types/tools/auth/flow.d.ts.map +1 -0
- package/types/tools/auth/index.d.ts +2 -1
- package/types/tools/auth/index.d.ts.map +1 -0
- package/types/tools/auth/models.d.ts +35 -33
- package/types/tools/auth/models.d.ts.map +1 -0
- package/types/tools/auth/tenant-store.d.ts +12 -11
- package/types/tools/auth/tenant-store.d.ts.map +1 -0
- package/types/tools/codegen/component-generation.d.ts +50 -47
- package/types/tools/codegen/component-generation.d.ts.map +1 -0
- package/types/tools/codegen/extract-files.d.ts +24 -22
- package/types/tools/codegen/extract-files.d.ts.map +1 -0
- package/types/tools/codegen/import-map.d.ts +103 -70
- package/types/tools/codegen/import-map.d.ts.map +1 -0
- package/types/tools/codegen/utils.d.ts +76 -75
- package/types/tools/codegen/utils.d.ts.map +1 -0
- package/types/tools/generate-map.d.ts +36 -26
- package/types/tools/generate-map.d.ts.map +1 -0
- package/types/tools/generateMetadata.d.ts +24 -22
- package/types/tools/generateMetadata.d.ts.map +1 -0
- package/types/tools/generateSites.d.ts +25 -22
- package/types/tools/generateSites.d.ts.map +1 -0
- package/types/tools/index.d.ts +22 -20
- package/types/tools/index.d.ts.map +1 -0
- package/types/tools/scaffold.d.ts +27 -25
- package/types/tools/scaffold.d.ts.map +1 -0
- package/types/tools/templating/components.d.ts +104 -103
- package/types/tools/templating/components.d.ts.map +1 -0
- package/types/tools/templating/index.d.ts +4 -3
- package/types/tools/templating/index.d.ts.map +1 -0
- package/types/tools/templating/plugins.d.ts +71 -67
- package/types/tools/templating/plugins.d.ts.map +1 -0
- package/types/tools/templating/utils.d.ts +42 -40
- package/types/tools/templating/utils.d.ts.map +1 -0
- package/types/utils/ensurePath.d.ts +7 -6
- package/types/utils/ensurePath.d.ts.map +1 -0
- package/types/utils/env.d.ts +9 -7
- package/types/utils/env.d.ts.map +1 -0
- package/types/utils/globalCache.d.ts +37 -0
- package/types/utils/globalCache.d.ts.map +1 -0
- package/types/utils/index.d.ts +5 -3
- package/types/utils/index.d.ts.map +1 -0
- package/types/utils/is-server.d.ts +8 -6
- package/types/utils/is-server.d.ts.map +1 -0
- package/types/utils/normalize-url.d.ts +2 -1
- package/types/utils/normalize-url.d.ts.map +1 -0
- package/types/utils/timeout-promise.d.ts +18 -17
- package/types/utils/timeout-promise.d.ts.map +1 -0
- package/types/utils/utils.d.ts +104 -79
- package/types/utils/utils.d.ts.map +1 -0
- package/client.js +0 -1
- package/codegen.js +0 -1
- package/config-cli.js +0 -1
- package/config.js +0 -1
- package/editing.js +0 -1
- package/i18n.js +0 -1
- package/layout.js +0 -1
- package/media.js +0 -1
- package/personalize.js +0 -1
- package/site.js +0 -1
- package/tools.js +0 -1
- package/utils.js +0 -1
|
@@ -1,359 +1,411 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.writeImportMap = exports.getImportValueAlias = exports.getImportedValues = exports.importUnitMocks = exports.
|
|
40
|
-
const ts = __importStar(require("typescript"));
|
|
41
|
-
const path_1 = __importDefault(require("path"));
|
|
42
|
-
const fs_1 = __importDefault(require("fs"));
|
|
43
|
-
const templating_1 = require("./../templating");
|
|
44
|
-
const debug_1 = __importDefault(require("./../../debug"));
|
|
45
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
46
|
-
const utils_1 = require("./utils");
|
|
47
|
-
let _getComponentList = templating_1.getComponentList;
|
|
48
|
-
const aliasImport = /^([a-zA-Z0-9]+) as .+$/;
|
|
49
|
-
const unitMocks = ({ getComponentListStub, }) => {
|
|
50
|
-
getComponentListStub && (_getComponentList = getComponentListStub);
|
|
51
|
-
};
|
|
52
|
-
exports.unitMocks = unitMocks;
|
|
53
|
-
/**
|
|
54
|
-
* Gets a Map object with import modules and their respective exports present throughout the paths specified
|
|
55
|
-
* @param {string} paths paths to files to be processed for import-map
|
|
56
|
-
* @returns {Map<string, ImportModule>} collection of keys and values, where keys refer to modules being processed and values are collections of exports for each module
|
|
57
|
-
*/
|
|
58
|
-
exports.getImportMap = _getImportMap;
|
|
59
|
-
/**
|
|
60
|
-
* Builds file contents for component map based on the default template
|
|
61
|
-
* @param {Map<string, ImportModule>} indexedImportMap map to be processed into final component-map.ts file
|
|
62
|
-
* @returns {string} file code for component-map.ts
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
exports.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
* @
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// if
|
|
188
|
-
//
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
//
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.writeImportMap = exports.getImportValueAlias = exports.getImportedValues = exports.importUnitMocks = exports.defaultMapTemplate = exports.getImportMap = exports.unitMocks = void 0;
|
|
40
|
+
const ts = __importStar(require("typescript"));
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const fs_1 = __importDefault(require("fs"));
|
|
43
|
+
const templating_1 = require("./../templating");
|
|
44
|
+
const debug_1 = __importDefault(require("./../../debug"));
|
|
45
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
46
|
+
const utils_1 = require("./utils");
|
|
47
|
+
let _getComponentList = templating_1.getComponentList;
|
|
48
|
+
const aliasImport = /^([a-zA-Z0-9]+) as .+$/;
|
|
49
|
+
const unitMocks = ({ getComponentListStub, }) => {
|
|
50
|
+
getComponentListStub && (_getComponentList = getComponentListStub);
|
|
51
|
+
};
|
|
52
|
+
exports.unitMocks = unitMocks;
|
|
53
|
+
/**
|
|
54
|
+
* Gets a Map object with import modules and their respective exports present throughout the paths specified
|
|
55
|
+
* @param {string} paths paths to files to be processed for import-map
|
|
56
|
+
* @returns {Map<string, ImportModule>} collection of keys and values, where keys refer to modules being processed and values are collections of exports for each module
|
|
57
|
+
*/
|
|
58
|
+
exports.getImportMap = _getImportMap;
|
|
59
|
+
/**
|
|
60
|
+
* Builds file contents for component map based on the default template
|
|
61
|
+
* @param {Map<string, ImportModule>} indexedImportMap map to be processed into final component-map.ts file
|
|
62
|
+
* @returns {string} file code for component-map.ts
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
exports.defaultMapTemplate = _defaultMapTemplate;
|
|
66
|
+
exports.importUnitMocks = {
|
|
67
|
+
set getImportMap(mockImplementation) {
|
|
68
|
+
exports.getImportMap = mockImplementation;
|
|
69
|
+
},
|
|
70
|
+
get getImportMap() {
|
|
71
|
+
return _getImportMap;
|
|
72
|
+
},
|
|
73
|
+
set defaultMapTemplate(mockImplementation) {
|
|
74
|
+
exports.defaultMapTemplate = mockImplementation;
|
|
75
|
+
},
|
|
76
|
+
get defaultMapTemplate() {
|
|
77
|
+
return _defaultMapTemplate;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Parses and AST import node and extracts all imported values from it
|
|
82
|
+
* @param {ts.ImportDeclaration} importNode import node to be parsed
|
|
83
|
+
* @returns {ImportNames | null} object with named, default and namespace imported values, or null if import node is not valid
|
|
84
|
+
*/
|
|
85
|
+
const getImportedValues = (importNode) => {
|
|
86
|
+
const importClause = importNode.importClause;
|
|
87
|
+
if (!importClause) {
|
|
88
|
+
console.warn('Cannot parse import string from: %s', importNode.getText());
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const result = {
|
|
92
|
+
named: [],
|
|
93
|
+
default: null,
|
|
94
|
+
namespace: null,
|
|
95
|
+
};
|
|
96
|
+
importClause.getChildren().forEach((child) => {
|
|
97
|
+
if (child.kind === ts.SyntaxKind.NamedImports) {
|
|
98
|
+
// import [...,]{a,b,c}
|
|
99
|
+
child.forEachChild((namedChild) => {
|
|
100
|
+
const importText = namedChild.getText().trim();
|
|
101
|
+
const aliasMatch = aliasImport.exec(importText);
|
|
102
|
+
result.named.push(aliasMatch ? aliasMatch[1] : importText);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else if (child.kind === ts.SyntaxKind.NamespaceImport) {
|
|
106
|
+
// * as coolName
|
|
107
|
+
result.namespace = child.getText().replace('* as ', '');
|
|
108
|
+
}
|
|
109
|
+
else if (child.kind === ts.SyntaxKind.Identifier) {
|
|
110
|
+
// import coolName
|
|
111
|
+
result.default = child.getText();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return result;
|
|
115
|
+
};
|
|
116
|
+
exports.getImportedValues = getImportedValues;
|
|
117
|
+
// return alias-like name for an import value/variable name
|
|
118
|
+
// this helps alleviate duplicate import names in import-map.ts
|
|
119
|
+
const getImportValueAlias = (importValue, moduleName, importType) => {
|
|
120
|
+
if (process.env.IMPORT_ALIAS_STRATEGY === 'plain')
|
|
121
|
+
return importValue;
|
|
122
|
+
// Add extra uniqueness since the same alias can be used for different import types
|
|
123
|
+
const importTypeId = importType === 'named' ? 'n' : importType === 'default' ? 'd' : 'ns';
|
|
124
|
+
const suffix = crypto_1.default.hash('sha1', `${moduleName}_${importTypeId}`);
|
|
125
|
+
return `${importValue}_${suffix}`;
|
|
126
|
+
};
|
|
127
|
+
exports.getImportValueAlias = getImportValueAlias;
|
|
128
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
129
|
+
function _getImportMap(paths) {
|
|
130
|
+
// make preparations for handling ts/js files
|
|
131
|
+
const appPath = process.cwd();
|
|
132
|
+
let cliCompilerOptions = {
|
|
133
|
+
baseUrl: appPath,
|
|
134
|
+
allowJs: true,
|
|
135
|
+
target: ts.ScriptTarget.ESNext,
|
|
136
|
+
};
|
|
137
|
+
const tsConfig = ts.readConfigFile(path_1.default.resolve(appPath, 'tsconfig.json'), ts.sys.readFile);
|
|
138
|
+
if (tsConfig.error) {
|
|
139
|
+
console.warn(`[Codegen] Error reading tsconfig.json from app root: ${tsConfig.error.messageText}`);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
cliCompilerOptions = Object.assign(Object.assign({}, tsConfig.config.compilerOptions), cliCompilerOptions);
|
|
143
|
+
}
|
|
144
|
+
const tsHost = ts.createCompilerHost(cliCompilerOptions, true);
|
|
145
|
+
// indexed version of import map - we will store and aggregate unique import paths and their imports here
|
|
146
|
+
const importMap = new Map();
|
|
147
|
+
// index to keep track of unique import values imported from different modules
|
|
148
|
+
// helps avoid duplicate import names in the final import-map.ts file
|
|
149
|
+
const importsList = [];
|
|
150
|
+
paths.forEach((codeFilePath) => {
|
|
151
|
+
const codeFileFullPath = path_1.default.isAbsolute(codeFilePath)
|
|
152
|
+
? codeFilePath
|
|
153
|
+
: path_1.default.resolve(appPath, codeFilePath);
|
|
154
|
+
// attempt to parse current file to extract imports from
|
|
155
|
+
const tsCodeSource = tsHost.getSourceFile(codeFileFullPath, ts.ScriptTarget.Latest, (msg) => {
|
|
156
|
+
throw new Error(`[Codegen] Failed to parse ${codeFileFullPath}: ${msg}`);
|
|
157
|
+
});
|
|
158
|
+
if (!tsCodeSource)
|
|
159
|
+
throw ReferenceError(`[Codegen] Failed to find file ${codeFileFullPath}`);
|
|
160
|
+
// By transpiling the code from current file to JS we get rid of unused imports and the type imports
|
|
161
|
+
const jsCode = ts.transpileModule(tsCodeSource.getFullText(), {
|
|
162
|
+
compilerOptions: cliCompilerOptions,
|
|
163
|
+
});
|
|
164
|
+
// despite the name, ts.createSourceFile only creates SourceFile instance in runtime. Go figure ¯\_(ツ)_/¯
|
|
165
|
+
const jsCodeSource = ts.createSourceFile('code.js', jsCode.outputText, ts.ScriptTarget.ESNext, true);
|
|
166
|
+
// finally, we parse the final, trasformed js code and process import statements
|
|
167
|
+
ts.forEachChild(jsCodeSource, (childNode) => {
|
|
168
|
+
var _a;
|
|
169
|
+
if (ts.isImportDeclaration(childNode) && childNode.importClause) {
|
|
170
|
+
const imports = (0, exports.getImportedValues)(childNode);
|
|
171
|
+
if (!imports) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// import path is extracted
|
|
175
|
+
const moduleName = childNode.moduleSpecifier.getText().replace(/['"]/g, '');
|
|
176
|
+
const resolvedModule = ts.nodeModuleNameResolver(moduleName, codeFileFullPath, cliCompilerOptions, tsHost);
|
|
177
|
+
// get import path and check if its import target exists
|
|
178
|
+
const resolvedImportPath = (_a = resolvedModule === null || resolvedModule === void 0 ? void 0 : resolvedModule.resolvedModule) === null || _a === void 0 ? void 0 : _a.resolvedFileName;
|
|
179
|
+
if (!resolvedImportPath) {
|
|
180
|
+
console.warn('[Codegen] Could not resolve a file for import %s', moduleName);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
let importModuleName;
|
|
184
|
+
if (resolvedImportPath.includes('node_modules') ||
|
|
185
|
+
resolvedImportPath.endsWith('.d.ts') ||
|
|
186
|
+
!(0, utils_1.toPosixPath)(resolvedImportPath).startsWith((0, utils_1.toPosixPath)(appPath) + '/')) {
|
|
187
|
+
// if import path points to a file in local app - process import path to the file (i.e. ./myComponent)
|
|
188
|
+
// if it points to node_modules or a file in monorepo - parse import path as dependency module name (i.e. React)
|
|
189
|
+
// external dependency → keep as-is
|
|
190
|
+
importModuleName = (0, utils_1.isNodeModuleImport)(moduleName)
|
|
191
|
+
? (0, utils_1.stripExtension)(moduleName)
|
|
192
|
+
: (0, utils_1.getRelativeImportPath)(resolvedImportPath, appPath);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
// local file
|
|
196
|
+
importModuleName = (0, utils_1.isNodeModuleImport)(moduleName)
|
|
197
|
+
? (0, utils_1.stripExtension)(moduleName)
|
|
198
|
+
: (0, utils_1.getRelativeImportPath)(resolvedImportPath, appPath);
|
|
199
|
+
}
|
|
200
|
+
// Set module import info in the map. If module import exists - add entries to existing entry
|
|
201
|
+
// Otherwise, add new entry
|
|
202
|
+
if (!importMap.has(importModuleName)) {
|
|
203
|
+
importMap.set(importModuleName, {
|
|
204
|
+
namedExports: new Map(),
|
|
205
|
+
defaultExport: null,
|
|
206
|
+
namespaceExport: null,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
const moduleEntry = importMap.get(importModuleName);
|
|
210
|
+
imports.named.forEach((importEntry) => {
|
|
211
|
+
const sameModuleNamedAlready = moduleEntry.namedExports.has(importEntry);
|
|
212
|
+
if (sameModuleNamedAlready) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const nameTaken = importsList.includes(importEntry);
|
|
216
|
+
const importValue = nameTaken
|
|
217
|
+
? (0, exports.getImportValueAlias)(importEntry, importModuleName, 'named')
|
|
218
|
+
: importEntry;
|
|
219
|
+
moduleEntry.namedExports.set(importEntry, importValue);
|
|
220
|
+
importsList.push(importEntry);
|
|
221
|
+
});
|
|
222
|
+
if (imports.namespace) {
|
|
223
|
+
const sameModuleNamedAlready = moduleEntry.namespaceExport;
|
|
224
|
+
if (sameModuleNamedAlready) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const nameTaken = importsList.includes(imports.namespace);
|
|
228
|
+
const importValue = nameTaken
|
|
229
|
+
? (0, exports.getImportValueAlias)(imports.namespace, importModuleName, 'namespace')
|
|
230
|
+
: imports.namespace;
|
|
231
|
+
moduleEntry.namespaceExport = importValue;
|
|
232
|
+
importsList.push(importValue);
|
|
233
|
+
}
|
|
234
|
+
if (imports.default) {
|
|
235
|
+
const sameModuleNamedAlready = moduleEntry.defaultExport;
|
|
236
|
+
if (sameModuleNamedAlready) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const nameTaken = importsList.includes(imports.default);
|
|
240
|
+
const importValue = nameTaken
|
|
241
|
+
? (0, exports.getImportValueAlias)(imports.default, importModuleName, 'default')
|
|
242
|
+
: imports.default;
|
|
243
|
+
moduleEntry.defaultExport = importValue;
|
|
244
|
+
importsList.push(importValue);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
return importMap;
|
|
250
|
+
}
|
|
251
|
+
const prepImportMaps = async (paths, separateMaps) => {
|
|
252
|
+
const importMapFileDefault = path_1.default.join(process.cwd(), '.sitecore', 'import-map.ts');
|
|
253
|
+
if (!separateMaps) {
|
|
254
|
+
return [{ map: (0, exports.getImportMap)(paths), path: importMapFileDefault }];
|
|
255
|
+
}
|
|
256
|
+
const appPath = process.cwd();
|
|
257
|
+
const serverPaths = [];
|
|
258
|
+
const clientPaths = [];
|
|
259
|
+
const importMapFileClient = path_1.default.join(process.cwd(), '.sitecore', 'import-map.client.ts');
|
|
260
|
+
const importMapFileServer = path_1.default.join(process.cwd(), '.sitecore', 'import-map.server.ts');
|
|
261
|
+
for (const componentPath of paths) {
|
|
262
|
+
const fullPath = path_1.default.isAbsolute(componentPath)
|
|
263
|
+
? componentPath
|
|
264
|
+
: path_1.default.resolve(appPath, componentPath);
|
|
265
|
+
// read the start of the file that may be 'use client'
|
|
266
|
+
const firstLine = await new Promise((resolve) => {
|
|
267
|
+
let readBuffer = '';
|
|
268
|
+
const stream = fs_1.default.createReadStream(fullPath, { end: 12 });
|
|
269
|
+
stream
|
|
270
|
+
.on('data', async (chunk) => {
|
|
271
|
+
readBuffer += chunk.toString();
|
|
272
|
+
})
|
|
273
|
+
.on('close', () => resolve(readBuffer))
|
|
274
|
+
.on('error', () => resolve(''));
|
|
275
|
+
});
|
|
276
|
+
if (!firstLine)
|
|
277
|
+
continue;
|
|
278
|
+
if (firstLine.match(/['"]use client['"]/)) {
|
|
279
|
+
clientPaths.push(fullPath);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
serverPaths.push(fullPath);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return [
|
|
286
|
+
{ map: (0, exports.getImportMap)(serverPaths), path: importMapFileServer },
|
|
287
|
+
{ map: (0, exports.getImportMap)(clientPaths), path: importMapFileClient, isClient: true },
|
|
288
|
+
];
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* Entry point function for generating import-map. Parses provided paths and outputs the modules and imports from those files into .sitecore/import-map.ts
|
|
292
|
+
* @param {WriteImportMapArgsInternal} args include/exclude paths settings to be processed for import-map, and the Sitecore configuration.
|
|
293
|
+
* @public
|
|
294
|
+
*/
|
|
295
|
+
const writeImportMap = (args) => {
|
|
296
|
+
return async ({ scConfig } = {}) => {
|
|
297
|
+
var _a;
|
|
298
|
+
const config = (_a = args.scConfig) !== null && _a !== void 0 ? _a : scConfig;
|
|
299
|
+
const defaultTemplate = args.serverTemplate || exports.defaultMapTemplate;
|
|
300
|
+
const clientTemplate = args.clientTemplate || exports.defaultMapTemplate;
|
|
301
|
+
if (!config) {
|
|
302
|
+
throw new Error('Sitecore configuration is required to be provided');
|
|
303
|
+
}
|
|
304
|
+
if (config.disableCodeGeneration) {
|
|
305
|
+
debug_1.default.common('Skipping import map generation. Code generation functionality is disabled.');
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
const paths = _getComponentList(args.paths, args.exclude).map((entry) => entry.filePath);
|
|
309
|
+
// TODO: don't run in pages router
|
|
310
|
+
const importMaps = await prepImportMaps(paths, args.separateServerClientMaps);
|
|
311
|
+
for (const importMap of importMaps) {
|
|
312
|
+
console.log(`[Codegen] Generating import map: ${JSON.stringify({
|
|
313
|
+
paths: args.paths,
|
|
314
|
+
exclude: args.exclude,
|
|
315
|
+
})}.\n Writing into ${importMap.path} ...`);
|
|
316
|
+
// get generated map and combine with default one
|
|
317
|
+
// can be expanded when adding support for non-react frameworks
|
|
318
|
+
const importMapContent = importMap.isClient
|
|
319
|
+
? clientTemplate(importMap.map)
|
|
320
|
+
: defaultTemplate(importMap.map);
|
|
321
|
+
try {
|
|
322
|
+
fs_1.default.writeFileSync(importMap.path, importMapContent, {
|
|
323
|
+
encoding: 'utf8',
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
catch (error) {
|
|
327
|
+
console.error(`[Codegen] Import Map generation failed. Error writing to file ${importMap.path}:`, error);
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
exports.writeImportMap = writeImportMap;
|
|
334
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
335
|
+
function _defaultMapTemplate(indexedImportMap, framework = 'core') {
|
|
336
|
+
const importStatements = [];
|
|
337
|
+
const importMapArray = Array.from(indexedImportMap);
|
|
338
|
+
// get import map entries after
|
|
339
|
+
const finalImportMap = importMapArray.map(([modulePath, imports]) => {
|
|
340
|
+
const defaultExport = {
|
|
341
|
+
name: 'default',
|
|
342
|
+
value: imports.defaultExport,
|
|
343
|
+
};
|
|
344
|
+
const namedExports = Array.from(imports.namedExports).map(([name, value]) => {
|
|
345
|
+
return {
|
|
346
|
+
name,
|
|
347
|
+
value,
|
|
348
|
+
};
|
|
349
|
+
});
|
|
350
|
+
const namespaceExport = {
|
|
351
|
+
name: '*',
|
|
352
|
+
value: imports.namespaceExport,
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
module: modulePath,
|
|
356
|
+
defaultExport,
|
|
357
|
+
namedExports,
|
|
358
|
+
namespaceExport,
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
finalImportMap.forEach((entry) => {
|
|
362
|
+
if (entry.namedExports.length > 0) {
|
|
363
|
+
const namedExports = entry.namedExports
|
|
364
|
+
.map((entry) => {
|
|
365
|
+
return entry.name !== entry.value ? `${entry.name} as ${entry.value}` : entry.name;
|
|
366
|
+
})
|
|
367
|
+
.join(', ');
|
|
368
|
+
importStatements.push(`import { ${namedExports} } from '${entry.module}';`);
|
|
369
|
+
}
|
|
370
|
+
if (entry.defaultExport.value) {
|
|
371
|
+
importStatements.push(`import ${entry.defaultExport.value} from '${entry.module}';`);
|
|
372
|
+
}
|
|
373
|
+
if (entry.namespaceExport.value) {
|
|
374
|
+
importStatements.push(`import * as ${entry.namespaceExport.value} from '${entry.module}';`);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
const outputExportEntries = (entry) => {
|
|
378
|
+
return ([...entry.namedExports, entry.defaultExport, entry.namespaceExport]
|
|
379
|
+
.filter((entry) => entry.value !== null)
|
|
380
|
+
.map((namedExport) => ` { name: '${namedExport.name}', value: ${namedExport.value} }`)
|
|
381
|
+
.join(',\n') + ',');
|
|
382
|
+
};
|
|
335
383
|
return `// This file is auto-generated by the Sitecore Content SDK.
|
|
336
384
|
// Below are built-in Content SDK imports neccessary for the import map
|
|
337
|
-
import {
|
|
385
|
+
import {
|
|
386
|
+
combineImportEntries,
|
|
387
|
+
defaultImportEntries,
|
|
388
|
+
ImportEntry,
|
|
389
|
+
} from '@sitecore-content-sdk/${framework}/codegen';
|
|
338
390
|
// end of built-in imports
|
|
339
391
|
|
|
340
392
|
${importStatements.join('\n')}
|
|
341
393
|
|
|
342
394
|
const importMap = [
|
|
343
|
-
${finalImportMap
|
|
344
|
-
.map((entry) => [
|
|
345
|
-
' {',
|
|
346
|
-
` module: '${entry.module}',`,
|
|
347
|
-
' exports: [',
|
|
348
|
-
outputExportEntries(entry),
|
|
349
|
-
' ]',
|
|
350
|
-
' }',
|
|
351
|
-
]
|
|
352
|
-
.filter(Boolean)
|
|
353
|
-
.join('\n'))
|
|
395
|
+
${finalImportMap
|
|
396
|
+
.map((entry) => [
|
|
397
|
+
' {',
|
|
398
|
+
` module: '${entry.module}',`,
|
|
399
|
+
' exports: [',
|
|
400
|
+
outputExportEntries(entry),
|
|
401
|
+
' ]',
|
|
402
|
+
' }',
|
|
403
|
+
]
|
|
404
|
+
.filter(Boolean)
|
|
405
|
+
.join('\n'))
|
|
354
406
|
.join(',\n')}
|
|
355
|
-
];
|
|
407
|
+
] as ImportEntry[];
|
|
356
408
|
|
|
357
409
|
export default combineImportEntries(defaultImportEntries, importMap);
|
|
358
|
-
`;
|
|
359
|
-
}
|
|
410
|
+
`;
|
|
411
|
+
}
|