Skip to content

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Sep 26, 2025

Replaces esbuild with rollup in our dist-cjs pre-bundle step.

update compilation target to es2022

@kuhe kuhe force-pushed the rollup branch 2 times, most recently from e5696c7 to 6d6ef0a Compare September 26, 2025 20:55
"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

"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];
            }
        }
    };
})();

@kuhe kuhe marked this pull request as ready for review September 29, 2025 15:34
@kuhe kuhe requested a review from a team as a code owner September 29, 2025 15:34
@kuhe
Copy link
Contributor Author

kuhe commented Sep 29, 2025

Sample diff of dist-cjs file with rollup vs esbuild:

rollup

'use strict';

class AbortSignal {
    onabort = null;
    _aborted = false;
    constructor() {
        Object.defineProperty(this, "_aborted", {
            value: false,
            writable: true,
        });
    }
    get aborted() {
        return this._aborted;
    }
    abort() {
        this._aborted = true;
        if (this.onabort) {
            this.onabort(this);
            this.onabort = null;
        }
    }
}

class AbortController {
    signal = new AbortSignal();
    abort() {
        this.signal.abort();
    }
}

exports.AbortController = AbortController;
exports.AbortSignal = AbortSignal;

esbuild

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/index.ts
var index_exports = {};
__export(index_exports, {
  AbortController: () => AbortController,
  AbortHandler: () => import_types.AbortHandler,
  AbortSignal: () => AbortSignal,
  IAbortController: () => import_types.AbortController,
  IAbortSignal: () => import_types.AbortSignal
});
module.exports = __toCommonJS(index_exports);

// src/AbortController.ts


// src/AbortSignal.ts
var import_types = require("@smithy/types");
var AbortSignal = class {
  constructor() {
    this.onabort = null;
    this._aborted = false;
    Object.defineProperty(this, "_aborted", {
      value: false,
      writable: true
    });
  }
  static {
    __name(this, "AbortSignal");
  }
  /**
   * Whether the associated operation has already been cancelled.
   */
  get aborted() {
    return this._aborted;
  }
  /**
   * @internal
   */
  abort() {
    this._aborted = true;
    if (this.onabort) {
      this.onabort(this);
      this.onabort = null;
    }
  }
};

// src/AbortController.ts
var AbortController = class {
  constructor() {
    this.signal = new AbortSignal();
  }
  static {
    __name(this, "AbortController");
  }
  abort() {
    this.signal.abort();
  }
};
// Annotate the CommonJS export names for ESM import in node:

0 && (module.exports = {
  AbortController,
  AbortSignal
});

@kuhe
Copy link
Contributor Author

kuhe commented Sep 29, 2025

FAQ:

Q: Why didn't you just use rollup in the first place because you knew from experience as early as 2016 that rollup was the best bundler for libraries?

A: I don't know what I was thinking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants