Skip to content

Commit

Permalink
fix(polyfills): ajout du replaceAll de manière globale (#6311)
Browse files Browse the repository at this point in the history
* fix: replace all

* fix: replace all

* fix: replace all

* fix: replace all

* fix: replace all

* fix: format

* fix: merge date

* fix: merge date

* fix: merge date

* fix: tsup

* fix: bug
  • Loading branch information
maxgfr authored Nov 28, 2024
1 parent 05580fd commit cd1bf5c
Show file tree
Hide file tree
Showing 29 changed files with 809 additions and 227 deletions.
4 changes: 2 additions & 2 deletions packages/code-du-travail-frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ scripts/logs/*
.env.*

## Panda
styled-system
styled-system-studio
src/styled-system
src/styled-system-studio
4 changes: 2 additions & 2 deletions packages/code-du-travail-frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
.next/
.swc/
styled-system/
dist/
src/styled-system/
CHANGELOG.md
2 changes: 0 additions & 2 deletions packages/code-du-travail-frontend/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Metadata } from "next/types";
import { SITE_URL } from "../src/config";
import { headers } from "next/headers";
import DefaultLayout from "../src/modules/config/DefaultLayout";
import { PolyfillComponent } from "../src/modules/utils";

export const metadata: Metadata = {
title: {
Expand Down Expand Up @@ -32,7 +31,6 @@ export default function RootLayout({
nonce={nonce}
defaultColorScheme={pathname.includes("/widgets") ? "light" : "system"}
>
<PolyfillComponent />
{children}
</DefaultLayout>
);
Expand Down
11 changes: 5 additions & 6 deletions packages/code-du-travail-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"lint": "yarn lint:css && next lint",
"precommit": "lint-staged",
"start": "next start",
"prebuild": "node -r @swc-node/register scripts/prebuild.ts && react-dsfr update-icons && panda codegen",
"tsup": "tsup",
"prebuild": "yarn tsup && node dist/prebuild.js && react-dsfr update-icons && panda codegen",
"build": "yarn prebuild && next build",
"build:analyze": "yarn prebuild && ANALYZE=true next build",
"pretest:api": "ELASTICSEARCH_URL=http://localhost:9200 NEXT_PUBLIC_ES_INDEX_PREFIX=cdtn_test NEXT_PUBLIC_APP_ENV=test NODE_ENV=test node -r @swc-node/register scripts/generate-data.ts",
"pretest:api": "yarn tsup && ELASTICSEARCH_URL=http://localhost:9200 NEXT_PUBLIC_ES_INDEX_PREFIX=cdtn_test NEXT_PUBLIC_APP_ENV=test NODE_ENV=test node dist/generate-data.js",
"test": "yarn pretest:api && ELASTICSEARCH_URL=http://localhost:9200 NEXT_PUBLIC_ES_INDEX_PREFIX=cdtn_test NEXT_PUBLIC_APP_ENV=test NODE_ENV=test jest --silent",
"test:watch": "npm run test -- --watch",
"test:frontend": "NEXT_PUBLIC_APP_ENV=test NODE_ENV=test jest --silent --testPathIgnorePatterns='.*\\.es\\.test\\.ts$'",
Expand All @@ -31,7 +32,7 @@
"type-check:watch": "npm run type-check -- --watch",
"format": "prettier --write \"**/*.{js,ts,tsx,jsx,json,md}\"",
"format:check": "prettier --check \"**/*.{js,ts,tsx,jsx,json,md}\"",
"clean:redirects": "node -r @swc-node/register scripts/clean-redirects.ts"
"clean:redirects": "yarn tsup && node dist/clean-redirects.js"
},
"dependencies": {
"@codegouvfr/react-dsfr": "^1.13.9",
Expand All @@ -50,7 +51,6 @@
"@socialgouv/matomo-next": "^1.6.1",
"@socialgouv/modeles-social": "workspace:^",
"@socialgouv/reference-article": "^1.0.1",
"core-js": "^3.39.0",
"cors": "^2.8.5",
"date-fns": "^2.22.1",
"debounce-promise": "^3.1.2",
Expand Down Expand Up @@ -87,8 +87,6 @@
},
"devDependencies": {
"@pandacss/dev": "^0.45.2",
"@swc-node/register": "^1.6.5",
"@swc/core": "^1.3.60",
"@testing-library/cypress": "^10.0.2",
"@testing-library/dom": "^8.11.3",
"@testing-library/jest-dom": "^5.16.5",
Expand Down Expand Up @@ -121,6 +119,7 @@
"stylelint-processor-styled-components": "^1.10.0",
"supertest": "^6.3.3",
"testing-library-selector": "0.3.1",
"tsup": "^8.3.5",
"typescript": "^5.5.4",
"xml2js": "^0.6.2"
}
Expand Down
3 changes: 2 additions & 1 deletion packages/code-du-travail-frontend/panda.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
},
},
},
outdir: "styled-system",
outdir: "src/styled-system",
outExtension: "js",
importMap: "@styled-system",
});
4 changes: 2 additions & 2 deletions packages/code-du-travail-frontend/postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
plugins: {
'@pandacss/dev/postcss': {},
"@pandacss/dev/postcss": {},
},
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import parse, { domToReact } from "html-react-parser";
import { ReactHTMLElement } from "react";

