generated from imranbarbhuiya/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mark polyfills as side-effect free (#141)
- Loading branch information
1 parent
08f9f17
commit 30eda0a
Showing
5 changed files
with
45 additions
and
2 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
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,3 @@ | ||
import { message } from './unusedImport/exports'; | ||
|
||
console.log(message); |
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,3 @@ | ||
export const message = 'Hello world'; | ||
|
||
export { default as assertStrict } from 'node:assert/strict'; |
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,10 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Unused Import Test > GIVEN a file that imports from a module exporting a node builtin and does not use it THEN it should be removed by esbuild 1`] = ` | ||
"// tests/fixtures/input/unusedImport/exports.ts | ||
var message = \\"Hello world\\"; | ||
// tests/fixtures/input/unusedImport.ts | ||
console.log(message); | ||
" | ||
`; |
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,25 @@ | ||
import esbuild, { type BuildOptions } from 'esbuild'; | ||
|
||
import { assertFileContent, buildAbsolutePath, createEsbuildConfig } from '../util'; | ||
|
||
import type { NodePolyfillsOptions } from '../../dist'; | ||
|
||
function createConfig(pluginOptions?: NodePolyfillsOptions): BuildOptions { | ||
return createEsbuildConfig( | ||
{ | ||
format: 'esm', | ||
entryPoints: [buildAbsolutePath('./fixtures/input/unusedImport.ts')], | ||
}, | ||
pluginOptions, | ||
); | ||
} | ||
|
||
describe('Unused Import Test', () => { | ||
test('GIVEN a file that imports from a module exporting a node builtin and does not use it THEN it should be removed by esbuild', async () => { | ||
const config = createConfig(); | ||
|
||
await esbuild.build(config); | ||
|
||
await assertFileContent('./fixtures/output/unusedImport.js'); | ||
}); | ||
}); |