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

Add script for checking lit.dev redirects #468

Merged
merged 3 commits into from
Sep 1, 2021
Merged

Add script for checking lit.dev redirects #468

merged 3 commits into from
Sep 1, 2021

Conversation

aomarks
Copy link
Member

@aomarks aomarks commented Sep 1, 2021

Custom script for checking lit.dev redirects.

image

It would be nice if we could use the 3rd party link checker we already have for this somehow, but it doesn't support checking for anchors (see stevenvachon/broken-link-checker#108 -- understandable since it would require DOM parsing) which is one of the main failure cases.

Fixes #467 (since we shouldn't need comments if we have the redirects checked in CI).

As part of this, I created a new lit-dev-tools-esm package.

The existing lit-dev-tools package is currently CommonJS, because mostly it is used for Eleventy plugins, and Eleventy doesn't support ES modules (11ty/eleventy#836).

We want ES modules for this new redirect checker script, because it needs to import some ES modules, and that is difficult to do with TypeScript, because TypeScript doesn't allow emitting an actual import statement, which is how CommonJS -> ESM interop works (microsoft/TypeScript#43329).

We also can't really have a mix of CommonJS and ESM in the same package, because the {"type": "module"} field has to be set to one or the other in the package.json. We could use .mjs extensions, but TypeScript won't emit those.

So the simplest solution seems to be to just have two packages!

@github-actions
Copy link

github-actions bot commented Sep 1, 2021

A live preview of this PR will be available at the URL(s) below.
The latest URL will be appended to this comment on each push.
Each build takes ~5-10 minutes, and will 404 until finished.

https://pr468-65e12fc---lit-dev-5ftespv5na-uc.a.run.app/
https://pr468-56cda15---lit-dev-5ftespv5na-uc.a.run.app/
https://pr468-24e8ba2---lit-dev-5ftespv5na-uc.a.run.app/
https://pr468-e20dfb1---lit-dev-5ftespv5na-uc.a.run.app/

@aomarks
Copy link
Member Author

aomarks commented Sep 1, 2021

Actually I'm going to create an ESM package for this, will reopen when ready.

@aomarks aomarks closed this Sep 1, 2021
The lit-dev-tools package is currently CommonJS, because mostly it
is used for Eleventy plugins, and Eleventy doesn't support ES
modules (11ty/eleventy#836).

We want ES modules for this new redirect checker script, because it
needs to import some ES modules, and that is difficult to do with
TypeScript, because TypeScript doesn't allow emitting an actual
`import` statement, which is how CommonJS -> ESM interop works
(microsoft/TypeScript#43329).

We also an't really have a mix of CommonJS and ESM in the same package,
because the {"type": "module"} field has to be set. We could use
.mjs extensions, but TypeScript won't emit those.

So the simplest solution seems to be to just have two packages!
@aomarks
Copy link
Member Author

aomarks commented Sep 1, 2021

Ready for review again.

@aomarks aomarks reopened this Sep 1, 2021
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz left a comment

Choose a reason for hiding this comment

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

LGTM!

const checkRedirect = async (
redirect: string
): Promise<ErrorMessage | typeof OK> => {
if (isUrl(redirect)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Non action thinking out loud: I initially thought "a relative url is a url" so had some confusion, since we are differentiating between absolute URLs and relative URLs with this check.
Comment on L46 helped.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, that is a little confusing. Renamed to isAbsoluteUrl.

@aomarks aomarks merged commit aca82f6 into main Sep 1, 2021
@aomarks aomarks deleted the redirect-checker branch September 1, 2021 19:43
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.

Add comments to docs that cover dev mode warnings
2 participants