@native-typescript/loader-of-typescript-for-node-js 4.0.0 → 5.0.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.
Files changed (49) hide show
  1. package/README.md +14 -7
  2. package/index.js +1 -0
  3. package/module.js +1 -0
  4. package/package.json +29 -18
  5. package/source/{entrypoint-of-source.js → entrypoint.js} +1 -1
  6. package/source/{options → features}/index.js +1 -0
  7. package/source/features/loading/TypeScript/base/module.js +1 -0
  8. package/source/{options → features}/loading/TypeScript/commonjs/loadCommonjsTypescript.js +2 -2
  9. package/source/features/loading/TypeScript/commonjs/module.js +1 -0
  10. package/source/features/loading/TypeScript/index.js +2 -0
  11. package/source/{options → features}/loading/TypeScript/module/loadModuleTypescript.js +2 -2
  12. package/source/features/loading/TypeScript/module/module.js +1 -0
  13. package/source/features/loading/TypeScript/module.js +1 -0
  14. package/source/features/loading/index.js +4 -0
  15. package/source/{options → features}/loading/load.js +13 -4
  16. package/source/features/loading/module.js +1 -0
  17. package/source/{options → features}/loading/with-known-format/loadWithKnownFormat.js +11 -6
  18. package/source/features/loading/with-known-format/module.js +1 -0
  19. package/source/features/loading/with-unknown-format/extracting-extension-from-url/module.js +1 -0
  20. package/source/{options → features}/loading/with-unknown-format/loadWithUnknownFormat.js +10 -4
  21. package/source/features/loading/with-unknown-format/module.js +1 -0
  22. package/source/{options → features}/loading/with-unknown-format/with-extension/loadWithExtension.js +17 -8
  23. package/source/features/loading/with-unknown-format/with-extension/module.js +1 -0
  24. package/source/{options → features}/loading/with-unknown-format/with-extension/unknown-TypeScript/determining-type-of-module/determineTypeOfModule.js +3 -2
  25. package/source/features/loading/with-unknown-format/with-extension/unknown-TypeScript/determining-type-of-module/module.js +1 -0
  26. package/source/features/loading/with-unknown-format/with-extension/unknown-TypeScript/determining-type-of-module/using-readFileSync-safely/module.js +1 -0
  27. package/source/{options → features}/loading/with-unknown-format/with-extension/unknown-TypeScript/determining-type-of-module/using-readFileSync-safely/useReadFileSyncSafely.js +2 -1
  28. package/source/{options → features}/loading/with-unknown-format/with-extension/unknown-TypeScript/loadUnknownTypescript.js +13 -8
  29. package/source/features/loading/with-unknown-format/with-extension/unknown-TypeScript/module.js +1 -0
  30. package/source/features/module.js +1 -0
  31. package/source/{options → features}/optionsOfLoadingTypescriptHook.js +2 -2
  32. package/source/index.js +1 -0
  33. package/source/module.js +1 -0
  34. package/source/utilities/index.js +0 -0
  35. package/source/utilities/module.js +1 -0
  36. package/source/options/loading/TypeScript/index.js +0 -2
  37. package/source/options/loading/index.js +0 -1
  38. /package/source/{options → features}/loading/TypeScript/base/index.js +0 -0
  39. /package/source/{options → features}/loading/TypeScript/base/loadTypescript.js +0 -0
  40. /package/source/{options → features}/loading/TypeScript/commonjs/index.js +0 -0
  41. /package/source/{options → features}/loading/TypeScript/module/index.js +0 -0
  42. /package/source/{options → features}/loading/with-known-format/index.js +0 -0
  43. /package/source/{options → features}/loading/with-unknown-format/extracting-extension-from-url/extractExtensionFromUrl.js +0 -0
  44. /package/source/{options → features}/loading/with-unknown-format/extracting-extension-from-url/index.js +0 -0
  45. /package/source/{options → features}/loading/with-unknown-format/index.js +0 -0
  46. /package/source/{options → features}/loading/with-unknown-format/with-extension/index.js +0 -0
  47. /package/source/{options → features}/loading/with-unknown-format/with-extension/unknown-TypeScript/determining-type-of-module/index.js +0 -0
  48. /package/source/{options → features}/loading/with-unknown-format/with-extension/unknown-TypeScript/determining-type-of-module/using-readFileSync-safely/index.js +0 -0
  49. /package/source/{options → features}/loading/with-unknown-format/with-extension/unknown-TypeScript/index.js +0 -0
