Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
move cache into folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Oct 28, 2020
1 parent 7b5da06 commit 50d0c97
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
__tests__/fixtures/*/.next
__tests__/fixtures/*/.mdx-data
__tests__/fixtures/*/out
.DS_Store
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ Install the package:
$ npm install next-mdx-enhanced
```

Open the `.gitgnore` file and add the `.mdx-data` directory:

```shell
# .gitignore

# Ignore next-mdx-enhanced cache directory
.mdx-data
```

This directory is populated with cache files as an optimization.

## Usage & Options

Open the `next.config.js` file and instantiate it as a Next.js plugin:
Expand Down
4 changes: 2 additions & 2 deletions __tests__/__snapshots__/babelPlugin.js.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`transforms as intended 1`] = `
"import something from \\"PATH/TO/NEXT/PROJECT/.mdx-data/9edc110b0a5f0cf4742677e8539f30c9.json\\";
"import something from \\"PATH/TO/NEXT/PROJECT/.next/cache/mdx-data/9edc110b0a5f0cf4742677e8539f30c9.json\\";
import a, { c as d } from './foo.mdx';
import b from \\"PATH/TO/NEXT/PROJECT/.mdx-data/9edc110b0a5f0cf4742677e8539f30c9.json\\";"
import b from \\"PATH/TO/NEXT/PROJECT/.next/cache/mdx-data/9edc110b0a5f0cf4742677e8539f30c9.json\\";"
`;
1 change: 0 additions & 1 deletion __tests__/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ test('options.onContent', async () => {
afterAll(() => {
return Promise.all([
rmfr(path.join(__dirname, 'fixtures/*/out'), { glob: true }),
rmfr(path.join(__dirname, 'fixtures/*/.mdx-data'), { glob: true }),
rmfr(path.join(__dirname, 'fixtures/*/.next'), { glob: true }),
])
})
Expand Down
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ module.exports = (pluginOptions = {}) => (nextConfig = {}) => {
pluginOptions.extendFrontMatter.phase = 'both'
}

if (!pluginOptions.usesSrc) pluginOptions.usesSrc = fs.existsSync(`src/pages`);
if (!pluginOptions.usesSrc) pluginOptions.usesSrc = fs.existsSync(`src/pages`)

pluginOptions.pagesDir = pluginOptions.usesSrc? `src/pages` : `pages`;
pluginOptions.pagesDir = pluginOptions.usesSrc ? `src/pages` : `pages`

return Object.assign({}, nextConfig, {
webpack(config, options) {
Expand Down Expand Up @@ -77,7 +77,9 @@ module.exports = (pluginOptions = {}) => (nextConfig = {}) => {
files: {
pattern:
pluginOptions.fileExtensions.length > 1
? `${pluginOptions.pagesDir}/**/*.{${pluginOptions.fileExtensions.join(',')}}`
? `${
pluginOptions.pagesDir
}/**/*.{${pluginOptions.fileExtensions.join(',')}}`
: `${pluginOptions.pagesDir}/**/*.${pluginOptions.fileExtensions[0]}`,
options: { cwd: config.context },
addFilesAsDependencies: true,
Expand Down Expand Up @@ -142,9 +144,9 @@ async function extractFrontMatter(
// TODO: remove this catch once this issue has been resolved
// https://github.com/zeit/next.js/issues/8068
debug('finish: frontmatter extensions')
debug('start: .mdx-data creation')
debug('start: mdx-data cache creation')
await Promise.all(fmPaths.map((fmPath) => fs.ensureDir(path.dirname(fmPath))))
debug('finish: .mdx-data creation')
debug('finish: mdx-data cache creation')
debug('start: write data files')
return Promise.all(
frontMatter.map((content, idx) => {
Expand Down
2 changes: 1 addition & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function generateFrontmatterPath(filePath, root) {
return normalizeToUnixPath(
path.join(
root,
'.mdx-data',
'.next/cache/mdx-data',
`${md5(filePathNormalized.replace(dirnameNormalized, ''))}.json`
)
)
Expand Down

0 comments on commit 50d0c97

Please sign in to comment.