declapract-typescript-ehmpathy 0.49.1 → 0.49.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.
@@ -2,6 +2,6 @@
2
2
  "dependencies": {
3
3
  "@aws-sdk/client-account": "@declapract{check.minVersion('3.1042.0')}",
4
4
  "@aws-sdk/client-iam": "@declapract{check.minVersion('3.1042.0')}",
5
- "sdk-environment": "@declapract{check.minVersion('0.1.4')}"
5
+ "sdk-environment": "@declapract{check.minVersion('0.1.5')}"
6
6
  }
7
7
  }
@@ -1,15 +1,46 @@
1
1
  import type { FileCheckFunction, FileFixFunction } from 'declapract';
2
2
 
3
+ /**
4
+ * .what = migrates simple-log-methods to sdk-logs with commit flow
5
+ * .why = sdk-logs with commit flow enables traceability in production logs
6
+ *
7
+ * .note = declapract semantics:
8
+ * - check returns = bad practice detected (file will be flagged)
9
+ * - check throws = bad practice not detected (file will be skipped)
10
+ * - fix returns {} = no changes needed
11
+ */
12
+
3
13
  export const check: FileCheckFunction = (contents) => {
14
+ // detect files that import from simple-log-methods
4
15
  if (contents?.includes("from 'simple-log-methods'")) return;
5
16
  throw new Error('does not match bad practice');
6
17
  };
7
18
 
8
19
  export const fix: FileFixFunction = (contents) => {
20
+ // no contents means no file to fix
9
21
  if (!contents) return {};
10
- return {
11
- contents: contents
12
- .replace(/from 'simple-log-methods'/g, "from 'sdk-logs'")
13
- .replace(/generateLogMethods/g, 'genLogMethods'),
14
- };
22
+
23
+ // step 1: replace package import and method name
24
+ const withSdkLogs = contents
25
+ .replace(/from 'simple-log-methods'/g, "from 'sdk-logs'")
26
+ .replace(/generateLogMethods/g, 'genLogMethods');
27
+
28
+ // step 2: add sdk-environment import if not already present (idempotent)
29
+ const needsEnvImport = !withSdkLogs.includes("from 'sdk-environment'");
30
+ const withEnvImport = needsEnvImport
31
+ ? withSdkLogs.replace(
32
+ /import { genLogMethods } from 'sdk-logs';/g,
33
+ "import { getEnvironment } from 'sdk-environment';\nimport { genLogMethods } from 'sdk-logs';",
34
+ )
35
+ : withSdkLogs;
36
+
37
+ // step 3: flow commit through env (only for no-arg calls)
38
+ const withCommitFlow = withEnvImport.replace(
39
+ /genLogMethods\(\)/g,
40
+ `genLogMethods({
41
+ env: { commit: getEnvironment.static().commit },
42
+ })`,
43
+ );
44
+
45
+ return { contents: withCommitFlow };
15
46
  };
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "dependencies": {
3
+ "sdk-environment": "@declapract{check.minVersion('0.1.5')}",
3
4
  "sdk-logs": "@declapract{check.minVersion('0.9.2')}"
4
5
  }
5
6
  }
@@ -1,3 +1,6 @@
1
+ import { getEnvironment } from 'sdk-environment';
1
2
  import { genLogMethods } from 'sdk-logs';
2
3
 
3
- export const log = genLogMethods();
4
+ export const log = genLogMethods({
5
+ env: { commit: getEnvironment.static().commit },
6
+ });
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.49.1",
5
+ "version": "0.49.2",
6
6
  "license": "MIT",
7
7
  "main": "src/index.js",
8
8
  "repository": "ehmpathy/declapract-typescript-ehmpathy",