Skip to content

Commit

Permalink
feat: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
shulandmimi committed May 8, 2024
1 parent f17157f commit 94de1f2
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 17 deletions.
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"editor.tabSize": 2,
"editor.inlineSuggest.showToolbar": "always"
"editor.inlineSuggest.showToolbar": "always",
"biome.enabled": true,
"prettier.enable": false,
"editor.defaultFormatter": "biomejs.biome",
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome",
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome",
},
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/core/src/config/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
};

const CUSTOM_CONFIG_RUNTIME_ISOLATE: &str = "runtime.isolate";
pub const CUSTOM_CONFIG_EXTERNAL_RECORD: &str = "RECORD_EXTERNAL";
pub const CUSTOM_CONFIG_EXTERNAL_RECORD: &str = "external.record";

pub fn get_config_runtime_isolate(context: &Arc<CompilationContext>) -> bool {
if let Some(val) = context.config.custom.get(CUSTOM_CONFIG_RUNTIME_ISOLATE) {
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ export const DEFAULT_CONFIG_NAMES = [
];

export const FARM_DEFAULT_NAMESPACE = 'FARM_DEFAULT_NAMESPACE';

export const CUSTOM_KEYS = {
external_record: 'external.record',
runtime_isolate: 'runtime.isolate'
};
8 changes: 6 additions & 2 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ import { parseUserConfig } from './schema.js';

import { externalAdapter } from '../plugin/js/external-adapter.js';
import merge from '../utils/merge.js';
import { DEFAULT_CONFIG_NAMES, FARM_DEFAULT_NAMESPACE } from './constants.js';
import {
CUSTOM_KEYS,
DEFAULT_CONFIG_NAMES,
FARM_DEFAULT_NAMESPACE
} from './constants.js';
import { mergeConfig, mergeFarmCliConfig } from './mergeConfig.js';
import { normalizeExternal } from './normalize-config/normalize-external.js';
import type {
Expand Down Expand Up @@ -510,7 +514,7 @@ export async function normalizeUserCompilationConfig(
// setting the custom configuration
resolvedCompilation.custom = {
...(resolvedCompilation.custom || {}),
'runtime.isolate': `${!!resolvedCompilation.runtime.isolate}`
[CUSTOM_KEYS.runtime_isolate]: `${!!resolvedCompilation.runtime.isolate}`
};

// normalize persistent cache at last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import path from 'node:path';
import { Config } from '../../../binding/index.js';
import { safeJsonParse } from '../../utils/json.js';
import { isObject } from '../../utils/share.js';
import { CUSTOM_KEYS } from '../constants.js';
import type { ResolvedCompilation, UserConfig } from '../types.js';

type PartialExternal = [string[], Record<string, string>];

export const RECORD_EXTERNAL_CUSTOM_KEY = 'RECORD_EXTERNAL';
export function partialExternal(
externalConfig: (string | Record<string, string>)[] = []
): PartialExternal {
Expand Down Expand Up @@ -86,7 +86,7 @@ export function normalizeExternal(
)
);

resolvedCompilation.custom[RECORD_EXTERNAL_CUSTOM_KEY] =
resolvedCompilation.custom[CUSTOM_KEYS.external_record] =
JSON.stringify(recordExternal);

resolvedCompilation.external = [
Expand All @@ -106,9 +106,9 @@ export function mergeCustomExternal<T extends Pick<Config['config'], 'custom'>>(
}

const oldRecordExternal: Record<string, string> = compilation.custom[
RECORD_EXTERNAL_CUSTOM_KEY
CUSTOM_KEYS.external_record
]
? safeJsonParse(compilation.custom[RECORD_EXTERNAL_CUSTOM_KEY], {}) || {}
? safeJsonParse(compilation.custom[CUSTOM_KEYS.external_record], {}) || {}
: {};

return [
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/plugin/js/external-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CUSTOM_KEYS } from '../../config/constants.js';
import {
RECORD_EXTERNAL_CUSTOM_KEY,
mergeCustomExternal,
partialExternal
} from '../../config/normalize-config/normalize-external.js';
Expand Down Expand Up @@ -30,7 +30,7 @@ export function externalAdapter(): JsPlugin {
compilation: {
external: stringExternal,
custom: {
[RECORD_EXTERNAL_CUSTOM_KEY]: JSON.stringify(recordExternal)
[CUSTOM_KEYS.external_record]: JSON.stringify(recordExternal)
}
}
};
Expand Down

0 comments on commit 94de1f2

Please sign in to comment.