Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
fix(externals): sanatize external name (#563)
Browse files Browse the repository at this point in the history
* fix(externals): sanatize external name

* fix(externals): address comment
  • Loading branch information
dogpatch626 authored Sep 15, 2023
1 parent cd83ead commit 4be6f3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,28 @@ describe('Esbuild plugin timeBuild', () => {
expect(fs.promises.writeFile).toHaveBeenCalledTimes(1);
expect(fs.promises.writeFile).toHaveBeenCalledWith('.esbuild-stats.mockBundleName.json', '{"file.js":{},"durationMs":3}');
});
it('should sanatize bundlename replacing `/` with `-`', async () => {
const plugin = timeBuild({ bundleName: '@scoped/mockBundleName', watch: false });
const hooks = runSetupAndGetLifeHooks(plugin);
const onStart = hooks.onStart[0];
const onEnd = hooks.onEnd[0];

process.hrtime.bigint.mockImplementation(() => BigInt(1000000)); // 1ms in nanoseconds
onStart(); // call onStart to load in the start time
jest.clearAllMocks();

process.hrtime.bigint.mockImplementation(() => BigInt(4000000)); // 4ms in nanoseconds

await onEnd({
metafile: {
outputs: {
'file.js': {},
},
},
});

expect(fs.promises.writeFile).toHaveBeenCalledWith('[email protected]', '{"file.js":{},"durationMs":3}');
});
it('should not log in watch mode', async () => {
const plugin = timeBuild({ bundleName: 'mockBundleName', watch: true });
const hooks = runSetupAndGetLifeHooks(plugin);
Expand Down
4 changes: 2 additions & 2 deletions packages/one-app-dev-bundler/esbuild/plugins/time-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const timeBuild = ({ bundleName, watch }) => ({

if (!watch) { // watch has its own logging
console.log(`${bundleName} bundle built in ${result.durationMs}ms`);

await fs.promises.writeFile(`.esbuild-stats.${bundleName}.json`, JSON.stringify({
const sanitizedName = bundleName.replace('/', '-');
await fs.promises.writeFile(`.esbuild-stats.${sanitizedName}.json`, JSON.stringify({
...result.metafile.outputs,
durationMs: result.durationMs,
}));
Expand Down

0 comments on commit 4be6f3b

Please sign in to comment.