@ddd-ts/freeze 0.0.43 → 0.0.45

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.
@@ -9,10 +9,46 @@ node_fs = require_runtime.__toESM(node_fs);
9
9
 
10
10
  //#region src/entrypoints/freeze-decorator.entrypoint.ts
11
11
  const cwd = process.cwd();
12
- const decoratorFile = require_project.project.getSourceFile(`${__dirname}/../references/freeze.decorator.d.ts`);
13
- if (!decoratorFile) throw new Error("The @Freeze decorator is not used in the project.");
14
- const references = decoratorFile.getFunction("Freeze")?.findReferences();
15
- if (!references) throw new Error("The @Freeze decorator is imported, but not used in the project.");
12
+ const resolveFromDistIndex = () => {
13
+ const decoratorFilePath = `${__dirname}/../../dist/index.d.ts`;
14
+ const decoratorFile = require_project.project.getSourceFile(decoratorFilePath);
15
+ if (!decoratorFile) throw new Error(`Cannot find index.d.ts at path ${decoratorFilePath}`);
16
+ const decoratorFunction = decoratorFile.getExportedDeclarations().get("Freeze")?.[0].asKind(ts_morph.ts.SyntaxKind.FunctionDeclaration);
17
+ if (!decoratorFunction) throw new Error(`Cannot find function for Freeze decorator in ${decoratorFilePath}`);
18
+ const references = decoratorFunction.findReferences();
19
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
20
+ return references;
21
+ };
22
+ const resolveFromDist = () => {
23
+ const decoratorFilePath = `${__dirname}/../references/freeze.decorator.d.ts`;
24
+ const decoratorFile = require_project.project.getSourceFile(decoratorFilePath);
25
+ if (!decoratorFile) throw new Error(`Cannot find freeze.decorator.d.ts at path ${decoratorFilePath}`);
26
+ const references = decoratorFile.getFunction("Freeze")?.findReferences();
27
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
28
+ return references;
29
+ };
30
+ const resolveFromSource = () => {
31
+ const decoratorFilePath = `${__dirname}/../references/freeze.decorator.ts`;
32
+ const decoratorFile = require_project.project.getSourceFile(decoratorFilePath);
33
+ if (!decoratorFile) throw new Error(`Cannot find freeze.decorator.ts at path ${decoratorFilePath}`);
34
+ const references = decoratorFile.getFunction("Freeze")?.findReferences();
35
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
36
+ return references;
37
+ };
38
+ let references;
39
+ try {
40
+ references = resolveFromDistIndex();
41
+ } catch (e) {
42
+ try {
43
+ references = resolveFromDist();
44
+ } catch (e) {
45
+ try {
46
+ references = resolveFromSource();
47
+ } catch (e) {
48
+ throw new Error("Cannot find declaration of the Freeze decorator in dist/index.d.ts, dist/references/freeze.decorator.d.ts or src/references/freeze.decorator.ts");
49
+ }
50
+ }
51
+ }
16
52
  function lowercasefirstletter(str) {
17
53
  return str.charAt(0).toLowerCase() + str.slice(1);
18
54
  }
@@ -7,10 +7,46 @@ import fs from "node:fs";
7
7
 
8
8
  //#region src/entrypoints/freeze-decorator.entrypoint.ts
9
9
  const cwd = process.cwd();
