Skip to content

Commit 58881db

Browse files
committed
Chore: Internal resolution error at node16 packages
1 parent 20246a1 commit 58881db

File tree

36 files changed

+201
-93
lines changed

36 files changed

+201
-93
lines changed

.changeset/bitter-hornets-beg.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
"prettier-config-custom": minor
3+
"@mincho-js/css-additional-types": minor
4+
"@mincho-js/transform-to-vanilla": minor
5+
"eslint-config-custom": minor
6+
"vite-config-custom": minor
7+
"tsconfig-custom": minor
8+
"react-babel": minor
9+
"@mincho-js/integration": minor
10+
"react-swc": minor
11+
"@mincho-js/debug-log": minor
12+
"@mincho-js/esbuild": minor
13+
"@mincho-js/babel": minor
14+
"@mincho-js/react": minor
15+
"@mincho-js/vite": minor
16+
"@mincho-js/css": minor
17+
---
18+
19+
**Big Changes**
20+
- co-location: [@sangkukbae](https://github.com/sangkukbae)'s work, It's still experimental.
21+
- packages: `node16` supports

configs/tsconfig-custom/tsconfig.base.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
2424
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
2525
"useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
26-
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26+
"moduleDetection": "force", /* Control what method is used to detect module-format JS files. */
2727

2828
/* Modules */
29-
"module": "ESNext", /* Specify what module code is generated. */
29+
"module": "NodeNext", /* Specify what module code is generated. */
3030
// "rootDir": ".", /* Specify the root folder within your source files. */
31-
"moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
31+
"moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */
3232
"baseUrl": ".", /* Specify the base directory to resolve non-relative module names. */
3333
"paths": { /* Specify a set of entries that re-map imports to additional lookup locations. */
3434
"@/*": ["src/*"]
@@ -42,7 +42,14 @@
4242
],
4343
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
4444
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
45+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
46+
"rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
47+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
48+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
49+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
50+
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
4551
"resolveJsonModule": true, /* Enable importing .json files. */
52+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4653
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
4754

4855
/* JavaScript Support */
@@ -77,6 +84,9 @@
7784

7885
/* Interop Constraints */
7986
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
87+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
88+
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
89+
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
8090
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
8191
// "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
8292
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
@@ -89,6 +99,7 @@
8999
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
90100
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
91101
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
102+
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
92103
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
93104
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
94105
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
@@ -105,6 +116,6 @@
105116

106117
/* Completeness */
107118
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
108-
"skipLibCheck": true
119+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
109120
}
110121
}

configs/vite-config-custom/index.js

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// @ts-check
22

3-
import { readdirSync, renameSync } from "node:fs";
3+
import { readdir, readFile, writeFile, unlink } from "node:fs/promises";
44
import { resolve, join } from "node:path";
55
import { cwd, env } from "node:process";
66

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

@@ -63,16 +64,9 @@ function NodeBuilder(viteConfigEnv) {
6364
"tsbuildinfo-cjs"
6465
)
6566
},
66-
afterBuild: () => {
67+
afterBuild: async () => {
6768
// 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-
});
69+
await renameDeclarationFiles(outCjsDir);
7670
}
7771
})
7872
);
@@ -170,6 +164,69 @@ function initCommonBuilder(viteConfigEnv) {
170164
};
171165
}
172166

