-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d5f87b
commit e20ec92
Showing
13 changed files
with
323 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"sonda": patch | ||
--- | ||
|
||
Rollup plugin: Fix detecting ESM files when `@rollup/plugin-commonjs` plugin is not installed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"sonda": patch | ||
--- | ||
|
||
Webpack plugin: Fix reported files sizes, which sometimes included imported dependencies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { vi, describe, it, expect } from 'vitest'; | ||
import { join } from 'path'; | ||
import esbuild from 'esbuild'; | ||
import { SondaEsbuildPlugin } from '../src/bundlers/esbuild'; | ||
import type { Options } from '../src/types'; | ||
|
||
const mocks = vi.hoisted( () => ( { | ||
generateReportFromAssets: vi.fn().mockResolvedValue( undefined ) | ||
} ) ); | ||
|
||
vi.mock( '../src/report/generate.js', () => ( { | ||
generateReportFromAssets: mocks.generateReportFromAssets | ||
} ) ); | ||
|
||
describe( 'SondaEsbuildPlugin', () => { | ||
it( 'should transform the code correctly', async () => { | ||
await esbuild.build( { | ||
entryPoints: [ join( import.meta.dirname, 'fixtures/bundlers/index.js' ) ], | ||
bundle: true, | ||
outfile: join( import.meta.dirname, 'dist/esbuild_1.js' ), | ||
sourcemap: true, | ||
plugins: [ SondaEsbuildPlugin() ], | ||
format: 'esm', | ||
} ); | ||
|
||
expect( mocks.generateReportFromAssets ).toHaveBeenCalledWith( | ||
[ | ||
join( import.meta.dirname, 'dist/esbuild_1.js.map' ), | ||
join( import.meta.dirname, 'dist/esbuild_1.js' ) | ||
], | ||
{ | ||
'tests/fixtures/bundlers/index.js': { | ||
belongsTo: null, | ||
bytes: 66, | ||
format: 'esm', | ||
imports: [ 'tests/fixtures/detailed/index.js' ] | ||
}, | ||
'tests/fixtures/detailed/index.js': { | ||
belongsTo: null, | ||
bytes: 238, | ||
format: 'esm', | ||
imports: [] | ||
}, | ||
'tests/fixtures/detailed/src/maths.js': { | ||
belongsTo: 'tests/fixtures/detailed/index.js', | ||
bytes: 201, | ||
format: 'esm', | ||
imports: [] | ||
}, | ||
'tests/fixtures/detailed/src/pow.js': { | ||
belongsTo: 'tests/fixtures/detailed/index.js', | ||
bytes: 67, | ||
format: 'esm', | ||
imports: [] | ||
} | ||
}, | ||
{ | ||
detailed: false | ||
} | ||
); | ||
} ); | ||
|
||
it( 'passes options to the `generateReportFromAssets` function', async () => { | ||
const options: Partial<Options> = { | ||
format: 'json', | ||
open: false | ||
}; | ||
|
||
await esbuild.build( { | ||
entryPoints: [ join( import.meta.dirname, 'fixtures/bundlers/index.js' ) ], | ||
bundle: true, | ||
outfile: join( import.meta.dirname, 'dist/esbuild_2.js' ), | ||
sourcemap: true, | ||
plugins: [ SondaEsbuildPlugin( options ) ], | ||
format: 'esm', | ||
} ); | ||
|
||
expect( mocks.generateReportFromAssets ).toHaveBeenCalledWith( | ||
expect.any( Array ), | ||
expect.any( Object ), | ||
{ ...options, detailed: false } | ||
); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { vi, describe, it, expect } from 'vitest'; | ||
import { join } from 'path'; | ||
import { rollup } from 'rollup'; | ||
import { SondaRollupPlugin } from '../src/bundlers/rollup'; | ||
import type { Options } from '../src/types'; | ||
|
||
const mocks = vi.hoisted( () => ( { | ||
generateReportFromAssets: vi.fn().mockResolvedValue( undefined ) | ||
} ) ); | ||
|
||
vi.mock( '../src/report/generate.js', () => ( { | ||
generateReportFromAssets: mocks.generateReportFromAssets | ||
} ) ); | ||
|
||
describe( 'SondaRollupPlugin', () => { | ||
it( 'should transform the code correctly', async () => { | ||
const bundle = await rollup( { | ||
input: join( import.meta.dirname, 'fixtures/bundlers/index.js' ), | ||
plugins: [ | ||
SondaRollupPlugin() | ||
], | ||
} ); | ||
|
||
/** | ||
* `write` method is used instead of the `generate`, because | ||
* the latter would not trigger the `writeBundle` hook. | ||
*/ | ||
await bundle.write( { | ||
file: join( import.meta.dirname, 'dist/rollup_1.js' ), | ||
sourcemap: true, | ||
format: 'es', | ||
} ); | ||
|
||
expect( mocks.generateReportFromAssets ).toHaveBeenCalledWith( | ||
[ | ||
join( import.meta.dirname, 'dist/rollup_1.js' ), | ||
join( import.meta.dirname, 'dist/rollup_1.js.map' ) | ||
], | ||
{ | ||
'tests/fixtures/bundlers/index.js': { | ||
belongsTo: null, | ||
bytes: 66, | ||
format: 'esm', | ||
imports: [ 'tests/fixtures/detailed/index.js' ] | ||
}, | ||
'tests/fixtures/detailed/index.js': { | ||
belongsTo: null, | ||
bytes: 238, | ||
format: 'esm', | ||
imports: [] | ||
} | ||
}, | ||
{} | ||
); | ||
} ); | ||
|
||
it( 'passes options to the `generateReportFromAssets` function', async () => { | ||
const options: Partial<Options> = { | ||
format: 'json', | ||
open: false | ||
}; | ||
|
||
const bundle = await rollup( { | ||
input: join( import.meta.dirname, 'fixtures/bundlers/index.js' ), | ||
plugins: [ SondaRollupPlugin( options ) ], | ||
} ); | ||
|
||
/** | ||
* `write` method is used instead of the `generate`, because | ||
* the latter would not trigger the `writeBundle` hook. | ||
*/ | ||
await bundle.write( { | ||
file: join( import.meta.dirname, 'dist/rollup_2.js' ), | ||
sourcemap: true, | ||
format: 'es', | ||
} ); | ||
|
||
expect( mocks.generateReportFromAssets ).toHaveBeenCalledWith( | ||
expect.any( Array ), | ||
expect.any( Object ), | ||
options | ||
); | ||
} ); | ||
} ); |
Oops, something went wrong.