diff --git a/nx.json b/nx.json index c25aeaa1f0e7..da4ed2456a75 100644 --- a/nx.json +++ b/nx.json @@ -26,7 +26,7 @@ }, "build:transpile": { "inputs": ["production", "^production"], - "dependsOn": ["^build:transpile:uncached", "^build:transpile", "build:transpile:uncached"], + "dependsOn": ["^build:transpile"], "outputs": ["{projectRoot}/build/npm", "{projectRoot}/build/esm", "{projectRoot}/build/cjs"] }, "build:types": { diff --git a/packages/angular-ivy/package.json b/packages/angular-ivy/package.json index 78c36cf46ab9..ce265938953b 100644 --- a/packages/angular-ivy/package.json +++ b/packages/angular-ivy/package.json @@ -67,7 +67,6 @@ "build:transpile": { "dependsOn": [ "^build:transpile", - "^build:transpile:uncached", "^build:types" ] } diff --git a/packages/angular/package.json b/packages/angular/package.json index 133d30bc738a..690980b1c7de 100644 --- a/packages/angular/package.json +++ b/packages/angular/package.json @@ -71,7 +71,6 @@ "build:transpile": { "dependsOn": [ "^build:transpile", - "^build:transpile:uncached", "^build:types" ] } diff --git a/packages/utils/package.json b/packages/utils/package.json index 01cf4acef51d..25a4317251e5 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -34,7 +34,6 @@ "build": "run-p build:transpile build:types", "build:dev": "yarn build", "build:transpile": "yarn ts-node scripts/buildRollup.ts", - "build:transpile:uncached": "yarn ts-node scripts/buildRollup.ts", "build:types": "run-s build:types:core build:types:downlevel", "build:types:core": "tsc -p tsconfig.types.json", "build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8", diff --git a/packages/utils/rollup.npm.config.js b/packages/utils/rollup.npm.config.js index dcf32469a4e4..5a62b528ef44 100644 --- a/packages/utils/rollup.npm.config.js +++ b/packages/utils/rollup.npm.config.js @@ -1,9 +1,3 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'; -export default makeNPMConfigVariants( - makeBaseNPMConfig({ - // We build the polyfills separately because they're not included in the top-level exports of the package, in order - // to keep them out of the public API. - entrypoints: ['src/index.ts', 'src/buildPolyfills/index.ts'], - }), -); +export default makeNPMConfigVariants(makeBaseNPMConfig()); diff --git a/packages/utils/scripts/buildRollup.ts b/packages/utils/scripts/buildRollup.ts index f48b0b23d6d9..6ce18d747787 100644 --- a/packages/utils/scripts/buildRollup.ts +++ b/packages/utils/scripts/buildRollup.ts @@ -14,17 +14,3 @@ run('yarn rollup -c rollup.npm.config.js'); // We want to distribute the README because it contains the MIT license blurb from Sucrase and Rollup fs.copyFileSync('src/buildPolyfills/README.md', 'build/cjs/buildPolyfills/README.md'); fs.copyFileSync('src/buildPolyfills/README.md', 'build/esm/buildPolyfills/README.md'); - -// Because we import our polyfills from `@sentry/utils/cjs/buildPolyfills` and `@sentry/utils/esm/buildPolyfills` rather -// than straight from `@sentry/utils` (so as to avoid having them in the package's public API), when tests run, they'll -// expect to find `cjs` and `esm` at the root level of the repo. -try { - fs.symlinkSync('build/cjs', 'cjs'); -} catch (oO) { - // if we get here, it's because the symlink already exists, so we're good -} -try { - fs.symlinkSync('build/esm', 'esm'); -} catch (oO) { - // same as above -} diff --git a/packages/utils/src/buildPolyfills/README.md b/packages/utils/src/buildPolyfills/README.md index 8171e8583a96..eedea6db9959 100644 --- a/packages/utils/src/buildPolyfills/README.md +++ b/packages/utils/src/buildPolyfills/README.md @@ -1,6 +1,6 @@ ## Build Polyfills -This is a collection of syntax and import/export polyfills either copied directly from or heavily inspired by those used by [Rollup](https://github.com/rollup/rollup) and [Sucrase](https://github.com/alangpierce/sucrase). When either tool uses one of these polyfills during a build, it injects the function source code into each file needing the function, which can lead to a great deal of duplication. For our builds, we have therefore implemented something similar to [`tsc`'s `importHelpers` behavior](https://www.typescriptlang.org/tsconfig#importHelpers): Instead of leaving the polyfills injected in multiple places, we instead replace each injected function with an `import` or `require` statement, pulling from the CJS or ESM builds as appropriate. (In other words, the injected `import` statements import from `@sentry/utils/esm/buildPolyfills` and the injected `require` statements pull from `@sentry/utils/cjs/buildPolyfills/`. Because these functions should never be part of the public API, they're not exported from the package directly.) +This is a collection of syntax and import/export polyfills either copied directly from or heavily inspired by those used by [Rollup](https://github.com/rollup/rollup) and [Sucrase](https://github.com/alangpierce/sucrase). When either tool uses one of these polyfills during a build, it injects the function source code into each file needing the function, which can lead to a great deal of duplication. For our builds, we have therefore implemented something similar to [`tsc`'s `importHelpers` behavior](https://www.typescriptlang.org/tsconfig#importHelpers): Instead of leaving the polyfills injected in multiple places, we instead replace each injected function with an `import` or `require` statement. Note that not all polyfills are currently used by the SDK, but all are included here for future compatitibility, should they ever be needed. Also, since we're never going to be calling these directly from within another TS file, their types are fairly generic. In some cases testing required more specific types, which can be found in the test files. diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 454d441080ec..d19991b7d401 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -34,3 +34,4 @@ export * from './cache'; export * from './eventbuilder'; export * from './anr'; export * from './lru'; +export * from './buildPolyfills'; diff --git a/rollup/plugins/extractPolyfillsPlugin.js b/rollup/plugins/extractPolyfillsPlugin.js index 134f39c64bdb..e036e70e9593 100644 --- a/rollup/plugins/extractPolyfillsPlugin.js +++ b/rollup/plugins/extractPolyfillsPlugin.js @@ -40,6 +40,13 @@ export function makeExtractPolyfillsPlugin() { return null; } + // The index.js file of the tuils package will include identifiers named after polyfills so we would inject the + // polyfills, however that would override the exports so we should just skip that file. + const isUtilsPackage = process.cwd().endsWith('packages/utils'); + if (isUtilsPackage && sourceFile === 'index.js') { + return null; + } + const parserOptions = { sourceFileName: sourceFile, // We supply a custom parser which wraps the provided `acorn` parser in order to override the `ecmaVersion` value. @@ -187,9 +194,7 @@ function createImportOrRequireNode(polyfillNodes, currentSourceFile, moduleForma // relative const isUtilsPackage = process.cwd().endsWith('packages/utils'); const importSource = literal( - isUtilsPackage - ? `./${path.relative(path.dirname(currentSourceFile), 'buildPolyfills')}` - : `@sentry/utils/${moduleFormat}/buildPolyfills`, + isUtilsPackage ? `./${path.relative(path.dirname(currentSourceFile), 'buildPolyfills')}` : '@sentry/utils', ); // This is the `x, y, z` of inside of `import { x, y, z }` or `var { x, y, z }`