Skip to content

Commit

Permalink
[cli] Replace psl with tldts (#12174)
Browse files Browse the repository at this point in the history
`psl` is one of the deps causing the `punycode` deprecation warning on
Node 22. [The newest version includes the deprecation
warning](lupomontero/psl#323), so we can't
just update `psl`.

Inspired by salesforce/tough-cookie#346.
  • Loading branch information
onsclom authored Sep 27, 2024
1 parent f197d82 commit fd86f5d
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 51 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-books-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vercel': patch
---

Replace `psl` with `tldts` for domain parsing
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"@types/node-fetch": "2.5.10",
"@types/npm-package-arg": "6.1.0",
"@types/pluralize": "0.0.29",
"@types/psl": "1.1.0",
"@types/qs": "6.9.7",
"@types/semver": "6.0.1",
"@types/split2": "4.2.3",
Expand Down Expand Up @@ -155,7 +154,6 @@
"promisepipe": "3.0.0",
"proxy": "2.0.0",
"proxy-agent": "6.3.0",
"psl": "1.1.31",
"qr-image": "3.2.0",
"raw-body": "2.4.1",
"rimraf": "3.0.2",
Expand All @@ -166,6 +164,7 @@
"supports-hyperlinks": "3.0.0",
"tar-fs": "1.16.3",
"title": "3.4.1",
"tldts": "6.1.47",
"tmp-promise": "1.0.3",
"tree-kill": "1.2.2",
"ts-node": "10.9.1",
Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/commands/certs/issue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from 'psl';
import { getSubdomain } from 'tldts';
import chalk from 'chalk';

import { Output } from '../../util/output';
Expand Down Expand Up @@ -175,14 +175,12 @@ async function runStartOrder(
);
const [header, ...rows] = dnsTable(
pendingChallenges.map(challenge => {
const parsedDomain = parse(challenge.domain);
if (parsedDomain.error) {
const subdomain = getSubdomain(challenge.domain);
if (!subdomain) {
throw new ERRORS.InvalidDomain(challenge.domain);
}
return [
parsedDomain.subdomain
? `_acme-challenge.${parsedDomain.subdomain}`
: `_acme-challenge`,
subdomain ? `_acme-challenge.${subdomain}` : `_acme-challenge`,
'TXT',
challenge.value,
];
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/src/commands/domains/buy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import psl from 'psl';
import { parse } from 'tldts';

import * as ERRORS from '../../util/errors-ts';
import Client from '../../util/client';
Expand Down Expand Up @@ -33,11 +33,7 @@ export default async function buy(
return 1;
}

const parsedDomain = psl.parse(domainName);
if (parsedDomain.error) {
output.error(`The provided domain name ${param(domainName)} is invalid`);
return 1;
}
const parsedDomain = parse(domainName);

const { domain: rootDomain, subdomain } = parsedDomain;
if (subdomain || !rootDomain) {
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/util/certs/get-wildcard-cns-for-alias.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import psl from 'psl';
import { parse } from 'tldts';
import { InvalidDomain } from '../errors-ts';
import isWildcardAlias from '../alias/is-wildcard-alias';
import extractDomain from '../alias/extract-domain';
Expand All @@ -8,10 +8,7 @@ export default function getWildcardCNSForAlias(alias: string) {
return [extractDomain(alias), alias];
}

const parsedDomain = psl.parse(alias);
if (parsedDomain.error) {
throw new InvalidDomain(alias);
}
const parsedDomain = parse(alias);

const { domain, subdomain } = parsedDomain;
if (!domain) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/util/certs/handle-cert-error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ms from 'ms';
import { parse } from 'psl';
import { parse } from 'tldts';
import chalk from 'chalk';
import * as ERRORS from '../errors-ts';
import { Output } from '../output';
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function handleCertError<T>(
`${dnsTable(
cns.map(cn => {
const parsed = parse(cn);
return !parsed.error && parsed.subdomain
return parsed.subdomain
? [parsed.subdomain, 'ALIAS', 'alias.vercel.com']
: ['', 'ALIAS', 'alias.vercel.com'];
})
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/src/util/deploy/generate-cert-for-deploy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import psl from 'psl';
import { parse } from 'tldts';
import { NowError } from '../now-error';
import Client from '../client';
import createCertForCns from '../certs/create-cert-for-cns';
Expand All @@ -11,11 +11,7 @@ export default async function generateCertForDeploy(
deployURL: string
) {
const { output } = client;
const parsedDomain = psl.parse(deployURL);
if (parsedDomain.error) {
return new InvalidDomain(deployURL, parsedDomain.error.message);
}

const parsedDomain = parse(deployURL);
const { domain } = parsedDomain;
if (!domain) {
return new InvalidDomain(deployURL);
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/util/domains/setup-domain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import psl from 'psl';
import { parse } from 'tldts';
import { NowError } from '../now-error';
import type { Domain } from '@vercel-internals/types';
import { Output } from '../output';
Expand Down Expand Up @@ -45,10 +45,7 @@ export default async function setupDomain(
output.debug(
`Domain ${aliasDomain} is not available to be purchased. Trying to add it`
);
const parsedDomain = psl.parse(aliasDomain);
if (parsedDomain.error) {
return new ERRORS.InvalidDomain(alias, parsedDomain.error.message);
}
const parsedDomain = parse(aliasDomain);
if (!parsedDomain.domain) {
return new ERRORS.InvalidDomain(alias);
}
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/util/is-root-domain.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import psl from 'psl';
import { parse } from 'tldts';

export default function isRootDomain(domainName: string) {
const parsedDomain = psl.parse(domainName);
if (parsedDomain.error) {
return false;
}
const parsedDomain = parse(domainName);
const { domain: rootDomain, subdomain } = parsedDomain;
return Boolean(!subdomain && rootDomain);
}
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fd86f5d

Please sign in to comment.