@jsenv/test 1.6.4 → 1.6.6

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.
@@ -10,7 +10,7 @@
10
10
  * - File execution result is returned, it contains status/errors/namespace/consoleCalls
11
11
  */
12
12
 
13
- import { createId } from "@paralleldrive/cuid2";
13
+ import crypto from "node:crypto";
14
14
  import { Abort, raceCallbacks } from "@jsenv/abort";
15
15
  import { ensureParentDirectories } from "@jsenv/filesystem";
16
16
 
@@ -73,7 +73,7 @@ export const run = async ({
73
73
  let coverageFileUrl;
74
74
  if (coverageEnabled) {
75
75
  coverageFileUrl = new URL(
76
- `./${runtime.name}/${createId()}.json`,
76
+ `./${runtime.name}/${crypto.randomUUID()}.json`,
77
77
  coverageTempDirectoryUrl,
78
78
  ).href;
79
79
  await ensureParentDirectories(coverageFileUrl);
@@ -0,0 +1,51 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { pathToFileURL } from "node:url";
3
+ import { normalizeImportMap, resolveImport } from "@jsenv/importmap";
4
+
5
+ let importMap;
6
+
7
+ const cwdUrl = `${String(pathToFileURL(process.cwd()))}/`;
8
+
9
+ if (process.env.IMPORT_MAP) {
10
+ importMap = JSON.parse(process.env.IMPORT_MAP);
11
+ } else if (process.env.IMPORT_MAP_PATH) {
12
+ const importmapFileUrl = pathToFileURL(process.env.IMPORT_MAP_PATH);
13
+ const importmapFileContentAsString = readFileSync(importmapFileUrl, "utf8");
14
+ importMap = JSON.parse(importmapFileContentAsString);
15
+ } else {
16
+ const importmapFileUrl = new URL("./import_map.json", cwdUrl);
17
+ const importmapFileContentAsString = readFileSync(importmapFileUrl, "utf8");
18
+ importMap = JSON.parse(importmapFileContentAsString);
19
+ }
20
+
21
+ const importMapBaseUrl = process.env.IMPORT_MAP_BASE_URL || cwdUrl;
22
+ importMap = normalizeImportMap(importMap, importMapBaseUrl);
23
+
24
+ export const resolve = (specifier, context, nextResolve) => {
25
+ try {
26
+ let mapped;
27
+ const importer = context.parentURL ? String(context.parentURL) : undefined;
28
+ const resolved = resolveImport({
29
+ specifier,
30
+ importer,
31
+ importMap,
32
+ defaultExtension: ".js",
33
+ onImportMapping: () => {
34
+ mapped = true;
35
+ },
36
+ });
37
+ if (mapped) {
38
+ return {
39
+ shortCircuit: true,
40
+ url: resolved,
41
+ };
42
+ }
43
+ } catch (e) {
44
+ if (e.message.includes("bare specifier")) {
45
+ return nextResolve(specifier, context);
46
+ }
47
+ console.error(e);
48
+ return nextResolve(specifier, context);
49
+ }
50
+ return nextResolve(specifier, context);
51
+ };
@@ -1,51 +1,3 @@
1
- import { readFileSync } from "node:fs";
2
- import { pathToFileURL } from "node:url";
3
- import { normalizeImportMap, resolveImport } from "@jsenv/importmap";
1
+ import { register } from "node:module";
4
2
 
5
- let importMap;
6
-
7
- const cwdUrl = `${String(pathToFileURL(process.cwd()))}/`;
8
-
9
- if (process.env.IMPORT_MAP) {
10
- importMap = JSON.parse(process.env.IMPORT_MAP);
11
- } else if (process.env.IMPORT_MAP_PATH) {
12
- const importmapFileUrl = pathToFileURL(process.env.IMPORT_MAP_PATH);
13
- const importmapFileContentAsString = readFileSync(importmapFileUrl, "utf8");
14
- importMap = JSON.parse(importmapFileContentAsString);
15
- } else {
16
- const importmapFileUrl = new URL("./import_map.json", cwdUrl);
17
- const importmapFileContentAsString = readFileSync(importmapFileUrl, "utf8");
18
- importMap = JSON.parse(importmapFileContentAsString);
19
- }
20
-
21
- const importMapBaseUrl = process.env.IMPORT_MAP_BASE_URL || cwdUrl;
22
- importMap = normalizeImportMap(importMap, importMapBaseUrl);
23
-
24
- export const resolve = (specifier, context, nextResolve) => {
25
- try {
26
- let mapped;
27
- const importer = context.parentURL ? String(context.parentURL) : undefined;
28
- const resolved = resolveImport({
29
- specifier,
30
- importer,
31
- importMap,
32
- defaultExtension: ".js",
33
- onImportMapping: () => {
34
- mapped = true;
35
- },
36
- });
37
- if (mapped) {
38
- return {
39
- shortCircuit: true,
40
- url: resolved,
41
- };
42
- }
43
- } catch (e) {
44
- if (e.message.includes("bare specifier")) {
45
- return nextResolve(specifier, context);
46
- }
47
- console.error(e);
48
- return nextResolve(specifier, context);
49
- }
50
- return nextResolve(specifier, context);
51
- };
3
+ register(new URL("./importmap_hooks.mjs", import.meta.url));
@@ -65,9 +65,7 @@ export const nodeWorkerThread = ({
65
65
  if (importMap) {
66
66
  env.IMPORT_MAP = JSON.stringify(importMap);
67
67
  env.IMPORT_MAP_BASE_URL = rootDirectoryUrl;
68
- commandLineOptions.push(
69
- `--experimental-loader=${IMPORTMAP_NODE_LOADER_FILE_URL}`,
70
- );
68
+ commandLineOptions.push(`--import=${IMPORTMAP_NODE_LOADER_FILE_URL}`);
71
69
  commandLineOptions.push(
72
70
  `--require=${fileURLToPath(NO_EXPERIMENTAL_WARNING_FILE_URL)}`,
73
71
  );