@elysiajs/openapi 1.3.9 → 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,69 +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
- let targetFile = (overrideOutputPath ? typeof overrideOutputPath === "string" ? overrideOutputPath.startsWith("/") ? overrideOutputPath : (0, import_path.join)(tmpRoot, "dist", overrideOutputPath) : overrideOutputPath(tmpRoot) : void 0) ?? (0, import_path.join)(
82
- tmpRoot,
83
- "dist",
84
- // remove leading like src or something similar
85
- fileName.slice(fileName.indexOf("/") + 1)
86
- );
87
- let existed = (0, import_fs.existsSync)(targetFile);
88
- if (!existed && overrideOutputPath) {
89
- targetFile = (0, import_path.join)(
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
+ }`
77
+ );
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)(
90
85
  tmpRoot,
91
86
  "dist",
92
- // use original file name as-is eg. in monorepo
93
- fileName
94
- );
95
- existed = (0, import_fs.existsSync)(targetFile);
96
- }
97
- if (!existed) {
98
- (0, import_fs.rmSync)((0, import_path.join)(tmpRoot, "tsconfig.json"));
99
- console.warn(
100
- "[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
87
+ // remove leading like src or something similar
88
+ fileName.slice(fileName.indexOf("/") + 1)
101
89
  );
102
- console.warn("Couldn't find generated declaration file");
103
- if ((0, import_fs.existsSync)((0, import_path.join)(tmpRoot, "dist"))) {
104
- const tempFiles = (0, import_fs.readdirSync)((0, import_path.join)(tmpRoot, "dist"), {
105
- recursive: true
106
- }).filter((x) => x.toString().endsWith(".d.ts")).map((x) => `- ${x}`).join("\n");
107
- if (tempFiles) {
108
- console.warn(
109
- "You can override with `overrideOutputPath` with one of the following:"
110
- );
111
- console.warn(tempFiles);
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
+ }
112
116
  }
117
+ return;
113
118
  }
114
- return;
115
119
  }
116
120
  const declaration = (0, import_fs.readFileSync)(targetFile, "utf8");
117
121
  if ((0, import_fs.existsSync)(tmpRoot))
@@ -32,69 +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
- let targetFile = (overrideOutputPath ? typeof overrideOutputPath === "string" ? overrideOutputPath.startsWith("/") ? overrideOutputPath : join(tmpRoot, "dist", overrideOutputPath) : overrideOutputPath(tmpRoot) : void 0) ?? join(
65
- tmpRoot,
66
- "dist",
67
- // remove leading like src or something similar
68
- fileName.slice(fileName.indexOf("/") + 1)
69
- );
70
- let existed = existsSync(targetFile);
71
- if (!existed && overrideOutputPath) {
72
- targetFile = join(
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
+ }`
60
+ );
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(
73
68
  tmpRoot,
74
69
  "dist",
75
- // use original file name as-is eg. in monorepo
76
- fileName
77
- );
78
- existed = existsSync(targetFile);
79
- }
80
- if (!existed) {
81
- rmSync(join(tmpRoot, "tsconfig.json"));
82
- console.warn(
83
- "[@elysiajs/openapi/gen] Failed to generate OpenAPI schema"
70
+ // remove leading like src or something similar
71
+ fileName.slice(fileName.indexOf("/") + 1)
84
72
  );
85
- console.warn("Couldn't find generated declaration file");
86
- if (existsSync(join(tmpRoot, "dist"))) {
87
- const tempFiles = readdirSync(join(tmpRoot, "dist"), {
88
- recursive: true
89
- }).filter((x) => x.toString().endsWith(".d.ts")).map((x) => `- ${x}`).join("\n");
90
- if (tempFiles) {
91
- console.warn(
92
- "You can override with `overrideOutputPath` with one of the following:"
93
- );
94
- console.warn(tempFiles);
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
+ }
95
99
  }
100
+ return;
96
101
  }
97
- return;
98
102
  }
99
103
  const declaration = readFileSync(targetFile, "utf8");
100
104
  if (existsSync(tmpRoot))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elysiajs/openapi",
3
- "version": "1.3.9",
3
+ "version": "1.3.10",
4
4
  "description": "Plugin for Elysia to auto-generate API documentation",
5
5
  "author": {
6
6
  "name": "saltyAom",