Skip to content

Commit 6b31904

Browse files
authored
Merge pull request #107 from samchon/v2.5
Complement #102 - `d.mts` files
2 parents 63ff93b + 06b5ccc commit 6b31904

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

build/dist.ts

+28-7
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,44 @@ async function documents(): Promise<void> {
1717
await fs.promises.link(`${ROOT}/${file}`, `${DIST}/${file}`);
1818
}
1919

20-
async function module(): Promise<void> {
21-
const javascript = async (location: string, file: string) => {
22-
const content: string = await fs.promises.readFile(location, "utf8");
23-
const replaced: string = content
24-
.replace(/(import|export)(.*)from "(.\/|..\/)(.*)"/g, str => {
20+
const substitude =
21+
(content: string) =>
22+
content.replace(
23+
/(import|export)(.*)from "(.\/|..\/)(.*)"/g,
24+
str => {
2525
const to: number = str.lastIndexOf(`"`);
2626
return [
2727
str.substring(0, to),
2828
`.mjs"`,
2929
str.substring(to + 1)
3030
].join("");
31-
})
31+
}
32+
);
33+
34+
async function module(): Promise<void> {
35+
const declaration = async (location: string)=> {
36+
const content = substitude(
37+
await fs.promises.readFile(location, "utf8")
38+
);
39+
await fs.promises.unlink(location);
40+
await fs.promises.writeFile(
41+
`${location.substring(0, location.length - 5)}.d.mts`,
42+
content,
43+
"utf8"
44+
);
45+
};
46+
const javascript = async (location: string, file: string) => {
47+
const content = substitude(
48+
await fs.promises.readFile(location, "utf8")
49+
)
3250
.replace(
3351
`//# sourceMappingURL=${file}.map`,
3452
`//# sourceMappingURL=${file.substring(0, file.length - 3)}.mjs.map`
3553
);
3654
await fs.promises.unlink(location);
3755
await fs.promises.writeFile(
3856
`${location.substring(0, location.length - 3)}.mjs`,
39-
replaced,
57+
content,
4058
"utf8"
4159
);
4260
};
@@ -52,6 +70,7 @@ async function module(): Promise<void> {
5270
"utf8"
5371
);
5472
};
73+
5574
const iterate = async (path: string): Promise<void> => {
5675
const directory: string[] = await fs.promises.readdir(path);
5776
for (const file of directory) {
@@ -61,6 +80,8 @@ async function module(): Promise<void> {
6180
if (stats.isDirectory()) await iterate(location);
6281
else if (location.substr(-3) === ".js")
6382
await javascript(location, file);
83+
else if (location.substr(-5) === ".d.ts")
84+
await declaration(location);
6485
else if (location.substr(-7) === ".js.map")
6586
await mapper(location);
6687
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"email": "[email protected]",
77
"url": "https://github.com/samchon"
88
},
9-
"version": "2.5.10",
9+
"version": "2.5.11",
1010
"main": "./index.js",
1111
"module": "./index.mjs",
1212
"esnext": "./index.mjs",

0 commit comments

Comments
 (0)