MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / ESM_FILE_FORMAT

Method ESM_FILE_FORMAT

tools/mcpack.js:937–956  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

935 this.throwInvalidPackageTargetError();
936 }
937 ESM_FILE_FORMAT(url) {
938 if (url.endsWith(".mjs"))
939 return "module";
940 if (url.endsWith(".cjs"))
941 return "commonjs";
942 if (url.endsWith(".json"))
943 return "json";
944 let packageURL = this.LOOKUP_PACKAGE_SCOPE(url);
945 if (packageURL) {
946 let pjson = this.READ_PACKAGE_JSON(packageURL);
947 if (undefined === pjson.type) {
948 if (url.endsWith(".js"))
949 return "commonjs"; // default for type
950 }
951 if (pjson.type == "module") {
952 if (url.endsWith(".js"))
953 return "module";
954 }
955 }
956 }
957 LOOKUP_PACKAGE_SCOPE(url) {
958 let scopeURL = url;
959 while (scopeURL != "file:///") {

Callers 1

ESM_RESOLVEMethod · 0.80

Calls 2

LOOKUP_PACKAGE_SCOPEMethod · 0.80
READ_PACKAGE_JSONMethod · 0.80

Tested by

no test coverage detected