-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Watch copied files #27
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ export default function copy(options = {}) { | |
|
||
return { | ||
name: 'copy', | ||
[hook]: async () => { | ||
async [hook]() { | ||
if (copyOnce && copied) { | ||
return | ||
} | ||
|
@@ -88,6 +88,10 @@ export default function copy(options = {}) { | |
} | ||
|
||
for (const { src, dest } of copyTargets) { | ||
try { | ||
this.addWatchFile(src) | ||
} catch { /* Cannot call addWatchFile after the build has finished. */ } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
await fs.copy(src, dest, restPluginOptions) | ||
|
||
if (verbose) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,93 @@ describe('Copy', () => { | |
expect(await fs.pathExists('dist/scss-multiple/nested-renamed')).toBe(true) | ||
expect(await fs.pathExists('dist/scss-multiple/nested-renamed/scss-3.scss')).toBe(true) | ||
}) | ||
|
||
test('Watches copied files in pre-build hook', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I based these off of the |
||
const watcher = watch({ | ||
input: 'src/index.js', | ||
output: { | ||
dir: 'build', | ||
format: 'esm' | ||
}, | ||
plugins: [ | ||
copy({ | ||
hook: 'buildStart', | ||
targets: [ | ||
{ src: 'src/assets/asset-1.js', dest: 'dist' } | ||
] | ||
}) | ||
] | ||
}) | ||
|
||
await sleep(1000) | ||
|
||
expect(await fs.pathExists('dist/asset-1.js')).toBe(true) | ||
|
||
await fs.remove('dist') | ||
|
||
expect(await fs.pathExists('dist/asset-1.js')).toBe(false) | ||
|
||
await replace({ | ||
files: 'src/assets/asset-1.js', | ||
from: 'asset1', | ||
to: 'assetX' | ||
}) | ||
|
||
await sleep(1000) | ||
|
||
expect(await fs.pathExists('dist/asset-1.js')).toBe(true) | ||
|
||
watcher.close() | ||
|
||
await replace({ | ||
files: 'src/assets/asset-1.js', | ||
from: 'assetX', | ||
to: 'asset1' | ||
}) | ||
}) | ||
|
||
test('Does not watch copied files in post-build hook', async () => { | ||
const watcher = watch({ | ||
input: 'src/index.js', | ||
output: { | ||
dir: 'build', | ||
format: 'esm' | ||
}, | ||
plugins: [ | ||
copy({ | ||
targets: [ | ||
{ src: 'src/assets/asset-1.js', dest: 'dist' } | ||
] | ||
}) | ||
] | ||
}) | ||
|
||
await sleep(1000) | ||
|
||
expect(await fs.pathExists('dist/asset-1.js')).toBe(true) | ||
|
||
await fs.remove('dist') | ||
|
||
expect(await fs.pathExists('dist/asset-1.js')).toBe(false) | ||
|
||
await replace({ | ||
files: 'src/assets/asset-1.js', | ||
from: 'asset1', | ||
to: 'assetX' | ||
}) | ||
|
||
await sleep(1000) | ||
|
||
expect(await fs.pathExists('dist/asset-1.js')).toBe(false) | ||
|
||
watcher.close() | ||
|
||
await replace({ | ||
files: 'src/assets/asset-1.js', | ||
from: 'assetX', | ||
to: 'asset1' | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Options', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was necessary because the
this
keyword was not available with the unbound arrow function syntax.See this issue for more details: rollup/rollup#1518 (comment)