declapract-typescript-ehmpathy 0.47.53 → 0.47.55

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.
@@ -1,6 +1,6 @@
1
- import fs from 'fs';
1
+ import fs from 'node:fs';
2
2
  import os from 'os';
3
- import path from 'path';
3
+ import path from 'node:path';
4
4
 
5
5
  /**
6
6
  * .what = creates a mock context with apikeys config in a temp directory
@@ -1,6 +1,7 @@
1
1
  import { FileCheckType, type FileFixFunction } from 'declapract';
2
- import { readFileSync } from 'fs';
3
- import { dirname, join } from 'path';
2
+
3
+ import { readFileSync } from 'node:fs';
4
+ import { dirname, join } from 'node:path';
4
5
 
5
6
  // check that the file contains the core structure
6
7
  export const check = FileCheckType.CONTAINS;
@@ -10,8 +10,24 @@ export const fix: FileFixFunction = (contents, context) => {
10
10
  .replace(/\/domain\/objects\//g, '/domain.objects/')
11
11
  .replace(/\/domain\//g, '/domain.objects/');
12
12
 
13
+ // fix internal export paths in index files
14
+ // when domain/index.ts moves to domain.objects/index.ts,
15
+ // exports like './objects/User' should become './User'
16
+ let fixedContents = contents;
17
+ if (fixedContents && context.relativeFilePath.includes('/domain/index.ts')) {
18
+ fixedContents = fixedContents
19
+ // export * from './objects' → remove (objects dir flattened to root)
20
+ .replace(/export\s+\*\s+from\s+['"]\.\/objects['"];?\n?/g, '')
21
+ // ./objects/Foo → ./Foo
22
+ .replace(/(['"])\.\/objects\//g, '$1./')
23
+ // ../domain/objects/Foo → ../domain.objects/Foo (for cross-references)
24
+ .replace(/(['"])([^'"]*?)\/domain\/objects\//g, '$1$2/domain.objects/')
25
+ // ../domain/Foo → ../domain.objects/Foo
26
+ .replace(/(['"])([^'"]*?)\/domain\//g, '$1$2/domain.objects/');
27
+ }
28
+
13
29
  return {
14
- contents: contents ?? null,
30
+ contents: fixedContents ?? null,
15
31
  relativeFilePath: newPath,
16
32
  };
17
33
  };
@@ -11,6 +11,7 @@ const OLD_PATH_PATTERNS = [
11
11
  /from\s+['"][^'"]*\/model\/domainObjects/,
12
12
  /from\s+['"][^'"]*\/model\//,
13
13
  /from\s+['"][^'"]*\/services\//,
14
+ /from\s+['"][^'"]*\/__nonpublished_modules__\//,
14
15
  ];
15
16
 
16
17
  export const check: FileCheckFunction = (contents) => {
@@ -43,7 +44,12 @@ export const fix: FileFixFunction = (contents) => {
43
44
  .replace(/(['"])([^'"]*?)\/model\/domainObjects\b/g, '$1$2/domain.objects')
44
45
  .replace(/(['"])([^'"]*?)\/model\//g, '$1$2/domain.objects/')
45
46
  // services layer fixes (services = business logic, not service clients)
46
- .replace(/(['"])([^'"]*?)\/services\//g, '$1$2/domain.operations/');
47
+ .replace(/(['"])([^'"]*?)\/services\//g, '$1$2/domain.operations/')
48
+ // nonpublished modules dir fix
49
+ .replace(
50
+ /(['"])([^'"]*?)\/__nonpublished_modules__\//g,
51
+ '$1$2/_topublish/',
52
+ );
47
53
 
48
54
  return { contents: fixed };
49
55
  };
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs/promises';
2
- import path from 'path';
2
+ import path from 'node:path';
3
3
 
4
4
  import { executeApply } from 'declapract';
5
5
  import { genTempDir, given, then, useThen, when } from 'test-fns';
@@ -1,8 +1,9 @@
1
- import { existsSync, readFileSync } from 'fs';
2
- import { join } from 'path';
3
- import util from 'util';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import util from 'node:util';
4
+
5
+ import { jest } from '@jest/globals';
4
6
 
5
- // eslint-disable-next-line no-undef
6
7
  jest.setTimeout(90000); // we're calling downstream apis
7
8
 
8
9
  // set console.log to not truncate nested objects
@@ -1,9 +1,10 @@
1
- import { execSync } from 'child_process';
2
- import { existsSync, readFileSync } from 'fs';
3
- import { join } from 'path';
4
- import util from 'util';
1
+ import { execSync } from 'node:child_process';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import util from 'node:util';
5
+
6
+ import { jest } from '@jest/globals';
5
7
 
6
- // eslint-disable-next-line no-undef
7
8
  jest.setTimeout(90000); // since we're calling downstream apis
8
9
 
9
10
  // set console.log to not truncate nested objects
@@ -1,6 +1,8 @@
1
- import { existsSync } from 'fs';
2
- import { join } from 'path';
3
- import util from 'util';
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import util from 'node:util';
4
+
5
+ import { jest } from '@jest/globals';
4
6
 
5
7
  // mock that getConfig just returns plaintext test env config in unit tests
6
8
  jest.mock('./src/utils/config/getConfig', () => ({
@@ -0,0 +1,39 @@
1
+ import type { FileCheckFunction, FileFixFunction } from 'declapract';
2
+
3
+ /**
4
+ * .what = detects and fixes uuidv4 imports to use uuid-fns instead
5
+ * .why = uuidv4 package is deprecated, uuid-fns provides same functionality with different export name
6
+ */
7
+
8
+ // pattern to detect uuidv4 imports
9
+ const UUIDV4_IMPORT_PATTERN = /from\s+['"]uuidv4['"]/;
10
+
11
+ export const check: FileCheckFunction = (contents) => {
12
+ if (!contents) throw new Error('no contents');
13
+
14
+ // check if file imports from uuidv4
15
+ if (UUIDV4_IMPORT_PATTERN.test(contents)) return; // matches bad practice
16
+
17
+ throw new Error('does not match bad practice');
18
+ };
19
+
20
+ export const fix: FileFixFunction = (contents) => {
21
+ if (!contents) return { contents };
22
+
23
+ // replace uuidv4 import with uuid-fns, alias getUuid as uuid to minimize code changes
24
+ const fixed = contents
25
+ // handle: import { uuid } from 'uuidv4' → import { getUuid as uuid } from 'uuid-fns'
26
+ .replace(
27
+ /import\s*\{\s*uuid\s*\}\s*from\s*['"]uuidv4['"]/g,
28
+ "import { getUuid as uuid } from 'uuid-fns'",
29
+ )
30
+ // handle: import { uuid as X } from 'uuidv4' → import { getUuid as X } from 'uuid-fns'
31
+ .replace(
32
+ /import\s*\{\s*uuid\s+as\s+(\w+)\s*\}\s*from\s*['"]uuidv4['"]/g,
33
+ "import { getUuid as $1 } from 'uuid-fns'",
34
+ )
35
+ // handle other uuidv4 imports (e.g., default import)
36
+ .replace(/from\s*['"]uuidv4['"]/g, "from 'uuid-fns'");
37
+
38
+ return { contents: fixed };
39
+ };
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import util from 'util';
1
+ import fs from 'node:fs';
2
+ import util from 'node:util';
3
3
 
4
4
  export const readFile = async (filePath: string): Promise<string> =>
5
5
  util.promisify(fs.readFile)(filePath, 'utf-8');
@@ -1,6 +1,6 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import util from 'util';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import util from 'node:util';
4
4
 
5
5
  /**
6
6
  * .what = configuration structure for use.apikeys.json
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "declapract-typescript-ehmpathy",
3
3
  "author": "ehmpathy",
4
4
  "description": "declapract best practices declarations for typescript",
5
- "version": "0.47.53",
5
+ "version": "0.47.55",
6
6
  "license": "MIT",
7
7
  "main": "src/index.js",
8
8
  "repository": "ehmpathy/declapract-typescript-ehmpathy",