* Parses the provided source and updates the parser state. * @param {string} content content of the lockfile * @returns {Lockfile} lockfile
(content)
| 247 | * @returns {Lockfile} lockfile |
| 248 | */ |
| 249 | static parse(content) { |
| 250 | // TODO handle merge conflicts |
| 251 | const data = JSON.parse(content); |
| 252 | if (data.version !== 1) { |
| 253 | throw new Error(`Unsupported lockfile version ${data.version}`); |
| 254 | } |
| 255 | const lockfile = new Lockfile(); |
| 256 | for (const key of Object.keys(data)) { |
| 257 | if (key === "version") continue; |
| 258 | const entry = data[key]; |
| 259 | lockfile.entries.set( |
| 260 | key, |
| 261 | typeof entry === "string" |
| 262 | ? entry |
| 263 | : { |
| 264 | resolved: key, |
| 265 | ...entry |
| 266 | } |
| 267 | ); |
| 268 | } |
| 269 | return lockfile; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Returns a string representation. |
no test coverage detected