Skip to content

Commit

Permalink
refactor(compiler): remove requireFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduy1407 committed Dec 1, 2023
1 parent d0db3a7 commit 43b765f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/compiler/config/transpile-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
TranspileResults,
} from '../../declarations';
import { RINDO_INTERNAL_CLIENT_ID } from '../bundle/entry-alias-ids';
import { requireFunc } from '../sys/environment';
import { parseImportPath } from '../transformers/rindo-import-path';

export const getTranspileResults = (code: string, input: TranspileOptions) => {
Expand Down Expand Up @@ -59,7 +58,7 @@ export const getTranspileConfig = (input: TranspileOptions): TranspileConfig =>
if (input.sys) {
transpileCtx.sys = input.sys;
} else if (!transpileCtx.sys) {
transpileCtx.sys = requireFunc('../sys/node/index.js').createNodeSys();
transpileCtx.sys = require('../sys/node/index.js').createNodeSys();
}

const compileOpts: TranspileOptions = {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/optimize/autoprefixer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Postcss } from 'postcss';

import type * as d from '../../declarations';
import { IS_NODE_ENV, requireFunc } from '../sys/environment';
import { IS_NODE_ENV } from '../sys/environment';

type CssProcessor = ReturnType<Postcss>;
let cssProcessor: CssProcessor;
Expand Down Expand Up @@ -102,7 +102,7 @@ export const autoprefixCss = async (cssText: string, opts: boolean | null | d.Au
* @returns postCSS with the Autoprefixer plugin applied
*/
const getProcessor = (autoprefixerOpts: d.AutoprefixerOptions): CssProcessor => {
const { postcss, autoprefixer } = requireFunc('../sys/node/autoprefixer.js');
const { postcss, autoprefixer } = require('../sys/node/autoprefixer.js');
if (!cssProcessor) {
cssProcessor = postcss([autoprefixer(autoprefixerOpts)]);
}
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/prerender/prerender-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { catchError, isFunction, isPromise, isRootPath, normalizePath } from '@u
import { dirname, join } from 'path';

import type * as d from '../../declarations';
import { requireFunc } from '../sys/environment';
import { crawlAnchorsForNextUrls } from './crawl-urls';
import { getPrerenderConfig } from './prerender-config';
import { getHydrateOptions } from './prerender-hydrate-options';
Expand Down Expand Up @@ -33,7 +32,7 @@ export const prerenderWorker = async (sys: d.CompilerSystem, prerenderRequest: d
const componentGraph = getComponentGraph(sys, prerenderCtx, prerenderRequest.componentGraphPath);

// webpack work-around/hack
const hydrateApp = requireFunc(prerenderRequest.hydrateAppFilePath);
const hydrateApp = require(prerenderRequest.hydrateAppFilePath);

if (prerenderCtx.templateHtml == null) {
// cache template html in this process
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/sys/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ export const IS_WEB_WORKER_ENV =
export const HAS_WEB_WORKER = IS_BROWSER_ENV && typeof Worker === 'function';

export const IS_FETCH_ENV = typeof fetch === 'function';

export const requireFunc = IS_NODE_ENV ? require : () => {};

0 comments on commit 43b765f

Please sign in to comment.