@hubspot/project-parsing-lib 0.18.0-beta.0 → 0.19.0-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 +8 -3
- package/src/exports/translate.d.ts +1 -0
- package/src/lang/copy.d.ts +0 -3
- package/src/lang/copy.js +0 -3
- package/src/lib/files.d.ts +11 -5
- package/src/lib/files.js +16 -13
- package/src/lib/profiles.js +6 -3
- package/src/lib/project.js +1 -1
- package/src/lib/translate.d.ts +10 -2
- package/src/lib/translate.js +10 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/project-parsing-lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0-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",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
|
-
"@hubspot/npm-scripts": "0.0
|
|
110
|
+
"@hubspot/npm-scripts": "0.3.0",
|
|
111
111
|
"@inquirer/prompts": "^7.1.0",
|
|
112
112
|
"@types/node": "^24.9.0",
|
|
113
113
|
"@types/npm-packlist": "7.0.3",
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"vitest": "^2.1.9"
|
|
127
127
|
},
|
|
128
128
|
"dependencies": {
|
|
129
|
-
"@hubspot/local-dev-lib": "
|
|
129
|
+
"@hubspot/local-dev-lib": "5.9.0",
|
|
130
130
|
"@npmcli/map-workspaces": "4.0.2",
|
|
131
131
|
"ajv": "8.18.0",
|
|
132
132
|
"ajv-formats": "3.0.1",
|
|
@@ -136,6 +136,11 @@
|
|
|
136
136
|
"resolutions": {
|
|
137
137
|
"ajv-formats/ajv": "8.18.0"
|
|
138
138
|
},
|
|
139
|
+
"overrides": {
|
|
140
|
+
"ajv-formats": {
|
|
141
|
+
"ajv": "8.18.0"
|
|
142
|
+
}
|
|
143
|
+
},
|
|
139
144
|
"scripts": {
|
|
140
145
|
"build": "tsx ./scripts/build.ts",
|
|
141
146
|
"lint": "echo 'Linting is disabled for Blazar'",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { translate, translateForLocalDev } from '../lib/translate.js';
|
|
2
|
+
export type { TranslateResult, TranslateForLocalDevResult, } from '../lib/translate.js';
|
|
2
3
|
export { isTranslationError, type TranslationError } from '../lib/errors.js';
|
|
3
4
|
export type { IntermediateRepresentation, IntermediateRepresentationLocalDev, IntermediateRepresentationNodeLocalDev, IntermediateRepresentationNode, TranslationContext, TranslationOptions, TranslationOptionsLocalDev, ComponentMeta, ComponentPermissions, } from '../lib/types.js';
|
package/src/lang/copy.d.ts
CHANGED
|
@@ -49,9 +49,6 @@ export declare function getMissingRequiredFieldError(field: string): string;
|
|
|
49
49
|
export declare function getFailedToFetchSchemasError(): string;
|
|
50
50
|
export declare function getUnsupportedTypeError(type: string): string;
|
|
51
51
|
export declare const logMessages: {
|
|
52
|
-
files: {
|
|
53
|
-
skippingPath: (path: string) => string;
|
|
54
|
-
};
|
|
55
52
|
workspaces: {
|
|
56
53
|
cannotAccessDirectory: (dir: string, e: unknown) => string;
|
|
57
54
|
};
|
package/src/lang/copy.js
CHANGED
|
@@ -64,9 +64,6 @@ export function getUnsupportedTypeError(type) {
|
|
|
64
64
|
return errorMessages.validation.unsupportedType(type);
|
|
65
65
|
}
|
|
66
66
|
export const logMessages = {
|
|
67
|
-
files: {
|
|
68
|
-
skippingPath: (path) => `Skipping ${path} as it is not in a valid directory`,
|
|
69
|
-
},
|
|
70
67
|
workspaces: {
|
|
71
68
|
cannotAccessDirectory: (dir, e) => `Cannot access directory ${dir}: ${e}`,
|
|
72
69
|
},
|
package/src/lib/files.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import { FileParseResult,
|
|
1
|
+
import { FileParseResult, HsProfileFile, TranslationContext } from './types.js';
|
|
2
2
|
export type MetaFileLocation = {
|
|
3
3
|
file: string;
|
|
4
4
|
parentDirectory?: string;
|
|
5
5
|
};
|
|
6
6
|
export declare function loadHsProfileFile(projectSourceDir: string, profile: string): HsProfileFile;
|
|
7
7
|
export declare function getAllHsProfiles(projectSourceDir: string): Promise<string[]>;
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
8
|
+
export type LoadHsMetaFilesResult = {
|
|
9
|
+
results: FileParseResult[];
|
|
10
|
+
skippedFiles: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare function loadHsMetaFiles(translationContext: TranslationContext): Promise<LoadHsMetaFilesResult>;
|
|
13
|
+
export type LocateHsMetaFilesResult = {
|
|
14
|
+
metaFiles: MetaFileLocation[];
|
|
15
|
+
skippedFiles: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare function locateHsMetaFiles(projectSourceDir: string): Promise<LocateHsMetaFilesResult>;
|
|
12
18
|
export declare function projectContainsHsMetaFiles(projectSourceDir: string): Promise<boolean>;
|
|
13
19
|
export declare function convertPathToPosixPath(filepath: string): string;
|
package/src/lib/files.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { walk } from '@hubspot/local-dev-lib/fs';
|
|
4
|
-
import { ALLOWED_COMPONENT_DIRECTORIES, ALLOWED_SUB_COMPONENT_DIRECTORIES,
|
|
5
|
-
import { errorMessages
|
|
6
|
-
import { logger } from '@hubspot/local-dev-lib/logger';
|
|
4
|
+
import { ALLOWED_COMPONENT_DIRECTORIES, ALLOWED_SUB_COMPONENT_DIRECTORIES, ALLOWED_TOP_LEVEL_FIELDS, METAFILE_EXTENSION, } from './constants.js';
|
|
5
|
+
import { errorMessages } from '../lang/copy.js';
|
|
7
6
|
import { getHsProfileFilename, getHsProfileName, getIsProfileFile, } from './profiles.js';
|
|
8
7
|
export function loadHsProfileFile(projectSourceDir, profile) {
|
|
9
8
|
if (!profile) {
|
|
@@ -33,13 +32,19 @@ export function getAllHsProfiles(projectSourceDir) {
|
|
|
33
32
|
});
|
|
34
33
|
}
|
|
35
34
|
export async function loadHsMetaFiles(translationContext) {
|
|
36
|
-
const metaFiles = await locateHsMetaFiles(translationContext.projectSourceDir);
|
|
37
|
-
return
|
|
35
|
+
const { metaFiles, skippedFiles } = await locateHsMetaFiles(translationContext.projectSourceDir);
|
|
36
|
+
return {
|
|
37
|
+
results: await parseHsMetaFiles(metaFiles, translationContext),
|
|
38
|
+
skippedFiles,
|
|
39
|
+
};
|
|
38
40
|
}
|
|
39
|
-
export async function locateHsMetaFiles(projectSourceDir
|
|
40
|
-
|
|
41
|
+
export async function locateHsMetaFiles(projectSourceDir) {
|
|
42
|
+
const metaFiles = [];
|
|
43
|
+
const skippedFiles = [];
|
|
44
|
+
const metaFileCandidates = await walk(projectSourceDir, ['node_modules']);
|
|
45
|
+
for (const file of metaFileCandidates) {
|
|
41
46
|
if (!file.endsWith(METAFILE_EXTENSION)) {
|
|
42
|
-
|
|
47
|
+
continue;
|
|
43
48
|
}
|
|
44
49
|
const pathRelativeToProjectSrcDir = path.relative(projectSourceDir, file);
|
|
45
50
|
const { dir: metaFileDir } = path.parse(pathRelativeToProjectSrcDir);
|
|
@@ -51,12 +56,10 @@ export async function locateHsMetaFiles(projectSourceDir, options = { silent: fa
|
|
|
51
56
|
metaFiles.push({ file, parentDirectory });
|
|
52
57
|
}
|
|
53
58
|
else {
|
|
54
|
-
|
|
55
|
-
logger.warn(logMessages.files.skippingPath(pathRelativeToProjectSrcDir));
|
|
56
|
-
}
|
|
59
|
+
skippedFiles.push(pathRelativeToProjectSrcDir);
|
|
57
60
|
}
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
}
|
|
62
|
+
return { metaFiles, skippedFiles };
|
|
60
63
|
}
|
|
61
64
|
async function parseHsMetaFiles(metaFileLocations, translationContext) {
|
|
62
65
|
const fileLoadResults = await Promise.all(metaFileLocations.map(fileLocation => {
|
package/src/lib/profiles.js
CHANGED
|
@@ -95,15 +95,18 @@ export function applyHsProfileVariables(fileParseResults, hsProfileContents) {
|
|
|
95
95
|
const profileVariables = getHsProfileVariables(hsProfileContents);
|
|
96
96
|
return fileParseResults.map(fileParseResult => {
|
|
97
97
|
const { content, file } = fileParseResult;
|
|
98
|
-
|
|
99
|
-
if (!content?.config) {
|
|
98
|
+
if (!content) {
|
|
100
99
|
return fileParseResult;
|
|
101
100
|
}
|
|
102
|
-
const
|
|
101
|
+
const uidWithVariablesReplaced = interpolate(file, content.uid, profileVariables);
|
|
102
|
+
const configWithVariablesReplaced = content.config
|
|
103
|
+
? replaceVariablesInValue(content.config, file, profileVariables)
|
|
104
|
+
: content.config;
|
|
103
105
|
return {
|
|
104
106
|
...fileParseResult,
|
|
105
107
|
content: {
|
|
106
108
|
...content,
|
|
109
|
+
uid: uidWithVariablesReplaced,
|
|
107
110
|
config: configWithVariablesReplaced,
|
|
108
111
|
},
|
|
109
112
|
};
|
package/src/lib/project.js
CHANGED
|
@@ -7,7 +7,7 @@ export async function getProjectMetadata(projectSrcDir) {
|
|
|
7
7
|
const components = {};
|
|
8
8
|
let metafiles = [];
|
|
9
9
|
if (fs.existsSync(projectSrcDir)) {
|
|
10
|
-
metafiles = await locateHsMetaFiles(projectSrcDir
|
|
10
|
+
({ metaFiles: metafiles } = await locateHsMetaFiles(projectSrcDir));
|
|
11
11
|
}
|
|
12
12
|
const seenComponentPaths = new Map();
|
|
13
13
|
Object.keys(Components).forEach(componentType => {
|
package/src/lib/translate.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import { IntermediateRepresentation, IntermediateRepresentationLocalDev, TranslationContext, TranslationOptions, TranslationOptionsLocalDev } from './types.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export interface TranslateResult {
|
|
3
|
+
intermediateRepresentation: IntermediateRepresentation;
|
|
4
|
+
skippedHsMetaFiles: string[];
|
|
5
|
+
}
|
|
6
|
+
export interface TranslateForLocalDevResult {
|
|
7
|
+
intermediateRepresentation: IntermediateRepresentationLocalDev;
|
|
8
|
+
skippedHsMetaFiles: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function translate(translationContext: TranslationContext, translationOptions?: TranslationOptions): Promise<TranslateResult>;
|
|
11
|
+
export declare function translateForLocalDev(translationContext: TranslationContext, translationOptions?: TranslationOptionsLocalDev): Promise<TranslateForLocalDevResult>;
|
package/src/lib/translate.js
CHANGED
|
@@ -13,7 +13,7 @@ export async function translate(translationContext, translationOptions = default
|
|
|
13
13
|
!isSupportedPlatformVersion(translationContext.platformVersion)) {
|
|
14
14
|
throw new Error(errorMessages.project.unsupportedPlatformVersion(translationContext.platformVersion));
|
|
15
15
|
}
|
|
16
|
-
const metafileContents = await loadHsMetaFiles(translationContext);
|
|
16
|
+
const { results: metafileContents, skippedFiles } = await loadHsMetaFiles(translationContext);
|
|
17
17
|
if (metafileContents.length === 0) {
|
|
18
18
|
throw new Error(errorMessages.project.noHsMetaFiles);
|
|
19
19
|
}
|
|
@@ -27,7 +27,7 @@ export async function translate(translationContext, translationOptions = default
|
|
|
27
27
|
if (!skipValidation) {
|
|
28
28
|
await validateIntermediateRepresentation(intermediateRepresentation, transformations, translationContext);
|
|
29
29
|
}
|
|
30
|
-
return intermediateRepresentation;
|
|
30
|
+
return { intermediateRepresentation, skippedHsMetaFiles: skippedFiles };
|
|
31
31
|
}
|
|
32
32
|
export async function translateForLocalDev(translationContext, translationOptions) {
|
|
33
33
|
const { skipValidation, profile, projectNodesAtLastUpload } = translationOptions || {};
|
|
@@ -35,7 +35,7 @@ export async function translateForLocalDev(translationContext, translationOption
|
|
|
35
35
|
!isSupportedPlatformVersion(translationContext.platformVersion)) {
|
|
36
36
|
throw new Error(errorMessages.project.unsupportedPlatformVersion(translationContext.platformVersion));
|
|
37
37
|
}
|
|
38
|
-
const metafileContents = await loadHsMetaFiles(translationContext);
|
|
38
|
+
const { results: metafileContents, skippedFiles } = await loadHsMetaFiles(translationContext);
|
|
39
39
|
if (metafileContents.length === 0) {
|
|
40
40
|
throw new Error(errorMessages.project.noHsMetaFiles);
|
|
41
41
|
}
|
|
@@ -53,10 +53,13 @@ export async function translateForLocalDev(translationContext, translationOption
|
|
|
53
53
|
}
|
|
54
54
|
const profileData = getLocalDevProfileData(baseIntermediateRepresentation.profileData?.vars.profileVariables);
|
|
55
55
|
return {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
intermediateRepresentation: {
|
|
57
|
+
intermediateNodesIndexedByUid: {
|
|
58
|
+
...projectNodes,
|
|
59
|
+
...projectNodesWithErrors,
|
|
60
|
+
},
|
|
61
|
+
profileData,
|
|
59
62
|
},
|
|
60
|
-
|
|
63
|
+
skippedHsMetaFiles: skippedFiles,
|
|
61
64
|
};
|
|
62
65
|
}
|