Skip to content

Add DTS issue workaround and prepare release #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: CI

on: [pull_request, push]
on: [pull_request]

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10.x
- name: Yarn install, build, and test
run: |
yarn install
yarn build
yarn test
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 10.x
- name: Yarn install, build, and test
run: |
yarn install
yarn build
yarn test
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The below is an example that only matches "\*.m.css" files, and [camel-cases das

### Visual Studio Code

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

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).

Expand Down Expand Up @@ -126,3 +126,11 @@ declare module '*.module.less' {
export default classes;
}
```

## Troubleshooting

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).

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).

You can also include this with any issues you file on this project.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-plugin-css-modules",
"version": "1.2.1",
"version": "1.3.0",
"main": "lib/index.js",
"author": "Brody McKee <[email protected]>",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const packageName = 'typescript-plugin-css-modules';
9 changes: 8 additions & 1 deletion src/helpers/DtsSnapshotCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as sass from 'sass';
import * as reserved from 'reserved-words';
import { transformClasses } from './classTransforms';
import { Options } from '../options';
import { Logger } from './Logger';
import { Logger } from './logger';

const NOT_CAMELCASE_REGEXP = /[\-_]/;

Expand Down Expand Up @@ -103,6 +103,13 @@ export default classes;
options: Options,
) {
const css = scriptSnapshot.getText(0, scriptSnapshot.getLength());

// FIXME: Temporary workaround for https://github.com/mrmckeb/typescript-plugin-css-modules/issues/41
// Needs investigation for a more elegant solution.
if (/export default classes/.test(css)) {
return scriptSnapshot;
}

const classes = this.getClasses(processor, css, fileName);
const dts = this.createExports(classes, options);
return ts.ScriptSnapshot.fromString(dts);
Expand Down
19 changes: 0 additions & 19 deletions src/helpers/Logger.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/helpers/__tests__/createMatchers.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMatchers } from '../createMatchers';
import { Options } from '../../options';
import { Logger } from '../Logger';
import { Logger } from '../logger';

describe('utils / createMatchers', () => {
const logger: Logger = { log: jest.fn(), error: jest.fn() };
Expand Down
1 change: 0 additions & 1 deletion src/helpers/config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/helpers/createMatchers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createIsCSS, createIsRelativeCSS } from './cssExtensions';
import { Options } from '../options';
import { Logger } from './Logger';
import { Logger } from './logger';

export const createMatchers = (logger: Logger, options: Options = {}) => {
// Allow custom matchers to be used, and handle bad matcher patterns.
Expand Down
21 changes: 21 additions & 0 deletions src/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { packageName } from '../config';

export interface Logger {
log(message: string): void;
error(error: Error): void;
}

export const createLogger = (info: ts.server.PluginCreateInfo): Logger => {
const log = (message: string) => {
info.project.projectService.logger.info(`[${packageName}] ${message}`);
};
const error = (error: Error) => {
log(`Failed ${error.toString()}`);
log(`Stack trace: ${error.stack}`);
};

return {
log,
error,
};
};
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import * as fs from 'fs';
import * as path from 'path';
import * as loadPostCssConfig from 'postcss-load-config';
import * as ts_module from 'typescript/lib/tsserverlibrary';

import { createMatchers } from './helpers/createMatchers';
import { isCSSFn } from './helpers/cssExtensions';
import { DtsSnapshotCreator } from './helpers/DtsSnapshotCreator';
import { Options } from './options';
import { LanguageServiceLogger } from './helpers/Logger';

import { createLogger } from './helpers/logger';
import * as postcss from 'postcss';
import * as postcssIcssSelectors from 'postcss-icss-selectors';

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

function create(info: ts.server.PluginCreateInfo) {
const logger = new LanguageServiceLogger(info);
const logger = createLogger(info);
const dtsSnapshotCreator = new DtsSnapshotCreator(logger);
const postcssConfig = getPostCssConfig(info.project.getCurrentDirectory());
const processor = postcss([
Expand Down Expand Up @@ -117,12 +115,12 @@ function init({ typescript: ts }: { typescript: typeof ts_module }) {
info.languageServiceHost.resolveModuleNames = (
moduleNames,
containingFile,
reusedNames,
...rest
) => {
const resolvedModules = _resolveModuleNames(
moduleNames,
containingFile,
reusedNames,
...rest,
);

return moduleNames.map((moduleName, index) => {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"outDir": "lib",
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": false,
"strict": true,
"strictNullChecks": true,
"target": "es5"
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/**"]
"exclude": ["**/__tests__/**"]
}
Loading