Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): add compatibility redirect for submodule types #1415

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading