@@ -52,7 +52,7 @@ if (require.main === module) {
52
52
fs . copyFileSync ( './README.md' , './npmDist/README.md' ) ;
53
53
54
54
// Should be done as the last step so only valid packages can be published
55
- const packageJSON = buildPackageJSON ( ) ;
55
+ const packageJSON = buildPackageJSON ( srcFiles ) ;
56
56
writeGeneratedFile ( './npmDist/package.json' , JSON . stringify ( packageJSON ) ) ;
57
57
58
58
showDirStats ( './npmDist' ) ;
@@ -72,7 +72,7 @@ function babelBuild(srcPath, options) {
72
72
return code + '\n' ;
73
73
}
74
74
75
- function buildPackageJSON ( ) {
75
+ function buildPackageJSON ( srcFiles ) {
76
76
const packageJSON = JSON . parse (
77
77
fs . readFileSync ( require . resolve ( '../package.json' ) , 'utf-8' ) ,
78
78
) ;
@@ -103,5 +103,19 @@ function buildPackageJSON() {
103
103
packageJSON . publishConfig = { tag : publishTag } ;
104
104
}
105
105
106
+ /**
107
+ * This prevents breaking previous versions of imports with explicit extensions
108
+ * Like `require("graphql/language/parser.js")`
109
+ */
110
+ for ( const srcFile of srcFiles ) {
111
+ if ( srcFile . endsWith ( '.ts' ) ) {
112
+ const srcFilePath = srcFile . slice ( 0 , srcFile . length - 3 ) ;
113
+ packageJSON . exports [ `./${ srcFilePath } .js` ] = {
114
+ require : `./${ srcFilePath } .js` ,
115
+ import : `./${ srcFilePath } .mjs` ,
116
+ } ;
117
+ }
118
+ }
119
+
106
120
return packageJSON ;
107
121
}
0 commit comments