@squiz/dxp-cli-next 5.31.0 → 5.32.0-develop.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.
Files changed (61) hide show
  1. package/lib/cdp/instance/activate/activate.js +6 -7
  2. package/lib/cdp/instance/activate/activate.spec.js +2 -8
  3. package/lib/cdp/utils.d.ts +2 -1
  4. package/lib/cdp/utils.js +4 -2
  5. package/lib/migration/create/create.js +5 -8
  6. package/lib/migration/create/create.spec.js +1 -0
  7. package/lib/migration/index.js +2 -0
  8. package/lib/migration/pre/pre.d.ts +3 -0
  9. package/lib/migration/pre/pre.js +54 -0
  10. package/lib/migration/pre/pre.spec.d.ts +1 -0
  11. package/lib/migration/pre/pre.spec.js +269 -0
  12. package/lib/migration/types/common.types.d.ts +10 -0
  13. package/lib/migration/types/createMigration.types.d.ts +4 -0
  14. package/lib/migration/types/index.d.ts +1 -0
  15. package/lib/migration/types/index.js +1 -0
  16. package/lib/migration/types/preMigration.types.d.ts +10 -0
  17. package/lib/migration/types/preMigration.types.js +2 -0
  18. package/lib/migration/utils/common.d.ts +8 -0
  19. package/lib/migration/utils/common.js +19 -1
  20. package/lib/migration/utils/createMigration.d.ts +26 -2
  21. package/lib/migration/utils/createMigration.js +13 -6
  22. package/lib/migration/utils/loadCctIdsFromFile.d.ts +1 -0
  23. package/lib/migration/utils/loadCctIdsFromFile.js +32 -0
  24. package/lib/migration/utils/loadCctIdsFromFile.spec.d.ts +1 -0
  25. package/lib/migration/utils/loadCctIdsFromFile.spec.js +91 -0
  26. package/lib/migration/utils/options.d.ts +2 -1
  27. package/lib/migration/utils/options.js +8 -0
  28. package/lib/page/layouts/deploy/deploy.js +44 -9
  29. package/lib/page/layouts/deploy/deploy.spec.js +110 -19
  30. package/lib/page/layouts/dev/dev.js +18 -4
  31. package/lib/page/layouts/dev/dev.spec.js +117 -8
  32. package/lib/page/layouts/validation/index.d.ts +2 -0
  33. package/lib/page/layouts/validation/index.js +5 -1
  34. package/lib/page/layouts/validation/property-consistency.d.ts +7 -0
  35. package/lib/page/layouts/validation/property-consistency.js +92 -0
  36. package/lib/page/layouts/validation/property-consistency.spec.d.ts +1 -0
  37. package/lib/page/layouts/validation/property-consistency.spec.js +305 -0
  38. package/lib/page/layouts/validation/validateLayoutFormat.d.ts +2 -0
  39. package/lib/page/layouts/validation/validateLayoutFormat.js +27 -0
  40. package/lib/page/layouts/validation/validateLayoutFormat.spec.d.ts +1 -0
  41. package/lib/page/layouts/validation/validateLayoutFormat.spec.js +42 -0
  42. package/lib/page/layouts/validation/zone-consistency.d.ts +1 -1
  43. package/lib/page/layouts/validation/zone-consistency.js +10 -9
  44. package/lib/page/layouts/validation/zone-consistency.spec.js +32 -34
  45. package/lib/page/utils/definitions.d.ts +347 -50
  46. package/lib/page/utils/definitions.js +103 -22
  47. package/lib/page/utils/definitions.spec.js +516 -267
  48. package/lib/page/utils/normalize.d.ts +8 -0
  49. package/lib/page/utils/normalize.js +61 -0
  50. package/lib/page/utils/normalize.spec.d.ts +1 -0
  51. package/lib/page/utils/normalize.spec.js +315 -0
  52. package/lib/page/utils/parse-args.d.ts +20 -4
  53. package/lib/page/utils/parse-args.js +48 -13
  54. package/lib/page/utils/parse-args.spec.js +159 -21
  55. package/lib/page/utils/render.d.ts +27 -9
  56. package/lib/page/utils/render.js +66 -12
  57. package/lib/page/utils/render.spec.js +14 -14
  58. package/lib/page/utils/server.d.ts +1 -1
  59. package/lib/page/utils/server.js +2 -2
  60. package/lib/page/utils/server.spec.js +13 -13
  61. package/package.json +1 -1
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const validateLayoutFormat_1 = require("./validateLayoutFormat");
4
+ const definitions_1 = require("../../utils/definitions");
5
+ describe('validateLayoutFormat', () => {
6
+ let mockLogger;
7
+ beforeEach(() => {
8
+ mockLogger = {
9
+ warn: jest.fn(),
10
+ };
11
+ });
12
+ afterEach(() => {
13
+ jest.clearAllMocks();
14
+ });
15
+ it('should not log a warning when file is manifest.json', () => {
16
+ const layoutFile = `/some/path/${definitions_1.LAYOUT_MANIFEST_FILE}`;
17
+ (0, validateLayoutFormat_1.validateLayoutFormat)(mockLogger, layoutFile);
18
+ expect(mockLogger.warn).not.toHaveBeenCalled();
19
+ });
20
+ it('should log a deprecation warning when file is not manifest.json', () => {
21
+ const layoutFile = '/some/path/page-layout.yaml';
22
+ (0, validateLayoutFormat_1.validateLayoutFormat)(mockLogger, layoutFile);
23
+ expect(mockLogger.warn).toHaveBeenCalledTimes(1);
24
+ expect(mockLogger.warn).toHaveBeenCalledWith('⚠️ DEPRECATED: The file name "page-layout.yaml" is deprecated. ' +
25
+ `Please migrate to "${definitions_1.LAYOUT_MANIFEST_FILE}" using the new layout definition format. ` +
26
+ `Support for files other than "${definitions_1.LAYOUT_MANIFEST_FILE}" will be removed in a future version. ` +
27
+ 'For more information, visit https://docs.squiz.net/component-service/latest/layouts/layout-files.html');
28
+ });
29
+ it('should extract filename correctly from full path', () => {
30
+ const layoutFile = '/very/deep/nested/path/to/layout/page-layout.yaml';
31
+ (0, validateLayoutFormat_1.validateLayoutFormat)(mockLogger, layoutFile);
32
+ expect(mockLogger.warn).toHaveBeenCalledWith(expect.stringContaining('"page-layout.yaml"'));
33
+ });
34
+ it('should log a default config file warning when file is not provided', () => {
35
+ (0, validateLayoutFormat_1.validateLayoutFormat)(mockLogger);
36
+ expect(mockLogger.warn).toHaveBeenCalledTimes(1);
37
+ expect(mockLogger.warn).toHaveBeenCalledWith('⚠️ DEFAULT CONFIG FILE: "manifest.json" has replaced "page-layout.yaml" as the default config file. ' +
38
+ `Please migrate to "${definitions_1.LAYOUT_MANIFEST_FILE}" using the new layout definition format. ` +
39
+ `Support for files other than "${definitions_1.LAYOUT_MANIFEST_FILE}" will be removed in a future version. ` +
40
+ 'For more information, visit https://docs.squiz.net/component-service/latest/layouts/layout-files.html');
41
+ });
42
+ });
@@ -1,6 +1,6 @@
1
1
  import { LayoutDefinition } from '../../utils/definitions';
