Skip to content

Commit 25a1ed4

Browse files
committed
Prepare package for publishing
1 parent 3bb0a60 commit 25a1ed4

File tree

6 files changed

+112
-8
lines changed

6 files changed

+112
-8
lines changed

.npmignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.vscode
2+
/node_modules
3+
/src
4+
.editorconfig
5+
npm-debug.log
6+
tsconfig.json
7+
tslint.json
8+
yarn-error.log
9+
yarn.lock

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Brody McKee
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# typescript-plugin-css-modules
2+
3+
A [TypeScript language service plugin](https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin)
4+
for [CSS Modules](https://github.com/css-modules/css-modules).
5+
6+
This project was inspired by this [`create-react-app` issue](https://github.com/facebook/create-react-app/issues/5677)
7+
and is heavily based on [`css-module-types`](https://github.com/timothykang/css-module-types).
8+
9+
## Usage
10+
11+
To install with Yarn:
12+
13+
```sh
14+
yarn add typescript-plugin-css-modules
15+
```
16+
17+
To install with npm:
18+
19+
```sh
20+
npm install --save typescript-plugin-css-modules
21+
```
22+
23+
Once installed, add this plugin to your `tsconfig.json`:
24+
25+
```json
26+
{
27+
"compilerOptions": {
28+
"plugins": [{ "name": "typescript-plugin-css-modules" }]
29+
}
30+
}
31+
```
32+
33+
You can also pass in your own file extension matcher (the default matcher is shown as an example):
34+
35+
```json
36+
{
37+
"compilerOptions": {
38+
"plugins": [
39+
{
40+
"name": "typescript-plugin-css-modules",
41+
"options": {
42+
"customMatcher": "\\.module\\.(sa|sc|c)ss$"
43+
}
44+
}
45+
]
46+
}
47+
}
48+
```
49+
50+
### Custom definitions
51+
52+
Depending on your project configuration, you may also need to declare modules. Where you store this is up to you. An
53+
example might look like: `src/@types/custom.d.ts`.
54+
55+
The below is an example that you can modify if you use a `customMatcher`.
56+
57+
```ts
58+
declare module '*.module.css' {
59+
const classes: { [key: string]: string };
60+
export default classes;
61+
}
62+
63+
declare module '*.module.scss' {
64+
const classes: { [key: string]: string };
65+
export default classes;
66+
}
67+
68+
declare module '*.module.sass' {
69+
const classes: { [key: string]: string };
70+
export default classes;
71+
}
72+
```

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "typescript-css-modules",
3-
"version": "1.0.0",
2+
"name": "typescript-plugin-css-modules",
3+
"version": "0.1.0",
44
"main": "lib/index.js",
5-
"repository": "git@github.com:mrmckeb/typescript-css-modules.git",
5+
"repository": "git@github.com:mrmckeb/typescript-plugin-css-modules.git",
66
"author": "Brody McKee <mrmckeb@hotmail.com>",
77
"license": "MIT",
88
"description": "CSS modules support for TypeScript",
@@ -15,12 +15,14 @@
1515
"typescript"
1616
],
1717
"scripts": {
18-
"build": "tsc",
18+
"build": "rm -rf ./lib && tsc",
19+
"prepublish": "yarn build",
1920
"test": "jest"
2021
},
2122
"husky": {
2223
"hooks": {
23-
"pre-commit": "pretty-quick --staged"
24+
"pre-commit": "pretty-quick --staged",
25+
"pre-push": "yarn test"
2426
}
2527
},
2628
"jest": {

src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as path from 'path';
22
import * as ts_module from 'typescript/lib/tsserverlibrary';
3-
import { types } from 'util';
43
import { isCSS as _isCSS, isRelativeCSS } from './helpers/cssExtensions';
54
import { getDtsSnapshot } from './helpers/cssSnapshots';
65

@@ -18,7 +17,7 @@ function init({ typescript: ts }: { typescript: typeof ts_module }) {
1817
isCSS = (fileName) => new RegExp(customMatcher).test(fileName);
1918
}
2019
} catch (e) {
21-
// There doesn't appear to be a way to throw warnings yet.
20+
// TODO: Provide error/warning to user.
2221
}
2322

2423
// Creates new virtual source files for the CSS modules.

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
"strict": true,
1515
"strictNullChecks": true,
1616
"target": "es5"
17-
}
17+
},
18+
"exclude": ["node_modules", "**/*.test.ts"]
1819
}

0 commit comments

Comments
 (0)