package/README.md CHANGED
@@ -25,13 +25,13 @@ For plain `.ts` files, the loader walks up directories from the file location:
25
25
 
26
26
  ## Requirements
27
27
 
28
- - Node.js `>=24.14.0`
29
- - npm `>=11.9.0`
28
+ - Node.js `>=26.9.0`
29
+ - npm `>=11.19.1`
30
30
 
31
31
  ## Installation
32
32
 
33
33
  ```bash
34
- npm install loader-of-typescript-for-node-js
34
+ npm install @native-typescript/loader-of-typescript-for-node-js
35
35
  ```
36
36
 
37
37
  ## Usage
@@ -39,22 +39,29 @@ npm install loader-of-typescript-for-node-js
39
39
  ### 1. Register through Node's import flag (recommended)
40
40
 
41
41
  ```bash
42
- node --import loader-of-typescript-for-node-js ./path/to/file.ts
42
+ node --import @native-typescript/loader-of-typescript-for-node-js/entrypoint ./path/to/file.ts
43
43
  ```
44
44
 
45
45
  You can also keep it enabled globally for a session:
46
46
 
47
47
  ```bash
48
- export NODE_OPTIONS="--import=loader-of-typescript-for-node-js"
48
+ export NODE_OPTIONS="--import=@native-typescript/loader-of-typescript-for-node-js/entrypoint"
49
49
  node ./path/to/file.ts
50
50
  ```
51
51
 
52
52
  ### 2. Register programmatically
53
53
 
54
- Importing the package runs its side-effect entrypoint and registers the hook:
54
+ Importing the `/entrypoint` subpath runs its side effect and registers the hook:
55
55
 
56
56
  ```ts
57
- import "loader-of-typescript-for-node-js";
57
+ import "@native-typescript/loader-of-typescript-for-node-js/entrypoint";
58
+ ```
59
+
60
+ The default export is the pure library (the loading hook and its options) and does
61
+ not register anything on import:
62
+
63
+ ```ts
64
+ import {loaderOfTypescriptForNodeJs_} from "@native-typescript/loader-of-typescript-for-node-js";
58
65
  ```
59
66
 
60
67
  ## Notes and limitations
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./source/module.js";
package/module.js ADDED
@@ -0,0 +1 @@
1
+ export * as loaderOfTypescriptForNodeJs_ from "./index.js";
package/package.json CHANGED
@@ -9,30 +9,40 @@
9
9
  },
10
10
  "description": "A loader of TypeScript for Node.js.",
11
11
  "devDependencies": {
12
- "@commitlint/cli": "20.5.0",
13
- "@commitlint/types": "20.5.0",
14
- "@release-it/conventional-changelog": "11.0.0",
12
+ "@commitlint/cli": "21.2.3",
13
+ "@commitlint/types": "21.2.3",
14
+ "@native-typescript/stringifying-arktype-errors": "4.0.0",
15
+ "@release-it/conventional-changelog": "12.0.2",
15
16
  "@stylistic/eslint-plugin": "5.10.0",
16
- "@types/node": "25.5.0",
17
- "@typescript-eslint/parser": "8.60.0",
18
- "eslint": "10.2.0",
17
+ "@types/node": "25.9.1",
18
+ "@typescript-eslint/eslint-plugin": "8.72.2",
19
+ "@typescript-eslint/parser": "8.72.2",
20
+ "arktype": "2.2.9",
21
+ "eslint": "10.4.0",
19
22
  "eslint-plugin-import-x": "4.16.2",
20
- "eslint-plugin-perfectionist": "5.8.0",
23
+ "eslint-plugin-perfectionist": "5.9.0",
21
24
  "eslint-plugin-unused-imports": "4.4.1",
22
- "expect": "30.3.0",
23
- "jiti": "2.6.1",
24
- "prettier": "3.8.3",
25
- "release-it": "20.0.1",
25
+ "expect": "30.5.1",
26
+ "jiti": "2.7.0",
27
+ "prettier": "3.9.6",
28
+ "release-it": "21.1.0",
29
+ "testcontainers": "12.0.0",
26
30
  "typescript": "6.0.3",
27
- "typescript-eslint": "8.60.0"
31
+ "typescript-eslint": "8.72.2"
28
32
  },
