@halospv3/hce.shared-config 2.6.4 → 3.0.0-develop.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 (152) hide show
  1. package/CHANGELOG.md +356 -101
  2. package/README.md +100 -87
  3. package/dotnet/.github/workflows/_unit_test.yml +6 -3
  4. package/dotnet/.github/workflows/ci.yml +2 -2
  5. package/dotnet/.github/workflows/dotnet-release.yml +31 -28
  6. package/dotnet/.github/workflows/sample-dotnet-build.yml +16 -11
  7. package/dotnet/ExecNupkgDeterministicator.README.md +20 -0
  8. package/dotnet/ExecNupkgDeterministicator.targets +173 -0
  9. package/dotnet/GitVersion.yml +3 -1
  10. package/dotnet/GitVersion6.0.yml +3 -1
  11. package/dotnet/HCE.Shared.sln +34 -0
  12. package/dotnet/HCE.Shared.targets +1 -0
  13. package/dotnet/PublishAll.targets +2 -0
  14. package/dotnet/SignAfterPack.targets +104 -0
  15. package/dotnet/samples/HCE.Shared.DeterministicNupkg/Dummy.cs +6 -0
  16. package/dotnet/samples/HCE.Shared.DeterministicNupkg/HCE.Shared.DeterministicNupkg.csproj +21 -0
  17. package/dotnet/samples/HCE.Shared.SignAfterPack/Class1.cs +6 -0
  18. package/dotnet/samples/HCE.Shared.SignAfterPack/HCE.Shared.SignAfterPack.csproj +21 -0
  19. package/dotnet/samples/HCE.Shared.SignAfterPack/sampleCert.samplepfx +0 -0
  20. package/dotnet/samples/README.md +7 -0
  21. package/package.json +72 -73
  22. package/src/CaseInsensitiveMap.ts +34 -0
  23. package/src/commitlintConfig.ts +17 -9
  24. package/src/debug.ts +3 -3
  25. package/src/dotnet/GithubNugetRegistryInfo.ts +60 -0
  26. package/src/dotnet/GitlabNugetRegistryInfo.ts +112 -0
  27. package/src/dotnet/IsNextVersionAlreadyPublished.cli.ts +44 -0
  28. package/src/dotnet/MSBuildProject.ts +557 -76
  29. package/src/dotnet/MSBuildProjectProperties.ts +280 -15
  30. package/src/dotnet/NugetProjectProperties.ts +608 -0
  31. package/src/dotnet/NugetRegistryInfo.ts +939 -0
  32. package/src/dotnet/helpers.ts +448 -0
  33. package/src/eslintConfig.ts +174 -71
  34. package/src/index.ts +1 -3
  35. package/src/semantic-release__commit-analyzer.d.ts +44 -38
  36. package/src/semantic-release__exec.d.ts +15 -0
  37. package/src/semantic-release__git.d.ts +85 -88
  38. package/src/semantic-release__github.d.ts +139 -139
  39. package/src/semanticReleaseConfig.ts +106 -47
  40. package/src/semanticReleaseConfigDotnet.ts +394 -104
  41. package/src/setupGitPluginSpec.ts +149 -57
  42. package/src/tsconfig.json +8 -8
  43. package/src/utils/Exact.ts +49 -0
  44. package/src/utils/GracefulRecursion.d.ts +12 -0
  45. package/src/utils/env.ts +44 -0
  46. package/src/utils/execAsync.ts +77 -0
  47. package/src/utils/miscTypes.ts +17 -0
  48. package/src/utils/reflection/FunctionLike.d.ts +17 -0
  49. package/src/utils/reflection/GetterDescriptor.d.ts +8 -0
  50. package/src/utils/reflection/InstancePropertyDescriptorMap.d.ts +32 -0
  51. package/src/utils/reflection/InstanceTypeOrSelfPropertyDescriptorMap.d.ts +20 -0
  52. package/src/utils/reflection/OwnGetterDescriptorMap.d.ts +17 -0
  53. package/src/utils/reflection/OwnKeyOf.d.ts +20 -0
  54. package/src/utils/reflection/OwnPropertyDescriptorMap.d.ts +82 -0
  55. package/src/utils/reflection/PropertyDescriptorMap.d.ts +15 -0
  56. package/src/utils/reflection/filterForGetters.ts +59 -0
  57. package/src/utils/reflection/getOwnPropertyDescriptors.ts +52 -0
  58. package/src/utils/reflection/getOwnPropertyDescriptorsRecursively.ts +127 -0
  59. package/src/utils/reflection/getPrototypeChainOf.ts +85 -0
  60. package/src/utils/reflection/getPrototypeOf.ts +12 -0
  61. package/src/utils/reflection/inheritance.ts +262 -0
  62. package/src/utils/reflection/isConstructor.ts +74 -0
  63. package/src/utils/reflection/isGetterDescriptor.ts +11 -0
  64. package/src/utils/reflection/listOwnGetters.ts +80 -0
  65. package/src/utils/reflection.ts +18 -0
  66. package/cjs/commitlintConfig-wrapper.mjs +0 -6
  67. package/cjs/commitlintConfig.cjs +0 -14
  68. package/cjs/commitlintConfig.cjs.map +0 -1
  69. package/cjs/commitlintConfig.d.ts +0 -4
  70. package/cjs/commitlintConfig.d.ts.map +0 -1
  71. package/cjs/debug.cjs +0 -13
  72. package/cjs/debug.cjs.map +0 -1
  73. package/cjs/debug.d.ts +0 -4
  74. package/cjs/debug.d.ts.map +0 -1
  75. package/cjs/dotnet/MSBuildProject.cjs +0 -84
  76. package/cjs/dotnet/MSBuildProject.cjs.map +0 -1
  77. package/cjs/dotnet/MSBuildProject.d.ts +0 -42
  78. package/cjs/dotnet/MSBuildProject.d.ts.map +0 -1
  79. package/cjs/dotnet/MSBuildProjectProperties.cjs +0 -22
  80. package/cjs/dotnet/MSBuildProjectProperties.cjs.map +0 -1
  81. package/cjs/dotnet/MSBuildProjectProperties.d.ts +0 -13
  82. package/cjs/dotnet/MSBuildProjectProperties.d.ts.map +0 -1
  83. package/cjs/dotnet/createDummyNupkg.cjs +0 -26
  84. package/cjs/dotnet/createDummyNupkg.cjs.map +0 -1
  85. package/cjs/dotnet/createDummyNupkg.d.ts +0 -2
  86. package/cjs/dotnet/createDummyNupkg.d.ts.map +0 -1
  87. package/cjs/dotnet/dotnetGHPR.cjs +0 -173
  88. package/cjs/dotnet/dotnetGHPR.cjs.map +0 -1
  89. package/cjs/dotnet/dotnetGHPR.d.ts +0 -37
  90. package/cjs/dotnet/dotnetGHPR.d.ts.map +0 -1
  91. package/cjs/dotnet/dotnetGLPR.cjs +0 -41
  92. package/cjs/dotnet/dotnetGLPR.cjs.map +0 -1
  93. package/cjs/dotnet/dotnetGLPR.d.ts +0 -13
  94. package/cjs/dotnet/dotnetGLPR.d.ts.map +0 -1
  95. package/cjs/dotnet/dotnetHelpers.cjs +0 -141
  96. package/cjs/dotnet/dotnetHelpers.cjs.map +0 -1
  97. package/cjs/dotnet/dotnetHelpers.d.ts +0 -26
  98. package/cjs/dotnet/dotnetHelpers.d.ts.map +0 -1
  99. package/cjs/dotnet-wrapper.mjs +0 -6
  100. package/cjs/dotnet.cjs +0 -15
  101. package/cjs/dotnet.cjs.map +0 -1
  102. package/cjs/dotnet.d.ts +0 -7
  103. package/cjs/dotnet.d.ts.map +0 -1
  104. package/cjs/envUtils-wrapper.mjs +0 -6
  105. package/cjs/envUtils.cjs +0 -37
  106. package/cjs/envUtils.cjs.map +0 -1
  107. package/cjs/envUtils.d.ts +0 -15
  108. package/cjs/envUtils.d.ts.map +0 -1
  109. package/cjs/eslintConfig-wrapper.mjs +0 -6
  110. package/cjs/eslintConfig.cjs +0 -52
  111. package/cjs/eslintConfig.cjs.map +0 -1
  112. package/cjs/eslintConfig.d.ts +0 -3
  113. package/cjs/eslintConfig.d.ts.map +0 -1
  114. package/cjs/findStaticConfig-wrapper.mjs +0 -6
  115. package/cjs/findStaticConfig.cjs +0 -34
  116. package/cjs/findStaticConfig.cjs.map +0 -1
  117. package/cjs/findStaticConfig.d.ts +0 -2
  118. package/cjs/findStaticConfig.d.ts.map +0 -1
  119. package/cjs/index-wrapper.mjs +0 -6
  120. package/cjs/index.cjs +0 -10
  121. package/cjs/index.cjs.map +0 -1
  122. package/cjs/index.d.ts +0 -5
  123. package/cjs/index.d.ts.map +0 -1
  124. package/cjs/semantic-release__commit-analyzer.d.cjs +0 -2
  125. package/cjs/semantic-release__commit-analyzer.d.cjs.map +0 -1
  126. package/cjs/semantic-release__git.d.cjs +0 -2
  127. package/cjs/semantic-release__git.d.cjs.map +0 -1
  128. package/cjs/semantic-release__github.d.cjs +0 -2
  129. package/cjs/semantic-release__github.d.cjs.map +0 -1
  130. package/cjs/semanticReleaseConfig-wrapper.mjs +0 -6
  131. package/cjs/semanticReleaseConfig.cjs +0 -33
  132. package/cjs/semanticReleaseConfig.cjs.map +0 -1
  133. package/cjs/semanticReleaseConfig.d.ts +0 -4
  134. package/cjs/semanticReleaseConfig.d.ts.map +0 -1
  135. package/cjs/semanticReleaseConfigDotnet-wrapper.mjs +0 -7
  136. package/cjs/semanticReleaseConfigDotnet.cjs +0 -112
  137. package/cjs/semanticReleaseConfigDotnet.cjs.map +0 -1
  138. package/cjs/semanticReleaseConfigDotnet.d.ts +0 -51
  139. package/cjs/semanticReleaseConfigDotnet.d.ts.map +0 -1
  140. package/cjs/setupGitPluginSpec-wrapper.mjs +0 -6
  141. package/cjs/setupGitPluginSpec.cjs +0 -67
  142. package/cjs/setupGitPluginSpec.cjs.map +0 -1
  143. package/cjs/setupGitPluginSpec.d.ts +0 -19
  144. package/cjs/setupGitPluginSpec.d.ts.map +0 -1
  145. package/src/dotnet/createDummyNupkg.ts +0 -30
  146. package/src/dotnet/dotnetGHPR.ts +0 -232
  147. package/src/dotnet/dotnetGLPR.ts +0 -46
  148. package/src/dotnet/dotnetHelpers.ts +0 -184
  149. package/src/dotnet.ts +0 -6
  150. package/src/envUtils.ts +0 -36
  151. package/src/findStaticConfig.ts +0 -31
  152. package/static/.releaserc.yml +0 -35
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@halospv3/hce.shared-config",
3
- "version": "2.6.4",
3
+ "version": "3.0.0-develop.2",
4
4
  "description": "Automate commit message quality, changelogs, and CI/CD releases. Exports a semantic-release shareable configuration deserialized from this package's '.releaserc.yml'. Shared resources for .NET projects are also distributed with this package.",
