@@ -745,3 +745,110 @@ it('can bundle a tsconfig-build-json project', async () => {
745
745
cwd : path . resolve ( fixturesFolder , 'simple' ) ,
746
746
} ) ;
747
747
} ) ;
748
+
749
+ it ( 'can bundle a simple project with additional exports' , async ( ) => {
750
+ const proj = path . join ( fixturesFolder , 'simple-exports' ) ;
751
+ const dist = path . join ( proj , 'dist' ) ;
752
+
753
+ await fse . remove ( dist ) ;
754
+
755
+ await expect ( execa ( 'node' , [ binaryFolder , 'build' ] , { cwd : proj } ) ) . resolves . toEqual (
756
+ expect . objectContaining ( {
757
+ exitCode : 0 ,
758
+ } ) ,
759
+ ) ;
760
+
761
+ await expect ( fse . readFile ( path . join ( dist , 'cjs' , 'index.js' ) , 'utf8' ) ) . resolves
762
+ . toMatchInlineSnapshot ( `
763
+ "use strict";
764
+ Object.defineProperty(exports, "__esModule", { value: true });
765
+ exports.someLetter = void 0;
766
+ exports.someLetter = 'a';
767
+ exports.default = { b: 'c' };
768
+ ` ) ;
769
+ await expect ( fse . readFile ( path . join ( dist , 'typings' , 'index.d.ts' ) , 'utf8' ) ) . resolves
770
+ . toMatchInlineSnapshot ( `
771
+ export declare const someLetter = "a";
772
+ declare const _default: {
773
+ b: string;
774
+ };
775
+ export default _default;
776
+ ` ) ;
777
+ await expect ( fse . readFile ( path . join ( dist , 'esm' , 'index.js' ) , 'utf8' ) ) . resolves
778
+ . toMatchInlineSnapshot ( `
779
+ export var someLetter = 'a';
780
+ export default { b: 'c' };
781
+ ` ) ;
782
+
783
+ await expect ( fse . readFile ( path . join ( dist , 'cjs' , 'sub' , 'index.js' ) , 'utf8' ) ) . resolves
784
+ . toMatchInlineSnapshot ( `
785
+ "use strict";
786
+ Object.defineProperty(exports, "__esModule", { value: true });
787
+ exports.someOtherLetter = void 0;
788
+ exports.someOtherLetter = 'd';
789
+ exports.default = { e: 'f' };
790
+ ` ) ;
791
+ await expect ( fse . readFile ( path . join ( dist , 'typings' , 'sub' , 'index.d.ts' ) , 'utf8' ) ) . resolves
792
+ . toMatchInlineSnapshot ( `
793
+ export declare const someOtherLetter = "d";
794
+ declare const _default: {
795
+ e: string;
796
+ };
797
+ export default _default;
798
+ ` ) ;
799
+ await expect ( fse . readFile ( path . join ( dist , 'esm' , 'sub' , 'index.js' ) , 'utf8' ) ) . resolves
800
+ . toMatchInlineSnapshot ( `
801
+ export var someOtherLetter = 'd';
802
+ export default { e: 'f' };
803
+ ` ) ;
804
+
805
+ await expect ( fse . readFile ( path . join ( dist , 'package.json' ) , 'utf8' ) ) . resolves
806
+ . toMatchInlineSnapshot ( `
807
+ {
808
+ "name": "simple-exports",
809
+ "engines": {
810
+ "node": ">= 12.0.0"
811
+ },
812
+ "main": "cjs/index.js",
813
+ "module": "esm/index.js",
814
+ "typings": "typings/index.d.ts",
815
+ "typescript": {
816
+ "definition": "typings/index.d.ts"
817
+ },
818
+ "type": "module",
819
+ "exports": {
820
+ ".": {
821
+ "require": {
822
+ "types": "./typings/index.d.cts",
823
+ "default": "./cjs/index.js"
824
+ },
825
+ "import": {
826
+ "types": "./typings/index.d.ts",
827
+ "default": "./esm/index.js"
828
+ },
829
+ "default": {
830
+ "types": "./typings/index.d.ts",
831
+ "default": "./esm/index.js"
832
+ }
833
+ },
834
+ "./sub": {
835
+ "require": {
836
+ "types": "./typings/sub/index.d.cts",
837
+ "default": "./cjs/sub/index.js"
838
+ },
839
+ "import": {
840
+ "types": "./typings/sub/index.d.ts",
841
+ "default": "./esm/sub/index.js"
842
+ },
843
+ "default": {
844
+ "types": "./typings/sub/index.d.ts",
845
+ "default": "./esm/sub/index.js"
846
+ }
847
+ },
848
+ "./package.json": "./package.json"
849
+ }
850
+ }
851
+ ` ) ;
852
+
853
+ await execa ( 'node' , [ binaryFolder , 'check' ] , { cwd : proj } ) ;
854
+ } ) ;
0 commit comments