Skip to content
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
62 changes: 62 additions & 0 deletions .changeset/sour-seahorses-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
"@smithy/service-client-documentation-generator": minor
"@smithy/experimental-identity-and-auth": minor
"@smithy/core": minor
"@smithy/abort-controller": minor
"@smithy/chunked-blob-reader": minor
"@smithy/chunked-blob-reader-native": minor
"@smithy/config-resolver": minor
"@smithy/credential-provider-imds": minor
"@smithy/eventstream-codec": minor
"@smithy/eventstream-serde-browser": minor
"@smithy/eventstream-serde-config-resolver": minor
"@smithy/eventstream-serde-node": minor
"@smithy/eventstream-serde-universal": minor
"@smithy/fetch-http-handler": minor
"@smithy/hash-blob-browser": minor
"@smithy/hash-node": minor
"@smithy/hash-stream-node": minor
"@smithy/invalid-dependency": minor
"@smithy/is-array-buffer": minor
"@smithy/md5-js": minor
"@smithy/middleware-apply-body-checksum": minor
"@smithy/middleware-compression": minor
"@smithy/middleware-content-length": minor
"@smithy/middleware-endpoint": minor
"@smithy/middleware-retry": minor
"@smithy/middleware-serde": minor
"@smithy/middleware-stack": minor
"@smithy/node-config-provider": minor
"@smithy/node-http-handler": minor
"@smithy/property-provider": minor
"@smithy/protocol-http": minor
"@smithy/querystring-builder": minor
"@smithy/querystring-parser": minor
"@smithy/service-error-classification": minor
"@smithy/shared-ini-file-loader": minor
"@smithy/signature-v4": minor
"@smithy/signature-v4a": minor
"@smithy/smithy-client": minor
"@smithy/types": minor
"@smithy/url-parser": minor
"@smithy/util-base64": minor
"@smithy/util-body-length-browser": minor
"@smithy/util-body-length-node": minor
"@smithy/util-buffer-from": minor
"@smithy/util-config-provider": minor
"@smithy/util-defaults-mode-browser": minor
"@smithy/util-defaults-mode-node": minor
"@smithy/util-endpoints": minor
"@smithy/util-hex-encoding": minor
"@smithy/util-middleware": minor
"@smithy/util-retry": minor
"@smithy/util-stream": minor
"@smithy/util-stream-browser": minor
"@smithy/util-stream-node": minor
"@smithy/util-uri-escape": minor
"@smithy/util-utf8": minor
"@smithy/util-waiter": minor
"@smithy/uuid": minor
---

