Skip to content

Commit

Permalink
fix(deno): Publish from build directory (#12773)
Browse files Browse the repository at this point in the history
In #12700 I adjusted
the prepack script to bring back the build directory, but I forgot to
adjust `npm pack X` to make sure we pack the tarball from the `build`
directory. This patch fixes that.
  • Loading branch information
AbhiPrasad authored Jul 5, 2024
1 parent eedd7c0 commit 0bad43b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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": "node ./scripts/prepack.js && yalc publish --push --sig"
"yalc:publish": "node ./scripts/prepack.js && yalc publish build --push --sig"
},
"volta": {
"extends": "../../package.json"
Expand Down
20 changes: 18 additions & 2 deletions packages/deno/scripts/prepack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0bad43b

Please sign in to comment.