-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"parserOptions": { | ||
"project": ["packages/nx-webpack-plugin/tsconfig.*?.json"] | ||
}, | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# nx-webpack-plugin | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build nx-webpack-plugin` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test nx-webpack-plugin` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { Config } from 'jest'; | ||
|
||
export default { | ||
displayName: 'nx-webpack-plugin', | ||
preset: '../../jest.preset.js', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/packages/nx-webpack-plugin', | ||
} as Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@deepkit/nx-webpack-plugin", | ||
"version": "0.0.1", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/marcus-sa/deepkit-community.git" | ||
}, | ||
"dependencies": { | ||
"tslib": "2.6.2", | ||
"webpack": "5.88.2", | ||
"ts-loader": "9.4.4" | ||
}, | ||
"peerDependencies": { | ||
"@deepkit/type-compiler": "*", | ||
"@nx/webpack": "^16.7.4" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "nx-webpack-plugin", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/nx-webpack-plugin/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/{projectRoot}", | ||
"tsConfig": "{projectRoot}/tsconfig.lib.json", | ||
"packageJson": "{projectRoot}/package.json", | ||
"main": "{projectRoot}/src/index.ts", | ||
"assets": ["{projectRoot}/*.md"] | ||
} | ||
}, | ||
"release": { | ||
"command": "release-it --config={projectRoot}/.release-it.json" | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"{projectRoot}/**/*.ts", | ||
"{projectRoot}/package.json" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "{projectRoot}/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
}, | ||
"tags": ["nx-webpack-plugin"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib/with-deepkit'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { NxWebpackPlugin } from '@nx/webpack'; | ||
import type { RuleSetRule } from 'webpack'; | ||
import type { LoaderOptions } from 'ts-loader/dist/interfaces'; | ||
import * as typeCompiler from '@deepkit/type-compiler'; | ||
|
||
interface TsLoaderRule extends RuleSetRule { | ||
readonly options: LoaderOptions; | ||
} | ||
|
||
type GetCustomTransformers = Exclude< | ||
LoaderOptions['getCustomTransformers'], | ||
string | ||
>; | ||
|
||
function addDeepkitTransformer( | ||
prevGetCustomTransformers: GetCustomTransformers, | ||
): GetCustomTransformers { | ||
return (program, getProgram) => { | ||
const customTransformers = { | ||
...prevGetCustomTransformers?.(program, getProgram), | ||
}; | ||
customTransformers.before = [ | ||
typeCompiler.transformer, | ||
...(customTransformers.before || []), | ||
]; | ||
customTransformers.afterDeclarations = [ | ||
typeCompiler.declarationTransformer, | ||
...(customTransformers.afterDeclarations || []), | ||
]; | ||
return customTransformers; | ||
}; | ||
} | ||
|
||
export function withDeepkit(): NxWebpackPlugin { | ||
return config => { | ||
const rules = config.module!.rules! as readonly RuleSetRule[]; | ||
|
||
rules | ||
.filter( | ||
(rule): rule is TsLoaderRule => !!rule.loader?.includes('ts-loader'), | ||
) | ||
.forEach(tsRule => { | ||
tsRule.options!.getCustomTransformers = addDeepkitTransformer( | ||
tsRule.options.getCustomTransformers as GetCustomTransformers, | ||
); | ||
}); | ||
|
||
return config; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "commonjs" | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"reflection": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"] | ||
}, | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], | ||
"include": ["src/**/*.ts"], | ||
"reflection": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.ts" | ||
], | ||
"reflection": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters