Skip to content

Commit

Permalink
fix: disable fork ts checker when any cli plugin is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Sep 28, 2022
1 parent 8076b73 commit c90364d
Showing 1 changed file with 85 additions and 75 deletions.
160 changes: 85 additions & 75 deletions lib/compiler/defaults/webpack-defaults.ts
Expand Up @@ -14,85 +14,95 @@ export const webpackDefaultsFactory = (
isDebugEnabled = false,
tsConfigFile = defaultConfiguration.compilerOptions.tsConfigPath,
plugins: MultiNestCompilerPlugins,
): webpack.Configuration => ({
entry: appendTsExtension(join(sourceRoot, entryFilename)),
devtool: isDebugEnabled ? 'inline-source-map' : false,
target: 'node',
output: {
filename: join(relativeSourceRoot, `${entryFilename}.js`),
},
ignoreWarnings: [/^(?!CriticalDependenciesWarning$)/],
externals: [nodeExternals() as any],
externalsPresets: { node: true },
module: {
rules: [
{
test: /.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: !isAnyPluginRegistered(plugins),
configFile: tsConfigFile,
getCustomTransformers: (program: any) => ({
before: plugins.beforeHooks.map((hook) => hook(program)),
after: plugins.afterHooks.map((hook) => hook(program)),
afterDeclarations: plugins.afterDeclarationsHooks.map((hook) =>
hook(program),
),
}),
): webpack.Configuration => {
const isPluginRegistered = isAnyPluginRegistered(plugins);
const webpackConfiguration: webpack.Configuration = {
entry: appendTsExtension(join(sourceRoot, entryFilename)),
devtool: isDebugEnabled ? 'inline-source-map' : false,
target: 'node',
output: {
filename: join(relativeSourceRoot, `${entryFilename}.js`),
},
ignoreWarnings: [/^(?!CriticalDependenciesWarning$)/],
externals: [nodeExternals() as any],
externalsPresets: { node: true },
module: {
rules: [
{
test: /.tsx?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: !isPluginRegistered,
configFile: tsConfigFile,
getCustomTransformers: (program: any) => ({
before: plugins.beforeHooks.map((hook) => hook(program)),
after: plugins.afterHooks.map((hook) => hook(program)),
afterDeclarations: plugins.afterDeclarationsHooks.map(
(hook) => hook(program),
),
}),
},
},
},
],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
plugins: [
new TsconfigPathsPlugin({
configFile: tsConfigFile,
}),
],
},
mode: 'none',
optimization: {
nodeEnv: false,
},
node: {
__filename: false,
__dirname: false,
},
plugins: [
new TsconfigPathsPlugin({
configFile: tsConfigFile,
new webpack.IgnorePlugin({
checkResource(resource: any) {
const lazyImports = [
'@nestjs/microservices',
'cache-manager',
'class-validator',
'class-transformer',
];
if (!lazyImports.includes(resource)) {
return false;
}
try {
require.resolve(resource, {
paths: [process.cwd()],
});
} catch (err) {
return true;
}
return false;
},
}),
],
},
mode: 'none',
optimization: {
nodeEnv: false,
},
node: {
__filename: false,
__dirname: false,
},
plugins: [
new webpack.IgnorePlugin({
checkResource(resource: any) {
const lazyImports = [
'@nestjs/microservices',
'cache-manager',
'class-validator',
'class-transformer',
];
if (!lazyImports.includes(resource)) {
return false;
}
try {
require.resolve(resource, {
paths: [process.cwd()],
});
} catch (err) {
return true;
}
return false;
},
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: tsConfigFile,
},
}),
],
});
};

if (!isPluginRegistered) {
webpackConfiguration.plugins!.push(
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: tsConfigFile,
},
}),
);
}

return webpackConfiguration;
};

function isAnyPluginRegistered(plugins: MultiNestCompilerPlugins) {
return (
Expand Down

0 comments on commit c90364d

Please sign in to comment.