@elysiajs/openapi 1.3.8 → 1.3.10

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.
@@ -49,54 +49,73 @@ var fromTypes = (targetFilePath, {
49
49
  throw new Error(
50
50
  `Couldn't find "${targetFilePath}" from ${projectRoot}`
51
51
  );
52
- if ((0, import_fs.existsSync)(tmpRoot))
53
- (0, import_fs.rmSync)(tmpRoot, { recursive: true, force: true });
54
- (0, import_fs.mkdirSync)(tmpRoot, { recursive: true });
55
- const tsconfig = tsconfigPath.startsWith("/") ? tsconfigPath : (0, import_path.join)(projectRoot, tsconfigPath);
56
- const extendsRef = (0, import_fs.existsSync)(tsconfig) ? `"extends": "${(0, import_path.join)(projectRoot, "tsconfig.json")}",` : "";
57
- (0, import_fs.writeFileSync)(
58
- (0, import_path.join)(tmpRoot, "tsconfig.json"),
59
- `{
60
- ${extendsRef}
61
- "compilerOptions": {
62
- "lib": ["ESNext"],
63
- "module": "ESNext",
64
- "noEmit": false,
65
- "declaration": true,
66
- "emitDeclarationOnly": true,
67
- "moduleResolution": "bundler",
68
- "skipLibCheck": true,
69
- "skipDefaultLibCheck": true,
70
- "outDir": "./dist"
71
- },
72
- "include": ["${src}"]
73
- }`
74
- );
75
- (0, import_child_process.spawnSync)(`tsc`, {
76
- shell: true,
77
- cwd: tmpRoot,
78
- stdio: debug ? "inherit" : void 0
79
- });
80
- const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
81
- const targetFile = (overrideOutputPath ? typeof overrideOutputPath === "string" ? overrideOutputPath.startsWith("/") ? overrideOutputPath : (0, import_path.join)(tmpRoot, "dist", overrideOutputPath) : overrideOutputPath(tmpRoot) : void 0) ?? (0, import_path.join)(tmpRoot, "dist", fileName);
82
- if (!(0, import_fs.existsSync)(targetFile)) {
83
- (0, import_fs.rmSync)((0, import_path.join)(tmpRoot, "tsconfig.json"));
84
- console.warn(
85
- "[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
52
+ let targetFile;
53
+ if (targetFilePath.endsWith(".d.ts")) targetFile = targetFilePath;
54
+ else {
55
+ if ((0, import_fs.existsSync)(tmpRoot))
56
+ (0, import_fs.rmSync)(tmpRoot, { recursive: true, force: true });
57
+ (0, import_fs.mkdirSync)(tmpRoot, { recursive: true });
58
+ const tsconfig = tsconfigPath.startsWith("/") ? tsconfigPath : (0, import_path.join)(projectRoot, tsconfigPath);
59
+ const extendsRef = (0, import_fs.existsSync)(tsconfig) ? `"extends": "${(0, import_path.join)(projectRoot, "tsconfig.json")}",` : "";
60
+ (0, import_fs.writeFileSync)(
61
+ (0, import_path.join)(tmpRoot, "tsconfig.json"),
62
+ `{
63
+ ${extendsRef}
64
+ "compilerOptions": {
65
+ "lib": ["ESNext"],
66
+ "module": "ESNext",
67
+ "noEmit": false,
68
+ "declaration": true,
69
+ "emitDeclarationOnly": true,
70
+ "moduleResolution": "bundler",
71
+ "skipLibCheck": true,
72
+ "skipDefaultLibCheck": true,
73
+ "outDir": "./dist"
74
+ },
75
+ "include": ["${src}"]
76
+ }`
86
77
  );
87
- console.warn("Couldn't find generated declaration file");
88
- if ((0, import_fs.existsSync)((0, import_path.join)(tmpRoot, "dist"))) {
89
- const tempFiles = (0, import_fs.readdirSync)((0, import_path.join)(tmpRoot, "dist"), {
90
- recursive: true
91
- }).filter((x) => x.toString().endsWith(".d.ts")).map((x) => `- ${x}`).join("\n");
92
- if (tempFiles) {
93
- console.warn(
94
- "You can override with `overrideOutputPath` with one of the following:"
95
- );
96
- console.warn(tempFiles);
78
+ (0, import_child_process.spawnSync)(`tsc`, {
79
+ shell: true,
80
+ cwd: tmpRoot,
81
+ stdio: debug ? "inherit" : void 0
82
+ });
83
+ const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
84
+ targetFile = (overrideOutputPath ? typeof overrideOutputPath === "string" ? overrideOutputPath.startsWith("/") ? overrideOutputPath : (0, import_path.join)(tmpRoot, "dist", overrideOutputPath) : overrideOutputPath(tmpRoot) : void 0) ?? (0, import_path.join)(
85
+ tmpRoot,
86
+ "dist",
87
+ // remove leading like src or something similar
88
+ fileName.slice(fileName.indexOf("/") + 1)
89
+ );
90
+ let existed = (0, import_fs.existsSync)(targetFile);
91
+ if (!existed && !overrideOutputPath) {
92
+ targetFile = (0, import_path.join)(
93
+ tmpRoot,
94
+ "dist",
95
+ // use original file name as-is eg. in monorepo
96
+ fileName
97
+ );
98
+ existed = (0, import_fs.existsSync)(targetFile);
99
+ }
100
+ if (!existed) {
101
+ (0, import_fs.rmSync)((0, import_path.join)(tmpRoot, "tsconfig.json"));
102
+ console.warn(
103
+ "[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
104
+ );
105
+ console.warn("Couldn't find generated declaration file");
106
+ if ((0, import_fs.existsSync)((0, import_path.join)(tmpRoot, "dist"))) {
107
+ const tempFiles = (0, import_fs.readdirSync)((0, import_path.join)(tmpRoot, "dist"), {
108
+ recursive: true
109
+ }).filter((x) => x.toString().endsWith(".d.ts")).map((x) => `- ${x}`).join("\n");
110
+ if (tempFiles) {
111
+ console.warn(
112
+ "You can override with `overrideOutputPath` with one of the following:"
113
+ );
114
+ console.warn(tempFiles);
115
+ }
97
116
  }
117
+ return;
98
118
  }
99
- return;
100
119
  }
101
120
  const declaration = (0, import_fs.readFileSync)(targetFile, "utf8");
102
121
  if ((0, import_fs.existsSync)(tmpRoot))
@@ -32,54 +32,73 @@ var fromTypes = (targetFilePath, {
32
32
  throw new Error(
33
33
  `Couldn't find "${targetFilePath}" from ${projectRoot}`
34
34
  );
35
- if (existsSync(tmpRoot))
36
- rmSync(tmpRoot, { recursive: true, force: true });
37
- mkdirSync(tmpRoot, { recursive: true });
38
- const tsconfig = tsconfigPath.startsWith("/") ? tsconfigPath : join(projectRoot, tsconfigPath);
39
- const extendsRef = existsSync(tsconfig) ? `"extends": "${join(projectRoot, "tsconfig.json")}",` : "";
40
- writeFileSync(
41
- join(tmpRoot, "tsconfig.json"),
42
- `{
43
- ${extendsRef}
44
- "compilerOptions": {
45
- "lib": ["ESNext"],
46
- "module": "ESNext",
47
- "noEmit": false,
48
- "declaration": true,
49
- "emitDeclarationOnly": true,
50
- "moduleResolution": "bundler",
51
- "skipLibCheck": true,
52
- "skipDefaultLibCheck": true,
53
- "outDir": "./dist"
54
- },
55
- "include": ["${src}"]
56
- }`
57
- );
58
- spawnSync(`tsc`, {
59
- shell: true,
60
- cwd: tmpRoot,
61
- stdio: debug ? "inherit" : void 0
62
- });
63
- const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
64
- const targetFile = (overrideOutputPath ? typeof overrideOutputPath === "string" ? overrideOutputPath.startsWith("/") ? overrideOutputPath : join(tmpRoot, "dist", overrideOutputPath) : overrideOutputPath(tmpRoot) : void 0) ?? join(tmpRoot, "dist", fileName);
65
- if (!existsSync(targetFile)) {
66
- rmSync(join(tmpRoot, "tsconfig.json"));
67
- console.warn(
68
- "[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
35
+ let targetFile;
36
+ if (targetFilePath.endsWith(".d.ts")) targetFile = targetFilePath;
37
+ else {
38
+ if (existsSync(tmpRoot))
39
+ rmSync(tmpRoot, { recursive: true, force: true });
40
+ mkdirSync(tmpRoot, { recursive: true });
41
+ const tsconfig = tsconfigPath.startsWith("/") ? tsconfigPath : join(projectRoot, tsconfigPath);
42
+ const extendsRef = existsSync(tsconfig) ? `"extends": "${join(projectRoot, "tsconfig.json")}",` : "";
43
+ writeFileSync(
44
+ join(tmpRoot, "tsconfig.json"),
45
+ `{
46
+ ${extendsRef}
47
+ "compilerOptions": {
48
+ "lib": ["ESNext"],
49
+ "module": "ESNext",
50
+ "noEmit": false,
51
+ "declaration": true,
52
+ "emitDeclarationOnly": true,
53
+ "moduleResolution": "bundler",
54
+ "skipLibCheck": true,
55
+ "skipDefaultLibCheck": true,
56
+ "outDir": "./dist"
57
+ },
58
+ "include": ["${src}"]
59
+ }`
69
60
  );
70
- console.warn("Couldn't find generated declaration file");
71
- if (existsSync(join(tmpRoot, "dist"))) {
72
- const tempFiles = readdirSync(join(tmpRoot, "dist"), {
73
- recursive: true
74
- }).filter((x) => x.toString().endsWith(".d.ts")).map((x) => `- ${x}`).join("\n");
75
- if (tempFiles) {
76
- console.warn(
77
- "You can override with `overrideOutputPath` with one of the following:"
78
- );
79
- console.warn(tempFiles);
61
+ spawnSync(`tsc`, {
62
+ shell: true,
63
+ cwd: tmpRoot,
64
+ stdio: debug ? "inherit" : void 0
65
+ });
66
+ const fileName = targetFilePath.replace(/.tsx$/, ".ts").replace(/.ts$/, ".d.ts");
67
+ targetFile = (overrideOutputPath ? typeof overrideOutputPath === "string" ? overrideOutputPath.startsWith("/") ? overrideOutputPath : join(tmpRoot, "dist", overrideOutputPath) : overrideOutputPath(tmpRoot) : void 0) ?? join(
68
+ tmpRoot,
69
+ "dist",
70
+ // remove leading like src or something similar
71
+ fileName.slice(fileName.indexOf("/") + 1)
72
+ );
73
+ let existed = existsSync(targetFile);
74
+ if (!existed && !overrideOutputPath) {
75
+ targetFile = join(
76
+ tmpRoot,
77
+ "dist",
78
+ // use original file name as-is eg. in monorepo
79
+ fileName
80
+ );
81
+ existed = existsSync(targetFile);
82
+ }
83
+ if (!existed) {
84
+ rmSync(join(tmpRoot, "tsconfig.json"));
85
+ console.warn(
86
+ "[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
87
+ );
88
+ console.warn("Couldn't find generated declaration file");
89
+ if (existsSync(join(tmpRoot, "dist"))) {
90
+ const tempFiles = readdirSync(join(tmpRoot, "dist"), {
91
+ recursive: true
92
+ }).filter((x) => x.toString().endsWith(".d.ts")).map((x) => `- ${x}`).join("\n");
93
+ if (tempFiles) {
94
+ console.warn(
95
+ "You can override with `overrideOutputPath` with one of the following:"
96
+ );
97
+ console.warn(tempFiles);
98
+ }
80
99
  }
100
+ return;
81
101
  }
82
- return;
83
102
  }
84
103
  const declaration = readFileSync(targetFile, "utf8");
85
104
  if (existsSync(tmpRoot))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/openapi",
3
- "version": "1.3.8",
3
+ "version": "1.3.10",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",