Skip to content

Commit aea812f

Browse files
Lms24lobsterkatie
andcommitted
feat(build): introduce root build directory in @sentry/browser
* add root build directory as the output directory for all module formats and bundles. This puts all build JS files and modules (bundles, esm, cjs) into one central build directory. Currently, `package.json`, Readme, License, etc. are still in the package root directories. This should keep things more organized and more clearly arranged. * adjust `tsconfig.json` to build type declarations (*.d.ts) into a separate directory (`build/types`). This deduplicates the identical declarations that were peviously compiled into `dist` and `esm`. * introduce `rootBuildDirectory` export in root `rollup.config.js` as it will (probably) be used in multiple packages and this lets us change the name for all of them at once. Co-authored-by: Katie Byers <[email protected]>
1 parent 4eadcaf commit aea812f

File tree

14 files changed

+68
-29
lines changed

14 files changed

+68
-29
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ jobs:
304304
with:
305305
name: ${{ github.sha }}
306306
path: |
307-
${{ github.workspace }}/packages/browser/build/**
307+
${{ github.workspace }}/packages/browser/build/bundles/**
308308
${{ github.workspace }}/packages/integrations/build/**
309309
${{ github.workspace }}/packages/tracing/build/**
310310
${{ github.workspace }}/packages/**/*.tgz

.size-limit.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
module.exports = [
22
{
33
name: '@sentry/browser - ES5 CDN Bundle (gzipped + minified)',
4-
path: 'packages/browser/build/bundle.min.js',
4+
path: 'packages/browser/build/bundles/bundle.min.js',
55
gzip: true,
66
limit: '100 KB',
77
},
88
{
99
name: '@sentry/browser - ES5 CDN Bundle (minified)',
10-
path: 'packages/browser/build/bundle.min.js',
10+
path: 'packages/browser/build/bundles/bundle.min.js',
1111
gzip: false,
1212
limit: '120 KB',
1313
},
1414
{
1515
name: '@sentry/browser - ES6 CDN Bundle (gzipped + minified)',
16-
path: 'packages/browser/build/bundle.es6.min.js',
16+
path: 'packages/browser/build/bundles/bundle.es6.min.js',
1717
gzip: true,
1818
limit: '100 KB',
1919
},
2020
{
2121
name: '@sentry/browser - ES6 CDN Bundle (minified)',
22-
path: 'packages/browser/build/bundle.es6.min.js',
22+
path: 'packages/browser/build/bundles/bundle.es6.min.js',
2323
gzip: false,
2424
limit: '120 KB',
2525
},
2626
{
2727
name: '@sentry/browser - Webpack (gzipped + minified)',
28-
path: 'packages/browser/esm/index.js',
28+
path: 'packages/browser/build/esm/index.js',
2929
import: '{ init }',
3030
gzip: true,
3131
limit: '100 KB',
3232
},
3333
{
3434
name: '@sentry/browser - Webpack (minified)',
35-
path: 'packages/browser/esm/index.js',
35+
path: 'packages/browser/build/esm/index.js',
3636
import: '{ init }',
3737
gzip: false,
3838
limit: '100 KB',

packages/browser/examples/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../build/bundle.js
1+
../build/bundles/bundle.js

packages/browser/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"engines": {
1010
"node": ">=6"
1111
},
12-
"main": "dist/index.js",
13-
"module": "esm/index.js",
12+
"main": "build/dist/index.js",
13+
"module": "build/esm/index.js",
1414
"types": "build/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
@@ -44,7 +44,7 @@
4444
"webpack": "^4.30.0"
4545
},
4646
"scripts": {
47-
"build": "run-p build:cjs build:esm build:bundle build:types",
47+
"build": "run-p build:cjs build:esm build:bundle build:types && bash ../../scripts/postbuild.sh",
4848
"build:bundle": "rollup --config",
4949
"build:cjs": "tsc -p tsconfig.cjs.json",
5050
"build:dev": "run-p build:cjs build:esm build:types",
@@ -59,18 +59,18 @@
5959
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
6060
"build:types:watch": "tsc -p tsconfig.types.json --watch",
6161
"circularDepCheck": "madge --circular src/index.ts",
62-
"clean": "rimraf dist esm build coverage .rpt2_cache",
62+
"clean": "rimraf build coverage .rpt2_cache",
6363
"fix": "run-s fix:eslint fix:prettier",
6464
"fix:eslint": "eslint . --format stylish --fix",
6565
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
6666
"link:yarn": "yarn link",
6767
"lint": "run-s lint:prettier lint:eslint",
6868
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
6969
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
70-
"pack": "npm pack",
70+
"pack": "npm pack ./build",
7171
"size:check": "run-p size:check:es5 size:check:es6",
72-
"size:check:es5": "cat build/bundle.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES5: \",$1,\"kB\";}'",
73-
"size:check:es6": "cat build/bundle.es6.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES6: \",$1,\"kB\";}'",
72+
"size:check:es5": "cat build/bundles/bundle.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES5: \",$1,\"kB\";}'",
73+
"size:check:es6": "cat build/bundles/bundle.es6.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES6: \",$1,\"kB\";}'",
7474
"test": "run-s test:unit",
7575
"test:unit": "jest --config test/unit/jest.config.js",
7676
"test:integration": "test/integration/run.js",

packages/browser/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const builds = [];
88
isAddOn: false,
99
jsVersion,
1010
licenseTitle: '@sentry/browser',
11-
outputFileBase: `bundle${jsVersion === 'es6' ? '.es6' : ''}`,
11+
outputFileBase: `bundles/bundle${jsVersion === 'es6' ? '.es6' : ''}`,
1212
});
1313

