@@ -14,14 +14,62 @@ import json from "@rollup/plugin-json";
1414
1515import nodeBuiltins from "builtin-modules" ;
1616
17+ /**
18+ * Gets the proper configuration needed for rollup's commonJS plugin for @opentelemetry/api.
19+ *
20+ * NOTE: this manual configuration is only needed because OpenTelemetry uses an
21+ * __exportStar downleveled helper function to declare its exports which confuses
22+ * rollup's automatic discovery mechanism.
23+ *
24+ * @returns an object reference that can be `...`'d into your cjs() configuration.
25+ */
26+ export function openTelemetryCommonJs ( ) {
27+ const namedExports = { } ;
28+
29+ for ( const key of [
30+ "@opentelemetry/api" ,
31+ "@azure/core-tracing/node_modules/@opentelemetry/api"
32+ ] ) {
33+ namedExports [ key ] = [
34+ "SpanKind" ,
35+ "TraceFlags" ,
36+ "getSpan" ,
37+ "setSpan" ,
38+ "SpanStatusCode" ,
39+ "getSpanContext" ,
40+ "setSpanContext"
41+ ] ;
42+ }
43+
44+ const releasedOpenTelemetryVersions = [ "0.10.2" , "1.0.0-rc.0" ] ;
45+
46+ for ( const version of releasedOpenTelemetryVersions ) {
47+ namedExports [
48+ // working around a limitation in the rollup common.js plugin - it's not able to resolve these modules so the named exports listed above will not get applied. We have to drill down to the actual path.
49+ `../../../common/temp/node_modules/.pnpm/@opentelemetry/api@${ version } /node_modules/@opentelemetry/api/build/src/index.js`
50+ ] = [
51+ "SpanKind" ,
52+ "TraceFlags" ,
53+ "getSpan" ,
54+ "setSpan" ,
55+ "StatusCode" ,
56+ "CanonicalCode" ,
57+ "getSpanContext" ,
58+ "setSpanContext"
59+ ] ;
60+ }
61+
62+ return namedExports ;
63+ }
64+
1765// #region Warning Handler
1866
1967/**
20- * A function that can determine whether a rollup warning should be ignored. If
68+ * A function that can determine whether a rollupwarning should be ignored. If
2169 * the function returns `true`, then the warning will not be displayed.
2270 */
2371
24- function ignoreNiseSinonEval ( warning ) {
72+ function ignoreNiseSinonEvalWarnings ( warning ) {
2573 return (
2674 warning . code === "EVAL" &&
2775 warning . id &&
@@ -30,14 +78,17 @@ function ignoreNiseSinonEval(warning) {
3078 ) ;
3179}
3280
33- function ignoreChaiCircularDependency ( warning ) {
81+ function ignoreChaiCircularDependencyWarnings ( warning ) {
3482 return (
3583 warning . code === "CIRCULAR_DEPENDENCY" &&
3684 warning . importer && warning . importer . includes ( "node_modules/chai" ) === true
3785 ) ;
3886}
3987
40- const warningInhibitors = [ ignoreChaiCircularDependency , ignoreNiseSinonEval ] ;
88+ const warningInhibitors = [
89+ ignoreChaiCircularDependencyWarnings ,
90+ ignoreNiseSinonEvalWarnings
91+ ] ;
4192
4293/**
4394 * Construct a warning handler for the shared rollup configuration
@@ -71,7 +122,22 @@ function makeBrowserTestConfig() {
71122 nodeResolve ( {
72123 mainFields : [ "module" , "browser" ]
73124 } ) ,
74- cjs ( ) ,
125+ cjs ( {
126+ namedExports : {
127+ // Chai's strange internal architecture makes it impossible to statically
128+ // analyze its exports.
129+ chai : [
130+ "version" ,
131+ "use" ,
132+ "util" ,
133+ "config" ,
134+ "expect" ,
135+ "should" ,
136+ "assert"
137+ ] ,
138+ ...openTelemetryCommonJs ( )
139+ }
140+ } ) ,
75141 json ( ) ,
76142 sourcemaps ( )
77143 //viz({ filename: "dist-test/browser-stats.html", sourcemap: true })
@@ -107,7 +173,7 @@ export function makeConfig(pkg, options) {
107173 ] ,
108174 output : { file : "dist/index.js" , format : "cjs" , sourcemap : true } ,
109175 preserveSymlinks : false ,
110- plugins : [ sourcemaps ( ) , nodeResolve ( ) ]
176+ plugins : [ sourcemaps ( ) , nodeResolve ( ) , cjs ( ) ]
111177 } ;
112178
113179 const config = [ baseConfig ] ;
0 commit comments