Skip to content

Commit 14b7962

Browse files
authored
ref(build): Introduce central build directory to packages with bundles (#4838)
Adds the central build directory to all our packages producing CDN bundles in addition to NPM tarballs: - Browser - Integrations - Tracing - WASM Additionally, the script that would formerly be called `postbuild.ts` is now `prepack.ts` and it runs first when executing `yarn build:npm`, followed by the tarball packing procedure via npm. Exception: Tracing needs to have the modified package.json in the build dir for our Playwright integration tests, so `prepack.ts` is also executed after every build.
1 parent a064c7c commit 14b7962

30 files changed

+111
-69
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ jobs:
204204
name: ${{ github.sha }}
205205
path: |
206206
${{ github.workspace }}/packages/browser/build/bundles/**
207-
${{ github.workspace }}/packages/integrations/build/**
208-
${{ github.workspace }}/packages/tracing/build/**
207+
${{ github.workspace }}/packages/integrations/build/bundles/**
208+
${{ github.workspace }}/packages/tracing/build/bundles/**
209209
${{ github.workspace }}/packages/**/*.tgz
210210
${{ github.workspace }}/packages/serverless/dist-awslambda-layer/*.zip
211211

.size-limit.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ module.exports = [
2525
},
2626
{
2727
name: '@sentry/browser - Webpack (gzipped + minified)',
28-
path: 'packages/browser/build/esm/index.js',
28+
path: 'packages/browser/build/npm/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/build/esm/index.js',
35+
path: 'packages/browser/build/npm/esm/index.js',
3636
import: '{ init }',
3737
gzip: false,
3838
limit: '100 KB',
@@ -53,13 +53,13 @@ module.exports = [
5353
},
5454
{
5555
name: '@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified)',
56-
path: 'packages/tracing/build/bundle.tracing.min.js',
56+
path: 'packages/tracing/build/bundles/bundle.tracing.min.js',
5757
gzip: true,
5858
limit: '100 KB',
5959
},
6060
{
6161
name: '@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified)',
62-
path: 'packages/tracing/build/bundle.tracing.es6.min.js',
62+
path: 'packages/tracing/build/bundles/bundle.tracing.es6.min.js',
6363
gzip: true,
6464
limit: '100 KB',
6565
},

packages/browser/.npmignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Info: the paths in this file are specified so that they align with the file
22
# structure in `./build` where this file is copied to. This is done by the
3-
# postbuild script `sentry-javascript/scripts/postbuild.ts`.
3+
# prepack script `sentry-javascript/scripts/prepack.ts`.
44

55
*
66

7-
# TODO remove bundles in v7
8-
!/bundles/**/*
7+
# TODO remove bundles (which in the tarball are inside `build`) in v7
8+
!/build/**/*
99

1010
!/dist/**/*
1111
!/types/**/*

packages/browser/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"engines": {
1010
"node": ">=6"
1111
},
12-
"main": "build/dist/index.js",
13-
"module": "build/esm/index.js",
14-
"types": "build/types/index.d.ts",
12+
"main": "build/npm/dist/index.js",
13+
"module": "build/npm/esm/index.js",
14+
"types": "build/npm/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -44,7 +44,7 @@
4444
"webpack": "^4.30.0"
4545
},
4646
"scripts": {
47-
"build": "run-p build:cjs build:esm build:bundle build:types && ts-node ../../scripts/postbuild.ts",
47+
"build": "run-p build:cjs build:esm build:bundle build:types",
4848
"build:bundle": "rollup --config",
4949
"build:cjs": "tsc -p tsconfig.cjs.json",
5050
"build:dev": "run-p build:cjs build:esm build:types",
@@ -58,7 +58,7 @@
5858
"build:dev:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
5959
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
6060
"build:types:watch": "tsc -p tsconfig.types.json --watch",
61-
"build:npm": "npm pack ./build",
61+
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build/npm",
6262
"circularDepCheck": "madge --circular src/index.ts",
6363
"clean": "rimraf build coverage .rpt2_cache",
6464
"fix": "run-s fix:eslint fix:prettier",

packages/browser/test/integration/run.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function build() {
7373

7474
writeFile(
7575
'artifacts/dedupe.js',
76-
readFile('../../../integrations/build/dedupe.js').replace('//# sourceMappingURL=dedupe.js.map', '')
76+
readFile('../../../integrations/build/bundles/dedupe.js').replace('//# sourceMappingURL=dedupe.js.map', '')
7777
);
7878
concatFiles('artifacts/setup.js', ['artifacts/dedupe.js', 'common/utils.js', 'common/triggers.js', 'common/init.js']);
7979
rmdir('artifacts/dedupe.js');

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
2-
const Sentry = require('../../build/dist/index.js');
3-
const Integrations = require('../../../integrations/dist/dedupe.js');
2+
const Sentry = require('../../build/npm/dist/index.js');
3+
const Integrations = require('../../../integrations/build/npm/dist/dedupe.js');
44

55
// Init
66
Sentry.init({

packages/browser/tsconfig.cjs.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

packages/browser/tsconfig.esm.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

packages/browser/tsconfig.types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"declaration": true,
66
"declarationMap": true,
77
"emitDeclarationOnly": true,
8-
"outDir": "build/types"
8+
"outDir": "build/npm/types"
99
}
1010
}

packages/integration-tests/utils/generatePlugin.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ const useBundle = bundleKey && !useCompiledModule;
1717

1818
const BUNDLE_PATHS: Record<string, Record<string, string>> = {
1919
browser: {
20-
cjs: 'build/dist/index.js',
21-
esm: 'build/esm/index.js',
20+
cjs: 'build/npm/dist/index.js',
21+
esm: 'build/npm/esm/index.js',
2222
bundle_es5: 'build/bundles/bundle.js',
2323
bundle_es5_min: 'build/bundles/bundle.min.js',
2424
bundle_es6: 'build/bundles/bundle.es6.js',
2525
bundle_es6_min: 'build/bundles/bundle.es6.min.js',
2626
},
2727
tracing: {
28-
cjs: 'dist/index.js',
29-
esm: 'esm/index.js',
30-
bundle_es5: 'build/bundle.tracing.js',
31-
bundle_es5_min: 'build/bundle.tracing.min.js',
32-
bundle_es6: 'build/bundle.tracing.es6.js',
33-
bundle_es6_min: 'build/bundle.tracing.es6.min.js',
28+
cjs: 'build/npm/dist/index.js',
29+
esm: 'build/npm/esm/index.js',
30+
bundle_es5: 'build/bundles/bundle.tracing.js',
31+
bundle_es5_min: 'build/bundles/bundle.tracing.min.js',
32+
bundle_es6: 'build/bundles/bundle.tracing.es6.js',
33+
bundle_es6_min: 'build/bundles/bundle.tracing.es6.min.js',
3434
},
3535
};
3636

packages/integrations/.npmignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
# Info: the paths in this file are specified so that they align with the file
2+
# structure in `./build` where this file is copied to. This is done by the
3+
# prepack script `sentry-javascript/scripts/prepack.ts`.
4+
15
*
2-
!/dist/**/*
6+
7+
# TODO remove bundles (which in the tarball are inside `build`) in v7
38
!/build/**/*
9+
10+
!/dist/**/*
411
!/esm/**/*
12+
!/types/**/*

packages/integrations/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"publishConfig": {
1313
"access": "public"
1414
},
15-
"main": "dist/index.js",
16-
"module": "esm/index.js",
17-
"types": "build/types/index.d.ts",
15+
"main": "build/npm/dist/index.js",
16+
"module": "build/npm/esm/index.js",
17+
"types": "build/npm/types/index.d.ts",
1818
"dependencies": {
1919
"@sentry/types": "6.19.4",
2020
"@sentry/utils": "6.19.4",
@@ -38,7 +38,7 @@
3838
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
3939
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
4040
"build:types:watch": "tsc -p tsconfig.types.json --watch",
41-
"build:npm": "npm pack",
41+
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build/npm",
4242
"circularDepCheck": "madge --circular src/index.ts",
4343
"clean": "rimraf dist esm build coverage .rpt2_cache",
4444
"fix": "run-s fix:eslint fix:prettier",

packages/integrations/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const baseBundleConfig = makeBaseBundleConfig({
1212
isAddOn: true,
1313
jsVersion,
1414
licenseTitle: '@sentry/integrations',
15-
outputFileBase: `${file.replace('.ts', '')}${jsVersion === 'ES6' ? '.es6' : ''}`,
15+
outputFileBase: `bundles/${file.replace('.ts', '')}${jsVersion === 'ES6' ? '.es6' : ''}`,
1616
});
1717

1818
// TODO We only need `commonjs` for localforage (used in the offline plugin). Once that's fixed, this can come out.

packages/integrations/tsconfig.cjs.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

packages/integrations/tsconfig.esm.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

packages/integrations/tsconfig.types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"declaration": true,
66
"declarationMap": true,
77
"emitDeclarationOnly": true,
8-
"outDir": "build/types"
8+
"outDir": "build/npm/types"
99
}
1010
}

packages/tracing/.npmignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
# Info: the paths in this file are specified so that they align with the file
2+
# structure in `./build` where this file is copied to. This is done by the
3+
# prepack script `sentry-javascript/scripts/prepack.ts`.
4+
15
*
2-
!/dist/**/*
6+
7+
# TODO remove bundles (which in the tarball are inside `build`) in v7
38
!/build/**/*
9+
10+
!/dist/**/*
411
!/esm/**/*
12+
!/types/**/*

packages/tracing/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"engines": {
1010
"node": ">=6"
1111
},
12-
"main": "dist/index.js",
13-
"module": "esm/index.js",
14-
"types": "build/types/index.d.ts",
12+
"main": "build/npm/dist/index.js",
13+
"module": "build/npm/esm/index.js",
14+
"types": "build/npm/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -29,7 +29,7 @@
2929
"jsdom": "^16.2.2"
3030
},
3131
"scripts": {
32-
"build": "run-p build:cjs build:esm build:types build:bundle",
32+
"build": "run-p build:cjs build:esm build:types build:bundle && ts-node ../../scripts/prepack.ts #necessary for integration tests",
3333
"build:bundle": "rollup --config",
3434
"build:cjs": "tsc -p tsconfig.cjs.json",
3535
"build:dev": "run-p build:cjs build:esm build:types",
@@ -43,7 +43,7 @@
4343
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
4444
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
4545
"build:types:watch": "tsc -p tsconfig.types.json --watch",
46-
"build:npm": "npm pack",
46+
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build/npm",
4747
"clean": "rimraf dist esm build coverage",
4848
"circularDepCheck": "madge --circular src/index.ts",
4949
"fix": "run-s fix:eslint fix:prettier",

packages/tracing/rollup.config.js

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

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

packages/tracing/tsconfig.cjs.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

packages/tracing/tsconfig.esm.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

packages/tracing/tsconfig.types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"declaration": true,
66
"declarationMap": true,
77
"emitDeclarationOnly": true,
8-
"outDir": "build/types"
8+
"outDir": "build/npm/types"
99
}
1010
}

