GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — sentry-javascript/scripts/prepack.ts at develop · akaedu2012/sentry-javascript Expand file tree/ Copy pathprepack.tsMore file actions 98 lines (84 loc) · 3.75 KB / Copy pathprepack.tsFile metadata and controls98 lines (84 loc) · 3.75 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 /* eslint-disable no-console */ /* This script prepares the central `build` directory for NPM package creation. It first copies all non-code files into the `build` directory, including `package.json`, which is edited to adjust entry point paths. These corrections are performed so that the paths align with the directory structure inside `build`. */ import * as fs from 'fs'; import * as path from 'path'; const NPM_BUILD_DIR = 'build/npm'; const BUILD_DIR = 'build'; const NPM_IGNORE = fs.existsSync('.npmignore') ? '.npmignore' : '../../.npmignore'; const ASSETS = ['README.md', 'LICENSE', 'package.json', NPM_IGNORE]; const ENTRY_POINTS = ['main', 'module', 'types', 'browser']; const packageWithBundles = process.argv.includes('--bundles'); const buildDir = packageWithBundles ? NPM_BUILD_DIR : BUILD_DIR; // eslint-disable-next-line @typescript-eslint/no-var-requires const pkgJson: { [key: string]: unknown } = require(path.resolve('package.json')); // check if build dir exists if (!fs.existsSync(path.resolve(buildDir))) { console.error(`\nERROR: Directory '${buildDir}' does not exist in ${pkgJson.name}.`); console.error("This script should only be executed after you've run `yarn build`."); process.exit(1); } // copy non-code assets to build dir ASSETS.forEach(asset => { const assetPath = path.resolve(asset); if (!fs.existsSync(assetPath)) { console.error(`\nERROR: Asset '${asset}' does not exist.`); process.exit(1); } const destinationPath = path.resolve(buildDir, path.basename(asset)); console.log(`Copying ${path.basename(asset)} to ${path.relative('../..', destinationPath)}.`); fs.copyFileSync(assetPath, destinationPath); }); // package.json modifications const newPackageJsonPath = path.resolve(buildDir, 'package.json'); // eslint-disable-next-line @typescript-eslint/no-var-requires const newPkgJson: { [key: string]: unknown } = require(newPackageJsonPath); // modify entry points to point to correct paths (i.e. strip out the build directory) ENTRY_POINTS.filter(entryPoint => newPkgJson[entryPoint]).forEach(entryPoint => { newPkgJson[entryPoint] = (newPkgJson[entryPoint] as string).replace(`${buildDir}/`, ''); }); delete newPkgJson.scripts; delete newPkgJson.volta; delete newPkgJson.jest; // write modified package.json to file (pretty-printed with 2 spaces) try { fs.writeFileSync(newPackageJsonPath, JSON.stringify(newPkgJson, null, 2)); } catch (error) { console.error(`\nERROR: Error while writing modified 'package.json' to disk in ${pkgJson.name}:\n`, error); process.exit(1); } 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(`\nERROR: Could not find a \`prepack\` function in './scripts/prepack.ts' in ${pkgJson.name}.`); console.error( 'Make sure your package-specific prepack script exports `function prepack(buildDir: string): boolean`.', ); process.exit(1); } } // execute package specific settings // 1. check if a script called `<package-root>/scripts/prepack.ts` exists // if yes, 2.) execute that script for things that are package-specific async function runPackageSpecificScripts(): Promise<void> { const packagePrepackPath = path.resolve('scripts', 'prepack.ts'); try { if (fs.existsSync(packagePrepackPath)) { await runPackagePrepack(packagePrepackPath); } } catch (error) { console.error(`\nERROR: Error while trying to load and run ./scripts/prepack.ts in ${pkgJson.name}:\n`, error); process.exit(1); } console.log(`\nSuccessfully finished prepack commands for ${pkgJson.name}\n`); } void runPackageSpecificScripts(); |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |