diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b68c117ec4b1..a8f026b2729f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -204,8 +204,8 @@ jobs: name: ${{ github.sha }} path: | ${{ github.workspace }}/packages/browser/build/bundles/** - ${{ github.workspace }}/packages/integrations/build/** - ${{ github.workspace }}/packages/tracing/build/** + ${{ github.workspace }}/packages/integrations/build/bundles/** + ${{ github.workspace }}/packages/tracing/build/bundles/** ${{ github.workspace }}/packages/**/*.tgz ${{ github.workspace }}/packages/serverless/dist-awslambda-layer/*.zip diff --git a/.size-limit.js b/.size-limit.js index 5f77b82f2f55..ad0aae688eae 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -25,14 +25,14 @@ module.exports = [ }, { name: '@sentry/browser - Webpack (gzipped + minified)', - path: 'packages/browser/build/esm/index.js', + path: 'packages/browser/build/npm/esm/index.js', import: '{ init }', gzip: true, limit: '100 KB', }, { name: '@sentry/browser - Webpack (minified)', - path: 'packages/browser/build/esm/index.js', + path: 'packages/browser/build/npm/esm/index.js', import: '{ init }', gzip: false, limit: '100 KB', @@ -53,13 +53,13 @@ module.exports = [ }, { name: '@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified)', - path: 'packages/tracing/build/bundle.tracing.min.js', + path: 'packages/tracing/build/bundles/bundle.tracing.min.js', gzip: true, limit: '100 KB', }, { name: '@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified)', - path: 'packages/tracing/build/bundle.tracing.es6.min.js', + path: 'packages/tracing/build/bundles/bundle.tracing.es6.min.js', gzip: true, limit: '100 KB', }, diff --git a/packages/browser/.npmignore b/packages/browser/.npmignore index 643a96e2e5f4..8c9dff2dc460 100644 --- a/packages/browser/.npmignore +++ b/packages/browser/.npmignore @@ -1,11 +1,11 @@ # Info: the paths in this file are specified so that they align with the file # structure in `./build` where this file is copied to. This is done by the -# postbuild script `sentry-javascript/scripts/postbuild.ts`. +# prepack script `sentry-javascript/scripts/prepack.ts`. * -# TODO remove bundles in v7 -!/bundles/**/* +# TODO remove bundles (which in the tarball are inside `build`) in v7 +!/build/**/* !/dist/**/* !/types/**/* diff --git a/packages/browser/package.json b/packages/browser/package.json index 1b6354177f4a..211c933c10bd 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -9,9 +9,9 @@ "engines": { "node": ">=6" }, - "main": "build/dist/index.js", - "module": "build/esm/index.js", - "types": "build/types/index.d.ts", + "main": "build/npm/dist/index.js", + "module": "build/npm/esm/index.js", + "types": "build/npm/types/index.d.ts", "publishConfig": { "access": "public" }, @@ -44,7 +44,7 @@ "webpack": "^4.30.0" }, "scripts": { - "build": "run-p build:cjs build:esm build:bundle build:types && ts-node ../../scripts/postbuild.ts", + "build": "run-p build:cjs build:esm build:bundle build:types", "build:bundle": "rollup --config", "build:cjs": "tsc -p tsconfig.cjs.json", "build:dev": "run-p build:cjs build:esm build:types", @@ -58,7 +58,7 @@ "build:dev:watch": "run-p build:cjs:watch build:esm:watch build:types:watch", "build:esm:watch": "tsc -p tsconfig.esm.json --watch", "build:types:watch": "tsc -p tsconfig.types.json --watch", - "build:npm": "npm pack ./build", + "build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build/npm", "circularDepCheck": "madge --circular src/index.ts", "clean": "rimraf build coverage .rpt2_cache", "fix": "run-s fix:eslint fix:prettier", diff --git a/packages/browser/test/integration/run.js b/packages/browser/test/integration/run.js index a961a11b657a..38ff9975b81a 100755 --- a/packages/browser/test/integration/run.js +++ b/packages/browser/test/integration/run.js @@ -73,7 +73,7 @@ function build() { writeFile( 'artifacts/dedupe.js', - readFile('../../../integrations/build/dedupe.js').replace('//# sourceMappingURL=dedupe.js.map', '') + readFile('../../../integrations/build/bundles/dedupe.js').replace('//# sourceMappingURL=dedupe.js.map', '') ); concatFiles('artifacts/setup.js', ['artifacts/dedupe.js', 'common/utils.js', 'common/triggers.js', 'common/init.js']); rmdir('artifacts/dedupe.js'); diff --git a/packages/browser/test/package/test-code.js b/packages/browser/test/package/test-code.js index b31e01de9986..e05a667db274 100644 --- a/packages/browser/test/package/test-code.js +++ b/packages/browser/test/package/test-code.js @@ -1,6 +1,6 @@ /* eslint-disable no-console */ -const Sentry = require('../../build/dist/index.js'); -const Integrations = require('../../../integrations/dist/dedupe.js'); +const Sentry = require('../../build/npm/dist/index.js'); +const Integrations = require('../../../integrations/build/npm/dist/dedupe.js'); // Init Sentry.init({ diff --git a/packages/browser/tsconfig.cjs.json b/packages/browser/tsconfig.cjs.json index 0605bd22f8b2..6782dae5e453 100644 --- a/packages/browser/tsconfig.cjs.json +++ b/packages/browser/tsconfig.cjs.json @@ -3,6 +3,6 @@ "compilerOptions": { "module": "commonjs", - "outDir": "build/dist", + "outDir": "build/npm/dist" } } diff --git a/packages/browser/tsconfig.esm.json b/packages/browser/tsconfig.esm.json index 9c69ab75381b..feffe52ca581 100644 --- a/packages/browser/tsconfig.esm.json +++ b/packages/browser/tsconfig.esm.json @@ -3,6 +3,6 @@ "compilerOptions": { "module": "es6", - "outDir": "build/esm", + "outDir": "build/npm/esm" } } diff --git a/packages/browser/tsconfig.types.json b/packages/browser/tsconfig.types.json index 65455f66bd75..374fd9bc9364 100644 --- a/packages/browser/tsconfig.types.json +++ b/packages/browser/tsconfig.types.json @@ -5,6 +5,6 @@ "declaration": true, "declarationMap": true, "emitDeclarationOnly": true, - "outDir": "build/types" + "outDir": "build/npm/types" } } diff --git a/packages/integration-tests/utils/generatePlugin.ts b/packages/integration-tests/utils/generatePlugin.ts index 00a0a7c55877..5163f81a668a 100644 --- a/packages/integration-tests/utils/generatePlugin.ts +++ b/packages/integration-tests/utils/generatePlugin.ts @@ -17,20 +17,20 @@ const useBundle = bundleKey && !useCompiledModule; const BUNDLE_PATHS: Record> = { browser: { - cjs: 'build/dist/index.js', - esm: 'build/esm/index.js', + cjs: 'build/npm/dist/index.js', + esm: 'build/npm/esm/index.js', bundle_es5: 'build/bundles/bundle.js', bundle_es5_min: 'build/bundles/bundle.min.js', bundle_es6: 'build/bundles/bundle.es6.js', bundle_es6_min: 'build/bundles/bundle.es6.min.js', }, tracing: { - cjs: 'dist/index.js', - esm: 'esm/index.js', - bundle_es5: 'build/bundle.tracing.js', - bundle_es5_min: 'build/bundle.tracing.min.js', - bundle_es6: 'build/bundle.tracing.es6.js', - bundle_es6_min: 'build/bundle.tracing.es6.min.js', + cjs: 'build/npm/dist/index.js', + esm: 'build/npm/esm/index.js', + bundle_es5: 'build/bundles/bundle.tracing.js', + bundle_es5_min: 'build/bundles/bundle.tracing.min.js', + bundle_es6: 'build/bundles/bundle.tracing.es6.js', + bundle_es6_min: 'build/bundles/bundle.tracing.es6.min.js', }, }; diff --git a/packages/integrations/.npmignore b/packages/integrations/.npmignore index d92f664ecfe3..c6e94588f342 100644 --- a/packages/integrations/.npmignore +++ b/packages/integrations/.npmignore @@ -1,4 +1,12 @@ +# Info: the paths in this file are specified so that they align with the file +# structure in `./build` where this file is copied to. This is done by the +# prepack script `sentry-javascript/scripts/prepack.ts`. + * -!/dist/**/* + +# TODO remove bundles (which in the tarball are inside `build`) in v7 !/build/**/* + +!/dist/**/* !/esm/**/* +!/types/**/* diff --git a/packages/integrations/package.json b/packages/integrations/package.json index 9fd8b5e16926..25dd588c9a34 100644 --- a/packages/integrations/package.json +++ b/packages/integrations/package.json @@ -12,9 +12,9 @@ "publishConfig": { "access": "public" }, - "main": "dist/index.js", - "module": "esm/index.js", - "types": "build/types/index.d.ts", + "main": "build/npm/dist/index.js", + "module": "build/npm/esm/index.js", + "types": "build/npm/types/index.d.ts", "dependencies": { "@sentry/types": "6.19.4", "@sentry/utils": "6.19.4", @@ -38,7 +38,7 @@ "build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***", "build:esm:watch": "tsc -p tsconfig.esm.json --watch", "build:types:watch": "tsc -p tsconfig.types.json --watch", - "build:npm": "npm pack", + "build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build/npm", "circularDepCheck": "madge --circular src/index.ts", "clean": "rimraf dist esm build coverage .rpt2_cache", "fix": "run-s fix:eslint fix:prettier", diff --git a/packages/integrations/rollup.config.js b/packages/integrations/rollup.config.js index cd7d9077a292..7b23d698dfa2 100644 --- a/packages/integrations/rollup.config.js +++ b/packages/integrations/rollup.config.js @@ -12,7 +12,7 @@ const baseBundleConfig = makeBaseBundleConfig({ isAddOn: true, jsVersion, licenseTitle: '@sentry/integrations', - outputFileBase: `${file.replace('.ts', '')}${jsVersion === 'ES6' ? '.es6' : ''}`, + outputFileBase: `bundles/${file.replace('.ts', '')}${jsVersion === 'ES6' ? '.es6' : ''}`, }); // TODO We only need `commonjs` for localforage (used in the offline plugin). Once that's fixed, this can come out. diff --git a/packages/integrations/tsconfig.cjs.json b/packages/integrations/tsconfig.cjs.json index abd80f77e1ff..6782dae5e453 100644 --- a/packages/integrations/tsconfig.cjs.json +++ b/packages/integrations/tsconfig.cjs.json @@ -3,6 +3,6 @@ "compilerOptions": { "module": "commonjs", - "outDir": "dist" + "outDir": "build/npm/dist" } } diff --git a/packages/integrations/tsconfig.esm.json b/packages/integrations/tsconfig.esm.json index b6ee3fa615c0..feffe52ca581 100644 --- a/packages/integrations/tsconfig.esm.json +++ b/packages/integrations/tsconfig.esm.json @@ -3,6 +3,6 @@ "compilerOptions": { "module": "es6", - "outDir": "esm" + "outDir": "build/npm/esm" } } diff --git a/packages/integrations/tsconfig.types.json b/packages/integrations/tsconfig.types.json index 65455f66bd75..374fd9bc9364 100644 --- a/packages/integrations/tsconfig.types.json +++ b/packages/integrations/tsconfig.types.json @@ -5,6 +5,6 @@ "declaration": true, "declarationMap": true, "emitDeclarationOnly": true, - "outDir": "build/types" + "outDir": "build/npm/types" } } diff --git a/packages/tracing/.npmignore b/packages/tracing/.npmignore index d92f664ecfe3..c6e94588f342 100644 --- a/packages/tracing/.npmignore +++ b/packages/tracing/.npmignore @@ -1,4 +1,12 @@ +# Info: the paths in this file are specified so that they align with the file +# structure in `./build` where this file is copied to. This is done by the +# prepack script `sentry-javascript/scripts/prepack.ts`. + * -!/dist/**/* + +# TODO remove bundles (which in the tarball are inside `build`) in v7 !/build/**/* + +!/dist/**/* !/esm/**/* +!/types/**/* diff --git a/packages/tracing/package.json b/packages/tracing/package.json index 2b555c4bd117..c8f37b4e921f 100644 --- a/packages/tracing/package.json +++ b/packages/tracing/package.json @@ -9,9 +9,9 @@ "engines": { "node": ">=6" }, - "main": "dist/index.js", - "module": "esm/index.js", - "types": "build/types/index.d.ts", + "main": "build/npm/dist/index.js", + "module": "build/npm/esm/index.js", + "types": "build/npm/types/index.d.ts", "publishConfig": { "access": "public" }, @@ -29,7 +29,7 @@ "jsdom": "^16.2.2" }, "scripts": { - "build": "run-p build:cjs build:esm build:types build:bundle", + "build": "run-p build:cjs build:esm build:types build:bundle && ts-node ../../scripts/prepack.ts #necessary for integration tests", "build:bundle": "rollup --config", "build:cjs": "tsc -p tsconfig.cjs.json", "build:dev": "run-p build:cjs build:esm build:types", @@ -43,7 +43,7 @@ "build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***", "build:esm:watch": "tsc -p tsconfig.esm.json --watch", "build:types:watch": "tsc -p tsconfig.types.json --watch", - "build:npm": "npm pack", + "build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build/npm", "clean": "rimraf dist esm build coverage", "circularDepCheck": "madge --circular src/index.ts", "fix": "run-s fix:eslint fix:prettier", diff --git a/packages/tracing/rollup.config.js b/packages/tracing/rollup.config.js index e53a34004303..529ddea29a1b 100644 --- a/packages/tracing/rollup.config.js +++ b/packages/tracing/rollup.config.js @@ -8,7 +8,7 @@ const builds = []; isAddOn: false, jsVersion, licenseTitle: '@sentry/tracing & @sentry/browser', - outputFileBase: `bundle.tracing${jsVersion === 'es6' ? '.es6' : ''}`, + outputFileBase: `bundles/bundle.tracing${jsVersion === 'es6' ? '.es6' : ''}`, }); builds.push(...makeConfigVariants(baseBundleConfig)); diff --git a/packages/tracing/tsconfig.cjs.json b/packages/tracing/tsconfig.cjs.json index abd80f77e1ff..6782dae5e453 100644 --- a/packages/tracing/tsconfig.cjs.json +++ b/packages/tracing/tsconfig.cjs.json @@ -3,6 +3,6 @@ "compilerOptions": { "module": "commonjs", - "outDir": "dist" + "outDir": "build/npm/dist" } } diff --git a/packages/tracing/tsconfig.esm.json b/packages/tracing/tsconfig.esm.json index b6ee3fa615c0..feffe52ca581 100644 --- a/packages/tracing/tsconfig.esm.json +++ b/packages/tracing/tsconfig.esm.json @@ -3,6 +3,6 @@ "compilerOptions": { "module": "es6", - "outDir": "esm" + "outDir": "build/npm/esm" } } diff --git a/packages/tracing/tsconfig.types.json b/packages/tracing/tsconfig.types.json index 65455f66bd75..374fd9bc9364 100644 --- a/packages/tracing/tsconfig.types.json +++ b/packages/tracing/tsconfig.types.json @@ -5,6 +5,6 @@ "declaration": true, "declarationMap": true, "emitDeclarationOnly": true, - "outDir": "build/types" + "outDir": "build/npm/types" } } diff --git a/packages/wasm/.npmignore b/packages/wasm/.npmignore index 8904efca5aea..0514c96743ba 100644 --- a/packages/wasm/.npmignore +++ b/packages/wasm/.npmignore @@ -1,4 +1,9 @@ +# Info: the paths in this file are specified so that they align with the file +# structure in `./build` where this file is copied to. This is done by the +# prepack script `sentry-javascript/scripts/prepack.ts`. + * + !/dist/**/* !/esm/**/* -!/build/types/**/* +!/types/**/* diff --git a/packages/wasm/package.json b/packages/wasm/package.json index 4e19e901ffe1..be2d9ac1a9ca 100644 --- a/packages/wasm/package.json +++ b/packages/wasm/package.json @@ -9,9 +9,9 @@ "engines": { "node": ">=6" }, - "main": "dist/index.js", - "module": "esm/index.js", - "types": "build/types/index.d.ts", + "main": "build/npm/dist/index.js", + "module": "build/npm/esm/index.js", + "types": "build/npm/types/index.d.ts", "publishConfig": { "access": "public" }, @@ -43,9 +43,9 @@ "build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***", "build:esm:watch": "tsc -p tsconfig.esm.json --watch", "build:types:watch": "tsc -p tsconfig.types.json --watch", - "build:npm": "npm pack", + "build:npm": "ts-node ../../scripts/prepack.ts -skipBundleCopy && npm pack ./build/npm", "circularDepCheck": "madge --circular src/index.ts", - "clean": "rimraf dist esm coverage *.js.map *.d.ts", + "clean": "rimraf dist esm build coverage *.js.map *.d.ts", "fix": "run-s fix:eslint fix:prettier", "fix:eslint": "eslint . --format stylish --fix", "fix:prettier": "prettier --write \"{src,test,scripts}/**/*.ts\"", diff --git a/packages/wasm/rollup.config.js b/packages/wasm/rollup.config.js index 0b4f26e0af17..edccdbd9287a 100644 --- a/packages/wasm/rollup.config.js +++ b/packages/wasm/rollup.config.js @@ -5,7 +5,7 @@ const baseBundleConfig = makeBaseBundleConfig({ isAddOn: true, jsVersion: 'es5', licenseTitle: '@sentry/wasm', - outputFileBase: 'wasm', + outputFileBase: 'bundles/wasm', }); export default makeConfigVariants(baseBundleConfig); diff --git a/packages/wasm/test/server.js b/packages/wasm/test/server.js index 0c6a1f3dc656..04640c76a154 100644 --- a/packages/wasm/test/server.js +++ b/packages/wasm/test/server.js @@ -6,7 +6,7 @@ const app = express(); // Wasm Integration Tests Artifacts app.use(express.static(path.resolve(__dirname, 'public'))); // Wasm Integration Bundle -app.use(express.static(path.resolve(__dirname, '../build'))); +app.use(express.static(path.resolve(__dirname, '../build/bundles'))); // Browser SDK Bundle app.use(express.static(path.resolve(__dirname, '../../browser/build/bundles'))); app.listen(process.env.PORT); diff --git a/packages/wasm/tsconfig.cjs.json b/packages/wasm/tsconfig.cjs.json index abd80f77e1ff..6782dae5e453 100644 --- a/packages/wasm/tsconfig.cjs.json +++ b/packages/wasm/tsconfig.cjs.json @@ -3,6 +3,6 @@ "compilerOptions": { "module": "commonjs", - "outDir": "dist" + "outDir": "build/npm/dist" } } diff --git a/packages/wasm/tsconfig.esm.json b/packages/wasm/tsconfig.esm.json index b6ee3fa615c0..feffe52ca581 100644 --- a/packages/wasm/tsconfig.esm.json +++ b/packages/wasm/tsconfig.esm.json @@ -3,6 +3,6 @@ "compilerOptions": { "module": "es6", - "outDir": "esm" + "outDir": "build/npm/esm" } } diff --git a/packages/wasm/tsconfig.types.json b/packages/wasm/tsconfig.types.json index 65455f66bd75..374fd9bc9364 100644 --- a/packages/wasm/tsconfig.types.json +++ b/packages/wasm/tsconfig.types.json @@ -5,6 +5,6 @@ "declaration": true, "declarationMap": true, "emitDeclarationOnly": true, - "outDir": "build/types" + "outDir": "build/npm/types" } } diff --git a/scripts/postbuild.ts b/scripts/prepack.ts similarity index 51% rename from scripts/postbuild.ts rename to scripts/prepack.ts index 959569bec034..beecd1230f38 100644 --- a/scripts/postbuild.ts +++ b/scripts/prepack.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /* This script prepares the central `build` directory for NPM package creation. It first copies all non-code files into the `build` directory, including `package.json`, which @@ -6,22 +7,22 @@ */ import * as fs from 'fs'; - +import * as fse from 'fs-extra'; import * as path from 'path'; -const BUILD_DIR = 'build'; +const NPM_BUILD_DIR = 'build/npm'; const ASSETS = ['README.md', 'LICENSE', 'package.json', '.npmignore']; const ENTRY_POINTS = ['main', 'module', 'types']; // check if build dir exists try { - if (!fs.existsSync(path.resolve(BUILD_DIR))) { - console.error(`Directory ${BUILD_DIR} DOES NOT exist`); + if (!fs.existsSync(path.resolve(NPM_BUILD_DIR))) { + console.error(`Directory ${NPM_BUILD_DIR} DOES NOT exist`); console.error("This script should only be executed after you've run `yarn build`."); process.exit(1); } } catch (error) { - console.error(`Error while looking up directory ${BUILD_DIR}`); + console.error(`Error while looking up directory ${NPM_BUILD_DIR}`); process.exit(1); } @@ -33,31 +34,51 @@ ASSETS.forEach(asset => { console.error(`Asset ${asset} does not exist.`); process.exit(1); } - fs.copyFileSync(assetPath, path.resolve(BUILD_DIR, asset)); + fs.copyFileSync(assetPath, path.resolve(NPM_BUILD_DIR, asset)); } catch (error) { - console.error(`Error while copying ${asset} to ${BUILD_DIR}`); + console.error(`Error while copying ${asset} to ${NPM_BUILD_DIR}`); process.exit(1); } }); +// TODO remove in v7! Until then: +// copy CDN bundles into npm dir to temporarily keep bundles in npm tarball +// inside the tarball, they are located in `build/` +// for now, copy it by default, unless explicitly forbidden via an command line arg +const tmpCopyBundles = !process.argv.includes('-skipBundleCopy'); +if (tmpCopyBundles) { + const npmTmpBundlesPath = path.resolve(NPM_BUILD_DIR, 'build'); + const cdnBundlesPath = path.resolve('build', 'bundles'); + try { + if (!fs.existsSync(npmTmpBundlesPath)) { + fs.mkdirSync(npmTmpBundlesPath); + } + void fse.copy(cdnBundlesPath, npmTmpBundlesPath); + } catch (error) { + console.error(`Error while tmp copying CDN bundles to ${NPM_BUILD_DIR}`); + process.exit(1); + } +} // package.json modifications -const packageJsonPath = path.resolve(BUILD_DIR, 'package.json'); +const packageJsonPath = path.resolve(NPM_BUILD_DIR, 'package.json'); +// eslint-disable-next-line @typescript-eslint/no-var-requires const pkgJson: { [key: string]: unknown } = require(packageJsonPath); // modify entry points to point to correct paths (i.e. strip out the build directory) ENTRY_POINTS.filter(entryPoint => pkgJson[entryPoint]).forEach(entryPoint => { - pkgJson[entryPoint] = (pkgJson[entryPoint] as string).replace(`${BUILD_DIR}/`, ''); + pkgJson[entryPoint] = (pkgJson[entryPoint] as string).replace(`${NPM_BUILD_DIR}/`, ''); }); delete pkgJson.scripts; delete pkgJson.volta; +delete pkgJson.jest; // write modified package.json to file (pretty-printed with 2 spaces) try { fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2)); } catch (error) { - console.error(`Error while writing package.json to disk`); + console.error('Error while writing package.json to disk'); process.exit(1); } -console.log(`\nSuccessfully finished postbuild commands for ${pkgJson.name}`); +console.log(`\nSuccessfully finished prepack commands for ${pkgJson.name}\n`);