11import * as d from '../../declarations' ;
2- import { COLLECTION_MANIFEST_FILE_NAME , buildJsonFileWarn , normalizePath } from '@utils' ;
2+ import { COLLECTION_MANIFEST_FILE_NAME , buildJsonFileError , normalizePath } from '@utils' ;
33import { getComponentsDtsTypesFilePath , isOutputTargetDistCollection } from '../output-targets/output-utils' ;
44
55
@@ -23,14 +23,13 @@ function validatePackageJsonOutput(config: d.Config, compilerCtx: d.CompilerCtx,
2323 validateModule ( config , compilerCtx , buildCtx , outputTarget ) ,
2424 validateCollection ( config , compilerCtx , buildCtx , outputTarget ) ,
2525 validateTypes ( config , compilerCtx , buildCtx , outputTarget ) ,
26- validateTypesExist ( config , compilerCtx , buildCtx , outputTarget ) ,
2726 validateBrowser ( compilerCtx , buildCtx )
2827 ] ) ;
2928}
3029
3130
3231export async function validatePackageFiles ( config : d . Config , compilerCtx : d . CompilerCtx , buildCtx : d . BuildCtx , outputTarget : d . OutputTargetDistCollection ) {
33- if ( Array . isArray ( buildCtx . packageJson . files ) ) {
32+ if ( ! config . devMode && Array . isArray ( buildCtx . packageJson . files ) ) {
3433 const actualDistDir = normalizePath ( config . sys . path . relative ( config . rootDir , outputTarget . dir ) ) ;
3534
3635 const validPaths = [
@@ -52,10 +51,11 @@ export async function validatePackageFiles(config: d.Config, compilerCtx: d.Comp
5251 await Promise . all ( buildCtx . packageJson . files . map ( async pkgFile => {
5352 const packageJsonDir = config . sys . path . dirname ( buildCtx . packageJsonFilePath ) ;
5453 const absPath = config . sys . path . join ( packageJsonDir , pkgFile ) ;
54+
5555 const hasAccess = await compilerCtx . fs . access ( absPath ) ;
5656 if ( ! hasAccess ) {
5757 const msg = `Unable to find "${ pkgFile } " within the package.json "files" array.` ;
58- packageJsonWarn ( compilerCtx , buildCtx , msg , `"${ pkgFile } "` ) ;
58+ packageJsonError ( compilerCtx , buildCtx , msg , `"${ pkgFile } "` ) ;
5959 }
6060 } ) ) ;
6161 }
@@ -92,7 +92,11 @@ export function validateModule(config: d.Config, compilerCtx: d.CompilerCtx, bui
9292}
9393
9494
95- export function validateTypes ( config : d . Config , compilerCtx : d . CompilerCtx , buildCtx : d . BuildCtx , outputTarget : d . OutputTargetDistCollection ) {
95+ export async function validateTypes ( config : d . Config , compilerCtx : d . CompilerCtx , buildCtx : d . BuildCtx , outputTarget : d . OutputTargetDistCollection ) {
96+ if ( config . devMode ) {
97+ return ;
98+ }
99+
96100 if ( typeof buildCtx . packageJson . types !== 'string' || buildCtx . packageJson . types === '' ) {
97101 const recommendedPath = getRecommendedTypesPath ( config , outputTarget ) ;
98102 const msg = `package.json "types" property is required when generating a distribution. It's recommended to set the "types" property to: ${ recommendedPath } ` ;
@@ -101,24 +105,18 @@ export function validateTypes(config: d.Config, compilerCtx: d.CompilerCtx, buil
101105 } else if ( ! buildCtx . packageJson . types . endsWith ( '.d.ts' ) ) {
102106 const msg = `package.json "types" file must have a ".d.ts" extension: ${ buildCtx . packageJson . types } ` ;
103107 packageJsonWarn ( compilerCtx , buildCtx , msg , `"types"` ) ;
104- }
105- }
106108
107-
108- export async function validateTypesExist ( config : d . Config , compilerCtx : d . CompilerCtx , buildCtx : d . BuildCtx , outputTarget : d . OutputTargetDistCollection ) {
109- if ( typeof buildCtx . packageJson . types !== 'string' ) {
110- return ;
111- }
112-
113- const pkgFile = config . sys . path . join ( config . rootDir , buildCtx . packageJson . types ) ;
114- const fileExists = await compilerCtx . fs . access ( pkgFile ) ;
115- if ( ! fileExists ) {
116- const recommendedPath = getRecommendedTypesPath ( config , outputTarget ) ;
117- let msg = `package.json "types" property is set to "${ buildCtx . packageJson . types } " but cannot be found.` ;
118- if ( buildCtx . packageJson . types !== recommendedPath ) {
119- msg += ` It's recommended to set the "types" property to: ${ recommendedPath } ` ;
109+ } else {
110+ const typesFile = config . sys . path . join ( config . rootDir , buildCtx . packageJson . types ) ;
111+ const typesFileExists = await compilerCtx . fs . access ( typesFile ) ;
112+ if ( ! typesFileExists ) {
113+ const recommendedPath = getRecommendedTypesPath ( config , outputTarget ) ;
114+ let msg = `package.json "types" property is set to "${ buildCtx . packageJson . types } " but cannot be found.` ;
115+ if ( buildCtx . packageJson . types !== recommendedPath ) {
116+ msg += ` It's recommended to set the "types" property to: ${ recommendedPath } ` ;
117+ }
118+ packageJsonError ( compilerCtx , buildCtx , msg , `"types"` ) ;
120119 }
121- packageJsonWarn ( compilerCtx , buildCtx , msg , `"types"` ) ;
122120 }
123121}
124122
@@ -148,8 +146,15 @@ export function getRecommendedTypesPath(config: d.Config, outputTarget: d.Output
148146}
149147
150148
149+ function packageJsonError ( compilerCtx : d . CompilerCtx , buildCtx : d . BuildCtx , msg : string , warnKey : string ) {
150+ const err = buildJsonFileError ( compilerCtx , buildCtx . diagnostics , buildCtx . packageJsonFilePath , msg , warnKey ) ;
151+ err . header = `Package Json` ;
152+ return err ;
153+ }
154+
151155function packageJsonWarn ( compilerCtx : d . CompilerCtx , buildCtx : d . BuildCtx , msg : string , warnKey : string ) {
152- const warn = buildJsonFileWarn ( compilerCtx , buildCtx . diagnostics , buildCtx . packageJsonFilePath , msg , warnKey ) ;
156+ const warn = buildJsonFileError ( compilerCtx , buildCtx . diagnostics , buildCtx . packageJsonFilePath , msg , warnKey ) ;
153157 warn . header = `Package Json` ;
158+ warn . level = 'warn' ;
154159 return warn ;
155160}
0 commit comments