diff --git a/.changeset/tidy-humans-type.md b/.changeset/tidy-humans-type.md new file mode 100644 index 00000000000..cc6f41c99e2 --- /dev/null +++ b/.changeset/tidy-humans-type.md @@ -0,0 +1,5 @@ +--- +"@smithy/util-defaults-mode-node": minor +--- + +defer loading of credential-provider-imds in util-defaults-mode-node diff --git a/packages/util-defaults-mode-node/src/resolveDefaultsModeConfig.ts b/packages/util-defaults-mode-node/src/resolveDefaultsModeConfig.ts index 5fcab6a489f..3d010a95e08 100644 --- a/packages/util-defaults-mode-node/src/resolveDefaultsModeConfig.ts +++ b/packages/util-defaults-mode-node/src/resolveDefaultsModeConfig.ts @@ -1,5 +1,4 @@ import { NODE_REGION_CONFIG_OPTIONS } from "@smithy/config-resolver"; -import { getInstanceMetadataEndpoint, httpRequest } from "@smithy/credential-provider-imds"; import { loadConfig } from "@smithy/node-config-provider"; import { memoize } from "@smithy/property-provider"; import type { DefaultsMode, ResolvedDefaultsMode } from "@smithy/smithy-client"; @@ -82,6 +81,7 @@ const inferPhysicalRegion = async (): Promise => { if (!process.env[ENV_IMDS_DISABLED]) { // We couldn't figure out the region from environment variables. Check IMDSv2 try { + const { getInstanceMetadataEndpoint, httpRequest } = await import("@smithy/credential-provider-imds"); const endpoint = await getInstanceMetadataEndpoint(); return (await httpRequest({ ...endpoint, path: IMDS_REGION_PATH })).toString(); } catch (e) { diff --git a/scripts/compilation/Inliner.js b/scripts/compilation/Inliner.js index 910765f3d47..280b3fdcdf1 100644 --- a/scripts/compilation/Inliner.js +++ b/scripts/compilation/Inliner.js @@ -48,6 +48,7 @@ module.exports = class Inliner { async tsc() { await spawnProcess("yarn", ["g:tsc", "-p", "tsconfig.cjs.json"], { cwd: this.packageDirectory }); console.log("Finished recompiling ./dist-cjs in " + this.package); + this.canonicalExports = Object.keys(require(this.outfile)); return this; } @@ -57,6 +58,7 @@ module.exports = class Inliner { */ async discoverVariants() { if (this.bailout) { + console.log("Inliner bailout."); return this; } this.variantEntries = Object.entries(this.pkgJson["react-native"] ?? {}); @@ -155,6 +157,9 @@ module.exports = class Inliner { mainFields: ["main"], allowOverwrite: true, entryPoints: [path.join(root, this.subfolder, this.package, "src", "index.ts")], + supported: { + "dynamic-import": false, + }, outfile: this.outfile, keepNames: true, packages: "external", @@ -338,6 +343,17 @@ module.exports = class Inliner { " were not found in the index." ); } + + // check ESM compat. + const tmpFileContents = this.canonicalExports + .filter((sym) => !sym.includes(":")) + .map((sym) => `import { ${sym} } from "${this.pkgJson.name}";`) + .join("\n"); + fs.writeFileSync(path.join(__dirname, "tmp", this.package + ".mjs"), tmpFileContents, "utf-8"); + await spawnProcess("node", [path.join(__dirname, "tmp", this.package + ".mjs")]); + console.log("ESM compatibility verified."); + fs.rmSync(path.join(__dirname, "tmp", this.package + ".mjs")); + return this; } }; diff --git a/scripts/compilation/tmp/.gitignore b/scripts/compilation/tmp/.gitignore new file mode 100644 index 00000000000..9044a0c52ec --- /dev/null +++ b/scripts/compilation/tmp/.gitignore @@ -0,0 +1 @@ +*.mjs \ No newline at end of file