Skip to content

Commit 3a5d854

Browse files
authored
fix(core): add compatibility types for submodules (#6509)
1 parent b06a8b7 commit 3a5d854

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Do not edit:
3+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
4+
*/
5+
declare module "@aws-sdk/core/account-id-endpoint" {
6+
export * from "@aws-sdk/core/dist-types/submodules/account-id-endpoint/index.d";
7+
}

packages/core/client.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Do not edit:
3+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
4+
*/
5+
declare module "@aws-sdk/core/client" {
6+
export * from "@aws-sdk/core/dist-types/submodules/client/index.d";
7+
}

packages/core/httpAuthSchemes.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Do not edit:
3+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
4+
*/
5+
declare module "@aws-sdk/core/httpAuthSchemes" {
6+
export * from "@aws-sdk/core/dist-types/submodules/httpAuthSchemes/index.d";
7+
}

packages/core/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@
6262
}
6363
},
6464
"files": [
65-
"dist-*/**",
65+
"./account-id-endpoint.d.ts",
66+
"./account-id-endpoint.js",
67+
"./client.d.ts",
6668
"./client.js",
69+
"./httpAuthSchemes.d.ts",
6770
"./httpAuthSchemes.js",
71+
"./protocols.d.ts",
6872
"./protocols.js",
69-
"./account-id-endpoint.js"
73+
"dist-*/**"
7074
],
7175
"sideEffects": false,
7276
"author": {

packages/core/protocols.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Do not edit:
3+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
4+
*/
5+
declare module "@aws-sdk/core/protocols" {
6+
export * from "@aws-sdk/core/dist-types/submodules/protocols/index.d";
7+
}

packages/core/scripts/lint.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ for (const submodule of submodules) {
2828
};
2929
fs.writeFileSync(path.join(root, "package.json"), JSON.stringify(pkgJson, null, 2) + "\n");
3030
}
31-
if (!pkgJson.files.includes(`./${submodule}.js`)) {
31+
if (!pkgJson.files.includes(`./${submodule}.js`) || !pkgJson.files.includes(`./${submodule}.d.ts`)) {
3232
pkgJson.files.push(`./${submodule}.js`);
33+
pkgJson.files.push(`./${submodule}.d.ts`);
3334
errors.push(`package.json files array missing ${submodule}.js compatibility redirect file.`);
35+
pkgJson.files = [...new Set(pkgJson.files)].sort();
3436
fs.writeFileSync(path.join(root, "package.json"), JSON.stringify(pkgJson, null, 2) + "\n");
3537
}
3638
// tsconfig metadata.
@@ -54,6 +56,23 @@ for (const submodule of submodules) {
5456
* This is a compatibility redirect for contexts that do not understand package.json exports field.
5557
*/
5658
module.exports = require("./dist-cjs/submodules/${submodule}/index.js");
59+
`
60+
);
61+
}
62+
// compatibility types file.
63+
const compatibilityTypesFile = path.join(root, `${submodule}.d.ts`);
64+
if (!fs.existsSync(compatibilityTypesFile)) {
65+
errors.push(`${submodule} is missing compatibility types file in the package root folder.`);
66+
fs.writeFileSync(
67+
compatibilityTypesFile,
68+
`
69+
/**
70+
* Do not edit:
71+
* This is a compatibility redirect for contexts that do not understand package.json exports field.
72+
*/
73+
declare module "@aws-sdk/core/${submodule}" {
74+
export * from "@aws-sdk/core/dist-types/submodules/${submodule}/index.d";
75+
}
5776
`
5877
);
5978
}

0 commit comments

Comments
 (0)