@tapjs/processinfo 2.0.0 → 2.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.
@@ -1,11 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import type { Serializable } from 'worker_threads';
3
1
  export * from './index.js';
4
- type GPPort = {
5
- postMessage: (x: Serializable) => any;
6
- };
7
- export declare const globalPreload: (context: {
8
- port?: GPPort;
9
- }) => string;
2
+ export declare const globalPreload: () => string;
10
3
  export declare const load: (url: string, context: any, nextLoad: Function) => Promise<any>;
11
4
  //# sourceMappingURL=esm.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"esm.d.mts","sourceRoot":"","sources":["../../lib/esm.mts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAOlD,cAAc,YAAY,CAAA;AAU1B,KAAK,MAAM,GAAG;IACZ,WAAW,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,GAAG,CAAA;CACtC,CAAA;AAED,eAAO,MAAM,aAAa,YAAa;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,WAkBvD,CAAA;AAGD,eAAO,MAAM,IAAI,QACV,MAAM,WACF,GAAG,YACF,QAAQ,iBAcnB,CAAA"}
1
+ {"version":3,"file":"esm.d.mts","sourceRoot":"","sources":["../../lib/esm.mts"],"names":[],"mappings":"AAOA,cAAc,YAAY,CAAA;AAa1B,eAAO,MAAM,aAAa,cAczB,CAAA;AAGD,eAAO,MAAM,IAAI,QACV,MAAM,WACF,GAAG,YACF,QAAQ,iBASnB,CAAA"}
package/dist/mjs/esm.mjs CHANGED
@@ -1,29 +1,33 @@
1
1
  // usage: node '--loader=@tapjs/processinfo/esm' foo.mjs
2
2
  import { fileURLToPath } from 'url';
3
3
  import { getExclude } from './get-exclude.js';
4
- import { getProcessInfo } from './get-process-info.js';
5
4
  import { resolve } from './require-resolve.js';
6
5
  // copy main module so that we can --loader=@tapjs/processinfo and use
7
6
  // this as the entry point as well.
8
7
  export * from './index.js';
