Skip to content

Commit 8698439

Browse files
authored
Add DTS issue workaround and prepare release (#43)
1 parent 7033534 commit 8698439

File tree

13 files changed

+823
-840
lines changed

13 files changed

+823
-840
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
name: CI
22

3-
on: [pull_request, push]
3+
on: [pull_request]
44

55
jobs:
66
build-and-test:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v1
10-
- uses: actions/setup-node@v1
11-
with:
12-
node-version: 10.x
13-
- name: Yarn install, build, and test
14-
run: |
15-
yarn install
16-
yarn build
17-
yarn test
9+
- uses: actions/checkout@v1
10+
- uses: actions/setup-node@v1
11+
with:
12+
node-version: 10.x
13+
- name: Yarn install, build, and test
14+
run: |
15+
yarn install
16+
yarn build
17+
yarn test

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The below is an example that only matches "\*.m.css" files, and [camel-cases das
8383

8484
### Visual Studio Code
8585

86-
By default, VSCode will use it's own version of TypeScript. To make it work with this plugin, you have two options:
86+
By default, VSCode will use its own version of TypeScript. To make it work with this plugin, you have two options:
8787

8888
1. Use your workspace's version of TypeScript, which will load plugins from your `tsconfig.json` file. This is the recommended approach. For instructions, see: [Using the workspace version of TypeScript](https://code.visualstudio.com/docs/languages/typescript#_using-the-workspace-version-of-typescript).
8989

@@ -126,3 +126,11 @@ declare module '*.module.less' {
126126
export default classes;
127127
}
128128
```
129+
130+
## Troubleshooting
131+
132+
If you're having issues with this extension, you can view the TypeScript Server Log in VSCode by entering `Typescript: Open TS Server log` in the [command palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette).
133+
134+
If that doesn't work, or you're not using VSCode, you can set the [TSS_LOG environment variable](https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29#logging).
135+
136+
You can also include this with any issues you file on this project.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typescript-plugin-css-modules",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"main": "lib/index.js",
55
"author": "Brody McKee <[email protected]>",
66
"license": "MIT",

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const packageName = 'typescript-plugin-css-modules';

src/helpers/DtsSnapshotCreator.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as sass from 'sass';
66
import * as reserved from 'reserved-words';
77
import { transformClasses } from './classTransforms';
88
import { Options } from '../options';
9-
import { Logger } from './Logger';
9+
import { Logger } from './logger';
1010

1111
const NOT_CAMELCASE_REGEXP = /[\-_]/;
1212

@@ -103,6 +103,13 @@ export default classes;
103103
options: Options,
104104
) {
105105
const css = scriptSnapshot.getText(0, scriptSnapshot.getLength());
106+
107+
// FIXME: Temporary workaround for https://github.com/mrmckeb/typescript-plugin-css-modules/issues/41
108+
// Needs investigation for a more elegant solution.
109+
if (/export default classes/.test(css)) {
110+
return scriptSnapshot;
111+
}
112+
106113
const classes = this.getClasses(processor, css, fileName);
107114
const dts = this.createExports(classes, options);
108115
return ts.ScriptSnapshot.fromString(dts);

src/helpers/Logger.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/helpers/__tests__/createMatchers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createMatchers } from '../createMatchers';
22
import { Options } from '../../options';
3-
import { Logger } from '../Logger';
3+
import { Logger } from '../logger';
44

55
describe('utils / createMatchers', () => {
66
const logger: Logger = { log: jest.fn(), error: jest.fn() };

src/helpers/config.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/helpers/createMatchers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createIsCSS, createIsRelativeCSS } from './cssExtensions';
22
import { Options } from '../options';
3-
import { Logger } from './Logger';
3+
import { Logger } from './logger';
44

55
export const createMatchers = (logger: Logger, options: Options = {}) => {
66
// Allow custom matchers to be used, and handle bad matcher patterns.

src/helpers/logger.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { packageName } from '../config';
2+
3+
export interface Logger {
4+
log(message: string): void;
5+
error(error: Error): void;
6+
}
7+
8+
export const createLogger = (info: ts.server.PluginCreateInfo): Logger => {
9+
const log = (message: string) => {
10+
info.project.projectService.logger.info(`[${packageName}] ${message}`);
11+
};
12+
const error = (error: Error) => {
13+
log(`Failed ${error.toString()}`);
14+
log(`Stack trace: ${error.stack}`);
15+
};
16+
17+
return {
18+
log,
19+
error,
20+
};
21+
};

src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import * as loadPostCssConfig from 'postcss-load-config';
44
import * as ts_module from 'typescript/lib/tsserverlibrary';
5-
65
import { createMatchers } from './helpers/createMatchers';
76
import { isCSSFn } from './helpers/cssExtensions';
87
import { DtsSnapshotCreator } from './helpers/DtsSnapshotCreator';
98
import { Options } from './options';
10-
import { LanguageServiceLogger } from './helpers/Logger';
11-
9+
import { createLogger } from './helpers/logger';
1210
import * as postcss from 'postcss';
1311
import * as postcssIcssSelectors from 'postcss-icss-selectors';
1412

@@ -34,7 +32,7 @@ function init({ typescript: ts }: { typescript: typeof ts_module }) {
3432
let _isCSS: isCSSFn;
3533

3634
function create(info: ts.server.PluginCreateInfo) {
37-
const logger = new LanguageServiceLogger(info);
35+
const logger = createLogger(info);
3836
const dtsSnapshotCreator = new DtsSnapshotCreator(logger);
3937
const postcssConfig = getPostCssConfig(info.project.getCurrentDirectory());
4038
const processor = postcss([
@@ -117,12 +115,12 @@ function init({ typescript: ts }: { typescript: typeof ts_module }) {
117115
info.languageServiceHost.resolveModuleNames = (
118116
moduleNames,
119117
containingFile,
120-
reusedNames,
118+
...rest
121119
) => {
122120
const resolvedModules = _resolveModuleNames(
123121
moduleNames,
124122
containingFile,
125-
reusedNames,
123+
...rest,
126124
);
127125

128126
return moduleNames.map((moduleName, index) => {

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
"noImplicitReturns": true,
1111
"noImplicitThis": true,
1212
"outDir": "lib",
13+
"resolveJsonModule": true,
1314
"rootDir": "src",
1415
"skipLibCheck": false,
1516
"strict": true,
16-
"strictNullChecks": true,
1717
"target": "es5"
1818
},
1919
"include": ["src"],
20-
"exclude": ["node_modules", "**/__tests__/**"]
20+
"exclude": ["**/__tests__/**"]
2121
}

0 commit comments

Comments
 (0)