reconstruct and build @anthropic-ai/claude-code source from source map

- Extract 4756 source files from cli.js.map (57MB)
- Set up Bun build system with bun:bundle feature flag shim
- Configure 90+ compile-time feature flags matching production defaults
- Inject MACRO constants (VERSION, BUILD_TIME, etc.)
- Create stubs for private packages (color-diff-napi, modifiers-napi, etc.)
- Install all public dependencies via pnpm
- Patch commander v14 to allow multi-char short flags (-d2e)
- Build output: dist/cli.js (22MB), verified working
This commit is contained in:
janlaywss
2026-03-31 19:19:50 +08:00
commit 6187147b74
37865 changed files with 5438634 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertLegacyOtlpGrpcOptions = void 0;
const api_1 = require("@opentelemetry/api");
const otlp_grpc_configuration_1 = require("./otlp-grpc-configuration");
const grpc_exporter_transport_1 = require("../grpc-exporter-transport");
const otlp_grpc_env_configuration_1 = require("./otlp-grpc-env-configuration");
/**
* @deprecated
* @param config
* @param signalIdentifier
*/
function convertLegacyOtlpGrpcOptions(config, signalIdentifier) {
if (config.headers) {
api_1.diag.warn('Headers cannot be set when using grpc');
}
// keep credentials locally in case user updates the reference on the config object
const userProvidedCredentials = config.credentials;
return (0, otlp_grpc_configuration_1.mergeOtlpGrpcConfigurationWithDefaults)({
url: config.url,
metadata: () => {
// metadata resolution strategy is merge, so we can return empty here, and it will not override the rest of the settings.
return config.metadata ?? (0, grpc_exporter_transport_1.createEmptyMetadata)();
},
compression: config.compression,
timeoutMillis: config.timeoutMillis,
concurrencyLimit: config.concurrencyLimit,
credentials: userProvidedCredentials != null
? () => userProvidedCredentials
: undefined,
userAgent: config.userAgent,
}, (0, otlp_grpc_env_configuration_1.getOtlpGrpcConfigurationFromEnv)(signalIdentifier), (0, otlp_grpc_configuration_1.getOtlpGrpcDefaultConfiguration)());
}
exports.convertLegacyOtlpGrpcOptions = convertLegacyOtlpGrpcOptions;
//# sourceMappingURL=convert-legacy-otlp-grpc-options.js.map

View File

