@contrast/esm-hooks 2.10.0 → 2.12.0

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/lib/common.mjs CHANGED
@@ -16,7 +16,9 @@
16
16
  import { readdir } from 'node:fs/promises';
17
17
  import path from 'node:path';
18
18
  import { fileURLToPath, pathToFileURL } from 'node:url';
19
+ import { primordials } from '@contrast/common';
19
20
 
21
+ const { ArrayPrototypeJoin } = primordials;
20
22
  const REDIRECTS_PATH = './redirects';
21
23
 
22
24
  export const mappings = await makeMappings();
@@ -84,7 +86,7 @@ export async function makeMappings() {
84
86
  // that's why the mapping below adds the `node:` prefix.
85
87
  let name = path.basename(dirent.name, '.mjs');
86
88
  if (pathStack.length) {
87
- name = `${pathStack.join('/')}/${name}`;
89
+ name = `${ArrayPrototypeJoin.call(pathStack, '/')}/${name}`;
88
90
  }
89
91
 
90
92
  // set flag to module or commonjs. i'm not sure this is needed but am keeping it
@@ -17,10 +17,12 @@ import path from 'node:path';
17
17
  import M from 'node:module';
18
18
  import { fileURLToPath } from 'node:url';
19
19
  import { findPackageJson } from '@contrast/find-package-json';
20
+ import { primordials } from '@contrast/common';
21
+ const { StringPrototypeSlice, JSONParse } = primordials;
20
22
 
21
23
  const isBuiltin = M.isBuiltin || function(pathname) {
22
24
  if (pathname.startsWith('node:')) {
23
- pathname = pathname.slice(5);
25
+ pathname = StringPrototypeSlice.call(pathname, 5);
24
26
  }
25
27
  return M.builtinModules.includes(pathname);
26
28
  };
@@ -57,7 +59,7 @@ export async function getFileType(filename, stopAt) {
57
59
  const pkg = await findPackageJson({ cwd: filename, stopAt });
58
60
  if (pkg) {
59
61
  const json = await readFile(pkg, 'utf8');
60
- const { type } = JSON.parse(json);
62
+ const { type } = JSONParse(json);
61
63
  if (type) {
62
64
  parentType = type;
63
65
  }
package/lib/hooks.mjs CHANGED
@@ -18,7 +18,10 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
18
18
  import { mappings } from './common.mjs';
19
19
  import { getFileType } from './get-file-type.mjs';
20
20
  import { default as initLoaderAgent } from './loader-agent.mjs';
21
- const [major, minor] = process.versions.node.split('.').map(it => +it);
21
+ import { primordials } from '@contrast/common';
22
+ const { StringPrototypeSplit, BufferPrototypeToString } = primordials;
23
+
24
+ const [major, minor] = StringPrototypeSplit.call(process.versions.node, '.').map(it => +it);
22
25
  const isLT16_12 = major < 16 || (major === 16 && minor < 12);
23
26
 
24
27
  /**
@@ -150,7 +153,7 @@ async function load(url, context, nextLoad) {
150
153
 
151
154
  const { source } = await nextLoad(url, context);
152
155
  const rewriteResult = await loaderAgent.rewriter.rewrite(
153
- source.toString(), // might be a Buffer
156
+ Buffer.isBuffer(source) ? BufferPrototypeToString.call(source) : source.toString(),
154
157
  rewriteOptions
155
158
  );
156
159
 
@@ -48,6 +48,7 @@ const ERROR_MESSAGE = 'An error prevented the Contrast agent from initializing i
48
48
  export default function init({ appInfo, agentVersion, port, modes }) {
49
49
  /** @type {LoaderAgent} */
50
50
  const core = {
51
+ Perf: require('@contrast/perf'),
51
52
  appInfo,
52
53
  agentVersion,
53
54
  // this will toggle functionality in hooks.mjs e.g. redirects/rewriting
@@ -72,6 +73,7 @@ export default function init({ appInfo, agentVersion, port, modes }) {
72
73
  };
73
74
 
74
75
  try {
76
+ core.Perf = require('@contrast/perf');
75
77
  require('@contrast/core/lib/messages')(core);
76
78
  require('@contrast/config')(core);
77
79
  require('@contrast/logger').default(core);
@@ -28,6 +28,7 @@ export const {
28
28
  deprecate,
29
29
  format,
30
30
  formatWithOptions,
31
+ getCallSite,
31
32
  getSystemErrorMap,
32
33
  getSystemErrorName,
33
34
  inherits,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/esm-hooks",
3
- "version": "2.10.0",
3
+ "version": "2.12.0",
4
4
  "type": "module",
5
5
  "description": "Support for loading and instrumenting ECMAScript modules",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -19,11 +19,11 @@
19
19
  "test": "../scripts/test.sh"
20
20
  },
21
21
  "dependencies": {
22
- "@contrast/common": "1.25.0",
23
- "@contrast/config": "1.32.0",
24
- "@contrast/core": "1.36.0",
25
- "@contrast/find-package-json": "^1.0.0",
26
- "@contrast/logger": "1.9.0",
27
- "@contrast/rewriter": "1.12.0"
22
+ "@contrast/common": "1.26.0",
23
+ "@contrast/config": "1.34.0",
24
+ "@contrast/core": "1.38.0",
25
+ "@contrast/find-package-json": "^1.1.0",
26
+ "@contrast/logger": "1.11.0",
27
+ "@contrast/rewriter": "1.14.0"
28
28
  }
29
29
  }