@knighted/module 1.0.0-alpha.4 → 1.0.0-alpha.5

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.
@@ -15,6 +15,21 @@ const defaultOptions = {
15
15
  modules: false,
16
16
  specifier: undefined
17
17
  };
18
+ const getLangFromExt = filename => {
19
+ const ext = (0, _nodePath.extname)(filename);
20
+ if (/\.js$/.test(ext)) {
21
+ return 'js';
22
+ }
23
+ if (/\.ts$/.test(ext)) {
24
+ return 'ts';
25
+ }
26
+ if (ext === '.tsx') {
27
+ return 'tsx';
28
+ }
29
+ if (ext === '.jsx') {
30
+ return 'jsx';
31
+ }
32
+ };
18
33
  const transform = async (filename, options = defaultOptions) => {
19
34
  const opts = {
20
35
  ...defaultOptions,
@@ -25,10 +40,7 @@ const transform = async (filename, options = defaultOptions) => {
25
40
  const ast = (0, _parse.parse)(code);
26
41
  let source = (0, _format.format)(code, ast, opts).toString();
27
42
  if (options.specifier) {
28
- const {
29
- code,
30
- error
31
- } = await _specifier.specifier.updateSrc(source, ({
43
+ const code = await _specifier.specifier.updateSrc(source, getLangFromExt(filename), ({
32
44
  value
33
45
  }) => {
34
46
  // Collapse any BinaryExpression or NewExpression to test for a relative specifier
@@ -39,9 +51,7 @@ const transform = async (filename, options = defaultOptions) => {
39
51
  return value.replace(/(.+)\.(?:m|c)?(?:j|t)s([)'"`]*)?$/, `$1${options.specifier}$2`);
40
52
  }
41
53
  });
42
- if (code && !error) {
43
- source = code;
44
- }
54
+ source = code;
45
55
  }
46
56
  if (opts.out) {
47
57
  await (0, _promises.writeFile)((0, _nodePath.resolve)(opts.out), source);
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import { resolve } from 'node:path';
1
+ import { resolve, extname } from 'node:path';
2
2
  import { readFile, writeFile } from 'node:fs/promises';
3
3
  import { specifier } from '@knighted/specifier';
4
4
  import { parse } from './parse.js';
@@ -9,6 +9,21 @@ const defaultOptions = {
9
9
  modules: false,
10
10
  specifier: undefined
11
11
  };
12
+ const getLangFromExt = filename => {
13
+ const ext = extname(filename);
14
+ if (/\.js$/.test(ext)) {
15
+ return 'js';
16
+ }
17
+ if (/\.ts$/.test(ext)) {
18
+ return 'ts';
19
+ }
20
+ if (ext === '.tsx') {
21
+ return 'tsx';
22
+ }
23
+ if (ext === '.jsx') {
24
+ return 'jsx';
25
+ }
26
+ };
12
27
  const transform = async (filename, options = defaultOptions) => {
13
28
  const opts = {
14
29
  ...defaultOptions,
@@ -19,10 +34,7 @@ const transform = async (filename, options = defaultOptions) => {
19
34
  const ast = parse(code);
20
35
  let source = format(code, ast, opts).toString();
21
36
  if (options.specifier) {
22
- const {
23
- code,
24
- error
25
- } = await specifier.updateSrc(source, ({
37
+ const code = await specifier.updateSrc(source, getLangFromExt(filename), ({
26
38
  value
27
39
  }) => {
28
40
  // Collapse any BinaryExpression or NewExpression to test for a relative specifier
@@ -33,9 +45,7 @@ const transform = async (filename, options = defaultOptions) => {
33
45
  return value.replace(/(.+)\.(?:m|c)?(?:j|t)s([)'"`]*)?$/, `$1${options.specifier}$2`);
34
46
  }
35
47
  });
36
- if (code && !error) {
37
- source = code;
38
- }
48
+ source = code;
39
49
  }
40
50
  if (opts.out) {
41
51
  await writeFile(resolve(opts.out), source);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knighted/module",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.5",
4
4
  "description": "Converts module differences in source files between ES and CommonJS.",
5
5
  "type": "module",
6
6
  "main": "dist/module.js",
@@ -57,25 +57,25 @@
57
57
  "url": "https://github.com/knightedcodemonkey/module/issues"
58
58
  },
59
59
  "devDependencies": {
60
- "@babel/preset-env": "^7.24.6",
61
- "@babel/preset-typescript": "^7.24.6",
62
- "@babel/types": "^7.24.6",
60
+ "@babel/preset-env": "^7.26.9",
61
+ "@babel/preset-typescript": "^7.27.0",
62
+ "@babel/types": "^7.27.0",
63
63
  "@eslint/js": "^9.3.0",
64
64
  "@types/babel__traverse": "^7.20.6",
65
- "@types/node": "^20.12.12",
66
- "babel-dual-package": "^1.1.3",
67
- "c8": "^9.1.0",
68
- "eslint": "^9.3.0",
65
+ "@types/node": "^22.13.17",
66
+ "babel-dual-package": "^1.1.4",
67
+ "c8": "^10.1.3",
68
+ "eslint": "^9.23.0",
69
69
  "eslint-plugin-n": "^17.7.0",
70
70
  "prettier": "^3.2.5",
71
- "tsx": "^4.11.2",
72
- "typescript": "^5.4.5",
73
- "typescript-eslint": "^8.0.0-alpha.26"
71
+ "tsx": "^4.19.3",
72
+ "typescript": "^5.8.2",
73
+ "typescript-eslint": "^8.29.0"
74
74
  },
75
75
  "dependencies": {
76
- "@babel/parser": "^7.24.6",
77
- "@babel/traverse": "^7.24.6",
78
- "@knighted/specifier": "^2.0.0-rc.1",
76
+ "@babel/parser": "^7.27.0",
77
+ "@babel/traverse": "^7.27.0",
78
+ "@knighted/specifier": "^2.0.0-rc.4",
79
79
  "magic-string": "^0.30.10"
80
80
  },
81
81
  "prettier": {