@hubspot/project-parsing-lib 0.23.0-beta.0 → 0.23.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.23.0-beta.0",
3
+ "version": "0.23.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
  "type": "module",
@@ -48,6 +48,9 @@ export declare const errorMessages: {
48
48
  migrateThemes: {
49
49
  rootReactThemeNotSupported: string;
50
50
  };
51
+ migrate: {
52
+ serverlessPackageWithoutAppFunction: string;
53
+ };
51
54
  };
52
55
  export declare function getInvalidJsonError(): string;
53
56
  export declare function getMissingTypeError(): string;
package/src/lang/copy.js CHANGED
@@ -49,6 +49,9 @@ export const errorMessages = {
49
49
  migrateThemes: {
50
50
  rootReactThemeNotSupported: 'Migrating themes that live at the root of the project src directory is not supported. Please move the theme to a subdirectory.',
51
51
  },
52
+ migrate: {
53
+ serverlessPackageWithoutAppFunction: 'Migration failed: an error occurred while exporting your app functions.',
54
+ },
52
55
  };
53
56
  export function getInvalidJsonError() {
54
57
  return errorMessages.validation.invalidJson;
@@ -5,6 +5,7 @@ import { mapToUserFacingType } from './transform.js';
5
5
  import { METAFILE_EXTENSION, Components, HS_PROJECT_JSON_FILENAME, APP_FUNCTIONS_PACKAGE_KEY, APP_FUNCTIONS_KEY, } from './constants.js';
6
6
  import { translate } from './translate.js';
7
7
  import { loadJsonFile } from './utils.js';
8
+ import { errorMessages } from '../lang/copy.js';
8
9
  const IR_FILENAME = 'ir.json';
9
10
  const filesDirectory = 'files';
10
11
  export const OUTPUT_IR_FILE = 'FULL_IR.json';
@@ -27,15 +28,16 @@ export async function migrate(inputDir, outputDir) {
27
28
  const sourceCodeOutputDir = path.join(outputDir, 'src');
28
29
  // Create the output directory if it doesn't exist
29
30
  ensureDirExists(sourceCodeOutputDir);
30
- files.forEach((filename) => {
31
- // Skip everything that's not an IR file
32
- if (!isIRFile(filename)) {
33
- return;
34
- }
31
+ const irFiles = files.filter((filename) => isIRFile(filename));
32
+ const irData = irFiles.map((filename) => ({
33
+ filename,
34
+ ir: loadJsonFile(filename),
35
+ }));
36
+ validateComponentTypes(irData);
37
+ irData.forEach(({ filename, ir }) => {
35
38
  const irDirName = path.dirname(filename);
36
- const IR = loadJsonFile(filename);
37
- const { metaFilePath } = IR;
38
- const component = convertIRToProjectConfig(IR);
39
+ const { metaFilePath } = ir;
40
+ const component = convertIRToProjectConfig(ir);
39
41
  const fullOutputPath = path.join(sourceCodeOutputDir, getTargetDirectoryFromComponentType(component.type));
40
42
  // Ensure the output directory exists
41
43
  const currentFilesDirectory = path.join(irDirName, filesDirectory);
@@ -71,6 +73,14 @@ function isIRFile(filename) {
71
73
  const { base } = path.parse(filename);
72
74
  return base.toLowerCase() === IR_FILENAME;
73
75
  }
76
+ function validateComponentTypes(irData) {
77
+ const componentTypes = new Set(irData.map(({ ir }) => mapToUserFacingType(ir.componentType)));
78
+ const hasServerlessPackage = componentTypes.has(APP_FUNCTIONS_PACKAGE_KEY);
79
+ const hasAppFunction = componentTypes.has(APP_FUNCTIONS_KEY);
80
+ if (hasServerlessPackage && !hasAppFunction) {
81
+ throw new Error(errorMessages.migrate.serverlessPackageWithoutAppFunction);
82
+ }
83
+ }
74
84
  function convertIRToProjectConfig(IR) {
75
85
  const { config, uid, componentType } = IR;
76
86
  return {