Skip to content

Commit 4b73bc2

Browse files
authored
fix: improve RuntimeGlobals type definition accuracy (#12403)
* fix: improve RuntimeGlobals type definition accuracy * fix: remove unnecessary string template syntax in RuntimeGlobals usage
1 parent 182b694 commit 4b73bc2

File tree

3 files changed

+6
-92
lines changed

3 files changed

+6
-92
lines changed

packages/rspack/etc/core.api.md

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -7115,93 +7115,7 @@ const RuntimeChunkPlugin: {
71157115
};
71167116

71177117
// @public (undocumented)
7118-
export const RuntimeGlobals: typeof RuntimeGlobals_2;
7119-
7120-
// @public (undocumented)
7121-
enum RuntimeGlobals_2 {
7122-
amdDefine = 65,
7123-
amdOptions = 66,
7124-
asyncModule = 72,
7125-
// (undocumented)
7126-
asyncModuleExportSymbol = 73,
7127-
baseURI = 70,
7128-
chunkCallback = 49,
7129-
chunkName = 36,
7130-
compatGetDefaultExport = 23,
7131-
createFakeNamespaceObject = 22,
7132-
createScript = 32,
7133-
createScriptUrl = 33,
7134-
currentRemoteGetScope = 58,
7135-
definePropertyGetters = 20,
7136-
ensureChunk = 13,
7137-
ensureChunkHandlers = 14,
7138-
ensureChunkIncludeEntries = 15,
7139-
entryModuleId = 9,
7140-
exports = 2,
7141-
externalInstallChunk = 53,
7142-
getChunkCssFilename = 39,
7143-
getChunkScriptFilename = 38,
7144-
getChunkUpdateCssFilename = 44,
7145-
getChunkUpdateScriptFilename = 43,
7146-
getFullHash = 26,
7147-
getTrustedTypesPolicy = 34,
7148-
getUpdateManifestFilename = 59,
7149-
global = 55,
7150-
harmonyModuleDecorator = 24,
7151-
hasCssModules = 41,
7152-
hasFetchPriority = 35,
7153-
hasOwnProperty = 68,
7154-
hmrDownloadManifest = 60,
7155-
hmrDownloadUpdateHandlers = 61,
7156-
hmrInvalidateModuleHandlers = 63,
7157-
hmrModuleData = 62,
7158-
hmrRuntimeStatePrefix = 64,
7159-
initializeSharing = 57,
7160-
instantiateWasm = 28,
7161-
interceptModuleExecution = 54,
7162-
loadScript = 31,
7163-
// (undocumented)
7164-
makeDeferredNamespaceObject = 74,
7165-
// (undocumented)
7166-
makeDeferredNamespaceObjectSymbol = 75,
7167-
makeNamespaceObject = 21,
7168-
module = 5,
7169-
moduleCache = 10,
7170-
moduleFactories = 11,
7171-
moduleFactoriesAddOnly = 12,
7172-
moduleId = 6,
7173-
moduleLoaded = 7,
7174-
nodeModuleDecorator = 25,
7175-
onChunksLoaded = 52,
7176-
prefetchChunk = 16,
7177-
prefetchChunkHandlers = 17,
7178-
preloadChunk = 18,
7179-
preloadChunkHandlers = 19,
7180-
publicPath = 8,
7181-
relativeUrl = 71,
7182-
require = 0,
7183-
requireScope = 1,
7184-
returnExportsFromRuntime = 4,
7185-
// @internal
7186-
rspackUniqueId = 42,
7187-
// @internal
7188-
rspackVersion = 40,
7189-
runtimeId = 37,
7190-
scriptNonce = 30,
7191-
shareScopeMap = 56,
7192-
startup = 45,
7193-
startupChunkDependencies = 51,
7194-
startupEntrypoint = 50,
7195-
// @deprecated (undocumented)
7196-
startupNoDefault = 46,
7197-
startupOnlyAfter = 47,
7198-
startupOnlyBefore = 48,
7199-
system = 67,
7200-
systemContext = 69,
7201-
thisAsExports = 3,
7202-
uncaughtErrorHandler = 29,
7203-
wasmInstances = 27
7204-
}
7118+
export const RuntimeGlobals: Record<"publicPath" | "chunkName" | "moduleId" | "module" | "exports" | "require" | "global" | "system" | "requireScope" | "thisAsExports" | "returnExportsFromRuntime" | "moduleLoaded" | "entryModuleId" | "moduleCache" | "moduleFactories" | "moduleFactoriesAddOnly" | "ensureChunk" | "ensureChunkHandlers" | "ensureChunkIncludeEntries" | "prefetchChunk" | "prefetchChunkHandlers" | "preloadChunk" | "preloadChunkHandlers" | "definePropertyGetters" | "makeNamespaceObject" | "createFakeNamespaceObject" | "compatGetDefaultExport" | "harmonyModuleDecorator" | "nodeModuleDecorator" | "getFullHash" | "wasmInstances" | "instantiateWasm" | "uncaughtErrorHandler" | "scriptNonce" | "loadScript" | "createScript" | "createScriptUrl" | "getTrustedTypesPolicy" | "hasFetchPriority" | "runtimeId" | "getChunkScriptFilename" | "getChunkCssFilename" | "rspackVersion" | "hasCssModules" | "rspackUniqueId" | "getChunkUpdateScriptFilename" | "getChunkUpdateCssFilename" | "startup" | "startupNoDefault" | "startupOnlyAfter" | "startupOnlyBefore" | "chunkCallback" | "startupEntrypoint" | "startupChunkDependencies" | "onChunksLoaded" | "externalInstallChunk" | "interceptModuleExecution" | "shareScopeMap" | "initializeSharing" | "currentRemoteGetScope" | "getUpdateManifestFilename" | "hmrDownloadManifest" | "hmrDownloadUpdateHandlers" | "hmrModuleData" | "hmrInvalidateModuleHandlers" | "hmrRuntimeStatePrefix" | "amdDefine" | "amdOptions" | "hasOwnProperty" | "systemContext" | "baseURI" | "relativeUrl" | "asyncModule" | "asyncModuleExportSymbol" | "makeDeferredNamespaceObject" | "makeDeferredNamespaceObjectSymbol", string>;
72057119

72067120
// @public (undocumented)
72077121
export class RuntimeModule {

packages/rspack/src/RuntimeGlobals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,15 +668,15 @@ function renderRuntimeGlobals(
668668

669669
export function createCompilerRuntimeGlobals(
670670
compilerOptions?: RspackOptionsNormalized
671-
): typeof RuntimeGlobals {
671+
): Record<keyof typeof RuntimeGlobals, string> {
672672
const res: Record<string, string> = {};
673673
for (const key of Object.keys(RuntimeGlobals)) {
674674
res[key] = renderRuntimeGlobals(
675675
RuntimeGlobals[key as keyof typeof RuntimeGlobals],
676676
compilerOptions
677677
);
678678
}
679-
return res as unknown as typeof RuntimeGlobals;
679+
return res as unknown as Record<keyof typeof RuntimeGlobals, string>;
680680
}
681681

682682
const DefaultRuntimeGlobals = createCompilerRuntimeGlobals();

packages/rspack/src/taps/compilation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export const createCompilationHooksRegisters: CreatePartialRegisters<
234234
codeGenerationResult: new CodeGenerationResult(result),
235235
moduleObject
236236
},
237-
{ [`${RuntimeGlobals.require}`]: moduleRequireFn }
237+
{ [RuntimeGlobals.require]: moduleRequireFn }
238238
),
239239
"Compilation.hooks.executeModule"
240240
);
@@ -243,14 +243,14 @@ export const createCompilationHooksRegisters: CreatePartialRegisters<
243243
};
244244

245245
const moduleCache: Record<string, any> = (moduleRequireFn[
246-
`${RuntimeGlobals.moduleCache}`.replace(
246+
RuntimeGlobals.moduleCache.replace(
247247
`${RuntimeGlobals.require}.`,
248248
""
249249
)
250250
] = {});
251251
const interceptModuleExecution: ((execOptions: any) => void)[] =
252252
(moduleRequireFn[
253-
`${RuntimeGlobals.interceptModuleExecution}`.replace(
253+
RuntimeGlobals.interceptModuleExecution.replace(
254254
`${RuntimeGlobals.require}.`,
255255
""
256256
)

0 commit comments

Comments
 (0)