Skip to content

Commit 0bad43b

Browse files
authored
fix(deno): Publish from build directory (#12773)
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.
1 parent eedd7c0 commit 0bad43b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

packages/deno/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"build:types": "run-s deno-types build:types:tsc build:types:bundle",
4242
"build:types:tsc": "tsc -p tsconfig.types.json",
4343
"build:types:bundle": "rollup -c rollup.types.config.mjs",
44-
"build:tarball": "node ./scripts/prepack.js && npm pack",
44+
"build:tarball": "node ./scripts/prepack.js && npm pack ./build",
4545
"circularDepCheck": "madge --circular src/index.ts",
4646
"clean": "rimraf build build-types build-test coverage sentry-deno-*.tgz",
4747
"prefix": "yarn deno-types",
@@ -55,7 +55,7 @@
5555
"test:types": "deno check ./build/index.mjs",
5656
"test:unit": "deno test --allow-read --allow-run",
5757
"test:unit:update": "deno test --allow-read --allow-write --allow-run -- --update",
58-
"yalc:publish": "node ./scripts/prepack.js && yalc publish --push --sig"
58+
"yalc:publish": "node ./scripts/prepack.js && yalc publish build --push --sig"
5959
},
6060
"volta": {
6161
"extends": "../../package.json"

packages/deno/scripts/prepack.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const ENTRY_POINTS = ['main', 'module', 'types', 'browser'];
1818
const EXPORT_MAP_ENTRY_POINT = 'exports';
1919
const TYPES_VERSIONS_ENTRY_POINT = 'typesVersions';
2020

21+
const ASSETS = ['README.md', 'LICENSE', 'package.json', '.npmignore'];
22+
2123
const PACKAGE_JSON = 'package.json';
2224

2325
/**
@@ -52,11 +54,25 @@ if (!fs.existsSync(path.resolve(BUILD_DIR))) {
5254
process.exit(1);
5355
}
5456

57+
const buildDirContents = fs.readdirSync(path.resolve(BUILD_DIR));
58+
59+
// copy non-code assets to build dir
60+
ASSETS.forEach(asset => {
61+
const assetPath = path.resolve(asset);
62+
if (fs.existsSync(assetPath)) {
63+
const destinationPath = path.resolve(BUILD_DIR, path.basename(asset));
64+
console.log(`Copying ${path.basename(asset)} to ${path.relative('../..', destinationPath)}.`);
65+
fs.copyFileSync(assetPath, destinationPath);
66+
}
67+
});
68+
5569
// package.json modifications
70+
const newPackageJsonPath = path.resolve(BUILD_DIR, PACKAGE_JSON);
71+
5672
/**
5773
* @type {PackageJson}
5874
*/
59-
const newPkgJson = { ...pkgJson };
75+
const newPkgJson = require(newPackageJsonPath);
6076

6177
// modify entry points to point to correct paths (i.e. strip out the build directory)
6278
ENTRY_POINTS.filter(entryPoint => newPkgJson[entryPoint]).forEach(entryPoint => {
@@ -100,7 +116,7 @@ if (newPkgJson[TYPES_VERSIONS_ENTRY_POINT]) {
100116
});
101117
}
102118

103-
const newPackageJsonPath = path.resolve(BUILD_DIR, PACKAGE_JSON);
119+
newPkgJson.files = buildDirContents;
104120

105121
// write modified package.json to file (pretty-printed with 2 spaces)
106122
try {

0 commit comments

Comments
 (0)