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

[WNMGDS-3028] Updated Angular Example #3358

Merged
merged 40 commits into from
Feb 6, 2025

Conversation

jack-ryan-nava-pbc
Copy link
Collaborator

Summary

A substantial number of changes have been made to enable our custom, preactement-based web component build process, to generate web components that can function when nested inside of other web components, or framework components like those used in Angular. This particular pull request is both proof that things are working (yay!) and a test to see that our web components could be used in a production-like manner.

The examples here are drawn from our existing Angular example but augmented to allow wrapping a la discussions we've had with developers on the CCXP team. The changes here are designed to address concerns by demonstrating example patterns. Specifically we address:

  1. Setting attributes via inputs passed from parent components
  2. Creating re-usable wrappers for our web components
  3. Monitoring and using our custom events in a couple of different ways
  4. Demonstrating that nested web components can alter global state via Outputs
  5. Unwrapped components work out of the box
  6. Analytics events can be listened for, though I have not gotten them to work on ds-dialog or ds-drawer components. Not sure if it's my Angular-fu (minimal) or my analytics-fu (also minimal)
  7. Importing styling and scripts globally via the angular.json file

A thing I need to do yet is update the README.md with some guidance on usage patterns.

What feedback am I looking for here? (listed in descending order of importance)

  1. Are these examples demonstrative of things we want Angular/web component teams to know? (This question is one that will be asked of CCXP.)
  2. Do some of the patterns I used here make sense? (This question is one that will be asked of CCXP.)
  3. What's going on with the Anayltics events on the Dialog and Drawer?
  4. Should I include other components?
  5. Should I wrap all the components?
  6. Does this look like trash? (styling updates maybe?)

How to test

  1. Pull down branch
  2. Build as per usual
  3. Navigate to /examples/angular
  4. yarn build
  5. yarn start
  6. Go to localhost:4200
  7. Observe! Click around. Look in the console! Take time to think.

