-
Notifications
You must be signed in to change notification settings - Fork 107
feat: use rollup for cjs distributions #1713
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
base: main
Are you sure you want to change the base?
Conversation
e5696c7
to
6d6ef0a
Compare
"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", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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];
}
}
};
})();
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
}); |
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 |
Replaces esbuild with rollup in our
dist-cjs
pre-bundle step.update compilation target to es2022