@microtronics/studio-cli 0.60.0 → 0.62.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.
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultFiles = void 0;
4
- const deployDirectoryName = 'dist/';
5
- const ddeDirectoryName = 'dde/';
6
- const dloDirectoryName = 'dlo/';
7
- const studioDirectoryName = '.studio/';
8
- const dfilesDirectoryName = 'dfiles/';
9
- var DefaultFiles;
10
- (function (DefaultFiles) {
11
- DefaultFiles.fileNames = {
12
- projectSettings: 'studio.json',
13
- mainAmx: 'main.amx',
14
- mainAmxReport: 'main.xml',
15
- ddeXml: 'dde.xml',
16
- ddeOpenApi: 'main.yaml',
17
- historyJson: 'history.json',
18
- mainDDE: 'main.dde',
19
- // autogenerated dlo files
20
- autoInc: 'auto.inc',
21
- defaultInc: 'default.inc',
22
- autoUplinkInc: 'app-uplink.inc',
23
- autoDdeInc: 'X-dde.inc',
24
- mainDdeInc: 'main-dde.inc',
25
- autoLocalDataInc: 'auto-local-data.inc',
26
- legacyAutoInc: 'legacy-auto.inc',
27
- legacyAutoDdeInc: 'legacy-auto-dde.inc',
28
- legacyAutoUplinkInc: 'legacy-auto-uplink.inc',
29
- reportTemplate: 'mdn_report_template.json',
30
- dloCfg: 'dlo.cfg'
31
- };
32
- const studioAutoPath = `${studioDirectoryName}auto/`;
33
- const studioAutoDloPath = `${studioAutoPath}dlo/`;
34
- const studioAutoDdePath = `${studioAutoPath}dde/`;
35
- DefaultFiles.filePaths = {
36
- studio: {
37
- // init file to test if we can write to the workspace
38
- initFile: `${studioAutoPath}.init`,
39
- // auto generated directory
40
- auto: {
41
- path: studioAutoPath,
42
- dlo: {
43
- path: studioAutoDloPath,
44
- autoInc: `${studioAutoDloPath}${DefaultFiles.fileNames.autoInc}`,
45
- defaultInc: `${studioAutoDloPath}${DefaultFiles.fileNames.defaultInc}`,
46
- autoUplinkInc: `${studioAutoDloPath}${DefaultFiles.fileNames.autoUplinkInc}`,
47
- autoLocalDataInc: `${studioAutoDloPath}${DefaultFiles.fileNames.autoLocalDataInc}`,
48
- autoDdeInc: `${studioAutoDloPath}${DefaultFiles.fileNames.autoDdeInc}`,
49
- mainDdeInc: `${studioAutoDloPath}${DefaultFiles.fileNames.mainDdeInc}`,
50
- legacyAutoInc: `${studioAutoDloPath}${DefaultFiles.fileNames.legacyAutoInc}`,
51
- legacyAutoDdeInc: `${studioAutoDloPath}${DefaultFiles.fileNames.legacyAutoDdeInc}`,
52
- legacyAutoUplinkInc: `${studioAutoDloPath}${DefaultFiles.fileNames.legacyAutoUplinkInc}`,
53
- cfg: `${studioAutoDloPath}${DefaultFiles.fileNames.dloCfg}`
54
- },
55
- dde: {
56
- path: studioAutoDdePath,
57
- historyJson: `${studioAutoDdePath}${DefaultFiles.fileNames.historyJson}`
58
- }
59
- },
60
- libdeps: `${studioDirectoryName}libdeps/`
61
- },
62
- dist: {
63
- path: deployDirectoryName,
64
- dloPath: `${deployDirectoryName}dlo/`,
65
- mainAmxPath: `${deployDirectoryName}dlo/${DefaultFiles.fileNames.mainAmx}`,
66
- mainAmxReportPath: `${deployDirectoryName}dlo/${DefaultFiles.fileNames.mainAmxReport}`,
67
- ddeXmlPath: `${deployDirectoryName}dde/${DefaultFiles.fileNames.ddeXml}`,
68
- ddeApiPath: `${deployDirectoryName}api/`,
69
- ddeApi: `${deployDirectoryName}api/${DefaultFiles.fileNames.ddeOpenApi}`,
70
- // ddeJson has changed to history.json and is now in dde/ dir
71
- historyJson: `${deployDirectoryName}dde/${DefaultFiles.fileNames.historyJson}`,
72
- povPath: `${deployDirectoryName}pov`,
73
- povDetailsPath: `${deployDirectoryName}pov/details`,
74
- dfilesPath: `${deployDirectoryName}dfiles`,
75
- dfilesProperties: `${deployDirectoryName}dfiles/properties.json`,
76
- bloPath: `${deployDirectoryName}blo`,
77
- reportTemplate: `${deployDirectoryName}/${DefaultFiles.fileNames.reportTemplate}`,
78
- definesTs: `${deployDirectoryName}defines.ts`,
79
- definesAppTs: `${deployDirectoryName}defines.app.ts`
80
- },
81
- dlo: {
82
- path: dloDirectoryName,
83
- mainDLO: `${dloDirectoryName}main.dlo`,
84
- mainINI: `${dloDirectoryName}main.ini`
85
- },
86
- dde: {
87
- path: ddeDirectoryName,
88
- mainDDE: `${ddeDirectoryName}main.dde`
89
- },
90
- dfiles: {
91
- path: dfilesDirectoryName,
92
- mainDFILES: `${dfilesDirectoryName}/main.dfiles`
93
- },
94
- appIni: 'app.ini',
95
- defaultsIni: 'defaults.ini'
96
- };
97
- /**
98
- * Changelog.md
99
- */
100
- DefaultFiles.readme = (name) => {
101
- return `# ${name} README
102
-
103
- This is the README for your project "${name}". Write a brief description what this project is about.`;
104
- };
105
- /**
106
- * Changelog.md
107
- */
108
- DefaultFiles.changelog = `# Changelog
109
-
110
- All notable changes to this project will be documented in this file.
111
-
112
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).`;
113
- })(DefaultFiles || (exports.DefaultFiles = DefaultFiles = {}));
114
- //# sourceMappingURL=defaultFiles.js.map
@@ -1,578 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Dependencies = exports.LIB_DEPS_PATH = void 0;
27
- const vscode_uri_1 = require("vscode-uri");
28
- const manifest_1 = require("./manifest");
29
- const semver = __importStar(require("semver"));
30
- const registryAPI_1 = require("./registryAPI");
31
- const defaultFiles_1 = require("./defaultFiles");
32
- const apm_1 = require("./package/apm");
33
- const child_process = __importStar(require("node:child_process"));
34
- const tinytar = require('tinytar-fix');
35
- const pako = require('pako');
36
- exports.LIB_DEPS_PATH = '.studio/libdeps';
37
- const PACKAGE_JSON = 'package.json';
38
- var Dependencies;
39
- (function (Dependencies) {
40
- /**
41
- * Just combine all dependencies in one object
42
- * Optional devDependencies can be excluded
43
- * @param manifest
44
- * @param production - set to true if devDependencies should be excluded
45
- */
46
- async function getAll(manifest, production = false) {
47
- const allDeps = manifest.libraryDependencies || {};
48
- // only list dependencies if we are not in production mode
49
- if (!production) {
50
- Object.assign(allDeps, manifest.libraryDevDependencies || {});
51
- }
52
- return allDeps;
53
- }
54
- Dependencies.getAll = getAll;
55
- /**
56
- * get the library name from the dependency id
57
- * eg. Microtronics/dlo-core -> dlo-core
58
- * @param dependencyId
59
- */
60
- function dependencyIdToName(dependencyId) {
61
- return dependencyId.split('/')[1];
62
- }
63
- Dependencies.dependencyIdToName = dependencyIdToName;
64
- /**
65
- * convert a dependency id to the libdeps path
66
- * eg. Microtronics/dlo-core would result into <cwd>/.studio/libdeps/dlo-core
67
- * @param cwd
68
- * @param dependencyId
69
- */
70
- function dependencyToPath(cwd, dependencyId) {
71
- const libraryName = dependencyIdToName(dependencyId);
72
- return vscode_uri_1.Utils.joinPath(cwd, exports.LIB_DEPS_PATH, libraryName);
73
- }
74
- Dependencies.dependencyToPath = dependencyToPath;
75
- /**
76
- * Removes the caret-range constraint from the version
77
- * @public
78
- * @param version
79
- */
80
- function rangeToVersion(version) {
81
- if (isNaN(version.split('')[0])) {
82
- return version.substring(1);
83
- }
84
- else {
85
- return version;
86
- }
87
- }
88
- Dependencies.rangeToVersion = rangeToVersion;
89
- /**
90
- * Validate if the given version satisfies the semver-range
91
- * @param libName
92
- * @param v1
93
- * @param range
94
- * @private
95
- */
96
- function satisfiesSemverRange(libName, v1, range) {
97
- const satisfies = semver.satisfies(v1, range, { includePrerelease: true });
98
- if (!satisfies) {
99
- throw new Error(`${libName}, version ${v1} does not satisfy required constraint ${range}`);
100
- }
101
- }
102
- Dependencies.satisfiesSemverRange = satisfiesSemverRange;
103
- /**
104
- * Build a dependency tree based on the manifest file and a list of dependencies that should be added
105
- * @param cwd
106
- * @param fs
107
- * @param dependenciesToAdd
108
- * @param development
109
- */
110
- async function validateDependencyTree(cwd, fs, dependenciesToAdd = {}, development = false) {
111
- const manifest = await manifest_1.Manifest.read(cwd, fs);
112
- const dependencies = manifest.libraryDependencies || {};
113
- // add development dependencies for install
114
- if (development) {
115
- Object.assign(dependencies, manifest.libraryDevDependencies);
116
- }
117
- const newNames = Object.keys(dependenciesToAdd);
118
- for (const newName of newNames) {
119
- if (Object.hasOwn(dependencies, newName)) {
120
- const newCaretVersion = dependenciesToAdd[newName];
121
- const existingCaretVersion = dependencies[newName];
122
- const newVersion = rangeToVersion(newCaretVersion);
123
- const existingVersion = rangeToVersion(existingCaretVersion);
124
- const compared = semver.compare(newVersion, existingVersion);
125
- if (compared === 1) {
126
- dependencies[newName] = newCaretVersion;
127
- satisfiesSemverRange(newName, newVersion, existingCaretVersion);
128
- }
129
- else if (compared === -1) {
130
- dependencies[newName] = existingCaretVersion;
131
- satisfiesSemverRange(newName, existingVersion, newCaretVersion);
132
- }
133
- }
134
- else {
135
- dependencies[newName] = dependenciesToAdd[newName];
136
- }
137
- }
138
- return dependencies;
139
- }
140
- Dependencies.validateDependencyTree = validateDependencyTree;
141
- /**
142
- * Validate if the given dependency is already installed
143
- * @param cwd
144
- * @param fs
145
- * @param publisherId
146
- * @param libraryName
147
- * @param libraryVersion
148
- */
149
- async function isDependencyInstalled(cwd, fs, publisherId, libraryName, libraryVersion) {
150
- const cleanVersion = rangeToVersion(libraryVersion);
151
- const libraryPath = vscode_uri_1.Utils.joinPath(cwd, exports.LIB_DEPS_PATH, libraryName);
152
- try {
153
- const libraryManifest = await manifest_1.Manifest.read(libraryPath, fs);
154
- const gte = semver.gte(libraryManifest.version, cleanVersion);
155
- return gte && libraryManifest.publisher.toLowerCase() === publisherId.toLowerCase();
156
- }
157
- catch (e) {
158
- // no manifest found or any other error -> trigger reinstall
159
- return false;
160
- }
161
- }
162
- Dependencies.isDependencyInstalled = isDependencyInstalled;
163
- /**
164
- * Remove installed dependency from the libdeps directory
165
- * @param cwd
166
- * @param fs
167
- * @param libraryName
168
- * @param logger
169
- */
170
- async function removeExisting(cwd, fs, logger, libraryName) {
171
- const libraryPath = vscode_uri_1.Utils.joinPath(cwd, exports.LIB_DEPS_PATH, libraryName);
172
- await fs.rm(libraryPath).catch(err => {
173
- logger.error('removeExisting', err);
174
- });
175
- }
176
- Dependencies.removeExisting = removeExisting;
177
- /**
178
- * Extract the given library.tar.gz array buffer
179
- * @param cwd
180
- * @param fs
181
- * @param logger
182
- * @param libraryName
183
- * @param archiveBuffer
184
- */
185
- async function extractLibraryContent(cwd, fs, logger, libraryName, archiveBuffer) {
186
- const files = tinytar.untar(pako.ungzip(archiveBuffer));
187
- await removeExisting(cwd, fs, logger, libraryName);
188
- for (const file of files.values()) {
189
- try {
190
- const filePath = vscode_uri_1.Utils.joinPath(cwd, exports.LIB_DEPS_PATH, libraryName, file.name);
191
- await fs.writeFile(filePath, file.data);
192
- }
193
- catch (e) {
194
- logger.error('Extracting lib', e);
195
- }
196
- }
197
- }
198
- Dependencies.extractLibraryContent = extractLibraryContent;
199
- /**
200
- * Install the given library with the version that the semver range accepts
201
- * @param cwd
202
- * @param fs
203
- * @param logger
204
- * @param env
205
- * @param token
206
- * @param publisherIdName
207
- * @param version
208
- * @param development - install as development dependency
209
- */
210
- async function installDependency(cwd, fs, logger, env, token, publisherIdName, version, development = false) {
211
- const [publisherId, libraryName] = publisherIdName.split('/');
212
- if (version && (await isDependencyInstalled(cwd, fs, publisherId, libraryName, version))) {
213
- return;
214
- }
215
- // just remove any existing version of this library.
216
- await removeExisting(cwd, fs, logger, libraryName);
217
- const libraryProfile = await registryAPI_1.Registry.getLibraryProfile(token, publisherId, libraryName, env);
218
- const versionToDownload = version
219
- ? libraryProfile.versions?.find(versionInfo => {
220
- return semver.eq(versionInfo.name, Dependencies.rangeToVersion(version));
221
- })
222
- : libraryProfile.versions[0];
223
- if (!versionToDownload) {
224
- throw new Error(`Library ${publisherIdName} with version ${version} does not exist!`);
225
- }
226
- const manifestFile = versionToDownload.files.find(file => {
227
- return file.name === 'studio.json';
228
- });
229
- const studioJSON = await fetchStudioJson(token, manifestFile.downloadUrl);
230
- const librarySubDependencies = studioJSON.libraryDependencies || {};
231
- // validate dependency ranges
232
- const newDependencies = { ...librarySubDependencies };
233
- newDependencies[publisherIdName] = `^${versionToDownload.name}`;
234
- await validateDependencyTree(cwd, fs, newDependencies, development);
235
- // install sub dependencies first
236
- for (const [libraryName, libraryVersion] of Object.entries(librarySubDependencies)) {
237
- await installDependency(cwd, fs, logger, env, token, libraryName, libraryVersion, development);
238
- }
239
- const libraryArchive = versionToDownload.files.find(file => {
240
- return file.name === 'library.tar.gz';
241
- });
242
- if (!libraryArchive) {
243
- throw new Error(`Library ${publisherIdName} has no content!`);
244
- }
245
- const libraryBuffer = await registryAPI_1.Registry.fetchCustomContent(token, libraryArchive.downloadUrl);
246
- await extractLibraryContent(cwd, fs, logger, libraryName, libraryBuffer);
247
- await linkLibraryApmParts(cwd, fs, logger, libraryName, development);
248
- // update manifest
249
- const manifest = await manifest_1.Manifest.read(cwd, fs);
250
- const dependencies = manifest.libraryDependencies || {};
251
- const devDependencies = manifest.libraryDevDependencies || {};
252
- const toAdd = development ? devDependencies : dependencies;
253
- toAdd[publisherIdName] = `^${versionToDownload.name}`;
254
- // re-assign dependency object in case it was newly created
255
- manifest.libraryDependencies = dependencies;
256
- manifest.libraryDevDependencies = devDependencies;
257
- await manifest_1.Manifest.write(cwd, fs, manifest);
258
- }
259
- Dependencies.installDependency = installDependency;
260
- /**
261
- * Install all dependencies that are referenced within the studio manifest
262
- * @param cwd
263
- * @param fs
264
- * @param logger
265
- * @param env
266
- * @param token
267
- */
268
- async function installDependencies(cwd, fs, logger, env, token) {
269
- const manifest = await manifest_1.Manifest.read(cwd, fs);
270
- const dependencies = manifest.libraryDependencies || {};
271
- const devDependencies = manifest.libraryDevDependencies || {};
272
- const allDependencies = Object.assign(dependencies, devDependencies);
273
- for (const [libraryName, libraryVersion] of Object.entries(allDependencies)) {
274
- const isDevelopment = Object.hasOwn(devDependencies, libraryName);
275
- // update the tree version with the actual installed version
276
- await installDependency(cwd, fs, logger, env, token, libraryName, libraryVersion, isDevelopment);
277
- }
278
- // Ensure blo/pov file: references are linked for all dependencies
279
- // (installDependency skips linking when the dependency is already installed)
280
- for (const [libraryId] of Object.entries(allDependencies)) {
281
- const libName = dependencyIdToName(libraryId);
282
- const isDevelopment = Object.hasOwn(devDependencies, libraryId);
283
- await linkLibraryApmParts(cwd, fs, logger, libName, isDevelopment);
284
- }
285
- logger.done(`Installed ${Object.entries(allDependencies).length} dependencies`);
286
- }
287
- Dependencies.installDependencies = installDependencies;
288
- /**
289
- * Uninstall the given library
290
- * Validates if the library is any sub-dependency of any other library
291
- * @param cwd
292
- * @param fs
293
- * @param publisherId
294
- * @param libraryName
295
- */
296
- async function uninstallDependency(cwd, fs, logger, publisherId, libraryName) {
297
- const manifest = await manifest_1.Manifest.read(cwd, fs);
298
- const dependencies = manifest.libraryDependencies || {};
299
- const devDependencies = manifest.libraryDevDependencies || {};
300
- const allDependencies = Object.assign(dependencies, devDependencies);
301
- const libraryId = `${publisherId}/${libraryName}`;
302
- delete allDependencies[libraryId];
303
- const validatedDependencies = await validateIfLibraryCanBeRemoved(cwd, fs, allDependencies);
304
- if (!Object.hasOwn(validatedDependencies, libraryId)) {
305
- await unlinkLibraryApmParts(cwd, fs, logger, libraryName);
306
- await removeExisting(cwd, fs, logger, libraryName);
307
- delete devDependencies[libraryId];
308
- delete dependencies[libraryId];
309
- await manifest_1.Manifest.write(cwd, fs, manifest);
310
- }
311
- else {
312
- throw new Error(`Library '${libraryName}' not removed. This library is a dependency of other libraries.`);
313
- }
314
- }
315
- Dependencies.uninstallDependency = uninstallDependency;
316
- /**
317
- * Install npm dependencies in pov and blo working paths if they exist and contain a package.json.
318
- * This ensures that a single `studio install` command sets up the entire project.
319
- * @param cwd
320
- * @param fs
321
- * @param logger
322
- */
323
- async function installNpmInApmParts(cwd, fs, logger) {
324
- const manifest = await manifest_1.Manifest.read(cwd, fs);
325
- const parts = [];
326
- if (manifest.pov?.details?.workingPath) {
327
- parts.push({ name: 'pov', workingPath: manifest.pov.details.workingPath });
328
- }
329
- if (manifest.blo?.workingPath) {
330
- parts.push({ name: 'blo', workingPath: manifest.blo.workingPath });
331
- }
332
- for (const { name, workingPath } of parts) {
333
- const partDir = vscode_uri_1.Utils.joinPath(cwd, workingPath);
334
- const packageJsonPath = vscode_uri_1.Utils.joinPath(partDir, PACKAGE_JSON);
335
- const hasPackageJson = await fs.stat(packageJsonPath);
336
- if (hasPackageJson) {
337
- logger.info(`Installing npm dependencies for ${name} (${workingPath})...`);
338
- await execNpmInstall(partDir, logger);
339
- }
340
- }
341
- }
342
- Dependencies.installNpmInApmParts = installNpmInApmParts;
343
- /**
344
- * Get all libraries that have dlo source
345
- * @param cwd
346
- * @param fs
347
- * @param apmPart currently only dlo and dfiles are supported
348
- */
349
- async function getApmPartDependencies(cwd, fs, apmPart) {
350
- const manifest = await manifest_1.Manifest.read(cwd, fs);
351
- const allDependencies = await getAll(manifest);
352
- const apmDependencies = [];
353
- // @ts-ignore
354
- const defaultApmPath = defaultFiles_1.DefaultFiles.filePaths[apmPart].path;
355
- const includeExtension = apmPart === apm_1.APM.Part.dlo ? 'inc' : 'dfiles';
356
- for (const dependencyId in allDependencies) {
357
- const depPath = Dependencies.dependencyToPath(cwd, dependencyId);
358
- const name = Dependencies.dependencyIdToName(dependencyId);
359
- const incPath = vscode_uri_1.Utils.joinPath(depPath, defaultApmPath, `${name}.${includeExtension}`);
360
- const exists = await fs.stat(incPath);
361
- if (exists) {
362
- apmDependencies.push({
363
- name,
364
- path: incPath
365
- });
366
- }
367
- }
368
- // add current project file if it is a library project
369
- if (manifest_1.Manifest.isLibrary(manifest)) {
370
- const incPath = vscode_uri_1.Utils.joinPath(cwd, defaultApmPath, `${manifest.name}.${includeExtension}`);
371
- if (await fs.stat(incPath)) {
372
- apmDependencies.push({
373
- name: manifest.name,
374
- path: incPath
375
- });
376
- }
377
- }
378
- return apmDependencies;
379
- }
380
- Dependencies.getApmPartDependencies = getApmPartDependencies;
381
- /**
382
- * Link a library's blo/pov exports into the consuming project's part package.json files.
383
- * After a library is extracted, check if it exports blo or pov parts and add `file:` references.
384
- * @param cwd
385
- * @param fs
386
- * @param logger
387
- * @param libraryName - short name, e.g. "pets-demo-lib"
388
- * @param development
389
- */
390
- async function linkLibraryApmParts(cwd, fs, logger, libraryName, development) {
391
- const manifest = await manifest_1.Manifest.read(cwd, fs);
392
- const partConfigs = [
393
- { partName: 'blo', partDistPath: 'blo', workingPath: manifest.blo?.workingPath },
394
- { partName: 'pov', partDistPath: 'pov/details', workingPath: manifest.pov?.details?.workingPath }
395
- ];
396
- for (const { partName, partDistPath, workingPath } of partConfigs) {
397
- if (!workingPath) {
398
- continue;
399
- }
400
- const libPartPackageJson = vscode_uri_1.Utils.joinPath(cwd, exports.LIB_DEPS_PATH, libraryName, 'dist', ...partDistPath.split('/'), PACKAGE_JSON);
401
- const libPartExists = await fs.stat(libPartPackageJson);
402
- if (!libPartExists) {
403
- continue;
404
- }
405
- try {
406
- const pkg = await readPartPackageJson(cwd, fs, workingPath);
407
- const depsKey = development ? 'devDependencies' : 'dependencies';
408
- pkg[depsKey] = pkg[depsKey] || {};
409
- const depth = workingPath.split('/').length;
410
- const relativePrefix = Array(depth).fill('..').join('/');
411
- pkg[depsKey][libraryName] = `file:${relativePrefix}/${exports.LIB_DEPS_PATH}/${libraryName}/dist/${partDistPath}`;
412
- await writePartPackageJson(cwd, fs, workingPath, pkg);
413
- logger.info(`Linked ${libraryName} to ${partName} (${workingPath})`);
414
- }
415
- catch (e) {
416
- logger.warn(`Could not link ${libraryName} to ${partName}: ${e}`);
417
- }
418
- }
419
- }
420
- Dependencies.linkLibraryApmParts = linkLibraryApmParts;
421
- /**
422
- * Unlink a library's blo/pov exports from the consuming project's part package.json files.
423
- * Removes `file:` references that were added by linkLibraryApmParts.
424
- * @param cwd
425
- * @param fs
426
- * @param logger
427
- * @param libraryName - short name, e.g. "pets-demo-lib"
428
- */
429
- async function unlinkLibraryApmParts(cwd, fs, logger, libraryName) {
430
- const manifest = await manifest_1.Manifest.read(cwd, fs);
431
- const partConfigs = [
432
- { partName: 'blo', workingPath: manifest.blo?.workingPath },
433
- { partName: 'pov', workingPath: manifest.pov?.details?.workingPath }
434
- ];
435
- for (const { partName, workingPath } of partConfigs) {
436
- if (!workingPath) {
437
- continue;
438
- }
439
- try {
440
- const pkg = await readPartPackageJson(cwd, fs, workingPath);
441
- let changed = false;
442
- // Remove from dependencies if it's a file: reference
443
- if (pkg.dependencies?.[libraryName]?.startsWith('file:')) {
444
- delete pkg.dependencies[libraryName];
445
- changed = true;
446
- }
447
- // Remove from devDependencies if it's a file: reference
448
- if (pkg.devDependencies?.[libraryName]?.startsWith('file:')) {
449
- delete pkg.devDependencies[libraryName];
450
- changed = true;
451
- }
452
- if (changed) {
453
- await writePartPackageJson(cwd, fs, workingPath, pkg);
454
- logger.info(`Unlinked ${libraryName} from ${partName}`);
455
- }
456
- }
457
- catch (e) {
458
- logger.warn(`Could not unlink ${libraryName} from ${partName}: ${e}`);
459
- }
460
- }
461
- }
462
- Dependencies.unlinkLibraryApmParts = unlinkLibraryApmParts;
463
- })(Dependencies || (exports.Dependencies = Dependencies = {}));
464
- async function readPartPackageJson(cwd, fs, workingPath) {
465
- const packageJsonPath = vscode_uri_1.Utils.joinPath(cwd, workingPath, PACKAGE_JSON);
466
- const data = await fs.readFile(packageJsonPath);
467
- const text = new TextDecoder().decode(data);
468
- return JSON.parse(text);
469
- }
470
- async function writePartPackageJson(cwd, fs, workingPath, pkg) {
471
- const packageJsonPath = vscode_uri_1.Utils.joinPath(cwd, workingPath, PACKAGE_JSON);
472
- const content = JSON.stringify(pkg, null, '\t') + '\n';
473
- await fs.writeFile(packageJsonPath, content);
474
- }
475
- async function fetchStudioJson(token, studioJsonURL) {
476
- return await registryAPI_1.Registry.fetchCustomContent(token, studioJsonURL, true);
477
- }
478
- async function validateIfLibraryCanBeRemoved(cwd, fs, dependencies) {
479
- const allLibraries = {};
480
- function updateAllLibsCache(name, publisherId, version, installed = false) {
481
- const exists = allLibraries[name];
482
- const cleanVersion = Dependencies.rangeToVersion(version);
483
- const cleanExistingVersion = Dependencies.rangeToVersion(version);
484
- if (!exists || semver.gt(cleanVersion, cleanExistingVersion)) {
485
- allLibraries[name] = {
486
- publisherId,
487
- version,
488
- installed
489
- };
490
- }
491
- }
492
- const srcDependencies = Object.entries(dependencies).map(([libraryId, version]) => {
493
- const [publisherId, name] = libraryId.split('/');
494
- updateAllLibsCache(name, publisherId, version, true);
495
- return name;
496
- });
497
- const subDependencies = {};
498
- // get all subdependencies
499
- for (const name of srcDependencies) {
500
- try {
501
- const sub = await getDependenciesOfInstalledLibrary(cwd, fs, name);
502
- subDependencies[name] = Object.entries(sub).map(([libraryId, version]) => {
503
- const [publisherId, name] = libraryId.split('/');
504
- updateAllLibsCache(name, publisherId, version);
505
- return name;
506
- });
507
- srcDependencies.push(...subDependencies[name]);
508
- }
509
- catch (e) {
510
- const missingLibrary = allLibraries[name];
511
- throw new Error(`Please import "${missingLibrary.publisherId}/${name}" first.`);
512
- }
513
- }
514
- const dstDependencies = [];
515
- // eslint-disable-next-line no-constant-condition
516
- while (1) {
517
- const tmp = srcDependencies.filter(srcDep => {
518
- // src already listed in dst -> skip
519
- if (dstDependencies.includes(srcDep)) {
520
- return false;
521
- }
522
- // check if all rqd clibs are already listed in dst
523
- const requires = subDependencies[srcDep] || [];
524
- return requires.every((rqd) => {
525
- return dstDependencies.includes(rqd);
526
- });
527
- });
528
- dstDependencies.push(...tmp);
529
- if (srcDependencies.length === dstDependencies.length) {
530
- break;
531
- }
532
- if (!tmp.length) {
533
- break;
534
- }
535
- }
536
- const sortedDependencies = {};
537
- [...new Set(dstDependencies)].forEach(libraryName => {
538
- const { version, publisherId } = allLibraries[libraryName];
539
- const dependencyEntry = buildDependencyEntry(publisherId, libraryName, version);
540
- sortedDependencies[dependencyEntry.libraryId] = dependencyEntry.libraryVersion;
541
- });
542
- return sortedDependencies;
543
- }
544
- async function getDependenciesOfInstalledLibrary(cwd, fs, libraryName) {
545
- const libDepsPath = vscode_uri_1.Utils.joinPath(cwd, exports.LIB_DEPS_PATH, libraryName);
546
- const manifest = await manifest_1.Manifest.read(libDepsPath, fs);
547
- return manifest?.libraryDependencies || {};
548
- }
549
- function buildDependencyEntry(publisherId, libraryId, libraryVersion) {
550
- return {
551
- libraryName: libraryId,
552
- publisherId,
553
- libraryVersion: libraryVersion[0] === '^' ? libraryVersion : '^' + libraryVersion,
554
- libraryId: `${publisherId}/${libraryId}`
555
- };
556
- }
557
- /**
558
- * Execute `npm install` in the given directory
559
- * @param cwd - working directory where npm install should be executed
560
- * @param logger
561
- */
562
- function execNpmInstall(cwd, logger) {
563
- return new Promise((resolve, reject) => {
564
- child_process.exec('npm ci', { cwd: cwd.fsPath, env: process.env }, (error, stdout, stderr) => {
565
- if (stdout) {
566
- logger.log(stdout);
567
- }
568
- if (stderr) {
569
- logger.error(stderr);
570
- }
571
- if (error) {
572
- reject(error);
573
- }
574
- resolve();
575
- });
576
- });
577
- }
578
- //# sourceMappingURL=dependencies.js.map