1414
builds.push(...makeConfigVariants(baseBundleConfig));

packages/browser/src/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,6 @@
212212
injectSdk(onLoadCallbacks);
213213
});
214214
}
215-
})(window, document, 'script', 'onerror', 'onunhandledrejection', 'Sentry', 'loader.js', '../../build/bundle.js', {
215+
})(window, document, 'script', 'onerror', 'onunhandledrejection', 'Sentry', 'loader.js', '../../build/bundles/bundle.js', {
216216
dsn: 'https://[email protected]/1'
217217
});

packages/browser/test/integration/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function build() {
8181
writeFile('artifacts/sdk.js', readFile('../../build/bundle.js').replace('//# sourceMappingURL=bundle.js.map', ''));
8282
writeFile(
8383
'artifacts/loader.js',
84-
readFile('../../src/loader.js').replace('../../build/bundle.js', '/base/artifacts/sdk.js')
84+
readFile('../../src/loader.js').replace('../../build/bundles/bundle.js', '/base/artifacts/sdk.js')
8585
);
8686

8787
writeFile(

packages/browser/test/package/test-code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
const Sentry = require('../../dist/index.js');
2+
const Sentry = require('../../build/dist/index.js');
33
const Integrations = require('../../../integrations/dist/dedupe.js');
44

55
// Init

packages/browser/tsconfig.cjs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
"compilerOptions": {
55
"module": "commonjs",
6-
"outDir": "dist"
6+
"outDir": "build/dist",
77
}
88
}

packages/browser/tsconfig.esm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
"compilerOptions": {
55
"module": "es6",
6-
"outDir": "esm"
6+
"outDir": "build/esm",
77
}
88
}

packages/integration-tests/utils/generatePlugin.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ const useBundle = bundleKey && !useCompiledModule;
1717

1818
const BUNDLE_PATHS: Record<string, Record<string, string>> = {
1919
browser: {
20-
cjs: 'dist/index.js',
21-
esm: 'esm/index.js',
22-
bundle_es5: 'build/bundle.js',
23-
bundle_es5_min: 'build/bundle.min.js',
24-
bundle_es6: 'build/bundle.es6.js',
25-
bundle_es6_min: 'build/bundle.es6.min.js',
20+
cjs: 'build/dist/index.js',
21+
esm: 'build/esm/index.js',
22+
bundle_es5: 'build/bundles/bundle.js',
23+
bundle_es5_min: 'build/bundles/bundle.min.js',
24+
bundle_es6: 'build/bundles/bundle.es6.js',
25+
bundle_es6_min: 'build/bundles/bundle.es6.min.js',
2626
},
2727
tracing: {
2828
cjs: 'dist/index.js',

packages/wasm/test/scripts/ensure-browser-bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { execSync } = require('child_process');
44

55
function ensureBrowserBundle() {
66
const browserPackageDir = path.resolve(__dirname, '../../../browser');
7-
if (!fs.existsSync(path.resolve(browserPackageDir, 'build/bundle.js'))) {
7+
if (!fs.existsSync(path.resolve(browserPackageDir, 'build/bundles/bundle.js'))) {
88
// eslint-disable-next-line no-console
99
console.warn('\nWARNING: Missing browser bundle. Bundle will be created before running wasm integration tests.');
1010
execSync(`pushd ${browserPackageDir} && yarn build:bundle && popd`);

packages/wasm/test/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ app.use(express.static(path.resolve(__dirname, 'public')));
88
// Wasm Integration Bundle
99
app.use(express.static(path.resolve(__dirname, '../build')));
1010
// Browser SDK Bundle
11-
app.use(express.static(path.resolve(__dirname, '../../browser/build')));
11+
app.use(express.static(path.resolve(__dirname, '../../browser/build/bundles')));
1212
app.listen(process.env.PORT);

scripts/postbuild.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
# This script prepares the `build` directory for NPM package creation.
4+
# It first copies all non-code files into the `build` directory, including `package.json` which
5+
# is edited via a few `sed` commands. These edits include corrections of paths (e.g. entry points)
6+
# in the copied package.json so that they align with the directory structure inside `build`.
7+
8+
BUILD_DIR=build
9+
10+
ASSETS="README.md
11+
LICENSE
12+
package.json"
13+
14+
# check if build dir exists
15+
if [ ! -d $BUILD_DIR ]; then
16+
echo "Directory ${BUILD_DIR}/ DOES NOT exist."
17+
echo "This script should only be executed after you've run \`yarn build\`."
18+
exit 1
19+
fi
20+
21+
# copy non-code assets to build dir
22+
for f in $ASSETS; do
23+
cp $f $BUILD_DIR/
24+
done
25+
26+
# package.json modifications
27+
28+
# sed command to modify package.json entry points in build dir
29+
# remove `BUILD_DIR` from `main`, `module` and `type` entry point paths
30+
entryPointsCommand="/\"(main|module|types)\": .*,/s/$BUILD_DIR\///"
31+
32+
# use empty backup file extension for sed in-place editing on MacOS and no backup for other platforms
33+
if [[ $(uname) == "Darwin" ]]; then
34+
sed -i "" -E "$entryPointsCommand" $BUILD_DIR/package.json
35+
else
36+
sed -i -E "$entryPointsCommand#" $BUILD_DIR/package.json
37+
fi
38+
39+
echo "Successfully finished postbuild commands"

0 commit comments

Comments
 (0)