|
1 |
| -import {semverUtils} from '@yarnpkg/core'; |
| 1 | +import {miscUtils, semverUtils} from '@yarnpkg/core'; |
2 | 2 | import {PortablePath, npath, toFilename, xfs, ppath, Filename} from '@yarnpkg/fslib';
|
3 | 3 | import {npmAuditTypes} from '@yarnpkg/plugin-npm-cli';
|
4 | 4 | import assert from 'assert';
|
@@ -60,27 +60,33 @@ export enum RequestType {
|
60 | 60 | }
|
61 | 61 |
|
62 | 62 | export type Request = {
|
| 63 | + registry?: string; |
63 | 64 | type: RequestType.Login;
|
64 | 65 | username: string;
|
65 | 66 | } | {
|
| 67 | + registry?: string; |
66 | 68 | type: RequestType.PackageInfo;
|
67 | 69 | scope?: string;
|
68 | 70 | localName: string;
|
69 | 71 | } | {
|
| 72 | + registry?: string; |
70 | 73 | type: RequestType.PackageTarball;
|
71 | 74 | scope?: string;
|
72 | 75 | localName: string;
|
73 | 76 | version?: string;
|
74 | 77 | } | {
|
| 78 | + registry?: string; |
75 | 79 | type: RequestType.Whoami;
|
76 | 80 | login: Login;
|
77 | 81 | } | {
|
78 | 82 | type: RequestType.Repository;
|
79 | 83 | } | {
|
| 84 | + registry?: string; |
80 | 85 | type: RequestType.Publish;
|
81 | 86 | scope?: string;
|
82 | 87 | localName: string;
|
83 | 88 | } | {
|
| 89 | + registry?: string; |
84 | 90 | type: RequestType.BulkAdvisories;
|
85 | 91 | };
|
86 | 92 |
|
@@ -160,6 +166,12 @@ export const validLogins = {
|
160 | 166 | let whitelist = new Map();
|
161 | 167 | let recording: Array<Request> | null = null;
|
162 | 168 |
|
| 169 | +export function sortJson<T>(data: Iterable<T>): Array<T> { |
| 170 | + return miscUtils.sortMap(data, request => { |
| 171 | + return JSON.stringify(request); |
| 172 | + }); |
| 173 | +} |
| 174 | + |
163 | 175 | export const startRegistryRecording = async (
|
164 | 176 | fn: () => Promise<void>,
|
165 | 177 | ) => {
|
@@ -573,51 +585,65 @@ export const startPackageServer = ({type}: { type: keyof typeof packageServerUrl
|
573 | 585 | return {
|
574 | 586 | type: RequestType.Repository,
|
575 | 587 | };
|
576 |
| - } else if ((match = url.match(/^\/-\/user\/org\.couchdb\.user:(.+)/))) { |
577 |
| - const [, username] = match; |
578 |
| - |
579 |
| - return { |
580 |
| - type: RequestType.Login, |
581 |
| - username, |
582 |
| - }; |
583 |
| - } else if (url === `/-/whoami`) { |
584 |
| - return { |
585 |
| - type: RequestType.Whoami, |
586 |
| - // Set later when login is parsed |
587 |
| - login: null as any, |
588 |
| - }; |
589 |
| - } else if (url === `/-/npm/v1/security/advisories/bulk`) { |
590 |
| - return { |
591 |
| - type: RequestType.BulkAdvisories, |
592 |
| - }; |
593 |
| - } else if ((match = url.match(/^\/(?:(@[^/]+)\/)?([^@/][^/]*)$/)) && method == `PUT`) { |
594 |
| - const [, scope, localName] = match; |
595 |
| - |
596 |
| - return { |
597 |
| - type: RequestType.Publish, |
598 |
| - scope, |
599 |
| - localName, |
600 |
| - }; |
601 |
| - } else if ((match = url.match(/^\/(?:(@[^/]+)\/)?([^@/][^/]*)$/))) { |
602 |
| - const [, scope, localName] = match; |
603 |
| - |
604 |
| - return { |
605 |
| - type: RequestType.PackageInfo, |
606 |
| - scope, |
607 |
| - localName, |
608 |
| - }; |
609 |
| - } else if ((match = url.match(/^\/(?:(@[^/]+)\/)?([^@/][^/]*)\/(-|tralala)\/\2-(.*)\.tgz$/))) { |
610 |
| - const [, scope, localName, split, version] = match; |
| 588 | + } else { |
| 589 | + let registry: {registry: string} | undefined; |
| 590 | + if ((match = url.match(/^\/registry\/([a-z]+)\//))) { |
| 591 | + url = url.slice(match[0].length - 1); |
| 592 | + registry = {registry: match[1]}; |
| 593 | + } |
611 | 594 |
|
612 |
| - if ((localName === `unconventional-tarball` || localName === `private-unconventional-tarball`) && split === `-`) |
613 |
| - return null; |
| 595 | + if ((match = url.match(/^\/-\/user\/org\.couchdb\.user:(.+)/))) { |
| 596 | + const [, username] = match; |
614 | 597 |
|
615 |
| - return { |
616 |
| - type: RequestType.PackageTarball, |
617 |
| - scope, |
618 |
| - localName, |
619 |
| - version, |
620 |
| - }; |
| 598 | + return { |
| 599 | + ...registry, |
| 600 | + type: RequestType.Login, |
| 601 | + username, |
| 602 | + }; |
| 603 | + } else if (url === `/-/whoami`) { |
| 604 | + return { |
| 605 | + ...registry, |
| 606 | + type: RequestType.Whoami, |
| 607 | + // Set later when login is parsed |
| 608 | + login: null as any, |
| 609 | + }; |
| 610 | + } else if (url === `/-/npm/v1/security/advisories/bulk`) { |
| 611 | + return { |
| 612 | + ...registry, |
| 613 | + type: RequestType.BulkAdvisories, |
| 614 | + }; |
| 615 | + } else if ((match = url.match(/^\/(?:(@[^/]+)\/)?([^@/][^/]*)$/)) && method == `PUT`) { |
| 616 | + const [, scope, localName] = match; |
| 617 | + |
| 618 | + return { |
| 619 | + ...registry, |
| 620 | + type: RequestType.Publish, |
| 621 | + scope, |
| 622 | + localName, |
| 623 | + }; |
| 624 | + } else if ((match = url.match(/^\/(?:(@[^/]+)\/)?([^@/][^/]*)$/))) { |
| 625 | + const [, scope, localName] = match; |
| 626 | + |
| 627 | + return { |
| 628 | + ...registry, |
| 629 | + type: RequestType.PackageInfo, |
| 630 | + scope, |
| 631 | + localName, |
| 632 | + }; |
| 633 | + } else if ((match = url.match(/^\/(?:(@[^/]+)\/)?([^@/][^/]*)\/(-|tralala)\/\2-(.*)\.tgz$/))) { |
| 634 | + const [, scope, localName, split, version] = match; |
| 635 | + |
| 636 | + if ((localName === `unconventional-tarball` || localName === `private-unconventional-tarball`) && split === `-`) |
| 637 | + return null; |
| 638 | + |
| 639 | + return { |
| 640 | + ...registry, |
| 641 | + type: RequestType.PackageTarball, |
| 642 | + scope, |
| 643 | + localName, |
| 644 | + version, |
| 645 | + }; |
| 646 | + } |
621 | 647 | }
|
622 | 648 |
|
623 | 649 | return null;
|
|
0 commit comments