Skip to content

Commit

Permalink
Adjust publish process to use "dist" as the project root
Browse files Browse the repository at this point in the history
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
hwillson committed Sep 24, 2019
1 parent ef6db11 commit 4c7af4e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
39 changes: 39 additions & 0 deletions config/prepareDist.js
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`);
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@apollo/client",
"version": "3.0.0-alpha.4",
"description": "A fully-featured caching GraphQL client.",
"private": true,
"keywords": [
"apollo",
"graphql",
Expand All @@ -12,11 +13,11 @@
],
"author": "opensource@apollographql.com",
"license": "MIT",
"main": "./lib/apollo-client.cjs.js",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"main": "./dist/apollo-client.cjs.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"sideEffects": [
"./lib/cache/inmemory/fixPolyfills.js"
"./dist/cache/inmemory/fixPolyfills.js"
],
"repository": {
"type": "git",
Expand All @@ -31,21 +32,22 @@
"build": "npx tsc",
"postbuild": "npm run bundle",
"watch": "npx tsc-watch --onSuccess \"npm run postbuild\"",
"clean": "npx rimraf -r lib coverage",
"clean": "npx rimraf -r dist coverage",
"test": "jest --config ./config/jest.config.js",
"test:ci": "npm run coverage -- --ci --maxWorkers=2 --reporters=default --reporters=jest-junit",
"test:watch": "jest --config ./config/jest.config.js --watch",
"bundle": "npx rollup -c ./config/rollup.config.js",
"coverage": "npx jest --config ./config/jest.config.js --verbose --coverage",
"coverage:upload": "npx codecov",
"bundlesize": "npm run build && bundlesize",
"predeploy": "npm run build",
"deploy": "npm publish --tag alpha"
"prepdist": "node ./config/prepareDist.js",
"predeploy": "npm run build && npm run prepdist",
"deploy": "cd dist && npm publish --tag alpha"
},
"bundlesize": [
{
"name": "apollo-client",
"path": "./lib/apollo-client.cjs.min.js",
"path": "./dist/apollo-client.cjs.min.js",
"maxSize": "21 kB"
}
],
Expand Down Expand Up @@ -98,8 +100,5 @@
},
"publishConfig": {
"access": "public"
},
"files": [
"lib"
]
}
}

0 comments on commit 4c7af4e

Please sign in to comment.