Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
fix(options): CLI option --ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
3axap4eHko committed Mar 20, 2023
1 parent 2471dae commit 60a4bd9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/swc/__tests__/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
})
);
});
});
})
11 changes: 11 additions & 0 deletions src/swc/__tests__/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
1 change: 1 addition & 0 deletions src/swc/dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async function initialCompilation(cliOptions: CliOptions, swcOptions: Options) {
const {
includeDotfiles,
filenames,
ignore,
copyFiles,
extensions,
outDir,
Expand Down
2 changes: 2 additions & 0 deletions src/swc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/swc/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { join, basename, extname } from "path";
*/
export async function globSources(
sources: string[],
includeDotfiles = false
includeDotfiles = false,
ignore: string[] = []
): Promise<string[]> {
const globConfig = {
dot: includeDotfiles,
nodir: true,
ignore,
};

const files = await Promise.all(
Expand Down

0 comments on commit 60a4bd9

Please sign in to comment.