From 150d98448dd1a50cd316048d775803f9889fa5be Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Tue, 10 Dec 2019 14:36:53 +0100 Subject: [PATCH] fix(next): skip test files --- src/compiler_next/config/validate-config.ts | 20 ++++----- .../sys/typescript/typescript-patch.ts | 22 +++++++--- .../sys/typescript/typescript-sys.ts | 41 +++++++++++++++---- src/declarations/config.ts | 6 +++ 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/compiler_next/config/validate-config.ts b/src/compiler_next/config/validate-config.ts index 1e2bdb5052f..293cd17e28d 100644 --- a/src/compiler_next/config/validate-config.ts +++ b/src/compiler_next/config/validate-config.ts @@ -1,5 +1,5 @@ import { Config, ConfigBundle, Diagnostic } from '../../declarations'; -import { buildError, isBoolean, sortBy } from '@utils'; +import { buildError, isBoolean, sortBy, buildWarn } from '@utils'; import { validateDevServer } from './validate-dev-server'; import { validateNamespace } from './validate-namespace'; import { validateOutputTargets } from './outputs'; @@ -115,17 +115,15 @@ export const validateConfig = (userConfig?: Config) => { setBooleanConfig(config, 'generateDocs', 'docs', false); setBooleanConfig(config, 'enableCache', 'cache', true); - // if (!Array.isArray(config.includeSrc)) { - // config.includeSrc = DEFAULT_INCLUDES.map(include => { - // return config.sys.path.join(config.srcDir, include); - // }); - // } + if (config.excludeSrc) { + const warn = buildWarn(diagnostics); + warn.messageText = `"excludeSrc" is deprecated, use the "exclude" option in tsconfig.json`; + } - // if (!Array.isArray(config.excludeSrc)) { - // config.excludeSrc = DEFAULT_EXCLUDES.map(include => { - // return config.sys.path.join(config.srcDir, include); - // }); - // } + if (config.includeSrc) { + const warn = buildWarn(diagnostics); + warn.messageText = `"includeSrc" is deprecated, use the "include" option in tsconfig.json`; + } // set to true so it doesn't bother going through all this again on rebuilds // config._isValidated = true; diff --git a/src/compiler_next/sys/typescript/typescript-patch.ts b/src/compiler_next/sys/typescript/typescript-patch.ts index 7e54ed90b4b..011343518e1 100644 --- a/src/compiler_next/sys/typescript/typescript-patch.ts +++ b/src/compiler_next/sys/typescript/typescript-patch.ts @@ -54,11 +54,23 @@ const validateTsConfig = async (config: d.Config, diagnostics: d.Diagnostic[], i diagnostics.push(loadTypeScriptDiagnostic(results.error)); } else if (results.config) { - if (hasSrcDirectoryInclude(results.config.include)) { - const warn = buildWarn(diagnostics); - warn.header = `tsconfig.json "include" required`; - warn.messageText = `In order for TypeScript to improve watch performance, it's recommended the "tsconfig.json" file should have the "include" property, with at least the app's "src" directory listed. For example: "include": ["src"]`; - } + const compilerOptions = results.config.compilerOptions; + if (hasSrcDirectoryInclude(results.config.include)) { + const warn = buildWarn(diagnostics); + warn.header = `tsconfig.json "include" required`; + warn.messageText = `In order for TypeScript to improve watch performance, it's recommended the "tsconfig.json" file should have the "include" property, with at least the app's "src" directory listed. For example: "include": ["src"]`; + } + + const target = (compilerOptions.target ?? 'es5').toLowerCase(); + if (['es3', 'es5', 'es2015', 'es2016'].includes(target)) { + const warn = buildWarn(diagnostics); + warn.messageText = `To improve bundling, it is always recommended to set the tsconfig.json “target” setting to "es2017". Note that the compiler will automatically handle transpilation for ES5-only browsers.`; + } + + if (compilerOptions.module !== 'esnext' && !config._isTesting) { + const warn = buildWarn(diagnostics); + warn.messageText = `To improve bundling, it is always recommended to set the tsconfig.json “module” setting to “esnext”. Note that the compiler will automatically handle bundling both modern and legacy builds.`; + } } } catch (e) { diff --git a/src/compiler_next/sys/typescript/typescript-sys.ts b/src/compiler_next/sys/typescript/typescript-sys.ts index edee4e982c4..d8ff56550d7 100644 --- a/src/compiler_next/sys/typescript/typescript-sys.ts +++ b/src/compiler_next/sys/typescript/typescript-sys.ts @@ -32,14 +32,34 @@ const patchTsSystemFileSystem = (config: d.Config, stencilSys: d.CompilerSystem, // !p.includes('/@types/estree') // )); + const skipFile = (readPath: string) => { + // filter e2e tests + if (readPath.includes('.e2e.') || readPath.includes('/e2e.')) { + // keep this test if it's an e2e file and we should be testing e2e + return true; + } + + // filter spec tests + if (readPath.includes('.spec.') || readPath.includes('/spec.')) { + return true; + } + return false; + }; + tsSys.createDirectory = (p) => stencilSys.mkdirSync(p); tsSys.directoryExists = (p) => { + if (skipFile(p)) { + return false; + } const s = inMemoryFs.statSync(p); return s.isDirectory; }; tsSys.fileExists = (p) => { + if (skipFile(p)) { + return false; + } const s = inMemoryFs.statSync(p); return s.isFile; }; @@ -63,17 +83,19 @@ const patchTsSystemFileSystem = (config: d.Config, stencilSys: d.CompilerSystem, depth--; dirItems.forEach(dirItem => { - if (Array.isArray(extensions) && extensions.length > 0) { - if (extensions.some(ext => dirItem.endsWith(ext))) { + if (!skipFile(dirItem)) { + if (Array.isArray(extensions) && extensions.length > 0) { + if (extensions.some(ext => dirItem.endsWith(ext))) { + matchingPaths.add(dirItem); + } + } else { matchingPaths.add(dirItem); } - } else { - matchingPaths.add(dirItem); - } - const s = inMemoryFs.statSync(dirItem); - if (s && s.isDirectory) { - visitDirectory(matchingPaths, dirItem, extensions, depth); + const s = inMemoryFs.statSync(dirItem); + if (s && s.isDirectory) { + visitDirectory(matchingPaths, dirItem, extensions, depth); + } } }); }; @@ -88,6 +110,9 @@ const patchTsSystemFileSystem = (config: d.Config, stencilSys: d.CompilerSystem, }; tsSys.readFile = (p) => { + if (skipFile(p)) { + return undefined; + } let content = inMemoryFs.readFileSync(p, {useCache: false}); if (typeof content !== 'string' && (p.startsWith('https:') || p.startsWith('http:'))) { diff --git a/src/declarations/config.ts b/src/declarations/config.ts index 7419d9be757..8fd640dcacd 100644 --- a/src/declarations/config.ts +++ b/src/declarations/config.ts @@ -61,6 +61,8 @@ export interface StencilConfig { * from the build process. * * The defaults are meant to exclude possible test files that you would not want to include in your final build. + * + * @deprecated Use the "exclude" option in tsconfig.json`; */ excludeSrc?: string[]; @@ -180,6 +182,10 @@ export interface StencilConfig { */ maxConcurrentTasksPerWorker?: number; preamble?: string; + + /** + * @deprecated Use the "include" option in tsconfig.json`; + */ includeSrc?: string[]; entryComponentsHint?: string[];