@contrast/esm-hooks 2.19.2 → 2.19.4

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/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@contrast/esm-hooks",
3
- "version": "2.19.2",
3
+ "version": "2.19.4",
4
4
  "type": "module",
5
5
  "description": "Support for loading and instrumenting ECMAScript modules",
6
6
  "license": "SEE LICENSE IN LICENSE",
7
7
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
8
8
  "files": [
9
9
  "lib/",
10
- "!lib/redirects/esm/node-fetch.mjs-tester"
10
+ "!lib/redirects/esm/node-fetch.mjs-tester",
11
+ "!*.test.*",
12
+ "!tsconfig.*",
13
+ "!*.map"
11
14
  ],
12
15
  "main": "lib/index.mjs",
13
16
  "types": "lib/index.d.ts",
@@ -20,10 +23,10 @@
20
23
  },
21
24
  "dependencies": {
22
25
  "@contrast/common": "1.29.1",
23
- "@contrast/config": "1.40.1",
24
- "@contrast/core": "1.45.1",
26
+ "@contrast/config": "1.40.2",
27
+ "@contrast/core": "1.45.2",
25
28
  "@contrast/find-package-json": "^1.1.0",
26
- "@contrast/logger": "1.18.1",
27
- "@contrast/rewriter": "1.21.2"
29
+ "@contrast/logger": "1.18.2",
30
+ "@contrast/rewriter": "1.21.4"
28
31
  }
29
32
  }
