Skip to content

Commit

Permalink
Update build scripts for recoil-relay (#1799)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1799

Update package build scripts for `recoil-relay`

Reviewed By: mondaychen

Differential Revision: D36429965

fbshipit-source-id: 60f984dcc987ae3468a24a563be225bbdcc644b2
  • Loading branch information
drarmstr authored and facebook-github-bot committed May 31, 2022
1 parent 530ef77 commit 4c31068
Show file tree
Hide file tree
Showing 18 changed files with 802 additions and 797 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ package-lock.json
/docs

# Generated files for recoil-relay unit tests
recoil-relay/__tests__/mock-graphql/__generated__
packages/recoil-relay/__tests__/mock-graphql/__generated__
2 changes: 1 addition & 1 deletion CHANGELOG-recoil-relay.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
## UPCOMING
**_Add new changes here as they land_**

## 0.1.0 (2022-05)
## 0.1.0 (2022-06)

Initial open source release
2 changes: 1 addition & 1 deletion CHANGELOG-recoil-sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
## UPCOMING
**_Add new changes here as they land_**

## 0.1.0 (2022-05)
## 0.1.0 (2022-06)

Initial open source release
4 changes: 3 additions & 1 deletion CHANGELOG-recoil.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
## UPCOMING
**_Add new changes here as they land_**

## 0.7.3 (2022-06-01)

- Atom effects can initialize or set atoms to wrapped values (#1681)
- Add `parentStoreID_UNSTABLE` to atom effects. This will match up with the store that the current store was cloned from, such as the host `<RecoilRoot>` store for `useRecoilCallback()` snapshots. (#1744)
- Add `parentStoreID_UNSTABLE` to atom effects which is the ID of the parent store it cloned from, such as the host `<RecoilRoot>` store for `useRecoilCallback()` snapshots. (#1744)
- Enable atoms and selectors to be used in family parameters (#1740)

## 0.7.2 (2022-04-13)
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG-refine.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

# Version numbers based on host Recoil Sync package

## 0.1.0 (2022-05)
## 0.1.0 (2022-06)

Initial open source release
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "recoil",
"version": "0.7.2",
"description": "Recoil - A state management library for React",
"main": "cjs/recoil.js",
"module": "es/recoil.js",
"react-native": "native/recoil.js",
"unpkg": "umd/recoil.js",
"main": "cjs/index.js",
"module": "es/index.js",
"react-native": "native/index.js",
"unpkg": "umd/index.js",
"files": [
"umd",
"es",
Expand All @@ -17,8 +17,9 @@
"license": "MIT",
"scripts": {
"prepare": "install-peers",
"build-all": "node scripts/build.mjs all",
"build": "rollup -c && node scripts/postbuild.js",
"build-TMP": "node scripts/build.mjs",
"pack": "node scripts/pack.mjs",
"test": "yarn relay && jest packages/*",
"format": "prettier --write \"./**/*.{js,md,json}\"",
"flow": "flow --show-all-errors",
Expand Down
18 changes: 18 additions & 0 deletions packages/recoil-relay/package-for-release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "recoil-relay",
"version": "0.1.0",
"description": "recoil-relay helps Recoil perform type safe and efficient queries using GraphQL with Relay",
"main": "cjs/index.js",
"module": "es/index.js",
"unpkg": "umd/index.js",
"types": "index.d.ts",
"files": ["umd", "es", "cjs", "index.d.ts"],
"repository": "https://github.com/facebookexperimental/Recoil.git",
"license": "MIT",
"dependencies": {},
"peerDependencies": {
"recoil": ">=0.7.3",
"react-relay": ">=13.2.0",
"relay-runtime": ">=13.2.0"
}
}
4 changes: 2 additions & 2 deletions packages/recoil-sync/package-for-release.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recoil-sync",
"version": "0.0.1-alpha.0",
"version": "0.1.0",
"description": "recoil-sync provides an add-on library to help synchronize Recoil state with external systems",
"main": "cjs/index.js",
"module": "es/index.js",
Expand All @@ -13,6 +13,6 @@
"transit-js": "^0.8.874"
},
"peerDependencies": {
"recoil": ">=0.7.0"
"recoil": ">=0.7.3"
}
}
10 changes: 5 additions & 5 deletions packages/recoil/package-for-release.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "recoil",
"version": "0.7.3-alpha.2",
"version": "0.7.3",
"description": "Recoil - A state management library for React",
"main": "cjs/recoil.js",
"module": "es/recoil.js",
"react-native": "native/recoil.js",
"unpkg": "umd/recoil.js",
"main": "cjs/index.js",
"module": "es/index.js",
"react-native": "native/index.js",
"unpkg": "umd/index.js",
"types": "index.d.ts",
"files": ["umd", "es", "cjs", "native", "index.d.ts"],
"repository": "https://github.com/facebookexperimental/Recoil.git",
Expand Down
6 changes: 3 additions & 3 deletions relay.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
// Configuration options accepted by the `relay-compiler` command-line tool and `babel-plugin-relay`.
src: "./packages/recoil-relay/__tests__",
schema: "./packages/recoil-relay/__tests__/mock-graphql/schema.graphql",
exclude: ["**/node_modules/**", "**/__mocks__/**", "**/__generated__/**"],
src: './packages/recoil-relay/__tests__',
schema: './packages/recoil-relay/__tests__/mock-graphql/schema.graphql',
exclude: ['**/node_modules/**', '**/__mocks__/**', '**/__generated__/**'],
}
209 changes: 72 additions & 137 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,191 +10,126 @@

import {rollup} from 'rollup';
import {
recoilInputOptions,
recoilSyncInputOptions,
createInputOption,
createOutputOption,
} from './rollup-configs.mjs';
import {exec} from 'child_process';
import * as fs from 'fs';
import {projectRootDir} from './project-root-dir.mjs';

const args = process.argv.slice(2);

if (args[0] === 'all') {
buildAll();
} else if (args[0] === 'recoil') {
buildRecoil();
}
import {createErrorHandler} from './utils.mjs';

// constants
const BUILD_TARGET = 'build';

function createErrorHandler(message) {
return err => {
if (err) {
console.error(`${message}\n`);
throw err;
}
};
const PACKAGES = {
recoil: {
inputFile: 'Recoil_index.js',
umdName: 'Recoil',
builds: {
common: ['cjs', 'es'],
dev: ['umd'],
prod: ['es-browsers', 'umd-prod'],
native: ['native'],
},
},
'recoil-sync': {
inputFile: 'RecoilSync_index.js',
umdName: 'RecoilSync',
builds: {
common: ['cjs', 'es'],
dev: ['umd'],
prod: ['es-browsers', 'umd-prod'],
},
},
'recoil-relay': {
inputFile: 'RecoilRelay_index.js',
umdName: 'RecoilRelay',
builds: {
common: ['cjs', 'es'],
dev: ['umd'],
prod: ['es-browsers', 'umd-prod'],
},
},
};

const args = process.argv.slice(2);
const target = args[0];
if (target === 'all' || target == null) {
buildAll();
} else {
if (PACKAGES[target] == null) {
throw new Error(`Unknown build target ${target}`);
}
buildPackage(target, PACKAGES[target]);
}

async function buildAll() {
console.log('Building all packages...');
await buildRecoil();
await buildRecoilSync();
}

async function buildRecoil() {
console.log('Building recoil...');
const createRecoilOutputOptions = type =>
createOutputOption(type, 'recoil', 'recoil', 'Recoil');
await build(
'recoil (common)',
recoilInputOptions.common,
['cjs', 'es'].map(createRecoilOutputOptions),
);
await build(
'recoil (dev)',
recoilInputOptions.dev,
['umd'].map(createRecoilOutputOptions),
);
await build(
'recoil (prod)',
recoilInputOptions.prod,
['es-browsers', 'umd-prod'].map(createRecoilOutputOptions),
);
await build(
'recoil (native)',
recoilInputOptions.native,
['native'].map(createRecoilOutputOptions),
);

console.log('Copying files...');
fs.copyFile(
`${projectRootDir}/packages/recoil/package-for-release.json`,
`${BUILD_TARGET}/recoil/package.json`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy package-for-release.json'),
);

fs.copyFile(
`${projectRootDir}/README.md`,
`${BUILD_TARGET}/recoil/README.md`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy README.md'),
);
fs.copyFile(
`${projectRootDir}/CHANGELOG-recoil.md`,
`${BUILD_TARGET}/recoil/CHANGELOG.md`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy CHANGELOG.md'),
);
fs.copyFile(
`${projectRootDir}/LICENSE`,
`${BUILD_TARGET}/recoil/LICENSE`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy LICENSE'),
);

console.log('Copying index.d.ts for TypeScript support...');
fs.copyFile(
`${projectRootDir}/typescript/index.d.ts`,
`${BUILD_TARGET}/recoil/index.d.ts`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy index.d.ts for recoil'),
);

console.log('Generating Flow type files...');
exec(
`npx flow-copy-source packages/recoil ${BUILD_TARGET}/recoil/cjs`,
err => {
createErrorHandler('Failed to copy recoil source files for flow types')(
err,
);
fs.rename(
`${BUILD_TARGET}/recoil/cjs/Recoil_index.js.flow`,
`${BUILD_TARGET}/recoil/cjs/recoil.js.flow`,
createErrorHandler('Failed to rename recoil.js.flow'),
);
},
);
console.log('Successfully built recoil!');
for (const [target, config] of Object.entries(PACKAGES)) {
await buildPackage(target, config);
}
}

async function buildRecoilSync() {
console.log('Building recoil-sync...');

const createRecoilSyncOutputOptions = type =>
createOutputOption(type, 'recoil-sync', 'index', 'RecoilSync');
await build(
'recoil-sync (common)',
recoilSyncInputOptions.common,
['cjs', 'es'].map(createRecoilSyncOutputOptions),
);
await build(
'recoil-sync (dev)',
recoilSyncInputOptions.dev,
['umd'].map(createRecoilSyncOutputOptions),
);
await build(
'recoil-sync (prod)',
recoilSyncInputOptions.prod,
['es-browsers', 'umd-prod'].map(createRecoilSyncOutputOptions),
);
async function buildPackage(target, config) {
console.log(`Building ${target}...`);
for (const [buildType, packageTypes] of Object.entries(config.builds)) {
await buildRollup(
`recoil (${buildType})`,
createInputOption(buildType, target, config.inputFile),
packageTypes.map(type => createOutputOption(type, target, config.umdName)));
}

console.log('Copying files...');
fs.copyFile(
`${projectRootDir}/packages/recoil-sync/package-for-release.json`,
`${BUILD_TARGET}/recoil-sync/package.json`,
`${projectRootDir}/packages/${target}/package-for-release.json`,
`${BUILD_TARGET}/${target}/package.json`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy package-for-release.json'),
);

fs.copyFile(
`${projectRootDir}/README-recoil-sync.md`,
`${BUILD_TARGET}/recoil-sync/README.md`,
`${projectRootDir}/README${target === 'recoil' ? '' : '-' + target}.md`,
`${BUILD_TARGET}/${target}/README.md`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy README.md'),
createErrorHandler(`Failed to copy README-${target}.md`),
);
fs.copyFile(
`${projectRootDir}/CHANGELOG-recoil-sync.md`,
`${BUILD_TARGET}/recoil-sync/CHANGELOG.md`,
`${projectRootDir}/CHANGELOG-${target}.md`,
`${BUILD_TARGET}/${target}/CHANGELOG.md`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy CHANGELOG.md'),
createErrorHandler(`Failed to copy CHANGELOG-${target}.md`),
);
fs.copyFile(
`${projectRootDir}/LICENSE`,
`${BUILD_TARGET}/recoil-sync/LICENSE`,
`${BUILD_TARGET}/${target}/LICENSE`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy LICENSE'),
);

console.log('Copying index.d.ts for TypeScript support...');
fs.copyFile(
`${projectRootDir}/typescript/recoil-sync.d.ts`,
`${BUILD_TARGET}/recoil-sync/index.d.ts`,
`${projectRootDir}/typescript/${target}.d.ts`,
`${BUILD_TARGET}/${target}/index.d.ts`,
fs.constants.COPYFILE_FICLONE,
createErrorHandler('Failed to copy recoil-sync.d.ts for recoil-sync'),
createErrorHandler(`Failed to copy ${target}.d.ts for TypeScript index.d.ts`),
);

console.log('Generating Flow type files...');
exec(
`npx flow-copy-source packages/recoil-sync ${BUILD_TARGET}/recoil-sync/cjs`,
`npx flow-copy-source packages/${target} ${BUILD_TARGET}/${target}/cjs`,
err => {
createErrorHandler('Failed to copy recoil source files for flow types')(
err,
);
createErrorHandler('Failed to copy source files for Flow types')(err);
fs.rename(
`${BUILD_TARGET}/recoil-sync/cjs/RecoilSync_index.js.flow`,
`${BUILD_TARGET}/recoil-sync/cjs/index.js.flow`,
createErrorHandler('Failed to rename RecoilSync_index.js.flow'),
`${BUILD_TARGET}/${target}/cjs/${config.inputFile}.flow`,
`${BUILD_TARGET}/${target}/cjs/${target}.js.flow`,
createErrorHandler(`Failed to rename ${target}.js.flow`),
);
},
);
console.log('Successfully built recoil-sync!');
console.log(`Successfully built ${target}!`);
}

async function build(name, inputOptions, outputOptionsList) {
async function buildRollup(name, inputOptions, outputOptionsList) {
try {
// create a bundle
const bundle = await rollup(inputOptions);
Expand Down
Loading

0 comments on commit 4c31068

Please sign in to comment.