Skip to content

Commit 80ab1be

Browse files
committed
ref(build): convert postbuild.sh to node script
add `postbuild.ts` node script which can be run with ts-node to replace the bash script `postbuild.sh`. This is done to conform with our decision to change all bash scripts to node s.t. they can be run on any platform (incl. Windows). Furthermore, it gives us the flexibility to make more adjustments that are harder to code/read in bash. * clone behaviour of `postbuild.sh` * add removal of `volta` and `scripts` properties in copied package.json * adjust calls to postbuild.sh to node script * adjust reference in comment to node script
1 parent faaacb8 commit 80ab1be

File tree

4 files changed

+48
-42
lines changed

4 files changed

+48
-42
lines changed

packages/browser/.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Info: the paths in this file are adjusted to match once this
22
# file is copied to `./build`. This is done by a postbuild script
3-
# located in sentry-javascript/scripts/postbuild.sh
3+
# located in sentry-javascript/scripts/postbuild.ts
44

55
*
66

packages/browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"webpack": "^4.30.0"
4545
},
4646
"scripts": {
47-
"build": "run-p build:cjs build:esm build:bundle build:types && bash ../../scripts/postbuild.sh",
47+
"build": "run-p build:cjs build:esm build:bundle build:types && ts-node ../../scripts/postbuild.ts",
4848
"build:bundle": "rollup --config",
4949
"build:cjs": "tsc -p tsconfig.cjs.json",
5050
"build:dev": "run-p build:cjs build:esm build:types",

scripts/postbuild.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

scripts/postbuild.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
This script prepares the central `build` directory for NPM package creation.
3+
It first copies all non-code files into the `build` directory, including `package.json` which
4+
is edited to adjust entry point paths. These corrections are performed so that they align with
5+
the directory structure inside `build`.
6+
*/
7+
8+
import * as fs from 'fs';
9+
10+
const BUILD_DIR = 'build';
11+
const ASSETS = ['README.md', 'LICENSE', 'package.json', '.npmignore'];
12+
const ENTRY_POINTS = ['main', 'module', 'types'];
13+
14+
// check if build dirs exists
15+
if (!fs.existsSync(BUILD_DIR)) {
16+
console.error(`Directory ${BUILD_DIR} DOES NOT exist`);
17+
console.error("This script should only be executed after you've run `yarn build`.");
18+
process.exit(1);
19+
}
20+
21+
// copy non-code assets to build dir
22+
ASSETS.forEach(asset => {
23+
if (!fs.existsSync(asset)) {
24+
console.error(`Asset ${asset} does not exist.`);
25+
process.exit(1);
26+
}
27+
fs.copyFileSync(asset, `${BUILD_DIR}/${asset}`);
28+
});
29+
30+
// package.json modifications
31+
const packageJsonPath = `${process.cwd()}/${BUILD_DIR}/package.json`;
32+
const pkg: { [key: string]: string } = require(packageJsonPath);
33+
34+
// modify entry points to point to correct paths (i.e. delete the build directory)
35+
ENTRY_POINTS.filter(entryPoint => !!pkg[entryPoint]).forEach(entryPoint => {
36+
pkg[entryPoint] = pkg[entryPoint].replace(`${BUILD_DIR}/`, '');
37+
});
38+
39+
// TODO decide if we want this:
40+
delete pkg.scripts;
41+
delete pkg.volta;
42+
43+
// write modified package.json to file
44+
fs.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2));
45+
46+
console.log('Successfully finishied postbuild commands');

0 commit comments

Comments
 (0)