Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
feat(wds): install node_modules when missing on project open (fixes #102
Browse files Browse the repository at this point in the history
)
  • Loading branch information
connor4312 committed May 24, 2018
1 parent a88aba9 commit e81697e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/server/tasks/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export abstract class Task<T> {
/**
* Runs the subtask and waits for it to complete.
*/
protected async awaitSubtask(task: Task<T>): Promise<T> {
protected async awaitSubtask<R>(task: Task<R>): Promise<R> {
this.subtasks.add(task);
const retValue = await task.start();
await task.untilStopped;
Expand Down
19 changes: 18 additions & 1 deletion src/server/webpack-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MissingWebpackConfig } from './errors';
import { Project } from './project';
import { ConsoleTask } from './tasks/console-task';
import { exists } from './util';
import { NpmInstallTask } from './tasks/npm-install-task';

/**
* Just making a note of some investigations here. *Ideally* I wanted to embed
Expand Down Expand Up @@ -61,9 +62,15 @@ export abstract class WebpackTask<T> extends ConsoleTask<T> {
throw new MissingWebpackConfig();
}

const [out, process] = await this.startWebpack(config);
this.state.next(WebpackState.Starting);

if (!(await exists(this.project.baseDir('node_modules')))) {
this.data.next('Node modules not found, starting installation. This may take a minute.\n');
await this.installNodeModules();
}

const [out, process] = await this.startWebpack(config);

process.on('exit', code => {
if (code === 0) {
this.state.next(WebpackState.Stopped);
Expand All @@ -82,6 +89,16 @@ export abstract class WebpackTask<T> extends ConsoleTask<T> {
this.state.next(WebpackState.Stopping);
}

/**
* Runs npm install. This is called when starting webpack if we detect
* that the user doesn't have their modules installed.
*/
protected async installNodeModules() {
const task = new NpmInstallTask(this.project.baseDir());
task.data.subscribe(data => this.data.next(data));
await this.awaitSubtask(task);
}

/**
* Reads stdout/err from the process and dispatches it accordingly.
*/
Expand Down

0 comments on commit e81697e

Please sign in to comment.