-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust publish process to use "dist" as the project root
These changes include a new script that is used to prepare the "dist" directory for publishing. This includes: - Copying a modified package.json into "dist", after it has been adjusted (remove "./dist" directory prefixes, remove un-needed package.json properties, and remove the private flag). - Copying the README.md into "dist". This script is now called as part of the "predeploy" script. The "deploy" script will now also cd into "dist" before publishing, so only the contents in "dist" will be published to npm (and "dist" will essentially serve as the published package root).
- Loading branch information
Showing
2 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// The Apollo Client source that is published to npm is located in the | ||
// "dist" directory. This utility script is called just before deploying | ||
// Apollo Client, to make sure the "dist" directory is prepared for publishing. | ||
// | ||
// This script will: | ||
// | ||
// - Copy the current root package.json into "dist" after adjusting it for | ||
// publishing. | ||
// - Copy the root README.md into "dist" | ||
|
||
const packageJson = require('../package.json'); | ||
const fs = require('fs'); | ||
|
||
// The root package.json is marked as private to prevent publishing | ||
// from happening in the root of the project. This sets the package back to | ||
// public so it can be published from the "dist" directory. | ||
packageJson.private = false; | ||
|
||
// Remove package.json items that we don't need to publish | ||
delete packageJson.scripts; | ||
delete packageJson.bundlesize; | ||
|
||
// The root package.json points to the CJS/ESM source in "dist", to support | ||
// on-going package development (e.g. running tests, supporting npm link, etc.). | ||
// When publishing from "dist" however, we need to update the package.json | ||
// to point to the files within the same directory. | ||
const distPackageJson = JSON.stringify( | ||
packageJson, | ||
(_key, value) => ( | ||
typeof value === 'string' ? value.replace(/\.\/dist\//, '') : value | ||
), | ||
2 | ||
); | ||
|
||
// Save the modified package.json to "dist" | ||
fs.writeFileSync(`${__dirname}/../dist/package.json`, distPackageJson); | ||
|
||
// Copy the README into "dist" | ||
fs.copyFileSync(`${__dirname}/../README.md`, `${__dirname}/../dist/README.md`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters