chore: clean up old WatchStateLoggerPlugin

This commit is contained in:
Igor Randjelovic
2021-03-26 23:20:27 +01:00
parent b7da9d573f
commit b2a636e307
5 changed files with 4 additions and 90 deletions

View File

@ -7,7 +7,6 @@ import FilterWarningsPlugin from 'webpack-filter-warnings-plugin';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import TerserPlugin from 'terser-webpack-plugin'; import TerserPlugin from 'terser-webpack-plugin';
// import { WatchStateLoggerPlugin } from '../plugins/WatchStateLoggerPlugin';
import { getProjectFilePath, getProjectRootPath } from '../helpers/project'; import { getProjectFilePath, getProjectRootPath } from '../helpers/project';
import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin'; import { PlatformSuffixPlugin } from '../plugins/PlatformSuffixPlugin';
import { addCopyRule, applyCopyRules } from '../helpers/copyRules'; import { addCopyRule, applyCopyRules } from '../helpers/copyRules';
@ -308,8 +307,6 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
applyCopyRules(config); applyCopyRules(config);
// add the WatchStateLogger plugin used to notify the CLI of build state
// config.plugin('WatchStateLoggerPlugin').use(WatchStateLoggerPlugin);
config.plugin('WatchStatePlugin').use(WatchStatePlugin); config.plugin('WatchStatePlugin').use(WatchStatePlugin);
config.when(env.hmr, (config) => { config.when(env.hmr, (config) => {

View File

@ -1,6 +1,7 @@
// @ts-nocheck // @ts-nocheck
// This is a runtime module - included by nativescript-hot-loader // This is a runtime module - included by nativescript-hot-loader
// this file should not include external dependencies // this file should not include external dependencies
// todo: add verbose logs when enabled
// --- // ---
if (module.hot) { if (module.hot) {

View File

@ -4,10 +4,9 @@ import { INativeScriptPlatform } from "../helpers/platform";
import { getProjectRootPath } from "../helpers/project"; import { getProjectRootPath } from "../helpers/project";
function sanitizeName(appName: string): string { function sanitizeName(appName: string): string {
const sanitizedName = appName.split("").filter((c) => return appName.split("").filter((c) =>
/[a-zA-Z0-9]/.test(c) /[a-zA-Z0-9]/.test(c)
).join(""); ).join("");
return sanitizedName;
} }
function getDistPath() { function getDistPath() {
const appName = sanitizeName(basename(getProjectRootPath())); const appName = sanitizeName(basename(getProjectRootPath()));

View File

@ -1,83 +0,0 @@
import webpack from 'webpack';
const id = 'WatchStateLoggerPlugin';
export enum messages {
compilationComplete = 'Webpack compilation complete.',
startWatching = 'Webpack compilation complete. Watching for file changes.',
changeDetected = 'File change detected. Starting incremental webpack compilation...',
}
/**
* This little plugin will report the webpack state through the console.
* So the {N} CLI can get some idea when compilation completes.
* @deprecated todo: remove soon
*/
export class WatchStateLoggerPlugin {
isRunningWatching: boolean;
apply(compiler) {
const plugin = this;
compiler.hooks.watchRun.tapAsync(id, function (compiler, callback) {
plugin.isRunningWatching = true;
if (plugin.isRunningWatching) {
console.log(messages.changeDetected);
}
notify(messages.changeDetected);
callback();
});
compiler.hooks.afterEmit.tapAsync(id, function (compilation, callback) {
callback();
if (plugin.isRunningWatching) {
console.log(messages.startWatching);
} else {
console.log(messages.compilationComplete);
}
const emittedFiles = Array.from(compilation.emittedAssets);
const chunkFiles = getChunkFiles(compilation);
notify(messages.compilationComplete);
// Send emitted files so they can be LiveSynced if need be
notify({ emittedFiles, chunkFiles, hash: compilation.hash });
});
}
}
function getChunkFiles(compilation: webpack.Compilation) {
const chunkFiles = [];
try {
compilation.chunks.forEach((chunk) => {
chunk.files.forEach((file) => {
if (file.indexOf('hot-update') === -1) {
chunkFiles.push(file);
}
});
});
} catch (e) {
console.log('Warning: Unable to find chunk files.');
}
return chunkFiles;
}
function notify(message: any) {
if (!process.send) {
return;
}
process.send(message, (error) => {
if (error) {
console.error(`[${id}] Process Send Error: `, error);
}
return null;
});
}

View File

@ -9,8 +9,8 @@ export enum messages {
} }
/** /**
* This little plugin will report the webpack state through the console. * This little plugin will report the webpack state through the console
* So the {N} CLI can get some idea when compilation completes. * and send status updates through IPC to the {N} CLI.
*/ */
export class WatchStatePlugin { export class WatchStatePlugin {
apply(compiler: any) { apply(compiler: any) {