Skip to content

Commit

Permalink
Generate single unified es module for exports
Browse files Browse the repository at this point in the history
- Minification hints and optimizations for webpack
  • Loading branch information
nev21 committed Apr 17, 2024
1 parent 24a5c6b commit 7af8a42
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 259 deletions.
338 changes: 169 additions & 169 deletions common/config/rush/npm-shrinkwrap.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ module.exports = function (grunt) {
"ts_async": {
// Default ES5
tsconfig: "./lib/tsconfig.json",
outDir: "./lib/dist/es5/mod"
outDir: "./lib/build/es5/mod"
},
"ts_async_es6": {
tsconfig: "./lib/tsconfig.es6.json",
outDir: "./lib/dist/es6/mod"
outDir: "./lib/build/es6/mod"
},
"ts_async-test": {
tsconfig: "./lib/test/tsconfig.test.json",
Expand Down
6 changes: 3 additions & 3 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
],
"main": "dist/es5/main/ts-async.js",
"esnext:main": "dist/es6/main/ts-async.js",
"module": "dist/es5/mod/index.js",
"esnext": "dist/es6/mod/index.js",
"module": "dist/es5/mod/ts-async.js",
"esnext": "dist/es6/mod/ts-async.js",
"types": "dist/types/ts-async.d.ts",
"repository": {
"type": "git",
Expand Down Expand Up @@ -74,7 +74,7 @@
},

"dependencies": {
"@nevware21/ts-utils": ">= 0.11.0 < 2.x"
"@nevware21/ts-utils": ">= 0.11.2 < 2.x"
},
"devDependencies": {
"@nevware21/tools-pre-proc": "0.1.0",
Expand Down
85 changes: 22 additions & 63 deletions lib/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,6 @@ const rollupConfigMainEntry = (srcPath, destPath, path, format = "umd") => {
return taskRollupConfig;
};

const rollupModule = (srcPath, destPath) => {
const taskRollupConfig = {
input: `./${srcPath}/index.js`,
output: {
file: `./${destPath}/${outputName}.js`,
banner: banner,
format: "esm",
name: "nevware21.ts-async",
freeze: false,
sourcemap: true
},
external: [ "fs", "path", "@nevware21/ts-utils" ],
plugins: [
cleanup({
comments: [
/[#@]__/,
/^!/
]
})
]
};

return taskRollupConfig;
};

const polyfillRollupConfigFactory = (srcPath, destPath, isMinified, format = "iife", postfix = "") => {
const taskRollupConfig = {
input: `./${srcPath}/polyfills.js`,
Expand Down Expand Up @@ -261,42 +236,26 @@ const polyfillRollupConfigFactory = (srcPath, destPath, isMinified, format = "ii
};

export default [
//rollupModule("build/es5", "dist-es5", false),
// rollupModule("build/es6", "dist-es6", false),

polyfillRollupConfigFactory("dist/es5/mod", "bundle/es5", true),
polyfillRollupConfigFactory("dist/es5/mod", "bundle/es5", false),

rollupConfigMainEntry("dist/es5/mod", "dist/es5", "main", "umd"),
rollupConfigMainEntry("dist/es6/mod", "dist/es6", "main", "umd"),

// Self contained bundles
rollupConfigFactory("dist/es5/mod", "dist/es5", false, "umd", "umd"),
rollupConfigFactory("dist/es6/mod", "dist/es6", false, "umd", "umd"),

rollupConfigFactory("dist/es5/mod", "bundle/es5", false, "esm", "esm"),
rollupConfigFactory("dist/es5/mod", "bundle/es5", true, "esm", "esm"),
// rollupConfigFactory("dist/es5/mod", "bundle/es5", false, "amd", "amd"),
// rollupConfigFactory("dist/es5/mod", "bundle/es5", true, "amd", "amd"),
// rollupConfigFactory("dist/es5/mod", "bundle/es5", false, "cjs", "cjs"),
// rollupConfigFactory("dist/es5/mod", "bundle/es5", true, "cjs", "cjs"),
rollupConfigFactory("dist/es5/mod", "bundle/es5", false, "iife", "iife"),
rollupConfigFactory("dist/es5/mod", "bundle/es5", true, "iife", "iife"),
rollupConfigFactory("dist/es5/mod", "bundle/es5", false, "umd", "umd"),
rollupConfigFactory("dist/es5/mod", "bundle/es5", true, "umd", "umd"),
// rollupConfigFactory("dist/es5/mod", "bundle/es5", false, "system", "system"),
// rollupConfigFactory("dist/es5/mod", "bundle/es5", true, "system", "system"),

rollupConfigFactory("dist/es6/mod", "bundle/es6", false, "esm", "esm"),
rollupConfigFactory("dist/es6/mod", "bundle/es6", true, "esm", "esm"),
// rollupConfigFactory("dist/es6/mod", "bundle/es6", false, "amd", "amd"),
// rollupConfigFactory("dist/es6/mod", "bundle/es6", true, "amd", "amd"),
// rollupConfigFactory("dist/es6/mod", "bundle/es6", false, "cjs", "cjs"),
// rollupConfigFactory("dist/es6/mod", "bundle/es6", true, "cjs", "cjs"),
rollupConfigFactory("dist/es6/mod", "bundle/es6", false, "iife", "iife"),
rollupConfigFactory("dist/es6/mod", "bundle/es6", true, "iife", "iife"),
rollupConfigFactory("dist/es6/mod", "bundle/es6", false, "umd", "umd"),
rollupConfigFactory("dist/es6/mod", "bundle/es6", true, "umd", "umd")
// rollupConfigFactory("dist/es6/mod", "bundle/es6", false, "system", "system"),
// rollupConfigFactory("dist/es6/mod", "bundle/es6", true, "system", "system")
polyfillRollupConfigFactory("build/es5/mod", "bundle/es5", true),
polyfillRollupConfigFactory("build/es5/mod", "bundle/es5", false),

rollupConfigMainEntry("build/es5/mod", "dist/es5", "main", "umd"),
rollupConfigMainEntry("build/es6/mod", "dist/es6", "main", "umd"),
rollupConfigMainEntry("build/es5/mod", "dist/es5", "mod", "es"),
rollupConfigMainEntry("build/es6/mod", "dist/es6", "mod", "es"),

// Self contained bundles (Used for testing -- will be removed in a future release)
rollupConfigFactory("build/es5/mod", "dist/es5", false, "umd", "umd"),

// ES5 Bundles
rollupConfigFactory("build/es5/mod", "bundle/es5", false, "iife", "iife"),
rollupConfigFactory("build/es5/mod", "bundle/es5", true, "iife", "iife"),
rollupConfigFactory("build/es5/mod", "bundle/es5", false, "umd", "umd"),
rollupConfigFactory("build/es5/mod", "bundle/es5", true, "umd", "umd"),

// ES6 Bundles
rollupConfigFactory("build/es6/mod", "bundle/es6", false, "iife", "iife"),
rollupConfigFactory("build/es6/mod", "bundle/es6", true, "iife", "iife"),
rollupConfigFactory("build/es6/mod", "bundle/es6", false, "umd", "umd"),
rollupConfigFactory("build/es6/mod", "bundle/es6", true, "umd", "umd")
];
25 changes: 20 additions & 5 deletions lib/src/promise/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import {
arrSlice, dumpObj, getKnownSymbol, hasSymbol, isFunction, isPromiseLike, isUndefined,
throwTypeError, WellKnownSymbols, objToString, scheduleTimeout, ITimerHandler, getWindow, isNode,
getGlobal, ILazyValue, objDefine, objDefineProp, lazySafeGetInst, iterForOf, isIterable,
isArray, arrForEach, createCachedValue, ICachedValue, safe, getInst, createCustomError
getGlobal, objDefine, objDefineProp, iterForOf, isIterable, isArray, arrForEach, createCachedValue,
ICachedValue, safe, getInst, createCustomError
} from "@nevware21/ts-utils";
import { doAwait, doAwaitResponse } from "./await";
import { _addDebugState, _promiseDebugEnabled } from "./debug";
Expand All @@ -36,7 +36,22 @@ let _uniquePromiseId = 0;
let _unhandledRejectionTimeout = 10;
let _aggregationError: ICachedValue<any>;

let _hasPromiseRejectionEvent: ILazyValue<any>;
/**
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PromiseRejectionEvent)
*/
interface _PromiseRejectionEvent extends Event {
/**
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PromiseRejectionEvent/promise)
*/
readonly promise: IPromise<any>;

/**
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/PromiseRejectionEvent/reason)
*/
readonly reason: any;
}

let _hasPromiseRejectionEvent: ICachedValue<_PromiseRejectionEvent>;

function dumpFnObj(value: any) {
if (isFunction(value)) {
Expand Down Expand Up @@ -103,8 +118,6 @@ export function _createPromise<T>(newPromise: PromiseCreatorFn, processor: Promi
let _handled = false;
let _unHandledRejectionHandler: ITimerHandler = null;
let _thePromise: IPromise<T>;

!_hasPromiseRejectionEvent && (_hasPromiseRejectionEvent = lazySafeGetInst(STR_PROMISE + "RejectionEvent"));

// https://tc39.es/ecma262/#sec-promise.prototype.then
function _then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): IPromise<TResult1 | TResult2> {
Expand Down Expand Up @@ -282,6 +295,8 @@ export function _createPromise<T>(newPromise: PromiseCreatorFn, processor: Promi
} else {
let gbl = getWindow() || getGlobal();

!_hasPromiseRejectionEvent && (_hasPromiseRejectionEvent = createCachedValue(safe(getInst<_PromiseRejectionEvent>, [STR_PROMISE + "RejectionEvent"]).v));

//#ifdef DEBUG
_debugLog(_toString(), "Emitting " + UNHANDLED_REJECTION);
//#endif
Expand Down
2 changes: 1 addition & 1 deletion lib/src/promise/idlePromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export function createIdleRacePromise<T>(values: Iterable<T | PromiseLike<T>>, t
* if the iterable passed is empty. If the iterable passed is non-empty but contains no pending promises, the returned promise will settle
* asynchronously when the system detects that the runtime is idle.
*/
export function createIdleRacePromise<T extends readonly unknown[] | []>(values: T, timeout?: number): IPromise<Awaited<T[number]>> {
export function createIdleRacePromise<T extends readonly unknown[] | []>(values: T, timeout?: number): IPromise<Awaited<T[number]>> {
!_raceIdleCreator && (_raceIdleCreator = _createRacePromise(createIdlePromise));
return _raceIdleCreator.v(values, timeout);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/test/src/promise/idle.promise.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

import { assert } from "chai";
import { createIdlePromise, setDefaultIdlePromiseTimeout } from "../../../src/promise/idlePromise";
import { getGlobal } from "@nevware21/ts-utils";
import { getGlobal, setBypassLazyCache } from "@nevware21/ts-utils";
import { setPromiseDebugState } from "../../../src/promise/debug";

describe("createIdlePromise", () => {
beforeEach(() => {
setDefaultIdlePromiseTimeout();
setBypassLazyCache(true);
});

afterEach(() => {
setBypassLazyCache(false);
});

it("should create a new idle promise with timeout from parameter", async () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/tsconfig.es6.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"target": "es6",
"outDir": "./dist-es6"
"outDir": "./build/es6"
}
}
2 changes: 1 addition & 1 deletion lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"declaration": true,
"declarationDir": "./build/types",
"removeComments": false,
"outDir": "./dist-es5"
"outDir": "./build/es5"
}
}
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
],
"main": "lib/dist/es5/main/ts-async.js",
"esnext:main": "lib/dist/es6/main/ts-async.js",
"module": "lib/dist/es5/mod/index.js",
"esnext": "lib/dist/es6/mod/index.js",
"module": "lib/dist/es5/mod/ts-async.js",
"esnext": "lib/dist/es6/mod/ts-async.js",
"types": "lib/dist/types/ts-async.d.ts",
"scripts": {
"postinstall": "node common/scripts/install-run-rush.js update --full",
Expand Down Expand Up @@ -79,7 +79,7 @@
"node": ">= 0.8.0"
},
"dependencies": {
"@nevware21/ts-utils": ">= 0.11.0 < 2.x"
"@nevware21/ts-utils": ">= 0.11.2 < 2.x"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
Expand Down Expand Up @@ -112,7 +112,7 @@
"size-limit": [
{
"name": "es5-full",
"path": "lib/dist/es5/mod/index.js",
"path": "lib/dist/es5/mod/ts-async.js",
"limit": "18 kb",
"brotli": false,
"ignore": [
Expand All @@ -122,7 +122,7 @@
},
{
"name": "es6-full",
"path": "lib/dist/es6/mod/index.js",
"path": "lib/dist/es6/mod/ts-async.js",
"limit": "17 kb",
"brotli": false,
"ignore": [
Expand All @@ -132,7 +132,7 @@
},
{
"name": "es5-zip",
"path": "lib/dist/es5/mod/index.js",
"path": "lib/dist/es5/mod/ts-async.js",
"limit": "7 Kb",
"gzip": true,
"ignore": [
Expand All @@ -142,7 +142,7 @@
},
{
"name": "es6-zip",
"path": "lib/dist/es6/mod/index.js",
"path": "lib/dist/es6/mod/ts-async.js",
"limit": "7 Kb",
"gzip": true,
"ignore": [
Expand All @@ -152,7 +152,7 @@
},
{
"name": "es5-promise",
"path": "lib/dist/es5/mod/index.js",
"path": "lib/dist/es5/mod/ts-async.js",
"limit": "8 kb",
"import": "{ createAsyncPromise }",
"brotli": false,
Expand All @@ -163,7 +163,7 @@
},
{
"name": "es5-any",
"path": "lib/dist/es5/mod/index.js",
"path": "lib/dist/es5/mod/ts-async.js",
"limit": "10 kb",
"import": "{ createAnyPromise }",
"brotli": false,
Expand All @@ -174,7 +174,7 @@
},
{
"name": "es5-race",
"path": "lib/dist/es5/mod/index.js",
"path": "lib/dist/es5/mod/ts-async.js",
"limit": "9 kb",
"import": "{ createRacePromise }",
"brotli": false,
Expand All @@ -185,14 +185,14 @@
},
{
"name": "es5-polypromise",
"path": "lib/dist/es5/mod/index.js",
"path": "lib/dist/es5/mod/ts-async.js",
"limit": "12 kb",
"import": "{ PolyPromise }",
"brotli": false
},
{
"name": "es5-ppolyfill",
"path": "lib/dist/es5/mod/polyfills.js",
"path": "lib/build/es5/mod/polyfills.js",
"limit": "12 kb",
"brotli": false
}
Expand Down
2 changes: 1 addition & 1 deletion tools/build-tools/pre-proc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"homepage": "https://github.com/nevware21/ts-async",
"dependencies": {
"globby": "^11.0.0",
"@nevware21/ts-utils": ">= 0.11.0 < 2.x"
"@nevware21/ts-utils": ">= 0.11.2 < 2.x"
},
"devDependencies": {
"@types/node": "^18.14.2",
Expand Down

0 comments on commit 7af8a42

Please sign in to comment.