@salesforce/packaging 0.1.20 → 1.0.2

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.
Files changed (34) hide show
  1. package/lib/interfaces/packagingInterfacesAndType.d.ts +1 -1
  2. package/lib/package/index.d.ts +1 -5
  3. package/lib/package/index.js +3 -5
  4. package/lib/package/package.d.ts +9 -0
  5. package/lib/package/package.js +22 -6
  6. package/lib/package/packageAncestry.d.ts +1 -1
  7. package/lib/package/packageAncestry.js +5 -5
  8. package/lib/package/packageConvert.js +13 -16
  9. package/lib/package/packageDelete.js +3 -5
  10. package/lib/package/packageInstall.js +7 -8
  11. package/lib/package/packageUninstall.js +2 -2
  12. package/lib/package/packageVersion.js +17 -17
  13. package/lib/package/packageVersionCreate.js +41 -38
  14. package/lib/package/packageVersionCreateRequest.js +2 -2
  15. package/lib/package/packageVersionList.js +2 -2
  16. package/lib/package/subscriberPackageVersion.d.ts +8 -2
  17. package/lib/package/subscriberPackageVersion.js +21 -6
  18. package/lib/{utils → package}/versionNumber.d.ts +0 -0
  19. package/lib/{utils → package}/versionNumber.js +0 -0
  20. package/lib/package1/index.d.ts +1 -1
  21. package/lib/package1/index.js +3 -15
  22. package/lib/utils/index.d.ts +1 -3
  23. package/lib/utils/index.js +5 -17
  24. package/lib/utils/packageUtils.d.ts +25 -48
  25. package/lib/utils/packageUtils.js +82 -71
  26. package/package.json +2 -2
  27. package/lib/constants.d.ts +0 -26
  28. package/lib/constants.js +0 -45
  29. package/lib/package/packageInstalledList.d.ts +0 -3
  30. package/lib/package/packageInstalledList.js +0 -15
  31. package/lib/utils/srcDevUtils.d.ts +0 -11
  32. package/lib/utils/srcDevUtils.js +0 -65
  33. package/lib/utils/uniqid.d.ts +0 -14
  34. package/lib/utils/uniqid.js +0 -34
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.numberToDuration = exports.combineSaveErrors = exports.formatDate = exports.generatePackageAliasEntry = exports.getPackageAliasesFromId = exports.getPackageIdFromAlias = exports.getConfigPackageDirectory = exports.getPackageVersionNumber = exports.concatVersion = exports.getInClauseItemsCount = exports.queryWithInConditionChunking = exports.getPackageVersionStrings = exports.getHasMetadataRemoved = exports.getContainerOptions = exports.escapeInstallationKey = exports.getPackageVersionId = exports.massageErrorMessage = exports.applyErrorAction = exports.validateIdNoThrow = exports.getSourceApiVersion = exports.validateId = exports.BY_LABEL = exports.BY_PREFIX = exports.DEFAULT_PACKAGE_DIR = exports.POLL_INTERVAL_SECONDS = exports.SOQL_WHERE_CLAUSE_MAX_LENGTH = exports.INSTALL_URL_BASE = exports.VERSION_NUMBER_SEP = void 0;
3
+ exports.copyDir = exports.zipDir = exports.numberToDuration = exports.combineSaveErrors = exports.generatePackageAliasEntry = exports.getPackageVersionNumber = exports.getPackageVersionStrings = exports.getContainerOptions = exports.escapeInstallationKey = exports.getPackageVersionId = exports.massageErrorMessage = exports.applyErrorAction = exports.validateIdNoThrow = exports.validateId = exports.uniqid = exports.BY_LABEL = exports.DEFAULT_PACKAGE_DIR = exports.POLL_INTERVAL_SECONDS = exports.INSTALL_URL_BASE = exports.VERSION_NUMBER_SEP = void 0;
4
4
  /*
5
5
  * Copyright (c) 2022, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -8,9 +8,18 @@ exports.numberToDuration = exports.combineSaveErrors = exports.formatDate = expo
8
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
9
  */
10
10
  const os = require("os");
