forked from nrwl/nx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(js): fix Rollup plugin to correctly handle .cjs.js and .mjs.js fi…
…le extensions for type definitions. Updated the Rollup plugin's logic for generating type definition files to ensure compatibility with additional file extensions, including .cjs.js and .mjs.js. This change improves the handling of entry points and ensures that corresponding .d.ts files are correctly named and emitted in all supported scenarios. Added a comprehensive test case to validate the new behavior. closed nrwl#29308
- Loading branch information
1 parent
5bdda1d
commit da02a50
Showing
3 changed files
with
75 additions
and
7 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,62 @@ | ||
import { typeDefinitions } from './type-definitions'; | ||
describe('typeDefinitions', () => { | ||
it('should emit correct .d.ts filenames for various file formats', () => { | ||
const mockBundle = { | ||
'index.js': { | ||
type: 'chunk', | ||
isEntry: true, | ||
fileName: 'index.js', | ||
facadeModuleId: '/project/src/index.ts', | ||
exports: ['default', 'namedExport1', 'namedExport2'], | ||
}, | ||
'index1.js': { | ||
type: 'chunk', | ||
isEntry: true, | ||
fileName: 'index.cjs', | ||
facadeModuleId: '/project/src/index.ts', | ||
exports: ['default', 'namedExport1', 'namedExport2'], | ||
}, | ||
'index2.js': { | ||
type: 'chunk', | ||
isEntry: true, | ||
fileName: 'index.mjs', | ||
facadeModuleId: '/project/src/index.ts', | ||
exports: ['default', 'namedExport1', 'namedExport2'], | ||
}, | ||
'index3.js': { | ||
type: 'chunk', | ||
isEntry: true, | ||
fileName: 'index.cjs.js', | ||
facadeModuleId: '/project/src/index.ts', | ||
exports: ['default', 'namedExport1', 'namedExport2'], | ||
}, | ||
'index4.js': { | ||
type: 'chunk', | ||
isEntry: true, | ||
fileName: 'index.mjs.js', | ||
facadeModuleId: '/project/src/index.ts', | ||
exports: ['default', 'namedExport1', 'namedExport2'], | ||
}, | ||
}; | ||
|
||
const mockOpts = {}; // Can be left empty for this scenario | ||
|
||
const mockEmitFile = jest.fn(); | ||
|
||
const plugin = typeDefinitions({ projectRoot: '/project' }); | ||
|
||
// Simulate the `this` context of a Rollup plugin | ||
const mockContext = { | ||
emitFile: mockEmitFile, | ||
}; | ||
|
||
// Run the plugin's `generateBundle` function | ||
(async function testPlugin() { | ||
await plugin.generateBundle.call(mockContext, mockOpts, mockBundle); | ||
|
||
mockEmitFile.mock.calls.forEach(([{ fileName }]) => { | ||
expect(fileName).toBe('index.d.ts'); | ||
}); | ||
})(); | ||
}); | ||
}); |
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