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

feat(scripts): update tsconfig files while copying clients #3152

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 10 additions & 0 deletions scripts/generate-clients/config/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "dist-cjs"
},
"exclude": ["test/**/*"],
"extends": "../../tsconfig.cjs.json",
"include": ["src/"]
}
10 changes: 10 additions & 0 deletions scripts/generate-clients/config/tsconfig.es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "dist-es",
"lib": ["dom", "es5", "es2015.promise", "es2015.collection", "es2015.iterable", "es2015.symbol.wellknown"]
},
"extends": "../../tsconfig.es.json",
"include": ["src/"]
}
10 changes: 10 additions & 0 deletions scripts/generate-clients/config/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"declarationDir": "dist-types"
},
"exclude": ["test/**/*", "dist-types/**/*"],
"extends": "../../tsconfig.types.json",
"include": ["src/"]
}
3 changes: 3 additions & 0 deletions scripts/generate-clients/config/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../typedoc.client.json"
}
46 changes: 37 additions & 9 deletions scripts/generate-clients/copy-to-clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const { normalize, join } = require("path");
const { copySync, removeSync } = require("fs-extra");
const { readdirSync, lstatSync, readFileSync, existsSync, writeFileSync } = require("fs");

const typedocJson = require("./config/typedoc.json");
const tsconfigCjsJson = require("./config/tsconfig.cjs.json");
const tsconfigEsJson = require("./config/tsconfig.es.json");
const tsconfigTypesJson = require("./config/tsconfig.types.json");

const getOverwritableDirectories = (subDirectories, packageName) => {
const additionalGeneratedFiles = {
"@aws-sdk/client-sts": ["defaultRoleAssumers.ts", "defaultStsRoleAssumers.ts", "defaultRoleAssumers.spec.ts"],
Expand Down Expand Up @@ -40,12 +45,22 @@ const mergeManifest = (fromContent = {}, toContent = {}) => {
const devDepsInRoot = ["downlevel-dts", "rimraf", "typedoc", "typescript"];
devDepsInRoot.forEach((devDep) => delete fromContent[name][devDep]);
}

// Replace tsconfig.json with tsconfig.cjs.json in scripts
if (name === "scripts") {
Object.entries(fromContent[name]).forEach(([key, value]) => {
fromContent[name][key] = value.replace("tsconfig.json", "tsconfig.cjs.json");
});
}

merged[name] = mergeManifest(fromContent[name], toContent[name]);

if (name === "scripts" || name === "devDependencies") {
// Allow target package.json(toContent) has its own special script or
// dev dependencies that won't be overwritten in codegen
merged[name] = { ...toContent[name], ...merged[name] };
}

if (name === "scripts" || name === "dependencies" || name === "devDependencies") {
// Sort by keys to make sure the order is stable
merged[name] = Object.fromEntries(Object.entries(merged[name]).sort());
Expand Down Expand Up @@ -134,16 +149,29 @@ const copyToClients = async (sourceDir, destinationDir) => {
},
};
writeFileSync(destSubPath, JSON.stringify(mergedManifest, null, 2).concat(`\n`));
} else if (packageSub === "typedoc.json") {
const typedocJson = {
extends: "../../typedoc.client.json",
};
writeFileSync(destSubPath, JSON.stringify(typedocJson, null, 2).concat(`\n`));
} else if (overWritableSubs.includes(packageSub) || !existsSync(destSubPath)) {
if (lstatSync(packageSubPath).isDirectory()) removeSync(destSubPath);
copySync(packageSubPath, destSubPath, {
overwrite: true,
});
if (packageSub === "typedoc.json") {
writeFileSync(destSubPath, JSON.stringify(typedocJson, null, 2).concat(`\n`));
} else if (packageSub.startsWith("tsconfig")) {
switch (packageSub) {
case "tsconfig.json":
const tsconfigCjsPath = join(destPath, "tsconfig.cjs.json");
if (existsSync(tsconfigCjsPath)) break;
writeFileSync(tsconfigCjsPath, JSON.stringify(tsconfigCjsJson, null, 2).concat(`\n`));
break;
case "tsconfig.es.json":
writeFileSync(destSubPath, JSON.stringify(tsconfigEsJson, null, 2).concat(`\n`));
break;
case "tsconfig.types.json":
writeFileSync(destSubPath, JSON.stringify(tsconfigTypesJson, null, 2).concat(`\n`));
break;
}
} else {
if (lstatSync(packageSubPath).isDirectory()) removeSync(destSubPath);
copySync(packageSubPath, destSubPath, {
overwrite: true,
});
}
}
}
}
Expand Down