5
5
  "keywords": [
6
6
  "halo",
@@ -20,124 +20,123 @@
20
20
  "!.husky/",
21
21
  "!.vscode/",
22
22
  "!_tsout/",
23
+ "!dotnet/samples/",
23
24
  "!tests/",
24
25
  "CHANGELOG.md",
25
- "cjs/**/*",
26
26
  "dotnet/**/*",
27
27
  "mjs/**/*",
28
- "src/**/*",
29
- "static/**/*"
28
+ "src/**/*"
30
29
  ],
31
- "main": "./cjs/index.cjs",
30
+ "main": "./mjs/index.mjs",
32
31
  "infra": "polyrepo",
33
- "repository": "github:halospv3/hce.shared",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/HaloSPV3/HCE.Shared.git"
35
+ },
34
36
  "scripts": {
35
37
  "build": "packemon build --addExports --addFiles --declaration --loadConfigs",
38
+ "build:clean": "npm run clean-build",
36
39
  "check": "npm run type && npm run test && npm run lint",
37
40
  "clean": "packemon clean",
38
- "coverage": "npm run test --coverage",
39
- "format": "prettier --write",
41
+ "clean-build": "npm run clean && npm run build",
42
+ "coverage": "npm run test -- --experimental-test-coverage",
40
43
  "lint": "eslint --cache --fix .",
44
+ "lint:check": "eslint --cache .",
41
45
  "eslint-inspector": "eslint --inspect-config",
42
46
  "pack": "packemon pack --addExports --addFiles --declaration --loadConfigs && npm run validate",
43
47
  "prepare": "husky",
44
48
  "presemantic-release": "npm run pack && npm run check",
45
- "semantic-release": "npx semantic-release",
46
- "pretest": "npm run build",
47
- "test": "tsx --test ./tests/**/*.test.ts",
49
+ "semantic-release": "semantic-release",
50
+ "test": "npm run build && npm run test:noBuild",
51
+ "test:cacheSampleProjects": "echo \"START: Cache Sample Projects\" && tsx ./tests/dotnet/MSBuildProject.projects.ts && echo \"DONE: Cache Sample Projects\"",
52
+ "pretest:noBuild": "npm run test:cacheSampleProjects",
53
+ "test:noBuild": "npm run test:justTest",
54
+ "test:justTest": "tsx --test --experimental-test-coverage --enable-source-maps --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=lcov.txt --test-reporter=junit --test-reporter-destination=junit.xml",
55
+ "test:watch": "npm run test:justTest -- -- --watch",
48
56
  "type": "tsc --build",
49
57
  "validate": "packemon validate",
50
- "watch": "packemon watch"
58
+ "watch": "packemon watch --loadConfigs"
51
59
  },