9
- let PORT = undefined;
10
- export const globalPreload = (context) => {
8
+ import { channel } from 'diagnostics_channel';
9
+ const PORT = channel('@tapjs/processinfo.files-loaded');
10
+ // on Node v20, loaders are executed in a separate isolated environment
11
+ // As a result, to register coverage and track files, we need to act in
12
+ // the globalPreload function. The load() method posts a message with the
13
+ // filename being loaded, because any registrations that happen in the
14
+ // loader thread will not have any effect.
15
+ // Using diagnostics channel means that this will keep working in all
16
+ // the versions supported, and easily be transferrable to an --import
17
+ // argument that attaches the loaders at run-time.
18
+ export const globalPreload = () => {
11
19
  // this will be something like path/to/dist/mjs/lib/esm.mjs
12
20
  // but we need path/to/dist/cjs/cjs.js
13
21
  const base = resolve('../cjs/cjs.js');
14
- const { port } = context || {};
15
- PORT = port;
16
22
  return `
17
- if (typeof port !== 'undefined') {
18
- const { createRequire } = getBuiltin('module')
19
- const require = createRequire(${JSON.stringify(base)})
20
- const { getProcessInfo } = require('./get-process-info.js')
21
- // must be called eagerly here.
22
- // this does all the registration as well.
23
- const processInfo = getProcessInfo()
24
- port.onmessage = (e) => processInfo.files.push(e.data)
25
- port.unref()
26
- }
23
+ const { createRequire } = getBuiltin('module')
24
+ const require = createRequire(${JSON.stringify(base)})
25
+ const { getProcessInfo } = require('./get-process-info.js')
26
+ const processInfo = getProcessInfo()
27
+ const { channel, subscribe } = require('diagnostics_channel')
28
+ subscribe('@tapjs/processinfo.files-loaded',
29
+ (e) => processInfo.files.push(e)
30
+ )
27
31
  `;
28
32
  };
29
33
  const exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_');
@@ -31,13 +35,7 @@ export const load = async (url, context, nextLoad) => {
31
35
  if (/^file:/.test(url)) {
32
36
  const filename = fileURLToPath(url);
33
37
  if (!exclude.test(filename)) {
34
- if (PORT) {
35
- PORT.postMessage(filename);
36
- }
37
- else {
38
- // call lazily so we don't double-register
39
- getProcessInfo().files.push(filename);
40
- }
38
+ PORT.publish(filename);
41
39
  }
42
40
  }
43
41
  return nextLoad(url, context);
@@ -1 +1 @@
1
- {"version":3,"file":"esm.mjs","sourceRoot":"","sources":["../../lib/esm.mts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAE9C,sEAAsE;AACtE,mCAAmC;AACnC,cAAc,YAAY,CAAA;AAa1B,IAAI,IAAI,GAAuB,SAAS,CAAA;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAA0B,EAAE,EAAE;IAC1D,2DAA2D;IAC3D,sCAAsC;IACtC,MAAM,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IACrC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;IAC9B,IAAI,GAAG,IAAI,CAAA;IACX,OAAO;;;kCAGyB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;;;;;;;;CAQrD,CAAA;AACD,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,UAAU,CAAC,6BAA6B,CAAC,CAAA;AACzD,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EACvB,GAAW,EACX,OAAY,EACZ,QAAkB,EAClB,EAAE;IACF,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACtB,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QACnC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC3B,IAAI,IAAI,EAAE;gBACR,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;aAC3B;iBAAM;gBACL,0CAA0C;gBAC1C,cAAc,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;aACtC;SACF;KACF;IACD,OAAO,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAA","sourcesContent":["// usage: node '--loader=@tapjs/processinfo/esm' foo.mjs\nimport { fileURLToPath } from 'url'\nimport type { Serializable } from 'worker_threads'\nimport { getExclude } from './get-exclude.js'\nimport { getProcessInfo } from './get-process-info.js'\nimport { resolve } from './require-resolve.js'\n\n// copy main module so that we can --loader=@tapjs/processinfo and use\n// this as the entry point as well.\nexport * from './index.js'\n\n// on Node v20, loaders are executed in a separate isolated environment\n// As a result, to register coverage and track files, we need to act in\n// the globalPreload function. The load() method posts a message with the\n// filename being loaded, because any registrations that happen in the\n// loader thread will not have any effect.\n// The check for the 'port' being undefined is to allow for support back to\n// 16.12, which had a globalPreload method, but did not have a sendMessage\n// port in that environment.\ntype GPPort = {\n postMessage: (x: Serializable) => any\n}\nlet PORT: undefined | GPPort = undefined\nexport const globalPreload = (context: { port?: GPPort }) => {\n // this will be something like path/to/dist/mjs/lib/esm.mjs\n // but we need path/to/dist/cjs/cjs.js\n const base = resolve('../cjs/cjs.js')\n const { port } = context || {}\n PORT = port\n return `\nif (typeof port !== 'undefined') {\n const { createRequire } = getBuiltin('module')\n const require = createRequire(${JSON.stringify(base)})\n const { getProcessInfo } = require('./get-process-info.js')\n // must be called eagerly here.\n // this does all the registration as well.\n const processInfo = getProcessInfo()\n port.onmessage = (e) => processInfo.files.push(e.data)\n port.unref()\n}\n`\n}\n\nconst exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_')\nexport const load = async (\n url: string,\n context: any,\n nextLoad: Function\n) => {\n if (/^file:/.test(url)) {\n const filename = fileURLToPath(url)\n if (!exclude.test(filename)) {\n if (PORT) {\n PORT.postMessage(filename)\n } else {\n // call lazily so we don't double-register\n getProcessInfo().files.push(filename)\n }\n }\n }\n return nextLoad(url, context)\n}\n"]}
1
+ {"version":3,"file":"esm.mjs","sourceRoot":"","sources":["../../lib/esm.mts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAE9C,sEAAsE;AACtE,mCAAmC;AACnC,cAAc,YAAY,CAAA;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAA;AAEvD,uEAAuE;AACvE,uEAAuE;AACvE,yEAAyE;AACzE,sEAAsE;AACtE,0CAA0C;AAC1C,qEAAqE;AACrE,qEAAqE;AACrE,kDAAkD;AAClD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE;IAChC,2DAA2D;IAC3D,sCAAsC;IACtC,MAAM,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IACrC,OAAO;;gCAEuB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;;;;;;;CAOnD,CAAA;AACD,CAAC,CAAA;AAED,MAAM,OAAO,GAAG,UAAU,CAAC,6BAA6B,CAAC,CAAA;AACzD,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EACvB,GAAW,EACX,OAAY,EACZ,QAAkB,EAClB,EAAE;IACF,IAAI,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACtB,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QACnC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAC3B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;SACvB;KACF;IACD,OAAO,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAC/B,CAAC,CAAA","sourcesContent":["// usage: node '--loader=@tapjs/processinfo/esm' foo.mjs\nimport { fileURLToPath } from 'url'\nimport { getExclude } from './get-exclude.js'\nimport { resolve } from './require-resolve.js'\n\n// copy main module so that we can --loader=@tapjs/processinfo and use\n// this as the entry point as well.\nexport * from './index.js'\n\nimport { channel } from 'diagnostics_channel'\nconst PORT = channel('@tapjs/processinfo.files-loaded')\n\n// on Node v20, loaders are executed in a separate isolated environment\n// As a result, to register coverage and track files, we need to act in\n// the globalPreload function. The load() method posts a message with the\n// filename being loaded, because any registrations that happen in the\n// loader thread will not have any effect.\n// Using diagnostics channel means that this will keep working in all\n// the versions supported, and easily be transferrable to an --import\n// argument that attaches the loaders at run-time.\nexport const globalPreload = () => {\n // this will be something like path/to/dist/mjs/lib/esm.mjs\n // but we need path/to/dist/cjs/cjs.js\n const base = resolve('../cjs/cjs.js')\n return `\nconst { createRequire } = getBuiltin('module')\nconst require = createRequire(${JSON.stringify(base)})\nconst { getProcessInfo } = require('./get-process-info.js')\nconst processInfo = getProcessInfo()\nconst { channel, subscribe } = require('diagnostics_channel')\nsubscribe('@tapjs/processinfo.files-loaded',\n (e) => processInfo.files.push(e)\n)\n`\n}\n\nconst exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_')\nexport const load = async (\n url: string,\n context: any,\n nextLoad: Function\n) => {\n if (/^file:/.test(url)) {\n const filename = fileURLToPath(url)\n if (!exclude.test(filename)) {\n PORT.publish(filename)\n }\n }\n return nextLoad(url, context)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapjs/processinfo",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "types": "./dist/cjs/index.d.ts",
6
6
  "module": "./dist/mjs/esm.mjs",
@@ -10,8 +10,8 @@
10
10
  "exports": {
11
11
  ".": {
12
12
  "import": {
13
- "types": "./dist/mjs/esm.d.ts",
14
- "default": "./dist/mjs/esm.js"
13
+ "types": "./dist/mjs/esm.d.mts",
14
+ "default": "./dist/mjs/esm.mjs"
15
15
  },
16
16
  "require": {
17
17
  "types": "./dist/cjs/index.d.ts",
package/dist/cjs/x.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const foo = "bar";
2
- //# sourceMappingURL=x.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"x.d.ts","sourceRoot":"","sources":["../../lib/x.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG,QAAQ,CAAA"}
package/dist/cjs/x.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.foo = void 0;
4
- exports.foo = 'bar';
5
- //# sourceMappingURL=x.js.map
package/dist/cjs/x.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"x.js","sourceRoot":"","sources":["../../lib/x.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG,KAAK,CAAA","sourcesContent":["export const foo = 'bar'\n"]}
package/dist/mjs/x.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare const foo = "bar";
2
- //# sourceMappingURL=x.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"x.d.ts","sourceRoot":"","sources":["../../lib/x.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG,QAAQ,CAAA"}
package/dist/mjs/x.js DELETED
@@ -1,2 +0,0 @@
1
- export const foo = 'bar';
2
- //# sourceMappingURL=x.js.map
package/dist/mjs/x.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"x.js","sourceRoot":"","sources":["../../lib/x.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,CAAA","sourcesContent":["export const foo = 'bar'\n"]}