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

Convert function expressions to declarations #4926

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4cffd1a
chore: add func-style eslint rule
Feb 7, 2021
e54edfc
refactor(website): convert function expressions to function declarations
Feb 7, 2021
df29e05
refactor(scripts): convert function expressions to function declarations
Feb 7, 2021
95f8021
refactor(netlify-cms-core): convert function expressions to function …
Feb 7, 2021
6caa2d1
refactor(netlify-cms-lib-util): convert function expressions to funct…
Feb 7, 2021
7011e9c
refactor(netlify-cms-ui-default): convert function expressions to fun…
Feb 7, 2021
1bc1a48
refactor(netlify-cms-widget-boolean): convert function expressions to…
Feb 7, 2021
028a4b9
refactor(netlify-cms-widget-code): convert function expressions to fu…
Feb 7, 2021
6223048
refactor(netlify-cms-widget-colorstring): convert function expression…
Feb 7, 2021
92f478f
refactor(netlify-cms-widget-markdown): convert function expressions t…
Feb 7, 2021
8540b09
refactor(netlify-cms-proxy-server): convert function expressions to f…
Feb 7, 2021
6b63c49
refactor(netlify-cms-widget-relation): convert function expressions t…
Feb 7, 2021
40c1751
refactor(netlify-cms-widget-select): convert function expressions to …
Feb 7, 2021
d742abf
refactor(netlify-cms-widget-object): convert function expressions to …
Feb 7, 2021
173fa16
refactor(netlify-cms-widget-number): convert function expressions to …
Feb 7, 2021
a8c426c
refactor(netlify-cms-widget-string): convert function expressions to …
Feb 7, 2021
93d107c
refactor(netlify-cms-widget-text): convert function expressions to fu…
Feb 7, 2021
69075d6
refactor(netlify-cms-widget-image): convert function expressions to f…
Feb 7, 2021
cb6d789
refactor(netlify-cms-widget-list): convert function expressions to fu…
Feb 7, 2021
fbeef11
refactor(netlify-cms-widget-map): convert function expressions to fun…
Feb 7, 2021
86a0646
refactor(netlify-cms-widget-datetime): convert function expressions t…
Feb 7, 2021
45cef91
refactor(netlify-cms-widget-date): convert function expressions to fu…
Feb 7, 2021
93b4116
refactor(netlify-cms-widget-file): convert function expressions to fu…
Feb 7, 2021
87010a5
refactor(netlify-cms-widget-media-library-cloudinary): convert functi…
Feb 7, 2021
eb01c79
refactor(netlify-cms-widget-media-library-uploadcare): convert functi…
Feb 7, 2021
8dbbf5d
refactor(netlify-cms-widget-media-backend-azure): convert function ex…
Feb 7, 2021
18ce010
refactor(netlify-cms-widget-media-backend-bitbucket): convert functio…
Feb 7, 2021
b2f9b8e
refactor(netlify-cms-widget-media-backend-github): convert function e…
Feb 7, 2021
095b9b7
refactor(netlify-cms-widget-media-backend-gitlab): convert function e…
Feb 7, 2021
4fe9030
refactor(netlify-cms-widget-media-backend-git-gateway): convert funct…
Feb 7, 2021
6e21f17
refactor(netlify-cms-widget-media-backend-proxy): convert function ex…
Feb 7, 2021
1c1dcbf
refactor(netlify-cms-widget-media-backend-test): convert function exp…
Feb 7, 2021
258f670
refactor(netlify-cms-editor-component-image): convert function expres…
Feb 7, 2021
dd46578
refactor(netlify-cms-lib-widgets): convert function expressions to fu…
Feb 7, 2021
f54bf70
refactor(babel.config.js): convert function expressions to function d…
Feb 7, 2021
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
'@emotion/styled-import': 'error',
'require-atomic-updates': [0],
'object-shorthand': ['error', 'always'],
'func-style': ['error', 'declaration'],
'prefer-const': [
'error',
{
Expand Down
8 changes: 4 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const defaultPlugins = [
],
];

const presets = () => {
function presets() {
return [
'@babel/preset-react',
'@babel/preset-env',
Expand All @@ -86,9 +86,9 @@ const presets = () => {
],
'@babel/typescript',
];
};
}

const plugins = () => {
function plugins() {
if (isESM) {
return [
...defaultPlugins,
Expand Down Expand Up @@ -129,7 +129,7 @@ const plugins = () => {
}

return defaultPlugins;
};
}

module.exports = {
presets: presets(),
Expand Down
4 changes: 2 additions & 2 deletions packages/netlify-cms-backend-azure/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

const getChangeItem = (item: AzureCommitItem) => {
function getChangeItem(item: AzureCommitItem) {
switch (item.action) {
case AzureCommitChangeType.ADD:
return {
Expand Down Expand Up @@ -195,7 +195,7 @@ const getChangeItem = (item: AzureCommitItem) => {
default:
return {};
}
};
}

type AzureCommitItem = {
action: AzureCommitChangeType;
Expand Down
4 changes: 2 additions & 2 deletions packages/netlify-cms-backend-azure/src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {

const MAX_CONCURRENT_DOWNLOADS = 10;

const parseAzureRepo = (config: Config) => {
function parseAzureRepo(config: Config) {
const { repo } = config.backend;

if (typeof repo !== 'string') {
Expand All @@ -51,7 +51,7 @@ const parseAzureRepo = (config: Config) => {
project,
repoName,
};
};
}

export default class Azure implements Implementation {
lock: AsyncLock;
Expand Down
8 changes: 4 additions & 4 deletions packages/netlify-cms-backend-bitbucket/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ export const API_NAME = 'Bitbucket';

const APPLICATION_JSON = 'application/json; charset=utf-8';

const replace404WithEmptyResponse = (err: FetchError) => {
function replace404WithEmptyResponse(err: FetchError) {
if (err && err.status === 404) {
console.log('This 404 was expected and handled appropriately.');
return { size: 0, values: [] as BitBucketFile[] } as BitBucketSrcResult;
} else {
return Promise.reject(err);
}
};
}

export default class API {
apiRoot: string;
Expand Down Expand Up @@ -653,8 +653,8 @@ export default class API {
params: {
pagelen: 50,
q: oneLine`
source.repository.full_name = "${this.repo}"
AND state = "${BitBucketPullRequestState.OPEN}"
source.repository.full_name = "${this.repo}"
AND state = "${BitBucketPullRequestState.OPEN}"
AND destination.branch.name = "${this.branch}"
AND comment_count > 0
AND ${sourceQuery}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ interface NetlifyUser extends Credentials {
user_metadata: { full_name: string; avatar_url: string };
}

const apiGet = async (path: string) => {
async function apiGet(path: string) {
const apiRoot = 'https://api.netlify.com/api/v1/sites';
const response = await fetch(`${apiRoot}/${path}`).then(res => res.json());
return response;
};
}

export default class GitGateway implements Implementation {
config: Config;
Expand Down
59 changes: 32 additions & 27 deletions packages/netlify-cms-backend-git-gateway/src/netlify-lfs-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ type ClientConfig = {
transformImages: ImageTransformations | boolean;
};

export const matchPath = ({ patterns }: ClientConfig, path: string) =>
patterns.some(pattern => minimatch(path, pattern, { matchBase: true }));
export function matchPath({ patterns }: ClientConfig, path: string) {
return patterns.some(pattern => minimatch(path, pattern, { matchBase: true }));
}

//
// API interactions
Expand All @@ -26,10 +27,10 @@ const defaultContentHeaders = {
['Content-Type']: 'application/vnd.git-lfs+json',
};

const resourceExists = async (
async function resourceExists(
{ rootURL, makeAuthorizedRequest }: ClientConfig,
{ sha, size }: PointerFile,
) => {
) {
const response = await makeAuthorizedRequest({
url: `${rootURL}/verify`,
method: 'POST',
Expand All @@ -45,20 +46,20 @@ const resourceExists = async (

// TODO: what kind of error to throw here? APIError doesn't seem
// to fit
};
}

const getTransofrmationsParams = (t: boolean | ImageTransformations) => {
function getTransofrmationsParams(t: boolean | ImageTransformations) {
if (isPlainObject(t) && !isEmpty(t)) {
const { nf_resize: resize, w, h } = t as ImageTransformations;
return `?nf_resize=${resize}&w=${w}&h=${h}`;
}
return '';
};
}

const getDownloadURL = async (
async function getDownloadURL(
{ rootURL, transformImages: t, makeAuthorizedRequest }: ClientConfig,
{ sha }: PointerFile,
) => {
) {
try {
const transformation = getTransofrmationsParams(t);
const transformedPromise = makeAuthorizedRequest(`${rootURL}/origin/${sha}${transformation}`);
Expand All @@ -81,21 +82,23 @@ const getDownloadURL = async (
console.error(error);
return { url: '', blob: new Blob() };
}
};
}

const uploadOperation = (objects: PointerFile[]) => ({
operation: 'upload',
transfers: ['basic'],
objects: objects.map(({ sha, ...rest }) => ({ ...rest, oid: sha })),
});
function uploadOperation(objects: PointerFile[]) {
return {
operation: 'upload',
transfers: ['basic'],
objects: objects.map(({ sha, ...rest }) => ({ ...rest, oid: sha })),
};
}

const getResourceUploadURLs = async (
async function getResourceUploadURLs(
{
rootURL,
makeAuthorizedRequest,
}: { rootURL: string; makeAuthorizedRequest: MakeAuthorizedRequest },
pointerFiles: PointerFile[],
) => {
) {
const response = await makeAuthorizedRequest({
url: `${rootURL}/objects/batch`,
method: 'POST',
Expand All @@ -113,33 +116,35 @@ const getResourceUploadURLs = async (
},
);
return uploadUrls;
};
}

const uploadBlob = (uploadURL: string, blob: Blob) =>
unsentRequest.fetchWithTimeout(uploadURL, {
function uploadBlob(uploadURL: string, blob: Blob) {
return unsentRequest.fetchWithTimeout(uploadURL, {
method: 'PUT',
body: blob,
});
}

const uploadResource = async (
async function uploadResource(
clientConfig: ClientConfig,
{ sha, size }: PointerFile,
resource: Blob,
) => {
) {
const existingFile = await resourceExists(clientConfig, { sha, size });
if (existingFile) {
return sha;
}
const [uploadURL] = await getResourceUploadURLs(clientConfig, [{ sha, size }]);
await uploadBlob(uploadURL, resource);
return sha;
};
}

//
// Create Large Media client

const configureFn = (config: ClientConfig, fn: Function) => (...args: unknown[]) =>
fn(config, ...args);
function configureFn(config: ClientConfig, fn: Function) {
return (...args: unknown[]) => fn(config, ...args);
}

const clientFns: Record<string, Function> = {
resourceExists,
Expand All @@ -159,7 +164,7 @@ export type Client = {
enabled: boolean;
};

export const getClient = (clientConfig: ClientConfig) => {
export function getClient(clientConfig: ClientConfig) {
return flow([
Object.keys,
map((key: string) => [key, configureFn(clientConfig, clientFns[key])]),
Expand All @@ -170,4 +175,4 @@ export const getClient = (clientConfig: ClientConfig) => {
enabled: clientConfig.enabled,
}),
])(clientFns);
};
}
19 changes: 11 additions & 8 deletions packages/netlify-cms-backend-github/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,15 @@ type MediaFile = {
path: string;
};

const withCmsLabel = (pr: GitHubPull, cmsLabelPrefix: string) =>
pr.labels.some(l => isCMSLabel(l.name, cmsLabelPrefix));
const withoutCmsLabel = (pr: GitHubPull, cmsLabelPrefix: string) =>
pr.labels.every(l => !isCMSLabel(l.name, cmsLabelPrefix));
function withCmsLabel(pr: GitHubPull, cmsLabelPrefix: string) {
return pr.labels.some(l => isCMSLabel(l.name, cmsLabelPrefix));
}

function withoutCmsLabel(pr: GitHubPull, cmsLabelPrefix: string) {
return pr.labels.every(l => !isCMSLabel(l.name, cmsLabelPrefix));
}

const getTreeFiles = (files: GitHubCompareFiles) => {
function getTreeFiles(files: GitHubCompareFiles) {
const treeFiles = files.reduce((arr, file) => {
if (file.status === 'removed') {
// delete the file
Expand All @@ -152,7 +155,7 @@ const getTreeFiles = (files: GitHubCompareFiles) => {
}, [] as { sha: string | null; path: string }[]);

return treeFiles;
};
}

export type Diff = {
path: string;
Expand Down Expand Up @@ -446,7 +449,7 @@ export default class API {
headers: { Accept: 'application/vnd.github.v3.raw' },
};

const errorHandler = (err: Error) => {
function errorHandler(err: Error) {
if (err.message === 'Not Found') {
console.log(
'%c %s does not have metadata',
Expand All @@ -455,7 +458,7 @@ export default class API {
);
}
throw err;
};
}

if (!this.useOpenAuthoring) {
const result = await this.request(
Expand Down
4 changes: 2 additions & 2 deletions packages/netlify-cms-backend-github/src/GraphQLAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ type GraphQLPullRequest = {
};
};

const transformPullRequest = (pr: GraphQLPullRequest) => {
function transformPullRequest(pr: GraphQLPullRequest) {
return {
...pr,
labels: pr.labels.nodes,
head: { ref: pr.headRefName, sha: pr.headRefOid, repo: { fork: pr.repository.isFork } },
base: { ref: pr.baseRefName, sha: pr.baseRefOid },
};
};
}

type Error = GraphQLError & { type: string };

Expand Down
4 changes: 2 additions & 2 deletions packages/netlify-cms-backend-github/src/__tests__/API.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ describe('github API', () => {
jest.resetAllMocks();
});

const mockAPI = (api, responses) => {
function mockAPI(api, responses) {
api.request = jest.fn().mockImplementation((path, options = {}) => {
const normalizedPath = path.indexOf('?') !== -1 ? path.substr(0, path.indexOf('?')) : path;
const response = responses[normalizedPath];
return typeof response === 'function'
? Promise.resolve(response(options))
: Promise.reject(new Error(`No response for path '${normalizedPath}'`));
});
};
}

describe('editorialWorkflowGit', () => {
it('should create PR with correct base branch name when publishing with editorial workflow', () => {
Expand Down
28 changes: 15 additions & 13 deletions packages/netlify-cms-backend-github/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const statues = gql`
${fragments.object}
`;

const buildFilesQuery = (depth = 1) => {
function buildFilesQuery(depth = 1) {
const PLACE_HOLDER = 'PLACE_HOLDER';
let query = oneLine`
...ObjectParts
Expand Down Expand Up @@ -93,21 +93,23 @@ const buildFilesQuery = (depth = 1) => {
query = query.replace(PLACE_HOLDER, '');

return query;
};
}

export const files = (depth: number) => gql`
query files($owner: String!, $name: String!, $expression: String!) {
repository(owner: $owner, name: $name) {
...RepositoryParts
object(expression: $expression) {
${buildFilesQuery(depth)}
export function files(depth: number) {
return gql`
query files($owner: String!, $name: String!, $expression: String!) {
repository(owner: $owner, name: $name) {
...RepositoryParts
object(expression: $expression) {
${buildFilesQuery(depth)}
}
}
}
}
${fragments.repository}
${fragments.object}
${fragments.fileEntry}
`;
${fragments.repository}
${fragments.object}
${fragments.fileEntry}
`;
}

const branchQueryPart = `
branch: ref(qualifiedName: $qualifiedName) {
Expand Down
Loading