Checklist

  • Prefixed the PR title with the Jira ticket number as [WNMGDS-####] Title or [NO-TICKET] if this is unticketed work.
  • Selected appropriate Type (only one) label for this PR, if it is a breaking change, label should only be Type: Breaking
  • Selected appropriate Impacts, multiple can be selected.
  • Selected appropriate release milestone

@jack-ryan-nava-pbc jack-ryan-nava-pbc added Impacts: Documentation Indicates that this item relates to documentation Type: Changed Indicates a change to an existing element of the DS. labels Dec 19, 2024
@jack-ryan-nava-pbc jack-ryan-nava-pbc added this to the 12.1.0 milestone Dec 19, 2024
@jack-ryan-nava-pbc jack-ryan-nava-pbc self-assigned this Dec 19, 2024
@jack-ryan-nava-pbc jack-ryan-nava-pbc marked this pull request as ready for review December 19, 2024 21:15
Copy link
Contributor

@pwolfert pwolfert left a comment

Choose a reason for hiding this comment

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

Seems to be working well 👍

Some questions and comments below

@jack-ryan-nava-pbc
Copy link
Collaborator Author

Button text change is working via latest changes here: #3391

@kim-cmsds @tamara-corbalt @pwolfert I'd appreciate another review so we can merge this. We'll get plenty of feedback later from CCXP.

@pwolfert
Copy link
Contributor

Do you get angular-related lockfile changes when you install?

@jack-ryan-nava-pbc
Copy link
Collaborator Author

@pwolfert let me push up that lockfile change

jack-ryan-nava-pbc and others added 4 commits January 27, 2025 13:59
* Auto-update package file commands to use `npm run`

Used the `yarn-to-npm` package for this

* Check in the first version of a package-lock generated by `synp`

using the experimental `--with-workspace` flag

* Fix out-of-sync react type dependency in one child design system

* Deleted and recreated the package-lock.json because of problems

I was not able to move foreward with the auto-migrated lockfile because of errors with `node-gyp` compiling things. I couldn't figure out any way to work around it except to make a fresh start and let the problematic locked dependencies go. Deleting it worked, but now that means we have a brand-new set of resolved dependencies, and that means we'll need to do a lot of thorough testing. I guess we'd need to do thorough testing anyway.

I'm not sure how, but when I run `npm install`, it also updates the `yarn.lock` file. That will at least give us some insights into what dependencies changed. We'll be able to directly compare the original locked dependencies and what we have now by inspecting this difference.

Also need to note here that I had to do the initial npm installation with the `--legacy-peer-deps` flag.

* Update all yarn commands and references to yarn

* Fix a ts-node / chalk error by downgrading `chalk`

All of the scripts that use `ts-node` would give the following error:

```
The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("chalk")' call instead.
  To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field `"type": "module"` to '/Users/patrickwolfert/Projects/design-system/package.json'.

1 import c from 'chalk';
                ~~~~~~~

    at createTSError (/Users/patrickwolfert/Projects/design-system/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/Users/patrickwolfert/Projects/design-system/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/Users/patrickwolfert/Projects/design-system/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/Users/patrickwolfert/Projects/design-system/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/Users/patrickwolfert/Projects/design-system/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/patrickwolfert/Projects/design-system/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1019:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) {
  diagnosticCodes: [ 1479 ]
}
```

I tried changing the tsconfig in several ways. Chalk is used by a mind-boggling number of our dependencies and indirect dependencies. `npm explain chalk` produced over 81,000 lines of output, and `chalk` can be found in our `package-lock.json` file 418 times. The latest version causes problems with ts-node because it only has an ESM version, and ts-node is trying to convert it into CJS for Node. My hypothesis now is that yarn was previously resolving it to the older version, and that's why it worked.

I also saw that we were using an older tsconfig node16 base even though we're on node18 now. I made that dependency explicit.

* Yarn lockfile updated again from chalk changes

I'm taking the opportunity to check this in and write a commit message to confirm that it was indeed resolving to `chalk` 4.1.2 prior to this migration. I checked out the `main` branch and reinstalled and checked the `yarn why chalk` output. The version we were using at the root level, which was getting consumed by `ts-node` and the scripts, was `4.1.2`. That confirms my hypothesis.

* Fix resolution override for react-docgen-typescript

* Get Gatsby to resolve the right version of the `@mdx-js/react`

My dev notes:

NPM is correctly resolving `@mdx-js/react` for the doc site to the version specified in the doc site package file (1.6.22), and it’s putting a `packages/docs/node_modules/@mdx-js/react` in the docs package; however, when I go to build it, it’s using 3.0.0, which is the version resolved in the root node_modules (because that’s what Storybook wants)

I believe that it’s TypeScript that is importing the wrong one, because TypeScript gives me an error about it. I’ve confirmed that it’s using the wrong one at build time because it’s trying to use a function that existed in 1.6.22 but was removed in 3.0 and throws an error

I learned about a `tsc --traceResolution` tool, and it basically told me that it tried 1.6.22, didn’t find any type definitions, and decided to use the project root version instead because it had definitions

I really don’t know why it was working before. It seems like TypeScript was able to import ES modules before this upgrade and now can’t. It’s not like the 1.6.22 type definitions existed in the yarn version. So why is TypeScript only now complaining?

I’ve made progress and also not. I’ve gotten TypeScript and the Gatsby compiler to correctly resolve and use the local 1.6.22 version of `@mdx-js/react` for our direct imports in our docs src, but when our `gatsby-plugin-mdx` (which the npm workspace hoists to the root) tries to import the same thing and use a 1.6.22 feature, it’s resolving to the root (hoisted) version!

Fixed it by telling webpack to always resolve that package to the local version.

I also needed to update the tsconfig so it would import ES modules and not just CJS

Unfortunately `npm run start` still doesn't work because there's something else that is throwing an error. We're a little closer though.

* Fix Gatsby's linter crashing the development server because of outdated plugins

I forced Gatsby to use a stripped-down version of our eslint config instead of its own built-in config, which is very outdated and uses an old version of eslint and an old FlowType plugin that doesn't work. These were some error messages we were getting:

```
ERROR #98123  WEBPACK

Generating development JavaScript bundle failed

Failed to load plugin 'flowtype' declared in 'BaseConfig » /Users/patrickwolfert/Projects/design-system/node_modules/eslint-config-react-app/index.js':
Package subpath './lib/rules/no-unused-expressions' is not defined by "exports" in
/Users/patrickwolfert/Projects/design-system/node_modules/eslint/package.json

failed Building development bundle - 15.275s
ERROR in Failed to load plugin 'flowtype' declared in 'BaseConfig »
/Users/patrickwolfert/Projects/design-system/node_modules/eslint-config-react-app/index.js': Package subpath './lib/rules/no-unused-expressions' is not
defined by "exports" in /Users/patrickwolfert/Projects/design-system/node_modules/eslint/package.json

develop compiled with 1 error
```

* Fix misordered command causing CI failure

* Ah, these commands were still incorrect

* Switch from `ts-node` to `tsx` after running into more ts-node issues with scripts

After fixing the docs issues, our scripts were broken again. TSX just works and doesn't complain about modules vs cjs and things like that.

* All `npm run` scripts need an additional `-- ` when passing args to the underlying command

* Missed the `--` in a couple places

* Missed some places where I needed `--` in the `build-examples.ts` script

* Get rid of the `yarn.lock` file

* Remove yarnrc that we don't need anymore

* Add an undo command per Jack's feedback

* Fix release-script problem that Kim found

* Remove extra yarn lockfiles that Jack found
@jack-ryan-nava-pbc
Copy link
Collaborator Author

@kim-cmsds @tamara-corbalt I've added this ticket to address a bug I found with child accordion elements. I'd like to get this initial work merged in soonish so this doesn't continue to drift and grow.

I think we'll release this in a 12.1.beta release for the CCXP team to consume.

Copy link
Collaborator

@tamara-corbalt tamara-corbalt left a comment

Choose a reason for hiding this comment

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

Everything working well for me!

@jack-ryan-nava-pbc jack-ryan-nava-pbc merged commit 50048fb into main Feb 6, 2025
1 check passed
@jack-ryan-nava-pbc jack-ryan-nava-pbc deleted the jryan/wnmgds-3028-new-angular-example branch February 6, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impacts: Documentation Indicates that this item relates to documentation Type: Changed Indicates a change to an existing element of the DS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants