Skip to content

Commit

Permalink
fix(core): add compatibility types for submodules (#6509)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe authored Sep 24, 2024
1 parent b06a8b7 commit 3a5d854
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/core/account-id-endpoint.d.ts
Original file line number Diff line number Diff line change
@@ -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";
}
7 changes: 7 additions & 0 deletions packages/core/client.d.ts
Original file line number Diff line number Diff line change
@@ -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";
}
7 changes: 7 additions & 0 deletions packages/core/httpAuthSchemes.d.ts
Original file line number Diff line number Diff line change
@@ -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";
}
8 changes: 6 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 7 additions & 0 deletions packages/core/protocols.d.ts
Original file line number Diff line number Diff line change
@@ -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";
}
21 changes: 20 additions & 1 deletion packages/core/scripts/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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";
}
`
);
}
Expand Down

0 comments on commit 3a5d854

Please sign in to comment.