Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support require to internal files without explicitly writing .js in the path #8660

Merged
merged 1 commit into from Feb 17, 2022

Conversation

giladgd
Copy link
Contributor

@giladgd giladgd commented Feb 17, 2022

Description of change

Support using require on internal module files without explicitly writing .js at the end of the path.

For example, this code would work now:

// in ESM projects
import {snakeCase} from "typeorm/util/StringUtils.js";

// in CommonJS projects
const {snakeCase: snakeCase1} = require("typeorm/util/StringUtils"); // this line previously thrown an error, this PR fixes that
const {snakeCase: snakeCase2} = require("typeorm/util/StringUtils.js");

console.log(snakeCase === snakeCase1); // true
console.log(snakeCase === snakeCase2); // true

Closes #8656
Closes tonivj5/typeorm-naming-strategies#16

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change - The change in this PR is hard to create a test for from within the module itself, since the exports property in package.json only reflects imports of the module from the outside, and does not affect internal file imports
  • Documentation has been updated to reflect this change - N/A
  • The new commits follow conventions explained in CONTRIBUTING.md

@@ -14,7 +14,12 @@
"import": "./index.mjs",
"require": "./index.js"
},
"./*": "./*"
"./browser": "./browser/index.js",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed since the new "./*" definition would make importing of "typeorm/browser" look for node_modules/typeorm/browser.js instead of node_modules/typeorm/browser/index.js, so this property makes sure importing "typeorm/browser" continues to work properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeORM module resolution issue after 0.2.42 Module not found StringUtils
2 participants