@diia-inhouse/genproto 3.2.1 → 3.2.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.
@@ -5,7 +5,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const node_child_process_1 = require("node:child_process");
7
7
  const promises_1 = __importDefault(require("node:fs/promises"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const glob_1 = require("glob");
8
10
  const index_1 = require("./index");
11
+ const reservedWords = new Set([
12
+ 'break',
13
+ 'case',
14
+ 'catch',
15
+ 'class',
16
+ 'const',
17
+ 'continue',
18
+ 'debugger',
19
+ 'default',
20
+ 'delete',
21
+ 'do',
22
+ 'else',
23
+ 'enum',
24
+ 'export',
25
+ 'extends',
26
+ 'false',
27
+ 'finally',
28
+ 'for',
29
+ 'function',
30
+ 'if',
31
+ 'import',
32
+ 'in',
33
+ 'instanceof',
34
+ 'new',
35
+ 'null',
36
+ 'return',
37
+ 'super',
38
+ 'switch',
39
+ 'this',
40
+ 'throw',
41
+ 'true',
42
+ 'try',
43
+ 'typeof',
44
+ 'var',
45
+ 'void',
46
+ 'while',
47
+ 'with',
48
+ 'yield',
49
+ 'let',
50
+ 'static',
51
+ 'implements',
52
+ 'interface',
53
+ 'package',
54
+ 'private',
55
+ 'protected',
56
+ 'public',
57
+ ]);
9
58
  class TsCommandBuilder extends index_1.CommandBuilder {
10
59
  // By default ts plugin should be linked to .bin dir but in case if it doesn't
11
60
  // try to look it up in "standard" locations
@@ -106,7 +155,56 @@ class TsCommandBuilder extends index_1.CommandBuilder {
106
155
  command.push(await this.iPath());
107
156
  return command;
108
157
  }
109
- async postProcess() { }
158
+ async postProcess() {
159
+ const files = await (0, glob_1.glob)(node_path_1.default.join(this.outputDir, '**/*.ts'));
160
+ for (const file of files) {
161
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
162
+ const content = await promises_1.default.readFile(file, 'utf8'); // nosemgrep: eslint.detect-non-literal-fs-filename
163
+ if (!content.includes('export namespace ')) {
164
+ continue;
165
+ }
166
+ const result = this.stripReservedWordTypeAliases(content);
167
+ if (result !== content) {
168
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
169
+ await promises_1.default.writeFile(file, result); // nosemgrep: eslint.detect-non-literal-fs-filename
170
+ }
171
+ }
172
+ }
173
+ stripReservedWordTypeAliases(content) {
174
+ const lines = content.split('\n');
175
+ const output = [];
176
+ let insideNamespace = false;
177
+ let namespaceStartIndex = -1;
178
+ let hasNonReservedMember = false;
179
+ for (const line of lines) {
180
+ if (line.startsWith('export namespace ')) {
181
+ insideNamespace = true;
182
+ namespaceStartIndex = output.length;
183
+ hasNonReservedMember = false;
184
+ output.push(line);
185
+ continue;
186
+ }
187
+ if (insideNamespace && line === '}') {
188
+ insideNamespace = false;
189
+ if (hasNonReservedMember) {
190
+ output.push(line);
191
+ }
192
+ else {
193
+ output.splice(namespaceStartIndex);
194
+ }
195
+ continue;
196
+ }
197
+ if (insideNamespace) {
198
+ const match = line.match(/^\s*export type (\w+) = typeof /);
199
+ if (match && reservedWords.has(match[1])) {
200
+ continue;
201
+ }
202
+ hasNonReservedMember = true;
203
+ }
204
+ output.push(line);
205
+ }
206
+ return output.join('\n');
207
+ }
110
208
  async isFileExists(file) {
111
209
  try {
112
210
  await promises_1.default.access(file, promises_1.default.constants.F_OK);
@@ -1 +1 @@
1
- {"version":3,"file":"tsCommandBuilder.js","sourceRoot":"","sources":["../../src/command/tsCommandBuilder.ts"],"names":[],"mappings":";;;;;AAAA,2DAA6C;AAC7C,gEAAiC;AAEjC,mCAAkD;AAElD,MAAqB,gBAAiB,SAAQ,sBAAc;IACxD,8EAA8E;IAC9E,4CAA4C;IACpC,iBAAiB,GAAG;QACxB,yCAAyC;QACzC,6CAA6C;QAC7C,iFAAiF;KACpF,CAAA;IAED,KAAK,CAAC,wBAAwB;QAC1B,MAAM,eAAe,GAAG,EAAE,CAAA;QAE1B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,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBAEjB,SAAQ;YACZ,CAAC;YAED,IAAI,eAAe,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBAClC,eAAe,GAAG,KAAK,CAAA;gBAEvB,IAAI,oBAAoB,EAAE,CAAC;oBACvB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACrB,CAAC;qBAAM,CAAC;oBACJ,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAA;gBACtC,CAAC;gBAED,SAAQ;YACZ,CAAC;YAED,IAAI,eAAe,EAAE,CAAC;gBAClB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAA;gBAE3D,IAAI,KAAK,IAAI,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBACvC,SAAQ;gBACZ,CAAC;gBAED,oBAAoB,GAAG,IAAI,CAAA;YAC/B,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACrB,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;IAEO,KAAK,CAAC,YAAY,CAAC,IAAY;QACnC,IAAI,CAAC;YACD,MAAM,kBAAE,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;QAC5C,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,KAAK,CAAA;QAChB,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC;CACJ;AA/LD,mCA+LC"}
@@ -4,5 +4,6 @@ export default class TsCommandBuilder extends CommandBuilder {
4
4
  getProtoTsPluginLocation(): Promise<string | undefined>;
5
5
  protocCommand(): Promise<string[]>;
6
6
  postProcess(): Promise<void>;
7
+ private stripReservedWordTypeAliases;
7
8
  private isFileExists;
8
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/genproto",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "description": "JS codegen from proto with imports from @diia-inhouse/types",
5
5
  "bin": {
6
6
  "genproto": "./dist/genproto.js"
@@ -15,6 +15,7 @@
15
15
  "lint-fix": "eslint --fix . && prettier --write .",
16
16
  "lint:lockfile": "lockfile-lint --path package-lock.json --allowed-hosts registry.npmjs.org --validate-https",
17
17
  "prepare": "npm run build",
18
+ "test": "vitest run",
18
19
  "find-circulars": "madge --circular --extensions ts ./"
19
20
  },
20
21
  "engines": {
@@ -22,6 +23,10 @@
22
23
  },
23
24
  "author": "Diia",
24
25
  "license": "SEE LICENSE IN LICENSE.md",
26
+ "files": [
27
+ "dist",
28
+ "src"
29
+ ],
25
30
  "dependencies": {
26
31
  "glob": "11.1.0",
27
32
  "lookpath": "1.2.2",
@@ -40,13 +45,11 @@
40
45
  "madge": "7.0.0",
41
46
  "prettier": "3.3.3",
42
47
  "rimraf": "6.0.1",
43
- "semantic-release": "24.0.0"
48
+ "semantic-release": "24.0.0",
49
+ "vitest": "4.1.1"
44
50
  },
45
51
  "release": {
46
- "extends": "@diia-inhouse/configs/dist/semantic-release/package",
47
- "branches": [
48
- "main"
49
- ]
52
+ "extends": "@diia-inhouse/configs/dist/semantic-release/package"
50
53
  },
51
54
  "commitlint": {
52
55
  "extends": "@diia-inhouse/configs/dist/commitlint"
@@ -1,8 +1,59 @@
1
1
  import { execSync } from 'node:child_process'
2
2
  import fs from 'node:fs/promises'
3
+ import path from 'node:path'
4
+
5
+ import { glob } from 'glob'
3
6
 
4
7
  import { CommandBuilder, Platform } from './index'
5
8
 
9
+ const reservedWords = new Set([
10
+ 'break',
11
+ 'case',
12
+ 'catch',
13
+ 'class',
14
+ 'const',
15
+ 'continue',
16
+ 'debugger',
17
+ 'default',
18
+ 'delete',
19
+ 'do',
20
+ 'else',
21
+ 'enum',
22
+ 'export',
23
+ 'extends',
24
+ 'false',
25
+ 'finally',
26
+ 'for',
27
+ 'function',
28
+ 'if',
29
+ 'import',
30
+ 'in',
31
+ 'instanceof',
32
+ 'new',
33
+ 'null',
34
+ 'return',
35
+ 'super',
36
+ 'switch',
37
+ 'this',
38
+ 'throw',
39
+ 'true',
40
+ 'try',
41
+ 'typeof',
42
+ 'var',
43
+ 'void',
44
+ 'while',
45
+ 'with',
46
+ 'yield',
47
+ 'let',
48
+ 'static',
49
+ 'implements',
50
+ 'interface',
51
+ 'package',
52
+ 'private',
53
+ 'protected',
54
+ 'public',
55
+ ])
56
+
6
57
  export default class TsCommandBuilder extends CommandBuilder {
7
58
  // By default ts plugin should be linked to .bin dir but in case if it doesn't
8
59
  // try to look it up in "standard" locations
@@ -120,7 +171,70 @@ export default class TsCommandBuilder extends CommandBuilder {
120
171
  return command
121
172
  }
122
173
 
123
- async postProcess(): Promise<void> {}
174
+ async postProcess(): Promise<void> {
175
+ const files = await glob(path.join(this.outputDir, '**/*.ts'))
176
+
177
+ for (const file of files) {
178
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
179
+ const content = await fs.readFile(file, 'utf8') // nosemgrep: eslint.detect-non-literal-fs-filename
180
+
181
+ if (!content.includes('export namespace ')) {
182
+ continue
183
+ }
184
+
185
+ const result = this.stripReservedWordTypeAliases(content)
186
+
187
+ if (result !== content) {
188
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
189
+ await fs.writeFile(file, result) // nosemgrep: eslint.detect-non-literal-fs-filename
190
+ }
191
+ }
192
+ }
193
+
194
+ private stripReservedWordTypeAliases(content: string): string {
195
+ const lines = content.split('\n')
196
+ const output: string[] = []
197
+ let insideNamespace = false
198
+ let namespaceStartIndex = -1
199
+ let hasNonReservedMember = false
200
+
201
+ for (const line of lines) {
202
+ if (line.startsWith('export namespace ')) {
203
+ insideNamespace = true
204
+ namespaceStartIndex = output.length
205
+ hasNonReservedMember = false
206
+ output.push(line)
207
+
208
+ continue
209
+ }
210
+
211
+ if (insideNamespace && line === '}') {
212
+ insideNamespace = false
213
+
214
+ if (hasNonReservedMember) {
215
+ output.push(line)
216
+ } else {
217
+ output.splice(namespaceStartIndex)
218
+ }
219
+
220
+ continue
221
+ }
222
+
223
+ if (insideNamespace) {
224
+ const match = line.match(/^\s*export type (\w+) = typeof /)
225
+
226
+ if (match && reservedWords.has(match[1])) {
227
+ continue
228
+ }
229
+
230
+ hasNonReservedMember = true
231
+ }
232
+
233
+ output.push(line)
234
+ }
235
+
236
+ return output.join('\n')
237
+ }
124
238
 
125
239
  private async isFileExists(file: string): Promise<boolean> {
126
240
  try {
@@ -1,13 +0,0 @@
1
- on:
2
- workflow_dispatch:
3
- inputs:
4
- pr_number:
5
- description: Number of accepted PR
6
- required: true
7
-
8
- jobs:
9
- accept-contribution:
10
- with:
11
- pr_number: ${{ inputs.pr_number }}
12
- uses: diia-open-source/reusable-workflows/.github/workflows/accept-contribution-be.yml@main
13
- secrets: inherit
package/.gitlab-ci.yml DELETED
@@ -1,10 +0,0 @@
1
- include:
2
- project: diia-inhouse/ci
3
- ref: main
4
- file: main/package.gitlab-ci.yaml
5
-
6
- variables:
7
- LINT_COMMIT: 'true'
8
- NODE_PACKAGE_MANAGER: 'npm'
9
- CHART_NAME: genproto
10
- OSS_PUBLISH_ENABLED: 'true'
package/.prettierignore DELETED
@@ -1 +0,0 @@
1
- dist
package/CONTRIBUTING.md DELETED
@@ -1,34 +0,0 @@
1
- # Contributing to the Diia project
2
-
3
- We're pleased that you're interested in contributing to the Diia project. At the moment we're welcoming contributions in various forms and we want to make contributing as easy and transparent as possible. You're welcome to contribute in any of the following ways:
4
-
5
- - Reporting a bug
6
- - Discussing the current state of the code
7
- - Proposing new features or ideas
8
-
9
- In the future we'll be considering welcoming code contributions and expanding our contributor community.
10
-
11
- ## Report using Issues
12
-
13
- We use GitHub issues to track public bugs. Report a bug, feature, idea or open a discussion point by [opening a new issue](../../issues/new); it's that easy!
14
-
15
- For bugs related to vulnerabilities or security concerns please feel free to contact us directly at [modt.opensource@thedigital.gov.ua](mailto:modt.opensource@thedigital.gov.ua).
16
-
17
- We'd also request that you detail bug reports with detail, background and sample code. Typically a great bug report includes:
18
-
19
- - A quick summary and/or background
20
- - Steps to reproduce
21
- - Be specific and provide sample code if you can.
22
- - What you expected would happen
23
- - What actually happens
24
- - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)
25
-
26
- For ideas, suggestions and discussion you're free to use any format that you find suitable.
27
-
28
- ## Licensing
29
-
30
- By contributing, you agree that your contributions will be licensed under the EUPL.
31
-
32
- You may obtain a copy of the License at [https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12](https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12).
33
-
34
- Questions regarding the Diia project, the License and any re-use should be directed to [modt.opensource@thedigital.gov.ua](mailto:modt.opensource@thedigital.gov.ua).
package/eslint.config.mjs DELETED
@@ -1,18 +0,0 @@
1
- import diiaConfig from '@diia-inhouse/eslint-config'
2
-
3
- /** @type {import('eslint').Linter.Config} */
4
- export default [
5
- ...diiaConfig,
6
- {
7
- ignores: ['*.js', '*.mjs', 'node_modules', 'dist', 'coverage', 'migrate-mongo-config.ts', 'src/generated/**'],
8
- },
9
- {
10
- languageOptions: {
11
- parserOptions: {
12
- project: ['./tsconfig.json', './tests/tsconfig.json'],
13
- ecmaVersion: 2022,
14
- sourceType: 'module',
15
- },
16
- },
17
- },
18
- ]
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "@diia-inhouse/configs/tsconfig",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "declaration": true,
6
- "declarationDir": "dist/types",
7
- "baseUrl": ".",
8
- "strict": true
9
- },
10
- "include": ["src/genproto.ts"],
11
- "exclude": ["node_modules"]
12
- }
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "@diia-inhouse/configs/tsconfig",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "declaration": true,
6
- "declarationDir": "dist/types",
7
- "baseUrl": ".",
8
- "strict": true
9
- },
10
- "include": ["src/genproto.ts"],
11
- "exclude": ["node_modules"]
12
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "@diia-inhouse/configs/tsconfig",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "declaration": true,
6
- "declarationDir": "dist/types",
7
- "baseUrl": ".",
8
- "noUnusedLocals": false,
9
- "noUnusedParameters": false,
10
- "strict": true
11
- },
12
- "include": ["src/genproto.ts"],
13
- "exclude": ["node_modules"]
14
- }