10
- const decoratorFile = project.getSourceFile(`${__dirname}/../references/freeze.decorator.d.ts`);
11
- if (!decoratorFile) throw new Error("The @Freeze decorator is not used in the project.");
12
- const references = decoratorFile.getFunction("Freeze")?.findReferences();
13
- if (!references) throw new Error("The @Freeze decorator is imported, but not used in the project.");
10
+ const resolveFromDistIndex = () => {
11
+ const decoratorFilePath = `${__dirname}/../../dist/index.d.ts`;
12
+ const decoratorFile = project.getSourceFile(decoratorFilePath);
13
+ if (!decoratorFile) throw new Error(`Cannot find index.d.ts at path ${decoratorFilePath}`);
14
+ const decoratorFunction = decoratorFile.getExportedDeclarations().get("Freeze")?.[0].asKind(ts.SyntaxKind.FunctionDeclaration);
15
+ if (!decoratorFunction) throw new Error(`Cannot find function for Freeze decorator in ${decoratorFilePath}`);
16
+ const references = decoratorFunction.findReferences();
17
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
18
+ return references;
19
+ };
20
+ const resolveFromDist = () => {
21
+ const decoratorFilePath = `${__dirname}/../references/freeze.decorator.d.ts`;
22
+ const decoratorFile = project.getSourceFile(decoratorFilePath);
23
+ if (!decoratorFile) throw new Error(`Cannot find freeze.decorator.d.ts at path ${decoratorFilePath}`);
24
+ const references = decoratorFile.getFunction("Freeze")?.findReferences();
25
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
26
+ return references;
27
+ };
28
+ const resolveFromSource = () => {
29
+ const decoratorFilePath = `${__dirname}/../references/freeze.decorator.ts`;
30
+ const decoratorFile = project.getSourceFile(decoratorFilePath);
31
+ if (!decoratorFile) throw new Error(`Cannot find freeze.decorator.ts at path ${decoratorFilePath}`);
32
+ const references = decoratorFile.getFunction("Freeze")?.findReferences();
33
+ if (!references) throw new Error("Cannot find declaration of the Freeze decorator");
34
+ return references;
35
+ };
36
+ let references;
37
+ try {
38
+ references = resolveFromDistIndex();
39
+ } catch (e) {
40
+ try {
41
+ references = resolveFromDist();
42
+ } catch (e) {
43
+ try {
44
+ references = resolveFromSource();
45
+ } catch (e) {
46
+ throw new Error("Cannot find declaration of the Freeze decorator in dist/index.d.ts, dist/references/freeze.decorator.d.ts or src/references/freeze.decorator.ts");
47
+ }
48
+ }
49
+ }
14
50
  function lowercasefirstletter(str) {
15
51
  return str.charAt(0).toLowerCase() + str.slice(1);
16
52
  }
@@ -7,13 +7,51 @@ let ts_morph = require("ts-morph");
7
7
  let node_path = require("node:path");
8
8
  let node_fs = require("node:fs");
9
9
  node_fs = require_runtime.__toESM(node_fs);
10
+ let _prettier_sync = require("@prettier/sync");
11
+ _prettier_sync = require_runtime.__toESM(_prettier_sync);
10
12
 
11
13
  //#region src/entrypoints/freeze-function.entrypoint.ts
12
14
  const cwd = process.cwd();
13
- const functionFile = require_project.project.getSourceFile(`${__dirname}/../references/freeze.function.d.ts`);
14
- if (!functionFile) throw new Error("The freeze function is not used in the project.");
15
- const references = functionFile.getFunction("freeze")?.findReferences();
16
- if (!references) throw new Error("The freeze function is imported, but not used in the project.");
15
+ const resolveFromDistIndex = () => {
16
+ const functionFilePath = `${__dirname}/../../dist/index.d.ts`;
17
+ const functionFile = require_project.project.getSourceFile(functionFilePath);
18
+ if (!functionFile) throw new Error(`Cannot find index.d.ts at path ${functionFilePath}`);
19
+ const freezeFunction = functionFile.getExportedDeclarations().get("freeze")?.[0].asKind(ts_morph.ts.SyntaxKind.FunctionDeclaration);
20
+ if (!freezeFunction) throw new Error(`Cannot find function for freeze in ${functionFilePath}`);
21
+ const references = freezeFunction.findReferences();
22
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
23
+ return references;
24
+ };
25
+ const resolveFromSource = () => {
26
+ const functionFilePath = `${__dirname}/../references/freeze.function.ts`;
27
+ const functionFile = require_project.project.getSourceFile(functionFilePath);
28
+ if (!functionFile) throw new Error(`Cannot find freeze.function.ts at path ${functionFilePath}`);
29
+ const references = functionFile.getFunction("freeze")?.findReferences();
30
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
31
+ return references;
32
+ };
33
+ const resolveFromDist = () => {
34
+ const functionFilePath = `${__dirname}/../references/freeze.function.d.ts`;
35
+ const functionFile = require_project.project.getSourceFile(functionFilePath);
36
+ if (!functionFile) throw new Error(`Cannot find freeze.function.d.ts at path ${functionFilePath}`);
37
+ const references = functionFile.getFunction("freeze")?.findReferences();
38
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
39
+ return references;
40
+ };
41
+ let references;
42
+ try {
43
+ references = resolveFromDistIndex();
44
+ } catch {
45
+ try {
46
+ references = resolveFromDist();
47
+ } catch {
48
+ try {
49
+ references = resolveFromSource();
50
+ } catch {
51
+ throw new Error("Cannot find references for freeze function in dist/index.d.ts, dist/references/freeze.function.d.ts or src/references/freeze.function.ts");
52
+ }
53
+ }
54
+ }
17
55
  function lowercasefirstletter(str) {
18
56
  return str.charAt(0).toLowerCase() + str.slice(1);
19
57
  }
