Skip to content

Commit

Permalink
Merge pull request #109 from samchon/v2.5
Browse files Browse the repository at this point in the history
Close #108 - revert both CSM and ESM support
  • Loading branch information
samchon committed Oct 10, 2022
2 parents 6b31904 + 9581f86 commit f60c359
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 81 deletions.
138 changes: 69 additions & 69 deletions build/dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,86 +17,86 @@ async function documents(): Promise<void> {
await fs.promises.link(`${ROOT}/${file}`, `${DIST}/${file}`);
}

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("");
}
);
// 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`,
content,
"utf8"
);
};
const mapper = async (location: string) => {
const content: string = await fs.promises.readFile(location, "utf8");
const parsed: {file: string } = JSON.parse(content);
parsed.file = parsed.file.substring(0, parsed.file.length - 3) + ".mjs";
// 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`,
// content,
// "utf8"
// );
// };
// const mapper = async (location: string) => {
// const content: string = await fs.promises.readFile(location, "utf8");
// const parsed: {file: string } = JSON.parse(content);
// parsed.file = parsed.file.substring(0, parsed.file.length - 3) + ".mjs";

await fs.promises.unlink(location);
await fs.promises.writeFile(
`${location.substring(0, location.length - 7)}.mjs.map`,
JSON.stringify(parsed),
"utf8"
);
};
// await fs.promises.unlink(location);
// await fs.promises.writeFile(
// `${location.substring(0, location.length - 7)}.mjs.map`,
// JSON.stringify(parsed),
// "utf8"
// );
// };

const iterate = async (path: string): Promise<void> => {
const directory: string[] = await fs.promises.readdir(path);
for (const file of directory) {
const location: string = `${path}/${file}`;
const stats: fs.Stats = await fs.promises.stat(location);
// const iterate = async (path: string): Promise<void> => {
// const directory: string[] = await fs.promises.readdir(path);
// for (const file of directory) {
// const location: string = `${path}/${file}`;
// const stats: fs.Stats = await fs.promises.stat(location);

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);
}
};
// 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);
// }
// };

cp.execSync(`npx tsc -p tsconfig.module.json`, { stdio: "inherit" });
await iterate(DIST);
}
// cp.execSync(`npx tsc -p tsconfig.module.json`, { stdio: "inherit" });
// await iterate(DIST);
// }

async function main(): Promise<void> {
cp.execSync(`npx rimraf ${DIST}`, { stdio: "inherit" });
await fs.promises.mkdir(DIST);

await documents();
await module();
// await module();
cp.execSync(`npx tsc -p tsconfig.json`, { stdio: "inherit" });
}
main();
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
"email": "samchon.github@gmail.com",
"url": "https://github.com/samchon"
},
"version": "2.5.11",
"main": "./index.js",
"module": "./index.mjs",
"esnext": "./index.mjs",
"version": "2.5.12",
"typings": "./index.d.ts",
"main": "./index.js",
"scripts": {
"api": "typedoc src --exclude \"**/+(test|benchmark)/**\" --excludeNotDocumented --plugin typedoc-plugin-external-module-name --plugin typedoc-plugin-exclude-references --out ../tstl@gh-pages/api",
"migration": "ts-node build/migration",
Expand Down
8 changes: 0 additions & 8 deletions tsconfig.module.json

This file was deleted.

0 comments on commit f60c359

Please sign in to comment.