import-in-the-middle 1.3.3 → 1.3.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/hook.mjs CHANGED
@@ -90,6 +90,11 @@ export async function resolve (specifier, context, parentResolve) {
90
90
  return url
91
91
  }
92
92
 
93
+ if (context.importAssertions && context.importAssertions.type === 'json') {
94
+ return url
95
+ }
96
+
97
+
93
98
  specifiers.set(url.url, specifier)
94
99
 
95
100
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,9 @@
1
+ // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
2
+ //
3
+ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
4
+
5
+ import coolFile from './something.json' assert { type: 'json' };
6
+
7
+ export default {
8
+ data: coolFile.data
9
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "data": "dog"
3
+ }
@@ -0,0 +1,15 @@
1
+ // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
2
+ //
3
+ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
4
+
5
+ import Hook from '../../index.js'
6
+ import jsonMjs from '../fixtures/json.mjs'
7
+ import { strictEqual } from 'assert'
8
+
9
+ Hook((exports, name) => {
10
+ if (name.match(/json\.mjs/)) {
11
+ exports.default.data += '-dawg'
12
+ }
13
+ })
14
+
15
+ strictEqual(jsonMjs.data, 'dog-dawg')
package/test/runtest CHANGED
@@ -15,6 +15,18 @@ const args = [
15
15
  '--unhandled-rejections=strict',
16
16
  ...process.argv.slice(2)
17
17
  ]
18
+
19
+ const [processMajor] = process.versions.node.split('.').map(Number)
20
+
21
+ const match = filename.match(/v([0-9]+)/)
22
+
23
+ const versionRequirement = match ? match[1] : 0;
24
+
25
+ if (processMajor < versionRequirement) {
26
+ console.log(`skipping ${filename} as this is Node.js v${processMajor} and test wants v${versionRequirement}`);
27
+ process.exit(0);
28
+ }
29
+
18
30
  if (!filename.includes('disabled')) {
19
31
  const isTypescript = path.extname(filename).slice(-2) === 'ts'
20
32
  const loaderPath = isTypescript