|
2 | 2 |
|
3 | 3 | import { readdirSync, renameSync } from "node:fs"; |
4 | 4 | import { resolve, join } from "node:path"; |
5 | | -import { cwd } from "node:process"; |
| 5 | +import { cwd, env } from "node:process"; |
6 | 6 |
|
7 | 7 | import { initConfigBuilder, ViteEnv, PluginBuilder } from "vite-config-builder"; |
8 | 8 | import { mergeConfig } from "vite"; |
@@ -35,46 +35,49 @@ function NodeBuilder(viteConfigEnv) { |
35 | 35 | const outEsmDir = resolve(packageRoot, "dist", "esm"); |
36 | 36 | const outCjsDir = resolve(packageRoot, "dist", "cjs"); |
37 | 37 |
|
| 38 | + const isCI = isGithubCI(); |
38 | 39 | if (ViteEnv.isProd()) { |
39 | | - plugins.add( |
40 | | - // This is currently a proprietary implementation. You might also like to see |
41 | | - // https://github.com/qmhc/vite-plugin-dts/issues/267 |
42 | | - dts({ |
43 | | - entryRoot, |
44 | | - include: ["src"], |
45 | | - outDir: outEsmDir, |
46 | | - tsconfigPath: resolve(packageRoot, "tsconfig.lib.json") |
47 | | - }), |
48 | | - dts({ |
49 | | - entryRoot, |
50 | | - include: ["src"], |
51 | | - outDir: outCjsDir, |
52 | | - tsconfigPath: resolve(packageRoot, "tsconfig.lib.json"), |
53 | | - compilerOptions: { |
54 | | - module: ModuleKind.CommonJS, |
| 40 | + if (!isCI) { |
| 41 | + plugins.add( |
| 42 | + // This is currently a proprietary implementation. You might also like to see |
| 43 | + // https://github.com/qmhc/vite-plugin-dts/issues/267 |
| 44 | + dts({ |
| 45 | + entryRoot, |
| 46 | + include: ["src"], |
| 47 | + outDir: outEsmDir, |
| 48 | + tsconfigPath: resolve(packageRoot, "tsconfig.lib.json") |
| 49 | + }), |
| 50 | + dts({ |
| 51 | + entryRoot, |
| 52 | + include: ["src"], |
55 | 53 | outDir: outCjsDir, |
56 | | - declarationDir: outCjsDir, |
57 | | - tsBuildInfoFile: resolve( |
58 | | - packageRoot, |
59 | | - ".cache", |
60 | | - "typescript", |
61 | | - "tsbuildinfo-cjs" |
62 | | - ) |
63 | | - }, |
64 | | - afterBuild: () => { |
65 | | - // Rename the CommonJS declaration file to .d.cts |
66 | | - readdirSync(outCjsDir).forEach((file) => { |
67 | | - if (file.endsWith(".d.ts")) { |
68 | | - renameSync( |
69 | | - join(outCjsDir, file), |
70 | | - join(outCjsDir, file.replace(".d.ts", ".d.cts")) |
71 | | - ); |
72 | | - } |
73 | | - }); |
74 | | - } |
75 | | - }), |
76 | | - externalizeDeps() |
77 | | - ); |
| 54 | + tsconfigPath: resolve(packageRoot, "tsconfig.lib.json"), |
| 55 | + compilerOptions: { |
| 56 | + module: ModuleKind.CommonJS, |
| 57 | + outDir: outCjsDir, |
| 58 | + declarationDir: outCjsDir, |
| 59 | + tsBuildInfoFile: resolve( |
| 60 | + packageRoot, |
| 61 | + ".cache", |
| 62 | + "typescript", |
| 63 | + "tsbuildinfo-cjs" |
| 64 | + ) |
| 65 | + }, |
| 66 | + afterBuild: () => { |
| 67 | + // Rename the CommonJS declaration file to .d.cts |
| 68 | + readdirSync(outCjsDir).forEach((file) => { |
| 69 | + if (file.endsWith(".d.ts")) { |
| 70 | + renameSync( |
| 71 | + join(outCjsDir, file), |
| 72 | + join(outCjsDir, file.replace(".d.ts", ".d.cts")) |
| 73 | + ); |
| 74 | + } |
| 75 | + }); |
| 76 | + } |
| 77 | + }) |
| 78 | + ); |
| 79 | + } |
| 80 | + plugins.add(externalizeDeps()); |
78 | 81 | } |
79 | 82 |
|
80 | 83 | if (ViteEnv.isTest()) { |
@@ -113,7 +116,7 @@ function NodeBuilder(viteConfigEnv) { |
113 | 116 | entry: { |
114 | 117 | index: entryFile |
115 | 118 | }, |
116 | | - formats: ["es", "cjs"], |
| 119 | + formats: isCI ? ["es"] : ["es", "cjs"], |
117 | 120 | fileName: (format, entryName) => |
118 | 121 | `${format === "es" ? "esm" : "cjs"}/${entryName}.${format === "es" ? "mjs" : "cjs"}` |
119 | 122 | }, |
@@ -166,3 +169,14 @@ function initCommonBuilder(viteConfigEnv) { |
166 | 169 | plugins |
167 | 170 | }; |
168 | 171 | } |
| 172 | + |
| 173 | +function isGithubCI() { |
| 174 | + if (env["PACKAGE_PUBLISH"] === "true") { |
| 175 | + return false; |
| 176 | + } |
| 177 | + |
| 178 | + if (env["GITHUB_ACTIONS"] === "true") { |
| 179 | + return true; |
| 180 | + } |
| 181 | + return false; |
| 182 | +} |
0 commit comments