Skip to content

Commit

Permalink
fix(next): warnings does not kill the process
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Dec 11, 2019
1 parent b93b32b commit 29ff45e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/cli_next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createNodeSysWithWatch } from '../sys/node_next/node-sys-watch';
import { loadConfig } from '@compiler';
import { parseFlags } from './parse-flags';
import { runTask } from './tasks/run-task';
import { shouldIgnoreError } from '@utils';
import { shouldIgnoreError, hasError } from '@utils';
import { setupWorkerController } from '../sys/node_next/worker';
import exit from 'exit';
import { join } from 'path';
Expand Down Expand Up @@ -48,7 +48,9 @@ export async function run(init: CliInitOptions) {

if (validated.diagnostics.length > 0) {
logger.printDiagnostics(validated.diagnostics);
exit(1);
if (hasError(validated.diagnostics)) {
exit(1);
}
}

setupWorkerController(sys, logger);
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/html/remove-unused-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as d from '../../declarations';
import { parseCss } from '../style/parse-css';
import { StringifyCss } from '../style/stringify-css';
import { UsedSelectors } from '../style/used-selectors';
import { hasError } from '@utils';


export function removeUnusedStyles(doc: Document, diagnostics: d.Diagnostic[]) {
Expand All @@ -24,8 +25,8 @@ function removeUnusedStyleText(usedSelectors: UsedSelectors, diagnostics: d.Diag
// parse the css from being applied to the document
const cssAst = parseCss(styleElm.innerHTML);

if (cssAst.stylesheet.diagnostics.length > 0) {
diagnostics.push(...cssAst.stylesheet.diagnostics);
diagnostics.push(...cssAst.stylesheet.diagnostics);
if (hasError(diagnostics)) {
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/compiler_next/config/load-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildError, catchError, isString, normalizePath } from '@utils';
import { buildError, catchError, isString, normalizePath, hasError } from '@utils';
import { CompilerSystem, Config, Diagnostic, LoadConfigInit, LoadConfigResults } from '../../declarations';
import { createLogger } from '../sys/logger';
import { createSystem } from '../sys/stencil-sys';
Expand Down Expand Up @@ -41,7 +41,7 @@ export const loadConfig = async (init: LoadConfigInit = {}) => {
}

const loadedConfigFile = await loadConfigFile(sys, results.diagnostics, configPath, isDefaultConfigPath);
if (results.diagnostics.length > 0) {
if (hasError(results.diagnostics)) {
return results;
}

Expand All @@ -65,7 +65,7 @@ export const loadConfig = async (init: LoadConfigInit = {}) => {

const validated = validateConfig(results.config);
results.diagnostics.push(...validated.diagnostics);
if (results.diagnostics.length > 0) {
if (hasError(results.diagnostics)) {
return results;
}

Expand Down Expand Up @@ -132,7 +132,7 @@ const loadConfigFile = async (sys: CompilerSystem, diagnostics: Diagnostic[], co
// the passed in config was a string, so it's probably a path to the config we need to load
// first clear the require cache so we don't get the same file
const configFileData = evaluateConfigFile(sys, diagnostics, configPath);
if (diagnostics.length > 0) {
if (hasError(diagnostics)) {
return config;
}

Expand Down Expand Up @@ -190,7 +190,7 @@ const evaluateConfigFile = (sys: CompilerSystem, diagnostics: Diagnostic[], conf
// browser environment, can't use node's require() to evaluate
let sourceText = sys.readFileSync(configFilePath, 'utf8');
sourceText = transpileTypedConfig(diagnostics, sourceText, configFilePath);
if (diagnostics.length > 0) {
if (hasError(diagnostics)) {
return configFileData;
}

Expand All @@ -210,7 +210,7 @@ const transpileTypedConfig = (diagnostics: Diagnostic[], sourceText: string, fil
// let's transpile an awesome stencil.config.ts file into
// a boring stencil.config.js file
const ts = loadTypescript(diagnostics);
if (diagnostics.length > 0) {
if (hasError(diagnostics)) {
return sourceText;
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiler_next/sys/typescript/typescript-patch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as d from '../../../declarations';
import { buildError, buildWarn, catchError, isString, loadTypeScriptDiagnostic, normalizePath } from '@utils';
import { buildError, buildWarn, catchError, isString, loadTypeScriptDiagnostic, normalizePath, hasError } from '@utils';
import { getTypeScriptSys } from './typescript-sys';
import { loadTypescript } from './typescript-load';
import { patchTypeScriptResolveModule } from './typescript-resolve-module';
Expand All @@ -9,7 +9,7 @@ import ts from 'typescript';

export const patchTypescript = async (config: d.Config, diagnostics: d.Diagnostic[], inMemoryFs: d.InMemoryFileSystem) => {
const loadedTs = loadTypescript(diagnostics);
if (diagnostics.length > 0) {
if (hasError(diagnostics)) {
return;
}

Expand Down
8 changes: 3 additions & 5 deletions src/compiler_next/transpile/transpile-to-es5.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as d from '../../declarations';
import { loadTypeScriptDiagnostics } from '@utils';
import { loadTypeScriptDiagnostics, hasError } from '@utils';
import { loadTypescript } from '../sys/typescript/typescript-load';


Expand All @@ -14,7 +14,7 @@ export async function transpileToEs5(input: string, inlineHelpers: boolean) {
moduleFile: null,
build: {}
};
if (diagnostics.length > 0) {
if (hasError(diagnostics)) {
return results;
}

Expand All @@ -34,12 +34,10 @@ export async function transpileToEs5(input: string, inlineHelpers: boolean) {
};

const tsResults = ts.transpileModule(input, transpileOpts);

results.diagnostics.push(
...loadTypeScriptDiagnostics(tsResults.diagnostics)
);

if (results.diagnostics.length === 0) {
if (!hasError(results.diagnostics)) {
results.code = fixHelpers(tsResults.outputText);
}

Expand Down
3 changes: 2 additions & 1 deletion src/dev-server/dev-client/app-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as d from '../../declarations';
import * as c from '../dev-server-constants';
import { emitBuildStatus } from './build-events';
import { logDiagnostic } from './logger';
import { hasError } from '@utils';


export function appError(win: d.DevClientWindow, doc: Document, config: d.DevClientConfig, buildResults: d.BuildResults) {
Expand All @@ -11,7 +12,7 @@ export function appError(win: d.DevClientWindow, doc: Document, config: d.DevCli

const diagnostics = buildResults.diagnostics.filter(diagnostic => diagnostic.level === 'error');

if (diagnostics.length === 0) {
if (hasError(diagnostics)) {
return;
}

Expand Down
7 changes: 4 additions & 3 deletions src/hydrate/runner/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { patchDomImplementation } from './patch-dom-implementation';
import { relocateMetaCharset } from '../../compiler/html/relocate-meta-charset';
import { removeUnusedStyles } from '../../compiler/html/remove-unused-styles';
import { updateCanonicalLink } from '../../compiler/html/canonical-link';
import { hasError } from '@utils';


export function renderToString(html: string | any, options?: SerializeDocumentOptions) {
Expand All @@ -16,7 +17,7 @@ export function renderToString(html: string | any, options?: SerializeDocumentOp

return new Promise<HydrateResults>(resolve => {
const results = generateHydrateResults(opts);
if (results.diagnostics.length > 0) {
if (hasError(results.diagnostics)) {
resolve(results);

} else if (typeof html === 'string') {
Expand Down Expand Up @@ -57,7 +58,7 @@ export function hydrateDocument(doc: any | string, options?: HydrateDocumentOpti

return new Promise<HydrateResults>(resolve => {
const results = generateHydrateResults(opts);
if (results.diagnostics.length > 0) {
if (hasError(results.diagnostics)) {
resolve(results);

} else if (typeof doc === 'string') {
Expand Down Expand Up @@ -181,7 +182,7 @@ function finalizeHydrate(win: Window, doc: Document, opts: HydrateFactoryOptions
relocateMetaCharset(doc);
} catch (e) {}

if (results.diagnostics.length === 0) {
if (!hasError(results.diagnostics)) {
results.httpStatus = 200;
}

Expand Down
4 changes: 2 additions & 2 deletions src/prerender/prerender-main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as d from '../declarations';
import { buildError, catchError } from '@utils';
import { buildError, catchError, hasError } from '@utils';
import { drainPrerenderQueue, initializePrerenderEntryUrls } from './prerender-queue';
import { generateRobotsTxt } from './robots-txt';
import { generateSitemapXml } from './sitemap-xml';
Expand Down Expand Up @@ -41,7 +41,7 @@ export async function runPrerender(prcs: NodeJS.Process, cliRootDir: string, con
}
}

if (diagnostics.length === 0) {
if (!hasError(diagnostics)) {
let workerCtrl: NodeWorkerController = null;

try {
Expand Down

0 comments on commit 29ff45e

Please sign in to comment.