|
1 | 1 | import * as path from 'path';
|
2 | 2 | import * as ts_module from 'typescript/lib/tsserverlibrary';
|
3 |
| -import { isCSS as _isCSS, isRelativeCSS } from './helpers/cssExtensions'; |
| 3 | +import { createMatchers } from './helpers/createMatchers'; |
| 4 | +import { isCSSFn } from './helpers/cssExtensions'; |
4 | 5 | import { getDtsSnapshot } from './helpers/cssSnapshots';
|
5 | 6 |
|
6 | 7 | function init({ typescript: ts }: { typescript: typeof ts_module }) {
|
7 |
| - let isCSS = _isCSS; |
| 8 | + let _isCSS: isCSSFn; |
8 | 9 | function create(info: ts.server.PluginCreateInfo) {
|
9 | 10 | // User options for plugin.
|
10 | 11 | const options: IOptions = info.config.options || {};
|
11 | 12 |
|
12 |
| - // Allow custom matchers to be used, handling bad matcher patterns; |
13 |
| - try { |
14 |
| - const { customMatcher } = options; |
15 |
| - if (customMatcher) { |
16 |
| - isCSS = (fileName) => new RegExp(customMatcher).test(fileName); |
17 |
| - } |
18 |
| - } catch (e) { |
19 |
| - // TODO: Provide error/warning to user. |
20 |
| - } |
| 13 | + // Create matchers using options object. |
| 14 | + const { isCSS, isRelativeCSS } = createMatchers(options); |
| 15 | + _isCSS = isCSS; |
21 | 16 |
|
22 | 17 | // Creates new virtual source files for the CSS modules.
|
23 | 18 | const _createLanguageServiceSourceFile = ts.createLanguageServiceSourceFile;
|
@@ -97,7 +92,7 @@ function init({ typescript: ts }: { typescript: typeof ts_module }) {
|
97 | 92 | }
|
98 | 93 |
|
99 | 94 | function getExternalFiles(project: ts_module.server.ConfiguredProject) {
|
100 |
| - return project.getFileNames().filter(isCSS); |
| 95 | + return project.getFileNames().filter(_isCSS); |
101 | 96 | }
|
102 | 97 |
|
103 | 98 | return { create, getExternalFiles };
|
|
0 commit comments