8000 ref(build): Add central `build` directory to packages without CDN bun… · MShineRay/sentry-javascript@329e033 · GitHub
[go: up one dir, main page]

Skip to content

Commit 329e033

Browse files
Lms24AbhiPrasad
andauthored
ref(build): Add central build directory to packages without CDN bundles (Part 1) (getsentry#4854)
This PR is part 1 of adding the `build` directory to packages _without_ CDN bundles. It is split into two parts to make reviewing easier. It covers the following packages: * Core * Gatsby * Hub * Minimal Additionally, it adjusts `prepack.ts` to handle both kinds of packages (with/without CDN bundles) via a CL argument. For the Gatsby SDK, additional actions have to be performed which are only relevant for this package. Therefore, `prepack.ts` now supports calling a package-specific `prepack.ts` file located in `<package>/scripts/prepack.ts`. While the tarball structure is identical to the structure in getsentry#4838 (except for temporary CDN bundles), the `build` directory structure is simplified due to the fact that there are no CDN bundles or legacy NPM packages to be added to it. Therefore we can reduce one hierarchy level, resulting in the following structure: ``` <sdk>/ ├─ build/ │ ├─ cjs/ // dist until v7 │ │ ├─ CJS modules (+maps) │ ├─ esm/ │ │ ├─ ES6 modules (+maps) │ ├─ types/ │ │ ├─ *.d.ts files (+maps) │ ├─ package.json │ ├─ LICENSE │ ├─ README.md ├─ ... ``` Co-authored-by: Abhijeet Prasad <aprasad@sentry.io>
1 parent eb11979 commit 329e033

19 files changed

+127
-38
lines changed

packages/core/.npmignore

Lines changed: 6 additions & 1 deletion
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/core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"engines": {
1010
"node": ">=6"
1111
},
12-
"main": "dist/index.js",
13-
"module": "esm/index.js",
12+
"main": "build/dist/index.js",
13+
"module": "build/esm/index.js",
1414
"types": "build/types/index.d.ts",
1515
"publishConfig": {
1616
"access": "public"
@@ -35,9 +35,9 @@
3535
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
3636
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
3737
"build:types:watch": "tsc -p tsconfig.types.json --watch",
38-
"build:npm": "npm pack",
38+
"build:npm": "ts-node ../../scripts/prepack.ts -noBundles && npm pack ./build",
3939
"circularDepCheck": "madge --circular src/index.ts",
40-
"clean": "rimraf dist esm coverage",
40+
"clean": "rimraf dist esm build coverage",
4141
"fix": "run-s fix:eslint fix:prettier",
4242
"fix:eslint": "eslint . --format stylish --fix",
4343
"fix:prettier": "prettier --write \"{src,test,scripts}/**/*.ts\"",

packages/core/tsconfig.cjs.json

Lines changed: 1 addition & 1 deletion
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/core/tsconfig.esm.json

Lines changed: 1 addition & 1 deletion
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
}

packages/gatsby/.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ module.exports = {
66
parserOptions: {
77
jsx: true,
88
},
9+
// ignoring the package-specific prepack script here b/c it is not
10+
// covered by a `tsconfig` which makes eslint throw an error
11+
ignorePatterns: ['scripts/prepack.ts'],
912
extends: ['../../.eslintrc.js'],
1013
};

packages/gatsby/.npmignore

Lines changed: 8 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

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

packages/gatsby/tsconfig.cjs.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)
0