submodule-version 2.3.2 → 3.0.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.
Files changed (120) hide show
  1. package/README.md +103 -20
  2. package/dist/runner/handleErrors/handleErrors.d.ts +1 -1
  3. package/dist/runner/handleErrors/handleErrors.js +3 -10
  4. package/dist/runner/handleErrors/handleErrors.js.map +1 -1
  5. package/dist/runner/index.js +0 -0
  6. package/dist/runner/runner.d.ts +4 -0
  7. package/dist/runner/runner.js +91 -37
  8. package/dist/runner/runner.js.map +1 -1
  9. package/dist/src/PubGrub/PubGrub.d.ts +28 -0
  10. package/dist/src/PubGrub/PubGrub.js +366 -0
  11. package/dist/src/PubGrub/PubGrub.js.map +1 -0
  12. package/dist/src/PubGrub/index.d.ts +2 -0
  13. package/dist/src/PubGrub/index.js +7 -0
  14. package/dist/src/PubGrub/index.js.map +1 -0
  15. package/dist/src/PubGrub/types.d.ts +56 -0
  16. package/dist/src/PubGrub/types.js +3 -0
  17. package/dist/src/PubGrub/types.js.map +1 -0
  18. package/dist/src/entryStore.d.ts +16 -0
  19. package/dist/src/entryStore.js +152 -0
  20. package/dist/src/entryStore.js.map +1 -0
  21. package/dist/src/errors.d.ts +28 -0
  22. package/dist/src/errors.js +30 -0
  23. package/dist/src/errors.js.map +1 -0
  24. package/dist/src/git/api/GithubError.d.ts +4 -0
  25. package/dist/src/git/api/GithubError.js +11 -0
  26. package/dist/src/git/api/GithubError.js.map +1 -0
  27. package/dist/src/git/api/api.d.ts +8 -0
  28. package/dist/src/git/api/api.js +133 -0
  29. package/dist/src/git/api/api.js.map +1 -0
  30. package/dist/src/git/api/index.d.ts +3 -0
  31. package/dist/src/git/api/index.js +8 -0
  32. package/dist/src/git/api/index.js.map +1 -0
  33. package/dist/src/git/git.d.ts +30 -23
  34. package/dist/src/git/git.js +8 -258
  35. package/dist/src/git/git.js.map +1 -1
  36. package/dist/src/git/index.d.ts +1 -0
  37. package/dist/src/git/index.js +3 -1
  38. package/dist/src/git/index.js.map +1 -1
  39. package/dist/src/git/local/index.d.ts +1 -0
  40. package/dist/src/git/local/index.js +6 -0
  41. package/dist/src/git/local/index.js.map +1 -0
  42. package/dist/src/git/local/local.d.ts +26 -0
  43. package/dist/src/git/local/local.js +288 -0
  44. package/dist/src/git/local/local.js.map +1 -0
  45. package/dist/src/index.d.ts +7 -0
  46. package/dist/src/index.js +16 -1
  47. package/dist/src/index.js.map +1 -1
  48. package/dist/src/printError.d.ts +1 -0
  49. package/dist/src/printError.js +158 -0
  50. package/dist/src/printError.js.map +1 -0
  51. package/dist/src/sv.d.ts +18 -8
  52. package/dist/src/sv.js +235 -131
  53. package/dist/src/sv.js.map +1 -1
  54. package/dist/src/versionUtil/index.d.ts +2 -0
  55. package/dist/src/versionUtil/index.js +6 -0
  56. package/dist/src/versionUtil/index.js.map +1 -0
  57. package/dist/src/versionUtil/versionUtil.d.ts +16 -0
  58. package/dist/src/versionUtil/versionUtil.js +70 -0
  59. package/dist/src/versionUtil/versionUtil.js.map +1 -0
  60. package/package.json +4 -2
  61. package/runner/handleErrors/handleErrors.ts +3 -10
  62. package/runner/runner.ts +128 -46
  63. package/src/PubGrub/PubGrub.ts +578 -0
  64. package/src/PubGrub/__tests__/PubGrub.test.ts +351 -0
  65. package/src/PubGrub/index.ts +12 -0
  66. package/src/PubGrub/types.ts +72 -0
  67. package/src/__tests__/entryStore.test.ts +248 -0
  68. package/src/__tests__/printError.test.ts +148 -0
  69. package/src/__tests__/sv.test.ts +441 -0
  70. package/src/entryStore.ts +212 -0
  71. package/src/errors.ts +39 -0
  72. package/src/git/api/GithubError.ts +5 -0
  73. package/src/git/api/api.ts +180 -0
  74. package/src/git/api/index.ts +3 -0
  75. package/src/git/git.ts +8 -396
  76. package/src/git/index.ts +1 -0
  77. package/src/git/local/index.ts +1 -0
  78. package/src/git/local/local.ts +430 -0
  79. package/src/index.ts +17 -0
  80. package/src/printError.ts +189 -0
  81. package/src/sv.ts +321 -134
  82. package/src/versionUtil/__tests__/versionUtil.test.ts +62 -0
  83. package/src/versionUtil/index.ts +2 -0
  84. package/src/versionUtil/versionUtil.ts +103 -0
  85. package/tsconfig.json +1 -1
  86. package/dist/runner/handleErrors/handleBuildGraphError.d.ts +0 -1
  87. package/dist/runner/handleErrors/handleBuildGraphError.js +0 -42
  88. package/dist/runner/handleErrors/handleBuildGraphError.js.map +0 -1
  89. package/dist/runner/handleErrors/handleGitError.d.ts +0 -1
  90. package/dist/runner/handleErrors/handleGitError.js +0 -27
  91. package/dist/runner/handleErrors/handleGitError.js.map +0 -1
  92. package/dist/runner/handleErrors/handleInstallError.d.ts +0 -1
  93. package/dist/runner/handleErrors/handleInstallError.js +0 -30
  94. package/dist/runner/handleErrors/handleInstallError.js.map +0 -1
  95. package/dist/src/__tests__/versionUtil.test.d.ts +0 -1
  96. package/dist/src/__tests__/versionUtil.test.js +0 -80
  97. package/dist/src/__tests__/versionUtil.test.js.map +0 -1
  98. package/dist/src/buildGraph/GraphError.d.ts +0 -11
  99. package/dist/src/buildGraph/GraphError.js +0 -11
  100. package/dist/src/buildGraph/GraphError.js.map +0 -1
  101. package/dist/src/buildGraph/buildGraph.d.ts +0 -8
  102. package/dist/src/buildGraph/buildGraph.js +0 -100
  103. package/dist/src/buildGraph/buildGraph.js.map +0 -1
  104. package/dist/src/buildGraph/index.d.ts +0 -2
  105. package/dist/src/buildGraph/index.js +0 -8
  106. package/dist/src/buildGraph/index.js.map +0 -1
  107. package/dist/src/git/__tests__/parseGitUrl.test.d.ts +0 -1
  108. package/dist/src/git/__tests__/parseGitUrl.test.js +0 -30
  109. package/dist/src/git/__tests__/parseGitUrl.test.js.map +0 -1
  110. package/dist/src/versionUtil.d.ts +0 -13
  111. package/dist/src/versionUtil.js +0 -79
  112. package/dist/src/versionUtil.js.map +0 -1
  113. package/runner/handleErrors/handleBuildGraphError.ts +0 -49
  114. package/runner/handleErrors/handleGitError.ts +0 -28
  115. package/runner/handleErrors/handleInstallError.ts +0 -26
  116. package/src/__tests__/versionUtil.test.ts +0 -96
  117. package/src/buildGraph/GraphError.ts +0 -12
  118. package/src/buildGraph/buildGraph.ts +0 -150
  119. package/src/buildGraph/index.ts +0 -2
  120. package/src/versionUtil.ts +0 -97
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "submodule-version",
3
3
  "description": "Git <S>ubmodule <V>ersioning tool",