@@ -0,0 +1,89 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOtlpGrpcDefaultConfiguration = exports.mergeOtlpGrpcConfigurationWithDefaults = exports.validateAndNormalizeUrl = void 0;
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
const grpc_exporter_transport_1 = require("../grpc-exporter-transport");
const url_1 = require("url");
const api_1 = require("@opentelemetry/api");
function validateAndNormalizeUrl(url) {
url = url.trim();
const hasProtocol = url.match(/^([\w]{1,8}):\/\//);
if (!hasProtocol) {
url = `https://${url}`;
}
const target = new url_1.URL(url);
if (target.protocol === 'unix:') {
return url;
}
if (target.pathname && target.pathname !== '/') {
api_1.diag.warn('URL path should not be set when using grpc, the path part of the URL will be ignored.');
}
if (target.protocol !== '' && !target.protocol?.match(/^(http)s?:$/)) {
api_1.diag.warn('URL protocol should be http(s)://. Using http://.');
}
return target.host;
}
exports.validateAndNormalizeUrl = validateAndNormalizeUrl;
function overrideMetadataEntriesIfNotPresent(metadata, additionalMetadata) {
for (const [key, value] of Object.entries(additionalMetadata.getMap())) {
// only override with env var data if the key has no values.
// not using Metadata.merge() as it will keep both values.
if (metadata.get(key).length < 1) {
metadata.set(key, value);
}
}
}
function mergeOtlpGrpcConfigurationWithDefaults(userProvidedConfiguration, fallbackConfiguration, defaultConfiguration) {
const rawUrl = userProvidedConfiguration.url ??
fallbackConfiguration.url ??
defaultConfiguration.url;
return {
...(0, otlp_exporter_base_1.mergeOtlpSharedConfigurationWithDefaults)(userProvidedConfiguration, fallbackConfiguration, defaultConfiguration),
metadata: () => {
const metadata = defaultConfiguration.metadata();
overrideMetadataEntriesIfNotPresent(metadata,
// clone to ensure we don't modify what the user gave us in case they hold on to the returned reference
userProvidedConfiguration.metadata?.().clone() ?? (0, grpc_exporter_transport_1.createEmptyMetadata)());
overrideMetadataEntriesIfNotPresent(metadata, fallbackConfiguration.metadata?.() ?? (0, grpc_exporter_transport_1.createEmptyMetadata)());
return metadata;
},
url: validateAndNormalizeUrl(rawUrl),
credentials: userProvidedConfiguration.credentials ??
fallbackConfiguration.credentials?.(rawUrl) ??
defaultConfiguration.credentials(rawUrl),
userAgent: userProvidedConfiguration.userAgent,
};
}
exports.mergeOtlpGrpcConfigurationWithDefaults = mergeOtlpGrpcConfigurationWithDefaults;
function getOtlpGrpcDefaultConfiguration() {
return {
...(0, otlp_exporter_base_1.getSharedConfigurationDefaults)(),
metadata: () => (0, grpc_exporter_transport_1.createEmptyMetadata)(),
url: 'http://localhost:4317',
credentials: (url) => {
if (url.startsWith('http://')) {
return () => (0, grpc_exporter_transport_1.createInsecureCredentials)();
}
else {
return () => (0, grpc_exporter_transport_1.createSslCredentials)();
}
},
};
}
exports.getOtlpGrpcDefaultConfiguration = getOtlpGrpcDefaultConfiguration;
//# sourceMappingURL=otlp-grpc-configuration.js.map

View File

@@ -0,0 +1,159 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOtlpGrpcConfigurationFromEnv = void 0;
const core_1 = require("@opentelemetry/core");
const grpc_exporter_transport_1 = require("../grpc-exporter-transport");
const node_http_1 = require("@opentelemetry/otlp-exporter-base/node-http");
const fs = require("fs");
const path = require("path");
const api_1 = require("@opentelemetry/api");
function fallbackIfNullishOrBlank(signalSpecific, nonSignalSpecific) {
if (signalSpecific != null && signalSpecific !== '') {
return signalSpecific;
}
if (nonSignalSpecific != null && nonSignalSpecific !== '') {
return nonSignalSpecific;
}
return undefined;
}
function getMetadataFromEnv(signalIdentifier) {
const signalSpecificRawHeaders = process.env[`OTEL_EXPORTER_OTLP_${signalIdentifier}_HEADERS`]?.trim();
const nonSignalSpecificRawHeaders = process.env['OTEL_EXPORTER_OTLP_HEADERS']?.trim();
const signalSpecificHeaders = (0, core_1.parseKeyPairsIntoRecord)(signalSpecificRawHeaders);
const nonSignalSpecificHeaders = (0, core_1.parseKeyPairsIntoRecord)(nonSignalSpecificRawHeaders);
if (Object.keys(signalSpecificHeaders).length === 0 &&
Object.keys(nonSignalSpecificHeaders).length === 0) {
return undefined;
}
const mergeHeaders = Object.assign({}, nonSignalSpecificHeaders, signalSpecificHeaders);
const metadata = (0, grpc_exporter_transport_1.createEmptyMetadata)();
// for this to work, metadata MUST be empty - otherwise `Metadata#set()` will merge items.
for (const [key, value] of Object.entries(mergeHeaders)) {
metadata.set(key, value);
}
return metadata;
}
function getMetadataProviderFromEnv(signalIdentifier) {
const metadata = getMetadataFromEnv(signalIdentifier);
if (metadata == null) {
return undefined;
}
return () => metadata;
}
function getUrlFromEnv(signalIdentifier) {
// This does not change the string beyond trimming on purpose.
// Normally a user would just use a host and port for gRPC, but the OTLP Exporter specification requires us to
// use the raw provided endpoint to derive credential settings. Therefore, we only normalize right when
// we merge user-provided, env-provided and defaults together, and we have determined which credentials to use.
//
// Examples:
// - example.test:4317 -> use secure credentials from environment (or provided via code)
// - http://example.test:4317 -> use insecure credentials if nothing else is provided
// - https://example.test:4317 -> use secure credentials from environment (or provided via code)
const specificEndpoint = process.env[`OTEL_EXPORTER_OTLP_${signalIdentifier}_ENDPOINT`]?.trim();
const nonSpecificEndpoint = process.env[`OTEL_EXPORTER_OTLP_ENDPOINT`]?.trim();
return fallbackIfNullishOrBlank(specificEndpoint, nonSpecificEndpoint);
}
/**
* Determines whether the env var for insecure credentials is set to {@code true}.
*
* It will allow the following values as {@code true}
* - 'true'
* - 'true '
* - ' true'
* - 'TrUE'
* - 'TRUE'
*
* It will not allow:
* - 'true false'
* - 'false true'
* - 'true!'
* - 'true,true'
* - '1'
* - ' '
*
* @param signalIdentifier
*/
function getInsecureSettingFromEnv(signalIdentifier) {
const signalSpecificInsecureValue = process.env[`OTEL_EXPORTER_OTLP_${signalIdentifier}_INSECURE`]
?.toLowerCase()
.trim();
const nonSignalSpecificInsecureValue = process.env[`OTEL_EXPORTER_OTLP_INSECURE`]
?.toLowerCase()
.trim();
return (fallbackIfNullishOrBlank(signalSpecificInsecureValue, nonSignalSpecificInsecureValue) === 'true');
}
function readFileFromEnv(signalSpecificEnvVar, nonSignalSpecificEnvVar, warningMessage) {
const signalSpecificPath = process.env[signalSpecificEnvVar]?.trim();
const nonSignalSpecificPath = process.env[nonSignalSpecificEnvVar]?.trim();
const filePath = fallbackIfNullishOrBlank(signalSpecificPath, nonSignalSpecificPath);
if (filePath != null) {
try {
return fs.readFileSync(path.resolve(process.cwd(), filePath));
}
catch {
api_1.diag.warn(warningMessage);
return undefined;
}
}
else {
return undefined;
}
}
function getClientCertificateFromEnv(signalIdentifier) {
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CLIENT_CERTIFICATE`, 'OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE', 'Failed to read client certificate chain file');
}
function getClientKeyFromEnv(signalIdentifier) {
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CLIENT_KEY`, 'OTEL_EXPORTER_OTLP_CLIENT_KEY', 'Failed to read client certificate private key file');
}
function getRootCertificateFromEnv(signalIdentifier) {
return readFileFromEnv(`OTEL_EXPORTER_OTLP_${signalIdentifier}_CERTIFICATE`, 'OTEL_EXPORTER_OTLP_CERTIFICATE', 'Failed to read root certificate file');
}
function getCredentialsFromEnvIgnoreInsecure(signalIdentifier) {
const clientKey = getClientKeyFromEnv(signalIdentifier);
const clientCertificate = getClientCertificateFromEnv(signalIdentifier);
const rootCertificate = getRootCertificateFromEnv(signalIdentifier);
// if the chain is not intact, @grpc/grpc-js will throw. This is fine when a user provides it in code, but env var
// config is not allowed to throw, so we add this safeguard and try to make the best of it here.
const clientChainIntact = clientKey != null && clientCertificate != null;
if (rootCertificate != null && !clientChainIntact) {
api_1.diag.warn('Client key and certificate must both be provided, but one was missing - attempting to create credentials from just the root certificate');
return (0, grpc_exporter_transport_1.createSslCredentials)(getRootCertificateFromEnv(signalIdentifier));
}
return (0, grpc_exporter_transport_1.createSslCredentials)(rootCertificate, clientKey, clientCertificate);
}
function getCredentialsFromEnv(signalIdentifier) {
if (getInsecureSettingFromEnv(signalIdentifier)) {
return (0, grpc_exporter_transport_1.createInsecureCredentials)();
}
return getCredentialsFromEnvIgnoreInsecure(signalIdentifier);
}
function getOtlpGrpcConfigurationFromEnv(signalIdentifier) {
return {
...(0, node_http_1.getSharedConfigurationFromEnvironment)(signalIdentifier),
metadata: getMetadataProviderFromEnv(signalIdentifier),
url: getUrlFromEnv(signalIdentifier),
credentials: (finalResolvedUrl) => {
// Always assume insecure on http:// and secure on https://, the protocol always takes precedence over the insecure setting.
// note: the spec does not make any exception for
// - "localhost:4317". If the protocol is omitted, credentials are required unless insecure is set
// - "unix://", as it's neither http:// nor https:// and therefore credentials are required unless insecure is set
if (finalResolvedUrl.startsWith('http://')) {
return () => {
return (0, grpc_exporter_transport_1.createInsecureCredentials)();
};
}
else if (finalResolvedUrl.startsWith('https://')) {
return () => {
return getCredentialsFromEnvIgnoreInsecure(signalIdentifier);
};
}
// defer to env settings in this case
return () => {
return getCredentialsFromEnv(signalIdentifier);
};
},
};
}
exports.getOtlpGrpcConfigurationFromEnv = getOtlpGrpcConfigurationFromEnv;
//# sourceMappingURL=otlp-grpc-env-configuration.js.map