@@ -1,28 +0,0 @@
1
- // @ts-check
2
- import M from 'node:module';
3
- import { expect } from 'chai';
4
- import { mappings } from './common.mjs';
5
-
6
- describe('esm-hooks common', function () {
7
- describe('mappings cover all builtin modules\' exports', function() {
8
- for (const [name, url] of Object.entries(mappings)) {
9
- it(`${name} mappings are complete`, async function() {
10
- // older versions of node don't have all the builtin modules
11
- const bareName = name.replace('node:', '');
12
- if (!M.builtinModules.includes(bareName)) {
13
- this.skip();
14
- return;
15
- }
16
-
17
- const redirectedImports = await import(url);
18
- const nativeImports = await import(name);
19
-
20
- const redirectedKeys = new Set(Object.keys(redirectedImports));
21
- const nativeKeys = new Set(Object.keys(nativeImports));
22
-
23
- const missing = new Set([...nativeKeys].filter(x => !redirectedKeys.has(x)));
24
- expect(missing.size).equal(0, `missing keys: [${[...missing].join(', ')}]`);
25
- });
26
- }
27
- });
28
- });
@@ -1,83 +0,0 @@
1
- import { expect } from 'chai';
2
- import * as sinon from 'sinon';
3
- import component from './debug-methods.mjs';
4
-
5
- function mockCore () {
6
- return { esmHooks: {} };
7
- }
8
-
9
- describe('esm-hooks debug-methods', function() {
10
- it('doesn\'t append debug methods to core.esmHooks if mask is 0', function() {
11
- const core = mockCore();
12
- component(core, { mask: 0, install: false });
13
- expect(core.esmHooks).to.be.empty.and.an('object');
14
- });
15
-
16
- [
17
- {
18
- mask: 1,
19
- expected: [
20
- /CJS\(\d\) _load\(\) request/,
21
- /ESM\(\d\) initialize\(\) specifier/,
22
- /ESM\(\d\) load\(\) url/,
23
- ]
24
- },
25
- {
26
- mask: 3,
27
- expected: [
28
- /CJS\(\d\) _load\(\) request/,
29
- /ESM\(\d\) initialize\(\) specifier/,
30
- /ESM\(\d\) resolve\(\) specifier/,
31
- /ESM\(\d\) load\(\) url/,
32
- ]
33
- },
34
- {
35
- mask: 7,
36
- expected: [
37
- /CJS\(\d\) _compile\(\) filename/,
38
- /CJS\(\d\) extensions\.js\(\) filename/,
39
- /CJS\(\d\) _load\(\) request/,
40
- /CJS\(\d\) require\(\) moduleId/,
41
- /ESM\(\d\) initialize\(\) specifier/,
42
- /ESM\(\d\) resolve\(\) specifier/,
43
- /ESM\(\d\) load\(\) url/,
44
- ],
45
- },
46
- ].forEach(({
47
- mask,
48
- expected
49
- }) => {
50
- describe(`mask = ${mask}`, function() {
51
- let core;
52
-
53
- function callMethods() {
54
- core.esmHooks.debugCjsCompile('filename');
55
- core.esmHooks.debugCjsExtensions('filename');
56
- core.esmHooks.debugCjsLoad('request');
57
- core.esmHooks.debugCjsRequire('moduleId');
58
- core.esmHooks.debugEsmInitialize('specifier');
59
- core.esmHooks.debugEsmResolve('specifier');
60
- core.esmHooks.debugEsmLoad('url');
61
- }
62
-
63
- before(async function() {
64
- core = { esmHooks: {} };
65
- component(core, { mask, install: false });
66
- sinon.stub(core.esmHooks, '_rawDebug');
67
- });
68
-
69
- after(function() {
70
- sinon.restore();
71
- });
72
-
73
- it('logs appropriate messages based on mask value', function() {
74
- callMethods();
75
-
76
- expect(core.esmHooks._rawDebug).to.have.callCount(expected.length);
77
- for (const rx of expected) {
78
- expect(core.esmHooks._rawDebug).to.have.been.calledWithMatch(sinon.match(rx));
79
- }
80
- });
81
- });
82
- });
83
- });
@@ -1,68 +0,0 @@
1
- // @ts-check
2
- import { expect } from 'chai';
3
- import path from 'path';
4
- import { getFileType } from './get-file-type.mjs';
5
- import { fileURLToPath, pathToFileURL } from 'url';
6
-
7
- describe('esm-hooks get-file-type', function () {
8
- it('handles URLs', async function () {
9
- const filename = pathToFileURL('/path/to/filename.js');
10
- expect(await getFileType(filename)).to.equal('commonjs');
11
- });
12
-
13
- it('handles file URL strings', async function () {
14
- const filename = pathToFileURL('/path/to/filename.js').href;
15
- expect(await getFileType(filename)).to.equal('commonjs');
16
- });
17
-
18
- it('returns builtin for node builtins', async function () {
19
- expect(await getFileType('node:child_process')).to.equal('builtin');
20
- });
21
-
22
- it('returns null when it cannot determine what the file is', async function() {
23
- expect(await getFileType('node:xyzzy')).to.equal(null);
24
- });
25
-
26
- it('returns null when the filename is not valid', async function() {
27
- expect(await getFileType('')).to.equal(null);
28
- });
29
-
30
- it('returns module when filename extension is .mjs', async function () {
31
- expect(await getFileType('filename.mjs')).to.equal('module');
32
- });
33
-
34
- it('returns module when filename extension is .js and parent type = module', async function () {
35
- const pathToEsmApp = path.resolve(
36
- fileURLToPath(import.meta.url),
37
- '../../../test/esm-app/index.js',
38
- );
39
-
40
- expect(await getFileType(pathToEsmApp)).to.equal('module');
41
- });
42
-
43
- it('stops searching when it reaches a provided stopAt', async function () {
44
- const pathToEsmApp = path.resolve(
45
- fileURLToPath(import.meta.url),
46
- '../../../test/esm-app/index.js',
47
- );
48
-
49
- expect(await getFileType(pathToEsmApp, path.dirname(pathToEsmApp))).to.equal('commonjs');
50
- });
51
-
52
- it('returns commonjs when filename extension is .cjs', async function () {
53
- expect(await getFileType('filename.cjs')).to.equal('commonjs');
54
- });
55
-
56
- it('returns commonjs when filename extension is .js and parent type != module', async function () {
57
- const pathToApp = path.resolve(
58
- fileURLToPath(import.meta.url),
59
- '../../../test/app/lib/index.js',
60
- );
61
-
62
- expect(await getFileType(pathToApp)).to.equal('commonjs');
63
- });
64
-
65
- it('returns null if unable to parse filename', async function () {
66
- expect(await getFileType('filename.json')).to.equal(null);
67
- });
68
- });