52
60
  "dependencies": {
53
- "@commitlint/cli": "^19.3.0",
54
- "@commitlint/config-conventional": "^19.2.2",
55
- "@commitlint/types": "^19.0.3",
56
- "@eslint/js": "^9.3.0",
61
+ "@commitlint/cli": "^19.8.1",
62
+ "@commitlint/config-conventional": "^19.8.1",
63
+ "@dotenvx/dotenvx": "^1.47.6",
64
+ "@eslint/js": "^9.31.0",
57
65
  "@semantic-release/changelog": "^6.0.3",
58
- "@semantic-release/commit-analyzer": "^13.0.0",
59
- "@semantic-release/exec": "^6.0.3",
66
+ "@semantic-release/commit-analyzer": "^13.0.1",
67
+ "@semantic-release/exec": "^7.1.0",
60
68
  "@semantic-release/git": "^10.0.1",
61
- "@semantic-release/github": "^10.0.4",
62
- "@semantic-release/npm": "^12.0.0",
63
- "@semantic-release/release-notes-generator": "^14.0.0",
64
- "@stylistic/eslint-plugin": "^5.0.0",
65
- "@types/js-yaml": "^4.0.9",
66
- "@types/node": "^20.12.12",
67
- "@types/semantic-release": "^20.0.6",
68
- "conventional-changelog-conventionalcommits": "^8.0.0",
69
- "debug": "^4.3.4",
70
- "eslint-plugin-jsonc": "^2.15.1",
71
- "globals": "^15.3.0",
72
- "husky": "^9.0.11",
73
- "js-yaml": "^4.1.0",
74
- "node-fetch": "^3.3.2",
75
- "semantic-release": "^24.0.0",
76
- "semantic-release-export-data": "^1.0.1",
77
- "typescript-eslint": "^8.35.1"
69
+ "@semantic-release/github": "^11.0.3",
70
+ "@semantic-release/npm": "^12.0.2",
71
+ "@semantic-release/release-notes-generator": "^14.0.3",
72
+ "@stylistic/eslint-plugin": "^5.1.0",
73
+ "@types/node": "~20.11.0",
74
+ "arktype": "^2.1.20",
75
+ "chardet": "^2.1.0",
76
+ "conventional-changelog-conventionalcommits": "^9.1.0",
77
+ "debug": "^4.4.1",
78
+ "eslint-plugin-jsonc": "^2.20.1",
79
+ "globals": "^16.3.0",
80
+ "husky": "^9.1.7",
81
+ "sanitize-filename": "^1.6.3",
82
+ "semantic-release": "^24.2.7",
83
+ "semantic-release-export-data": "^1.1.0",
84
+ "ts-essentials": "^10.1.1",
85
+ "typescript-eslint": "^8.37.0"
78
86
  },
