-
Notifications
You must be signed in to change notification settings - Fork 61
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
❎ Exclude files listed in project config from myst build and watch #924
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'myst-config': patch | ||
'myst-cli': patch | ||
--- | ||
|
||
Exclude files listed in project confg from myst build and watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import fs from 'node:fs'; | ||
import { extname, join } from 'node:path'; | ||
import { extname, join, sep } from 'node:path'; | ||
import { glob } from 'glob'; | ||
import { isDirectory } from 'myst-cli-utils'; | ||
import { RuleId } from 'myst-common'; | ||
import type { ISession } from '../session/types.js'; | ||
import { selectors } from '../store/index.js'; | ||
import { addWarningForFile } from '../utils/addWarningForFile.js'; | ||
import { fileInfo } from '../utils/fileInfo.js'; | ||
import { nextLevel } from '../utils/nextLevel.js'; | ||
|
@@ -136,36 +138,51 @@ function indexFileFromPages(pages: (LocalProjectFolder | LocalProjectPage)[], pa | |
/** | ||
* Build project structure from local file/folder structure. | ||
*/ | ||
export function projectFromPath( | ||
export async function projectFromPath( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotta make sure we update this with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in curvenote here: |
||
session: ISession, | ||
path: string, | ||
indexFile?: string, | ||
): Omit<LocalProject, 'bibliography'> { | ||
): Promise<Omit<LocalProject, 'bibliography'>> { | ||
const ext_string = VALID_FILE_EXTENSIONS.join(' or '); | ||
if (indexFile) { | ||
if (!isValidFile(indexFile)) | ||
throw Error(`Index file ${indexFile} has invalid extension; must be ${ext_string}}`); | ||
if (!fs.existsSync(indexFile)) throw Error(`Index file ${indexFile} not found`); | ||
} | ||
const rootConfigYamls = session.configFiles.map((file) => join(path, file)); | ||
const projectConfig = selectors.selectLocalProjectConfig(session.store.getState(), path); | ||
const excludePatterns = projectConfig?.exclude ?? []; | ||
const excludeFiles = ( | ||
await Promise.all( | ||
excludePatterns.map(async (pattern) => { | ||
const matches = await glob(pattern.split(sep).join('/')); | ||
return matches | ||
.map((match) => match.split('/').join(sep)) | ||
.filter((match) => isValidFile(match)); | ||
}), | ||
) | ||
).flat(); | ||
const ignoreFiles = [...rootConfigYamls, ...excludeFiles]; | ||
let implicitIndex = false; | ||
if (!indexFile) { | ||
const searchPages = projectPagesFromPath( | ||
session, | ||
path, | ||
1, | ||
{}, | ||
{ ignore: rootConfigYamls, suppressWarnings: true }, | ||
{ ignore: ignoreFiles, suppressWarnings: true }, | ||
); | ||
if (!searchPages.length) { | ||
throw Error(`No valid files with extensions ${ext_string} found in path "${path}"`); | ||
} | ||
indexFile = indexFileFromPages(searchPages, path); | ||
if (!indexFile) throw Error(`Unable to find any index file in path "${path}"`); | ||
implicitIndex = true; | ||
} | ||
const pageSlugs: PageSlugs = {}; | ||
const { slug } = fileInfo(indexFile, pageSlugs); | ||
const pages = projectPagesFromPath(session, path, 1, pageSlugs, { | ||
ignore: [indexFile, ...rootConfigYamls], | ||
ignore: [indexFile, ...ignoreFiles], | ||
}); | ||
return { file: indexFile, index: slug, path, pages }; | ||
return { file: indexFile, index: slug, path, pages, implicitIndex }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an edge case here:
When you update
exclude
in the project config, it will rebuild the project correctly with the newexclude
value respected. However,chokidar.watch
is not updated, so if you stop excluding a file you will not start watching it, and if you exclude a previously watched file, it will continue to be watched. I don't think this is a big deal... worst case scenario is you just kill yourmyst start
process and call it again to re-watch the correct stuff. (And if it is a problem, we can probably fix it....)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I think it shouldn't be that big a deal that the watch is lagging.