Skip to content

Commit

Permalink
format config folder
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Jul 31, 2023
1 parent ec805aa commit 25e2599
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 261 deletions.
4 changes: 0 additions & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ node_modules/
.yalc/
.next/

/config
config/*
!config/processInvariants.ts

/src/__tests__/ApolloClient.ts
/src/__tests__/__snapshots__/ApolloClient.ts.snap
/src/__tests__/__snapshots__/client.ts.snap
Expand Down
16 changes: 7 additions & 9 deletions config/bundlesize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ const minPath = join(__dirname, "..", minFile);
const gzipByteLen = gzipSync(readFileSync(minPath)).byteLength;
const overLimit = gzipByteLen > gzipBundleByteLengthLimit;

const message = `Minified + GZIP-encoded bundle size for ${
minFile
} = ${
bytes(gzipByteLen, { unit: "KB" })
}, ${
overLimit ? "exceeding" : "under"
} limit ${
bytes(gzipBundleByteLengthLimit, { unit: "KB" })
}`;
const message = `Minified + GZIP-encoded bundle size for ${minFile} = ${bytes(
gzipByteLen,
{ unit: "KB" }
)}, ${overLimit ? "exceeding" : "under"} limit ${bytes(
gzipBundleByteLengthLimit,
{ unit: "KB" }
)}`;

if (overLimit) {
throw new Error(message);
Expand Down
70 changes: 36 additions & 34 deletions config/entryPoints.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
const entryPoints = [
{ dirs: [], bundleName: "main" },
{ dirs: ['cache'] },
{ dirs: ['core'] },
{ dirs: ['dev'] },
{ dirs: ['errors'] },
{ dirs: ['link', 'batch'] },
{ dirs: ['link', 'batch-http'] },
{ dirs: ['link', 'context'] },
{ dirs: ['link', 'core'] },
{ dirs: ['link', 'error'] },
{ dirs: ['link', 'http'] },
{ dirs: ['link', 'persisted-queries'] },
{ dirs: ['link', 'retry'] },
{ dirs: ['link', 'remove-typename'] },
{ dirs: ['link', 'schema'] },
{ dirs: ['link', 'subscriptions'] },
{ dirs: ['link', 'utils'] },
{ dirs: ['link', 'ws'] },
{ dirs: ['react'] },
{ dirs: ['react', 'components'] },
{ dirs: ['react', 'context'] },
{ dirs: ['react', 'hoc'] },
{ dirs: ['react', 'hooks'] },
{ dirs: ['react', 'parser'] },
{ dirs: ['react', 'ssr'] },
{ dirs: ['testing'], extensions: [".js", ".jsx"] },
{ dirs: ['testing', 'core'] },
{ dirs: ['utilities'] },
{ dirs: ['utilities', 'globals'], sideEffects: true },
{ dirs: ["cache"] },
{ dirs: ["core"] },
{ dirs: ["dev"] },
{ dirs: ["errors"] },
{ dirs: ["link", "batch"] },
{ dirs: ["link", "batch-http"] },
{ dirs: ["link", "context"] },
{ dirs: ["link", "core"] },
{ dirs: ["link", "error"] },
{ dirs: ["link", "http"] },
{ dirs: ["link", "persisted-queries"] },
{ dirs: ["link", "retry"] },
{ dirs: ["link", "remove-typename"] },
{ dirs: ["link", "schema"] },
{ dirs: ["link", "subscriptions"] },
{ dirs: ["link", "utils"] },
{ dirs: ["link", "ws"] },
{ dirs: ["react"] },
{ dirs: ["react", "components"] },
{ dirs: ["react", "context"] },
{ dirs: ["react", "hoc"] },
{ dirs: ["react", "hooks"] },
{ dirs: ["react", "parser"] },
{ dirs: ["react", "ssr"] },
{ dirs: ["testing"], extensions: [".js", ".jsx"] },
{ dirs: ["testing", "core"] },
{ dirs: ["utilities"] },
{ dirs: ["utilities", "globals"], sideEffects: true },
];

const lookupTrie = Object.create(null);
entryPoints.forEach(info => {
entryPoints.forEach((info) => {
let node = lookupTrie;
info.dirs.forEach(dir => {
info.dirs.forEach((dir) => {
const dirs = node.dirs || (node.dirs = Object.create(null));
node = dirs[dir] || (dirs[dir] = { isEntry: false });
});
node.isEntry = true;
});

exports.forEach = function(callback, context) {
exports.forEach = function (callback, context) {
entryPoints.forEach(callback, context);
};

Expand Down Expand Up @@ -76,9 +76,11 @@ exports.check = function (id, parentId) {
return false;
}

console.warn(`Risky cross-entry-point nested import of ${id} in ${
partsAfterDist(parentId).join("/")
}`);
console.warn(
`Risky cross-entry-point nested import of ${id} in ${partsAfterDist(
parentId
).join("/")}`
);
}
}

Expand Down
20 changes: 11 additions & 9 deletions config/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import glob = require("glob");

export const distDir = path.resolve(__dirname, "..", "dist");

export function eachFile(dir: string, callback: (
absPath: string,
relPath: string,
) => any) {
export function eachFile(
dir: string,
callback: (absPath: string, relPath: string) => any
) {
const promises: Promise<any>[] = [];

return new Promise<void>((resolve, reject) => {
glob(`${dir.replace(/\\/g, '/')}/**/*.js`, (error, files) => {
glob(`${dir.replace(/\\/g, "/")}/**/*.js`, (error, files) => {
if (error) return reject(error);

files.sort().forEach(file => {
files.sort().forEach((file) => {
const relPath = path.relative(dir, file);

// Outside the distDir, somehow.
Expand All @@ -32,9 +32,11 @@ export function eachFile(dir: string, callback: (
// This file is not meant to be imported or processed.
if (relPath.endsWith("invariantErrorCodes.js")) return;

promises.push(new Promise(resolve => {
resolve(callback(file, relPath));
}));
promises.push(
new Promise((resolve) => {
resolve(callback(file, relPath));
})
);
});

resolve();
Expand Down
28 changes: 12 additions & 16 deletions config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ const defaults = {
},
snapshotFormat: {
escapeString: true,
printBasicPrototype: true
printBasicPrototype: true,
},
transform: {
'^.+\\.tsx?$': [
'ts-jest',
"^.+\\.tsx?$": [
"ts-jest",
{
diagnostics: {
warnOnly: process.env.TEST_ENV !== 'ci'
warnOnly: process.env.TEST_ENV !== "ci",
},
},
],
},
resolver: "ts-jest-resolver",
};

const ignoreTSFiles = '.ts$';
const ignoreTSXFiles = '.tsx$';
const ignoreTSFiles = ".ts$";
const ignoreTSXFiles = ".tsx$";

const react17TestFileIgnoreList = [
ignoreTSFiles,
// For now, we only support useSuspenseQuery with React 18, so no need to test
// it with React 17
'src/react/hooks/__tests__/useSuspenseQuery.test.tsx',
'src/react/hooks/__tests__/useBackgroundQuery.test.tsx'
]
"src/react/hooks/__tests__/useSuspenseQuery.test.tsx",
"src/react/hooks/__tests__/useBackgroundQuery.test.tsx",
];

const tsStandardConfig = {
...defaults,
displayName: 'Core Tests',
displayName: "Core Tests",
testPathIgnorePatterns: [ignoreTSXFiles],
}
};

// For both React (Jest) "projects", ignore core tests (.ts files) as they
// do not import React, to avoid running them twice.
Expand All @@ -65,9 +65,5 @@ const standardReact17Config = {
};

module.exports = {
projects: [
tsStandardConfig,
standardReact17Config,
standardReact18Config,
],
projects: [tsStandardConfig, standardReact17Config, standardReact18Config],
};
18 changes: 10 additions & 8 deletions config/postprocessDist.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { distDir } from './helpers.ts';
import fs from 'node:fs';
import path from 'node:path';
import { distDir } from "./helpers.ts";
import fs from "node:fs";
import path from "node:path";

const globalTypesFile = path.resolve(distDir, "utilities/globals/global.d.ts");
fs.writeFileSync(globalTypesFile,
fs.readFileSync(globalTypesFile, "utf8")
fs.writeFileSync(
globalTypesFile,
fs
.readFileSync(globalTypesFile, "utf8")
.split("\n")
.filter(line => line.trim() !== 'const __DEV__: boolean;')
.join("\n"),
.filter((line) => line.trim() !== "const __DEV__: boolean;")
.join("\n"),
"utf8"
);
);
13 changes: 3 additions & 10 deletions config/precheck.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
const {
lockfileVersion,
} = require("../package-lock.json");
const { lockfileVersion } = require("../package-lock.json");

const expectedVersion = 2;

if (typeof lockfileVersion !== "number" ||
lockfileVersion < expectedVersion) {
if (typeof lockfileVersion !== "number" || lockfileVersion < expectedVersion) {
throw new Error(
`Old lockfileVersion (${
lockfileVersion
}) found in package-lock.json (expected ${
expectedVersion
} or later)`
`Old lockfileVersion (${lockfileVersion}) found in package-lock.json (expected ${expectedVersion} or later)`
);
}

Expand Down
60 changes: 34 additions & 26 deletions config/prepareDist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@
// - Create a new `package.json` for each sub-set bundle we support, and
// store it in the appropriate dist sub-directory.

const fs = require('fs');
const path = require('path');
const recast = require('recast');
const fs = require("fs");
const path = require("path");
const recast = require("recast");

const distRoot = `${__dirname}/../dist`;


/* @apollo/client */

const packageJson = require('../package.json');
const entryPoints = require('./entryPoints.js');
const packageJson = require("../package.json");
const entryPoints = require("./entryPoints.js");

// Enable default interpretation of .js files as ECMAScript modules. We don't
// put this in the source ../package.json file because it interferes with tools
// like ts-node, which we use to run various ../config/*.ts scripts.
// TODO(benjamn) Fully diagnose that interference.
packageJson.type = 'module';
packageJson.type = "module";

// 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
Expand All @@ -43,23 +42,28 @@ delete packageJson.engines;
// 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) => {
if (typeof value === 'string' && value.startsWith('./dist/')) {
const parts = value.split('/');
parts.splice(1, 1); // remove dist
return parts.join('/');
}
return value;
}, 2) + "\n";
const distPackageJson =
JSON.stringify(
packageJson,
(_key, value) => {
if (typeof value === "string" && value.startsWith("./dist/")) {
const parts = value.split("/");
parts.splice(1, 1); // remove dist
return parts.join("/");
}
return value;
},
2
) + "\n";

// Save the modified package.json to "dist"
fs.writeFileSync(`${distRoot}/package.json`, distPackageJson);

// Copy supporting files into "dist"
const srcDir = `${__dirname}/..`;
const destDir = `${srcDir}/dist`;
fs.copyFileSync(`${srcDir}/README.md`, `${destDir}/README.md`);
fs.copyFileSync(`${srcDir}/LICENSE`, `${destDir}/LICENSE`);
fs.copyFileSync(`${srcDir}/README.md`, `${destDir}/README.md`);
fs.copyFileSync(`${srcDir}/LICENSE`, `${destDir}/LICENSE`);

// Create individual bundle package.json files, storing them in their
// associated dist directory. This helps provide a way for the Apollo Client
Expand All @@ -73,14 +77,18 @@ entryPoints.forEach(function buildPackageJson({
}) {
if (!dirs.length) return;
fs.writeFileSync(
path.join(distRoot, ...dirs, 'package.json'),
JSON.stringify({
name: path.posix.join('@apollo', 'client', ...dirs),
type: "module",
main: `${bundleName}.cjs`,
module: 'index.js',
types: 'index.d.ts',
sideEffects,
}, null, 2) + "\n",
path.join(distRoot, ...dirs, "package.json"),
JSON.stringify(
{
name: path.posix.join("@apollo", "client", ...dirs),
type: "module",
main: `${bundleName}.cjs`,
module: "index.js",
types: "index.d.ts",
sideEffects,
},
null,
2
) + "\n"
);
});
Loading

0 comments on commit 25e2599

Please sign in to comment.