Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/tasty-ducks-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@mincho-js/css-additional-types": patch
"@mincho-js/transform-to-vanilla": patch
"vite-config-custom": patch
"@mincho-js/integration": patch
"@mincho-js/debug-log": patch
"@mincho-js/esbuild": patch
"@mincho-js/babel": patch
"@mincho-js/react": patch
"@mincho-js/vite": patch
"@mincho-js/css": patch
---

**package**
- Achieve all [Are the types wrong](https://github.com/arethetypeswrong/arethetypeswrong.github.io) using [vite-plugin-dts-build's dual mode](https://github.com/black7375/vite-plugin-dts-build#dual-module-support).
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ build/Release
node_modules/
jspm_packages/

# Package Redirect - Sync with package.json "workspaces"
configs/*/**/package.json
packages/*/**/package.json
examples/*/**/package.json

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

Expand Down Expand Up @@ -90,6 +95,7 @@ out
# Nuxt.js build / generate output
.nuxt
dist
dist-ssr

# Gatsby files
.cache/
Expand Down
96 changes: 3 additions & 93 deletions configs/vite-config-custom/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// @ts-check

import { readdir, readFile, writeFile, unlink } from "node:fs/promises";
import { resolve, join } from "node:path";
import { cwd, env } from "node:process";

import { PromisePool } from "@supercharge/promise-pool";
import { initConfigBuilder, ViteEnv, PluginBuilder } from "vite-config-builder";
import { mergeConfig } from "vite";

import { ModuleKind, ModuleResolutionKind } from "typescript";
import { externalizeDeps } from "vite-plugin-externalize-deps";
import tsconfigPaths from "vite-tsconfig-paths";
import { dts } from "vite-plugin-dts-build";
import { dtsForEsm, dtsForCjs } from "vite-plugin-dts-build";

// == Main Configs ============================================================
export function NodeConfig(viteConfigEnv, extendConfigs = {}) {
Expand All @@ -33,48 +30,24 @@ function NodeBuilder(viteConfigEnv) {
const packageRoot = cwd();
const entryRoot = resolve(packageRoot, "src");
const entryFile = resolve(entryRoot, "index.ts");
const cacheEsmDir = resolve(packageRoot, ".cache", "typescript", "esm");
const cacheCjsDir = resolve(packageRoot, ".cache", "typescript", "cjs");
const outEsmDir = resolve(packageRoot, "dist", "esm");
const outCjsDir = resolve(packageRoot, "dist", "cjs");

const runtimeEnv = getRuntimeEnv();
if (ViteEnv.isProd()) {
if (runtimeEnv === "LOCAL" || runtimeEnv === "PUBLISH") {
plugins.add(
// This is currently a proprietary implementation. You might also like to see
// https://github.com/qmhc/vite-plugin-dts/issues/267
dts({
dtsForEsm({
include: ["src"],
cacheDir: cacheEsmDir,
outDir: outEsmDir,
tsconfigPath: resolve(packageRoot, "tsconfig.lib.json")
})
);
}
if (runtimeEnv === "PUBLISH") {
plugins.add(
dts({
dtsForCjs({
include: ["src"],
cacheDir: cacheCjsDir,
outDir: outCjsDir,
tsconfigPath: resolve(packageRoot, "tsconfig.lib.json"),
compilerOptions: {
module: ModuleKind.CommonJS,
moduleResolution: ModuleResolutionKind.Node10,
outDir: outCjsDir,
declarationDir: outCjsDir,
tsBuildInfoFile: resolve(
packageRoot,
".cache",
"typescript",
"tsbuildinfo-cjs"
)
},
afterBuild: async () => {
// Rename the CommonJS declaration file to .d.cts
await renameDeclarationFiles(outCjsDir);
}
})
);
}
Expand Down Expand Up @@ -171,69 +144,6 @@ function initCommonBuilder(viteConfigEnv) {
};
}

async function renameDeclarationFiles(dir) {
try {
const allFiles = await collectDeclarationFiles(dir);

if (allFiles.length === 0) {
return;
}
console.log(`Processing ${allFiles.length} declaration files...`);

const { errors } = await PromisePool.for(allFiles)
.withConcurrency(10)
.process(processCtsFile);

if (errors.length > 0) {
console.error(`${errors.length} files failed to process`);
}
} catch (error) {
console.error(`Error processing: ${error.message}`);
}
}

async function collectDeclarationFiles(dir, fileList = []) {
try {
const fileOrDirs = await readdir(dir, { withFileTypes: true });
const subDirectories = [];

for (const fileOrDir of fileOrDirs) {
const fullPath = join(dir, fileOrDir.name);

if (fileOrDir.isDirectory()) {
subDirectories.push(fullPath);
} else if (fileOrDir.name.endsWith(".d.ts")) {
fileList.push(fullPath);
}
}

if (subDirectories.length > 0) {
await PromisePool.for(subDirectories)
.withConcurrency(8)
.process(async (subDir) => {
await collectDeclarationFiles(subDir, fileList);
});
}

return fileList;
} catch (error) {
console.error(`Error reading directory ${dir}: ${error.message}`);
return fileList;
}
}

async function processCtsFile(fullPath) {
// Change import paths from .js to .cjs
const content = await readFile(fullPath, "utf8");
const importRegex = /from ['"](.+)\.js['"];?$/gm;
const modifiedContent = content.replace(importRegex, "from '$1.cjs'");

// Change file extension from .d.ts to .d.cts
const newPath = fullPath.replace(".d.ts", ".d.cts");
await writeFile(newPath, modifiedContent, "utf8");
await unlink(fullPath);
}

function getRuntimeEnv() {
if (env["PACKAGE_PUBLISH"] === "true") {
return "PUBLISH";
Expand Down
3 changes: 1 addition & 2 deletions configs/vite-config-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
"devDependencies": {
"prettier-config-custom": "workspace:^",
"vite-config-builder": "^0.0.2",
"vite-plugin-dts-build": "^0.1.3",
"vite-plugin-dts-build": "^0.2.2",
"vite-plugin-externalize-deps": "^0.9.0",
"vite-tsconfig-paths": "^5.1.4"
},
"dependencies": {
"@supercharge/promise-pool": "^3.2.0",
"typescript": "^5.8.3",
"vite": "^6.3.5"
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"task": "yarn turbo run --cache-dir .cache/turbo",
"clean": "yarn g:clean && yarn task clean",
"build": "yarn task build",
"build:full": "PACKAGE_PUBLISH=true yarn task build",
"build:type": "yarn tsc --build",
"lint": "yarn lint:action & yarn task lint",
"lint:action": "yarn run -T eslint '.github/**/*.{js,yaml,yml}' --cache --cache-location .cache/eslint_action",
Expand Down
3 changes: 2 additions & 1 deletion packages/babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
},
"files": [
"dist",
"src"
"src",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
3 changes: 2 additions & 1 deletion packages/css-additional-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
},
"files": [
"README.md",
"dist/"
"dist/",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
3 changes: 2 additions & 1 deletion packages/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
},
"files": [
"README.md",
"dist/"
"dist/",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
3 changes: 2 additions & 1 deletion packages/debug-log/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"files": [
"README.md",
"importMeta.d.ts",
"dist/"
"dist/",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
3 changes: 2 additions & 1 deletion packages/esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
},
"files": [
"dist",
"src"
"src",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
3 changes: 2 additions & 1 deletion packages/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
},
"files": [
"dist",
"src"
"src",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
3 changes: 2 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
},
"files": [
"dist",
"src"
"src",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
3 changes: 2 additions & 1 deletion packages/transform-to-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
},
"files": [
"README.md",
"dist/"
"dist/",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
},
"files": [
"dist",
"src"
"src",
"**/package.json"
],
"scripts": {
"clean": "yarn g:clean",
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6659,12 +6659,11 @@ __metadata:
version: 0.0.0-use.local
resolution: "vite-config-custom@workspace:configs/vite-config-custom"
dependencies:
"@supercharge/promise-pool": "npm:^3.2.0"
prettier-config-custom: "workspace:^"
typescript: "npm:^5.8.3"
vite: "npm:^6.3.5"
vite-config-builder: "npm:^0.0.2"
vite-plugin-dts-build: "npm:^0.1.3"
vite-plugin-dts-build: "npm:^0.2.2"
vite-plugin-externalize-deps: "npm:^0.9.0"
vite-tsconfig-paths: "npm:^5.1.4"
languageName: unknown
Expand All @@ -6685,15 +6684,16 @@ __metadata:
languageName: node
linkType: hard

"vite-plugin-dts-build@npm:^0.1.3":
version: 0.1.3
resolution: "vite-plugin-dts-build@npm:0.1.3"
"vite-plugin-dts-build@npm:^0.2.2":
version: 0.2.2
resolution: "vite-plugin-dts-build@npm:0.2.2"
dependencies:
"@supercharge/promise-pool": "npm:^3.2.0"
fs-extra: "npm:^11.3.0"
peerDependencies:
typescript: "*"
vite: "*"
checksum: 10/42ad0e051541a71b4f5e6a992b6abc246c39e15970ef48f4b7c241e3d2034fa65d29fde705e2d7de3f814818bcc50713040c1e38dc65d4c4792be2aa1fad1d79
checksum: 10/04028d7bd8fad724ff9a276da685cb2cf7cf008b3b75e8e02e5deaccb70e53e316c9ea1d498d86a1ec71ec575805dfee500021278430ffd58270ac8746148a9c
languageName: node
linkType: hard

Expand Down