79
87
  "devDependencies": {
80
- "@babel/cli": "^7.24.6",
81
- "@babel/core": "^7.24.6",
82
- "@babel/eslint-parser": "^7.24.6",
83
- "@eslint/eslintrc": "^3.1.0",
84
- "@tsconfig/node-lts": "^20.1.2",
85
- "@types/babel__core": "^7.20.5",
88
+ "@babel/cli": "^7.28.0",
89
+ "@babel/core": "^7.28.0",
90
+ "@babel/eslint-parser": "^7.28.0",
91
+ "@commitlint/types": "^19.8.1",
92
+ "@eslint/config-inspector": "^1.1.0",
93
+ "@eslint/markdown": "^7.0.0",
94
+ "@semantic-release/gitlab": "^13.2.6",
95
+ "@tsconfig/node20": "^20.1.6",
86
96
  "@types/debug": "^4.1.12",
87
97
  "@types/tmp": "^0.2.6",
88
- "ajv": "^8.13.0",
89
- "ajv-draft-04": "^1.0.0",
90
- "dotenv": "^16.4.5",
91
- "eslint": "^9.0.0",
92
- "node-fetch": "^3.3.2",
93
- "packemon": "^4.0.1",
94
- "prettier": "^3.2.5",
95
- "prettier-config-moon": "^1.1.2",
98
+ "conventional-changelog-preset-loader": "^5.0.0",
99
+ "eslint": "^9.31.0",
100
+ "eslint-plugin-jsdoc": "^51.4.0",
101
+ "eslint-plugin-unicorn": "^59.0.1",
102
+ "packemon": "^4.1.2",
96
103
  "tmp": "^0.2.3",
97
- "tslib": "^2.6.2",
98
- "tsx": "^4.10.5",
99
- "typescript": "^5.4.5"
104
+ "tslib": "^2.8.1",
105
+ "tsx": "^4.20.3",
106
+ "typescript": "^5.8.3"
100
107
  },