2
2
  /**
3
- * Validates that zones defined in YAML match zones used in the Handlebars template
3
+ * Validates that zones defined in layout definition match zones used in the Handlebars template
4
4
  * @param layout The layout definition containing zones and template
5
5
  * @returns Error message if validation fails, null if validation passes
6
6
  */
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateZoneConsistency = void 0;
4
4
  /**
5
- * Validates that zones defined in YAML match zones used in the Handlebars template
5
+ * Validates that zones defined in layout definition match zones used in the Handlebars template
6
6
  * @param layout The layout definition containing zones and template
7
7
  * @returns Error message if validation fails, null if validation passes
8
8
  */
9
9
  function validateZoneConsistency(layout) {
10
- const yamlZones = Object.keys(layout.zones || {});
10
+ var _a, _b;
11
+ const layoutZones = (_b = (_a = layout.zones) === null || _a === void 0 ? void 0 : _a.map(zone => zone.key)) !== null && _b !== void 0 ? _b : [];
11
12
  const template = layout.template;
12
13
  // If no template is provided, skip validation
13
14
  if (!template) {
@@ -24,19 +25,19 @@ function validateZoneConsistency(layout) {
24
25
  }
25
26
  // Convert the set to an array
26
27
  const templateZoneArray = Array.from(templateZones);
27
- // Find zones defined in YAML but not used in template
28
- const unusedYamlZones = yamlZones.filter(zone => !templateZones.has(zone));
29
- // Find zones used in template but not defined in YAML
30
- const undefinedTemplateZones = templateZoneArray.filter(zone => !yamlZones.includes(zone));
28
+ // Find zones defined in layout definition but not used in template
29
+ const unusedLayoutZones = layoutZones.filter(zone => !templateZones.has(zone));
30
+ // Find zones used in template but not defined in layout definition
31
+ const undefinedTemplateZones = templateZoneArray.filter(zone => !layoutZones.includes(zone));
31
32
  // Create an array of errors
32
33
  const errors = [];
33
34
  // Add the unused zones to the errors
34
- if (unusedYamlZones.length > 0) {
35
- errors.push(`Zones defined in YAML but not used in template: ${unusedYamlZones.join(', ')}`);
35
+ if (unusedLayoutZones.length > 0) {
36
+ errors.push(`Zones defined in layout definition but not used in template: ${unusedLayoutZones.join(', ')}`);
36
37
  }
37
38
  // Add the undefined zones to the errors
38
39
  if (undefinedTemplateZones.length > 0) {
39
- errors.push(`Zones used in template but not defined in YAML: ${undefinedTemplateZones.join(', ')}`);
40
+ errors.push(`Zones used in template but not defined in layout definition: ${undefinedTemplateZones.join(', ')}`);
40
41
  }
41
42
  // If there are errors, return the errors
42
43
  if (errors.length > 0) {
@@ -10,67 +10,65 @@ describe('validateZoneConsistency', () => {
10
10
  template,
11
11
  });
12
12
  it('should return null for valid zone consistency', () => {
13
- const layout = createMockLayout({
14
- header: { displayName: 'Header', description: 'Header zone' },
15
- content: { displayName: 'Content', description: 'Content zone' },
16
- }, '<div>{{zones.header}}</div><div>{{zones.content}}</div>');
13
+ const layout = createMockLayout([
14
+ { key: 'header', displayName: 'Header', description: 'Header zone' },
15
+ { key: 'content', displayName: 'Content', description: 'Content zone' },
16
+ ], '<div>{{zones.header}}</div><div>{{zones.content}}</div>');
17
17
  const result = (0, zone_consistency_1.validateZoneConsistency)(layout);
18
18
  expect(result).toBeNull();
19
19
  });
20
20
  it('should return null when no template is provided', () => {
21
- const layout = createMockLayout({
22
- header: { displayName: 'Header', description: 'Header zone' },
23
- }, '');
21
+ const layout = createMockLayout([{ key: 'header', displayName: 'Header', description: 'Header zone' }], '');
24
22
  const result = (0, zone_consistency_1.validateZoneConsistency)(layout);
25
23
  expect(result).toBeNull();
26
24
  });
27
25
  it('should detect zones defined in YAML but not used in template', () => {
28
- const layout = createMockLayout({
29
- header: { displayName: 'Header', description: 'Header zone' },
30
- sidebar: { displayName: 'Sidebar', description: 'Sidebar zone' },
31
- }, '<div>{{zones.header}}</div>');
26
+ const layout = createMockLayout([
27
+ { key: 'header', displayName: 'Header', description: 'Header zone' },
28
+ { key: 'sidebar', displayName: 'Sidebar', description: 'Sidebar zone' },
29
+ ], '<div>{{zones.header}}</div>');
32
30
  const result = (0, zone_consistency_1.validateZoneConsistency)(layout);
33
31
  expect(result).toContain('Zone consistency validation failed');
34
- expect(result).toContain('Zones defined in YAML but not used in template: sidebar');
32
+ expect(result).toContain('Zones defined in layout definition but not used in template: sidebar');
35
33
  });
36
34
  it('should detect zones used in template but not defined in YAML', () => {
37
- const layout = createMockLayout({
38
- header: { displayName: 'Header', description: 'Header zone' },
39
- }, '<div>{{zones.header}}</div><div>{{zones.footer}}</div>');
35
+ const layout = createMockLayout([{ key: 'header', displayName: 'Header', description: 'Header zone' }], '<div>{{zones.header}}</div><div>{{zones.footer}}</div>');
40
36
  const result = (0, zone_consistency_1.validateZoneConsistency)(layout);
41
37
  expect(result).toContain('Zone consistency validation failed');
42
- expect(result).toContain('Zones used in template but not defined in YAML: footer');
38
+ expect(result).toContain('Zones used in template but not defined in layout definition: footer');
43
39
  });
44
40
  it('should detect both unused and undefined zones', () => {
45
- const layout = createMockLayout({
46
- header: { displayName: 'Header', description: 'Header zone' },
47
- sidebar: { displayName: 'Sidebar', description: 'Sidebar zone' },
48
- }, '<div>{{zones.header}}</div><div>{{zones.footer}}</div>');
41
+ const layout = createMockLayout([
42
+ { key: 'header', displayName: 'Header', description: 'Header zone' },
43
+ { key: 'sidebar', displayName: 'Sidebar', description: 'Sidebar zone' },
44
+ ], '<div>{{zones.header}}</div><div>{{zones.footer}}</div>');
49
45
  const result = (0, zone_consistency_1.validateZoneConsistency)(layout);
50
46
  expect(result).toContain('Zone consistency validation failed');
51
- expect(result).toContain('Zones defined in YAML but not used in template: sidebar');
52
- expect(result).toContain('Zones used in template but not defined in YAML: footer');
47
+ expect(result).toContain('Zones defined in layout definition but not used in template: sidebar');
48
+ expect(result).toContain('Zones used in template but not defined in layout definition: footer');
53
49
  });
54
50
  it('should handle Handlebars each loops', () => {
55
- const layout = createMockLayout({
56
- items: { displayName: 'Items', description: 'Items zone' },
57
- }, '<div>{{#each zones.items}}<p>{{this}}</p>{{/each}}</div>');
51
+ const layout = createMockLayout([{ key: 'items', displayName: 'Items', description: 'Items zone' }], '<div>{{#each zones.items}}<p>{{this}}</p>{{/each}}</div>');
58
52
  const result = (0, zone_consistency_1.validateZoneConsistency)(layout);
59
53
  expect(result).toBeNull();
60
54
  });
61
55
  it('should handle Handlebars if conditions', () => {
62
- const layout = createMockLayout({
63
- optional: { displayName: 'Optional', description: 'Optional zone' },
64
- }, '<div>{{#if zones.optional}}{{zones.optional}}{{/if}}</div>');
56
+ const layout = createMockLayout([
57
+ {
58
+ key: 'optional',
59
+ displayName: 'Optional',
60
+ description: 'Optional zone',
61
+ },
62
+ ], '<div>{{#if zones.optional}}{{zones.optional}}{{/if}}</div>');
65
63
  const result = (0, zone_consistency_1.validateZoneConsistency)(layout);
66
64
  expect(result).toBeNull();
67
65
  });
68
66
  it('should handle complex Handlebars patterns', () => {
69
- const layout = createMockLayout({
70
- header: { displayName: 'Header', description: 'Header zone' },
71
- content: { displayName: 'Content', description: 'Content zone' },
72
- sidebar: { displayName: 'Sidebar', description: 'Sidebar zone' },
73
- }, `
67
+ const layout = createMockLayout([
68
+ { key: 'header', displayName: 'Header', description: 'Header zone' },
69
+ { key: 'content', displayName: 'Content', description: 'Content zone' },
70
+ { key: 'sidebar', displayName: 'Sidebar', description: 'Sidebar zone' },
71
+ ], `
74
72
  <div>{{zones.header}}</div>
75
73
  <div>
76
74
  {{#if zones.sidebar}}
@@ -83,7 +81,7 @@ describe('validateZoneConsistency', () => {
83
81
  expect(result).toBeNull();
84
82
  });
85
83
  it('should handle empty zones object', () => {
86
- const layout = createMockLayout({}, '<div>Static content only</div>');
84
+ const layout = createMockLayout([], '<div>Static content only</div>');
87
85
  const result = (0, zone_consistency_1.validateZoneConsistency)(layout);
88
86
  expect(result).toBeNull();
89
87
  });