Skip to content

Commit 0045b5c

Browse files
committed
ref(build): introduce central build directory to packages with bundles
in this commit: * move browser npm build files to `build/npm` * adjust `postbuild.ts` for tmp copying of bundles into npm
1 parent a064c7c commit 0045b5c

File tree

9 files changed

+40
-24
lines changed

9 files changed

+40
-24
lines changed

.size-limit.js

+2-2
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',

packages/browser/.npmignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
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

+4-4
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
},
@@ -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": "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/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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ 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',

scripts/postbuild.ts

+25-9
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
*/
77

88
import * as fs from 'fs';
9-
9+
import * as fse from 'fs-extra';
1010
import * as path from 'path';
1111

12-
const BUILD_DIR = 'build';
12+
const NPM_BUILD_DIR = 'build/npm';
1313
const ASSETS = ['README.md', 'LICENSE', 'package.json', '.npmignore'];
1414
const ENTRY_POINTS = ['main', 'module', 'types'];
1515

1616
// check if build dir exists
1717
try {
18-
if (!fs.existsSync(path.resolve(BUILD_DIR))) {
19-
console.error(`Directory ${BUILD_DIR} DOES NOT exist`);
18+
if (!fs.existsSync(path.resolve(NPM_BUILD_DIR))) {
19+
console.error(`Directory ${NPM_BUILD_DIR} DOES NOT exist`);
2020
console.error("This script should only be executed after you've run `yarn build`.");
2121
process.exit(1);
2222
}
2323
} catch (error) {
24-
console.error(`Error while looking up directory ${BUILD_DIR}`);
24+
console.error(`Error while looking up directory ${NPM_BUILD_DIR}`);
2525
process.exit(1);
2626
}
2727

@@ -33,24 +33,40 @@ ASSETS.forEach(asset => {
3333
console.error(`Asset ${asset} does not exist.`);
3434
process.exit(1);
3535
}
36-
fs.copyFileSync(assetPath, path.resolve(BUILD_DIR, asset));
36+
fs.copyFileSync(assetPath, path.resolve(NPM_BUILD_DIR, asset));
3737
} catch (error) {
38-
console.error(`Error while copying ${asset} to ${BUILD_DIR}`);
38+
console.error(`Error while copying ${asset} to ${NPM_BUILD_DIR}`);
3939
process.exit(1);
4040
}
4141
});
4242

43+
// TODO remove in v7! Until then:
44+
// copy CDN bundles into npm dir to temporarily keep bundles in npm tarball
45+
// inside the tarball, they are located in `build/`
46+
const npmTmpBundlesPath = path.resolve(NPM_BUILD_DIR, 'build');
47+
const cdnBundlesPaht = path.resolve('build', 'bundles');
48+
try {
49+
if (!fs.existsSync(npmTmpBundlesPath)) {
50+
fs.mkdirSync(npmTmpBundlesPath);
51+
}
52+
fse.copy(cdnBundlesPaht, npmTmpBundlesPath);
53+
} catch (error) {
54+
console.error(`Error while tmp copying CDN bundles to ${NPM_BUILD_DIR}`);
55+
}
56+
// end remove
57+
4358
// package.json modifications
44-
const packageJsonPath = path.resolve(BUILD_DIR, 'package.json');
59+
const packageJsonPath = path.resolve(NPM_BUILD_DIR, 'package.json');
4560
const pkgJson: { [key: string]: unknown } = require(packageJsonPath);
4661

4762
// modify entry points to point to correct paths (i.e. strip out the build directory)
4863
ENTRY_POINTS.filter(entryPoint => pkgJson[entryPoint]).forEach(entryPoint => {
49-
pkgJson[entryPoint] = (pkgJson[entryPoint] as string).replace(`${BUILD_DIR}/`, '');
64+
pkgJson[entryPoint] = (pkgJson[entryPoint] as string).replace(`${NPM_BUILD_DIR}/`, '');
5065
});
5166

5267
delete pkgJson.scripts;
5368
delete pkgJson.volta;
69+
delete pkgJson.jest;
5470

5571
// write modified package.json to file (pretty-printed with 2 spaces)
5672
try {

0 commit comments

Comments
 (0)