packages/wasm/.npmignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
# Info: the paths in this file are specified so that they align with the file
2+
# structure in `./build` where this file is copied to. This is done by the
3+
# prepack script `sentry-javascript/scripts/prepack.ts`.
4+
15
*
6+
27
!/dist/**/*
38
!/esm/**/*
4-
!/build/types/**/*
9+
!/types/**/*

packages/wasm/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"engines": {
1010
"node": ">=6"
1111
},
12-
"main": "dist/index.js",
13-
"module": "esm/index.js",
14-
"types": "build/types/index.d.ts",
12+
"main": "build/npm/dist/index.js",
13+
"module": "build/npm/esm/index.js",
14+
"types": "build/npm/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
1717
},
@@ -43,9 +43,9 @@
4343
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
4444
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
4545
"build:types:watch": "tsc -p tsconfig.types.json --watch",
46-
"build:npm": "npm pack",
46+
"build:npm": "ts-node ../../scripts/prepack.ts -skipBundleCopy && npm pack ./build/npm",
4747
"circularDepCheck": "madge --circular src/index.ts",
48-
"clean": "rimraf dist esm coverage *.js.map *.d.ts",
48+
"clean": "rimraf dist esm build coverage *.js.map *.d.ts",
4949
"fix": "run-s fix:eslint fix:prettier",
5050
"fix:eslint": "eslint . --format stylish --fix",
5151
"fix:prettier": "prettier --write \"{src,test,scripts}/**/*.ts\"",

packages/wasm/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const baseBundleConfig = makeBaseBundleConfig({
55
isAddOn: true,
66
jsVersion: 'es5',
77
licenseTitle: '@sentry/wasm',
8-
outputFileBase: 'wasm',
8+
outputFileBase: 'bundles/wasm',
99
});
1010

1111
export default makeConfigVariants(baseBundleConfig);

packages/wasm/test/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const app = express();
66
// Wasm Integration Tests Artifacts
77
app.use(express.static(path.resolve(__dirname, 'public')));
88
// Wasm Integration Bundle
9-
app.use(express.static(path.resolve(__dirname, '../build')));
9+
app.use(express.static(path.resolve(__dirname, '../build/bundles')));
1010
// Browser SDK Bundle
1111
app.use(express.static(path.resolve(__dirname, '../../browser/build/bundles')));
1212
app.listen(process.env.PORT);

packages/wasm/tsconfig.cjs.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

packages/wasm/tsconfig.esm.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

packages/wasm/tsconfig.types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"declaration": true,
66
"declarationMap": true,
77
"emitDeclarationOnly": true,
8-
"outDir": "build/types"
8+
"outDir": "build/npm/types"
99
}
1010
}

0 commit comments

Comments
 (0)