Skip to content

Commit a4077d2

Browse files
committed
add build dir to @sentry/gatsby
1 parent 883ba49 commit a4077d2

File tree

6 files changed

+55
-6
lines changed

6 files changed

+55
-6
lines changed

packages/gatsby/.npmignore

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
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/**/*
10+
11+
# Gatsby specific
512
!gatsby-browser.js
613
!gatsby-node.js

packages/gatsby/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"engines": {
1414
"node": ">=6"
1515
},
16-
"main": "dist/index.js",
17-
"module": "esm/index.js",
16+
"main": "build/dist/index.js",
17+
"module": "build/esm/index.js",
1818
"types": "build/types/index.d.ts",
1919
"publishConfig": {
2020
"access": "public"
@@ -46,7 +46,7 @@
4646
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
4747
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
4848
"build:types:watch": "tsc -p tsconfig.types.json --watch",
49-
"build:npm": "npm pack",
49+
"build:npm": "ts-node ../../scripts/prepack.ts -noBundles && npm pack ./build",
5050
"circularDepCheck": "madge --circular src/index.ts",
5151
"clean": "rimraf dist esm build coverage",
5252
"fix": "run-s fix:eslint fix:prettier",

packages/gatsby/scripts/prepack.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable no-console */
2+
// DO NOT RUN this script yourself!
3+
// This is invoked from the main `prepack.ts` script in `sentry-javascript/scripts/prepack.ts`.
4+
import * as fs from 'fs';
5+
import * as path from 'path';
6+
7+
const BUILD_DIR = 'build';
8+
const PACKAGE_ASSETS = ['gatsby-browser.js', 'gatsby-node.js'];
9+
10+
// copy package-specific assets to build dir
11+
PACKAGE_ASSETS.forEach(asset => {
12+
const assetPath = path.resolve(asset);
13+
try {
14+
if (!fs.existsSync(assetPath)) {
15+
console.error(`Asset ${asset} does not exist.`);
16+
process.exit(1);
17+
}
18+
fs.copyFileSync(assetPath, path.resolve(BUILD_DIR, asset));
19+
} catch (error) {
20+
console.error(`Error while copying ${asset} to ${BUILD_DIR}`);
21+
}
22+
});

packages/gatsby/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/dist"
77
}
88
}

packages/gatsby/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/esm"
77
}
88
}

scripts/prepack.ts

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
the directory structure inside `build`.
77
*/
88

9+
import * as childProcess from 'child_process';
910
import * as fs from 'fs';
1011
import * as fse from 'fs-extra';
1112
import * as path from 'path';
@@ -88,4 +89,23 @@ try {
8889
process.exit(1);
8990
}
9091

92+
// execute package specific settings
93+
// 1. check if a package called `<package-root>/scripts/prepack.ts` exitsts
94+
// if yes, 2.) execute that script for things that are package-specific
95+
const packagePrepackPath = path.resolve('scripts', 'prepack.ts');
96+
try {
97+
if (fs.existsSync(packagePrepackPath)) {
98+
const proc = childProcess.fork(packagePrepackPath);
99+
proc.on('exit', code => {
100+
if (code !== 0) {
101+
console.error(`Error while executing ${packagePrepackPath.toString()}`);
102+
process.exit(1);
103+
}
104+
});
105+
}
106+
} catch (error) {
107+
console.error(`Error while trying to access ${packagePrepackPath.toString()}`);
108+
process.exit(1);
109+
}
110+
91111
console.log(`\nSuccessfully finished prepack commands for ${pkgJson.name}\n`);

0 commit comments

Comments
 (0)