Skip to content

Commit bc2be87

Browse files
Merge pull request #66 from HichemTab-tech/fix-compatibility-issues
Fix compatibility issues with default imports vs partial imports
2 parents 7dc6694 + 5a6fd3d commit bc2be87

6 files changed

Lines changed: 14 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"./vite-plugin": {
1717
"types": "./dist/vite-plugin.d.ts",
18-
"import": "./dist/vite-plugin.js",
18+
"import": "./dist/vite-plugin.mjs",
1919
"require": "./dist/vite-plugin.js"
2020
}
2121
},

src/vite-plugin.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PluginOption } from "vite";
22
import { transform } from "./ts-transformer.js";
33

4+
// noinspection JSUnusedGlobalSymbols
45
/**
56
* A function that provides a Vite plugin for transforming TypeScript files at runtime.
67
* The plugin is named "vite-plugin-ts-runtime-picker" and it is enforced to run at the 'pre' stage.
@@ -11,7 +12,7 @@ import { transform } from "./ts-transformer.js";
1112
*
1213
* @returns {PluginOption} A Vite plugin configuration object for handling TypeScript runtime transformations.
1314
*/
14-
function TsRuntimePickerVitePlugin(): PluginOption {
15+
export default function TsRuntimePickerVitePlugin(): PluginOption {
1516
return {
1617
name: "vite-plugin-ts-runtime-picker",
1718
enforce: "pre",
@@ -29,4 +30,4 @@ function TsRuntimePickerVitePlugin(): PluginOption {
2930
} as PluginOption;
3031
}
3132

32-
export { TsRuntimePickerVitePlugin, TsRuntimePickerVitePlugin as default };
33+
export { TsRuntimePickerVitePlugin };

test/vite-plugin.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ describe('TsRuntimePickerVitePlugin', () => {
1515
it('should create a Vite plugin with the correct configuration', () => {
1616
const plugin = TsRuntimePickerVitePlugin();
1717

18+
// @ts-ignore
1819
expect(plugin.name).toBe('vite-plugin-ts-runtime-picker');
20+
// @ts-ignore
1921
expect(plugin.enforce).toBe('pre');
22+
// @ts-ignore
2023
expect(typeof plugin.transform).toBe('function');
2124
});
2225

@@ -25,6 +28,7 @@ describe('TsRuntimePickerVitePlugin', () => {
2528
const code = 'const x = 1;';
2629
const id = 'file.ts';
2730

31+
// @ts-ignore
2832
const result = plugin.transform(code, id);
2933

3034
expect(transformer.transform).toHaveBeenCalledWith(code, id);
@@ -39,6 +43,7 @@ describe('TsRuntimePickerVitePlugin', () => {
3943
const code = 'const x = <div />;';
4044
const id = 'file.tsx';
4145

46+
// @ts-ignore
4247
const result = plugin.transform(code, id);
4348

4449
expect(transformer.transform).toHaveBeenCalledWith(code, id);
@@ -53,6 +58,7 @@ describe('TsRuntimePickerVitePlugin', () => {
5358
const code = 'const x = 1;';
5459
const id = 'file.js';
5560

61+
// @ts-ignore
5662
const result = plugin.transform(code, id);
5763

5864
expect(transformer.transform).not.toHaveBeenCalled();

test/webpack-loader.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('TsRuntimePickerWebpackLoader', () => {
1717

1818
// Create a mock loader context
1919
callback = vi.fn();
20+
// noinspection JSUnusedGlobalSymbols
2021
loaderContext = {
2122
resourcePath: 'file.ts',
2223
async: () => callback

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "ESNext", // Use the latest JavaScript features
4-
"module": "CommonJS", // Use ESNext modules
4+
"module": "ESNext", // Use ESNext modules
55
"moduleResolution": "Node", // Resolve modules using Node.js rules
66
"lib": ["ESNext", "DOM"], // Include necessary libraries
77
"outDir": "./dist", // Output directory

vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export default defineConfig({
1818
'vite-plugin': resolve(__dirname, 'src/vite-plugin.ts'),
1919
'webpack-loader': resolve(__dirname, 'src/webpack-loader.ts')
2020
},
21-
formats: ['cjs'],
22-
fileName: (_format, entryName) => `${entryName}.js`
21+
formats: ['cjs', 'es'],
22+
fileName: (format, entryName) => `${entryName}.${format === 'es' ? 'mjs' : 'js'}`
2323
},
2424
outDir: 'dist',
2525
emptyOutDir: true,

0 commit comments

Comments
 (0)