Skip to content

feat: Add import path alias.#247

Merged
cullylarson merged 11 commits intocanaryfrom
feature/add-path-alias
Feb 14, 2022
Merged

feat: Add import path alias.#247
cullylarson merged 11 commits intocanaryfrom
feature/add-path-alias

Conversation

@cullylarson
Copy link
Copy Markdown
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
Copy Markdown
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.

"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
Copy Markdown
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.

"typeRoots": ["node_modules/@types", "types"],
"rootDir": "."
"rootDir": ".",
"baseUrl": ".",
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread README.md
- 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
Copy Markdown
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