Skip to content

Commit

Permalink
[Bug] Package sizes are too large #132
Browse files Browse the repository at this point in the history
  • Loading branch information
nev21 committed Mar 22, 2024
1 parent 8ce4f1b commit d2e0db2
Show file tree
Hide file tree
Showing 21 changed files with 1,050 additions and 914 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ jobs:
run: npm run test --verbose
- name: Report Coverage
run: npm run codecov
- name: Size tests
if: matrix.node == 20 || matrix.node == 18 # Only run size tests on the latest Node.js versions
run: npm run size
2 changes: 0 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
!tsconfig.json
!/README.md
!/LICENSE
!lib/dist-esm/**
!lib/dist/**
!lib/bundle/**
!lib/src/**
!lib/types/**
1,530 changes: 773 additions & 757 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"
outDir: "./lib/dist/es5/mod"
},
"ts_async_es6": {
tsconfig: "./lib/tsconfig.es6.json",
outDir: "./lib/dist-es6"
outDir: "./lib/dist/es6/mod"
},
"ts_async-test": {
tsconfig: "./lib/test/tsconfig.test.json",
Expand Down
2 changes: 1 addition & 1 deletion lib/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
!tsconfig.**.json
!/README.md
!/LICENSE
!dist-es**/**
!bundle/**
!dist/**
!types/**
10 changes: 5 additions & 5 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
],
"main": "dist/es5/main/ts-async.js",
"esnext:main": "dist/es6/main/ts-async.js",
"module": "dist-es5/index.js",
"esnext": "dist-es6/index.js",
"types": "types/ts-async.d.ts",
"module": "dist/es5/mod/index.js",
"esnext": "dist/es6/mod/index.js",
"types": "dist/types/ts-async.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/nevware21/ts-async.git"
Expand All @@ -54,7 +54,7 @@
"build": "npm run pre-proc && grunt ts_async --verbose && npm run pre-proc -- -restore && npm run package && npm run dtsgen",
"rebuild": "npm run build && npm run test",
"package": "rollup -c rollup.config.js --bundleConfigAsCjs",
"test": "grunt ts_async-test && npm run test:node && npm run test:browser && npm run test:worker && npm run coverage:report",
"test": "npm run pre-proc test && grunt ts_async-test && npm run test:node && npm run test:browser && npm run test:worker && npm run coverage:report&& npm run pre-proc -- -restore",
"test:node": "nyc ts-mocha --type-check -p ./test/tsconfig.test.json ./test/**/*.test.ts --trace-uncaught",
"test:browser": "karma start karma.browser.conf.js --single-run",
"test:worker": "cross-env NODE_OPTIONS=--max-old-space-size=8192 karma start karma.worker.conf.js --single-run",
Expand All @@ -74,7 +74,7 @@
},

