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): Call it.

* snowpack/src/sources/local-install.ts (InstallRunResult): export it.

* snowpack/src/sources/local.ts (InstallRunResult): import it.
(installDependencies): export it and give it a type.
  • Loading branch information
joaotavora committed Jan 13, 2021
1 parent 7b9cf8a commit 0024b55
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 @@ -96,6 +96,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 @@ -1341,8 +1343,16 @@ export async function startServer(commandOptions: CommandOptions): Promise<Snowp
.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(config)
.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/sources/local-install.ts
Expand Up @@ -18,7 +18,7 @@ interface InstallRunOptions {
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 @@ -6,7 +6,7 @@ import {ImportMap, InstallOptions as EsinstallOptions} from 'esinstall';
import {existsSync, promises as fs} from 'fs';
import * as colors from 'kleur/colors';
import path from 'path';
import {run as installRunner} from './local-install';
import {InstallRunResult, run as installRunner} from './local-install';
import {logger} from '../logger';
import {getInstallTargets} from '../scan-imports';
import {CommandOptions, PackageSource, PackageSourceLocal, SnowpackConfig} from '../types';
Expand All @@ -26,14 +26,15 @@ const DEV_DEPENDENCIES_DIR = path.join(PROJECT_CACHE_DIR, process.env.NODE_ENV |
* 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(config: SnowpackConfig) {
export async function installDependencies(config: SnowpackConfig)
: Promise <InstallRunResult | null> {
const installTargets = await getInstallTargets(
config,
config.packageOptions.source === 'local' ? config.packageOptions.knownEntrypoints : [],
);
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 0024b55

Please sign in to comment.