@@ -73,7 +111,8 @@ for (const ref of references) for (const refref of ref.getReferences()) {
73
111
  ...other.values(),
74
112
  `export type ${serializedName} = ${result}`
75
113
  ].join("\n");
76
- node_fs.default.writeFileSync(`${directory.getPath()}/${serializedFilename}.ts`, output);
114
+ const formattedOutput = _prettier_sync.default.format(output, { parser: "typescript" });
115
+ node_fs.default.writeFileSync(`${directory.getPath()}/${serializedFilename}.ts`, formattedOutput);
77
116
  console.log(`${rpath} - ${name$1}: Frozen as ${serializedName} in ${serializedFilename}.ts`);
78
117
  }
79
118
 
@@ -5,13 +5,50 @@ import { getPrettyType } from "../utils/get-pretty-type.mjs";
5
5
  import { ts } from "ts-morph";
6
6
  import { relative } from "node:path";
7
7
  import fs from "node:fs";
8
+ import prettier from "@prettier/sync";
8
9
 
9
10
  //#region src/entrypoints/freeze-function.entrypoint.ts
10
11
  const cwd = process.cwd();
11
- const functionFile = project.getSourceFile(`${__dirname}/../references/freeze.function.d.ts`);
12
- if (!functionFile) throw new Error("The freeze function is not used in the project.");
13
- const references = functionFile.getFunction("freeze")?.findReferences();
14
- if (!references) throw new Error("The freeze function is imported, but not used in the project.");
12
+ const resolveFromDistIndex = () => {
13
+ const functionFilePath = `${__dirname}/../../dist/index.d.ts`;
14
+ const functionFile = project.getSourceFile(functionFilePath);
15
+ if (!functionFile) throw new Error(`Cannot find index.d.ts at path ${functionFilePath}`);
16
+ const freezeFunction = functionFile.getExportedDeclarations().get("freeze")?.[0].asKind(ts.SyntaxKind.FunctionDeclaration);
17
+ if (!freezeFunction) throw new Error(`Cannot find function for freeze in ${functionFilePath}`);
18
+ const references = freezeFunction.findReferences();
19
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
20
+ return references;
21
+ };
22
+ const resolveFromSource = () => {
23
+ const functionFilePath = `${__dirname}/../references/freeze.function.ts`;
24
+ const functionFile = project.getSourceFile(functionFilePath);
25
+ if (!functionFile) throw new Error(`Cannot find freeze.function.ts at path ${functionFilePath}`);
26
+ const references = functionFile.getFunction("freeze")?.findReferences();
27
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
28
+ return references;
29
+ };
30
+ const resolveFromDist = () => {
31
+ const functionFilePath = `${__dirname}/../references/freeze.function.d.ts`;
32
+ const functionFile = project.getSourceFile(functionFilePath);
33
+ if (!functionFile) throw new Error(`Cannot find freeze.function.d.ts at path ${functionFilePath}`);
34
+ const references = functionFile.getFunction("freeze")?.findReferences();
35
+ if (!references) throw new Error("Cannot find declaration of the freeze function");
36
+ return references;
37
+ };
38
+ let references;
39
+ try {
40
+ references = resolveFromDistIndex();
41
+ } catch {
42
+ try {
43
+ references = resolveFromDist();
44
+ } catch {
45
+ try {
46
+ references = resolveFromSource();
47
+ } catch {
48
+ throw new Error("Cannot find references for freeze function in dist/index.d.ts, dist/references/freeze.function.d.ts or src/references/freeze.function.ts");
49
+ }
50
+ }
51
+ }
15
52
  function lowercasefirstletter(str) {
16
53
  return str.charAt(0).toLowerCase() + str.slice(1);
17
54
  }
