@node-cli/perf 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -3,4 +3,3 @@
3
3
  */
4
4
 
5
5
  export * from "./performance";
6
- export * from "./unique-id";
@@ -1,6 +1,6 @@
1
1
  import { PerformanceObserver, performance } from "node:perf_hooks";
2
2
  import { Logger } from "@node-cli/logger";
3
- import { uniqueID } from "./unique-id.js";
3
+ import { uniqueID } from "@node-cli/utilities";
4
4
  const logger = new Logger({
5
5
  boring: process.env.NODE_ENV === "test"
6
6
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/performance.ts"],"sourcesContent":["import { PerformanceObserver, performance } from \"node:perf_hooks\";\n\nimport { Logger } from \"@node-cli/logger\";\nimport { uniqueID } from \"./unique-id.js\";\n\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nexport class Performance {\n\tperfObserver: PerformanceObserver;\n\tstartMarkerName: any;\n\tmeasureName: string;\n\n\tconstructor() {\n\t\tthis.perfObserver = new PerformanceObserver(\n\t\t\t/* istanbul ignore next */ () => {\n\t\t\t\tperformance.clearMeasures();\n\t\t\t}\n\t\t);\n\t\tthis.perfObserver.observe({ type: \"measure\" });\n\t}\n\n\tstart() {\n\t\tif (this.startMarkerName) {\n\t\t\tlogger.error(\"Performance.start() can only be called once\");\n\t\t} else {\n\t\t\tthis.startMarkerName = uniqueID();\n\t\t\tperformance.mark(this.startMarkerName);\n\t\t}\n\t}\n\n\tstop() {\n\t\tif (this.startMarkerName) {\n\t\t\tconst stopMarkerName = uniqueID();\n\t\t\tthis.measureName = `internal-${this.startMarkerName}-${stopMarkerName}`;\n\n\t\t\tperformance.mark(stopMarkerName);\n\n\t\t\tperformance.measure(\n\t\t\t\tthis.measureName,\n\t\t\t\tthis.startMarkerName,\n\t\t\t\tstopMarkerName\n\t\t\t);\n\t\t\tthis.startMarkerName = undefined;\n\t\t} else {\n\t\t\tlogger.error(\n\t\t\t\t\"Performance.stop() can only be called once after Performance.start()\"\n\t\t\t);\n\t\t}\n\t}\n\n\tstatic now() {\n\t\treturn performance?.now() * 1e6;\n\t}\n\n\tget now() {\n\t\treturn Performance.now;\n\t}\n\n\tget results() {\n\t\treturn {\n\t\t\tduration:\n\t\t\t\tperformance?.getEntriesByName(this.measureName)[0]?.duration ||\n\t\t\t\tundefined,\n\t\t};\n\t}\n}\n"],"names":["PerformanceObserver","performance","Logger","uniqueID","logger","boring","process","env","NODE_ENV","Performance","perfObserver","startMarkerName","measureName","constructor","clearMeasures","observe","type","start","error","mark","stop","stopMarkerName","measure","undefined","now","results","duration","getEntriesByName"],"mappings":"AAAA,SAASA,mBAAmB,EAAEC,WAAW,QAAQ,kBAAkB;AAEnE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,QAAQ,QAAQ,iBAAiB;AAE1C,MAAMC,SAAS,IAAIF,OAAO;IACzBG,QAAQC,QAAQC,IAAIC,aAAa;AAClC;AAEA,OAAO,MAAMC;IACZC,aAAkC;IAClCC,gBAAqB;IACrBC,YAAoB;IAEpBC,aAAc;QACb,IAAI,CAACH,eAAe,IAAIV,oBACvB,wBAAwB,GAAG;YAC1BC,YAAYa;QACb;QAED,IAAI,CAACJ,aAAaK,QAAQ;YAAEC,MAAM;QAAU;IAC7C;IAEAC,QAAQ;QACP,IAAI,IAAI,CAACN,iBAAiB;YACzBP,OAAOc,MAAM;QACd,OAAO;YACN,IAAI,CAACP,kBAAkBR;YACvBF,YAAYkB,KAAK,IAAI,CAACR;QACvB;IACD;IAEAS,OAAO;QACN,IAAI,IAAI,CAACT,iBAAiB;YACzB,MAAMU,iBAAiBlB;YACvB,IAAI,CAACS,cAAc,CAAC,SAAS,EAAE,IAAI,CAACD,gBAAgB,CAAC,EAAEU,eAAe,CAAC;YAEvEpB,YAAYkB,KAAKE;YAEjBpB,YAAYqB,QACX,IAAI,CAACV,aACL,IAAI,CAACD,iBACLU;YAED,IAAI,CAACV,kBAAkBY;QACxB,OAAO;YACNnB,OAAOc,MACN;QAEF;IACD;IAEA,OAAOM,MAAM;QACZ,OAAOvB,aAAauB,QAAQ;IAC7B;IAEA,IAAIA,MAAM;QACT,OAAOf,YAAYe;IACpB;IAEA,IAAIC,UAAU;QACb,OAAO;YACNC,UACCzB,aAAa0B,iBAAiB,IAAI,CAACf,YAAY,CAAC,EAAE,EAAEc,YACpDH;QACF;IACD;AACD"}
1
+ {"version":3,"sources":["../src/performance.ts"],"sourcesContent":["import { PerformanceObserver, performance } from \"node:perf_hooks\";\n\nimport { Logger } from \"@node-cli/logger\";\nimport { uniqueID } from \"@node-cli/utilities\";\n\nconst logger = new Logger({\n\tboring: process.env.NODE_ENV === \"test\",\n});\n\nexport class Performance {\n\tperfObserver: PerformanceObserver;\n\tstartMarkerName: any;\n\tmeasureName: string;\n\n\tconstructor() {\n\t\tthis.perfObserver = new PerformanceObserver(\n\t\t\t/* istanbul ignore next */ () => {\n\t\t\t\tperformance.clearMeasures();\n\t\t\t}\n\t\t);\n\t\tthis.perfObserver.observe({ type: \"measure\" });\n\t}\n\n\tstart() {\n\t\tif (this.startMarkerName) {\n\t\t\tlogger.error(\"Performance.start() can only be called once\");\n\t\t} else {\n\t\t\tthis.startMarkerName = uniqueID();\n\t\t\tperformance.mark(this.startMarkerName);\n\t\t}\n\t}\n\n\tstop() {\n\t\tif (this.startMarkerName) {\n\t\t\tconst stopMarkerName = uniqueID();\n\t\t\tthis.measureName = `internal-${this.startMarkerName}-${stopMarkerName}`;\n\n\t\t\tperformance.mark(stopMarkerName);\n\n\t\t\tperformance.measure(\n\t\t\t\tthis.measureName,\n\t\t\t\tthis.startMarkerName,\n\t\t\t\tstopMarkerName\n\t\t\t);\n\t\t\tthis.startMarkerName = undefined;\n\t\t} else {\n\t\t\tlogger.error(\n\t\t\t\t\"Performance.stop() can only be called once after Performance.start()\"\n\t\t\t);\n\t\t}\n\t}\n\n\tstatic now() {\n\t\treturn performance?.now() * 1e6;\n\t}\n\n\tget now() {\n\t\treturn Performance.now;\n\t}\n\n\tget results() {\n\t\treturn {\n\t\t\tduration:\n\t\t\t\tperformance?.getEntriesByName(this.measureName)[0]?.duration ||\n\t\t\t\tundefined,\n\t\t};\n\t}\n}\n"],"names":["PerformanceObserver","performance","Logger","uniqueID","logger","boring","process","env","NODE_ENV","Performance","perfObserver","startMarkerName","measureName","constructor","clearMeasures","observe","type","start","error","mark","stop","stopMarkerName","measure","undefined","now","results","duration","getEntriesByName"],"mappings":"AAAA,SAASA,mBAAmB,EAAEC,WAAW,QAAQ,kBAAkB;AAEnE,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,QAAQ,QAAQ,sBAAsB;AAE/C,MAAMC,SAAS,IAAIF,OAAO;IACzBG,QAAQC,QAAQC,IAAIC,aAAa;AAClC;AAEA,OAAO,MAAMC;IACZC,aAAkC;IAClCC,gBAAqB;IACrBC,YAAoB;IAEpBC,aAAc;QACb,IAAI,CAACH,eAAe,IAAIV,oBACvB,wBAAwB,GAAG;YAC1BC,YAAYa;QACb;QAED,IAAI,CAACJ,aAAaK,QAAQ;YAAEC,MAAM;QAAU;IAC7C;IAEAC,QAAQ;QACP,IAAI,IAAI,CAACN,iBAAiB;YACzBP,OAAOc,MAAM;QACd,OAAO;YACN,IAAI,CAACP,kBAAkBR;YACvBF,YAAYkB,KAAK,IAAI,CAACR;QACvB;IACD;IAEAS,OAAO;QACN,IAAI,IAAI,CAACT,iBAAiB;YACzB,MAAMU,iBAAiBlB;YACvB,IAAI,CAACS,cAAc,CAAC,SAAS,EAAE,IAAI,CAACD,gBAAgB,CAAC,EAAEU,eAAe,CAAC;YAEvEpB,YAAYkB,KAAKE;YAEjBpB,YAAYqB,QACX,IAAI,CAACV,aACL,IAAI,CAACD,iBACLU;YAED,IAAI,CAACV,kBAAkBY;QACxB,OAAO;YACNnB,OAAOc,MACN;QAEF;IACD;IAEA,OAAOM,MAAM;QACZ,OAAOvB,aAAauB,QAAQ;IAC7B;IAEA,IAAIA,MAAM;QACT,OAAOf,YAAYe;IACpB;IAEA,IAAIC,UAAU;QACb,OAAO;YACNC,UACCzB,aAAa0B,iBAAiB,IAAI,CAACf,YAAY,CAAC,EAAE,EAAEc,YACpDH;QACF;IACD;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/perf",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "Set of performance tools for Node.js",
@@ -13,7 +13,7 @@
13
13
  "node": ">=16",
14
14
  "dependencies": {
15
15
  "@node-cli/logger": ">=1.0.0",
16
- "lodash": "4.17.21"
16
+ "@node-cli/utilities": ">=1.0.0"
17
17
  },
18
18
  "scripts": {
19
19
  "build": "yarn run clean && yarn run build:types && yarn run build:js && yarn run build:barrel",
@@ -29,5 +29,5 @@
29
29
  "publishConfig": {
30
30
  "access": "public"
31
31
  },
32
- "gitHead": "2e74543c37e77ca482acc9fda6d8716bc634e722"
32
+ "gitHead": "f70aec7d6e950b8c76048917a1fcb01c90a0beb3"
33
33
  }
@@ -1,17 +0,0 @@
1
- /**
2
- * Generate a random number to append to an `id` string.
3
- *
4
- * NOTE: we are still using the good old lodash uniqueId when
5
- * the code is not in production, so that the results are a
6
- * little bit more consistent tests after test instead of
7
- * being completely random, so that they do not break
8
- * potential snapshot tests.
9
- *
10
- * @param {String} prefix - When a prefix is provided, the
11
- * function will return a random
12
- * number appended to the provided
13
- * prefix.
14
- *
15
- * @returns {String} - Returns a string with random numbers.
16
- */
17
- export declare const uniqueID: (prefix?: string) => string;
package/dist/unique-id.js DELETED
@@ -1,26 +0,0 @@
1
- import _ from "lodash";
2
- /**
3
- * Generate a random number to append to an `id` string.
4
- *
5
- * NOTE: we are still using the good old lodash uniqueId when
6
- * the code is not in production, so that the results are a
7
- * little bit more consistent tests after test instead of
8
- * being completely random, so that they do not break
9
- * potential snapshot tests.
10
- *
11
- * @param {String} prefix - When a prefix is provided, the
12
- * function will return a random
13
- * number appended to the provided
14
- * prefix.
15
- *
16
- * @returns {String} - Returns a string with random numbers.
17
- */ export const uniqueID = (prefix)=>{
18
- if (process.env.NODE_ENV !== "production") {
19
- return _.uniqueId(prefix);
20
- }
21
- // Extract the decimal part
22
- const randomNumber = `${Math.random()}`.split(".")[1];
23
- return prefix ? `${prefix}${randomNumber}` : randomNumber;
24
- };
25
-
26
- //# sourceMappingURL=unique-id.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/unique-id.ts"],"sourcesContent":["import _ from \"lodash\";\n\n/**\n * Generate a random number to append to an `id` string.\n *\n * NOTE: we are still using the good old lodash uniqueId when\n * the code is not in production, so that the results are a\n * little bit more consistent tests after test instead of\n * being completely random, so that they do not break\n * potential snapshot tests.\n *\n * @param {String} prefix - When a prefix is provided, the\n * function will return a random\n * number appended to the provided\n * prefix.\n *\n * @returns {String} - Returns a string with random numbers.\n */\nexport const uniqueID = (prefix?: string): string => {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\treturn _.uniqueId(prefix);\n\t}\n\t// Extract the decimal part\n\tconst randomNumber = `${Math.random()}`.split(\".\")[1];\n\treturn prefix ? `${prefix}${randomNumber}` : randomNumber;\n};\n"],"names":["_","uniqueID","prefix","process","env","NODE_ENV","uniqueId","randomNumber","Math","random","split"],"mappings":"AAAA,OAAOA,OAAO,SAAS;AAEvB;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMC,WAAW,CAACC;IACxB,IAAIC,QAAQC,IAAIC,aAAa,cAAc;QAC1C,OAAOL,EAAEM,SAASJ;IACnB;IACA,2BAA2B;IAC3B,MAAMK,eAAe,CAAC,EAAEC,KAAKC,SAAS,CAAC,CAACC,MAAM,IAAI,CAAC,EAAE;IACrD,OAAOR,SAAS,CAAC,EAAEA,OAAO,EAAEK,aAAa,CAAC,GAAGA;AAC9C,EAAE"}