@astral/pack 1.3.0 → 1.4.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.
@@ -29,7 +29,7 @@ const checkPackageVersion = async (config) => {
29
29
  services_1.logger.info('Версии пакета:', versions);
30
30
  }
31
31
  else {
32
- throw new Error('Не удалось провести анализ коммитов');
32
+ throw new Error('Нет новых коммитов для анализа');
33
33
  }
34
34
  }
35
35
  catch (err) {
@@ -39,12 +39,12 @@ const checkPackageVersion = async (config) => {
39
39
  if (versions.currentVersion === versions.nextVersion) {
40
40
  throw Error('Версии пакетов совпадают');
41
41
  }
42
- const { packPrivateDirPath, semanticRelease: semanticReleaseConfig } = config;
43
- const versionFilePath = path_1.default.join(packPrivateDirPath, semanticReleaseConfig.versionsFileName);
42
+ const { projectPath, packPrivateDirName, semanticRelease: semanticReleaseConfig, } = config;
43
+ const versionFilePath = path_1.default.join(projectPath, packPrivateDirName, semanticReleaseConfig.versionsFileName);
44
44
  services_1.logger.progress('Запись данных о версиях в файл', versionFilePath);
45
45
  try {
46
- if (!fs_1.default.existsSync(packPrivateDirPath)) {
47
- fs_1.default.mkdirSync('.pack');
46
+ if (!fs_1.default.existsSync(path_1.default.join(projectPath, packPrivateDirName))) {
47
+ fs_1.default.mkdirSync(packPrivateDirName);
48
48
  }
49
49
  fs_1.default.writeFileSync(versionFilePath, JSON.stringify(versions));
50
50
  services_1.logger.success('Данные о версиях в файл успешно записаны');
@@ -9,7 +9,7 @@ export declare class ConfigService {
9
9
  /**
10
10
  * Директория, где хранятся приватные файлы для @astral/pack
11
11
  */
12
- readonly packPrivateDirPath: string;
12
+ readonly packPrivateDirName = ".pack";
13
13
  readonly lang: Lang;
14
14
  private readonly configName;
15
15
  private readonly logger;
@@ -47,7 +47,7 @@ class ConfigService {
47
47
  /**
48
48
  * Директория, где хранятся приватные файлы для @astral/pack
49
49
  */
50
- packPrivateDirPath;
50
+ packPrivateDirName = '.pack';
51
51
  lang;
52
52
  configName = 'pack.config.js';
53
53
  logger = new services_1.Logger();
@@ -55,7 +55,6 @@ class ConfigService {
55
55
  constructor() {
56
56
  this.config = this.parseConfig();
57
57
  this.lang = this.checkLanguage();
58
- this.packPrivateDirPath = path_1.default.join(this.projectPath, '.pack');
59
58
  }
60
59
  get sourcePath() {
61
60
  if (fs_1.default.existsSync(path_1.default.join(this.projectPath, 'src'))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astral/pack",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "main": "./index.js",
5
5
  "bin": {
6
6
  "pack": "bin.js"
@@ -6,5 +6,9 @@ export declare class SemanticRelease {
6
6
  currentVersion: any;
7
7
  nextVersion: any;
8
8
  };
9
+ /**
10
+ * Ищет директорию .pack на 5 уровней вложенности директорий
11
+ */
12
+ private getVersionsDirPath;
9
13
  }
10
14
  export declare const createSemanticRelease: (config: ConfigService) => SemanticRelease;
@@ -13,13 +13,12 @@ class SemanticRelease {
13
13
  this._config = _config;
14
14
  }
15
15
  parseVersions = () => {
16
- const { packPrivateDirPath, semanticRelease } = this._config;
17
- const versionsFilePath = path_1.default.join(packPrivateDirPath, semanticRelease.versionsFileName);
16
+ const { semanticRelease } = this._config;
17
+ const versionsFilePath = path_1.default.join(this.getVersionsDirPath(), semanticRelease.versionsFileName);
18
18
  if (!fs_1.default.existsSync(versionsFilePath)) {
19
19
  throw Error('Файл с версиями не найден');
20
20
  }
21
- // eslint-disable-next-line @typescript-eslint/no-var-requires
22
- const { currentVersion, nextVersion } = require(`${packPrivateDirPath}/${semanticRelease.versionsFileName}`);
21
+ const { currentVersion, nextVersion } = JSON.parse(fs_1.default.readFileSync(versionsFilePath, 'utf8'));
23
22
  const versions = {
24
23
  currentVersion,
25
24
  nextVersion,
@@ -27,6 +26,22 @@ class SemanticRelease {
27
26
  Logger_1.logger.info('Версия пакета взята из файла', versionsFilePath, versions);
28
27
  return versions;
29
28
  };
29
+ /**
30
+ * Ищет директорию .pack на 5 уровней вложенности директорий
31
+ */
32
+ getVersionsDirPath = () => {
33
+ const { packPrivateDirName, projectPath } = this._config;
34
+ const levelsToCheck = 5;
35
+ let currentDir = projectPath;
36
+ for (let i = 0; i < levelsToCheck; i++) {
37
+ const packDirPath = path_1.default.join(currentDir, packPrivateDirName);
38
+ if (fs_1.default.existsSync(packDirPath)) {
39
+ return packDirPath;
40
+ }
41
+ currentDir = path_1.default.dirname(currentDir);
42
+ }
43
+ return currentDir;
44
+ };
30
45
  }
31
46
  exports.SemanticRelease = SemanticRelease;
32
47
  const createSemanticRelease = (config) => new SemanticRelease(config);