From 60a4bd9dc1327d351475d3c40ac4c00e27110909 Mon Sep 17 00:00:00 2001 From: Ivan Zakharchanka <3axap4eHko@gmail.com> Date: Mon, 20 Mar 2023 01:34:37 -0400 Subject: [PATCH] fix(options): CLI option --ignore --- src/swc/__tests__/options.test.ts | 17 +++++++++++++++++ src/swc/__tests__/sources.test.ts | 11 +++++++++++ src/swc/dir.ts | 1 + src/swc/options.ts | 2 ++ src/swc/sources.ts | 4 +++- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/swc/__tests__/options.test.ts b/src/swc/__tests__/options.test.ts index 329f785..911f6c8 100644 --- a/src/swc/__tests__/options.test.ts +++ b/src/swc/__tests__/options.test.ts @@ -240,4 +240,21 @@ describe('parserArgs', () => { expect(result.swcOptions).toEqual(expectedOptions); }); }) + + describe("--ignore", () => { + it("includes ignore in cli options", async () => { + const args = [ + "node", + "/path/to/node_modules/swc-cli/bin/swc.js", + "src", + "--ignore", + "*.js", + ]; + expect(parserArgs(args).cliOptions).toEqual( + expect.objectContaining({ + ignore: ["*.js"], + }) + ); + }); + }); }) diff --git a/src/swc/__tests__/sources.test.ts b/src/swc/__tests__/sources.test.ts index f25beb6..8115e3d 100644 --- a/src/swc/__tests__/sources.test.ts +++ b/src/swc/__tests__/sources.test.ts @@ -58,6 +58,17 @@ describe("globSources", () => { expect([...files]).toEqual(["file"]); }); + + it("ignore sources when patterns provided", async () => { + (fs as any).setMockStats({ directory: { isDirectory: () => true } }); + + (glob as unknown as jest.Mock).mockResolvedValue([]); + await globSources(["directory"], false, ["**/file"]); + expect(glob).toHaveBeenCalledWith( + "directory/**", + expect.objectContaining({ ignore: ["**/file"] }) + ); + }); }); describe("splitCompilableAndCopyable", () => { diff --git a/src/swc/dir.ts b/src/swc/dir.ts index d5e7327..b9a1762 100644 --- a/src/swc/dir.ts +++ b/src/swc/dir.ts @@ -98,6 +98,7 @@ async function initialCompilation(cliOptions: CliOptions, swcOptions: Options) { const { includeDotfiles, filenames, + ignore, copyFiles, extensions, outDir, diff --git a/src/swc/options.ts b/src/swc/options.ts index c61660f..e150310 100644 --- a/src/swc/options.ts +++ b/src/swc/options.ts @@ -160,6 +160,7 @@ export interface CliOptions { readonly sourceMapTarget?: string; readonly filename: string; readonly filenames: string[]; + readonly ignore: string[]; readonly extensions: string[]; readonly watch: boolean; readonly copyFiles: boolean; @@ -261,6 +262,7 @@ export default function parserArgs(args: string[]) { outFile: opts.outFile, filename: opts.filename, filenames, + ignore: opts.ignore, sync: !!opts.sync, sourceMapTarget: opts.sourceMapTarget, extensions: opts.extensions || DEFAULT_EXTENSIONS, diff --git a/src/swc/sources.ts b/src/swc/sources.ts index f171018..fa4233e 100644 --- a/src/swc/sources.ts +++ b/src/swc/sources.ts @@ -8,11 +8,13 @@ import { join, basename, extname } from "path"; */ export async function globSources( sources: string[], - includeDotfiles = false + includeDotfiles = false, + ignore: string[] = [] ): Promise { const globConfig = { dot: includeDotfiles, nodir: true, + ignore, }; const files = await Promise.all(