@@ -71,7 +108,8 @@ for (const ref of references) for (const refref of ref.getReferences()) {
71
108
  ...other.values(),
72
109
  `export type ${serializedName} = ${result}`
73
110
  ].join("\n");
74
- fs.writeFileSync(`${directory.getPath()}/${serializedFilename}.ts`, output);
111
+ const formattedOutput = prettier.format(output, { parser: "typescript" });
112
+ fs.writeFileSync(`${directory.getPath()}/${serializedFilename}.ts`, formattedOutput);
75
113
  console.log(`${rpath} - ${name$1}: Frozen as ${serializedName} in ${serializedFilename}.ts`);
76
114
  }
77
115
 
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env -S node -r @swc-node/register
1
2
  import './freeze-decorator.entrypoint';
2
3
  import './freeze-function.entrypoint';
3
4
  //# sourceMappingURL=freeze.entrypoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"freeze.entrypoint.d.ts","sourceRoot":"","sources":["../../src/entrypoints/freeze.entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,+BAA+B,CAAC;AACvC,OAAO,8BAA8B,CAAC"}
1
+ {"version":3,"file":"freeze.entrypoint.d.ts","sourceRoot":"","sources":["../../src/entrypoints/freeze.entrypoint.ts"],"names":[],"mappings":";AACA,OAAO,+BAA+B,CAAC;AACvC,OAAO,8BAA8B,CAAC"}
@@ -1,2 +1,3 @@
1
+ #!/usr/bin/env -S node -r @swc-node/register
1
2
  require('./freeze-decorator.entrypoint.js');
2
3
  require('./freeze-function.entrypoint.js');
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env -S node -r @swc-node/register
1
2
  import "./freeze-decorator.entrypoint.mjs";
2
3
  import "./freeze-function.entrypoint.mjs";
3
4
 
@@ -63,6 +63,7 @@ function exploreNativeType(type, checker, declarations = /* @__PURE__ */ new Map
63
63
  }, "")}}`;
64
64
  }
65
65
  if (type.flags & typescript.TypeFlags.TypeParameter) return type.symbol.name;
66
+ if (type.flags & typescript.TypeFlags.Unknown) return "unknown";
66
67
  return JSON.stringify({
67
68
  name: checker.typeToString(type),
68
69
  flags: listTypeFlagsNames(type.flags)
@@ -61,6 +61,7 @@ function exploreNativeType(type, checker, declarations = /* @__PURE__ */ new Map
61
61
  }, "")}}`;
62
62
  }
63
63
  if (type.flags & ts.TypeFlags.TypeParameter) return type.symbol.name;