29
33
  "engines": {
30
- "node": ">=24.14.0",
31
- "npm": ">=11.9.0"
34
+ "node": ">=26.9.0",
35
+ "npm": ">=11.19.1"
36
+ },
37
+ "exports": {
38
+ ".": "./module.js",
39
+ "./entrypoint": "./source/entrypoint.js"
32
40
  },
33
- "exports": "./source/entrypoint-of-source.js",
34
41
  "homepage": "https://github.com/native-typescript/loader-of-typescript-for-node-js#readme",
35
42
  "name": "@native-typescript/loader-of-typescript-for-node-js",
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
36
46
  "repository": {
37
47
  "type": "git",
38
48
  "url": "git+https://github.com/native-typescript/loader-of-typescript-for-node-js.git"
@@ -45,10 +55,11 @@
45
55
  "prettier:check": "node --env-file-if-exists='./.env' ./node_modules/.bin/prettier --check .",
46
56
  "prettier:fix": "node --env-file-if-exists='./.env' ./node_modules/.bin/prettier --write .",
47
57
  "release-it": "node --env-file-if-exists='./.env' ./node_modules/.bin/release-it --config='./release-it.config.ts'",
48
- "test:check": "node --env-file-if-exists='./.env' --experimental-test-coverage --test --test-concurrency=1 --test-coverage-exclude='**/*.test.*' --test-coverage-exclude='node_modules/**/*' --test-coverage-exclude='testing/**/*' --test-coverage-include='source/**/*' --test-global-setup='./testing/entrypoint-of-testing.ts' '**/*.test.ts'",
49
- "test:check:unit": "node --env-file-if-exists='./.env' --test --test-global-setup='./testing/entrypoint-of-testing.ts' '**/*.unit.test.ts'",
58
+ "test:check": "node --env-file-if-exists='./.env' --experimental-test-coverage --test --test-concurrency=1 --test-coverage-exclude='**/*.test.*' --test-coverage-exclude='node_modules/**/*' --test-coverage-exclude='testing/**/*' --test-coverage-include='source/**/*' --test-global-setup='./testing/entrypoint.ts' '**/*.test.ts'",
59
+ "test:check:integration": "node --env-file-if-exists='./.env' --test --test-concurrency=1 --test-global-setup='./testing/entrypoint.ts' '**/*.integration.test.ts'",
60
+ "test:check:unit": "node --env-file-if-exists='./.env' --test --test-global-setup='./testing/entrypoint.ts' '**/*.unit.test.ts'",
50
61
  "typescript:check": "node --env-file-if-exists='./.env' ./node_modules/.bin/tsc"
51
62
  },
52
63
  "type": "module",
53
- "version": "4.0.0"
64
+ "version": "5.0.0"
54
65
  }
@@ -1,3 +1,3 @@
1
- import {optionsOfLoadingTypescriptHook} from "./options/index.js";
1
+ import {optionsOfLoadingTypescriptHook} from "./features/module.js";
2
2
  import {registerHooks} from "node:module";
3
3
  registerHooks(optionsOfLoadingTypescriptHook);
@@ -1 +1,2 @@
1
+ export * from "./loading/module.js";
1
2
  export {optionsOfLoadingTypescriptHook} from "./optionsOfLoadingTypescriptHook.js";
@@ -0,0 +1 @@
1
+ export * as base_ from "./index.js";
@@ -1,4 +1,4 @@
1
- import {loadTypescript} from "../base/index.js";
1
+ import {base_} from "../base/module.js";
2
2
  /** @typedef {import("node:module").LoadFnOutput} LoadFnOutput */
