Skip to content

Commit 88dece2

Browse files
committed
refactor: moves appConfigImportRegex to utils package, and resolves them in esbuild plugin
1 parent 5ea599b commit 88dece2

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

app-config-esbuild/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Plugin } from 'esbuild';
22
import path from 'path';
33
import { ConfigLoadingOptions, loadValidatedConfig } from '@app-config/config';
4-
import { generateModuleText, packageNameRegex } from '@app-config/utils';
4+
import { appConfigImportRegex, generateModuleText, packageNameRegex } from '@app-config/utils';
55
import type { SchemaLoadingOptions } from '@app-config/schema';
66

77
export interface Options {
@@ -24,6 +24,11 @@ export const createPlugin = ({
2424
namespace: '@app-config/esbuild',
2525
}));
2626

27+
build.onResolve({ filter: appConfigImportRegex }, (args) => ({
28+
path: args.path,
29+
namespace: '@app-config/esbuild',
30+
}));
31+
2732
build.onLoad({ filter: /.*/, namespace: '@app-config/esbuild' }, async () => {
2833
const { fullConfig, environment, validationFunctionCode, filePaths } =
2934
await loadValidatedConfig(loadingOptions, schemaLoadingOptions);

app-config-rollup/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Plugin } from 'rollup';
2-
import { generateModuleText, packageNameRegex } from '@app-config/utils';
2+
import { appConfigImportRegex, generateModuleText, packageNameRegex } from '@app-config/utils';
33
import { ConfigLoadingOptions, loadValidatedConfig } from '@app-config/config';
44
import type { SchemaLoadingOptions } from '@app-config/schema';
55

@@ -13,10 +13,6 @@ export interface Options {
1313
readGlobal?: boolean;
1414
}
1515

16-
// vite resolves first before passing to the rollup plugin
17-
export const appConfigImportRegex =
18-
/(app-config|app-config-main|@app-config\/main)\/dist(\/es)?\/index\.js/;
19-
2016
export default function appConfigRollup(
2117
options: Options = {},
2218
): Plugin & { currentFilePaths?: string[] } {

app-config-utils/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const isWindows = isNode && /^win/.test(process.platform);
77
export const packageNameRegex =
88
/(^@(lcdev|servall)\/app-config)|(^@app-config\/main)|(\.?app-config(\.\w+)?\.(toml|yml|yaml|json|json5))|(\.config-placeholder)/;
99

10+
export const appConfigImportRegex =
11+
/(app-config|app-config-main|@app-config\/main)\/dist(\/es)?\/index\.js/;
12+
1013
export type JsonPrimitive = number | string | boolean | null;
1114

1215
export interface JsonObject {

0 commit comments

Comments
 (0)