GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(deno): Add prepack for deno build by AbhiPrasad · Pull Request #12700 · getsentry/sentry-javascript

fix(deno): Add prepack for deno build #12700

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.

Sign up for GitHub

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
AbhiPrasad merged 2 commits into develop from abhi-fix-deno-output
Jul 2, 2024

Uh oh!

There was an error while loading. Please reload this page.

Merged

fix(deno): Add prepack for deno build #12700

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
7052d59
fix(deno): Add prepack for deno build
AbhiPrasad Jun 28, 2024
17c1a4d
use simpler script
AbhiPrasad Jul 2, 2024
File filter
Filter by extension


Clear filters
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

6 changes: 3 additions & 3 deletions 6 packages/deno/package.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
"build:types": "run-s deno-types build:types:tsc build:types:bundle",
"build:types:tsc": "tsc -p tsconfig.types.json",
"build:types:bundle": "rollup -c rollup.types.config.mjs",
"build:tarball": "npm pack",
"build:tarball": "node ./scripts/prepack.js && npm pack",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build build-types build-test coverage",
"clean": "rimraf build build-types build-test coverage sentry-deno-*.tgz",
"prefix": "yarn deno-types",
"fix": "eslint . --format stylish --fix",
"prelint": "yarn deno-types",
Expand All @@ -55,7 +55,7 @@
"test:types": "deno check ./build/index.mjs",
"test:unit": "deno test --allow-read --allow-run",
"test:unit:update": "deno test --allow-read --allow-write --allow-run -- --update",
"yalc:publish": "yalc publish --push --sig"
"yalc:publish": "node ./scripts/prepack.js && yalc publish --push --sig"
},
"volta": {
"extends": "../../package.json"
Expand Down
111 changes: 111 additions & 0 deletions 111 packages/deno/scripts/prepack.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/* 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`.
*
* TODO(v9): Remove this script and change the Deno SDK to import from build/X.
*/

const fs = require('node:fs');
const path = require('node:path');

const BUILD_DIR = 'build';

const ENTRY_POINTS = ['main', 'module', 'types', 'browser'];
const EXPORT_MAP_ENTRY_POINT = 'exports';
const TYPES_VERSIONS_ENTRY_POINT = 'typesVersions';

const PACKAGE_JSON = 'package.json';

/**
* @typedef {Record<(typeof ENTRY_POINTS)[number], string>} PackageJsonEntryPoints - an object containing module details
*/

/**
* @typedef {Record<string, string>} ConditionalExportEntryPoints - an object containing module details
*/

/**
* @typedef {Record<string, Record<string, string[]>>} TypeVersions - an object containing module details
*/

/**
* @typedef {Partial<ConditionalExportEntryPoints> & Record<string, Partial<ConditionalExportEntryPoints>>} PackageJsonExports - types for `package.json` exports
*/

/**
* @typedef {Record<string, unknown> & PackageJsonEntryPoints & {[EXPORT_MAP_ENTRY_POINT]: PackageJsonExports} & {[TYPES_VERSIONS_ENTRY_POINT]: TypeVersions}} PackageJson - types for `package.json`
*/

/**
* @type {PackageJson}
*/
const pkgJson = require(path.resolve(PACKAGE_JSON));

// check if build dir exists
if (!fs.existsSync(path.resolve(BUILD_DIR))) {
console.error(`\nERROR: Directory '${BUILD_DIR}' does not exist in ${pkgJson.name}.`);
console.error("This script should only be executed after you've run `yarn build`.");
process.exit(1);
}

// package.json modifications
/**
* @type {PackageJson}
*/
const newPkgJson = { ...pkgJson };

// 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].replace(`${BUILD_DIR}/`, '');
});

/**
* Recursively traverses the exports object and rewrites all string values to remove the build directory.
*
* @param {PackageJsonExports} exportsObject - the exports object to traverse
* @param {string} key - the key of the current exports object
*/
function rewriteConditionalExportEntryPoint(exportsObject, key) {
const exportsField = exportsObject[key];
if (!exportsField) {
return;
}

if (typeof exportsField === 'string') {
exportsObject[key] = exportsField.replace(`${BUILD_DIR}/`, '');
return;
}
Object.keys(exportsField).forEach(subfieldKey => {
rewriteConditionalExportEntryPoint(exportsField, subfieldKey);
});
}

if (newPkgJson[EXPORT_MAP_ENTRY_POINT]) {
Object.keys(newPkgJson[EXPORT_MAP_ENTRY_POINT]).forEach(key => {
rewriteConditionalExportEntryPoint(newPkgJson[EXPORT_MAP_ENTRY_POINT], key);
});
}

if (newPkgJson[TYPES_VERSIONS_ENTRY_POINT]) {
Object.entries(newPkgJson[TYPES_VERSIONS_ENTRY_POINT]).forEach(([key, val]) => {
newPkgJson[TYPES_VERSIONS_ENTRY_POINT][key] = Object.entries(val).reduce((acc, [key, val]) => {
const newKey = key.replace(`${BUILD_DIR}/`, '');
acc[newKey] = val.map(v => v.replace(`${BUILD_DIR}/`, ''));
return acc;
}, {});
});
}

const newPackageJsonPath = path.resolve(BUILD_DIR, PACKAGE_JSON);

// 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);
}
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.
You are visitor 01402775 — 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.