Skip to content

Commit

Permalink
Fix #2088: unbreak automatic reinstall of linked dependencies on change
Browse files Browse the repository at this point in the history
* snowpack/src/commands/dev.ts (installDependencies): import it.
(onDepWatchEvent): Use it.

* snowpack/src/commands/install.ts (InstallRunResult): export it.

* snowpack/src/sources/local.ts (InstallRunResult): import it.
(installDependencies): export it.
  • Loading branch information
joaotavora committed Dec 23, 2020
1 parent 0fb1827 commit 5390f7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
12 changes: 11 additions & 1 deletion snowpack/src/commands/dev.ts
Expand Up @@ -94,6 +94,8 @@ interface FoundFile {
isResolve: boolean;
}

import {installDependencies} from '../sources/local';

const FILE_BUILD_RESULT_ERROR = `Build Result Error: There was a problem with a file build result.`;

/**
Expand Down Expand Up @@ -1320,8 +1322,16 @@ export async function startDevServer(commandOptions: CommandOptions): Promise<Sn
.filter(([_, packageManifest]) => packageManifest && !packageManifest['_id']) // only watch symlinked deps for now
.map(([fileLoc]) => `${path.dirname(fileLoc!)}/**`),
);

let working : Promise<any> | null = null; // only one installl at a time
function onDepWatchEvent() {
hmrEngine.broadcastMessage({type: 'reload'});
if (!working)
// FIXME: If one changes, reinstall _all_. Inefficient?
working = installDependencies()
.then(() => {
hmrEngine.broadcastMessage({type: 'reload'})
working = null;
});
}
const depWatcher = chokidar.watch([...symlinkedFileLocs], {
cwd: '/', // we’re using absolute paths, so watch from root
Expand Down
2 changes: 1 addition & 1 deletion snowpack/src/commands/install.ts
Expand Up @@ -60,7 +60,7 @@ interface InstallRunOptions extends CommandOptions {
shouldPrintStats: boolean;
}

interface InstallRunResult {
export interface InstallRunResult {
importMap: ImportMap;
newLockfile: ImportMap | null;
stats: DependencyStatsOutput | null;
Expand Down
7 changes: 4 additions & 3 deletions snowpack/src/sources/local.ts
Expand Up @@ -3,7 +3,7 @@ import {ImportMap} from 'esinstall';
import {existsSync, promises as fs} from 'fs';
import * as colors from 'kleur/colors';
import path from 'path';
import {getInstallTargets, run as installRunner} from '../commands/install';
import {InstallRunResult, getInstallTargets, run as installRunner} from '../commands/install';
import {logger} from '../logger';
import {CommandOptions, PackageSource, SnowpackConfig} from '../types';
import {checkLockfileHash, DEV_DEPENDENCIES_DIR, updateLockfileHash} from '../util';
Expand All @@ -13,12 +13,13 @@ import {checkLockfileHash, DEV_DEPENDENCIES_DIR, updateLockfileHash} from '../ut
* your entire source app for dependency install targets, installs them,
* and then updates the "hash" file used to check node_modules freshness.
*/
async function installDependencies(commandOptions: CommandOptions) {
export async function installDependencies(commandOptions:CommandOptions = installCommandOptions)
: Promise<InstallRunResult | null>{
const {config} = commandOptions;
const installTargets = await getInstallTargets(config);
if (installTargets.length === 0) {
logger.info('Nothing to install.');
return;
return null;
}
// 2. Install dependencies, based on the scan of your final build.
const installResult = await installRunner({
Expand Down

0 comments on commit 5390f7d

Please sign in to comment.