101
108
  "engines": {
102
- "node": ">=20.8.1",
109
+ "node": "^20.11.0 || >=21.2.0",
103
110
  "npm": ">=10.5.0"
104
111
  },
105
112
  "engineStrict": true,
106
113
  "publishConfig": {
107
- "tag": "latest"
114
+ "tag": "latest",
115
+ "provenance": true
108
116
  },
109
117
  "exports": {
118
+ ".": {
119
+ "types": "./mjs/index.d.ts",
120
+ "import": "./mjs/index.mjs"
121
+ },
110
122
  "./package.json": "./package.json",
111
123
  "./*": {
112
- "types": "./cjs/*.d.ts",
113
- "default": "./cjs/*.cjs"
114
- },
115
- "./dotnet/*": {
116
- "types": "./cjs/dotnet/*.d.ts",
117
- "default": "./cjs/dotnet/*.cjs"
118
- },
119
- ".": {
120
- "types": "./cjs/index.d.ts",
121
- "import": "./cjs/index-wrapper.mjs",
122
- "default": "./cjs/index.cjs"
124
+ "types": "./mjs/*.d.ts",
125
+ "import": "./mjs/*.mjs"
123
126
  }
124
127
  },
125
- "types": "./cjs/index.d.ts",
128
+ "types": "./mjs/index.d.ts",
126
129
  "packemon": {
127
- "format": [
128
- "cjs"
129
- ],
130
130
  "platform": "node",
131
131
  "inputs": {
132
+ "CaseInsensitiveMap": "src/CaseInsensitiveMap.ts",
132
133
  "commitlintConfig": "src/commitlintConfig.ts",
133
- "dotnet": "src/dotnet.ts",
134
134
  "eslintConfig": "src/eslintConfig.ts",
135
- "envUtils": "src/envUtils.ts",
136
- "findStaticConfig": "src/findStaticConfig.ts",
137
135
  "index": "src/index.ts",
138
136
  "semanticReleaseConfig": "src/semanticReleaseConfig.ts",
139
137
  "semanticReleaseConfigDotnet": "src/semanticReleaseConfigDotnet.ts",
140
138
  "setupGitPluginSpec": "src/setupGitPluginSpec.ts"
141
139
  }
142
- }
140
+ },
141
+ "packageManager": "pnpm@10.13.1+sha512.37ebf1a5c7a30d5fabe0c5df44ee8da4c965ca0c5af3dbab28c3a1681b70a256218d05c81c9c0dcf767ef6b8551eb5b960042b9ed4300c59242336377e01cfad"
143
142
  }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * https://stackoverflow.com/a/50022230/14894786
3
+ * licensed under CC BY-SA 4.0
4
+ * changes: add overrides, remove "as any", remove empty lines
5
+ */
6
+ export class CaseInsensitiveMap<T, U> extends Map<T, U> {
7
+ override delete(key: T): boolean {
8
+ if (typeof key === 'string') {
9
+ key = key.toLowerCase() as T;
10
+ }
11
+ return super.delete(key);
12
+ }
13
+
14
+ override get(key: T): U | undefined {
15
+ if (typeof key === 'string') {
16
+ key = key.toLowerCase() as T;
17
+ }
18
+ return super.get(key);
19
+ }
20
+
21
+ override has(key: T): boolean {
22
+ if (typeof key === 'string') {
23
+ key = key.toLowerCase() as T;
24
+ }
25
+ return super.has(key);
26
+ }
27
+
28
+ override set(key: T, value: U): this {
29
+ if (typeof key === 'string') {
30
+ key = key.toLowerCase() as T;
31
+ }
32
+ return super.set(key, value);
33
+ }
34
+ }
@@ -1,14 +1,22 @@
1
- import { type RuleConfigSeverity, type UserConfig } from '@commitlint/types';
1
+ import type { RuleConfigSeverity, UserConfig } from '@commitlint/types';
2
+
3
+ // explicit type annotations for isolatedDeclarations. Allows for faster processing.
2
4
 
