Skip to content

Commit

Permalink
Fix esm...
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish committed Mar 5, 2024
1 parent 99a9d0f commit 1946283
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
makeSetSDKSourcePlugin,
makeSucrasePlugin,
} from './plugins/index.mjs';
import { makePackageNodeEsm } from './plugins/make-esm-plugin.mjs';
import { mergePlugins } from './utils.mjs';

const packageDotJSON = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' }));
Expand Down Expand Up @@ -120,7 +121,7 @@ export function makeBaseNPMConfig(options = {}) {
export function makeNPMConfigVariants(baseConfig) {
const variantSpecificConfigs = [
{ output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } },
{ output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm') } },
{ output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm'), plugins: [makePackageNodeEsm()] } },
];

return variantSpecificConfigs.map(variant => deepMerge(baseConfig, variant));
Expand Down
16 changes: 16 additions & 0 deletions dev-packages/rollup-utils/plugins/make-esm-plugin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Outputs a package.json file with {type: module} in the root of the output directory so that Node
* treats .js files as ESM.
*/
export function makePackageNodeEsm() {
return {
name: 'make-package-node-esm',
generateBundle() {
this.emitFile({
type: 'asset',
fileName: 'package.json',
source: '{ "type": "module" }',
});
},
};
}
5 changes: 3 additions & 2 deletions packages/node-experimental/src/integrations/tracing/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { PrismaInstrumentation } from '@prisma/instrumentation';
// When importing CommonJs modules into an ESM module, we import the named exports directly.
import * as prismaInstrumentation from '@prisma/instrumentation';
import { defineIntegration } from '@sentry/core';
import type { IntegrationFn } from '@sentry/types';

Expand All @@ -10,7 +11,7 @@ const _prismaIntegration = (() => {
registerInstrumentations({
instrumentations: [
// does not have a hook to adjust spans & add origin
new PrismaInstrumentation({}),
new prismaInstrumentation.PrismaInstrumentation({}),
],
});
},
Expand Down
8 changes: 5 additions & 3 deletions packages/node-experimental/src/sdk/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import { defaultStackParser, getSentryRelease } from './api';
import { NodeClient } from './client';
import { initOtel } from './initOtel';

function getCjsOnlyIntegrations(isCjs = typeof require !== 'undefined'): Integration[] {
return isCjs ? [nativeNodeFetchIntegration(), modulesIntegration()] : [];
}

/** Get the default integrations for the Node Experimental SDK. */
export function getDefaultIntegrations(options: Options): Integration[] {
// TODO
Expand All @@ -51,17 +55,15 @@ export function getDefaultIntegrations(options: Options): Integration[] {
// Native Wrappers
consoleIntegration(),
httpIntegration(),
nativeNodeFetchIntegration(),
// Global Handlers
onUncaughtExceptionIntegration(),
onUnhandledRejectionIntegration(),
// Event Info
contextLinesIntegration(),
localVariablesIntegration(),
nodeContextIntegration(),
modulesIntegration(),
httpIntegration(),
nativeNodeFetchIntegration(),
...getCjsOnlyIntegrations(),
...(hasTracingEnabled(options) ? getAutoPerformanceIntegrations() : []),
];
}
Expand Down

0 comments on commit 1946283

Please sign in to comment.