MCPcopy
hub / github.com/browserless/browserless / importDefault

Function importDefault

bin/browserless.js:99–132  ·  view source on GitHub ↗
(files, fileName)

Source from the content-addressed store, hash-verified

97};
98
99const importDefault = async (files, fileName) => {
100 const pJSON = await projectPackageJSON;
101 // Check first if overrides are manually specified in the project's package.json
102 if (pJSON && pJSON.browserless && typeof pJSON.browserless === 'object') {
103 const camelCaseFileName = camelCase(fileName);
104 const relativePath = pJSON.browserless[camelCaseFileName];
105 if (relativePath) {
106 const fullFilePath = path.join(
107 compiledDir,
108 translateSrcToBuild(relativePath),
109 );
110 log(`Importing module from package.json: "${fullFilePath}"`);
111 return (await import(fullFilePath)).default;
112 }
113 }
114
115 const classModuleFile = files.find((f) =>
116 path.parse(f).name.endsWith(fileName),
117 );
118
119 if (!classModuleFile) {
120 return;
121 }
122
123 const fullFilePath = normalizeFileProtocol(
124 path.join(compiledDir, classModuleFile),
125 );
126
127 if (!classModuleFile) {
128 return;
129 }
130 log(`Importing module from found files: "${fullFilePath}"`);
131 return (await import(fullFilePath)).default;
132};
133
134const clean = async () =>
135 fs.rm(path.join(compiledDir), {

Callers 2

buildFunction · 0.85
startFunction · 0.85

Calls 3

camelCaseFunction · 0.85
translateSrcToBuildFunction · 0.85
normalizeFileProtocolFunction · 0.85

Tested by

no test coverage detected