Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f3d202a

Browse files
committedOct 27, 2021
compatibility with explicit extensions imports
1 parent ab6f158 commit f3d202a

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed
 

‎resources/build-npm.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ if (require.main === module) {
1818
fs.rmSync('./npmDist', { recursive: true, force: true });
1919
fs.mkdirSync('./npmDist');
2020

21-
const packageJSON = buildPackageJSON();
22-
2321
const srcFiles = readdirRecursive('./src', { ignoreDir: /^__.*__$/ });
22+
23+
const packageJSON = buildPackageJSON(srcFiles);
24+
2425
for (const filepath of srcFiles) {
2526
const srcPath = path.join('./src', filepath);
2627
const destPath = path.join('./npmDist', filepath);
@@ -91,7 +92,7 @@ function babelBuild(srcPath, options) {
9192
return code + '\n';
9293
}
9394

94-
function buildPackageJSON() {
95+
function buildPackageJSON(srcFiles) {
9596
const packageJSON = JSON.parse(
9697
fs.readFileSync(require.resolve('../package.json'), 'utf-8'),
9798
);
@@ -122,5 +123,19 @@ function buildPackageJSON() {
122123
packageJSON.publishConfig = { tag: publishTag };
123124
}
124125

126+
/**
127+
* This prevents breaking previous versions of imports with explicit extensions
128+
* Like `require("graphql/language/parser.js")`
129+
*/
130+
for (const srcFile of srcFiles) {
131+
if (srcFile.endsWith('.ts')) {
132+
const srcFilePath = srcFile.slice(0, srcFile.length - 3);
133+
packageJSON.exports[`./${srcFilePath}.js`] = {
134+
require: `./${srcFilePath}.js`,
135+
import: `./${srcFilePath}.mjs`,
136+
};
137+
}
138+
}
139+
125140
return packageJSON;
126141
}

0 commit comments

Comments
 (0)
Please sign in to comment.