Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: egoist/joycon
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.1.0
Choose a base ref
...
head repository: egoist/joycon
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.1.1
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Dec 1, 2021

  1. fix: just parse the contents as json by default (#26)

    * fix: just parse the contents as json by default
    
    really no point in returning raw text, if a user wants to parse the content they will add a loader anyway
    
    * Update README.md
    egoist authored Dec 1, 2021
    1
    Copy the full SHA
    4c1e876 View commit details
Showing with 5 additions and 12 deletions.
  1. +1 −1 README.md
  2. +4 −11 src/index.js
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ joycon.load(['package-lock.json', 'yarn.lock'])
})
```

By default only `.js`, `.cjs`, and `.json` file are parsed, otherwise raw data will be returned, so you can add custom loader to parse them:
By default non-js files are parsed as JSON, if you want something different you can add a loader:

```js
const joycon = new JoyCon()
15 changes: 4 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -157,19 +157,12 @@ export default class JoyCon {
return require(filepath)
}

if (extname === 'json') {
if (this.packageJsonCache.has(filepath)) {
return this.packageJsonCache.get(filepath)[options.packageKey]
}

const data = this.options.parseJSON(readFileSync(filepath))
return data
if (this.packageJsonCache.has(filepath)) {
return this.packageJsonCache.get(filepath)[options.packageKey]
}

// Don't parse data
// If it's neither .js nor .json
// Leave this to user-land
return readFileSync(filepath)
const data = this.options.parseJSON(readFileSync(filepath))
return data
},
}
const loader = this.findLoader(filepath) || defaultLoader