Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
ref(build): Add central build directory to packages without CDN bundles (Part 1)#4854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
67e5952
adjust `prepack.ts` to distinguish between packages with/-out bundles
Lms24 883ba49
add build dir to `@sentry/core`
Lms24 92c07de
add build dir to `@sentry/gatsby`
Lms24 f03d3b6
add build dir to `@sentry/hub`
Lms24 25ff8a6
add build dir to `@sentry/minimal`
Lms24 0a56148
prepack: use dynamic imports instead of child process
Lms24 356775d
adjust prepack.ts to exit with error when package-specific prepack.ts…
Lms24 c0cf355
apply review suggestions
Lms24 d70d4ef
change variable name, add error message
Lms24 f918c59
Update scripts/prepack.ts
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/**/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,6 @@ | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "outDir": "dist" | ||
| "outDir": "build/dist" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,6 @@ | ||
| "compilerOptions": { | ||
| "module": "es6", | ||
| "outDir": "esm" | ||
| "outDir": "build/esm" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| # 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/**/* | ||
| # Gatsby specific | ||
| !gatsby-browser.js | ||
| !gatsby-node.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* eslint-disable no-console */ | ||
| // DO NOT RUN this script yourself! | ||
| // This is invoked from the main `prepack.ts` script in `sentry-javascript/scripts/prepack.ts`. | ||
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| const PACKAGE_ASSETS = ['gatsby-browser.js', 'gatsby-node.js']; | ||
| export function prepack(buildDir: string): boolean { | ||
| // copy package-specific assets to build dir | ||
| return PACKAGE_ASSETS.every(asset => { | ||
| const assetPath = path.resolve(asset); | ||
| try { | ||
| if (!fs.existsSync(assetPath)) { | ||
| console.error(`Asset ${asset} does not exist.`); | ||
| return false; | ||
| } | ||
| fs.copyFileSync(assetPath, path.resolve(buildDir, asset)); | ||
| } catch (error) { | ||
| console.error(`Error while copying ${asset} to ${buildDir}`); | ||
| return false; | ||
| } | ||
| return true; | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,6 @@ | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "outDir": "dist" | ||
| "outDir": "build/dist" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,6 @@ | ||
| "compilerOptions": { | ||
| "module": "es6", | ||
| "outDir": "esm" | ||
| "outDir": "build/esm" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/**/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,6 @@ | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "outDir": "dist" | ||
| "outDir": "build/dist" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,6 @@ | ||
| "compilerOptions": { | ||
| "module": "es6", | ||
| "outDir": "esm" | ||
| "outDir": "build/esm" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/**/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,6 @@ | ||
| "compilerOptions": { | ||
| "module": "commonjs", | ||
| "outDir": "dist" | ||
| "outDir": "build/dist" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3,6 +3,6 @@ | ||
| "compilerOptions": { | ||
| "module": "es6", | ||
| "outDir": "esm" | ||
| "outDir": "build/esm" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11,18 +11,23 @@ import * as fse from 'fs-extra'; | ||
| import * as path from 'path'; | ||
| const NPM_BUILD_DIR = 'build/npm'; | ||
| const BUILD_DIR = 'build'; | ||
| const ASSETS = ['README.md', 'LICENSE', 'package.json', '.npmignore']; | ||
| const ENTRY_POINTS = ['main', 'module', 'types']; | ||
| const packageWithBundles = !process.argv.includes('-noBundles'); | ||
| const buildDir = packageWithBundles ? NPM_BUILD_DIR : BUILD_DIR; | ||
| // check if build dir exists | ||
| try { | ||
| if (!fs.existsSync(path.resolve(NPM_BUILD_DIR))) { | ||
| console.error(`Directory ${NPM_BUILD_DIR} DOES NOT exist`); | ||
| if (!fs.existsSync(path.resolve(buildDir))) { | ||
| console.error(`Directory ${buildDir} DOES NOT exist`); | ||
| console.error("This script should only be executed after you've run `yarn build`."); | ||
| process.exit(1); | ||
| } | ||
| } catch (error) { | ||
| console.error(`Error while looking up directory ${NPM_BUILD_DIR}`); | ||
| console.error(`Error while looking up directory ${buildDir}`); | ||
| process.exit(1); | ||
| } | ||
| @@ -34,9 +39,9 @@ ASSETS.forEach(asset => { | ||
| console.error(`Asset ${asset} does not exist.`); | ||
| process.exit(1); | ||
| } | ||
| fs.copyFileSync(assetPath, path.resolve(NPM_BUILD_DIR, asset)); | ||
| fs.copyFileSync(assetPath, path.resolve(buildDir, asset)); | ||
| } catch (error) { | ||
| console.error(`Error while copying ${asset} to ${NPM_BUILD_DIR}`); | ||
| console.error(`Error while copying ${asset} to ${buildDir}`); | ||
| process.exit(1); | ||
| } | ||
| }); | ||
| @@ -45,28 +50,30 @@ ASSETS.forEach(asset => { | ||
| // copy CDN bundles into npm dir to temporarily keep bundles in npm tarball | ||
| // inside the tarball, they are located in `build/` | ||
| // for now, copy it by default, unless explicitly forbidden via an command line arg | ||
| const tmpCopyBundles = !process.argv.includes('-skipBundleCopy'); | ||
| const tmpCopyBundles = packageWithBundles && !process.argv.includes('-skipBundleCopy'); | ||
| if (tmpCopyBundles) { | ||
| const npmTmpBundlesPath = path.resolve(NPM_BUILD_DIR, 'build'); | ||
| const npmTmpBundlesPath = path.resolve(buildDir, 'build'); | ||
| const cdnBundlesPath = path.resolve('build', 'bundles'); | ||
| try { | ||
| if (!fs.existsSync(npmTmpBundlesPath)) { | ||
| fs.mkdirSync(npmTmpBundlesPath); | ||
| } | ||
| void fse.copy(cdnBundlesPath, npmTmpBundlesPath); | ||
| } catch (error) { | ||
| console.error(`Error while tmp copying CDN bundles to ${NPM_BUILD_DIR}`); | ||
| console.error(`Error while tmp copying CDN bundles to ${buildDir}`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| // end remove | ||
| // package.json modifications | ||
| const packageJsonPath = path.resolve(NPM_BUILD_DIR, 'package.json'); | ||
| const packageJsonPath = path.resolve(buildDir, 'package.json'); | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| const pkgJson: { [key: string]: unknown } = require(packageJsonPath); | ||
| // modify entry points to point to correct paths (i.e. strip out the build directory) | ||
| ENTRY_POINTS.filter(entryPoint => pkgJson[entryPoint]).forEach(entryPoint => { | ||
| pkgJson[entryPoint] = (pkgJson[entryPoint] as string).replace(`${NPM_BUILD_DIR}/`, ''); | ||
| pkgJson[entryPoint] = (pkgJson[entryPoint] as string).replace(`${buildDir}/`, ''); | ||
| }); | ||
| delete pkgJson.scripts; | ||
| @@ -81,4 +88,34 @@ try { | ||
| process.exit(1); | ||
| } | ||
| console.log(`\nSuccessfully finished prepack commands for ${pkgJson.name}\n`); | ||
| async function runPackagePrepack(packagePrepackPath: string): Promise<void> { | ||
| const { prepack } = await import(packagePrepackPath); | ||
| if (prepack && typeof prepack === 'function') { | ||
| const isSuccess = prepack(buildDir); | ||
| if (!isSuccess) { | ||
| process.exit(1); | ||
| } | ||
| } else { | ||
| console.error(`Could not find a prepack function in ${packagePrepackPath}.`); | ||
| console.error( | ||
| 'Make sure, your package-specific prepack script exports `function prepack(buildDir: string): boolean`.', | ||
| ); | ||
| process.exit(1); | ||
| } | ||
Lms24 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| // execute package specific settings | ||
| // 1. check if a package called `<package-root>/scripts/prepack.ts` exitsts | ||
| // if yes, 2.) execute that script for things that are package-specific | ||
| void (async () => { | ||
| const packagePrepackPath = path.resolve('scripts', 'prepack.ts'); | ||
| try { | ||
| if (fs.existsSync(packagePrepackPath)) { | ||
| await runPackagePrepack(packagePrepackPath); | ||
| } | ||
| } catch (error) { | ||
| console.error(`Error while trying to access ${packagePrepackPath.toString()}`); | ||
| process.exit(1); | ||
| } | ||
| console.log(`\nSuccessfully finished prepack commands for ${pkgJson.name}\n`); | ||
| })(); | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.