167+
async function renameDeclarationFiles(dir) {
168+
try {
169+
const allFiles = await collectDeclarationFiles(dir);
170+
171+
if (allFiles.length === 0) {
172+
return;
173+
}
174+
console.log(`Processing ${allFiles.length} declaration files...`);
175+
176+
const { errors } = await PromisePool.for(allFiles)
177+
.withConcurrency(10)
178+
.process(processCtsFile);
179+
180+
if (errors.length > 0) {
181+
console.error(`${errors.length} files failed to process`);
182+
}
183+
} catch (error) {
184+
console.error(`Error processing: ${error.message}`);
185+
}
186+
}
187+
188+
async function collectDeclarationFiles(dir, fileList = []) {
189+
try {
190+
const fileOrDirs = await readdir(dir, { withFileTypes: true });
191+
const subDirectories = [];
192+
193+
for (const fileOrDir of fileOrDirs) {
194+
const fullPath = join(dir, fileOrDir.name);
195+
196+
if (fileOrDir.isDirectory()) {
197+
subDirectories.push(fullPath);
198+
} else if (fileOrDir.name.endsWith(".d.ts")) {
199+
fileList.push(fullPath);
200+
}
201+
}
202+
203+
if (subDirectories.length > 0) {
204+
await PromisePool.for(subDirectories)
205+
.withConcurrency(8)
206+
.process(async (subDir) => {
207+
await collectDeclarationFiles(subDir, fileList);
208+
});
209+
}
210+
211+
return fileList;
212+
} catch (error) {
213+
console.error(`Error reading directory ${dir}: ${error.message}`);
214+
return fileList;
215+
}
216+
}
217+
218+
async function processCtsFile(fullPath) {
219+
// Change import paths from .js to .cjs
220+
const content = await readFile(fullPath, "utf8");
221+
const importRegex = /from ['"](.+)\.js['"];?$/gm;
222+
const modifiedContent = content.replace(importRegex, "from '$1.cjs'");
223+
224+
// Change file extension from .d.ts to .d.cts
225+
const newPath = fullPath.replace(".d.ts", ".d.cts");
226+
await writeFile(newPath, modifiedContent, "utf8");
227+
await unlink(fullPath);
228+
}
229+
173230
function isGithubCI() {
174231
if (env["PACKAGE_PUBLISH"] === "true") {
175232
return false;

configs/vite-config-custom/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
},
1616
"peerDependencies": {
1717
"vite": "*"
18+
},
19+
"dependencies": {
20+
"@supercharge/promise-pool": "^3.2.0"
1821
}
1922
}

packages/babel/src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { transformCallExpression } from "@/transforms/callExpression";
2-
import postprocess from "@/transforms/postprocess";
3-
import preprocess from "@/transforms/preprocess";
4-
import { PluginOptions, PluginState } from "@/types";
51
import { PluginObj, transformSync } from "@babel/core";
6-
import { styledComponentPlugin } from "./styled";
2+
import { transformCallExpression } from "@/transforms/callExpression.js";
3+
import postprocess from "@/transforms/postprocess.js";
4+
import preprocess from "@/transforms/preprocess.js";
5+
import { PluginOptions, PluginState } from "@/types.js";
6+
import { styledComponentPlugin } from "@/styled.js";
77

88
export function minchoBabelPlugin(): PluginObj<PluginState> {
99
return {
@@ -18,8 +18,8 @@ export function minchoBabelPlugin(): PluginObj<PluginState> {
1818
};
1919
}
2020

21-
export { styledComponentPlugin as minchoStyledComponentPlugin } from "@/styled";
22-
export type { PluginOptions } from "@/types";
21+
export { styledComponentPlugin as minchoStyledComponentPlugin } from "@/styled.js";
22+
export type { PluginOptions } from "@/types.js";
2323

2424
// == Tests ====================================================================
2525
// Ignore errors when compiling to CommonJS.

packages/babel/src/styled.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { types as t, PluginObj } from "@babel/core";
2-
import type { PluginState, ProgramScope } from "@/types";
3-
import { registerImportMethod } from "@/utils";
2+
import type { PluginState, ProgramScope } from "@/types.js";
3+
import { registerImportMethod } from "@/utils.js";
44

55
/**
66
* The plugin for transforming styled components

packages/babel/src/transforms/callExpression.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { ProgramScope } from "@/types";
1+
import type { ProgramScope } from "@/types.js";
22
import {
33
extractionAPIs,
44
getNearestIdentifier,
55
registerImportMethod
6-
} from "@/utils";
6+
} from "@/utils.js";
77
import { NodePath, types as t } from "@babel/core";
88

99
/**

packages/babel/src/transforms/postprocess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NodePath, types as t, transformFromAstSync } from "@babel/core";
2-
import type { PluginState, ProgramScope } from "@/types";
2+
import type { PluginState, ProgramScope } from "@/types.js";
33

44
export default function postprocess(
55
path: NodePath<t.Node>,

packages/babel/src/transforms/preprocess.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ProgramScope } from "@/types";
1+
import type { ProgramScope } from "@/types.js";
22
import { NodePath, types as t } from "@babel/core";
33
import hash from "@emotion/hash";
44

packages/babel/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NodePath, types as t } from "@babel/core";
22
import { addNamed } from "@babel/helper-module-imports";
3-
import type { ProgramScope } from "./types";
3+
import type { ProgramScope } from "./types.js";
44

55
export function invariant(cond: boolean, msg: string): asserts cond {
66
if (!cond) {

0 commit comments

Comments
 (0)