Skip to content

Commit

Permalink
chore(contented-processor): pipeline.type to support ``^[a-zA-Z_$][\w…
Browse files Browse the repository at this point in the history
…$]*$` (#706)

#### What this PR does / why we need it:

As per title.

#### Which issue(s) will this PR fix?:
  • Loading branch information
fuxingloh authored Nov 17, 2023
1 parent 7d381b8 commit f8e86ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/contented-processor/src/ContentedProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export class ContentedProcessor {
config.outDir = config.outDir ?? './.contented';
config.pipelines.forEach((pipeline) => {
pipeline.type = pipeline.type ?? 'Docs';
if (pipeline.type.match(/[^a-zA-Z]/g)) {
if (!pipeline.type.match(/^[a-zA-Z_$][\w$]*$/)) {
throw new Error(
'Due to codegen, pipeline.type must be a string with allowed characters within the range of [a-zA-Z].',
'Due to codegen, pipeline.type must be a string with allowed characters within the range of ^[a-zA-Z_$][\\w$]*$.',
);
}

Expand Down
18 changes: 17 additions & 1 deletion packages/contented-processor/src/ContentedProcessor.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,25 @@ describe('validation', () => {
],
};
expect(() => new ContentedProcessor(config)).toThrow(
'Due to codegen, pipeline.type must be a string with allowed characters within the range of [a-zA-Z].',
'Due to codegen, pipeline.type must be a string with allowed characters within the range of ^[a-zA-Z_$][\\w$]*$.',
);
});

it('should allow type.name with _', async () => {
const config: Config = {
rootDir: './fixtures',
outDir: './.contented',
pipelines: [
{
type: '_type',
pattern: '**/*.md',
processor: 'md',
},
],
};

expect(() => new ContentedProcessor(config)).not.toThrow();
});
});

it('should dedup 2 files', async () => {
Expand Down

0 comments on commit f8e86ba

Please sign in to comment.