@hubspot/cli 8.4.0-beta.0 → 8.5.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/lang/en.d.ts CHANGED
@@ -3279,6 +3279,15 @@ export declare const lib: {
3279
3279
  fileFiltered: (filename: string) => string;
3280
3280
  legacyFileDetected: (filename: string, platformVersion: string) => string;
3281
3281
  projectDoesNotExist: (accountId: number) => string;
3282
+ workspaceIncluded: (workspaceDir: string, archivePath: string) => string;
3283
+ fileDependencyIncluded: (packageName: string, localPath: string, archivePath: string) => string;
3284
+ malformedPackageJson: (packageJsonPath: string, error: string) => string;
3285
+ workspaceCollision: (archivePath: string, workspaceDir: string, existingWorkspace: string) => string;
3286
+ fileDependencyAlreadyIncluded: (packageName: string, archivePath: string) => string;
3287
+ updatingLockfile: (lockfilePath: string) => string;
3288
+ updatingPackageJsonWorkspaces: (packageJsonPath: string) => string;
3289
+ updatedWorkspaces: (workspaces: string) => string;
3290
+ updatedFileDependency: (packageName: string, relativePath: string) => string;
3282
3291
  };
3283
3292
  };
3284
3293
  importData: {
package/lang/en.js CHANGED
@@ -1450,7 +1450,7 @@ export const commands = {
1450
1450
  noRunnableComponents: `No supported components were found in this project. Run ${uiCommandReference('hs project add')} to see a list of available components and add one to your project.`,
1451
1451
  accountNotCombined: `\nLocal development of unified apps is currently only compatible with accounts that are opted into the unified apps beta. Make sure that this account is opted in or switch accounts using ${uiCommandReference('hs account use')}.`,
1452
1452
  unsupportedAccountFlagLegacy: 'The --project-account and --testing-account flags are not supported for projects with platform versions earlier than 2025.2.',
1453
- unsupportedAccountFlagV2: 'The --account flag is is not supported supported for projects with platform versions 2025.2 and newer. Use --testing-account and --project-account flags to specify accounts to use for local dev',
1453
+ unsupportedAccountFlagV2: 'The --account flag is not supported for projects with platform versions 2025.2 and newer. Use --testing-account and --project-account flags to specify accounts to use for local dev',
1454
1454
  localDevAlreadyRunning: `Another ${uiCommandReference('hs project dev')} process is already running. To proceed with local development of this project, stop the existing process and re-run ${uiCommandReference('hs project dev')}.`,
1455
1455
  },
1456
1456
  examples: {
@@ -3299,6 +3299,15 @@ export const lib = {
3299
3299
  fileFiltered: (filename) => `Ignore rule triggered for "${filename}"`,
3300
3300
  legacyFileDetected: (filename, platformVersion) => `The ${chalk.bold(filename)} file is not supported on platform version ${chalk.bold(platformVersion)} and will be ignored.`,
3301
3301
  projectDoesNotExist: (accountId) => `Upload cancelled. Run ${uiCommandReference('hs project upload')} again to create the project in ${uiAccountDescription(accountId)}.`,
3302
+ workspaceIncluded: (workspaceDir, archivePath) => `Including workspace: ${workspaceDir} → ${archivePath}`,
3303
+ fileDependencyIncluded: (packageName, localPath, archivePath) => `Including file: dependency ${packageName}: ${localPath} → ${archivePath}`,
3304
+ malformedPackageJson: (packageJsonPath, error) => `Skipping malformed package.json at ${packageJsonPath}: ${error}`,
3305
+ workspaceCollision: (archivePath, workspaceDir, existingWorkspace) => `Workspace collision: ${archivePath} from ${workspaceDir} and ${existingWorkspace}`,
3306
+ fileDependencyAlreadyIncluded: (packageName, archivePath) => `file: dependency ${packageName} already included as workspace: ${archivePath}`,
3307
+ updatingLockfile: (lockfilePath) => `Updating package-lock.json in archive: ${lockfilePath}`,
3308
+ updatingPackageJsonWorkspaces: (packageJsonPath) => `Updating package.json workspaces in archive: ${packageJsonPath}`,
3309
+ updatedWorkspaces: (workspaces) => ` Updated workspaces: ${workspaces}`,
3310
+ updatedFileDependency: (packageName, relativePath) => ` Updated dependencies.${packageName}: file:${relativePath}`,
3302
3311
  },
3303
3312
  },
3304
3313
  importData: {
@@ -78,7 +78,6 @@ export declare const APP_AUTH_TYPES: {
78
78
  export declare const FEATURES: {
79
79
  readonly UNIFIED_APPS: "Developers:UnifiedApps:PrivateBeta";
80
80
  readonly APP_EVENTS: "Developers:UnifiedApps:AppEventsAccess";
81
- readonly APPS_HOME: "UIE:AppHome";
82
81
  readonly THEME_MIGRATION_2025_2: "Developers:ProjectThemeMigrations:2025.2";
83
82
  readonly AGENT_TOOLS: "ThirdPartyAgentTools";
84
83
  };
package/lib/constants.js CHANGED
@@ -70,7 +70,6 @@ export const APP_AUTH_TYPES = {
70
70
  export const FEATURES = {
71
71
  UNIFIED_APPS: 'Developers:UnifiedApps:PrivateBeta',
72
72
  APP_EVENTS: 'Developers:UnifiedApps:AppEventsAccess',
73
- APPS_HOME: 'UIE:AppHome',
74
73
  THEME_MIGRATION_2025_2: 'Developers:ProjectThemeMigrations:2025.2',
75
74
  AGENT_TOOLS: 'ThirdPartyAgentTools',
76
75
  };
package/lib/hasFeature.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { http } from '@hubspot/local-dev-lib/http';
2
2
  import { fetchEnabledFeatures } from '@hubspot/local-dev-lib/api/localDevAuth';
3
- import { FEATURES } from './constants.js';
4
- const FEATURES_THAT_DEFAULT_ON = [FEATURES.APPS_HOME];
3
+ const FEATURES_THAT_DEFAULT_ON = [];
5
4
  export async function hasFeature(accountId, feature) {
6
5
  const { data: { enabledFeatures }, } = await fetchEnabledFeatures(accountId);
7
6
  if (enabledFeatures[feature] === undefined &&
@@ -42,6 +42,10 @@ export async function autoUpdateCLI(argv) {
42
42
  debugError(e);
43
43
  }
44
44
  const cliUpgradeInfo = getCliUpgradeInfo();
45
+ // Ignore all update notifications if the current version is a pre-release (contains a hyphen)
46
+ if (cliUpgradeInfo.current && cliUpgradeInfo.current.includes('-')) {
47
+ showManualInstallHelp = false;
48
+ }
45
49
  if (isAllowAutoUpdatesEnabled &&
46
50
  cliUpgradeInfo.current &&
47
51
  cliUpgradeInfo.latest &&
@@ -49,9 +53,8 @@ export async function autoUpdateCLI(argv) {
49
53
  !argv.useEnv &&
50
54
  !process.env.SKIP_HUBSPOT_CLI_AUTO_UPDATES &&
51
55
  !preventAutoUpdateForCommand(argv._)) {
52
- // Ignore all update notifications if the current version is a pre-release (contains a hyphen)
53
- if (cliUpgradeInfo.current.includes('-')) {
54
- showManualInstallHelp = false;
56
+ if (!showManualInstallHelp) {
57
+ // Pre-release version detected, skip auto-update
55
58
  }
56
59
  else if (!['major', 'latest'].includes(cliUpgradeInfo.type)) {
57
60
  // type "latest" => current installed version is latest
@@ -1,7 +1,7 @@
1
1
  import { marketplaceDistribution, oAuth, privateDistribution, staticAuth, EMPTY_PROJECT, PROJECT_WITH_APP, FEATURES, } from '../../constants.js';
2
2
  import { commands, lib } from '../../../lang/en.js';
3
3
  import { listPrompt } from '../../prompts/promptUtils.js';
4
- import { APP_EVENTS_KEY as AppEventsKey, PAGES_KEY as PagesKey, } from '@hubspot/project-parsing-lib/constants';
4
+ import { APP_EVENTS_KEY as AppEventsKey } from '@hubspot/project-parsing-lib/constants';
5
5
  import { isV2Project } from '../platformVersion.js';
6
6
  import path from 'path';
7
7
  import { getConfigForPlatformVersion } from './legacy.js';
@@ -47,7 +47,6 @@ export async function createV2App(providedAuth, providedDistribution) {
47
47
  }
48
48
  const componentTypeToGateMap = {
49
49
  [AppEventsKey]: FEATURES.APP_EVENTS,
50
- [PagesKey]: FEATURES.APPS_HOME,
51
50
  'workflow-action-tool': FEATURES.AGENT_TOOLS,
52
51
  };
53
52
  export async function calculateComponentTemplateChoices(components, authType, distribution, accountId, projectMetadata) {
@@ -6,6 +6,7 @@ import { uploadProject } from '@hubspot/local-dev-lib/api/projects';
6
6
  import { shouldIgnoreFile } from '@hubspot/local-dev-lib/ignoreRules';
7
7
  import { isTranslationError, translate, } from '@hubspot/project-parsing-lib/translate';
8
8
  import { projectContainsHsMetaFiles } from '@hubspot/project-parsing-lib/projects';
9
+ import { findAndParsePackageJsonFiles, collectWorkspaceDirectories, collectFileDependencies, } from '@hubspot/project-parsing-lib/workspaces';
9
10
  import SpinniesManager from '../ui/SpinniesManager.js';
10
11
  import { uiAccountDescription } from '../ui/index.js';
11
12
  import util from 'node:util';
@@ -16,6 +17,7 @@ import { isV2Project } from './platformVersion.js';
16
17
  import ProjectValidationError from '../errors/ProjectValidationError.js';
17
18
  import { walk } from '@hubspot/local-dev-lib/fs';
18
19
  import { LEGACY_CONFIG_FILES } from '../constants.js';
20
+ import { archiveWorkspacesAndDependencies, getPackageJsonPathsToUpdate, getLockfilePathsToUpdate, } from './workspaces.js';
19
21
  async function uploadProjectFiles(accountId, projectName, filePath, uploadMessage, platformVersion, intermediateRepresentation) {
20
22
  const accountIdentifier = uiAccountDescription(accountId) || `${accountId}`;
21
23
  SpinniesManager.add('upload', {
@@ -48,6 +50,15 @@ export async function handleProjectUpload({ accountId, projectConfig, projectDir
48
50
  await validateNoHSMetaMismatch(srcDir, projectConfig);
49
51
  const tempFile = tmp.fileSync({ postfix: '.zip' });
50
52
  uiLogger.debug(lib.projectUpload.handleProjectUpload.compressing(tempFile.name));
53
+ // Collect workspace directories and file: dependencies for v2+ projects only.
54
+ // Versions <= 2025.1 do not support the new npm workspaces bundling behavior.
55
+ let workspaceMappings = [];
56
+ let fileDependencyMappings = [];
57
+ if (isV2Project(projectConfig.platformVersion)) {
58
+ const parsedPackageJsons = await findAndParsePackageJsonFiles(srcDir);
59
+ workspaceMappings = await collectWorkspaceDirectories(parsedPackageJsons);
60
+ fileDependencyMappings = await collectFileDependencies(parsedPackageJsons);
61
+ }
51
62
  const output = fs.createWriteStream(tempFile.name);
52
63
  const archive = archiver('zip');
53
64
  const result = new Promise((resolve, reject) => output.on('close', async function () {
@@ -91,8 +102,14 @@ export async function handleProjectUpload({ accountId, projectConfig, projectDir
91
102
  }
92
103
  }));
93
104
  archive.pipe(output);
105
+ const modifiedPackageJsonPaths = getPackageJsonPathsToUpdate(srcDir, workspaceMappings, fileDependencyMappings);
106
+ const lockfilePathsToUpdate = getLockfilePathsToUpdate(srcDir, workspaceMappings, fileDependencyMappings);
94
107
  let loggedIgnoredNodeModule = false;
95
108
  archive.directory(srcDir, false, file => {
109
+ if (modifiedPackageJsonPaths.has(file.name) ||
110
+ lockfilePathsToUpdate.has(file.name)) {
111
+ return false;
112
+ }
96
113
  const ignored = shouldIgnoreFile(file.name, true);
97
114
  if (ignored) {
98
115
  const isNodeModule = file.name.includes('node_modules');
@@ -105,6 +122,8 @@ export async function handleProjectUpload({ accountId, projectConfig, projectDir
105
122
  }
106
123
  return ignored ? false : file;
107
124
  });
125
+ // Archive workspaces and file: dependencies
126
+ await archiveWorkspacesAndDependencies(archive, srcDir, projectDir, workspaceMappings, fileDependencyMappings);
108
127
  archive.finalize();
109
128
  return result;
110
129
  }
@@ -0,0 +1,42 @@
1
+ import archiver from 'archiver';
2
+ import { WorkspaceMapping, FileDependencyMapping } from '@hubspot/project-parsing-lib/workspaces';
3
+ /**
4
+ * Result of archiving workspaces and file dependencies
5
+ */
6
+ export type WorkspaceArchiveResult = {
7
+ packageWorkspaces: Map<string, string[]>;
8
+ packageFileDeps: Map<string, Map<string, string>>;
9
+ };
10
+ /**
11
+ * Generates a short hash of the input string for use in workspace paths.
12
+ * Uses SHA256 truncated to 8 hex characters (4 billion possibilities).
13
+ */
14
+ export declare function shortHash(input: string): string;
15
+ /**
16
+ * Determines the archive path for an external workspace or file: dependency.
17
+ * Produces `_workspaces/<basename>-<hash>` with no subdirectory.
18
+ * The hash prevents collisions between different directories with the same basename.
19
+ */
20
+ export declare function computeExternalArchivePath(absolutePath: string): string;
21
+ /**
22
+ * Updates package.json files in the archive to reflect new workspace and file: dependency paths.
23
+ *
24
+ * Workspace entries in packageWorkspaces are already in final form:
25
+ * - Internal workspaces: relative paths (e.g. "../packages/utils")
26
+ * - External workspaces: relative paths (e.g. "../_workspaces/logger-abc")
27
+ *
28
+ * Only external file: dependencies appear in packageFileDeps; internal ones
29
+ * keep their original file: references and are left untouched.
30
+ */
31
+ export declare function updatePackageJsonInArchive(archive: archiver.Archiver, srcDir: string, packageWorkspaces: Map<string, string[]>, packageFileDeps: Map<string, Map<string, string>>): Promise<void>;
32
+ export declare function rewriteLockfileForExternalDeps(lockfileContent: Record<string, unknown>, pathMappings: Array<{
33
+ oldPath: string;
34
+ newPath: string;
35
+ }>): Record<string, unknown>;
36
+ export declare function getPackageJsonPathsToUpdate(srcDir: string, workspaceMappings: WorkspaceMapping[], fileDependencyMappings: FileDependencyMapping[]): Set<string>;
37
+ export declare function getLockfilePathsToUpdate(srcDir: string, workspaceMappings: WorkspaceMapping[], fileDependencyMappings: FileDependencyMapping[]): Set<string>;
38
+ /**
39
+ * Main orchestration function that handles archiving of workspaces and file dependencies.
40
+ * This is the clean integration point for upload.ts.
41
+ */
42
+ export declare function archiveWorkspacesAndDependencies(archive: archiver.Archiver, srcDir: string, projectDir: string, workspaceMappings: WorkspaceMapping[], fileDependencyMappings: FileDependencyMapping[]): Promise<WorkspaceArchiveResult>;
@@ -0,0 +1,350 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import crypto from 'crypto';
4
+ import { shouldIgnoreFile } from '@hubspot/local-dev-lib/ignoreRules';
5
+ import { getPackableFiles, } from '@hubspot/project-parsing-lib/workspaces';
6
+ import { uiLogger } from '../ui/logger.js';
7
+ import { lib } from '../../lang/en.js';
8
+ /**
9
+ * Generates a short hash of the input string for use in workspace paths.
10
+ * Uses SHA256 truncated to 8 hex characters (4 billion possibilities).
11
+ */
12
+ export function shortHash(input) {
13
+ return crypto.createHash('sha256').update(input).digest('hex').slice(0, 8);
14
+ }
15
+ /**
16
+ * Determines the archive path for an external workspace or file: dependency.
17
+ * Produces `_workspaces/<basename>-<hash>` with no subdirectory.
18
+ * The hash prevents collisions between different directories with the same basename.
19
+ */
20
+ export function computeExternalArchivePath(absolutePath) {
21
+ const resolved = path.resolve(absolutePath);
22
+ const name = path.basename(resolved);
23
+ return path.join('_workspaces', `${name}-${shortHash(resolved)}`);
24
+ }
25
+ /**
26
+ * Returns true if dir is inside srcDir (i.e. it will already be included
27
+ * in the archive from the srcDir walk and must not be copied again).
28
+ */
29
+ function isInsideSrcDir(dir, srcDir) {
30
+ const rel = path.relative(path.resolve(srcDir), path.resolve(dir));
31
+ return !rel.startsWith('..') && !path.isAbsolute(rel);
32
+ }
33
+ /**
34
+ * Creates a file filter function for workspace archiving.
35
+ * Filters files based on packable files list and ignore rules.
36
+ */
37
+ function createWorkspaceFileFilter(packableFiles) {
38
+ return (file) => {
39
+ if (packableFiles.size > 0 && !packableFiles.has(file.name)) {
40
+ uiLogger.debug(lib.projectUpload.handleProjectUpload.fileFiltered(file.name));
41
+ return false;
42
+ }
43
+ const ignored = shouldIgnoreFile(file.name, true);
44
+ if (ignored) {
45
+ uiLogger.debug(lib.projectUpload.handleProjectUpload.fileFiltered(file.name));
46
+ return false;
47
+ }
48
+ return file;
49
+ };
50
+ }
51
+ /**
52
+ * Archives workspace directories and returns mapping information.
53
+ *
54
+ * Internal workspaces (inside srcDir) are not archived — they are already
55
+ * included via the srcDir walk. Their relative paths (from the package.json
56
+ * directory to the workspace directory) are stored directly in the entries.
57
+ *
58
+ * External workspaces (outside srcDir) are copied to `_workspaces/<name>-<hash>`
59
+ * and their relative archive paths (e.g. `../_workspaces/<name>-<hash>`) are stored.
60
+ */
61
+ async function archiveWorkspaceDirectories(archive, srcDir, workspaceMappings) {
62
+ const externalArchivePaths = new Map(); // resolvedDir -> archivePath
63
+ const archivePathToDir = new Map(); // archivePath -> resolvedDir (collision detection)
64
+ const packageWorkspaceEntries = new Map();
65
+ const externalsToArchive = [];
66
+ for (const mapping of workspaceMappings) {
67
+ const { workspaceDir, sourcePackageJsonPath } = mapping;
68
+ if (!packageWorkspaceEntries.has(sourcePackageJsonPath)) {
69
+ packageWorkspaceEntries.set(sourcePackageJsonPath, []);
70
+ }
71
+ if (isInsideSrcDir(workspaceDir, srcDir)) {
72
+ // Internal: already in archive from srcDir walk.
73
+ // Store the relative path from the package.json directory so npm can resolve it.
74
+ const relPath = path.relative(path.dirname(sourcePackageJsonPath), path.resolve(workspaceDir));
75
+ packageWorkspaceEntries.get(sourcePackageJsonPath).push(relPath);
76
+ }
77
+ else {
78
+ // External: archive to _workspaces/<name>-<hash>.
79
+ const archivePath = computeExternalArchivePath(workspaceDir);
80
+ const resolvedDir = path.resolve(workspaceDir);
81
+ // Detect hash collisions (different dirs mapping to the same archive path)
82
+ const existing = archivePathToDir.get(archivePath);
83
+ if (existing && existing !== resolvedDir) {
84
+ throw new Error(lib.projectUpload.handleProjectUpload.workspaceCollision(archivePath, workspaceDir, existing));
85
+ }
86
+ if (!externalArchivePaths.has(resolvedDir)) {
87
+ externalArchivePaths.set(resolvedDir, archivePath);
88
+ archivePathToDir.set(archivePath, resolvedDir);
89
+ externalsToArchive.push({ dir: workspaceDir, archivePath });
90
+ }
91
+ const relPkgJsonDir = path.relative(srcDir, path.dirname(sourcePackageJsonPath));
92
+ const relativeEntry = path.relative(relPkgJsonDir, archivePath);
93
+ packageWorkspaceEntries.get(sourcePackageJsonPath).push(relativeEntry);
94
+ }
95
+ }
96
+ // Fetch packable files in parallel (I/O optimization)
97
+ const withPackableFiles = await Promise.all(externalsToArchive.map(async (item) => ({
98
+ ...item,
99
+ packableFiles: await getPackableFiles(item.dir),
100
+ })));
101
+ // Archive directories sequentially (archiver requires sequential operations)
102
+ for (const { dir, archivePath, packableFiles } of withPackableFiles) {
103
+ uiLogger.log(lib.projectUpload.handleProjectUpload.workspaceIncluded(dir, archivePath));
104
+ archive.directory(dir, archivePath, createWorkspaceFileFilter(packableFiles));
105
+ }
106
+ return { externalArchivePaths, packageWorkspaceEntries };
107
+ }
108
+ /**
109
+ * Archives file: dependencies and returns mapping information.
110
+ *
111
+ * Internal file: dependencies (inside srcDir) are skipped — their original
112
+ * `file:` references in package.json remain valid after upload.
113
+ *
114
+ * External file: dependencies are archived to `_workspaces/<name>-<hash>`
115
+ * and tracked in the returned map so package.json can be rewritten.
116
+ */
117
+ async function archiveFileDependencies(archive, srcDir, fileDependencyMappings, externalArchivePaths) {
118
+ const packageFileDeps = new Map();
119
+ const toArchive = [];
120
+ for (const mapping of fileDependencyMappings) {
121
+ const { packageName, localPath, sourcePackageJsonPath } = mapping;
122
+ if (isInsideSrcDir(localPath, srcDir)) {
123
+ // Internal: original file: reference stays unchanged, nothing to do
124
+ continue;
125
+ }
126
+ // External: archive to _workspaces/<name>-<hash>
127
+ const archivePath = computeExternalArchivePath(localPath);
128
+ const resolvedPath = path.resolve(localPath);
129
+ if (!packageFileDeps.has(sourcePackageJsonPath)) {
130
+ packageFileDeps.set(sourcePackageJsonPath, new Map());
131
+ }
132
+ const relPkgJsonDir = path.relative(srcDir, path.dirname(sourcePackageJsonPath));
133
+ const relativeArchivePath = path.relative(relPkgJsonDir, archivePath);
134
+ packageFileDeps
135
+ .get(sourcePackageJsonPath)
136
+ .set(packageName, relativeArchivePath);
137
+ // Only archive each unique path once
138
+ if (!externalArchivePaths.has(resolvedPath)) {
139
+ externalArchivePaths.set(resolvedPath, archivePath);
140
+ toArchive.push({ localPath, archivePath, packageName });
141
+ }
142
+ }
143
+ // Fetch packable files in parallel (I/O optimization)
144
+ const withPackableFiles = await Promise.all(toArchive.map(async (item) => ({
145
+ ...item,
146
+ packableFiles: await getPackableFiles(item.localPath),
147
+ })));
148
+ // Archive directories sequentially (archiver requires sequential operations)
149
+ for (const { localPath, archivePath, packageName, packableFiles, } of withPackableFiles) {
150
+ uiLogger.log(lib.projectUpload.handleProjectUpload.fileDependencyIncluded(packageName, localPath, archivePath));
151
+ archive.directory(localPath, archivePath, createWorkspaceFileFilter(packableFiles));
152
+ }
153
+ return packageFileDeps;
154
+ }
155
+ /**
156
+ * Updates package.json files in the archive to reflect new workspace and file: dependency paths.
157
+ *
158
+ * Workspace entries in packageWorkspaces are already in final form:
159
+ * - Internal workspaces: relative paths (e.g. "../packages/utils")
160
+ * - External workspaces: relative paths (e.g. "../_workspaces/logger-abc")
161
+ *
162
+ * Only external file: dependencies appear in packageFileDeps; internal ones
163
+ * keep their original file: references and are left untouched.
164
+ */
165
+ export async function updatePackageJsonInArchive(archive, srcDir, packageWorkspaces, packageFileDeps) {
166
+ // Collect all package.json paths that need updating
167
+ const allPackageJsonPaths = new Set([
168
+ ...packageWorkspaces.keys(),
169
+ ...packageFileDeps.keys(),
170
+ ]);
171
+ for (const packageJsonPath of allPackageJsonPaths) {
172
+ if (!fs.existsSync(packageJsonPath)) {
173
+ continue;
174
+ }
175
+ const relativePackageJsonPath = path.relative(srcDir, packageJsonPath);
176
+ let rawContent;
177
+ try {
178
+ rawContent = fs.readFileSync(packageJsonPath, 'utf8');
179
+ }
180
+ catch {
181
+ continue;
182
+ }
183
+ let packageJson;
184
+ try {
185
+ packageJson = JSON.parse(rawContent);
186
+ }
187
+ catch (e) {
188
+ uiLogger.warn(lib.projectUpload.handleProjectUpload.malformedPackageJson(packageJsonPath, e instanceof Error ? e.message : String(e)));
189
+ archive.append(rawContent, { name: relativePackageJsonPath });
190
+ continue;
191
+ }
192
+ let modified = false;
193
+ // Update workspaces field — entries are already in their final form
194
+ const workspaceEntries = packageWorkspaces.get(packageJsonPath);
195
+ if (workspaceEntries && packageJson.workspaces) {
196
+ packageJson.workspaces = workspaceEntries;
197
+ modified = true;
198
+ uiLogger.debug(lib.projectUpload.handleProjectUpload.updatingPackageJsonWorkspaces(relativePackageJsonPath));
199
+ uiLogger.debug(lib.projectUpload.handleProjectUpload.updatedWorkspaces(workspaceEntries.join(', ')));
200
+ }
201
+ // Update external file: dependencies; internal ones are left untouched
202
+ const fileDeps = packageFileDeps.get(packageJsonPath);
203
+ if (fileDeps && fileDeps.size > 0 && packageJson.dependencies) {
204
+ for (const [packageName, archivePath] of fileDeps.entries()) {
205
+ if (packageJson.dependencies[packageName]?.startsWith('file:')) {
206
+ packageJson.dependencies[packageName] = `file:${archivePath}`;
207
+ modified = true;
208
+ uiLogger.debug(lib.projectUpload.handleProjectUpload.updatedFileDependency(packageName, archivePath));
209
+ }
210
+ }
211
+ }
212
+ archive.append(modified ? JSON.stringify(packageJson, null, 2) : rawContent, { name: relativePackageJsonPath });
213
+ }
214
+ // Ensure all append operations are queued before finalize is called
215
+ // Use setImmediate to yield control and let archiver process the queue
216
+ await new Promise(resolve => setImmediate(resolve));
217
+ }
218
+ export function rewriteLockfileForExternalDeps(lockfileContent, pathMappings) {
219
+ if (pathMappings.length === 0) {
220
+ return lockfileContent;
221
+ }
222
+ const packages = lockfileContent.packages;
223
+ if (!packages) {
224
+ return lockfileContent;
225
+ }
226
+ const newPackages = {};
227
+ for (const [key, value] of Object.entries(packages)) {
228
+ const mapping = pathMappings.find(m => m.oldPath === key);
229
+ newPackages[mapping ? mapping.newPath : key] = value;
230
+ }
231
+ for (const [key, value] of Object.entries(newPackages)) {
232
+ if (key.startsWith('node_modules/') &&
233
+ typeof value === 'object' &&
234
+ value !== null) {
235
+ const entry = value;
236
+ if (entry.link === true && typeof entry.resolved === 'string') {
237
+ const mapping = pathMappings.find(m => m.oldPath === entry.resolved);
238
+ if (mapping) {
239
+ newPackages[key] = { ...entry, resolved: mapping.newPath };
240
+ }
241
+ }
242
+ }
243
+ }
244
+ const rootEntry = newPackages[''];
245
+ if (rootEntry && typeof rootEntry === 'object' && rootEntry !== null) {
246
+ const root = rootEntry;
247
+ if (Array.isArray(root.workspaces)) {
248
+ newPackages[''] = {
249
+ ...root,
250
+ workspaces: root.workspaces.map((ws) => {
251
+ if (typeof ws !== 'string')
252
+ return ws;
253
+ const mapping = pathMappings.find(m => m.oldPath === ws);
254
+ return mapping ? mapping.newPath : ws;
255
+ }),
256
+ };
257
+ }
258
+ }
259
+ return { ...lockfileContent, packages: newPackages };
260
+ }
261
+ export function getPackageJsonPathsToUpdate(srcDir, workspaceMappings, fileDependencyMappings) {
262
+ const paths = new Set();
263
+ for (const { sourcePackageJsonPath } of workspaceMappings) {
264
+ paths.add(path.relative(srcDir, sourcePackageJsonPath));
265
+ }
266
+ for (const { localPath, sourcePackageJsonPath } of fileDependencyMappings) {
267
+ if (!isInsideSrcDir(localPath, srcDir)) {
268
+ paths.add(path.relative(srcDir, sourcePackageJsonPath));
269
+ }
270
+ }
271
+ return paths;
272
+ }
273
+ function getDirsWithExternalDeps(srcDir, workspaceMappings, fileDependencyMappings) {
274
+ const dirs = new Set();
275
+ for (const { workspaceDir, sourcePackageJsonPath } of workspaceMappings) {
276
+ if (!isInsideSrcDir(workspaceDir, srcDir)) {
277
+ dirs.add(path.dirname(sourcePackageJsonPath));
278
+ }
279
+ }
280
+ for (const { localPath, sourcePackageJsonPath } of fileDependencyMappings) {
281
+ if (!isInsideSrcDir(localPath, srcDir)) {
282
+ dirs.add(path.dirname(sourcePackageJsonPath));
283
+ }
284
+ }
285
+ return dirs;
286
+ }
287
+ export function getLockfilePathsToUpdate(srcDir, workspaceMappings, fileDependencyMappings) {
288
+ const dirsWithExternalDeps = getDirsWithExternalDeps(srcDir, workspaceMappings, fileDependencyMappings);
289
+ const paths = new Set();
290
+ for (const dir of dirsWithExternalDeps) {
291
+ const lockfilePath = path.join(dir, 'package-lock.json');
292
+ if (fs.existsSync(lockfilePath)) {
293
+ paths.add(path.relative(srcDir, lockfilePath));
294
+ }
295
+ }
296
+ return paths;
297
+ }
298
+ async function rewriteLockfilesInArchive(archive, srcDir, externalArchivePaths, dirsWithExternalDeps) {
299
+ if (externalArchivePaths.size === 0)
300
+ return;
301
+ for (const dir of dirsWithExternalDeps) {
302
+ const lockfilePath = path.join(dir, 'package-lock.json');
303
+ if (!fs.existsSync(lockfilePath))
304
+ continue;
305
+ let rawContent;
306
+ try {
307
+ rawContent = fs.readFileSync(lockfilePath, 'utf8');
308
+ }
309
+ catch {
310
+ continue;
311
+ }
312
+ let lockfileContent;
313
+ try {
314
+ lockfileContent = JSON.parse(rawContent);
315
+ }
316
+ catch {
317
+ continue;
318
+ }
319
+ const pathMappings = [];
320
+ for (const [absoluteExternalPath, archivePath] of externalArchivePaths) {
321
+ pathMappings.push({
322
+ oldPath: path.relative(dir, absoluteExternalPath),
323
+ newPath: path.relative(dir, path.join(srcDir, archivePath)),
324
+ });
325
+ }
326
+ const rewritten = rewriteLockfileForExternalDeps(lockfileContent, pathMappings);
327
+ const relativeLockfilePath = path.relative(srcDir, lockfilePath);
328
+ uiLogger.debug(lib.projectUpload.handleProjectUpload.updatingLockfile(relativeLockfilePath));
329
+ archive.append(JSON.stringify(rewritten, null, 2), {
330
+ name: relativeLockfilePath,
331
+ });
332
+ }
333
+ await new Promise(resolve => setImmediate(resolve));
334
+ }
335
+ /**
336
+ * Main orchestration function that handles archiving of workspaces and file dependencies.
337
+ * This is the clean integration point for upload.ts.
338
+ */
339
+ export async function archiveWorkspacesAndDependencies(archive, srcDir, projectDir, workspaceMappings, fileDependencyMappings) {
340
+ // Archive workspace directories (internal ones are skipped, externals are copied)
341
+ const { externalArchivePaths, packageWorkspaceEntries } = await archiveWorkspaceDirectories(archive, srcDir, workspaceMappings);
342
+ // Archive external file: dependencies (internals are skipped)
343
+ const packageFileDeps = await archiveFileDependencies(archive, srcDir, fileDependencyMappings, externalArchivePaths);
344
+ // Update package.json files with new paths
345
+ await updatePackageJsonInArchive(archive, srcDir, packageWorkspaceEntries, packageFileDeps);
346
+ // Rewrite lock files to point to archive paths for external deps
347
+ const dirsWithExternalDeps = getDirsWithExternalDeps(srcDir, workspaceMappings, fileDependencyMappings);
348
+ await rewriteLockfilesInArchive(archive, srcDir, externalArchivePaths, dirsWithExternalDeps);
349
+ return { packageWorkspaces: packageWorkspaceEntries, packageFileDeps };
350
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cli",
3
- "version": "8.4.0-beta.0",
3
+ "version": "8.5.0-beta.0",
4
4
  "description": "The official CLI for developing on HubSpot",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "https://github.com/HubSpot/hubspot-cli",
@@ -11,9 +11,9 @@
11
11
  ],
12
12
  "dependencies": {
13
13
  "@hubspot/local-dev-lib": "5.3.3",
14
- "@hubspot/project-parsing-lib": "0.12.1",
14
+ "@hubspot/project-parsing-lib": "0.14.0",
15
15
  "@hubspot/serverless-dev-runtime": "7.0.7",
16
- "@hubspot/ui-extensions-dev-server": "2.0.3",
16
+ "@hubspot/ui-extensions-dev-server": "2.0.4",
17
17
  "@inquirer/prompts": "7.1.0",
18
18
  "@modelcontextprotocol/sdk": "1.25.0",
19
19
  "archiver": "7.0.1",