@ranger1/dx 0.1.7 → 0.1.8

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/lib/env-policy.js CHANGED
@@ -1,15 +1,12 @@
1
1
  import { existsSync, readFileSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
+ import stripJsonComments from 'strip-json-comments'
3
4
 
4
5
  const DEFAULT_POLICY_PATH = 'env-policy.jsonc'
5
6
 
6
7
  let cachedPolicy = null
7
8
  let cachedPolicyDir = null
8
9
 
9
- function sanitizeJsonc(raw) {
10
- return raw.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '')
11
- }
12
-
13
10
  function assertStringArray(value, fieldPath) {
14
11
  if (!Array.isArray(value)) {
15
12
  throw new Error(`${fieldPath} 必须是数组`)
@@ -39,7 +36,7 @@ export function loadEnvPolicy(configDir) {
39
36
  let parsed
40
37
  try {
41
38
  const raw = readFileSync(policyPath, 'utf8')
42
- parsed = JSON.parse(sanitizeJsonc(raw) || '{}')
39
+ parsed = JSON.parse(stripJsonComments(raw) || '{}')
43
40
  } catch (error) {
44
41
  throw new Error(`无法解析 ${DEFAULT_POLICY_PATH}: ${error.message}`)
45
42
  }
package/lib/env.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readFileSync } from 'node:fs'
2
2
  import { join } from 'node:path'
3
+ import stripJsonComments from 'strip-json-comments'
3
4
 
4
5
  function resolveProjectRoot() {
5
6
  return process.env.DX_PROJECT_ROOT || process.cwd()
@@ -112,7 +113,7 @@ export class EnvManager {
112
113
 
113
114
  try {
114
115
  const raw = readFileSync(configPath, 'utf8')
115
- const sanitized = raw.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '')
116
+ const sanitized = stripJsonComments(raw)
116
117
  this.requiredEnvConfig = JSON.parse(sanitized || '{}') || { _common: [] }
117
118
  } catch (error) {
118
119
  throw new Error(`无法解析 required-env.jsonc: ${error.message}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,8 +26,15 @@
26
26
  "access": "public"
27
27
  },
28
28
  "dependencies": {
29
+ "strip-json-comments": "^5.0.3",
29
30
  "yaml": "^2.8.1"
30
31
  },
32
+ "devDependencies": {
33
+ "jest": "^29.7.0"
34
+ },
35
+ "scripts": {
36
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest"
37
+ },
31
38
  "engines": {
32
39
  "node": ">=20.11.0"
33
40
  }