samchon/tstl

Should be compatible with non "commonjs" mode compilation

samchon opened this issue · 1 comments

Summary

When creating a TypeScript project using esnext mode compilation option and importing the tstl module, it occurs an error that Cannot find the module 'tstl'.

  • TSTL Version: 2.4.0
  • Expected behavior: No problem with esnext mode compilation
  • Actual behavior: Compile error occurs

tsconfig.json

{
    "compilerOptions": {
        "mode": "esnext"
    }
}

Code occuring the bug

// DO NOT USE "require" FUNCTIONS
export import base = require("./base");
export import experimental = require("./experimental");
export import ranges = require("./ranges");

// DO NOT OMIT "/index"
export * from "./container";
export * from "./iterator";
export * from "./algorithm";
export * from "./exception";
export * from "./functional";
export * from "./numeric";
export * from "./thread";
export * from "./utility";

Looking at the src/index.ts file, you can see that require functions, a typical domain function of commonjs mode, are being used. To be compatible with non-commonjs modules' compilation, those statements must be changed to export * as x from "${x}" form,

Also, importing and exporting all objects from a directory are implemented by combining the features into a ${directory}/index.ts file like src/container/index.ts. However, the code is omitting the /index. Convenience with omitting the /index is also a typical spec supported by the commonjs. They also must be changed to specifying the full path without omitting the /index.

// NAMESPACE BY `export * as ${name}`
export * as base from "./base/index";
export * as experimental from "./experimental/index";
export * as ranges from "./ranges/index";

// FULL PATH WITHOUT OMITTING THE "/index"
export * from "./container/index";
export * from "./iterator/index";
export * from "./algorithm/index";
export * from "./exception/index";
export * from "./functional/index";
export * from "./numeric/index";
export * from "./thread/index";
export * from "./utility/index";

To validate the compability, those commands should be run when testing. Those command would be enrolled into package.json which can be used npm run module. Also, the test script would be inserted into the .github/workflows/build.yml for the test automation.

tsc --noEmit --module amd
tsc --noEmit --module system
tsc --noEmit --module umd
tsc --noEmit --module esnext