@tapjs/processinfo 3.0.0 → 3.0.1

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,3 +1,4 @@
1
- export declare const saveLineLengths: (filename: string, content: string) => void;
1
+ /// <reference types="node" />
2
+ export declare const saveLineLengths: (filename: string, content?: string | Buffer) => void;
2
3
  export declare const getLineLengths: (filename: string) => number[] | undefined;
3
4
  //# sourceMappingURL=line-lengths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-lengths.d.ts","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,eAAe,aAAc,MAAM,WAAW,MAAM,SAchE,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
1
+ {"version":3,"file":"line-lengths.d.ts","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAYA,eAAO,MAAM,eAAe,aAAc,MAAM,YAAY,MAAM,GAAG,MAAM,SAgB1E,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
@@ -9,6 +9,10 @@ const cache = g[kLLC] || new Map();
9
9
  g[kLLC] = cache;
10
10
  const sourceMapComment = '//# sourceMappingURL=';
11
11
  const saveLineLengths = (filename, content) => {
12
+ if (content === undefined)
13
+ return;
14
+ if (typeof content === 'object')
15
+ content = String(content);
12
16
  if (filename.startsWith('file://'))
13
17
  filename = (0, url_1.fileURLToPath)(filename);
14
18
  // no need if it's not sourcemapped
@@ -1 +1 @@
1
- {"version":3,"file":"line-lengths.js","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;AAExE,6BAAmC;AAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;AAC9D,MAAM,CAAC,GAAG,MAET,CAAA;AACD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC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LLC = Symbol.for('@tapjs/processinfo lineLength cache')\nconst g = global as {\n [kLLC]?: Map<string, number[]>\n}\nconst cache = g[kLLC] || new Map<string, number[]>()\ng[kLLC] = cache\n\nconst sourceMapComment = '//# sourceMappingURL='\nexport const saveLineLengths = (filename: string, content: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n // no need if it's not sourcemapped\n // don't cache an empty array, though, because ts-node files will show\n // up first as source, and then as their built content.\n const last = content.trimEnd().split('\\n').pop()\n if (cache.has(filename) || !last?.startsWith(sourceMapComment)) return\n const ll = content\n .replace(/[\\n\\u2028\\u2029]$/, '')\n .split(/\\n|\\u2028|\\u2029/)\n .map(l => l.length)\n cache.set(filename, ll)\n\n cache.set(filename, ll)\n}\n\nexport const getLineLengths = (filename: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n return cache.get(filename)\n}\n"]}
1
+ {"version":3,"file":"line-lengths.js","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;AAExE,6BAAmC;AAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;AAC9D,MAAM,CAAC,GAAG,MAET,CAAA;AACD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAoB,CAAA;AACpD,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;AAEf,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AACzC,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,OAAyB,EAAE,EAAE;IAC7E,IAAI,OAAO,KAAK,SAAS;QAAE,OAAM;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC1D,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,IAAA,mBAAa,EAAC,QAAQ,CAAC,CAAA;IACtE,mCAAmC;IACnC,sEAAsE;IACtE,uDAAuD;IACvD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;IAChD,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAM;IACtE,MAAM,EAAE,GAAG,OAAO;SACf,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,KAAK,CAAC,kBAAkB,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IACrB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAEvB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AACzB,CAAC,CAAA;AAhBY,QAAA,eAAe,mBAgB3B;AAEM,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,EAAE;IACjD,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,IAAA,mBAAa,EAAC,QAAQ,CAAC,CAAA;IACtE,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC5B,CAAC,CAAA;AAHY,QAAA,cAAc,kBAG1B","sourcesContent":["// TODO: Refactor once https://github.com/nodejs/node/issues/48460 fixed\n\nimport { fileURLToPath } from 'url'\n\nconst kLLC = Symbol.for('@tapjs/processinfo lineLength cache')\nconst g = global as {\n [kLLC]?: Map<string, number[]>\n}\nconst cache = g[kLLC] || new Map<string, number[]>()\ng[kLLC] = cache\n\nconst sourceMapComment = '//# sourceMappingURL='\nexport const saveLineLengths = (filename: string, content?: string | Buffer) => {\n if (content === undefined) return\n if (typeof content === 'object') content = String(content)\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n // no need if it's not sourcemapped\n // don't cache an empty array, though, because ts-node files will show\n // up first as source, and then as their built content.\n const last = content.trimEnd().split('\\n').pop()\n if (cache.has(filename) || !last?.startsWith(sourceMapComment)) return\n const ll = content\n .replace(/[\\n\\u2028\\u2029]$/, '')\n .split(/\\n|\\u2028|\\u2029/)\n .map(l => l.length)\n cache.set(filename, ll)\n\n cache.set(filename, ll)\n}\n\nexport const getLineLengths = (filename: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n return cache.get(filename)\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.mts","sourceRoot":"","sources":["../../src/hooks.mts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAatD,eAAO,MAAM,aAAa,YAAa;IAAE,IAAI,CAAC,EAAE,WAAW,CAAA;CAAE,WAwB5D,CAAA;AAED,eAAO,MAAM,UAAU;UAAsB,WAAW;UAEvD,CAAA;AAsBD,eAAO,MAAM,IAAI,QACV,MAAM,WACF,GAAG,YACF,QAAQ,iBAqBnB,CAAA;AAGD,eAAO,MAAM,KAAK,YAGjB,CAAA"}
1
+ {"version":3,"file":"hooks.d.mts","sourceRoot":"","sources":["../../src/hooks.mts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AActD,eAAO,MAAM,aAAa,YAAa;IAAE,IAAI,CAAC,EAAE,WAAW,CAAA;CAAE,WAwB5D,CAAA;AAED,eAAO,MAAM,UAAU;UAAsB,WAAW;UAEvD,CAAA;AA0BD,eAAO,MAAM,IAAI,QACV,MAAM,WACF,GAAG,YACF,QAAQ,iBAqBnB,CAAA;AAGD,eAAO,MAAM,KAAK,YAGjB,CAAA"}
@@ -1,4 +1,5 @@
1
1
  // hooks used by loader-legacy.mjs and loader.mjs
2
+ import { readFile } from 'node:fs/promises';
2
3
  import { parse } from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
4
5
  import { getExclude } from './get-exclude.js';
@@ -37,7 +38,7 @@ export const initialize = ({ port }) => {
37
38
  PORT = port;
38
39
  };
39
40
  const exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_', false);
40
- const record = (url, content) => {
41
+ const record = async (url, content) => {
41
42
  const filename = url.startsWith('file://') ? fileURLToPath(url) : url;
42
43
  if (exclude.test(filename)) {
43
44
  return;
@@ -45,14 +46,16 @@ const record = (url, content) => {
45
46
  if (fakeMains.includes(filename)) {
46
47
  return;
47
48
  }
49
+ // try to get the actual contents of the file on disk, since it has
50
+ // likely been transpiled by the time we get at it.
51
+ content = await readFile(filename, 'utf8').catch(() => content);
48
52
  if (PORT) {
49
53
  PORT.postMessage({ filename, content });
50
54
  }
51
55
  else {
52
56
  // call lazily so we don't double-register
53
57
  getProcessInfo().files.push(filename);
54
- if (content)
55
- saveLineLengths(filename, content);
58
+ saveLineLengths(filename, content);
56
59
  }
57
60
  };
58
61
  export const load = async (url, context, nextLoad) => {
@@ -64,7 +67,7 @@ export const load = async (url, context, nextLoad) => {
64
67
  // symlink it for them. Don't blow up when this happens, just tell
65
68
  // node that it's commonjs.
66
69
  if (!ext) {
67
- record(url);
70
+ await record(url);
68
71
  return {
69
72
  format: 'commonjs',
70
73
  shortCircuit: true,
@@ -72,7 +75,7 @@ export const load = async (url, context, nextLoad) => {
72
75
  }
73
76
  }
74
77
  const ret = await nextLoad(url, context);
75
- record(url, String(ret.source));
78
+ await record(url, ret.source);
76
79
  return ret;
77
80
  };
78
81
  // just for testing purposes
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.mjs","sourceRoot":"","sources":["../../src/hooks.mts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE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QACL,0CAA0C;QAC1C,cAAc,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACrC,IAAI,OAAO;YAAE,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;KAChD;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EACvB,GAAW,EACX,OAAY,EACZ,QAAkB,EAClB,EAAE;IACF,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC7B,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QACnC,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC/B,+DAA+D;QAC/D,gEAAgE;QAChE,kEAAkE;QAClE,2BAA2B;QAC3B,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,CAAC,GAAG,CAAC,CAAA;YACX,OAAO;gBACL,MAAM,EAAE,UAAU;gBAClB,YAAY,EAAE,IAAI;aACnB,CAAA;SACF;KACF;IAED,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACxC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IAC/B,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,EAAE;IACxB,IAAI,GAAG,SAAS,CAAA;IAChB,cAAc,GAAG,gBAAgB,EAAE,CAAC,cAAc,CAAA;AACpD,CAAC,CAAA","sourcesContent":["// hooks used by loader-legacy.mjs and loader.mjs\n\nimport { parse } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { MessagePort } from 'node:worker_threads'\nimport { getExclude } from './get-exclude.js'\nimport { getImportMetaURL } from './get-import-meta-url.js'\nimport { fakeMains } from './get-main.js'\nimport {\n getProcessInfo as _getProcessInfo,\n reset as processInfoReset,\n} from './get-process-info.js'\nimport { saveLineLengths } from './line-lengths.js'\nlet getProcessInfo = _getProcessInfo\n\nlet PORT: undefined | MessagePort = undefined\n\nexport const globalPreload = (context: { port?: MessagePort }) => {\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 = getImportMetaURL('../cjs/[global preload].js')\n const { port } = context || {}\n PORT = port\n return `\nif (typeof port !== 'undefined') {\n const { createRequire } = getBuiltin('module')\n const { fileURLToPath } = getBuiltin('url')\n const require = createRequire(${JSON.stringify(base)})\n const { getProcessInfo } = require('./get-process-info.js')\n const { saveLineLengths } = require('./line-lengths.js')\n // must be called eagerly here.\n // this does all the registration as well.\n const processInfo = getProcessInfo()\n port.onmessage = (e) => {\n const { filename, content } = e.data\n processInfo.files.push(filename)\n saveLineLengths(filename, content)\n }\n port.unref()\n}\n`\n}\n\nexport const initialize = ({ port }: { port: MessagePort }) => {\n PORT = port\n}\n\nconst exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_', false)\n\nconst record = (url: string, content?: string) => {\n const filename = url.startsWith('file://') ? fileURLToPath(url) : url\n if (exclude.test(filename)) {\n return\n }\n if (fakeMains.includes(filename)) {\n return\n }\n\n if (PORT) {\n PORT.postMessage({ filename, content })\n } else {\n // call lazily so we don't double-register\n getProcessInfo().files.push(filename)\n if (content) saveLineLengths(filename, content)\n }\n}\n\nexport const load = async (\n url: string,\n context: any,\n nextLoad: Function\n) => {\n if (url.startsWith('file://')) {\n const filename = fileURLToPath(url)\n const { ext } = parse(filename)\n // Package bins will sometimes have an extensionless bin script\n // instead of just naming their extensioned file and letting npm\n // symlink it for them. Don't blow up when this happens, just tell\n // node that it's commonjs.\n if (!ext) {\n record(url)\n return {\n format: 'commonjs',\n shortCircuit: true,\n }\n }\n }\n\n const ret = await nextLoad(url, context)\n record(url, String(ret.source))\n return ret\n}\n\n// just for testing purposes\nexport const reset = () => {\n PORT = undefined\n getProcessInfo = processInfoReset().getProcessInfo\n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MAAM,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC7B,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,EAAE;IACxB,IAAI,GAAG,SAAS,CAAA;IAChB,cAAc,GAAG,gBAAgB,EAAE,CAAC,cAAc,CAAA;AACpD,CAAC,CAAA","sourcesContent":["// hooks used by loader-legacy.mjs and loader.mjs\n\nimport { readFile } from 'node:fs/promises'\nimport { parse } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { MessagePort } from 'node:worker_threads'\nimport { getExclude } from './get-exclude.js'\nimport { getImportMetaURL } from './get-import-meta-url.js'\nimport { fakeMains } from './get-main.js'\nimport {\n getProcessInfo as _getProcessInfo,\n reset as processInfoReset,\n} from './get-process-info.js'\nimport { saveLineLengths } from './line-lengths.js'\n\nlet getProcessInfo = _getProcessInfo\n\nlet PORT: undefined | MessagePort = undefined\n\nexport const globalPreload = (context: { port?: MessagePort }) => {\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 = getImportMetaURL('../cjs/[global preload].js')\n const { port } = context || {}\n PORT = port\n return `\nif (typeof port !== 'undefined') {\n const { createRequire } = getBuiltin('module')\n const { fileURLToPath } = getBuiltin('url')\n const require = createRequire(${JSON.stringify(base)})\n const { getProcessInfo } = require('./get-process-info.js')\n const { saveLineLengths } = require('./line-lengths.js')\n // must be called eagerly here.\n // this does all the registration as well.\n const processInfo = getProcessInfo()\n port.onmessage = (e) => {\n const { filename, content } = e.data\n processInfo.files.push(filename)\n saveLineLengths(filename, content)\n }\n port.unref()\n}\n`\n}\n\nexport const initialize = ({ port }: { port: MessagePort }) => {\n PORT = port\n}\n\nconst exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_', false)\n\nconst record = async (url: string, content?: string) => {\n const filename = url.startsWith('file://') ? fileURLToPath(url) : url\n if (exclude.test(filename)) {\n return\n }\n if (fakeMains.includes(filename)) {\n return\n }\n\n // try to get the actual contents of the file on disk, since it has\n // likely been transpiled by the time we get at it.\n content = await readFile(filename, 'utf8').catch(() => content)\n\n if (PORT) {\n PORT.postMessage({ filename, content })\n } else {\n // call lazily so we don't double-register\n getProcessInfo().files.push(filename)\n saveLineLengths(filename, content)\n }\n}\n\nexport const load = async (\n url: string,\n context: any,\n nextLoad: Function\n) => {\n if (url.startsWith('file://')) {\n const filename = fileURLToPath(url)\n const { ext } = parse(filename)\n // Package bins will sometimes have an extensionless bin script\n // instead of just naming their extensioned file and letting npm\n // symlink it for them. Don't blow up when this happens, just tell\n // node that it's commonjs.\n if (!ext) {\n await record(url)\n return {\n format: 'commonjs',\n shortCircuit: true,\n }\n }\n }\n\n const ret = await nextLoad(url, context)\n await record(url, ret.source)\n return ret\n}\n\n// just for testing purposes\nexport const reset = () => {\n PORT = undefined\n getProcessInfo = processInfoReset().getProcessInfo\n}\n"]}
@@ -1,3 +1,4 @@
1
- export declare const saveLineLengths: (filename: string, content: string) => void;
1
+ /// <reference types="node" />
2
+ export declare const saveLineLengths: (filename: string, content?: string | Buffer) => void;
2
3
  export declare const getLineLengths: (filename: string) => number[] | undefined;
3
4
  //# sourceMappingURL=line-lengths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"line-lengths.d.ts","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,eAAe,aAAc,MAAM,WAAW,MAAM,SAchE,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
1
+ {"version":3,"file":"line-lengths.d.ts","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAYA,eAAO,MAAM,eAAe,aAAc,MAAM,YAAY,MAAM,GAAG,MAAM,SAgB1E,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
@@ -6,6 +6,10 @@ const cache = g[kLLC] || new Map();
6
6
  g[kLLC] = cache;
7
7
  const sourceMapComment = '//# sourceMappingURL=';
8
8
  export const saveLineLengths = (filename, content) => {
9
+ if (content === undefined)
10
+ return;
11
+ if (typeof content === 'object')
12
+ content = String(content);
9
13
  if (filename.startsWith('file://'))
10
14
  filename = fileURLToPath(filename);
11
15
  // no need if it's not sourcemapped
@@ -1 +1 @@
1
- {"version":3,"file":"line-lengths.js","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;AAC9D,MAAM,CAAC,GAAG,MAET,CAAA;AACD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAoB,CAAA;AACpD,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;AAEf,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAChD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,OAAe,EAAE,EAAE;IACnE,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACtE,mCAAmC;IACnC,sEAAsE;IACtE,uDAAuD;IACvD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;IAChD,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAM;IACtE,MAAM,EAAE,GAAG,OAAO;SACf,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,KAAK,CAAC,kBAAkB,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IACrB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAEvB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AACzB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,EAAE;IACjD,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACtE,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC5B,CAAC,CAAA","sourcesContent":["// TODO: Refactor once https://github.com/nodejs/node/issues/48460 fixed\n\nimport { fileURLToPath } from 'url'\n\nconst kLLC = Symbol.for('@tapjs/processinfo lineLength cache')\nconst g = global as {\n [kLLC]?: Map<string, number[]>\n}\nconst cache = g[kLLC] || new Map<string, number[]>()\ng[kLLC] = cache\n\nconst sourceMapComment = '//# sourceMappingURL='\nexport const saveLineLengths = (filename: string, content: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n // no need if it's not sourcemapped\n // don't cache an empty array, though, because ts-node files will show\n // up first as source, and then as their built content.\n const last = content.trimEnd().split('\\n').pop()\n if (cache.has(filename) || !last?.startsWith(sourceMapComment)) return\n const ll = content\n .replace(/[\\n\\u2028\\u2029]$/, '')\n .split(/\\n|\\u2028|\\u2029/)\n .map(l => l.length)\n cache.set(filename, ll)\n\n cache.set(filename, ll)\n}\n\nexport const getLineLengths = (filename: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n return cache.get(filename)\n}\n"]}
1
+ {"version":3,"file":"line-lengths.js","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;AAC9D,M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AAA;IACtE,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC5B,CAAC,CAAA","sourcesContent":["// TODO: Refactor once https://github.com/nodejs/node/issues/48460 fixed\n\nimport { fileURLToPath } from 'url'\n\nconst kLLC = Symbol.for('@tapjs/processinfo lineLength cache')\nconst g = global as {\n [kLLC]?: Map<string, number[]>\n}\nconst cache = g[kLLC] || new Map<string, number[]>()\ng[kLLC] = cache\n\nconst sourceMapComment = '//# sourceMappingURL='\nexport const saveLineLengths = (filename: string, content?: string | Buffer) => {\n if (content === undefined) return\n if (typeof content === 'object') content = String(content)\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n // no need if it's not sourcemapped\n // don't cache an empty array, though, because ts-node files will show\n // up first as source, and then as their built content.\n const last = content.trimEnd().split('\\n').pop()\n if (cache.has(filename) || !last?.startsWith(sourceMapComment)) return\n const ll = content\n .replace(/[\\n\\u2028\\u2029]$/, '')\n .split(/\\n|\\u2028|\\u2029/)\n .map(l => l.length)\n cache.set(filename, ll)\n\n cache.set(filename, ll)\n}\n\nexport const getLineLengths = (filename: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n return cache.get(filename)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapjs/processinfo",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "files": [
5
5
  "dist"
6
6
  ],