Skip to content
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.

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

fix(deno): Publish from build directory #12773

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading