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: svelteness/svelte-jester
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.1
Choose a base ref
...
head repository: svelteness/svelte-jester
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.1.2
Choose a head ref
  • 3 commits
  • 4 files changed
  • 3 contributors

Commits on Aug 16, 2020

  1. Copy the full SHA
    32fca5e View commit details
  2. Merge pull request #15 from tom-fletcher/master

    feat: improved rootMode to handle more monorepo use cases
    mihar-22 authored Aug 16, 2020
    Copy the full SHA
    d2685f9 View commit details
  3. chore(release): 1.1.2

    mihar-22 committed Aug 16, 2020
    Copy the full SHA
    674b701 View commit details
Showing with 24 additions and 8 deletions.
  1. +2 −0 CHANGELOG.md
  2. +8 −1 README.md
  3. +1 −1 package.json
  4. +13 −6 src/svelteconfig.js
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.1.2](https://github.com/mihar-22/svelte-jester/compare/v1.1.1...v1.1.2) (2020-08-16)

### [1.1.1](https://github.com/mihar-22/svelte-jester/compare/v1.1.0...v1.1.1) (2020-08-15)


9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -143,7 +143,14 @@ They are loaded from `svelte.config.js`.
`compilerOptions` (default: {}): Use this to pass in
[Svelte compiler options](https://svelte.dev/docs#svelte_compile).

`rootMode` (default: ""): Pass in `upward` to walk up from each file's directory and return the first `svelte.config.js` found, or throw an error if no config file is discovered. This is particularly useful in a monorepo using Jest projects as it allows each package to have it's own `svelte.config.js`, and is similar to Babel's `rootMode`. Default behaviour is to look for a `svelte.config.js` in the root directory.
`rootMode` (default: ""): Pass in `upward` to walk up from the transforming file's directory and use the first `svelte.config.js` found, or throw an error if no config file is discovered. This is particularly useful in a monorepo as it allows you to:
- Run tests from the worktree root using Jest projects where you only want to put `svelte.config.js` in workspace folders, and not in the root.
- Run tests from the worktree root using Jest projects, but have different `svelte.config.js` configurations for individual workspaces.
- Have one common `svelte.config.js` in your worktree root (or any directory above the file being transformed) without needing individual `svelte.config.js` files in each workspace. _Note - this root config file can be overriden if necessary by putting another config file into a workspace folder_

The default mode is to load `svelte.config.js` from the current project root to avoid the risk of accidentally loading a `svelte.config.js` from outside the current project folder.

When `upward` is set it will stop at the first config file it finds above the file being transformed, but will walk up the directory structure all the way to the filesystem root if it cannot find any config file. This means that if there is no `svelte.config.js` file in the project above the file being transformed, it is always possible that someone will have a forgotten `svelte.config.js` in their home directory which could cause unexpected errors in your builds.

```json
"transform": {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-jester",
"version": "1.1.1",
"version": "1.1.2",
"description": "A Jest transformer for Svelte - compile your components before importing them into tests",
"main": "src/transformer.js",
"license": "MIT",
19 changes: 13 additions & 6 deletions src/svelteconfig.js
Original file line number Diff line number Diff line change
@@ -6,16 +6,23 @@ const configFilename = 'svelte.config.js'
exports.getSvelteConfig = (rootMode, filename) => {
const configDir = rootMode === 'upward'
? getConfigDir(path.dirname(filename))
: getConfigDir(process.cwd())
return path.resolve(configDir, configFilename)
: process.cwd()
const configFile = path.resolve(configDir, configFilename)

if (!fs.existsSync(configFile)) {
throw Error(`Could not find ${configFilename}`)
}

return configFile
}

const getConfigDir = (searchDir) => {
if (fs.existsSync(path.join(searchDir, configFilename))) {
return searchDir
} else if (searchDir === process.cwd()) {
throw Error(`Could not find ${configFilename}`)
} else {
return getConfigDir(path.resolve(searchDir, '..'))
}

const parentDir = path.resolve(searchDir, '..')
return parentDir !== searchDir
? getConfigDir(parentDir)
: searchDir // Stop walking at filesystem root
}