Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve more cases on deep import #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion server/child-processes/create-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down