Skip to content

Commit 3104016

Browse files
committed
fix(cli-with-sentry): add missing esbuild config for shadow-npm-inject
- Copy esbuild.inject.config.mjs from cli package to cli-with-sentry - Copy esbuild-inject-import-meta.mjs polyfill - Update paths to reference cli package source (no src/ in cli-with-sentry) - Output to cli-with-sentry/dist/shadow-npm-inject.js Fixes provenance workflow failure where shadow-npm-inject.js was missing from the cli-with-sentry package distribution. The cli-with-sentry package builds from the cli package's source files but outputs to its own dist/ directory with Sentry telemetry enabled.
1 parent b8f5f0b commit 3104016

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Polyfill for import.meta.url in CommonJS bundles.
3+
* This file is injected by esbuild's inject option.
4+
*/
5+
6+
// Convert __filename to file:// URL format.
7+
export const __importMetaUrl =
8+
typeof __filename !== 'undefined'
9+
? `file://${__filename.replace(/\\/g, '/')}`
10+
: 'file:///unknown'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* esbuild configuration for building shadow npm inject script.
3+
*
4+
* This builds the inject script that is loaded via --require flag
5+
* when spawning npm with shadow arborist.
6+
*/
7+
8+
import { writeFileSync } from 'node:fs'
9+
import path from 'node:path'
10+
import { fileURLToPath } from 'node:url'
11+
12+
import { build } from 'esbuild'
13+
14+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
15+
const rootPath = path.join(__dirname, '..')
16+
const cliPath = path.join(__dirname, '..', '..', 'cli')
17+
18+
const config = {
19+
entryPoints: [path.join(cliPath, 'src/shadow/npm/inject.mts')],
20+
bundle: true,
21+
outfile: path.join(rootPath, 'dist/shadow-npm-inject.js'),
22+
// Target Node.js environment (not browser).
23+
platform: 'node',
24+
// Target Node.js 18+ features.
25+
target: 'node18',
26+
format: 'cjs',
27+
28+
// With platform: 'node', esbuild automatically externalizes all Node.js built-ins.
29+
external: [
30+
'node-gyp', // Required for require.resolve('node-gyp/package.json')
31+
],
32+
33+
// Suppress warnings for intentional CommonJS compatibility code.
34+
logOverride: {
35+
'commonjs-variable-in-esm': 'silent',
36+
'empty-import-meta': 'silent',
37+
'require-resolve-not-external': 'silent',
38+
},
39+
40+
// Source maps off for production.
41+
sourcemap: false,
42+
43+
// Don't minify (keep readable for debugging).
44+
minify: false,
45+
46+
// Keep names for better stack traces.
47+
keepNames: true,
48+
49+
// Write directly to disk.
50+
write: true,
51+
52+
// Define environment variables and import.meta.
53+
define: {
54+
'process.env.NODE_ENV': '"production"',
55+
'import.meta.url': '__importMetaUrl',
56+
},
57+
58+
// Inject import.meta.url polyfill for CJS.
59+
inject: [path.join(__dirname, 'esbuild-inject-import-meta.mjs')],
60+
}
61+
62+
// Run build if invoked directly.
63+
if (fileURLToPath(import.meta.url) === process.argv[1]) {
64+
build(config)
65+
.then(() => {
66+
console.log('Built shadow-npm-inject.js')
67+
})
68+
.catch(error => {
69+
console.error('Build failed:', error)
70+
process.exitCode = 1
71+
})
72+
}
73+
74+
export default config

0 commit comments

Comments
 (0)