@hubspot/project-parsing-lib 0.1.0 → 0.1.1-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/project-parsing-lib",
3
- "version": "0.1.0",
3
+ "version": "0.1.1-beta.0",
4
4
  "description": "Parsing library for converting projects directory structures to their intermediate representation",
5
5
  "license": "Apache-2.0",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -21,7 +21,7 @@ async function translate(translationContext, translationOptions = defaultOptions
21
21
  throw new Error(copy_1.errorMessages.project.noHsMetaFiles);
22
22
  }
23
23
  const transformation = (0, transform_1.transform)(metafileContents);
24
- const intermediateRepresentation = (0, transform_1.getIntermediateRepresentation)(transformation);
24
+ const intermediateRepresentation = (0, transform_1.getIntermediateRepresentation)(transformation, skipValidation);
25
25
  // Remove once extensions and serverless functions are supported
26
26
  if (!skipValidation) {
27
27
  await (0, validation_1.validateIntermediateRepresentation)(intermediateRepresentation, transformation, translationContext);
package/src/lib/errors.js CHANGED
@@ -31,11 +31,13 @@ class TranslationError extends Error {
31
31
  toString() {
32
32
  const listOfErrors = this.errors.map(({ file, errors }) => {
33
33
  if (errors.length === 0) {
34
- return '';
34
+ return null;
35
35
  }
36
36
  return copy_1.errorMessages.validation.errorWithFileHeader(path_1.default.join(this.translationContext.projectSourceDir, file), errors);
37
37
  });
38
- return `${this.message}: ${listOfErrors}`;
38
+ return `${this.message}: ${listOfErrors
39
+ .filter(error => error !== null)
40
+ .join('')}`;
39
41
  }
40
42
  }
41
43
  exports.TranslationError = TranslationError;
@@ -1,4 +1,4 @@
1
1
  import { FileParseResult, IntermediateRepresentation, Transformation } from './types';
2
2
  export declare function mapToUserFacingType(type: string): string;
3
3
  export declare function transform(fileParseResults: FileParseResult[]): Transformation[];
4
- export declare function getIntermediateRepresentation(transformations: Transformation[]): IntermediateRepresentation;
4
+ export declare function getIntermediateRepresentation(transformations: Transformation[], skipValidation: boolean | undefined): IntermediateRepresentation;
@@ -65,18 +65,27 @@ function transform(fileParseResults) {
65
65
  };
66
66
  });
67
67
  }
68
- function getIntermediateRepresentation(transformations) {
68
+ function getIntermediateRepresentation(transformations, skipValidation) {
69
69
  const nodes = transformations.reduce((acc, current) => {
70
70
  if (!current.intermediateRepresentation) {
71
71
  return acc;
72
72
  }
73
73
  const { uid } = current.intermediateRepresentation;
74
- if (acc[uid]) {
74
+ if (uid && acc[uid]) {
75
75
  const duplicates = transformations
76
76
  .filter(t => t.intermediateRepresentation?.uid === uid)
77
77
  .map(t => t.fileParseResult.file);
78
78
  throw new Error(copy_1.errorMessages.project.duplicateUid(uid, duplicates));
79
79
  }
80
+ if (!skipValidation) {
81
+ return {
82
+ ...acc,
83
+ // If the uid is not defined just make one up for the sake of indexing.
84
+ // It will still fail validation, but this prevents collisions so we validate all files.
85
+ [uid ||
86
+ `missing-${current.fileParseResult.file}`]: current.intermediateRepresentation,
87
+ };
88
+ }
80
89
  return {
81
90
  ...acc,
82
91
  [uid]: current.intermediateRepresentation,