Skip to content

Commit

Permalink
fix: check different node environment (#1947)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost authored Nov 20, 2024
1 parent 3770a12 commit 3085d64
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-humans-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farmfe/core": patch
---

judgement node environment with check input value
6 changes: 4 additions & 2 deletions packages/core/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
green,
isArray,
isEmptyObject,
isNodeEnv,
isObject,
isWindows,
normalizeBasePath,
Expand Down Expand Up @@ -669,7 +670,8 @@ const formatFromExt: Record<string, Format> = {
cjs: 'cjs',
mjs: 'esm',
cts: 'cjs',
mts: 'esm'
mts: 'esm',
js: 'esm'
};

const formatToExt: Record<Format, string> = {
Expand Down Expand Up @@ -948,7 +950,7 @@ export async function loadConfigFile(
function checkCompilationInputValue(userConfig: UserConfig, logger: Logger) {
const { compilation } = userConfig;
const targetEnv = compilation?.output?.targetEnv;
const isTargetNode = targetEnv === 'node';
const isTargetNode = isNodeEnv(targetEnv);
const defaultHtmlPath = './index.html';
let inputIndexConfig: { index?: string } = { index: '' };
let errorMessage = '';
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/utils/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import os from 'node:os';
import path, { dirname } from 'node:path';
import readline from 'node:readline';
import { fileURLToPath } from 'node:url';
import { Config } from '../types/binding.js';
import { Config, OutputConfig } from '../types/binding.js';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore import packageJson from '../../package.json';

Expand Down Expand Up @@ -177,3 +177,7 @@ export function tryStatSync(file: string): fs.Stats | undefined {
return fs.statSync(file, { throwIfNoEntry: false });
} catch {}
}

export function isNodeEnv(env: OutputConfig['targetEnv']): boolean {
return /^(node|library)(?!-browser)/.test(env);
}

0 comments on commit 3085d64

Please sign in to comment.