Skip to content

Commit

Permalink
feat: add support for TypeScript 5.x (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmckeb committed Mar 11, 2023
1 parent 0365602 commit aa18204
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 155 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@
"prettier": "^2.8.4",
"sass-svg": "^1.2.0",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
"typescript": "5.0.1-rc"
},
"peerDependencies": {
"typescript": ">=3.9.0"
"typescript": ">=4.0.0"
},
"pnpm": {
"peerDependencyRules": {
Expand Down
60 changes: 30 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions src/helpers/getDtsSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from 'fs';
import tsModule from 'typescript/lib/tsserverlibrary';
import { Options } from '../options';
import { getCssExports } from './getCssExports';
Expand All @@ -9,23 +10,12 @@ export const getDtsSnapshot = (
ts: typeof tsModule,
processor: Processor,
fileName: string,
scriptSnapshot: ts.IScriptSnapshot,
options: Options,
logger: Logger,
compilerOptions: tsModule.CompilerOptions,
directory: string,
): tsModule.IScriptSnapshot => {
const css = scriptSnapshot.getText(0, scriptSnapshot.getLength());

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

const css = readFileSync(fileName, 'utf-8');
const cssExports = getCssExports({
css,
fileName,
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { server } from 'typescript/lib/tsserverlibrary';

export interface Logger {
log: (message: string) => void;
error: (error: unknown) => void;
}

export const createLogger = (info: ts.server.PluginCreateInfo): Logger => {
export const createLogger = (info: server.PluginCreateInfo): Logger => {
const log = (message: string) => {
info.project.projectService.logger.info(
`[typescript-plugin-css-modules] ${message}`,
Expand Down
Loading

0 comments on commit aa18204

Please sign in to comment.