awslabs / llrt

LLRT (Low Latency Runtime) is an experimental, lightweight JavaScript runtime designed to address the growing demand for fast and efficient Serverless applications.
Apache License 2.0
7.76k stars 342 forks source link

fix: [ERROR] No replacement found for "getRuntimeConfig" #282

Closed nabetti1720 closed 3 months ago

nabetti1720 commented 3 months ago

Description of changes

Detail

There is wrapper logic in build.mjs that injects AWS credentials and region parameters into runtimeConfig.shared.js in @aws-sdk.

However, we found that there are runtimeConfig.shared.js in @aws-sdk that do not follow the following rules.

@aws-sdk/client-s3/dist-es/runtimeConfig.shared.js:

// getRuntimeConfig is included in the code, so it is successfully bundled.
...
export const getRuntimeConfig = (config) => {
    return {
        apiVersion: "2006-03-01",
        base64Decoder: config?.base64Decoder ?? fromBase64,
        base64Encoder: config?.base64Encoder ?? toBase64,
        disableHostPrefix: config?.disableHostPrefix ?? false,
        endpointProvider: config?.endpointProvider ?? defaultEndpointResolver,
        extensions: config?.extensions ?? [],
        getAwsChunkedEncodingStream: config?.getAwsChunkedEncodingStream ?? getAwsChunkedEncodingStream,
        logger: config?.logger ?? new NoOpLogger(),
        sdkStreamMixin: config?.sdkStreamMixin ?? sdkStreamMixin,
        serviceId: config?.serviceId ?? "S3",
        signerConstructor: config?.signerConstructor ?? SignatureV4MultiRegion,
        signingEscapePath: config?.signingEscapePath ?? false,
        urlParser: config?.urlParser ?? parseUrl,
        useArnRegion: config?.useArnRegion ?? false,
        utf8Decoder: config?.utf8Decoder ?? fromUtf8,
        utf8Encoder: config?.utf8Encoder ?? toUtf8,
    };
};

For example, @aws-sdk/lib-storage (which I hope to bundle in the future)

@aws-sdk/lib-storage/dist-es/runtimeConfig.shared.js:

// Error during bundling because getRuntimeConfig is not included in the code.
export const ClientSharedValues = {
    lstatSync: () => { },
};

This PR allows for runtimeConfig.shared.js that do not follow the laws to be bundled as is, without making an error that the wrapper logic cannot be injected.

Checklist

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

richarddavison commented 3 months ago

Fantastic! I'll also look into adding @aws-sdk/lib-storage! For reference I also added https://github.com/awslabs/llrt/issues/283