View File

@@ -0,0 +1,50 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createServiceClientConstructor = void 0;
const grpc = require("@grpc/grpc-js");
/**
* Creates a unary service client constructor that, when instantiated, does not serialize/deserialize anything.
* Allows for passing in {@link Buffer} directly, serialization can be handled via protobufjs or custom implementations.
*
* @param path service path
* @param name service name
*/
function createServiceClientConstructor(path, name) {
const serviceDefinition = {
export: {
path: path,
requestStream: false,
responseStream: false,
requestSerialize: (arg) => {
return arg;
},
requestDeserialize: (arg) => {
return arg;
},
responseSerialize: (arg) => {
return arg;
},
responseDeserialize: (arg) => {
return arg;
},
},
};
return grpc.makeGenericClientConstructor(serviceDefinition, name);
}
exports.createServiceClientConstructor = createServiceClientConstructor;
//# sourceMappingURL=create-service-client-constructor.js.map

View File

@@ -0,0 +1,131 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createOtlpGrpcExporterTransport = exports.GrpcExporterTransport = exports.createEmptyMetadata = exports.createSslCredentials = exports.createInsecureCredentials = void 0;
const version_1 = require("./version");
const DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${version_1.VERSION}`;
function createUserAgent(userAgent) {
if (userAgent) {
return `${userAgent} ${DEFAULT_USER_AGENT}`;
}
return DEFAULT_USER_AGENT;
}
// values taken from '@grpc/grpc-js` so that we don't need to require/import it.
const GRPC_COMPRESSION_NONE = 0;
const GRPC_COMPRESSION_GZIP = 2;
function toGrpcCompression(compression) {
return compression === 'gzip' ? GRPC_COMPRESSION_GZIP : GRPC_COMPRESSION_NONE;
}
function createInsecureCredentials() {
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const { credentials,
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('@grpc/grpc-js');
return credentials.createInsecure();
}
exports.createInsecureCredentials = createInsecureCredentials;
function createSslCredentials(rootCert, privateKey, certChain) {
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const { credentials,
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('@grpc/grpc-js');
return credentials.createSsl(rootCert, privateKey, certChain);
}
exports.createSslCredentials = createSslCredentials;
function createEmptyMetadata() {
// Lazy-load so that we don't need to require/import '@grpc/grpc-js' before it can be wrapped by instrumentation.
const { Metadata,
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('@grpc/grpc-js');
return new Metadata();
}
exports.createEmptyMetadata = createEmptyMetadata;
class GrpcExporterTransport {
_parameters;
_client;
_metadata;
constructor(_parameters) {
this._parameters = _parameters;
}
shutdown() {
this._client?.close();
}
send(data, timeoutMillis) {
// We need to make a for gRPC
const buffer = Buffer.from(data);
if (this._client == null) {
// Lazy require to ensure that grpc is not loaded before instrumentations can wrap it
const { createServiceClientConstructor,
// eslint-disable-next-line @typescript-eslint/no-require-imports
} = require('./create-service-client-constructor');
try {
this._metadata = this._parameters.metadata();
}
catch (error) {
return Promise.resolve({
status: 'failure',
error: error,
});
}
const clientConstructor = createServiceClientConstructor(this._parameters.grpcPath, this._parameters.grpcName);
try {
this._client = new clientConstructor(this._parameters.address, this._parameters.credentials(), {
'grpc.default_compression_algorithm': toGrpcCompression(this._parameters.compression),
'grpc.primary_user_agent': createUserAgent(this._parameters.userAgent),
});
}
catch (error) {
return Promise.resolve({
status: 'failure',
error: error,
});
}
}
return new Promise(resolve => {
const deadline = Date.now() + timeoutMillis;
// this should never happen
if (this._metadata == null) {
return resolve({
error: new Error('metadata was null'),
status: 'failure',
});
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore The gRPC client constructor is created on runtime, so we don't have any types for the resulting client.
this._client.export(buffer, this._metadata, { deadline: deadline }, (err, response) => {
if (err) {
resolve({
status: 'failure',
error: err,
});
}
else {
resolve({
data: response,
status: 'success',
});
}
});
});
}
}
exports.GrpcExporterTransport = GrpcExporterTransport;
function createOtlpGrpcExporterTransport(options) {
return new GrpcExporterTransport(options);
}
exports.createOtlpGrpcExporterTransport = createOtlpGrpcExporterTransport;
//# sourceMappingURL=grpc-exporter-transport.js.map

View File

@@ -0,0 +1,23 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createOtlpGrpcExportDelegate = exports.convertLegacyOtlpGrpcOptions = void 0;
var convert_legacy_otlp_grpc_options_1 = require("./configuration/convert-legacy-otlp-grpc-options");
Object.defineProperty(exports, "convertLegacyOtlpGrpcOptions", { enumerable: true, get: function () { return convert_legacy_otlp_grpc_options_1.convertLegacyOtlpGrpcOptions; } });
var otlp_grpc_export_delegate_1 = require("./otlp-grpc-export-delegate");
Object.defineProperty(exports, "createOtlpGrpcExportDelegate", { enumerable: true, get: function () { return otlp_grpc_export_delegate_1.createOtlpGrpcExportDelegate; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1,33 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createOtlpGrpcExportDelegate = void 0;
const otlp_exporter_base_1 = require("@opentelemetry/otlp-exporter-base");
const grpc_exporter_transport_1 = require("./grpc-exporter-transport");
function createOtlpGrpcExportDelegate(options, serializer, grpcName, grpcPath) {
return (0, otlp_exporter_base_1.createOtlpNetworkExportDelegate)(options, serializer, (0, grpc_exporter_transport_1.createOtlpGrpcExporterTransport)({
address: options.url,
compression: options.compression,
credentials: options.credentials,
metadata: options.metadata,
userAgent: options.userAgent,
grpcName,
grpcPath,
}));
}
exports.createOtlpGrpcExportDelegate = createOtlpGrpcExportDelegate;
//# sourceMappingURL=otlp-grpc-export-delegate.js.map

View File

@@ -0,0 +1,21 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.208.0';
//# sourceMappingURL=version.js.map