11
+ const fs = require("fs");
12
+ const path_1 = require("path");
13
+ const stream_1 = require("stream");
14
+ const util_1 = require("util");
15
+ const crypto_1 = require("crypto");
16
+ const util = require("util");
11
17
  const core_1 = require("@salesforce/core");
12
18
  const ts_types_1 = require("@salesforce/ts-types");
13
19
  const kit_1 = require("@salesforce/kit");
20
+ const core_2 = require("@salesforce/core");
21
+ const globby = require("globby");
22
+ const JSZIP = require("jszip");
14
23
  core_1.Messages.importMessagesDirectory(__dirname);
15
24
  const messages = core_1.Messages.loadMessages('@salesforce/packaging', 'pkg_utils');
16
25
  exports.VERSION_NUMBER_SEP = '.';
@@ -35,7 +44,7 @@ const ID_REGISTRY = [
35
44
  ];
36
45
  exports.INSTALL_URL_BASE = new core_1.SfdcUrl('https://login.salesforce.com/packaging/installPackage.apexp?p0=');
37
46
  // https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_soslsoql.htm
38
- exports.SOQL_WHERE_CLAUSE_MAX_LENGTH = 4000;
47
+ const SOQL_WHERE_CLAUSE_MAX_LENGTH = 4000;
39
48
  exports.POLL_INTERVAL_SECONDS = 30;
