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

feat: Add import path alias. #247

Merged
merged 11 commits into from
Feb 14, 2022
Merged

feat: Add import path alias. #247

merged 11 commits into from
Feb 14, 2022

Conversation

cullylarson
Copy link
Contributor

Adds a @/ path alias.

Changes

  • Add path alias to tsconfig.
  • Update jest config to include the path alias from tsconfig.
  • Update all import paths to work with the new alias.
  • Update the ts-node npm script to work with the path alias.

Checklist

  • Requires dependency update?
  • Generating a new app works.
  • Jest and e2e tests pass.
  • Prisma, nexus, etc. builds run.
  • Database migrations, seeds, etc. run.

Comment on lines +262 to +263
type: 'ProfileRelationalCreateInput',
});
Copy link
Contributor Author

@cullylarson cullylarson Feb 9, 2022

Choose a reason for hiding this comment

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

These are changes that will end up in the created app after the initial commit (potentially from something like an eslint --fix). So just made them here so there aren't uncommitted changes just after creating the app.

I.e. you create a bison app, it sets up your repo, builds the project, etc., you cd into the project folder and git status, you'll see some uncommitted changes.

@@ -41,7 +41,7 @@
"test:e2e": "cross-env DOTENV_CONFIG_PATH=.env.test ts-node -r dotenv/config $(yarn bin)/start-server-and-test 'yarn test:server' http://localhost:3001 'yarn cypress:run'",
"test:e2e:local": "cross-env CYPRESS_LOCAL=true CYPRESS_BASE_URL=http://localhost:3000 cypress open",
"test:server": "next start --port 3001",
"ts-node": "ts-node-dev --project tsconfig.cjs.json",
"ts-node": "ts-node-dev --project tsconfig.cjs.json -r tsconfig-paths/register",
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 what makes ts-node work with the path alias. Without it, none of the scripts run with ts-node would be able to use path aliases.

@@ -17,7 +17,11 @@
"sourceMap": true,
"plugins": [{ "name": "nexus/typescript-language-service" }],
"typeRoots": ["node_modules/@types", "types"],
"rootDir": "."
"rootDir": ".",
"baseUrl": ".",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason tsconfig-paths/register won't work without a baseUrl set.

@cullylarson cullylarson changed the title feat: Add path alias. feat: Add import path alias. Feb 9, 2022
Copy link
Contributor

@code-jenn-or code-jenn-or left a comment

Choose a reason for hiding this comment

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

Thanks for taking the lead on this one! Only thing I think we should do is provide a blurb in the readme for bison users to understand our move to using alias'd paths.

@@ -24,6 +24,7 @@ We're always improving on this, and we welcome suggestions from the community!
- Customizable [Hygen Templates](https://www.hygen.io/) to generate new files
- Fully wired up login/signup pages with client and server-side validation.
- Eslint pre-configured with [Echobind best practices](https://github.com/echobind/eslint-plugin-echobind)
- Import path alias to the root project folder (`@/`) to avoid the need for long relative import paths.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perfecto! Thanks for adding this.

@cullylarson cullylarson merged commit 1e5de2c into canary Feb 14, 2022
@cullylarson cullylarson deleted the feature/add-path-alias branch February 14, 2022 23:32
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.

3 participants