export const ContentParser = ({
children,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client";

import { fr } from "@codegouvfr/react-dsfr";
import { css } from "@styled-system/css";
import React from "react";
import { css } from "../../../styled-system/css";

export const ListWithArrow = ({ items }: { items: JSX.Element[] }) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Button from "@codegouvfr/react-dsfr/Button";
import { usePathname } from "next/navigation";
import { SITE_URL } from "../../config";
import { fr } from "@codegouvfr/react-dsfr";
import { css } from "../../../styled-system/css";
import { css } from "@styled-system/css";
import { useCommonTracking } from "./tracking";

type Props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DefaultColorScheme } from "@codegouvfr/react-dsfr/next-appdir";
import { StartDsfrSystem } from "./StartDsfrSystem";
import { StartDsfrLight } from "./StartDsfrLight";
import { StartDsfrDark } from "./StartDsfrDark";
import { PolyfillComponent } from "./PolyfillComponent";

type Props = {
children: React.ReactNode;
Expand Down Expand Up @@ -44,6 +45,7 @@ export default function DefaultLayout({
/>
</head>
<body>
<PolyfillComponent />
<DsfrProvider lang={lang}>{children}</DsfrProvider>
<MatomoAnalytics />
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use client";

if (!("canParse" in URL)) {
(URL as any).canParse = function canParse(url, base) {
try {
if (base !== undefined) {
new URL(url, base);
} else {
new URL(url);
}
return true;
} catch {
return false;
}
};
}

if (!("replaceAll" in String.prototype)) {
(String.prototype as any).replaceAll = function (
searchValue: string,
replaceValue: string
) {
return this.split(searchValue).join(replaceValue);
};
}

export const PolyfillComponent = () => {
return null;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fr } from "@codegouvfr/react-dsfr";
import Link from "next/link";
import { css } from "../../../styled-system/css";
import { css } from "@styled-system/css";

type Props = {
letters: string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fr } from "@codegouvfr/react-dsfr";
import Link from "next/link";
import { css } from "../../../styled-system/css";
import { css } from "@styled-system/css";
import Image from "next/image";
import { Highlight } from "@codegouvfr/react-dsfr/Highlight";
import AgreementSearch from "./AgreementSearch.svg";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fr } from "@codegouvfr/react-dsfr";
import { css } from "../../../../styled-system/css";
import { css } from "@styled-system/css";
import { Button } from "@codegouvfr/react-dsfr/Button";

type Props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react";
import * as Sentry from "@sentry/nextjs";
import { fr } from "@codegouvfr/react-dsfr";
import { Button } from "@codegouvfr/react-dsfr/Button";
import { css } from "../../../../styled-system/css";
import { css } from "@styled-system/css";
import { useCombobox } from "downshift";
import { fetchSuggestResults } from "../../layout/header/fetchSuggestResults";
import { SUGGEST_MAX_RESULTS } from "../../../config";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fr } from "@codegouvfr/react-dsfr";
import { css } from "../../../../styled-system/css";
import { css } from "@styled-system/css";

type Props = {
sectionId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { fr } from "@codegouvfr/react-dsfr";
import { css } from "../../../styled-system/css";
import { css } from "@styled-system/css";
import Image from "next/image";
import { HomeSearch } from "./Components";
import { useRouter } from "next/navigation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useCombobox } from "downshift";
import { fetchSuggestResults } from "./fetchSuggestResults";
import { SUGGEST_MAX_RESULTS } from "../../../config";
import { fr } from "@codegouvfr/react-dsfr";
import { css } from "../../../../styled-system/css";
import { css } from "@styled-system/css";
import { useLayoutTracking } from "../tracking";

type Props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useNeedMoreInfoEvents } from "./tracking";
import servicesDeRenseignement from "../../../data/services-de-renseignement.json";
import { Button } from "@codegouvfr/react-dsfr/Button";
import { fr } from "@codegouvfr/react-dsfr";
import { css } from "../../../../styled-system/css";
import { css } from "@styled-system/css";

type ServiceRenseignement = {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { fr } from "@codegouvfr/react-dsfr";
import { Button } from "@codegouvfr/react-dsfr/Button";
import { css } from "../../../../styled-system/css";
import { css } from "@styled-system/css";
import { createModal } from "@codegouvfr/react-dsfr/Modal";
import { PopupContent } from "./PopupContent";
import { useIsModalOpen } from "@codegouvfr/react-dsfr/Modal/useIsModalOpen";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { fr } from "@codegouvfr/react-dsfr";
import { Button } from "@codegouvfr/react-dsfr/Button";
import { useState } from "react";
import { css } from "../../../../styled-system/css";
import { css } from "@styled-system/css";
import { useModeleEvents } from "../tracking";

export const CopyButton = ({ slug }: { slug: string }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fr } from "@codegouvfr/react-dsfr";
import Html from "../../common/Html";
import { css } from "../../../../styled-system/css";
import { css } from "@styled-system/css";
import { getDisclaimer } from "../helpers";
import { Alert } from "@codegouvfr/react-dsfr/Alert";
import { DownloadTile } from "./DownloadTile";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fr } from "@codegouvfr/react-dsfr";
import { CallOut } from "@codegouvfr/react-dsfr/CallOut";
import { css } from "../../../styled-system/css";
import { css } from "@styled-system/css";

type StatsProps = {
title: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fr } from "@codegouvfr/react-dsfr";
import { Tile } from "@codegouvfr/react-dsfr/Tile";
import { css } from "../../../styled-system/css";
import { css } from "@styled-system/css";

type Props = {
title: string;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./sort";
export * from "./events";
export * from "./PolyfillComponent";
6 changes: 5 additions & 1 deletion packages/code-du-travail-frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
{
"name": "next"
}
]
],
"baseUrl": ".",
"paths": {
"@styled-system/*": ["./src/styled-system/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules", "cypress"]
Expand Down
5 changes: 5 additions & 0 deletions packages/code-du-travail-frontend/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["scripts", "!scripts/**/__tests__/**", "!scripts/**/*.test.*"],
});
Loading

0 comments on commit cd1bf5c

Please sign in to comment.