MCPcopy Create free account
hub / github.com/walterhiggins/ScriptCraft / readModuleFromDirectory

Function readModuleFromDirectory

src/main/js/lib/require.js:101–121  ·  view source on GitHub ↗
(dir)

Source from the content-addressed store, hash-verified

99 }
100
101 function readModuleFromDirectory(dir) {
102 // look for a package.json file
103 var pkgJsonFile = new File(dir, './package.json');
104 if (pkgJsonFile.exists()) {
105 var pkg = scload(pkgJsonFile);
106 var mainFile = new File(dir, pkg.main);
107 if (mainFile.exists()) {
108 return mainFile;
109 } else {
110 return null;
111 }
112 } else {
113 // look for an index.js file
114 var indexJsFile = new File(dir, './index.js');
115 if (indexJsFile.exists()) {
116 return indexJsFile;
117 } else {
118 return null;
119 }
120 }
121 }
122
123 /**********************************************************************
124### module name resolution

Callers 1

fileExistsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected