Skip to content

Commit

Permalink
ref(build): Introduce central build directory to packages with bund…
Browse files Browse the repository at this point in the history
…les (#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.
  • Loading branch information
Lms24 committed Apr 5, 2022
1 parent a064c7c commit 14b7962
Show file tree
Hide file tree
Showing 30 changed files with 111 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
},
Expand Down
6 changes: 3 additions & 3 deletions packages/browser/.npmignore
Original file line number Diff line number Diff line change
@@ -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/**/*
Expand Down
10 changes: 5 additions & 5 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/test/integration/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/test/package/test-code.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

"compilerOptions": {
"module": "commonjs",
"outDir": "build/dist",
"outDir": "build/npm/dist"
}
}
2 changes: 1 addition & 1 deletion packages/browser/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

"compilerOptions": {
"module": "es6",
"outDir": "build/esm",
"outDir": "build/npm/esm"
}
}
2 changes: 1 addition & 1 deletion packages/browser/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/types"
"outDir": "build/npm/types"
}
}
16 changes: 8 additions & 8 deletions packages/integration-tests/utils/generatePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ const useBundle = bundleKey && !useCompiledModule;

const BUNDLE_PATHS: Record<string, Record<string, string>> = {
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',
},
};

Expand Down
10 changes: 9 additions & 1 deletion packages/integrations/.npmignore
Original file line number Diff line number Diff line change
@@ -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/**/*
8 changes: 4 additions & 4 deletions packages/integrations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

"compilerOptions": {
"module": "commonjs",
"outDir": "dist"
"outDir": "build/npm/dist"
}
}
2 changes: 1 addition & 1 deletion packages/integrations/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

"compilerOptions": {
"module": "es6",
"outDir": "esm"
"outDir": "build/npm/esm"
}
}
2 changes: 1 addition & 1 deletion packages/integrations/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/types"
"outDir": "build/npm/types"
}
}
10 changes: 9 additions & 1 deletion packages/tracing/.npmignore
Original file line number Diff line number Diff line change
@@ -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/**/*
10 changes: 5 additions & 5 deletions packages/tracing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

"compilerOptions": {
"module": "commonjs",
"outDir": "dist"
"outDir": "build/npm/dist"
}
}
2 changes: 1 addition & 1 deletion packages/tracing/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

"compilerOptions": {
"module": "es6",
"outDir": "esm"
"outDir": "build/npm/esm"
}
}
2 changes: 1 addition & 1 deletion packages/tracing/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/types"
"outDir": "build/npm/types"
}
}
7 changes: 6 additions & 1 deletion packages/wasm/.npmignore
Original file line number Diff line number Diff line change
@@ -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/**/*
10 changes: 5 additions & 5 deletions packages/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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\"",
Expand Down
2 changes: 1 addition & 1 deletion packages/wasm/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const baseBundleConfig = makeBaseBundleConfig({
isAddOn: true,
jsVersion: 'es5',
licenseTitle: '@sentry/wasm',
outputFileBase: 'wasm',
outputFileBase: 'bundles/wasm',
});

export default makeConfigVariants(baseBundleConfig);
2 changes: 1 addition & 1 deletion packages/wasm/test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion packages/wasm/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

"compilerOptions": {
"module": "commonjs",
"outDir": "dist"
"outDir": "build/npm/dist"
}
}
2 changes: 1 addition & 1 deletion packages/wasm/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

"compilerOptions": {
"module": "es6",
"outDir": "esm"
"outDir": "build/npm/esm"
}
}
2 changes: 1 addition & 1 deletion packages/wasm/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/types"
"outDir": "build/npm/types"
}
}

0 comments on commit 14b7962

Please sign in to comment.