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

Print user friendly error if no entrypoint can be found #1848

Merged
merged 5 commits into from Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/Bundler.js
Expand Up @@ -142,7 +142,9 @@ class Bundler extends EventEmitter {
contentHash:
typeof options.contentHash === 'boolean'
? options.contentHash
: isProduction
: isProduction,
throwErrors:
typeof options.throwErrors === 'boolean' ? options.throwErrors : true
};
}

Expand Down Expand Up @@ -223,6 +225,7 @@ class Bundler extends EventEmitter {

let isInitialBundle = !this.entryAssets;
let startTime = Date.now();
let initialised = !isInitialBundle;
this.pending = true;
this.error = null;

Expand All @@ -242,10 +245,24 @@ class Bundler extends EventEmitter {

this.entryAssets = new Set();
for (let entry of this.entryFiles) {
let asset = await this.resolveAsset(entry);
this.buildQueue.add(asset);
this.entryAssets.add(asset);
try {
let asset = await this.resolveAsset(entry);
this.buildQueue.add(asset);
this.entryAssets.add(asset);
} catch (err) {
throw new Error(
`Cannot resolve entry "${entry}" from "${
this.options.rootDir
}"`
);
}
}

if (this.entryAssets.size === 0) {
throw new Error('No entries found.');
}

initialised = true;
}

// Build the queued assets.
Expand Down Expand Up @@ -318,10 +335,11 @@ class Bundler extends EventEmitter {
this.hmr.emitError(err);
}

if (process.env.NODE_ENV === 'production') {
process.exitCode = 1;
} else if (process.env.NODE_ENV === 'test' && !this.hmr) {
if (this.options.throwErrors && !this.hmr) {
throw err;
} else if (process.env.NODE_ENV === 'production' || !initialised) {
await this.stop();
process.exit(1);
}
} finally {
this.pending = false;
Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Expand Up @@ -202,6 +202,7 @@ async function bundle(main, command) {
};
}

command.throwErrors = false;
command.scopeHoist = command.experimentalScopeHoisting || false;
const bundler = new Bundler(main, command);

Expand Down
3 changes: 2 additions & 1 deletion test/utils.js
Expand Up @@ -37,7 +37,8 @@ function bundler(file, opts) {
cache: false,
killWorkers: false,
hmr: false,
logLevel: 0
logLevel: 0,
throwErrors: true
},
opts
)
Expand Down