|
| 1 | +/** |
| 2 | + * |
| 3 | + * This script builds a minimal bundle of the code |
| 4 | + * in SSOOIDCClient and its CreateTokenCommand, with everything else |
| 5 | + * left external. |
| 6 | + * |
| 7 | + * This is to break a cyclical dependency with the credential providers |
| 8 | + * and certain services used by those providers. |
| 9 | + * |
| 10 | + */ |
| 11 | + |
| 12 | +const fs = require("fs"); |
| 13 | +const path = require("path"); |
| 14 | +const esbuild = require("esbuild"); |
| 15 | + |
| 16 | +const root = path.join(__dirname, "..", "..", ".."); |
| 17 | + |
| 18 | +(async () => { |
| 19 | + const defaultRuntimeConfigFile = path.join(root, "clients", "client-sso-oidc", "src", "runtimeConfig.ts"); |
| 20 | + const nodeRuntimeConfig = fs.readFileSync(defaultRuntimeConfigFile); |
| 21 | + const browserRuntimeConfig = fs.readFileSync( |
| 22 | + path.join(path.dirname(defaultRuntimeConfigFile), "runtimeConfig.browser.ts") |
| 23 | + ); |
| 24 | + |
| 25 | + for (const platform of ["browser", "node"]) { |
| 26 | + if (platform === "browser") { |
| 27 | + fs.writeFileSync(defaultRuntimeConfigFile, browserRuntimeConfig); |
| 28 | + } else { |
| 29 | + fs.writeFileSync(defaultRuntimeConfigFile, nodeRuntimeConfig); |
| 30 | + } |
| 31 | + |
| 32 | + const outfile = path.join( |
| 33 | + root, |
| 34 | + "packages", |
| 35 | + "token-providers", |
| 36 | + "src", |
| 37 | + "client-sso-oidc-bundle", |
| 38 | + `dist-${platform}.ts` |
| 39 | + ); |
| 40 | + |
| 41 | + await esbuild.build({ |
| 42 | + platform, |
| 43 | + bundle: true, |
| 44 | + format: "esm", |
| 45 | + mainFields: ["module", "main"], |
| 46 | + entryPoints: [path.join(root, "packages", "token-providers", "scripts", "api", "source.js")], |
| 47 | + outfile: outfile, |
| 48 | + external: ["tslib", "@aws-crypto/*", "@smithy/*", "@aws-sdk/middleware-*", "@aws-sdk/types", "@aws-sdk/util-*"], |
| 49 | + }); |
| 50 | + |
| 51 | + await new Promise((r) => setTimeout(r, 1000)); |
| 52 | + |
| 53 | + fs.writeFileSync(outfile, `// @ts-nocheck \n/* eslint-disable */\n` + fs.readFileSync(outfile)); |
| 54 | + } |
| 55 | + |
| 56 | + fs.writeFileSync(defaultRuntimeConfigFile, nodeRuntimeConfig); |
| 57 | +})(); |
0 commit comments