Skip to content

Commit 18dd957

Browse files
authored
fix(core): add compatibility redirect for submodule types (#1415)
1 parent 64600d8 commit 18dd957

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

.changeset/modern-pumpkins-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/core": patch
3+
---
4+
5+
add compatibility types redirect

packages/core/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
*.tgz
77
*.log
88
package-lock.json
9+
!*.d.ts

packages/core/cbor.d.ts

Lines changed: 7 additions & 0 deletions
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 "@smithy/core/cbor" {
6+
export * from "@smithy/core/dist-types/submodules/cbor/index.d";
7+
}

packages/core/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@
6868
}
6969
},
7070
"files": [
71-
"dist-*/**",
72-
"./cbor.js"
71+
"./cbor.d.ts",
72+
"./cbor.js",
73+
"dist-*/**"
7374
],
7475
"homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/core",
7576
"repository": {

packages/core/scripts/lint.js

Lines changed: 20 additions & 1 deletion
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 "@smithy/core/${submodule}" {
74+
export * from "@smithy/core/dist-types/submodules/${submodule}/index.d";
75+
}
5776
`
5877
);
5978
}

0 commit comments

Comments
 (0)