Skip to content

Commit

Permalink
Merge pull request Rich-Harris#2 from divriots/deepimport
Browse files Browse the repository at this point in the history
fix deep imports + tmp folder
  • Loading branch information
gqio authored May 7, 2019
2 parents af86613 + 713b429 commit da732cd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path');
const sander = require('sander');

exports.root = path.resolve(__dirname);
exports.tmpdir = '/tmp';
exports.tmpdir = '/tmp/packd-es-cache';
exports.registry = 'https://registry.npmjs.org';

try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@
"devDependencies": {
"eslint": "^5.12.0"
}
}
}
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

0 comments on commit da732cd

Please sign in to comment.