40
49
  exports.DEFAULT_PACKAGE_DIR = {
41
50
  path: '',
@@ -44,8 +53,29 @@ exports.DEFAULT_PACKAGE_DIR = {
44
53
  versionNumber: '0.1.0.NEXT',
45
54
  default: true,
46
55
  };
47
- exports.BY_PREFIX = (() => Object.fromEntries(ID_REGISTRY.map((id) => [id.prefix, { prefix: id.prefix, label: id.label }])))();
48
56
  exports.BY_LABEL = (() => Object.fromEntries(ID_REGISTRY.map((id) => [id.label.replace(/ /g, '_').toUpperCase(), { prefix: id.prefix, label: id.label }])))();
57
+ /**
58
+ * A function to generate a unique id and return it in the context of a template, if supplied.
59
+ *
60
+ * A template is a string that can contain `${%s}` to be replaced with a unique id.
61
+ * If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
62
+ *
63
+ * @param options an object with the following properties:
64
+ * - template: a template string.
65
+ * - length: the length of the unique id as presented in hexadecimal.
66
+ */
67
+ function uniqid(options) {
68
+ const uniqueString = (0, crypto_1.randomBytes)(Math.ceil((options?.length ?? 32) / 2.0))
69
+ .toString('hex')
70
+ .slice(0, options?.length ?? 32);
71
+ if (!options?.template) {
72
+ return uniqueString;
73
+ }
74
+ return options.template.includes('%s')
75
+ ? util.format(options.template, uniqueString)
76
+ : `${options.template}${uniqueString}`;
77
+ }
78
+ exports.uniqid = uniqid;
49
79
  function validateId(idObj, value) {
50
80
  if (!validateIdNoThrow(idObj, value)) {
51
81
  throw messages.createError('invalidIdOrAlias', [
@@ -56,10 +86,6 @@ function validateId(idObj, value) {
56
86
  }
57
87
  }
58
88
  exports.validateId = validateId;
59
- function getSourceApiVersion(project) {
60
- return project?.getSfProjectJson().get('sourceApiVersion');
61
- }
62
- exports.getSourceApiVersion = getSourceApiVersion;
63
89
  function validateIdNoThrow(idObj, value) {
64
90
  if (!value || (value.length !== 15 && value.length !== 18)) {
65
91
  return false;
@@ -177,25 +203,6 @@ async function getContainerOptions(packageIds, connection) {
177
203
  return new Map();
178
204
  }
179
205
  exports.getContainerOptions = getContainerOptions;
180
- /**
181
- * Return the Package2Version.HasMetadataRemoved field value for the given Id (05i)
182
- *
183
- * @param packageVersionId package version ID (05i)
184
- * @param connection For tooling query
185
- */
186
- async function getHasMetadataRemoved(packageVersionId, connection) {
187
- const query = `SELECT HasMetadataRemoved FROM Package2Version WHERE Id = '${packageVersionId}'`;
188
- const queryResult = await connection.tooling.query(query);
189
- if (!queryResult || queryResult.records === null || queryResult.records.length === 0) {
190
- throw messages.createError('errorInvalidIdNoMatchingVersionId', [
191
- exports.BY_LABEL.PACKAGE_VERSION_ID.label,
192
- packageVersionId,
193
- exports.BY_LABEL.PACKAGE_VERSION_ID.label,
194
- ]);
195
- }
196
- return queryResult.records[0].HasMetadataRemoved;
197
- }
198
- exports.getHasMetadataRemoved = getHasMetadataRemoved;
199
206
  /**
200
207
  * Given a list of subscriber package version IDs (04t), return the associated version strings (e.g., Major.Minor.Patch.Build)
201
208
  *
@@ -240,7 +247,7 @@ async function queryWithInConditionChunking(query, items, replaceToken, connecti
240
247
  return records;
241
248
  }
242
249
  const whereClause = query.substring(query.toLowerCase().indexOf('where'), query.length);
243
- const inClauseItemsMaxLength = exports.SOQL_WHERE_CLAUSE_MAX_LENGTH - whereClause.length - replaceToken.length;
250
+ const inClauseItemsMaxLength = SOQL_WHERE_CLAUSE_MAX_LENGTH - whereClause.length - replaceToken.length;
244
251
  let itemsQueried = 0;
245
252
  while (itemsQueried < items.length) {
246
253
  const chunkCount = getInClauseItemsCount(items, itemsQueried, inClauseItemsMaxLength);
@@ -263,7 +270,6 @@ async function queryWithInConditionChunking(query, items, replaceToken, connecti
263
270
  }
264
271
  return records;
265
272
  }
266
- exports.queryWithInConditionChunking = queryWithInConditionChunking;
267
273
  /**
268
274
  * Returns the number of items that can be included in a quoted comma-separated string (e.g., "'item1','item2'") not exceeding maxLength
269
275
  */
@@ -285,54 +291,17 @@ function getInClauseItemsCount(items, startIndex, maxLength) {
285
291
  }
286
292
  return includedCount;
287
293
  }
288
- exports.getInClauseItemsCount = getInClauseItemsCount;
289
294
  /**
290
295
  * Return a version string in Major.Minor.Patch.Build format, using 0 for any empty part
291
296
  */
292
297
  function concatVersion(major, minor, patch, build) {
293
298
  return [major, minor, patch, build].map((part) => (part ? `${part}` : '0')).join('.');
294
299
  }
295
- exports.concatVersion = concatVersion;
296
300
  function getPackageVersionNumber(package2VersionObj) {
297
301
  const version = concatVersion(package2VersionObj.MajorVersion, package2VersionObj.MinorVersion, package2VersionObj.PatchVersion, undefined);
298
302
  return version.slice(0, version.lastIndexOf('.'));
299
303
  }
300
304
  exports.getPackageVersionNumber = getPackageVersionNumber;
301
- // TODO: replace with sfProject.getPackageDirectoryWithProperty()
302
- function getConfigPackageDirectory(packageDirs, lookupProperty, lookupValue) {
303
- return packageDirs?.find((pkgDir) => pkgDir[lookupProperty] === lookupValue);
304
- }
305
- exports.getConfigPackageDirectory = getConfigPackageDirectory;
306
- /**
307
- * Given a packageAlias, attempt to return the associated id from the config
308
- *
309
- * @param packageAlias string representing a package alias
310
- * @param project for obtaining the project config
311
- * @returns the associated id or the arg given.
312
- */
313
- // TODO: replace with SfProject.getPackageIdFromAlias()
314
- function getPackageIdFromAlias(packageAlias, project) {
315
- const packageAliases = project.getSfProjectJson().getContents().packageAliases || {};
316
- // return alias if it exists, otherwise return what was passed in
317
- return packageAliases[packageAlias] || packageAlias;
318
- }
319
- exports.getPackageIdFromAlias = getPackageIdFromAlias;
320
- /**
321
- * Given a package id, attempt to return the associated aliases from the config
322
- *
323
- * @param packageId string representing a package id
324
- * @param project for obtaining the project config
325
- * @returns an array of alias for the given id.
326
- */
327
- // TODO: replace with SfProject.getAliasesFromPackageId()
328
- function getPackageAliasesFromId(packageId, project) {
329
- const packageAliases = project?.getSfProjectJson().getContents().packageAliases || {};
330
- // check for a matching alias
331
- return Object.entries(packageAliases)
332
- .filter((alias) => alias[1] === packageId)
333
- .map((alias) => alias[0]);
334
- }
335
- exports.getPackageAliasesFromId = getPackageAliasesFromId;
336
305
  /**
337
306
  * Generate package alias json entry for this package version that can be written to sfdx-project.json
338
307
  *
@@ -346,7 +315,7 @@ exports.getPackageAliasesFromId = getPackageAliasesFromId;
346
315
  */
347
316
  // TODO: move sfProject
348
317
  async function generatePackageAliasEntry(connection, project, packageVersionId, packageVersionNumber, branch, packageId) {
349
- const aliasForPackageId = getPackageAliasesFromId(packageId, project);
318
+ const aliasForPackageId = project.getAliasesFromPackageId(packageId);
350
319
  let packageName;
351
320
  if (aliasForPackageId?.length === 0) {
352
321
  const query = `SELECT Name FROM Package2 WHERE Id = '${packageId}'`;
@@ -362,11 +331,6 @@ async function generatePackageAliasEntry(connection, project, packageVersionId,
362
331
  return [packageAlias, packageVersionId];
363
332
  }
364
333
  exports.generatePackageAliasEntry = generatePackageAliasEntry;
365
- function formatDate(date) {
366
- const pad = (num) => (num < 10 ? `0${num}` : `${num}`);
367
- return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
368
- }
369
- exports.formatDate = formatDate;
370
334
  function combineSaveErrors(sObject, crudOperation, errors) {
371
335
  const errorMessages = errors.map((error) => {
372
336
  const fieldsString = error.fields?.length > 0 ? `Fields: [${error.fields.join(', ')}]` : '';
@@ -385,4 +349,51 @@ function numberToDuration(duration, unit = kit_1.Duration.Unit.MILLISECONDS) {
385
349
  return (0, ts_types_1.isNumber)(duration) ? new kit_1.Duration(duration, unit) : duration;
386
350
  }
387
351
  exports.numberToDuration = numberToDuration;
352
+ const pipeline = (0, util_1.promisify)(stream_1.pipeline);
353
+ /**
354
+ * Zips directory to given zipfile.
355
+ *
356
+ * https://github.com/archiverjs/node-archiver
357
+ *
358
+ * @param dir to zip
359
+ * @param zipfile
360
+ */
361
+ async function zipDir(dir, zipfile) {
362
+ const logger = core_2.Logger.childFromRoot('srcDevUtils#zipDir');
363
+ const timer = process.hrtime();
364
+ const globbyResult = await globby('**/*', { expandDirectories: true, cwd: dir });
365
+ const zip = new JSZIP();
366
+ // add files tp zip
367
+ for (const file of globbyResult) {
368
+ zip.file(file, fs.readFileSync((0, path_1.join)(dir, file)));
369
+ }
370
+ // write zip to file
371
+ const zipStream = zip.generateNodeStream({
372
+ type: 'nodebuffer',
373
+ streamFiles: true,
374
+ compression: 'DEFLATE',
375
+ compressionOptions: {
376
+ level: 3,
377
+ },
378
+ });
379
+ await pipeline(zipStream, fs.createWriteStream(zipfile));
380
+ const stat = fs.statSync(zipfile);
381
+ logger.debug(`${stat.size} bytes written to ${zipfile} in ${getElapsedTime(timer)}ms`);
382
+ return;
383
+ }
384
+ exports.zipDir = zipDir;
385
+ function getElapsedTime(timer) {
386
+ const elapsed = process.hrtime(timer);
387
+ return (elapsed[0] * 1000 + elapsed[1] / 1000000).toFixed(3);
388
+ }
389
+ function copyDir(src, dest) {
390
+ fs.mkdirSync(dest, { recursive: true });
391
+ const entries = fs.readdirSync(src, { withFileTypes: true });
392
+ entries.map((entry) => {
393
+ const srcPath = (0, path_1.join)(src, entry.name);
394
+ const destPath = (0, path_1.join)(dest, entry.name);
395
+ return entry.isDirectory() ? copyDir(srcPath, destPath) : fs.copyFileSync(srcPath, destPath);
396
+ });
397
+ }
398
+ exports.copyDir = copyDir;
388
399
  //# sourceMappingURL=packageUtils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/packaging",
3
- "version": "0.1.20",
3
+ "version": "1.0.2",
4
4
  "description": "packing libraries to Salesforce packaging platform",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -65,7 +65,7 @@
65
65
  "@types/jszip": "^3.4.1",
66
66
  "@types/xml2js": "^0.4.11",
67
67
  "@typescript-eslint/eslint-plugin": "^5.40.1",
68
- "@typescript-eslint/parser": "5.41.0",
68
+ "@typescript-eslint/parser": "5.42.0",
69
69
  "chai": "^4.3.6",
70
70
  "commitizen": "^4.2.4",
71
71
  "eslint": "^8.26.0",
@@ -1,26 +0,0 @@
1
- import { Duration } from '@salesforce/kit';
2
- export declare const consts: {
3
- DEFAULT_USER_DIR_MODE: string;
4
- DEFAULT_USER_FILE_MODE: string;
5
- DEFAULT_STREAM_TIMEOUT_MINUTES: number;
6
- MIN_STREAM_TIMEOUT_MINUTES: number;
7
- DEFAULT_SRC_WAIT_MINUTES: number;
8
- DEFAULT_MDAPI_WAIT_MINUTES: number;
9
- DEFAULT_MDAPI_RETRIEVE_WAIT_MINUTES: number;
10
- DEFAULT_MDAPI_POLL_INTERVAL_MINUTES: number;
11
- DEFAULT_MDAPI_POLL_INTERVAL_MILLISECONDS: number;
12
- MIN_SRC_WAIT_MINUTES: number;
13
- MIN_SRC_DEPLOY_WAIT_MINUTES: number;
14
- WORKSPACE_CONFIG_FILENAME: string;
15
- OLD_WORKSPACE_CONFIG_FILENAME: string;
16
- DEFAULT_DEV_HUB_USERNAME: string;
17
- DEFAULT_USERNAME: string;
18
- ACKNOWLEDGED_USAGE_COLLECTION_FILENAME: string;
19
- PACKAGE_VERSION_INFO_FILE_ZIP: string;
20
- INSTANCE_URL_TOKEN: string;
21
- PACKAGE2_DESCRIPTOR_FILE: string;
22
- PACKAGE_INSTALL_POLL_FREQUENCY: number;
23
- PACKAGE_INSTALL_POLL_TIMEOUT: number;
24
- PACKAGE_PUBLISH_POLL_FREQUENCY: Duration;
25
- PACKAGE_PUBLISH_POLL_TIMEOUT: Duration;
26
- };
package/lib/constants.js DELETED
@@ -1,45 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.consts = void 0;
10
- /* --------------------------------------------------------------------------------------------------------------------
11
- * WARNING: This file has been deprecated and should now be considered locked against further changes. Its contents
12
- * have been partially or wholly superseded by functionality included in the @salesforce/core npm package, and exists
13
- * now to service prior uses in this repository only until they can be ported to use the new @salesforce/core library.
14
- *
15
- * If you need or want help deciding where to add new functionality or how to migrate to the new library, please
16
- * contact the CLI team at alm-cli@salesforce.com.
17
- * ----------------------------------------------------------------------------------------------------------------- */
18
- const kit_1 = require("@salesforce/kit");
19
- exports.consts = {
20
- DEFAULT_USER_DIR_MODE: '700',
21
- DEFAULT_USER_FILE_MODE: '600',
22
- DEFAULT_STREAM_TIMEOUT_MINUTES: 6,
23
- MIN_STREAM_TIMEOUT_MINUTES: 2,
24
- DEFAULT_SRC_WAIT_MINUTES: 33,
25
- DEFAULT_MDAPI_WAIT_MINUTES: 0,
26
- DEFAULT_MDAPI_RETRIEVE_WAIT_MINUTES: -1,
27
- DEFAULT_MDAPI_POLL_INTERVAL_MINUTES: 0.1,
28
- DEFAULT_MDAPI_POLL_INTERVAL_MILLISECONDS: 0.1 * 60 * 1000,
29
- MIN_SRC_WAIT_MINUTES: 1,
30
- MIN_SRC_DEPLOY_WAIT_MINUTES: 0,
31
- WORKSPACE_CONFIG_FILENAME: 'sfdx-project.json',
32
- OLD_WORKSPACE_CONFIG_FILENAME: 'sfdx-workspace.json',
33
- DEFAULT_DEV_HUB_USERNAME: 'defaultdevhubusername',
34
- DEFAULT_USERNAME: 'defaultusername',
35
- ACKNOWLEDGED_USAGE_COLLECTION_FILENAME: 'acknowledgedUsageCollection.json',
36
- PACKAGE_VERSION_INFO_FILE_ZIP: 'package-version-info.zip',
37
- // tokens to be replaced on source:push
38
- INSTANCE_URL_TOKEN: '__SFDX_INSTANCE_URL__',
39
- PACKAGE2_DESCRIPTOR_FILE: 'package2-descriptor.json',
40
- PACKAGE_INSTALL_POLL_FREQUENCY: 5000,
41
- PACKAGE_INSTALL_POLL_TIMEOUT: 5,
42
- PACKAGE_PUBLISH_POLL_FREQUENCY: kit_1.Duration.milliseconds(0),
43
- PACKAGE_PUBLISH_POLL_TIMEOUT: kit_1.Duration.milliseconds(0), // 0ms
44
- };
45
- //# sourceMappingURL=constants.js.map
@@ -1,3 +0,0 @@
1
- import { Connection } from '@salesforce/core';
2
- import { InstalledPackages } from '../interfaces';
3
- export declare function packageInstalledList(conn: Connection): Promise<InstalledPackages[]>;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packageInstalledList = void 0;
4
- const utils_1 = require("../utils");
5
- async function packageInstalledList(conn) {
6
- try {
7
- const query = 'SELECT Id, SubscriberPackageId, SubscriberPackage.NamespacePrefix, SubscriberPackage.Name, SubscriberPackageVersion.Id, SubscriberPackageVersion.Name, SubscriberPackageVersion.MajorVersion, SubscriberPackageVersion.MinorVersion, SubscriberPackageVersion.PatchVersion, SubscriberPackageVersion.BuildNumber FROM InstalledSubscriberPackage ORDER BY SubscriberPackageId';
8
- return (await conn.tooling.query(query)).records;
9
- }
10
- catch (err) {
11
- throw (0, utils_1.applyErrorAction)((0, utils_1.massageErrorMessage)(err));
12
- }
13
- }
14
- exports.packageInstalledList = packageInstalledList;
15
- //# sourceMappingURL=packageInstalledList.js.map
@@ -1,11 +0,0 @@
1
- /**
2
- * Zips directory to given zipfile.
3
- *
4
- * https://github.com/archiverjs/node-archiver
5
- *
6
- * @param dir to zip
7
- * @param zipfile
8
- */
9
- export declare function zipDir(dir: string, zipfile: string): Promise<void>;
10
- export declare function getElapsedTime(timer: [number, number]): string;
11
- export declare function copyDir(src: string, dest: string): void;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.copyDir = exports.getElapsedTime = exports.zipDir = void 0;
4
- /*
5
- * Copyright (c) 2020, salesforce.com, inc.
6
- * All rights reserved.
7
- * Licensed under the BSD 3-Clause license.
8
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
- */
10
- const fs = require("fs");
11
- const path_1 = require("path");
12
- const stream_1 = require("stream");
13
- const util_1 = require("util");
14
- const core_1 = require("@salesforce/core");
15
- const globby = require("globby");
16
- const JSZIP = require("jszip");
17
- const pipeline = (0, util_1.promisify)(stream_1.pipeline);
18
- /**
19
- * Zips directory to given zipfile.
20
- *
21
- * https://github.com/archiverjs/node-archiver
22
- *
23
- * @param dir to zip
24
- * @param zipfile
25
- */
26
- async function zipDir(dir, zipfile) {
27
- const logger = core_1.Logger.childFromRoot('srcDevUtils#zipDir');
28
- const timer = process.hrtime();
29
- const globbyResult = await globby('**/*', { expandDirectories: true, cwd: dir });
30
- const zip = new JSZIP();
31
- // add files tp zip
32
- for (const file of globbyResult) {
33
- zip.file(file, fs.readFileSync((0, path_1.join)(dir, file)));
34
- }
35
- // write zip to file
36
- const zipStream = zip.generateNodeStream({
37
- type: 'nodebuffer',
38
- streamFiles: true,
39
- compression: 'DEFLATE',
40
- compressionOptions: {
41
- level: 3,
42
- },
43
- });
44
- await pipeline(zipStream, fs.createWriteStream(zipfile));
45
- const stat = fs.statSync(zipfile);
46
- logger.debug(`${stat.size} bytes written to ${zipfile} in ${getElapsedTime(timer)}ms`);
47
- return;
48
- }
49
- exports.zipDir = zipDir;
50
- function getElapsedTime(timer) {
51
- const elapsed = process.hrtime(timer);
52
- return (elapsed[0] * 1000 + elapsed[1] / 1000000).toFixed(3);
53
- }
54
- exports.getElapsedTime = getElapsedTime;
55
- function copyDir(src, dest) {
56
- fs.mkdirSync(dest, { recursive: true });
57
- const entries = fs.readdirSync(src, { withFileTypes: true });
58
- entries.map((entry) => {
59
- const srcPath = (0, path_1.join)(src, entry.name);
60
- const destPath = (0, path_1.join)(dest, entry.name);
61
- return entry.isDirectory() ? copyDir(srcPath, destPath) : fs.copyFileSync(srcPath, destPath);
62
- });
63
- }
64
- exports.copyDir = copyDir;
65
- //# sourceMappingURL=srcDevUtils.js.map
@@ -1,14 +0,0 @@
1
- /**
2
- * A function to generate a unique id and return it in the context of a template, if supplied.
3
- *
4
- * A template is a string that can contain `${%s}` to be replaced with a unique id.
5
- * If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
6
- *
7
- * @param options an object with the following properties:
8
- * - template: a template string.
9
- * - length: the length of the unique id as presented in hexadecimal.
10
- */
11
- export declare function uniqid(options?: {
12
- template?: string;
13
- length?: number;
14
- }): string;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uniqid = void 0;
4
- /*
5
- * Copyright (c) 2022, salesforce.com, inc.
6
- * All rights reserved.
7
- * Licensed under the BSD 3-Clause license.
8
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
- */
10
- const crypto_1 = require("crypto");
11
- const util = require("util");
12
- /**
13
- * A function to generate a unique id and return it in the context of a template, if supplied.
14
- *
15
- * A template is a string that can contain `${%s}` to be replaced with a unique id.
16
- * If the template contains the "%s" placeholder, it will be replaced with the unique id otherwise the id will be appended to the template.
17
- *
18
- * @param options an object with the following properties:
19
- * - template: a template string.
20
- * - length: the length of the unique id as presented in hexadecimal.
21
- */
22
- function uniqid(options) {
23
- const uniqueString = (0, crypto_1.randomBytes)(Math.ceil((options?.length ?? 32) / 2.0))
24
- .toString('hex')
25
- .slice(0, options?.length ?? 32);
26
- if (!options?.template) {
27
- return uniqueString;
28
- }
29
- return options.template.includes('%s')
30
- ? util.format(options.template, uniqueString)
31
- : `${options.template}${uniqueString}`;
32
- }
33
- exports.uniqid = uniqid;
34
- //# sourceMappingURL=uniqid.js.map