From 9455a27e70ecdc30def3adaee866134dd01cecfc Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 18 Dec 2023 11:13:08 -0800 Subject: [PATCH 1/5] Add `resolveImplementationPackageForTypesPackage` util --- packages/core/src/createPackage.ts | 88 +++++++++++++++++------------- 1 file changed, 51 insertions(+), 37 deletions(-) diff --git a/packages/core/src/createPackage.ts b/packages/core/src/createPackage.ts index e42c61d..519ee07 100644 --- a/packages/core/src/createPackage.ts +++ b/packages/core/src/createPackage.ts @@ -106,15 +106,10 @@ export async function createPackageFromNpm( throw new Error(parsed.error); } const packageName = parsed.data.name; - const specs = + const { tarballUrl, packageVersion } = parsed.data.versionKind === "none" && typeof definitelyTyped === "string" - ? [ - parsePackageSpec(`${packageName}@${major(definitelyTyped)}.${minor(definitelyTyped)}`).data!, - parsePackageSpec(`${packageName}@${major(definitelyTyped)}`).data!, - parsePackageSpec(`${packageName}@latest`).data!, - ] - : [parsed.data]; - const { tarballUrl, packageVersion } = await getNpmTarballUrl(specs, before); + ? await resolveImplementationPackageForTypesPackage(packageName, definitelyTyped, { before }) + : await getNpmTarballUrl([parsed.data], before); const pkg = await createPackageFromTarballUrl(tarballUrl); if (!definitelyTyped || pkg.containsTypes()) { return pkg; @@ -143,43 +138,62 @@ export async function createPackageFromNpm( return pkg; } +export async function resolveImplementationPackageForTypesPackage( + typesPackageName: string, + typesPackageVersion: string, + options?: Pick, +): Promise { + if (!typesPackageName.startsWith("@types/")) { + throw new Error(`'resolveImplementationPackageForTypesPackage' expects an @types package name and version`); + } + const packageName = ts.unmangleScopedPackageName(typesPackageName.slice("@types/".length)); + return getNpmTarballUrl( + [ + parsePackageSpec(`${packageName}@${major(typesPackageVersion)}.${minor(typesPackageVersion)}`).data!, + parsePackageSpec(`${packageName}@${major(typesPackageVersion)}`).data!, + parsePackageSpec(`${packageName}@latest`).data!, + ], + options?.before, + ); +} + export async function resolveTypesPackageForPackage( packageName: string, packageVersion: string, before?: Date, -): Promise<{ packageName: string; packageVersion: string; tarballUrl: string } | undefined> { +): Promise { const typesPackageName = ts.getTypesPackageName(packageName); try { - return { - packageName: typesPackageName, - ...(await getNpmTarballUrl( - [ - { - name: typesPackageName, - versionKind: "range", - version: `${major(packageVersion)}.${minor(packageVersion)}`, - }, - { - name: typesPackageName, - versionKind: "range", - version: `${major(packageVersion)}`, - }, - { - name: typesPackageName, - versionKind: "tag", - version: "latest", - }, - ], - before, - )), - }; + return await getNpmTarballUrl( + [ + { + name: typesPackageName, + versionKind: "range", + version: `${major(packageVersion)}.${minor(packageVersion)}`, + }, + { + name: typesPackageName, + versionKind: "range", + version: `${major(packageVersion)}`, + }, + { + name: typesPackageName, + versionKind: "tag", + version: "latest", + }, + ], + before, + ); } catch {} } -async function getNpmTarballUrl( - packageSpecs: readonly ParsedPackageSpec[], - before?: Date, -): Promise<{ tarballUrl: string; packageVersion: string }> { +export interface ResolvedPackageId { + packageName: string; + packageVersion: string; + tarballUrl: string; +} + +async function getNpmTarballUrl(packageSpecs: readonly ParsedPackageSpec[], before?: Date): Promise { const fetchPackument = packageSpecs.some( (spec) => spec.versionKind === "range" || (spec.versionKind === "tag" && spec.version !== "latest"), ); @@ -227,7 +241,7 @@ async function getNpmTarballUrl( } if (packageVersion && tarballUrl) { - return { packageVersion, tarballUrl }; + return { packageName: packageSpec.name, packageVersion, tarballUrl }; } } throw new Error(`Failed to find a matching version for ${packageSpecs[0].name}`); From 4e7c0dddb789cef833ba99a866098f82c34704a9 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 18 Dec 2023 11:13:51 -0800 Subject: [PATCH 2/5] Add changeset --- .changeset/green-crews-dream.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/green-crews-dream.md diff --git a/.changeset/green-crews-dream.md b/.changeset/green-crews-dream.md new file mode 100644 index 0000000..be70059 --- /dev/null +++ b/.changeset/green-crews-dream.md @@ -0,0 +1,5 @@ +--- +"@arethetypeswrong/core": patch +--- + +Add `resolveImplementationPackageForTypesPackage` util From 0257134310e336995759a1e598c997a97c026a83 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 18 Dec 2023 11:14:58 -0800 Subject: [PATCH 3/5] Add tsup to recognized build tools --- packages/core/src/types.ts | 3 ++- packages/core/src/utils.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 097f4ca..9c428fe 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -35,7 +35,8 @@ export type BuildTool = | "microbundle" | "@microsoft/api-extractor" | "tshy" - | "@rspack/cli"; + | "@rspack/cli" + | "tsup"; export interface Analysis { packageName: string; diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index eb1ee30..4105074 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -166,4 +166,5 @@ export const allBuildTools = Object.keys({ "@microsoft/api-extractor": true, tshy: true, "@rspack/cli": true, + tsup: true, } satisfies Record) as BuildTool[]; From fffff4d5928627bfd6fe42360cdd5b9f467c6566 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 18 Dec 2023 11:15:24 -0800 Subject: [PATCH 4/5] Add changeset --- .changeset/clever-ants-raise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/clever-ants-raise.md diff --git a/.changeset/clever-ants-raise.md b/.changeset/clever-ants-raise.md new file mode 100644 index 0000000..de1692a --- /dev/null +++ b/.changeset/clever-ants-raise.md @@ -0,0 +1,5 @@ +--- +"@arethetypeswrong/core": patch +--- + +Add tsup to recognized build tools From 2ccf89899daf31f77a18a74cbf12e7a71fcf5ec8 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 18 Dec 2023 11:28:03 -0800 Subject: [PATCH 5/5] Update snapshots --- .../cli/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.md | 1 + .../test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cli/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.md b/packages/cli/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.md index 72d2604..3c44065 100644 --- a/packages/cli/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.md +++ b/packages/cli/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.md @@ -9,6 +9,7 @@ $ attw @reduxjs__toolkit@2.0.0-beta.0.tgz -f table-flipped Build tools: - typescript@~4.9 - @microsoft/api-extractor@^7.13.2 +- tsup@^6.7.0 🎭 Import resolved to a CommonJS type declaration file, but an ESM JavaScript file. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md diff --git a/packages/core/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.json b/packages/core/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.json index d8e8e98..a58dddb 100644 --- a/packages/core/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.json +++ b/packages/core/test/snapshots/@reduxjs__toolkit@2.0.0-beta.0.tgz.json @@ -6,7 +6,8 @@ }, "buildTools": { "typescript": "~4.9", - "@microsoft/api-extractor": "^7.13.2" + "@microsoft/api-extractor": "^7.13.2", + "tsup": "^6.7.0" }, "entrypoints": { "./package.json": {