From 1e40e59b7b9101d5f099fea7f934541cfe7267f1 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 4 Jul 2024 12:02:37 -0400 Subject: [PATCH] fix(deno): Publish from build directory --- packages/deno/package.json | 4 ++-- packages/deno/scripts/prepack.js | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/deno/package.json b/packages/deno/package.json index 4451a454cea2..36bdd552173f 100644 --- a/packages/deno/package.json +++ b/packages/deno/package.json @@ -41,7 +41,7 @@ "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": "node ./scripts/prepack.js && npm pack", + "build:tarball": "node ./scripts/prepack.js && npm pack ./build", "circularDepCheck": "madge --circular src/index.ts", "clean": "rimraf build build-types build-test coverage sentry-deno-*.tgz", "prefix": "yarn deno-types", @@ -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": "node ./scripts/prepack.js && yalc publish --push --sig" + "yalc:publish": "node ./scripts/prepack.js && yalc publish build --push --sig" }, "volta": { "extends": "../../package.json" diff --git a/packages/deno/scripts/prepack.js b/packages/deno/scripts/prepack.js index 19422f912715..6c7db2bc9878 100644 --- a/packages/deno/scripts/prepack.js +++ b/packages/deno/scripts/prepack.js @@ -18,6 +18,8 @@ const ENTRY_POINTS = ['main', 'module', 'types', 'browser']; const EXPORT_MAP_ENTRY_POINT = 'exports'; const TYPES_VERSIONS_ENTRY_POINT = 'typesVersions'; +const ASSETS = ['README.md', 'LICENSE', 'package.json', '.npmignore']; + const PACKAGE_JSON = 'package.json'; /** @@ -52,11 +54,25 @@ if (!fs.existsSync(path.resolve(BUILD_DIR))) { process.exit(1); } +const buildDirContents = fs.readdirSync(path.resolve(BUILD_DIR)); + +// copy non-code assets to build dir +ASSETS.forEach(asset => { + const assetPath = path.resolve(asset); + if (fs.existsSync(assetPath)) { + const destinationPath = path.resolve(BUILD_DIR, path.basename(asset)); + console.log(`Copying ${path.basename(asset)} to ${path.relative('../..', destinationPath)}.`); + fs.copyFileSync(assetPath, destinationPath); + } +}); + // package.json modifications +const newPackageJsonPath = path.resolve(BUILD_DIR, PACKAGE_JSON); + /** * @type {PackageJson} */ -const newPkgJson = { ...pkgJson }; +const newPkgJson = 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 => { @@ -100,7 +116,7 @@ if (newPkgJson[TYPES_VERSIONS_ENTRY_POINT]) { }); } -const newPackageJsonPath = path.resolve(BUILD_DIR, PACKAGE_JSON); +newPkgJson.files = buildDirContents; // write modified package.json to file (pretty-printed with 2 spaces) try {