update dist-cjs generation to use rollup
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
},
"devDependencies": {
"@microsoft/api-extractor": "7.52.7",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-typescript": "^12.1.4",
"@tsconfig/recommended": "1.0.2",
"@types/jest": "28.1.3",
"@types/jsdom": "20.0.1",
Expand All @@ -51,6 +53,7 @@
"jest": "29.7.0",
"prettier": "3.2.5",
"puppeteer": "^19.2.0",
"rollup": "^4.52.2",
"ts-jest": "29.1.2",
"turbo": "2.3.3",
"typescript": "~5.8.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import type { Identity, IdentityProvider } from "@smithy/types";
/**
* @internal
*/
export const createIsIdentityExpiredFunction = (expirationMs: number) => (identity: Identity) =>
doesIdentityRequireRefresh(identity) && identity.expiration!.getTime() - Date.now() < expirationMs;
export const createIsIdentityExpiredFunction = (expirationMs: number) =>
function isIdentityExpired(identity: Identity) {
return doesIdentityRequireRefresh(identity) && identity.expiration!.getTime() - Date.now() < expirationMs;
};

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import type { Identity, IdentityProvider } from "@smithy/types";
/**
* @internal
*/
export const createIsIdentityExpiredFunction = (expirationMs: number) => (identity: Identity) =>
doesIdentityRequireRefresh(identity) && identity.expiration!.getTime() - Date.now() < expirationMs;
export const createIsIdentityExpiredFunction = (expirationMs: number) =>
function isIdentityExpired(identity: Identity) {
return doesIdentityRequireRefresh(identity) && identity.expiration!.getTime() - Date.now() < expirationMs;
};

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "4.1.0",
"scripts": {
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
"build:cjs": "node ../../scripts/inline service-client-documentation-generator",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a runtime package so it doesn't need inlining

"build:cjs": "yarn g:tsc -p tsconfig.cjs.json",
"build:es": "yarn g:tsc -p tsconfig.es.json",
"build:types": "yarn g:tsc -p tsconfig.types.json",
"build:types:downlevel": "rimraf dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
Expand Down
126 changes: 98 additions & 28 deletions scripts/compilation/Inliner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const fs = require("fs");
const path = require("path");
const { spawnProcess } = require("./../utils/spawn-process");
const walk = require("./../utils/walk");
const esbuild = require("esbuild");
const rollup = require("rollup");
const { nodeResolve } = require("@rollup/plugin-node-resolve");
const typescript = require("@rollup/plugin-typescript");

const root = path.join(__dirname, "..", "..");

Expand All @@ -18,7 +20,6 @@ module.exports = class Inliner {
this.platform = "node";
this.isPackage = fs.existsSync(path.join(root, "packages", pkg));
this.isLib = fs.existsSync(path.join(root, "lib", pkg));
this.isClient = !this.isPackage && !this.isLib;
this.isCore = pkg === "core";
this.reExportStubs = false;
this.subfolder = this.isPackage ? "packages" : this.isLib ? "lib" : "clients";
Expand Down Expand Up @@ -154,28 +155,68 @@ module.exports = class Inliner {
return this;
}

this.variantExternalsForEsBuild = this.variantExternals.map(
(variant) => "*/" + path.basename(variant).replace(/.js$/, "")
const variantExternalsForRollup = this.variantExternals.map((variant) =>
path.basename(variant).replace(/.js$/, "")
);

const buildOptions = {
platform: this.platform,
target: ["node18"],
bundle: true,
format: "cjs",
mainFields: ["main"],
allowOverwrite: true,
entryPoints: [path.join(root, this.subfolder, this.package, "src", "index.ts")],
supported: {
"dynamic-import": false,
const entryPoint = path.join(root, this.subfolder, this.package, "src", "index.ts");

const inputOptions = {
input: entryPoint,
plugins: [
nodeResolve(),
typescript({
compilerOptions: {
importHelpers: true,
noEmitHelpers: false,
module: "esnext",
target: "es2022",
noCheck: true,
removeComments: true,
},
}),
],
external: (id) => {
const relative = !!id.match(/^\.?\.?\//);
if (!relative) {
this.verbose && console.log("EXTERN (pkg)", id);
return true;
}

const local = id.includes(`/packages/`) && id.includes(`/dist-es/`);
if (local) {
this.verbose && console.log("EXTERN (local)", id);
return true;
}

if (id === entryPoint) {
this.verbose && console.log("INTERN (entry point)", id);
return false;
}

for (const file of variantExternalsForRollup) {
const idWithoutExtension = id.replace(/\.ts$/, "");
if (idWithoutExtension.endsWith(file)) {
this.verbose && console.log("EXTERN (variant)", id);
return true;
}
}

this.verbose && console.log("INTERN (invariant)", id);
return false;
},
outfile: this.outfile,
keepNames: true,
packages: "external",
external: ["@smithy/*", "@aws-sdk/*", "node_modules/*", ...this.variantExternalsForEsBuild],
};

await esbuild.build(buildOptions);
const outputOptions = {
file: this.outfile,
format: "cjs",
exports: "named",
preserveModules: false,
};

const bundle = await rollup.rollup(inputOptions);
await bundle.write(outputOptions);
await bundle.close();

if (this.isCore) {
const submodules = fs.readdirSync(path.join(root, this.subfolder, this.package, "src", "submodules"));
Expand All @@ -189,12 +230,18 @@ module.exports = class Inliner {
) {
continue;
}
await esbuild.build({
...buildOptions,
keepNames: false,
entryPoints: [path.join(root, this.subfolder, this.package, "src", "submodules", submodule, "index.ts")],
outfile: path.join(root, this.subfolder, this.package, "dist-cjs", "submodules", submodule, "index.js"),

const submoduleBundle = await rollup.rollup({
...inputOptions,
input: path.join(root, this.subfolder, this.package, "src", "submodules", submodule, "index.ts"),
});

await submoduleBundle.write({
...outputOptions,
file: path.join(root, this.subfolder, this.package, "dist-cjs", "submodules", submodule, "index.js"),
});

await submoduleBundle.close();
}
}

Expand Down Expand Up @@ -398,10 +445,33 @@ module.exports = class Inliner {
}

// check ESM compat.
const tmpFileContents = this.canonicalExports
.filter((sym) => !sym.includes(":"))
.map((sym) => `import { ${sym} } from "${this.pkgJson.name}";`)
.join("\n");
const tmpFileContents =
`import assert from "node:assert";\n` +
this.canonicalExports
.filter((sym) => !sym.includes(":"))
.map((sym) => {
if (
[
"getDefaultClientConfiguration", // renamed as an alias
"generateIdempotencyToken", // sometimes called v4
"expectInt", // aliased to expectLong
"handleFloat", // aliased to limitedParseDouble
"limitedParseFloat", // aliased to limitedParseDouble
"strictParseFloat", // aliased to strictParseDouble
"strictParseInt", // aliased to strictParseLong
].includes(sym)
) {
return `import { ${sym} } from "${this.pkgJson.name}";`;
}
return `import { ${sym} } from "${this.pkgJson.name}";
if (typeof ${sym} === "function") {
if (${sym}.name !== "${sym}") {
throw new Error(${sym}.name + " does not equal expected ${sym}.")
}
}
`;
})
.join("\n");
fs.writeFileSync(path.join(__dirname, "tmp", this.package + ".mjs"), tmpFileContents, "utf-8");
await spawnProcess("node", [path.join(__dirname, "tmp", this.package + ".mjs")]);
if (this.verbose) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"importHelpers": true,
"module": "commonjs",
"noEmitHelpers": false,
"target": "ES2018",
"target": "es2022",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it safe to upgrade to es2022?

Smithy-TS has the same language level support as AWS SDK JSv3. JSv3 already uses the @tsconfig/node18 preset which has a language target of es2022.

The dist code diff for a sampling of language constructs:

source:

const x: any = undefined;

(async () => {
    const y = {
        async *[Symbol.asyncIterator]() {
            for await (const p of x) {
                yield 1;
                yield 2;
                yield x ?? x;
                yield x?.x?.()?.[0];
            }
        }
    }
})();

es2018:

"use strict";
const x = undefined;
(async () => {
    const y = {
        async *[Symbol.asyncIterator]() {
            var _a, _b;
            for await (const p of x) {
                yield 1;
                yield 2;
                yield x !== null && x !== void 0 ? x : x;
                yield (_b = (_a = x === null || x === void 0 ? void 0 : x.x) === null || _a === void 0 ? void 0 : _a.call(x)) === null || _b === void 0 ? void 0 : _b[0];
            }
        }
    };
})();

es2022:

"use strict";
const x = undefined;
(async () => {
    const y = {
        async *[Symbol.asyncIterator]() {
            for await (const p of x) {
                yield 1;
                yield 2;
                yield x ?? x;
                yield x?.x?.()?.[0];
            }
        }
    };
})();

"noCheck": true
}
}
2 changes: 1 addition & 1 deletion tsconfig.es.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"module": "ESNext",
"moduleResolution": "bundler",
"noEmitHelpers": false,
"target": "ES2020",
"target": "es2022",
"noCheck": true
}
}
Loading
Loading