64
+ if (type.flags & ts.TypeFlags.Unknown) return "unknown";
64
65
  return JSON.stringify({
65
66
  name: checker.typeToString(type),
66
67
  flags: listTypeFlagsNames(type.flags)
@@ -1 +1 @@
1
- {"version":3,"file":"get-pretty-type.d.ts","sourceRoot":"","sources":["../../src/utils/get-pretty-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAe,IAAI,EAAE,MAAM,UAAU,CAAC;AAEzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,GAAG;IAC5D,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,oBAAoB,CAAC;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CA+BA"}
1
+ {"version":3,"file":"get-pretty-type.d.ts","sourceRoot":"","sources":["../../src/utils/get-pretty-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAe,IAAI,EAAE,MAAM,UAAU,CAAC;AAEzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,GAAG;IAC5D,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,oBAAoB,CAAC;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAmCA"}
@@ -4,12 +4,16 @@ let ts_morph = require("ts-morph");
4
4
  //#region src/utils/get-pretty-type.ts
5
5
  function getPrettyType(type, contextNode) {
6
6
  const project = contextNode.getProject();
7
- const typeTextForEmbedding = project.getTypeChecker().compilerObject.typeToString(type.compilerType, contextNode.compilerNode, ts_morph.ts.TypeFormatFlags.NoTruncation | ts_morph.ts.TypeFormatFlags.UseFullyQualifiedType | ts_morph.ts.TypeFormatFlags.InTypeAlias);
7
+ const typeTextForEmbedding = project.getTypeChecker().compilerObject.typeToString(type.compilerType, void 0, ts_morph.ts.TypeFormatFlags.NoTruncation | ts_morph.ts.TypeFormatFlags.UseFullyQualifiedType | ts_morph.ts.TypeFormatFlags.InTypeAlias);
8
8
  const fileName = `__pretty_${Date.now()}_${Math.random().toString(16).slice(2)}.ts`;
9
9
  const sf = project.createSourceFile(fileName, `
10
- type Pretty<T> = { [K in keyof T]: T[K] } & {};
10
+ type DeepPretty<T> = T extends object
11
+ ? T extends Function
12
+ ? T
13
+ : { [K in keyof T]: DeepPretty<T[K]> } & {}
14
+ : T;
11
15
  declare const __v: ${typeTextForEmbedding};
12
- export type __X = Pretty<typeof __v>;
16
+ export type __X = DeepPretty<typeof __v>;
13
17
  `, { overwrite: true });
14
18
  const alias = sf.getTypeAliasOrThrow("__X");
15
19
  const pretty = alias.getType();
@@ -3,12 +3,16 @@ import { Project, ts } from "ts-morph";
3
3
  //#region src/utils/get-pretty-type.ts
4
4
  function getPrettyType(type, contextNode) {
5
5
  const project = contextNode.getProject();
6
- const typeTextForEmbedding = project.getTypeChecker().compilerObject.typeToString(type.compilerType, contextNode.compilerNode, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseFullyQualifiedType | ts.TypeFormatFlags.InTypeAlias);
6
+ const typeTextForEmbedding = project.getTypeChecker().compilerObject.typeToString(type.compilerType, void 0, ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseFullyQualifiedType | ts.TypeFormatFlags.InTypeAlias);
7
7
  const fileName = `__pretty_${Date.now()}_${Math.random().toString(16).slice(2)}.ts`;
8
8
  const sf = project.createSourceFile(fileName, `
9
- type Pretty<T> = { [K in keyof T]: T[K] } & {};
9
+ type DeepPretty<T> = T extends object
10
+ ? T extends Function
11
+ ? T
12
+ : { [K in keyof T]: DeepPretty<T[K]> } & {}
13
+ : T;
10
14
  declare const __v: ${typeTextForEmbedding};
11
- export type __X = Pretty<typeof __v>;
15
+ export type __X = DeepPretty<typeof __v>;
12
16
  `, { overwrite: true });
13
17
  const alias = sf.getTypeAliasOrThrow("__X");
14
18
  const pretty = alias.getType();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts/freeze",
3
- "version": "0.0.43",
3
+ "version": "0.0.45",
4
4
  "types": "dist/index.d.ts",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,15 +17,17 @@
17
17
  "typescript": "^5.5.4"
18
18
  },
19
19
  "dependencies": {
20
- "@ddd-ts/core": "0.0.43",
21
- "@ddd-ts/shape": "0.0.43",
22
- "@ddd-ts/traits": "0.0.43",
23
- "@ddd-ts/types": "0.0.43"
20
+ "@ddd-ts/core": "0.0.45",
21
+ "@ddd-ts/shape": "0.0.45",
22
+ "@ddd-ts/traits": "0.0.45",
23
+ "@ddd-ts/types": "0.0.45",
24
+ "@prettier/sync": "^0.6.1",
25
+ "prettier": "^3.8.1"
24
26
  },
25
27
  "devDependencies": {
26
- "@ddd-ts/tools": "0.0.43",
28
+ "@ddd-ts/tools": "0.0.45",
27
29
  "@types/jest": "^29.5.1",
28
- "@types/node": "^17.0.13"
30
+ "@types/node": "^22.14.1"
29
31
  },
30
32
  "exports": {
31
33
  ".": {