3
3
  /** @typedef {import("node:module").LoadHookContext} LoadHookContext */
4
4
  /**
@@ -14,7 +14,7 @@ import {loadTypescript} from "../base/index.js";
14
14
  * @returns {LoadFnOutput}
15
15
  */
16
16
  export function loadCommonjsTypescript(url, context, nextLoad) {
17
- const output = loadTypescript(
17
+ const output = base_.loadTypescript(
18
18
  {output: `commonjs`, reformattedContext: `commonjs-typescript`},
19
19
  url,
20
20
  context,
@@ -0,0 +1 @@
1
+ export * as commonjs_ from "./index.js";
@@ -0,0 +1,2 @@
1
+ export * from "./commonjs/module.js";
2
+ export * from "./module/module.js";
@@ -1,4 +1,4 @@
1
- import {loadTypescript} from "../base/index.js";
1
+ import {base_} from "../base/module.js";
2
2
  /** @typedef {import("node:module").LoadFnOutput} LoadFnOutput */
3
3
  /** @typedef {import("node:module").LoadHookContext} LoadHookContext */
4
4
  /**
@@ -14,7 +14,7 @@ import {loadTypescript} from "../base/index.js";
14
14
  * @returns {LoadFnOutput}
15
15
  */
16
16
  export function loadModuleTypescript(url, context, nextLoad) {
17
- const output = loadTypescript(
17
+ const output = base_.loadTypescript(
18
18
  {output: `module`, reformattedContext: `module-typescript`},
19
19
  url,
20
20
  context,
@@ -0,0 +1 @@
1
+ export * as module_ from "./index.js";
@@ -0,0 +1 @@
1
+ export * as typescript_ from "./index.js";
@@ -0,0 +1,4 @@
1
+ export {load} from "./load.js";
2
+ export * from "./TypeScript/module.js";
3
+ export * from "./with-known-format/module.js";
4
+ export * from "./with-unknown-format/module.js";
@@ -1,5 +1,5 @@
1
- import {loadWithKnownFormat} from "./with-known-format/index.js";
2
- import {loadWithUnknownFormat} from "./with-unknown-format/index.js";
1
+ import {withKnownFormat_} from "./with-known-format/module.js";
2
+ import {withUnknownFormat_} from "./with-unknown-format/module.js";
3
3
  /** @typedef {import("node:module").LoadFnOutput} LoadFnOutput */
4
4
  /** @typedef {import("node:module").LoadHookContext} LoadHookContext */
5
5
  /**
@@ -18,10 +18,19 @@ export function load(
18
18
  nextLoad,
19
19
  ) {
20
20
  if (typeof context.format === `string`) {
21
- const output = loadWithKnownFormat(url, context, nextLoad, context.format);
21
+ const output = withKnownFormat_.loadWithKnownFormat(
22
+ url,
23
+ context,
24
+ nextLoad,
25
+ context.format,
26
+ );
22
27
  return output;
23
28
  } else {
24
- const output = loadWithUnknownFormat(url, context, nextLoad);
29
+ const output = withUnknownFormat_.loadWithUnknownFormat(
30
+ url,
31
+ context,
32
+ nextLoad,
33
+ );
25
34
  return output;
26
35
  }
27
36
  }
@@ -0,0 +1 @@
1
+ export * as loading_ from "./index.js";
@@ -1,7 +1,4 @@
1
- import {
2
- loadCommonjsTypescript,
3
- loadModuleTypescript,
4
- } from "../TypeScript/index.js";
1
+ import {typescript_} from "../TypeScript/module.js";
5
2
  /** @typedef {import("node:module").LoadFnOutput} LoadFnOutput */
6
3
  /** @typedef {import("node:module").LoadHookContext} LoadHookContext */
7
4
  /**
@@ -23,11 +20,19 @@ export function loadWithKnownFormat(
23
20
  ) {
24
21
  switch (formatOfContext) {
25
22
  case `commonjs-typescript`: {
26
- const output = loadCommonjsTypescript(url, context, nextLoad);
23
+ const output = typescript_.commonjs_.loadCommonjsTypescript(
24
+ url,
25
+ context,
26
+ nextLoad,
27
+ );
27
28
  return output;
28
29
  }
29
30
  case `module-typescript`: {
30
- const output = loadModuleTypescript(url, context, nextLoad);
31
+ const output = typescript_.module_.loadModuleTypescript(
32
+ url,
33
+ context,
34
+ nextLoad,
35
+ );
31
36
  return output;
32
37
  }
33
38
  default: {
@@ -0,0 +1 @@
1
+ export * as withKnownFormat_ from "./index.js";
@@ -0,0 +1 @@
1
+ export * as extractingExtensionFromUrl_ from "./index.js";
@@ -1,5 +1,5 @@
1
- import {extractExtensionFromUrl} from "./extracting-extension-from-url/index.js";
2
- import {loadWithExtension} from "./with-extension/index.js";
1
+ import {extractingExtensionFromUrl_} from "./extracting-extension-from-url/module.js";
2
+ import {withExtension_} from "./with-extension/module.js";
3
3
  /** @typedef {import("node:module").LoadFnOutput} LoadFnOutput */
4
4
  /** @typedef {import("node:module").LoadHookContext} LoadHookContext */
5
5
  /**
@@ -17,12 +17,18 @@ export function loadWithUnknownFormat(
17
17
  /** @type {NextLoad} */
18
18
  nextLoad,
19
19
  ) {
20
- const extensionOfUrl = extractExtensionFromUrl(url);
20
+ const extensionOfUrl =
21
+ extractingExtensionFromUrl_.extractExtensionFromUrl(url);
21
22
  if (extensionOfUrl === null) {
22
23
  const output = nextLoad(url, context);
23
24
  return output;
24
25
  } else {
25
- const output = loadWithExtension(url, context, nextLoad, extensionOfUrl);
26
+ const output = withExtension_.loadWithExtension(
27
+ url,
28
+ context,
29
+ nextLoad,
30
+ extensionOfUrl,
31
+ );
26
32
  return output;
27
33
  }
28
34
  }
@@ -0,0 +1 @@
1
+ export * as withUnknownFormat_ from "./index.js";
@@ -1,8 +1,5 @@
1
- import {
2
- loadCommonjsTypescript,
3
- loadModuleTypescript,
4
- } from "../../TypeScript/index.js";
5
- import {loadUnknownTypescript} from "./unknown-TypeScript/index.js";
1
+ import {typescript_} from "../../TypeScript/module.js";
2
+ import {unknownTypescript_} from "./unknown-TypeScript/module.js";
6
3
  /** @typedef {import("node:module").LoadFnOutput} LoadFnOutput */
7
4
  /** @typedef {import("node:module").LoadHookContext} LoadHookContext */
8
5
  /**
@@ -24,15 +21,27 @@ export function loadWithExtension(
24
21
  ) {
25
22
  switch (extensionOfUrl) {
26
23
  case `cts`: {
27
- const output = loadCommonjsTypescript(url, context, nextLoad);
24
+ const output = typescript_.commonjs_.loadCommonjsTypescript(
25
+ url,
26
+ context,
27
+ nextLoad,
28
+ );
28
29
  return output;
29
30
  }
30
31
  case `mts`: {
31
- const output = loadModuleTypescript(url, context, nextLoad);
32
+ const output = typescript_.module_.loadModuleTypescript(
33
+ url,
34
+ context,
35
+ nextLoad,
36
+ );
32
37
  return output;
33
38
  }
34
39
  case `ts`: {
35
- const output = loadUnknownTypescript(url, context, nextLoad);
40
+ const output = unknownTypescript_.loadUnknownTypescript(
41
+ url,
42
+ context,
43
+ nextLoad,
44
+ );
36
45
  return output;
37
46
  }
38
47
  default: {
@@ -0,0 +1 @@
1
+ export * as withExtension_ from "./index.js";
@@ -1,4 +1,4 @@
1
- import {useReadFileSyncSafely} from "./using-readFileSync-safely/index.js";
1
+ import {usingReadFileSyncSafely_} from "./using-readFileSync-safely/module.js";
2
2
  import {dirname, resolve} from "node:path";
3
3
  import {fileURLToPath} from "node:url";
4
4
  /** @returns {"commonjs" | "module"} */
@@ -9,7 +9,8 @@ export function determineTypeOfModule(
9
9
  let pathOfCurrentDirectory = dirname(fileURLToPath(url));
10
10
  for (;;) {
11
11
  const pathOfPackageJson = resolve(pathOfCurrentDirectory, `package.json`);
12
- const contentOfPackageJson = useReadFileSyncSafely(pathOfPackageJson);
12
+ const contentOfPackageJson =
13
+ usingReadFileSyncSafely_.useReadFileSyncSafely(pathOfPackageJson);
13
14
  if (contentOfPackageJson === null) {
14
15
  const pathOfParentDirectory = dirname(pathOfCurrentDirectory);
15
16
  if (pathOfParentDirectory === pathOfCurrentDirectory) {
@@ -0,0 +1 @@
1
+ export * as determiningTypeOfModule_ from "./index.js";
@@ -1,10 +1,11 @@
1
1
  import {readFileSync} from "node:fs";
2
- /** @returns {null | Uint8Array<ArrayBuffer>} */
2
+ /** @returns {Buffer | null} */
3
3
  export function useReadFileSyncSafely(
4
4
  /** @type {string} */
5
5
  path,
6
6
  ) {
7
7
  try {
8
+ /** @type {Buffer} */
8
9
  const content = readFileSync(path);
9
10
  return content;
10
11
  } catch (error) {
@@ -1,8 +1,5 @@
1
- import {
2
- loadCommonjsTypescript,
3
- loadModuleTypescript,
4
- } from "../../../TypeScript/index.js";
5
- import {determineTypeOfModule} from "./determining-type-of-module/index.js";
1
+ import {typescript_} from "../../../TypeScript/module.js";
2
+ import {determiningTypeOfModule_} from "./determining-type-of-module/module.js";
6
3
  /** @typedef {import("node:module").LoadFnOutput} LoadFnOutput */
7
4
  /** @typedef {import("node:module").LoadHookContext} LoadHookContext */
8
5
  /**
@@ -20,14 +17,22 @@ export function loadUnknownTypescript(
20
17
  /** @type {NextLoad} */
21
18
  nextLoad,
22
19
  ) {
23
- const typeOfModule = determineTypeOfModule(url);
20
+ const typeOfModule = determiningTypeOfModule_.determineTypeOfModule(url);
24
21
  switch (typeOfModule) {
25
22
  case `commonjs`: {
26
- const output = loadCommonjsTypescript(url, context, nextLoad);
23
+ const output = typescript_.commonjs_.loadCommonjsTypescript(
24
+ url,
25
+ context,
26
+ nextLoad,
27
+ );
27
28
  return output;
28
29
  }
29
30
  case `module`: {
30
- const output = loadModuleTypescript(url, context, nextLoad);
31
+ const output = typescript_.module_.loadModuleTypescript(
32
+ url,
33
+ context,
34
+ nextLoad,
35
+ );
31
36
  return output;
32
37
  }
33
38
  }
@@ -0,0 +1 @@
1
+ export * as unknownTypescript_ from "./index.js";
@@ -0,0 +1 @@
1
+ export * from "./index.js";
@@ -1,6 +1,6 @@
1
- import {load} from "./loading/index.js";
1
+ import {loading_} from "./loading/module.js";
2
2
  /** @typedef {import("node:module").RegisterHooksOptions} RegisterHooksOptions */
3
3
  /** @satisfies {RegisterHooksOptions} */
4
4
  export const optionsOfLoadingTypescriptHook = /** @type {const} */ ({
5
- load: load,
5
+ load: loading_.load,
6
6
  });
@@ -0,0 +1 @@
1
+ export * from "./features/module.js";
@@ -0,0 +1 @@
1
+ export * from "./index.js";
File without changes
@@ -0,0 +1 @@
1
+ export * as utilities_ from "./index.js";
@@ -1,2 +0,0 @@
1
- export * from "./commonjs/index.js";
2
- export * from "./module/index.js";
@@ -1 +0,0 @@
1
- export {load} from "./load.js";