Skip to content

Commit

Permalink
Merge pull request samchon#107 from samchon/v2.5
Browse files Browse the repository at this point in the history
Complement samchon#102 - `d.mts` files
  • Loading branch information
samchon committed Oct 10, 2022
2 parents 63ff93b + 06b5ccc commit 6b31904
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
35 changes: 28 additions & 7 deletions build/dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,44 @@ async function documents(): Promise<void> {
await fs.promises.link(`${ROOT}/${file}`, `${DIST}/${file}`);
}

async function module(): Promise<void> {
const javascript = async (location: string, file: string) => {
const content: string = await fs.promises.readFile(location, "utf8");
const replaced: string = content
.replace(/(import|export)(.*)from "(.\/|..\/)(.*)"/g, str => {
const substitude =
(content: string) =>
content.replace(
/(import|export)(.*)from "(.\/|..\/)(.*)"/g,
str => {
const to: number = str.lastIndexOf(`"`);
return [
str.substring(0, to),
`.mjs"`,
str.substring(to + 1)
].join("");
})
}
);

async function module(): Promise<void> {
const declaration = async (location: string)=> {
const content = substitude(
await fs.promises.readFile(location, "utf8")
);
await fs.promises.unlink(location);
await fs.promises.writeFile(
`${location.substring(0, location.length - 5)}.d.mts`,
content,
"utf8"
);
};
const javascript = async (location: string, file: string) => {
const content = substitude(
await fs.promises.readFile(location, "utf8")
)
.replace(
`//# sourceMappingURL=${file}.map`,
`//# sourceMappingURL=${file.substring(0, file.length - 3)}.mjs.map`
);
await fs.promises.unlink(location);
await fs.promises.writeFile(
`${location.substring(0, location.length - 3)}.mjs`,
replaced,
content,
"utf8"
);
};
Expand All @@ -52,6 +70,7 @@ async function module(): Promise<void> {
"utf8"
);
};

const iterate = async (path: string): Promise<void> => {
const directory: string[] = await fs.promises.readdir(path);
for (const file of directory) {
Expand All @@ -61,6 +80,8 @@ async function module(): Promise<void> {
if (stats.isDirectory()) await iterate(location);
else if (location.substr(-3) === ".js")
await javascript(location, file);
else if (location.substr(-5) === ".d.ts")
await declaration(location);
else if (location.substr(-7) === ".js.map")
await mapper(location);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "samchon.github@gmail.com",
"url": "https://github.com/samchon"
},
"version": "2.5.10",
"version": "2.5.11",
"main": "./index.js",
"module": "./index.mjs",
"esnext": "./index.mjs",
Expand Down

0 comments on commit 6b31904

Please sign in to comment.