@knighted/duel 1.0.2 → 1.0.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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![codecov](https://codecov.io/gh/knightedcodemonkey/duel/branch/main/graph/badge.svg?token=7K74BRLHFy)](https://codecov.io/gh/knightedcodemonkey/duel)
5
5
  [![NPM version](https://img.shields.io/npm/v/@knighted/duel.svg)](https://www.npmjs.com/package/@knighted/duel)
6
6
 
7
- Node.js tool for building a TypeScript dual package.
7
+ Tool for building a Node.js [dual package](https://nodejs.org/api/packages.html#dual-commonjses-module-packages) with TypeScript. Supports CommonJS and ES module projects.
8
8
 
9
9
  ## Features
10
10
 
@@ -37,7 +37,7 @@ Then, given a `package.json` that defines `"type": "module"` and a `tsconfig.js
37
37
  }
38
38
  ```
39
39
 
40
- You can create a build for the project defined by the above configuration, **and also a separate dual CJS build** by defining the following npm run script in your `package.json`:
40
+ You can create an ES module build for the project defined by the above configuration, **and also a dual CJS build** by defining the following npm run script in your `package.json`:
41
41
 
42
42
  ```json
43
43
  "scripts": {
package/dist/init.cjs CHANGED
@@ -8,8 +8,8 @@ var _nodeProcess = require("node:process");
8
8
  var _nodeUtil = require("node:util");
9
9
  var _nodePath = require("node:path");
10
10
  var _promises = require("node:fs/promises");
11
- var _stripJsonComments = _interopRequireDefault(require("strip-json-comments"));
12
11
  var _readPkgUp = require("read-pkg-up");
12
+ var _jsoncParser = _interopRequireDefault(require("jsonc-parser"));
13
13
  var _util = require("./util.cjs");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
  const init = async args => {
@@ -104,10 +104,14 @@ const init = async args => {
104
104
  }
105
105
  if (stats.isFile()) {
106
106
  let tsconfig = null;
107
- try {
108
- tsconfig = JSON.parse((0, _stripJsonComments.default)((await (0, _promises.readFile)(configPath)).toString()));
109
- } catch (err) {
110
- (0, _util.logError)(`The config file found at ${configPath} is not parsable as JSON.`);
107
+ const errors = [];
108
+ const jsonText = (await (0, _promises.readFile)(configPath)).toString();
109
+ tsconfig = _jsoncParser.default.parse(jsonText, errors, {
110
+ disallowComments: false,
111
+ allowTrailingComma: true
112
+ });
113
+ if (errors.length) {
114
+ (0, _util.logError)(`The config file found at ${configPath} is not parsable as JSONC.`);
111
115
  return false;
112
116
  }
113
117
  if (!tsconfig.compilerOptions?.outDir) {
package/dist/init.js CHANGED
@@ -2,8 +2,8 @@ import { cwd } from 'node:process';
2
2
  import { parseArgs } from 'node:util';
3
3
  import { resolve, join, dirname } from 'node:path';
4
4
  import { stat, readFile } from 'node:fs/promises';
5
- import stripJsonComments from 'strip-json-comments';
6
5
  import { readPackageUp } from 'read-pkg-up';
6
+ import JSONC from 'jsonc-parser';
7
7
  import { logError, log } from './util.js';
8
8
  const init = async args => {
9
9
  let parsed = null;
@@ -97,10 +97,14 @@ const init = async args => {
97
97
  }
98
98
  if (stats.isFile()) {
99
99
  let tsconfig = null;
100
- try {
101
- tsconfig = JSON.parse(stripJsonComments((await readFile(configPath)).toString()));
102
- } catch (err) {
103
- logError(`The config file found at ${configPath} is not parsable as JSON.`);
100
+ const errors = [];
101
+ const jsonText = (await readFile(configPath)).toString();
102
+ tsconfig = JSONC.parse(jsonText, errors, {
103
+ disallowComments: false,
104
+ allowTrailingComma: true
105
+ });
106
+ if (errors.length) {
107
+ logError(`The config file found at ${configPath} is not parsable as JSONC.`);
104
108
  return false;
105
109
  }
106
110
  if (!tsconfig.compilerOptions?.outDir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knighted/duel",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "TypeScript dual packages.",
5
5
  "type": "module",
6
6
  "main": "dist",
@@ -25,11 +25,17 @@
25
25
  "prepack": "npm run build"
26
26
  },
27
27
  "keywords": [
28
- "tsc",
28
+ "node",
29
29
  "typescript",
30
+ "esm",
31
+ "cjs",
32
+ "commonjs",
30
33
  "dual package",
34
+ "build",
35
+ "tsc",
31
36
  "cts",
32
- "mts"
37
+ "mts",
38
+ "mjs"
33
39
  ],
34
40
  "files": [
35
41
  "dist"
@@ -60,8 +66,8 @@
60
66
  "@knighted/specifier": "^1.0.1",
61
67
  "find-up": "^6.3.0",
62
68
  "glob": "^10.3.3",
63
- "read-pkg-up": "^10.0.0",
64
- "strip-json-comments": "^5.0.1"
69
+ "jsonc-parser": "^3.2.0",
70
+ "read-pkg-up": "^10.0.0"
65
71
  },
66
72
  "prettier": {
67
73
  "arrowParens": "avoid",