Skip to content

Commit 24b9be9

Browse files
committed
Store resolved path to file
1 parent 4416463 commit 24b9be9

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

source/magic-json.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, test } from 'node:test'
22
import assert from 'node:assert/strict'
3+
import path from 'node:path'
34
import json, { type Metadata } from './magic-json.js'
45

56
type IndentationPattern = [ indent: string, description: string, eol: string ]
@@ -141,3 +142,12 @@ describe('Line endings', () => {
141142
assert.equal(meta.useCRLF, true)
142143
})
143144
})
145+
146+
describe('metadata', () => {
147+
148+
test('Stores resolved path to file', async () => {
149+
const obj = await json.fromFile('./package.json')
150+
const meta = json['getMetadata'](obj)
151+
assert(meta?.filepath === path.resolve('./package.json'))
152+
})
153+
})

source/magic-json.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'node:path'
12
import { readFile, writeFile } from 'node:fs/promises'
23
import { deprecate } from 'node:util'
34

@@ -42,7 +43,7 @@ export default abstract class MagicJSON {
4243
const json = this.parse(text)
4344
const meta = this.#metas.get(json)
4445
if (meta)
45-
meta.filepath = filepath
46+
meta.filepath = path.resolve(filepath)
4647
return json
4748
}
4849

0 commit comments

Comments
 (0)