Skip to content

Commit

Permalink
feat: Make sync-pnpm watch mode optional
Browse files Browse the repository at this point in the history
Watch mode is selected by passing the `--watch` argument.

We now explicitly pass this argument when we want to watch
(e.g. when we have `start`ed) and we don't when we just need
to sync once (e.g. when linting or running tests on CI)
  • Loading branch information
vitch committed May 19, 2023
1 parent e388caa commit c004493
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js:fix": "eslint . --fix",
"lint:types": "glint",
"start": "concurrently 'ember serve' 'npm:_syncPnpm' --names 'docs-app serve,docs-app sync built package'",
"start": "concurrently 'ember serve' 'pnpm sync-pnpm --watch' --names 'docs-app serve,docs-app sync built package'",
"test:ember": "ember test",
"_syncPnpm": "pnpm sync-pnpm"
},
Expand Down
4 changes: 3 additions & 1 deletion internal/sync-pnpm/bin/sync-pnpm.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import syncPnpm from '../index.js';

await syncPnpm();
let watchMode = process.argv.find((arg) => arg === '--watch') !== undefined;

await syncPnpm({ watchMode });
11 changes: 10 additions & 1 deletion internal/sync-pnpm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const syncDir = './dist';

const DEBOUNCE_INTERVAL = 50;

export default async function syncPnpm(dir = process.cwd()) {
export default async function syncPnpm({ dir = process.cwd(), watchMode = false }) {
const root = await findRoot(dir);
const ownPackageJson = await readJson(join(dir, 'package.json'));
const ownDependencies = [
Expand Down Expand Up @@ -48,6 +48,14 @@ export default async function syncPnpm(dir = process.cwd()) {
}
}

if (!watchMode) {
for (const [syncFrom, syncTo] of Object.entries(paths)) {
syncDependency(syncFrom, syncTo);
}

return;
}

let fromPaths = Object.keys(paths);
let watcher = new Watcher(fromPaths);

Expand All @@ -74,6 +82,7 @@ export default async function syncPnpm(dir = process.cwd()) {
await syncDependency(foundFromPath, paths[foundFromPath]);
}
}

setTimeout(handleDirtyPaths, DEBOUNCE_INTERVAL);
}

Expand Down
2 changes: 1 addition & 1 deletion test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"lint:types": "glint",
"lint:prettier": "prettier -c .",
"lint:prettier:fix": "prettier -w .",
"start": "concurrently 'ember serve' 'npm:_syncPnpm' --names 'test-app serve,test-app sync built package'",
"start": "concurrently 'ember serve' 'sync-pnpm --watch' --names 'test-app serve,test-app sync built package'",
"test": "ember test",
"test:ember": "ember test",
"typecheck": "pnpm tsc -v; pnpm glint --version; pnpm lint:types",
Expand Down

0 comments on commit c004493

Please sign in to comment.