Allow --copy to accept individual files alongside directories#252
Allow --copy to accept individual files alongside directories#252
Conversation
getCopyDirs now stats each path to determine whether it is a file or a directory. Directories keep the existing behavior (glob appended with /**). Files are passed as-is to cpx2, which copies them directly into the destination root. Paths that cannot be stat'd (not yet created, permission errors) fall back to directory glob behavior to preserve backwards compatibility. Closes #236
Coverage Report for CI Build 24619421759Coverage increased (+0.03%) to 91.496%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
Pull request overview
This PR extends DomStack’s --copy option so it can handle individual files in addition to directories by stat’ing each provided path and only appending /** for directories (or paths that can’t be stat’d), then propagates the resulting async API to build and watch mode.
Changes:
- Make
getCopyDirs()async and return eitherdir/**(directories) or the file path as-is (files). - Await
getCopyDirs()inbuildCopy()and inDomStack.watch()watcher setup. - Update the existing
getCopyDirs()test to use the async API.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/build-copy/index.js | Implements async stat-based detection to support copying files as well as directories; updates build step to await the new API. |
| lib/build-copy/index.test.js | Updates test to await getCopyDirs() (but currently only asserts the directory-glob fallback). |
| index.js | Updates watch-mode copy watcher setup to await getCopyDirs() before constructing cpx watchers. |
Comments suppressed due to low confidence (1)
index.js:255
copyDirsnow includes both directory globs and file paths, so the name is misleading in the watch setup. Consider renaming the local to something likecopyGlobs/copyEntriesto better reflect its contents.
const copyDirs = await getCopyDirs(this.opts.copy)
this.#cpxWatchers = [
cpx.watch(getCopyGlob(this.#src), this.#dest, { ignore: this.opts.ignore }),
...copyDirs.map(copyDir => cpx.watch(copyDir, this.#dest))
]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Renames the local variable in buildCopy to copyGlobs to clarify that the array now contains either directory globs or file paths, not just dirs. Adds two tests: one asserting existing files are passed through as-is, and one asserting existing directories still get /** appended.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
index.js:255
getCopyDirs()can now return bare file paths as well as directory globs, but this code still names the resulting listcopyDirs/copyDir. Renaming these locals tocopyGlobs/copySources(andcopyGlob/copySource) would avoid confusion when reading or extending the watch setup.
const copyDirs = await getCopyDirs(this.opts.copy)
this.#cpxWatchers = [
cpx.watch(getCopyGlob(this.#src), this.#dest, { ignore: this.opts.ignore }),
...copyDirs.map(copyDir => cpx.watch(copyDir, this.#dest))
]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
index.js:255
- In watch mode,
copyDirsnow contains a mix of directory globs (".../**") and file paths. Renaming this local (and thecopyDirloop variable) tocopyGlobs/copyPathswould better reflect what is being watched/copied and align with the naming already used inbuildCopy().
// ── Copy watchers & browser-sync ─────────────────────────────────────
const copyDirs = await getCopyDirs(this.opts.copy)
this.#cpxWatchers = [
cpx.watch(getCopyGlob(this.#src), this.#dest, { ignore: this.opts.ignore }),
...copyDirs.map(copyDir => cpx.watch(copyDir, this.#dest))
]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ile support Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
--copynow accepts individual file paths in addition to directories. Directories continue to use the existing/**glob behavior. Files are passed directly to cpx2, which places them in the destination root.Paths that cannot be stat'd (do not exist yet, or have permission issues) fall back to directory glob behavior to preserve backwards compatibility.
getCopyDirsis now async. BothbuildCopyand the watch-mode watcher setup in theDomStackclass have been updated to await it.Closes #236