Skip to content

Commit

Permalink
Fix formatting (#552)
Browse files Browse the repository at this point in the history
* remove prettier for packages/paypal-js

* uninstall prettier for packages/react-paypal-js

* update prettier version to 3.1.1 in root level

* remove format and format:check

* remove format:check from validate

* change format, update node version to v18, fixed build errors

* run changeset add --empty

* update prettier version from 3.1.1 to 3.3.3

* remove .nvmrc and lint-staged.config.js in react-paypal-js

* fix package-lock registry value for prettier

* fix changesets + prettier

---------

Co-authored-by: Hai-Yen Nguyen <[email protected]>
Co-authored-by: Shane Brunson <[email protected]>
  • Loading branch information
3 people authored Aug 9, 2024
1 parent f96c7f6 commit 638e8e6
Show file tree
Hide file tree
Showing 90 changed files with 608 additions and 1,468 deletions.
6 changes: 6 additions & 0 deletions .changeset/silver-trees-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@paypal/react-paypal-js": patch
"@paypal/paypal-js": patch
---

remove .nvmrc and lint-staged.config.js in react-paypal-js
6 changes: 6 additions & 0 deletions .changeset/slow-plums-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@paypal/react-paypal-js": patch
"@paypal/paypal-js": patch
---

remove the prettier dependency from each packages, update the prettier root version, fixed build error, update note version to 18
1,214 changes: 177 additions & 1,037 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
]
},
"devDependencies": {
"@changesets/cli": "^2.25.2",
"@changesets/cli": "^2.27.7",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1"
"prettier": "^3.3.3"
}
}
2 changes: 1 addition & 1 deletion packages/paypal-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ We also provide a legacy build that includes the [promise-polyfill](https://gith
The paypal-js script is also available on the [unpkg CDN](https://unpkg.com/). The iife/paypal-js.js build assigns the `loadScript` function to the window object as `window.paypalLoadScript`. Here's an example:

```html
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<script src="https://unpkg.com/@paypal/[email protected]/dist/iife/paypal-js.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion packages/paypal-js/bundle-tests/bundle-size.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("bundle size", () => {

test(`paypal-js.legacy.min.js should be less than ${maxLegacyBundleSizeInKiloBytes} KB`, () => {
const { size: sizeInBytes } = fs.statSync(
"dist/iife/paypal-js.legacy.min.js"
"dist/iife/paypal-js.legacy.min.js",
);
const [sizeInKiloBytes] = filesize(sizeInBytes, { output: "array" });

Expand Down
2 changes: 1 addition & 1 deletion packages/paypal-js/e2e-tests/browser-global.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
Expand Down
6 changes: 3 additions & 3 deletions packages/paypal-js/e2e-tests/browser-global.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ test("Browser global window.paypalLoadScript", async ({ page }) => {
route.fulfill({
status: 200,
body: successfulSDKResponseMock(),
})
}),
);

await page.goto("/e2e-tests/browser-global.html");

await expect(page).toHaveTitle(
"Demo with window.paypalLoadScript | PayPal JS"
"Demo with window.paypalLoadScript | PayPal JS",
);

const scriptElement = await page.locator(
'script[src^="https://www.paypal.com/sdk/js"]'
'script[src^="https://www.paypal.com/sdk/js"]',
);
const uidFromDOM = await scriptElement.getAttribute("data-uid-auto");

Expand Down
2 changes: 1 addition & 1 deletion packages/paypal-js/e2e-tests/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ http.createServer(function (request, response) {
response.end(
"Sorry, check with the site admin for error: " +
error.code +
" ..\n"
" ..\n",
);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/paypal-js/e2e-tests/load-cached-script.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion packages/paypal-js/e2e-tests/load-cached-script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test("Load cached script", async ({ page }) => {
route.fulfill({
status: 200,
body: successfulSDKResponseMock(),
})
}),
);

let sdkRequestCounter = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/paypal-js/e2e-tests/reload-script.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion packages/paypal-js/e2e-tests/validation-errors.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
Expand Down
8 changes: 4 additions & 4 deletions packages/paypal-js/e2e-tests/validation-errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ test("Validation errors", async ({ page }) => {
route.fulfill({
status: 400,
body: validationErrorSDKResponseMock(),
})
}),
);

await page.goto("/e2e-tests/validation-errors.html");
await expect(page).toHaveTitle("Validation Errors | PayPal JS");
await page.locator("#btn-load-no-client-id").click();

await page.waitForResponse((response) =>
response.url().startsWith("https://www.paypal.com/sdk/js")
response.url().startsWith("https://www.paypal.com/sdk/js"),
);

await page.waitForFunction(
'document.querySelector("#error-message").innerText.length'
'document.querySelector("#error-message").innerText.length',
);

const errorMessage = await page.locator("#error-message").innerText();
expect(errorMessage).toEqual(
'Error: The script "https://www.paypal.com/sdk/js?" failed to load. Check the HTTP status code and response body in DevTools to learn more.'
'Error: The script "https://www.paypal.com/sdk/js?" failed to load. Check the HTTP status code and response body in DevTools to learn more.',
);
});
5 changes: 2 additions & 3 deletions packages/paypal-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"test:e2e": "playwright test",
"test:e2e:debug": "PWDEBUG=1 playwright test --project=\"chromium\"",
"test:e2e:start": "node e2e-tests/http-server.js",
"typecheck": "tsc --noEmit",
"validate": "npm run check-node-version && npm run format:check && npm run typecheck && npm run build && npm run lint && npm test -- --watch=false --coverage.enabled --coverage.include=src && npm run test:bundle -- --watch=false",
"typecheck": "tsc --noEmit --allowSyntheticDefaultImports",
"validate": "npm run check-node-version && npm run typecheck && npm run build && npm run lint && npm test -- --watch=false --coverage.enabled --coverage.include=src && npm run test:bundle -- --watch=false",
"openapi": "npm run openapi-orders && npm run openapi-subscriptions",
"openapi-orders": "openapi-typescript node_modules/@paypal/paypal-rest-api-specifications/openapi/checkout_orders_v2.json -o types/apis/openapi/checkout_orders_v2.d.ts",
"openapi-subscriptions": "openapi-typescript node_modules/@paypal/paypal-rest-api-specifications/openapi/billing_subscriptions_v1.json -o types/apis/openapi/billing_subscriptions_v1.d.ts"
Expand Down Expand Up @@ -66,7 +66,6 @@
"jsdom": "^23.0.1",
"lint-staged": "15.2.0",
"openapi-typescript": "^6.7.3",
"prettier": "3.1.1",
"rollup": "4.9.1",
"semver": "7.5.4",
"standard-version": "9.5.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/paypal-js/src/legacy/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Promise from "promise-polyfill";
import * as Promise from "promise-polyfill";
import {
loadScript as originalLoadScript,
loadCustomScript as originalLoadCustomScript,
Expand All @@ -7,7 +7,7 @@ import type { PayPalScriptOptions } from "../../types/script-options";
import type { PayPalNamespace } from "../../types/index";

export function loadScript(
options: PayPalScriptOptions
options: PayPalScriptOptions,
): Promise<PayPalNamespace | null> {
return originalLoadScript(options, Promise);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/paypal-js/src/load-script.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import { loadScript, loadCustomScript } from "./load-script";
test("should still resolve when global window object does not exist", async () => {
await expect(loadScript({ clientId: "test" })).resolves.toBeNull();
await expect(
loadCustomScript({ url: "https://www.example.com/index.js" })
loadCustomScript({ url: "https://www.example.com/index.js" }),
).resolves.toBeUndefined();
});
28 changes: 14 additions & 14 deletions packages/paypal-js/src/load-script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vi.mock("./utils", async () => {
const namespace = attributes["data-namespace"] || "paypal";
vi.stubGlobal(namespace, { version: "5" });
process.nextTick(() => onSuccess());
}
},
),
};
});
Expand All @@ -38,7 +38,7 @@ describe("loadScript()", () => {

const response = await loadScript({ clientId: "test" });
expect(mockedInsertScriptElement.mock.calls[0][0].url).toEqual(
"https://www.paypal.com/sdk/js?client-id=test"
"https://www.paypal.com/sdk/js?client-id=test",
);
expect(mockedInsertScriptElement).toHaveBeenCalledTimes(1);
expect(response).toEqual(window.paypal);
Expand All @@ -53,7 +53,7 @@ describe("loadScript()", () => {
});
expect(mockedInsertScriptElement).toHaveBeenCalledTimes(1);
expect(mockedInsertScriptElement.mock.calls[0][0].url).toEqual(
"https://www.sandbox.paypal.com/sdk/js?client-id=test"
"https://www.sandbox.paypal.com/sdk/js?client-id=test",
);
expect(response).toEqual(window.paypal);
});
Expand All @@ -67,7 +67,7 @@ describe("loadScript()", () => {
});
expect(mockedInsertScriptElement).toHaveBeenCalledTimes(1);
expect(mockedInsertScriptElement.mock.calls[0][0].url).toEqual(
"https://www.paypal.com/sdk/js?client-id=test"
"https://www.paypal.com/sdk/js?client-id=test",
);
expect(response).toEqual(window.paypal);
});
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("loadScript()", () => {
const { message: errorMessage } = err as Record<string, string>;

expect(errorMessage).toBe(
"The window.paypal global variable is not available."
"The window.paypal global variable is not available.",
);
}
});
Expand All @@ -129,9 +129,9 @@ describe("loadScript()", () => {
clientId: "test",
// @ts-expect-error intentionally sending invalid value
environment: "invalid",
})
}),
).toThrowError(
'The `environment` option must be either "production" or "sandbox"'
'The `environment` option must be either "production" or "sandbox"',
);
});

Expand All @@ -140,7 +140,7 @@ describe("loadScript()", () => {
expect(() => loadScript()).toThrow("Expected an options object.");
// @ts-expect-error ignore invalid arguments error
expect(() => loadScript({}, {})).toThrow(
"Expected PromisePonyfill to be a function."
"Expected PromisePonyfill to be a function.",
);
});
});
Expand All @@ -163,7 +163,7 @@ describe("loadCustomScript()", () => {

await loadCustomScript(options);
expect(mockedInsertScriptElement).toHaveBeenCalledWith(
expect.objectContaining(options)
expect.objectContaining(options),
);
});

Expand All @@ -179,16 +179,16 @@ describe("loadCustomScript()", () => {
url: "https://www.example.com/index.js",
// @ts-expect-error ignore invalid arguments error
attributes: "",
})
}),
).toThrow("Expected attributes to be an object.");
expect(() =>
loadCustomScript(
{
url: "https://www.example.com/index.js",
},
// @ts-expect-error ignore invalid arguments error
{}
)
{},
),
).toThrow("Expected PromisePonyfill to be a function.");
});

Expand All @@ -209,7 +209,7 @@ describe("loadCustomScript()", () => {
const { message } = err as Record<string, string>;

expect(message).toBe(
'The script "https://www.example.com/index.js" failed to load. Check the HTTP status code and response body in DevTools to learn more.'
'The script "https://www.example.com/index.js" failed to load. Check the HTTP status code and response body in DevTools to learn more.',
);
}
});
Expand All @@ -225,7 +225,7 @@ describe("loadCustomScript()", () => {
url: "https://www.example.com/index.js",
},
// @ts-expect-error ignore mock error
PromisePonyfill
PromisePonyfill,
);
expect(PromisePonyfill).toHaveBeenCalledTimes(1);
});
Expand Down
12 changes: 6 additions & 6 deletions packages/paypal-js/src/load-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { PayPalNamespace } from "../types/index";
*/
export function loadScript(
options: PayPalScriptOptions,
PromisePonyfill: PromiseConstructor = Promise
PromisePonyfill: PromiseConstructor = Promise,
): Promise<PayPalNamespace | null> {
validateArguments(options, PromisePonyfill);

Expand All @@ -36,7 +36,7 @@ export function loadScript(
url,
attributes: attributes,
},
PromisePonyfill
PromisePonyfill,
).then(() => {
const newWindowNamespace = getPayPalWindowNamespace(namespace);

Expand All @@ -45,7 +45,7 @@ export function loadScript(
}

throw new Error(
`The window.${namespace} global variable is not available.`
`The window.${namespace} global variable is not available.`,
);
});
}
Expand All @@ -62,7 +62,7 @@ export function loadCustomScript(
url: string;
attributes?: Record<string, string>;
},
PromisePonyfill: PromiseConstructor = Promise
PromisePonyfill: PromiseConstructor = Promise,
): Promise<void> {
validateArguments(options, PromisePonyfill);

Expand All @@ -86,7 +86,7 @@ export function loadCustomScript(
onSuccess: () => resolve(),
onError: () => {
const defaultError = new Error(
`The script "${url}" failed to load. Check the HTTP status code and response body in DevTools to learn more.`
`The script "${url}" failed to load. Check the HTTP status code and response body in DevTools to learn more.`,
);

return reject(defaultError);
Expand All @@ -112,7 +112,7 @@ function validateArguments(options: unknown, PromisePonyfill?: unknown) {
environment !== "sandbox"
) {
throw new Error(
'The `environment` option must be either "production" or "sandbox".'
'The `environment` option must be either "production" or "sandbox".',
);
}

Expand Down
Loading

0 comments on commit 638e8e6

Please sign in to comment.