"dependencies": {
"@nevware21/ts-utils": ">= 0.10.5 < 2.x"
"@nevware21/ts-utils": ">= 0.11.0 < 2.x"
},
"devDependencies": {
"@nevware21/tools-pre-proc": "0.1.0",
Expand Down
99 changes: 52 additions & 47 deletions lib/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import cleanup from 'rollup-plugin-cleanup';
import minify from "rollup-plugin-minify-es";

Expand Down Expand Up @@ -87,7 +88,7 @@ const rollupConfigFactory = (srcPath, destPath, isMinified, path, format = "iife
const taskRollupConfig = {
input: `./${srcPath}/index.js`,
output: {
file: `./bundle/${destPath}/${path}/${outputName}${postfix}.js`,
file: `./${destPath}/${path}/${outputName}${postfix}.js`,
banner: banner,
format: format,
name: "nevware21.ts-async",
Expand All @@ -102,6 +103,7 @@ const rollupConfigFactory = (srcPath, destPath, isMinified, path, format = "iife
preferBuiltins: true,
mainFields: mainFields
}),
commonjs(),
cleanup({
comments: [
/[#@]__/,
Expand All @@ -112,7 +114,7 @@ const rollupConfigFactory = (srcPath, destPath, isMinified, path, format = "iife
};

if (isMinified) {
taskRollupConfig.output.file = `./bundle/${destPath}/${path}/${outputName}${postfix}.min.js`;
taskRollupConfig.output.file = `./${destPath}/${path}/${outputName}${postfix}.min.js`;
if (format !== "esm") {
taskRollupConfig.plugins.push(
uglify3({
Expand Down Expand Up @@ -149,7 +151,7 @@ const rollupConfigFactory = (srcPath, destPath, isMinified, path, format = "iife
return taskRollupConfig;
};

const rollupConfigMainEntry = (srcPath, destPath, path) => {
const rollupConfigMainEntry = (srcPath, destPath, path, format = "umd") => {
let mainFields = [ "module", "main" ];
if (destPath === "es6") {
mainFields = [ "esnext", "module", "main" ];
Expand All @@ -158,26 +160,24 @@ const rollupConfigMainEntry = (srcPath, destPath, path) => {
const taskRollupConfig = {
input: `./${srcPath}/index.js`,
output: {
file: `./dist/${destPath}/${path}/${outputName}.js`,
file: `./${destPath}/${path}/${outputName}.js`,
banner: banner,
format: "umd",
format: format,
name: "nevware21.ts-async",
freeze: false,
sourcemap: true
sourcemap: true,
globals: {
"@nevware21/ts-utils": "nevware21.ts-utils"
}
},
external: [ "fs", "path" ],
external: [ "fs", "path", "@nevware21/ts-utils" ],
plugins: [
nodeResolve({
module: true,
browser: false,
preferBuiltins: true,
mainFields: mainFields
}),
cleanup({
comments: [
/[#@]__/,
/^!/,
"some"
"some",
"ts"
]
})
]
Expand Down Expand Up @@ -215,7 +215,7 @@ const polyfillRollupConfigFactory = (srcPath, destPath, isMinified, format = "ii
const taskRollupConfig = {
input: `./${srcPath}/polyfills.js`,
output: {
file: `./bundle/${destPath}/${polyFillOutputName}${postfix}.js`,
file: `./${destPath}/${polyFillOutputName}${postfix}.js`,
banner: polyFillBanner,
format: format,
name: "nevware21.ts-async",
Expand All @@ -229,6 +229,7 @@ const polyfillRollupConfigFactory = (srcPath, destPath, isMinified, format = "ii
browser: false,
preferBuiltins: true
}),
commonjs(),
cleanup({
comments: [
/[#@]__/,
Expand All @@ -239,7 +240,7 @@ const polyfillRollupConfigFactory = (srcPath, destPath, isMinified, format = "ii
};

if (isMinified) {
taskRollupConfig.output.file = `./bundle/${destPath}/${polyFillOutputName}${postfix}.min.js`;
taskRollupConfig.output.file = `./${destPath}/${polyFillOutputName}${postfix}.min.js`;
taskRollupConfig.plugins.push(
uglify3({
ie8: false,
Expand All @@ -263,35 +264,39 @@ export default [
//rollupModule("build/es5", "dist-es5", false),
// rollupModule("build/es6", "dist-es6", false),

polyfillRollupConfigFactory("dist-es5", "es5", true),
polyfillRollupConfigFactory("dist-es5", "es5", false),

rollupConfigMainEntry("dist-es5", "es5", "main"),
rollupConfigMainEntry("dist-es6", "es6", "main"),

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

rollupConfigFactory("dist-es6", "es6", false, "esm", "esm"),
rollupConfigFactory("dist-es6", "es6", true, "esm", "esm"),
// rollupConfigFactory("dist-es6", "es6", false, "amd", "amd"),
// rollupConfigFactory("dist-es6", "es6", true, "amd", "amd"),
// rollupConfigFactory("dist-es6", "es6", false, "cjs", "cjs"),
// rollupConfigFactory("dist-es6", "es6", true, "cjs", "cjs"),
rollupConfigFactory("dist-es6", "es6", false, "iife", "iife"),
rollupConfigFactory("dist-es6", "es6", true, "iife", "iife"),
rollupConfigFactory("dist-es6", "es6", false, "umd", "umd"),
rollupConfigFactory("dist-es6", "es6", true, "umd", "umd")
// rollupConfigFactory("dist-es6", "es6", false, "system", "system"),
// rollupConfigFactory("dist-es6", "es6", true, "system", "system")
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")
];
24 changes: 12 additions & 12 deletions lib/src/helpers/doWhileAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ const _doneChk = /*#__PURE__*/<T>(isDone: boolean, state: IWhileState<T>, value:
* callback function returns a promise the while loop will be asynchronous and an {@link IPromise}
* will be returned and resolved with the last value returned by the callback or rejected if the
* callback promise rejects or throws an error.
* @since 0.5.0
* @group Loop
* @typeParam T - Identifies the element type returned by the callback function.
* @param callbackFn A function that will be called until the `state.isDone` flag is set to `true`
* the function will receive a single {@link IWhileState state} argument. The callback function
* may return either a value or a promise, if a promise is returned the while loop will wait
* until the promise is resolved before calling the callback function again.
* @param isDoneFn An optional function that will be called after the callback function is called,
* that can be used to stop the while loop. The function will receive a single {@link IWhileState state}
* argument. If the function returns `true` the while loop will stop, otherwise the while loop will continue.
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
* If thisArg is omitted, null or undefined the array will be used as the this value.
* @remarks
* - If an `isDoneFn` is provided the `state.isDone` property will be set to the provided value and
* is accessible withing the callback function. The callbackFn may overwrite the value of the
Expand All @@ -63,18 +75,6 @@ const _doneChk = /*#__PURE__*/<T>(isDone: boolean, state: IWhileState<T>, value:
* loop will wait until the promise is resolved before calling the callback function again.
* - If the callback function throws an error when executing `synchronously` the exception will
* also be thrown `synchronously` otherwise the returned promise will be rejected with the error.
* @since 0.5.0
* @group Loop
* @typeParam T - Identifies the element type returned by the callback function.
* @param callbackFn A function that will be called until the `state.isDone` flag is set to `true`
* the function will receive a single {@link IWhileState state} argument. The callback function
* may return either a value or a promise, if a promise is returned the while loop will wait
* until the promise is resolved before calling the callback function again.
* @param isDoneFn An optional function that will be called after the callback function is called,
* that can be used to stop the while loop. The function will receive a single {@link IWhileState state}
* argument. If the function returns `true` the while loop will stop, otherwise the while loop will continue.
* @param thisArg An object to which the this keyword can refer in the callbackfn function.
* If thisArg is omitted, null or undefined the array will be used as the this value.
* @example
* ```ts
* // Synchronous example
Expand Down
30 changes: 1 addition & 29 deletions lib/src/interfaces/IPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface IPromise<T> extends PromiseLike<T>, Promise<T> {
* // expected output: Uh-oh!
* ```
*/
catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): Promise<T | TResult>;
catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): Promise<T | TResult>;

/**
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
Expand Down Expand Up @@ -195,32 +195,4 @@ export interface IPromise<T> extends PromiseLike<T>, Promise<T> {
* ```
*/
finally(onfinally?: FinallyPromiseHandler): IPromise<T>

/**
* Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
* resolved value cannot be modified from the callback.
* @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
* @returns A Promise for the completion of the callback.
* @example
* ```ts
* function doFunction() {
* return createPromise((resolve, reject) => {
* if (Math.random() > 0.5) {
* resolve('Function has completed');
* } else {
* reject(new Error('Function failed to process'));
* }
* });
* }
*
* doFunction().then((data) => {
* console.log(data);
* }).catch((err) => {
* console.error(err);
* }).finally(() => {
* console.log('Function processing completed');
* });
* ```
*/
finally(onFinally?: FinallyPromiseHandler): Promise<T>;
}
11 changes: 7 additions & 4 deletions lib/src/promise/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT license.
*/

import { objDefineProp } from "@nevware21/ts-utils";
import { objDefineProperties } from "@nevware21/ts-utils";

let _debugState: any;
let _debugResult: any;
Expand Down Expand Up @@ -53,9 +53,12 @@ export function _addDebugState(thePromise: any, stateFn: () => string, resultFn:
_debugResult = _debugResult || { toString: () => "[[PromiseResult]]" };
_debugHandled = _debugHandled || { toString: () => "[[PromiseIsHandled]]" };

objDefineProp(thePromise, _debugState, { get: stateFn });
objDefineProp(thePromise, _debugResult, { get: resultFn });
objDefineProp(thePromise, _debugHandled, { get: handledFn });
let props: PropertyDescriptorMap = {};
props[_debugState] = { get: stateFn };
props[_debugResult] = { get: resultFn };
props[_debugHandled] = { get: handledFn };

objDefineProperties(thePromise, props);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/src/promise/timeoutPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @nevware21/ts-async
* https://github.com/nevware21/ts-async
*
* Copyright (c) 2022 Nevware21
* Copyright (c) 2024 Nevware21
* Licensed under the MIT license.
*/

Expand Down
Loading

0 comments on commit d2e0db2

Please sign in to comment.