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

Test bundler module res #124

Merged
merged 21 commits into from
Oct 6, 2023
Merged

Test bundler module res #124

merged 21 commits into from
Oct 6, 2023

Conversation

anncatton
Copy link
Contributor

@anncatton anncatton commented Oct 5, 2023

Converting all apps and packages to use the ESM format, EXCLUDING consent-ui. This is the general direction JS is moving and we have already run into issues with newer versions of external libraries, i.e. url-join and nanoid.

Change summary:

package.json files:

  • type: module
  • enforce node version 18 or higher (with .npmrc engine-strict=true setting)
  • set apps' "exports" to null as these shouldn't need to be imported anywhere
  • switch "main" to "exports" field to match esm recommendation
  • for all apps, start script will use ts-node to run from the src folder to avoid an issue encountered with the prisma generated client folder, which was not being added to the dist folder on build, as per @justincorrigible 's suggestion
  • updates all "workspace:^" references to use the ^ instead of * syntax, for consistency. This is how it appears when installing a local package with pnpm add <package>

tsconfig.base.json:

  • default module and moduleResolution settings will be NodeNext as recommended here, target becomes ESNext

extended tsconfig.json files:

  • set tsnode.esm to true, cannot run without this
  • set tsnode.logError to true to prevent apps running start script with ts-node from crashing if any type errors are encountered

consent-ui:

  • overriding the base tsconfig with the Bundler option recommended here, to continue taking advantage of nextjs magic.
  • not setting this app as type: module because this broke the postcss/tailwind styles
  • removed the @ alias for absolute imports, but will continue using this kind of import here

General:

  • removes absolute paths as these do not work with esm modules.
  • adds a .js file extensions to all imports, the path cannot be resolved properly otherwise
  • adds version import from package.json in all apps. assert { type: 'json' } required on the import to align with changes in Node 17, as mentioned here
  • sets all package versions to 0.1.0

Packages:

  • common renamed to types
  • restructured types folders
  • modified types package.json to allow submodule imports, and updates all import statements

Documentation will be added for all of this in #128

@@ -35,7 +36,7 @@ const LocalizedLink = ({
...rest
}: LocalizedLinkProps) => {
let locale = linkLang;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haven't found a nice way to import these routes, so far only a json file has worked with the nextjs.config rewrites. Adding a TODO to look at a way to get rid of the as here

@anncatton anncatton marked this pull request as ready for review October 5, 2023 19:20

import { version } from '@/../../package.json';
import logger from '@/logger';
import packageJson from '../../package.json' assert { type: 'json' };
Copy link
Contributor

@justincorrigible justincorrigible Oct 5, 2023

Choose a reason for hiding this comment

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

these absolute import paths can be troubleshot. I have a fix for them (to be applied in the next PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joneubank pointed out that absolute paths, while looking nice and tidy, can actually add confusion, and the esm standard is for relative paths anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

they can also cleanup in some cases. ideally we could use both.

Copy link
Contributor

@justincorrigible justincorrigible Oct 5, 2023

Choose a reason for hiding this comment

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

you're right, relative is the ESM standard, but they make PR reviewing (as you don't have a full IDE in github), and they also make app onboarding so much harder (chasing the "dot dot rabbit" down its hole, vs "ah, this comes from the global utils" at first glance).

besides, just like having types in a js file (which is not js spec either), absolute paths are something we can handle through TS transpilation

@@ -1,4 +1,4 @@
import { Prisma, ConsentCategory } from '../../src/generated/client';
import { Prisma, ConsentCategory } from '../../src/generated/client/index.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

oof. now this one "requirement" will sting for a lot of people 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yuuuuup.


import { ValidLanguage } from '@/i18n';
import ConsentForm from '@/components/ConsentForm';
import { ValidLanguage } from 'src/i18n';
Copy link
Contributor

Choose a reason for hiding this comment

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

does this absolute path work because of nextjs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes appears it is nextjs + the bundler setting magic

"node": ">=18"
},
"node": ">=18"
},
Copy link
Contributor

@justincorrigible justincorrigible Oct 6, 2023

Choose a reason for hiding this comment

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

curious about this change. is this project using tabs or spaces?

edit: checked, it's spaces. I was under the impression we were going to use tabs in all new projects 🤔
did we change direction?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the linter settings (which apply things like tabs instead of spaces on fix-on-save) haven't been configured for all files in the repo (like package.json files), and when I was initially setting up the repo I was still using spaces so this may be a holdover from back then

In other words... my bad 🙈 This one's totally on me haha

Copy link
Contributor

Choose a reason for hiding this comment

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

absolutely terrible. I'm heartbroken!!
how dare you!? 😂

/s

anncatton and others added 2 commits October 6, 2023 09:07
Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>
mistryrn
mistryrn previously approved these changes Oct 6, 2023
Copy link
Contributor

@mistryrn mistryrn left a comment

Choose a reason for hiding this comment

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

Looks good! Tested locally and confirmed things are still building, running in dev, and now actually running with the start command too 😅 Thanks so much for going down the rabbit holes required to get this all in! 🙌 🙇

Other than the little README update we talked about on Slack, this looks good to go 🚀

README.md Outdated
@@ -41,12 +41,14 @@ The directory structure is as follows:
│ └── src
├── docker-scripts/ ← Docker Init Scripts
└── packages/
├── common/ ← Shared Validation & Types
│ └── src
├── types/ ← Shared Validation & Types/
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Looks like we've got some rogue trailing slashes here: & Types/, Logger/, APIs/ -- also do you mind putting these in alphabetical order like they appear in the directory?

mistryrn
mistryrn previously approved these changes Oct 6, 2023
Copy link
Contributor

@mistryrn mistryrn left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Contributor

@mistryrn mistryrn left a comment

Choose a reason for hiding this comment

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

🚀 (for reals this time)

@anncatton anncatton merged commit 4abd47e into develop Oct 6, 2023
3 checks passed
@anncatton anncatton deleted the test-bundler-module-res branch October 6, 2023 16:57
@anncatton anncatton restored the test-bundler-module-res branch October 6, 2023 16:57
@anncatton anncatton deleted the test-bundler-module-res branch October 6, 2023 16:57
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.

4 participants