@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 +3 -1
- package/lib/get-file-type.mjs +4 -2
- package/lib/hooks.mjs +5 -2
- package/lib/loader-agent.mjs +2 -0
- package/lib/redirects/builtin/util.mjs +1 -0
- package/package.json +7 -7
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 = `${
|
|
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
|
package/lib/get-file-type.mjs
CHANGED
|
@@ -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 =
|
|
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 } =
|
|
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
|
-
|
|
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
|
-
|
|
156
|
+
Buffer.isBuffer(source) ? BufferPrototypeToString.call(source) : source.toString(),
|
|
154
157
|
rewriteOptions
|
|
155
158
|
);
|
|
156
159
|
|
package/lib/loader-agent.mjs
CHANGED
|
@@ -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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/esm-hooks",
|
|
3
|
-
"version": "2.
|
|
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.
|
|
23
|
-
"@contrast/config": "1.
|
|
24
|
-
"@contrast/core": "1.
|
|
25
|
-
"@contrast/find-package-json": "^1.
|
|
26
|
-
"@contrast/logger": "1.
|
|
27
|
-
"@contrast/rewriter": "1.
|
|
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
|
}
|