From 9462f2e8aef018d3e16bb730a24a2f943091d036 Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 24 Sep 2024 14:22:09 +0000 Subject: [PATCH] fix(core): add compatibility types for submodules --- packages/core/account-id-endpoint.d.ts | 7 +++++++ packages/core/client.d.ts | 7 +++++++ packages/core/httpAuthSchemes.d.ts | 7 +++++++ packages/core/package.json | 8 ++++++-- packages/core/protocols.d.ts | 7 +++++++ packages/core/scripts/lint.js | 21 ++++++++++++++++++++- 6 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 packages/core/account-id-endpoint.d.ts create mode 100644 packages/core/client.d.ts create mode 100644 packages/core/httpAuthSchemes.d.ts create mode 100644 packages/core/protocols.d.ts diff --git a/packages/core/account-id-endpoint.d.ts b/packages/core/account-id-endpoint.d.ts new file mode 100644 index 000000000000..60f14d19208d --- /dev/null +++ b/packages/core/account-id-endpoint.d.ts @@ -0,0 +1,7 @@ +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +declare module "@aws-sdk/core/account-id-endpoint" { + export * from "@aws-sdk/core/dist-types/submodules/account-id-endpoint/index.d"; +} diff --git a/packages/core/client.d.ts b/packages/core/client.d.ts new file mode 100644 index 000000000000..ce995aea2ef8 --- /dev/null +++ b/packages/core/client.d.ts @@ -0,0 +1,7 @@ +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +declare module "@aws-sdk/core/client" { + export * from "@aws-sdk/core/dist-types/submodules/client/index.d"; +} diff --git a/packages/core/httpAuthSchemes.d.ts b/packages/core/httpAuthSchemes.d.ts new file mode 100644 index 000000000000..3783b5e795c2 --- /dev/null +++ b/packages/core/httpAuthSchemes.d.ts @@ -0,0 +1,7 @@ +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +declare module "@aws-sdk/core/httpAuthSchemes" { + export * from "@aws-sdk/core/dist-types/submodules/httpAuthSchemes/index.d"; +} diff --git a/packages/core/package.json b/packages/core/package.json index 87f9e0358418..746a9b66eb9b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -62,11 +62,15 @@ } }, "files": [ - "dist-*/**", + "./account-id-endpoint.d.ts", + "./account-id-endpoint.js", + "./client.d.ts", "./client.js", + "./httpAuthSchemes.d.ts", "./httpAuthSchemes.js", + "./protocols.d.ts", "./protocols.js", - "./account-id-endpoint.js" + "dist-*/**" ], "sideEffects": false, "author": { diff --git a/packages/core/protocols.d.ts b/packages/core/protocols.d.ts new file mode 100644 index 000000000000..7a363347cbcc --- /dev/null +++ b/packages/core/protocols.d.ts @@ -0,0 +1,7 @@ +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +declare module "@aws-sdk/core/protocols" { + export * from "@aws-sdk/core/dist-types/submodules/protocols/index.d"; +} diff --git a/packages/core/scripts/lint.js b/packages/core/scripts/lint.js index f9900a24cef4..307f7533e4ad 100644 --- a/packages/core/scripts/lint.js +++ b/packages/core/scripts/lint.js @@ -28,9 +28,11 @@ for (const submodule of submodules) { }; fs.writeFileSync(path.join(root, "package.json"), JSON.stringify(pkgJson, null, 2) + "\n"); } - if (!pkgJson.files.includes(`./${submodule}.js`)) { + if (!pkgJson.files.includes(`./${submodule}.js`) || !pkgJson.files.includes(`./${submodule}.d.ts`)) { pkgJson.files.push(`./${submodule}.js`); + pkgJson.files.push(`./${submodule}.d.ts`); errors.push(`package.json files array missing ${submodule}.js compatibility redirect file.`); + pkgJson.files = [...new Set(pkgJson.files)].sort(); fs.writeFileSync(path.join(root, "package.json"), JSON.stringify(pkgJson, null, 2) + "\n"); } // tsconfig metadata. @@ -54,6 +56,23 @@ for (const submodule of submodules) { * This is a compatibility redirect for contexts that do not understand package.json exports field. */ module.exports = require("./dist-cjs/submodules/${submodule}/index.js"); +` + ); + } + // compatibility types file. + const compatibilityTypesFile = path.join(root, `${submodule}.d.ts`); + if (!fs.existsSync(compatibilityTypesFile)) { + errors.push(`${submodule} is missing compatibility types file in the package root folder.`); + fs.writeFileSync( + compatibilityTypesFile, + ` +/** + * Do not edit: + * This is a compatibility redirect for contexts that do not understand package.json exports field. + */ +declare module "@aws-sdk/core/${submodule}" { + export * from "@aws-sdk/core/dist-types/submodules/${submodule}/index.d"; +} ` ); }