-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
17 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,11 @@ | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; | ||
|
||
export const ESMImportShim = ` | ||
import {createRequire} from 'node:module'; | ||
import {fileURLToPath} from 'node:url'; | ||
import {dirname } from 'node:path'; | ||
`; | ||
|
||
const ESMRequireShim = ` | ||
const require = createRequire(import.meta.url); | ||
`; | ||
|
||
const ESMDirnameShim = ` | ||
const filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
`; | ||
|
||
function makeESMImportShimPlugin(shim) { | ||
return { | ||
transform(code) { | ||
const SHIM_REGEXP = /\/\/ #START_SENTRY_ESM_IMPORT_SHIM[\s\S]*?\/\/ #END_SENTRY_ESM_IMPORT_SHIM/; | ||
return code.replace(SHIM_REGEXP, shim); | ||
}, | ||
}; | ||
} | ||
|
||
function makeESMRequireShimPlugin(shim) { | ||
return { | ||
transform(code) { | ||
const SHIM_REGEXP = /\/\/ #START_SENTRY_ESM_REQUIRE_SHIM[\s\S]*?\/\/ #END_SENTRY_ESM_REQUIRE_SHIM/; | ||
return code.replace(SHIM_REGEXP, shim); | ||
}, | ||
}; | ||
} | ||
|
||
function makeESMDirnameShimPlugin(shim) { | ||
return { | ||
transform(code) { | ||
const SHIM_REGEXP = /\/\/ #START_SENTRY_ESM_DIRNAME_SHIM[\s\S]*?\/\/ #END_SENTRY_ESM_DIRNAME_SHIM/; | ||
return code.replace(SHIM_REGEXP, shim); | ||
}, | ||
}; | ||
} | ||
|
||
const variants = makeNPMConfigVariants( | ||
export default makeNPMConfigVariants( | ||
makeBaseNPMConfig({ | ||
packageSpecificConfig: { | ||
output: { dir: 'lib', preserveModules: false }, | ||
plugins: [commonjs()], | ||
}, | ||
}), | ||
); | ||
|
||
for (const variant of variants) { | ||
if (variant.output.format === 'esm') { | ||
variant.plugins.push(makeESMImportShimPlugin(ESMImportShim)); | ||
variant.plugins.push(makeESMRequireShimPlugin(ESMRequireShim)); | ||
variant.plugins.push(makeESMDirnameShimPlugin(ESMDirnameShim)); | ||
} else { | ||
// Remove the ESM shim comment | ||
variant.plugins.push(makeESMImportShimPlugin('')); | ||
variant.plugins.push(makeESMRequireShimPlugin('')); | ||
variant.plugins.push(makeESMDirnameShimPlugin('')); | ||
} | ||
} | ||
|
||
export default variants; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters