Skip to content

Add resolveCwd option and change default resolution behavior #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 2, 2022

Conversation

mshick
Copy link
Contributor

@mshick mshick commented Jul 15, 2022

This PR addresses #266 and #8 . It adds an optional boolean, useRelativeCwd to the mdx config. When set to true the cwd will be set to the directory the file currently being processed resides in.

I've included a test which will attempt to bundle a relatively-linked image from an mdx file.

@changeset-bot
Copy link

changeset-bot bot commented Jul 15, 2022

⚠️ No Changeset found

Latest commit: 33b29a8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@mshick
Copy link
Contributor Author

mshick commented Jul 15, 2022

Can be tested on a live project by adding an override to your package.json

e.g.,

  "overrides": {
    "@contentlayer/core": "mshick/contentlayer#build"
  }

@schickling schickling added this to the Next milestone Aug 1, 2022
@mshick mshick changed the title Add useRelativeCwd option Add resolveCwd option and change default resolution behavior Aug 1, 2022
@mshick
Copy link
Contributor Author

mshick commented Aug 1, 2022

@schickling Because MDX Bundler has it's own cwd option I've left that as-is, allowing the user to set any arbitrary path they want.

contentlayer now supports a resolveCwd option which is a union of relative and contentDirPath options. If neither cwd nor resolveCwd are provided then the new relative behavior is used as the default. If the user prefers the current behavior they can use the contentDirPath option.

This will be a breaking change for some users when using the default. If an mdx import was defined relative to the contentDirPath and the file being processed was at, say, content/posts/post.mdx then the imports would change as follows:

Before:

import { Widget } from '../components/Widget'

After:

import { Widget } from '../../components/Widget'

If the user had a flat content directory, say all their files in the root of contentDirPath (content/post.mdx) then there would be no change.

@schickling schickling merged commit 868328a into contentlayerdev:main Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants