diff --git a/src/index.ts b/src/index.ts index a227098..8bc33e0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,7 +56,8 @@ async function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions, const rootPath = process.cwd(); const projectPath = getProjectPath(rootPath); - const [filesPaths, filesNames, filesNamesToPaths, filesFoundPaths, foldersFoundPaths] = await getTargetsPaths(rootPath, options.globs, options.withNodeModules); // prettier-ignore + const [filesPaths, filesNames, filesNamesToPaths, filesExplicitPaths, filesFoundPaths, foldersFoundPaths] = await getTargetsPaths(rootPath, options.globs, options.withNodeModules); // prettier-ignore + const filesExplicitPathsSet = new Set(filesExplicitPaths); const filesPathsTargets = filesPaths.filter(negate(isBinaryPath)).sort(); const [foldersPathsTargets, foldersExtraPaths] = getExpandedFoldersPaths(foldersFoundPaths, projectPath); const filesExtraPaths = await getFoldersChildrenPaths([rootPath, ...foldersExtraPaths]); @@ -103,7 +104,7 @@ async function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions, const cliFormatConfig = options.formatOptions; const cacheVersion = stringify({ prettierVersion, cliVersion, pluginsNames, pluginsVersions, editorConfigs, ignoreContents, prettierConfigs, ignoreManualFilesPaths, ignoreManualFilesContents, prettierManualFilesPaths, prettierManualFilesContents, cliContextConfig, cliFormatConfig, pluginsDefaultOptions, pluginsCustomOptions }); // prettier-ignore - const shouldCache = options.cache && !pluginsVersionsMissing.length && isUndefined(cliContextConfig.cursorOffset); + const shouldCache = options.cache && !options.dump && !pluginsVersionsMissing.length && isUndefined(cliContextConfig.cursorOffset); const cache = shouldCache ? new Cache(cacheVersion, projectPath, options, stdout) : undefined; const prettier = await makePrettier(options, cache); @@ -112,8 +113,10 @@ async function runGlobs(options: Options, pluginsDefaultOptions: PluginsOptions, filesPathsTargets.map(async (filePath) => { const isIgnored = () => (ignoreManual ? ignoreManual(filePath) : getIgnoreResolved(filePath, ignoreNames)); const isCacheable = () => cache?.has(filePath, isIgnored); - const ignored = cache ? !(await isCacheable()) : await isIgnored(); - if (ignored) return; + const isExplicitlyIncluded = () => filesExplicitPathsSet.has(filePath); + const isForceIncluded = options.dump && isExplicitlyIncluded(); + const isExcluded = cache ? !(await isCacheable()) : await isIgnored(); + if (!isForceIncluded && isExcluded) return; const getFormatOptions = async (): Promise => { const editorConfig = options.editorConfig ? getEditorConfigFormatOptions(await getEditorConfigResolved(filePath, editorConfigNames)) : {}; const prettierConfig = prettierManualConfig || (options.config ? await getPrettierConfigResolved(filePath, prettierConfigNames) : {}); diff --git a/src/types.ts b/src/types.ts index d76f108..9bfed09 100644 --- a/src/types.ts +++ b/src/types.ts @@ -48,6 +48,7 @@ type Options = { globs: string[]; /* OUTPUT OPTIONS */ check: boolean; + dump: boolean; list: boolean; write: boolean; /* CONFIG OPTIONS */ diff --git a/src/utils.ts b/src/utils.ts index 135da49..10db735 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -192,7 +192,7 @@ async function getTargetsPaths( rootPath: string, globs: string[], withNodeModules: boolean, -): Promise<[string[], string[], Record, string[], string[]]> { +): Promise<[string[], string[], Record, string[], string[], string[]]> { const targetFiles: string[] = []; const targetFilesNames: string[] = []; const targetFilesNamesToPaths: Record = {}; @@ -225,9 +225,10 @@ async function getTargetsPaths( filesNamesToPaths[fileName] = uniq(next); } + const filesExplicitPaths = targetFiles; const filesFoundPaths = result.filesFound; const foldersFoundPaths = [rootPath, ...result.directoriesFound]; - return [filesPaths, filesNames, filesNamesToPaths, filesFoundPaths, foldersFoundPaths]; + return [filesPaths, filesNames, filesNamesToPaths, filesExplicitPaths, filesFoundPaths, foldersFoundPaths]; } function isArray(value: unknown): value is unknown[] { @@ -309,6 +310,7 @@ async function normalizeOptions(options: unknown, targets: unknown[]): Promise { + runCli("print-code", [ + "./ignored.js" + ], { + stdoutIsTTY: true, + }).test({ + status: 0, + write: [], + stderr: "" + }); + + runCli("print-code", [ + "./not-ignored.js" + ], { + stdoutIsTTY: true, + }).test({ + status: 0, + write: [], + stderr: "" + }); +});