4
- "version": "2.3.2",
4
+ "version": "3.0.0",
5
5
  "repository": "github:guljeny/submodule-version",
6
6
  "main": "dist/src/index.js",
7
7
  "bin": {
@@ -11,7 +11,7 @@
11
11
  "scripts": {
12
12
  "prepare": "npm run build",
13
13
  "test": "npx jest",
14
- "build": "rm -rf ./dist && npx tsc",
14
+ "build": "rm -rf ./dist && npx tsc && chmod +x dist/runner/index.js",
15
15
  "lint": "npx eslint ./src"
16
16
  },
17
17
  "author": "Yauheni Hul",
@@ -25,6 +25,7 @@
25
25
  "license": "ISC",
26
26
  "devDependencies": {
27
27
  "@types/jest": "^29.5.13",
28
+ "@types/semver": "^7.5.8",
28
29
  "eslint": "9.9.1",
29
30
  "eslint-config-soft": "^1.0.5",
30
31
  "ts-jest": "^29.2.5",
@@ -33,6 +34,7 @@
33
34
  "dependencies": {
34
35
  "chalk": "^4.1.2",
35
36
  "jest": "^29.7.0",
37
+ "semver": "^7.6.3",
36
38
  "typescript": "^5.6.2",
37
39
  "yargs": "^17.7.2"
38
40
  }
@@ -1,13 +1,6 @@
1
- import { handleBuildGraphError } from './handleBuildGraphError';
2
- import { handleInstallError } from './handleInstallError';
3
- import { handleGitError } from './handleGitError';
1
+ import { printError } from '../../src';
4
2
  import { log } from '../log';
5
3
 
6
- export const handleErrors = async (error: Error, gitUrl: string) => {
7
- await Promise.all([
8
- handleBuildGraphError(error),
9
- handleInstallError(error, gitUrl),
10
- handleGitError(error),
11
- ]);
12
- log.error('unhandled error', error.message);
4
+ export const handleErrors = async (error: Error) => {
5
+ log.error(printError(error));
13
6
  };
package/runner/runner.ts CHANGED
@@ -1,37 +1,106 @@
1
1
  import chalk from 'chalk';
2
2
  import yargs from 'yargs';
3
- import { SV } from '../src';
3
+ import { SV, SVError } from '../src';
4
4
  import { log } from './log';
5
5
  import { handleErrors } from './handleErrors';
6
6
 
7
- const BASE_DIR = 'modules';
7
+ /* 'A.B.C' { name: 'C', parent: 'B' } (parent — непосредственный родитель) */
8
+ const splitPath = (modulePath: string): { name: string, parent?: string } => {
9
+ const parts = modulePath.split('.');
10
+ const name = parts.pop() as string;
8
11
 
9
- const makeEvent = (event: (sv: SV, arg: any) => Promise<void>) => {
10
- const sv = new SV(process.cwd(), BASE_DIR);
12
+ return { name, parent: parts.pop() };
13
+ };
11
14
 
12
- return async (arg: any) => {
13
- const { url: gitUrl } = arg as {url: string};
15
+ const makeEvent = (
16
+ event: (sv: SV, arg: any) => Promise<void>,
17
+ { skipInit = false } = {},
18
+ ) => async (arg: any) => {
19
+ const sv = new SV(process.cwd(), arg.modulesDir);
14
20
 
15
- try {
16
- await event(sv, arg);
17
- } catch (e) {
18
- handleErrors(e as Error, gitUrl);
21
+ try {
22
+ /* publish умеет работать с ещё не git/npm-инициализированным проектом */
23
+ if (!skipInit) {
24
+ await sv.init();
19
25
  }
20
- };
26
+
27
+ await event(sv, arg);
28
+ } catch (e) {
29
+ handleErrors(e as Error);
30
+ }
21
31
  };
22
32
 
23
- const install = makeEvent(async (sv, arg) => {
24
- const { url: gitUrl, target } = arg as {url: string, target?: string};
25
- await sv.install(gitUrl, target);
33
+ const put = makeEvent(async (sv, arg) => {
34
+ const { url: gitUrl, target, ver } = arg as {
35
+ url: string,
36
+ target?: string,
37
+ ver?: string,
38
+ };
39
+
40
+ await sv.put(gitUrl, ver || target, ver ? target : undefined);
26
41
  });
27
42
 
28
- const update = makeEvent(async sv => {
29
- await sv.update();
43
+ const update = makeEvent(async (sv, arg) => {
44
+ const { path: modulePath } = arg as { path?: string };
45
+
46
+ if (!modulePath) {
47
+ /* init внутри makeEvent уже пересобрал модули на максимально разрешённые */
48
+ log.message(chalk.green.bold('Modules are up to date!'));
49
+
50
+ return;
51
+ }
52
+
53
+ const { name, parent } = splitPath(modulePath);
54
+ const entry = sv.getResolution()[name];
55
+
56
+ if (!entry) throw new SVError('ADDON_NOT_FOUND', { name });
57
+
58
+ await sv.put(entry.url, '*', parent);
30
59
  });
31
60
 
32
- const remove = makeEvent(async (sv, arg) => {
33
- const { name } = arg as {name: string};
34
- await sv.remove(name);
61
+ const del = makeEvent(async (sv, arg) => {
62
+ const { path: modulePath } = arg as {path: string};
63
+ const { name, parent } = splitPath(modulePath);
64
+
65
+ await sv.delete(name, parent);
66
+ });
67
+
68
+ const listVersions = makeEvent(async (sv, arg) => {
69
+ const { name, installed } = arg as { name?: string, installed?: boolean };
70
+
71
+ if (installed) {
72
+ const resolution = sv.getResolution();
73
+
74
+ if (name && !resolution[name]) {
75
+ throw new SVError('ADDON_NOT_FOUND', { name });
76
+ }
77
+
78
+ const names = name ? [name] : Object.keys(resolution);
79
+
80
+ await Promise.all(names.map(async moduleName => {
81
+ const version = await sv.currentVersion(moduleName);
82
+
83
+ log.message(
84
+ chalk.bold(moduleName),
85
+ version || chalk.red('no version tag'),
86
+ );
87
+ }));
88
+
89
+ return;
90
+ }
91
+
92
+ const versions = sv.listVersions(name);
93
+
94
+ if (name) {
95
+ log.message(chalk.bold(name), (versions as string[]).join(', '));
96
+
97
+ return;
98
+ }
99
+
100
+ Object.entries(versions as Record<string, string[]>)
101
+ .forEach(([moduleName, moduleVersions]) => {
102
+ log.message(chalk.bold(moduleName), moduleVersions.join(', '));
103
+ });
35
104
  });
36
105
 
37
106
  const publish = makeEvent(async (sv, arg) => {
@@ -50,59 +119,72 @@ const publish = makeEvent(async (sv, arg) => {
50
119
  chalk.green.bold('version'),
51
120
  chalk.bgGreen.black(` ${version} `),
52
121
  );
53
- });
122
+ }, { skipInit: true });
54
123
 
55
124
  const validate = makeEvent(async sv => {
56
- const result = await sv.buildGraph();
57
-
58
- Object.entries(result).forEach(([name, entry]) => {
59
- if (!entry.used.includes(entry.version) && entry.versions.length === 0) {
60
- log.message(
61
- chalk.yellow('⚠️ WARN: Module'),
62
- chalk.bgYellow.black(` ${name} `),
63
- chalk.yellow('does not contain any version tag!'),
64
- );
65
- }
66
- });
125
+ sv.getResolution();
67
126
 
68
127
  log.message(chalk.green.bold('Everything is up to date!🔥'));
69
128
  });
70
129
 
71
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
72
130
  export const s = yargs.scriptName('sv')
73
- .usage('$0 <cmd> [args]')
131
+ .usage('$0 [cmd] [args]')
132
+ .option('modules-dir', {
133
+ type: 'string',
134
+ describe: 'Directory where submodules live'
135
+ + ' (stored in package.json as sv-dir)',
136
+ })
74
137
  .command(
75
- ['validate', '$0', 'v'],
138
+ ['$0'],
76
139
  'Validate and install modules',
77
140
  () => {},
78
141
  validate,
79
142
  )
80
143
  .command(
81
- ['update', 'u'],
82
- 'Update git modules to actual versions',
83
- () => {},
144
+ ['update [path]', 'u'],
145
+ 'Update modules to the latest allowed versions',
146
+ y => y.positional('path', {
147
+ type: 'string',
148
+ describe: 'Module path (A.B.C), all modules when omitted',
149
+ }),
84
150
  update,
85
151
  )
86
152
  .command(
87
- ['install <url> [target]', 'i'],
88
- 'Install new submodule',
153
+ ['put <url> [target]', 'install', 'i'],
154
+ 'Install a submodule or change its version',
89
155
  y => y.positional('url', {
90
156
  type: 'string',
91
- describe: 'Git submodule url',
157
+ describe: 'Git submodule url or installed module name',
92
158
  }).positional('target', {
93
159
  type: 'string',
94
- describe: 'Target module name',
160
+ describe: 'Parent module name',
161
+ }).option('ver', {
162
+ type: 'string',
163
+ alias: 'v',
164
+ describe: 'Version to install',
165
+ }),
166
+ put,
167
+ )
168
+ .command(
169
+ ['delete <path>', 'remove', 'r'],
170
+ 'Delete submodule by path',
171
+ y => y.positional('path', {
172
+ type: 'string',
173
+ describe: 'Submodule path (A.B.C)',
95
174
  }),
96
- install,
175
+ del,
97
176
  )
98
177
  .command(
99
- ['remove <name>', 'r'],
100
- 'Remove submodule by name',
178
+ ['list-versions [name]', 'ls'],
179
+ 'List available versions of all modules or one',
101
180
  y => y.positional('name', {
102
181
  type: 'string',
103
- describe: 'Submodule name',
182
+ describe: 'Module name',
183
+ }).option('installed', {
184
+ type: 'boolean',
185
+ describe: 'Show installed versions instead of available',
104
186
  }),
105
- remove,
187
+ listVersions,
106
188
  )
107
189
  .command(
108
190
  ['publish [module]', 'p'],