Skip to content

Commit

Permalink
fix(bundling): copy initial assets correctly in watch mode for esbuild (
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Feb 24, 2023
1 parent 65b1cdd commit 53a1c42
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
26 changes: 26 additions & 0 deletions e2e/esbuild/src/esbuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
packageInstall,
rmDist,
runCommandUntil,
waitUntil,
} from '@nrwl/e2e/utils';

describe('EsBuild Plugin', () => {
Expand Down Expand Up @@ -67,6 +68,31 @@ describe('EsBuild Plugin', () => {
expect(() => runCLI(`build ${myPkg}`)).toThrow();
expect(() => runCLI(`build ${myPkg} --skipTypeCheck`)).not.toThrow();
expect(runCommand(`node dist/libs/${myPkg}/index.js`)).toMatch(/Bye/);
// Reset file
updateFile(
`libs/${myPkg}/src/index.ts`,
`
console.log('Hello');
`
);

/* Test that watch mode copies assets on start, and again on update.
*/
updateFile(`libs/${myPkg}/assets/a.md`, 'initial a');
const watchProcess = await runCommandUntil(
`build ${myPkg} --watch`,
(output) => {
return output.includes('watching for changes');
}
);
readFile(`dist/libs/${myPkg}/assets/a.md`).includes('initial a');
updateFile(`libs/${myPkg}/assets/a.md`, 'updated a');
await expect(
waitUntil(() =>
readFile(`dist/libs/${myPkg}/assets/a.md`).includes('updated a')
)
).resolves.not.toThrow();
watchProcess.kill();
}, 300_000);

it('should support bundling everything or only workspace libs', async () => {
Expand Down
25 changes: 13 additions & 12 deletions packages/js/src/utils/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ export async function copyAssets(
callback:
typeof options?.watch === 'object' ? options.watch.onCopy : undefined,
});
const result: CopyAssetsResult = {
success: true,
};

if (options.watch) {
const dispose = await assetHandler.watchAndProcessOnAssetChange();
return {
success: true,
stop: dispose,
};
} else {
try {
await assetHandler.processAllAssetsOnce();
} catch {
return { success: false };
}
return { success: true };
result.stop = await assetHandler.watchAndProcessOnAssetChange();
}

try {
await assetHandler.processAllAssetsOnce();
} catch {
result.success = false;
}

return result;
}

1 comment on commit 53a1c42

@vercel
Copy link

@vercel vercel bot commented on 53a1c42 Feb 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx.dev
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.