3
- // CJS compatibility; This enum cannot be required.
4
5
  const disabled = 0 as RuleConfigSeverity.Disabled;
5
- const commitlintConfig: UserConfig = {
6
- extends: ['@commitlint/config-conventional'],
7
- rules: {
8
- 'body-max-line-length': [disabled],
9
- 'footer-max-line-length': [disabled],
10
- 'header-max-length': [disabled],
11
- },
6
+ const commitlintConfig: UserConfig & {
7
+ extends: UserConfig['extends'] | ['@commitlint/config-conventional'];
8
+ rules: {
9
+ 'body-max-line-length': [typeof disabled];
10
+ 'footer-max-line-length': [typeof disabled];
11
+ 'header-max-length': [typeof disabled];
12
+ };
13
+ } = {
14
+ extends: ['@commitlint/config-conventional'],
15
+ rules: {
16
+ 'body-max-line-length': [disabled],
17
+ 'footer-max-line-length': [disabled],
18
+ 'header-max-length': [disabled],
19
+ },
12
20
  };
13
21
 
14
22
  // only `default` export is loaded via `extends` config key!
package/src/debug.ts CHANGED
@@ -2,8 +2,8 @@ import debug from 'debug';
2
2
 
3
3
  const _debug = debug('@halospv3/hce.shared-config');
4
4
 
5
- if (process.argv.some(v => v.includes('--debug')) || debug.enabled('*')) {
6
- debug.enable(_debug.namespace);
5
+ if (process.argv.some(v => v.includes('--debug')) || debug.enabled('@halospv3/hce.shared-config')) {
6
+ debug.enable(_debug.namespace);
7
7
  }
8
8
 
9
- export default _debug;
9
+ export default _debug;
@@ -0,0 +1,60 @@
1
+ import { getEnvVarValue } from '../utils/env.js';
2
+ import {
3
+ NugetRegistryInfo,
4
+ NRIOptsBase,
5
+ } from './NugetRegistryInfo.js';
6
+
7
+ const NUGET_PKG_GITHUB_COM = 'https://nuget.pkg.github.com';
8
+ const DefaultGithubTokenEnvVars = Object.freeze([
9
+ 'GH_TOKEN',
10
+ 'GITHUB_TOKEN',
11
+ ] as const);
12
+
13
+ export class GithubNugetRegistryInfo extends NugetRegistryInfo {
14
+ static readonly NUGET_PKG_GITHUB_COM = 'https://nuget.pkg.github.com';
15
+ // todo: deduplicate definition
16
+ static readonly DefaultGithubTokenEnvVars = Object.freeze([
17
+ 'GH_TOKEN',
18
+ 'GITHUB_TOKEN',
19
+ ] as const);
20
+
21
+ // GithubNugetRegistryInfo.CtorArgs(...) behaves differently than NugetRegistryInfo.CtorArgs(...)
22
+ /**
23
+ * Creates an instance of GithubNugetRegistryInfo.
24
+ * @param opts The input type of {@link GHNRIOpts.from}
25
+ */
26
+ constructor(opts: typeof GHNRIOpts.inferIn) {
27
+ super(GHNRIOpts.from(opts));
28
+ }
29
+
30
+ /**
31
+ * Returns `https://nuget.pkg.github.com/${GITHUB_REPOSITORY_OWNER}/index.json`
32
+ * or (if GITHUB_REPOSITORY_OWNER is not defined in {@link process.env} nor
33
+ * {@link process.cwd() $CWD}/.env) `undefined`.
34
+ * @returns If GITHUB_REPOSITORY_OWNER is defined, returns the GitHub Package Repository URL endpoint for NuGet pushes (--source).\
35
+ * Otherwise, returns `undefined`
36
+ */
37
+ static getNugetGitHubUrl(): string | undefined {
38
+ const owner = getEnvVarValue('GITHUB_REPOSITORY_OWNER');
39
+ return owner === undefined
40
+ ? undefined
41
+ : `${NUGET_PKG_GITHUB_COM}/${owner}/index.json`;
42
+ }
43
+ }
44
+ const GHNRI = GithubNugetRegistryInfo;
45
+
46
+ /**
47
+ * The default value of {@link GHNRIOpts.t.source `source`} is dependent on
48
+ * {@link GHNRI.getNugetGitHubUrl} and will default to an empty string if the
49
+ * environment variable `GITHUB_REPOSITORY_OWNER` is undefined!
50
+ */
51
+ export const GHNRIOpts = NRIOptsBase.merge({
52
+ /** @see {@link GHNRI.getNugetGitHubUrl } */
53
+ source: NRIOptsBase.get('source')
54
+ .default(() => GHNRI.getNugetGitHubUrl() ?? ''),
55
+ tokenEnvVars: NRIOptsBase.get('tokenEnvVars')
56
+ .default(
57
+ /* must be a function. A fixed-length array is NOT a primitive type! */
58
+ () => DefaultGithubTokenEnvVars,
59
+ ),
60
+ });
@@ -0,0 +1,112 @@
1
+ import { isNativeError } from 'node:util/types';
2
+ import { getEnvVarValue } from '../utils/env.js';
3
+ import {
4
+ NugetRegistryInfo,
5
+ NRIOpts,
6
+ NRIOptsBase,
7
+ } from './NugetRegistryInfo.js';
8
+
9
+ // https://docs.gitlab.com/ee/user/packages/nuget_repository/
10
+ export class GitlabNugetRegistryInfo extends NugetRegistryInfo {
11
+ /**
12
+ * The GitLab API v4 root URL.
13
+ * @returns The value of the environment variable `CI_API_V4_URL`.
14
+ * If that's `undefined`, 'https://gitlab.com/api/v4' is returned, instead.
15
+ */
16
+ static get CI_API_V4_URL() {
17
+ return getEnvVarValue('CI_API_V4_URL') ?? 'https://gitlab.com/api/v4';
18
+ }
19
+
20
+ /**
21
+ * CI_PROJECT_ID - If you want to publish to your GitLab server, this needs to be set to the Id of the project you want to publish to. When running in GitLab CI this is already set to the project the pipeline runs in by GitLab.
22
+ * This method checks the contents of your `.env` file, if present.
23
+ * @returns The value of the environment variable `CI_PROJECT_ID` or `undefined`.
24
+ * @todo add URI encoded project pathname as alternative e.g. 'halospv3%2FHCE.Shared' in 'https://gitlab.com/api/v4/projects/halospv3%2FHCE.Shared'
25
+ */
26
+ static get projectId() {
27
+ return getEnvVarValue('CI_PROJECT_ID');
28
+ }
29
+
30
+ /**
31
+ * CI_PROJECT_NAMESPACE_ID
32
+ * This method checks the contents of your `.env` file, if present.
33
+ * @returns The value of the environment variable 'CI_PROJECT_NAMESPACE_ID' or `undefined`.
34
+ */
35
+ static get ownerId() {
36
+ return getEnvVarValue('CI_PROJECT_NAMESPACE_ID');
37
+ }
38
+
39
+ static readonly DefaultGitlabTokenEnvVars = Object.freeze([
40
+ 'GL_TOKEN',
41
+ 'GITLAB_TOKEN',
42
+ 'CI_JOB_TOKEN',
43
+ ] as const);
44
+
45
+ /**
46
+ * Creates an instance of GitlabNugetRegistryInfo.
47
+ * @param opts The input type of {@link GLNRIOpts.from}
48
+ */
49
+ constructor(opts: typeof GLNRIOpts.inferIn) {
50
+ const optsOut = GLNRIOpts.from(opts);
51
+ if (isNativeError(optsOut.source))
52
+ throw optsOut.source;
53
+ super(optsOut as typeof optsOut & { source: string });
54
+ }
55
+
56
+ /**
57
+ * Get the GitLab Nuget API for your project url as seen in https://docs.gitlab.com/ee/user/packages/nuget_repository/index.html#publish-a-nuget-package-by-using-cicd
58
+ * ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json
59
+ * @returns If {@link this.projectId} is a string, a string formatted like
60
+ * `${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/nuget/index.json`.
61
+ * Else, {@link Error}.
62
+ */
63
+ static get projectUrl(): string | Error {
64
+ return this.projectId
65
+ ? `${this.CI_API_V4_URL}/projects/${this.projectId}/packages/nuget/index.json`
66
+ : new Error('The project-type URL was specified, but one or more of the required environment variables (CI_API_V4_URL, CI_PROJECT_ID) were undefined.');
67
+ }
68
+
69
+ /**
70
+ * ${CI_API_V4_URL}/groups/${CI_PROJECT_NAMESPACE_ID}/-/packages/nuget/index.json
71
+ * @returns If {@link ownerId} is a string, then a string formatted like
72
+ * `${CI_API_V4_URL}/groups/${CI_PROJECT_NAMESPACE_ID}/-/packages/nuget/index.json`.
73
+ * Else, {@link Error}.
74
+ */
75
+ static get groupUrl(): string | Error {
76
+ return this.ownerId
77
+ ? `${this.CI_API_V4_URL}/groups/${this.ownerId}/-/packages/nuget/index.json`
78
+ : new Error('env.CI_PROJECT_NAMESPACE_ID must be defined to use its GitLab API endpoint!');
79
+ }
80
+ }
81
+ const GLNRI = GitlabNugetRegistryInfo;
82
+
83
+ /**
84
+ * The Arktype definition for {@link GitlabNugetRegistryInfo}'s constructor parameter. Construct an object of this type by calling {@link GLNRIOpts.from}
85
+ */
86
+ export const GLNRIOpts = NRIOpts.merge({
87
+ tokenEnvVars: NRIOptsBase.get('tokenEnvVars').default(
88
+ () => GLNRI.DefaultGitlabTokenEnvVars,
89
+ ),
90
+ /**
91
+ * The GitLab Nuget API URL to push packages to -OR- a keyword such as "group"
92
+ * or "project" used to determine URL.
93
+ * @default GLNRI.projectUrl
94
+ * @see {@link GLNRI.projectUrl}, {@link GLNRI.groupUrl}
95
+ */
96
+ // todo: change '"group" | "project"' to '"GITLAB:PROJECT" | "GITLAB:GROUP"'
97
+ source: NRIOptsBase.get('source')
98
+ .or('"group" | "project" | Error')
99
+ .pipe((source: string | Error): string | Error => {
100
+ switch (source) {
101
+ case 'group': {
102
+ return GLNRI.groupUrl;
103
+ }
104
+ case 'project': {
105
+ return GLNRI.projectUrl;
106
+ }
107
+ default: {
108
+ return source;
109
+ }
110
+ }
111
+ }).default(() => GLNRI.projectUrl),
112
+ });
@@ -0,0 +1,44 @@
1
+ import { NugetRegistryInfo, getGithubOutput } from './NugetRegistryInfo.js';
2
+
3
+ const args = process.argv.slice(2);
4
+
5
+ // Parse command-line arguments - https://stackoverflow.com/a/76298476/14894786
6
+ const options: {
7
+ packageId?: string;
8
+ source?: string;
9
+ } & Record<string, string> = {};
10
+ for (let i = 0; i < args.length; i += 2) {
11
+ const argName = args[i];
12
+ const argValue = args[i + 1];
13
+ if (argValue !== undefined && argName?.startsWith('--') === true && options[argName.slice(2)] !== undefined) {
14
+ options[argName.slice(2)] = argValue;
15
+ }
16
+ }
17
+
18
+ if (typeof options.packageId !== 'string')
19
+ throw new Error('packageId must be a string');
20
+ if (typeof options.source !== 'string')
21
+ throw new Error('source must be a string');
22
+
23
+ const packageId = options.packageId,
24
+ source = options.source,
25
+ versionPattern = new RegExp(/\d+\.\d+\.\d+([-+].+)?/);
26
+ const ghOutput = await getGithubOutput() ?? {};
27
+ const matches = versionPattern.exec(ghOutput['new-release-version'] ?? '');
28
+ if (matches === null || matches.length === 0)
29
+ throw new Error(
30
+ 'The variable new-release-version is not present in the GITHUB_OUTPUT env file or its value contains invalid characters.',
31
+ );
32
+
33
+ const nextVersion = matches[0];
34
+ const isPublished = await NugetRegistryInfo.IsNextVersionAlreadyPublished(
35
+ source,
36
+ packageId,
37
+ nextVersion,
38
+ );
39
+
40
+ if (typeof isPublished !== 'boolean')
41
+ throw new Error('isPublished is not a boolean');
42
+ if (isPublished)
43
+ throw new Error(`${packageId}@${nextVersion} already exists at ${source}.`);
44
+ console.log(`OK: ${packageId}@${nextVersion} does NOT yet exist at ${source}. Yay.`);