-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathbuild-and-test-otel-api.js
More file actions
71 lines (64 loc) · 1.91 KB
/
Copy pathbuild-and-test-otel-api.js
File metadata and controls
71 lines (64 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env node
'use strict'
const path = require('node:path')
const webpack = require('webpack')
const {
EXTERNALS,
runOtelApiBundleScenario,
} = require('../helpers/otel-api-bundle')
const DatadogWebpackPlugin = require('../../webpack')
/**
* @param {{ entry: string, outfile: string, workingDirectory: string }} paths
* @param {boolean} outputModule
* @returns {Promise<void>}
*/
function build (paths, outputModule) {
return new Promise((resolve, reject) => {
const externalType = outputModule ? 'node-commonjs' : 'commonjs'
const externals = {
'@opentelemetry/api': `${externalType} @opentelemetry/api`,
'@opentelemetry/api-logs': `${externalType} @opentelemetry/api-logs`,
}
for (const name of EXTERNALS) {
externals[name] = `${externalType} ${name}`
}
webpack({
context: paths.workingDirectory,
devtool: false,
entry: paths.entry,
experiments: { outputModule },
externals,
externalsType: outputModule ? 'module' : 'commonjs',
mode: 'development',
optimization: { minimize: false },
output: {
filename: path.basename(paths.outfile),
hashFunction: 'sha256',
module: outputModule,
path: path.dirname(paths.outfile),
},
plugins: [new DatadogWebpackPlugin()],
target: 'node18',
}, (error, stats) => {
if (error) return reject(error)
if (stats.hasErrors()) return reject(new Error(stats.toString({ errors: true })))
resolve()
})
})
}
async function main () {
for (const [outputModule, extension] of [[false, 'js'], [true, 'mjs']]) {
for (const applicationOwnsApi of [false, true]) {
await runOtelApiBundleScenario({
applicationOwnsApi,
build: paths => build(paths, outputModule),
extension,
})
}
}
}
main().catch((error) => {
// eslint-disable-next-line no-console
console.error(error)
process.exitCode = 1
})