Skip to content

Commit

Permalink
fix(core): add compatibility redirect for submodule types (#1415)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Sep 24, 2024
1 parent 64600d8 commit 18dd957
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-pumpkins-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/core": patch
---

add compatibility types redirect
1 change: 1 addition & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.tgz
*.log
package-lock.json
!*.d.ts
7 changes: 7 additions & 0 deletions packages/core/cbor.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 "@smithy/core/cbor" {
export * from "@smithy/core/dist-types/submodules/cbor/index.d";
}
5 changes: 3 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
}
},
"files": [
"dist-*/**",
"./cbor.js"
"./cbor.d.ts",
"./cbor.js",
"dist-*/**"
],
"homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/core",
"repository": {
Expand Down
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 "@smithy/core/${submodule}" {
export * from "@smithy/core/dist-types/submodules/${submodule}/index.d";
}
`
);
}
Expand Down

0 comments on commit 18dd957

Please sign in to comment.