@@ -2,20 +2,22 @@ import type { Plugin } from 'esbuild';
22import path from 'path' ;
33import { ConfigLoadingOptions , loadValidatedConfig } from '@app-config/config' ;
44import { generateModuleText , packageNameRegex } from '@app-config/utils' ;
5- import type { SchemaLoadingOptions } from '@app-config/schema' ;
5+ import { loadSchema , SchemaLoadingOptions } from '@app-config/schema' ;
66
77export interface Options {
88 useGlobalNamespace ?: boolean ;
99 loadingOptions ?: ConfigLoadingOptions ;
1010 schemaLoadingOptions ?: SchemaLoadingOptions ;
1111 injectValidationFunction ?: boolean ;
12+ doNotLoadConfig ?: boolean ;
1213}
1314
1415export const createPlugin = ( {
1516 useGlobalNamespace = true ,
1617 loadingOptions,
1718 schemaLoadingOptions,
1819 injectValidationFunction = true ,
20+ doNotLoadConfig = false ,
1921} : Options = { } ) : Plugin => ( {
2022 name : '@app-config/esbuild' ,
2123 setup ( build ) {
@@ -25,6 +27,24 @@ export const createPlugin = ({
2527 } ) ) ;
2628
2729 build . onLoad ( { filter : / .* / , namespace : '@app-config/esbuild' } , async ( ) => {
30+ if ( doNotLoadConfig ) {
31+ const { validationFunctionCode } = await loadSchema ( schemaLoadingOptions ) ;
32+
33+ const code = generateModuleText ( 'no-config' , {
34+ environment : undefined ,
35+ useGlobalNamespace : true ,
36+ validationFunctionCode : injectValidationFunction ? validationFunctionCode : undefined ,
37+ esmValidationCode : true ,
38+ } ) ;
39+
40+ return {
41+ loader : 'js' ,
42+ contents : code ,
43+ resolveDir : path . parse ( process . cwd ( ) ) . root ,
44+ watchFiles : [ ] ,
45+ } ;
46+ }
47+
2848 const { fullConfig, environment, validationFunctionCode, filePaths } =
2949 await loadValidatedConfig ( loadingOptions , schemaLoadingOptions ) ;
3050
0 commit comments