diff --git a/server/child-processes/create-bundle.js b/server/child-processes/create-bundle.js index 75780b6..81ce17b 100644 --- a/server/child-processes/create-bundle.js +++ b/server/child-processes/create-bundle.js @@ -133,7 +133,7 @@ function bundle(cwd, deep, query) { const moduleName = query.name || makeLegalIdentifier(pkg.name); const entry = deep - ? path.resolve(cwd, deep) + ? findEntryDeep(path.resolve(cwd, deep)) : findEntry( path.resolve( cwd, @@ -162,6 +162,48 @@ function findEntry(file) { } } +function findEntryDeep(file) { + let isFound = false; + let isFolder = false; + + try { + var stats = sander.statSync(file); + isFolder = stats.isDirectory(); + isFound = true; + } catch (err) { + // Nothing found + } + + if (isFound && !isFolder) + { + return file; + } + else if (isFound && isFolder) + { + return lookupEntry([`${file}/index.mjs`, `${file}/index.js`]); + } + + // Lookup extensions + return lookupEntry( [`${file}.mjs`, `${file}.js`] ); +} + +function lookupEntry(files) { + for (var i in files) { + let file = files[i]; + try { + const stats = sander.statSync(file); + info(`File found in package - ${file}`); + return file; + } catch (err) { + // Doesn't exist + info(`File NOT found in package - ${file}`); + } + } + + info(`Can't find any entry, tried: ${files}`); + return undefined; // Will fail later +} + async function bundleWithRollup(cwd, pkg, moduleEntry, name) { const bundle = await rollup.rollup({ input: path.resolve(cwd, moduleEntry),