diff --git a/package.json b/package.json index fcddf972d..d9495df4b 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,8 @@ "regenerator-runtime": "^0.13.3", "reselect": "^4.0.0", "swr": "^0.1.16", - "whatwg-fetch": "^3.0.0" + "whatwg-fetch": "^3.0.0", + "yaml": "^1.9.2" }, "scripts": { "prepare": "node source/scripts/prepare.js", @@ -101,7 +102,7 @@ "mon-entreprise:serve": "PORT=5000 serve --config serve.mon-entreprise.json --no-clipboard", "mon-entreprise:test": "cypress open --browser chromium", "mycompanyinfrance:serve": "PORT=5001 serve --config serve.infrance.json --no-clipboard", - "mycompanyinfrance:test": "cypress open --browser chromium --env language=en --config baseUrl=http://localhost:8080/infrance", + "mycompanyinfrance:test": "cypress open --browser chromium --config baseUrl=http://localhost:8080/infrance", "serve-dev": "yarn run mon-entreprise:serve & yarn run mycompanyinfrance:serve" }, "devDependencies": { diff --git a/source/components/Documentation/RuleSource.tsx b/source/components/Documentation/RuleSource.tsx index 70d36d17c..a5ef6da7f 100644 --- a/source/components/Documentation/RuleSource.tsx +++ b/source/components/Documentation/RuleSource.tsx @@ -1,5 +1,5 @@ import { ParsedRule } from 'Engine/types' -import { safeDump } from 'js-yaml' +import yaml from 'yaml' import React from 'react' import rules from 'Rules' import PublicodeHighlighter from '../ui/PublicodeHighlighter' @@ -12,7 +12,7 @@ export default function RuleSource({ dottedName }: RuleSourceProps) { return (

Source publicode

- +

Ci-dessus la règle d'origine, écrite en publicode. Publicode est un langage déclaratif développé par beta.gouv.fr en partenariat avec diff --git a/source/engine/parseRules.ts b/source/engine/parseRules.ts index d63e8e055..83f1de2df 100644 --- a/source/engine/parseRules.ts +++ b/source/engine/parseRules.ts @@ -1,5 +1,5 @@ import parseRule from 'Engine/parseRule' -import { safeLoad } from 'js-yaml' +import yaml from 'yaml' import { lensPath, set } from 'ramda' import { compilationError } from './error' import { parseReference } from './parseReference' @@ -10,7 +10,7 @@ export default function parseRules( ): ParsedRules { const rules = typeof rawRules === 'string' - ? (safeLoad(rawRules.replace(/\t/g, ' ')) as Rules) + ? (yaml.parse(rawRules.replace(/\t/g, ' ')) as Rules) : { ...rawRules } extractInlinedNames(rules) diff --git a/source/scripts/i18n/translate-rules.js b/source/scripts/i18n/translate-rules.js index 93bc437b0..9a56baace 100644 --- a/source/scripts/i18n/translate-rules.js +++ b/source/scripts/i18n/translate-rules.js @@ -1,4 +1,4 @@ -var { safeDump } = require('js-yaml') +var { stringify } = require('yaml') var fs = require('fs') const { @@ -9,7 +9,10 @@ const { const [missingTranslations, resolved] = getRulesMissingTranslations() -fs.writeFileSync(rulesTranslationPath, safeDump(resolved, { sortKeys: true })) +fs.writeFileSync( + rulesTranslationPath, + stringify(resolved, { sortMapEntries: true }) +) missingTranslations.forEach(async ([dottedName, attr, value]) => { try { @@ -18,7 +21,7 @@ missingTranslations.forEach(async ([dottedName, attr, value]) => { // C'est très bourrin, mais on ne veut pas perdre une traduction qu'on a payé fs.writeFileSync( rulesTranslationPath, - safeDump(resolved, { sortKeys: true }) + stringify(resolved, { sortMapEntries: true }) ) } catch (e) { console.log(e) diff --git a/source/scripts/i18n/translate-ui.js b/source/scripts/i18n/translate-ui.js index 99393818d..c378bc132 100644 --- a/source/scripts/i18n/translate-ui.js +++ b/source/scripts/i18n/translate-ui.js @@ -1,4 +1,4 @@ -var { safeDump, safeLoad } = require('js-yaml') +var { stringify, parse } = require('yaml') var R = require('ramda') var fs = require('fs') @@ -9,7 +9,7 @@ const { } = require('./utils') const missingTranslations = getUiMissingTranslations() -let translatedKeys = safeLoad(fs.readFileSync(UiTranslationPath, 'utf-8')) +let translatedKeys = parse(fs.readFileSync(UiTranslationPath, 'utf-8')) Object.entries(missingTranslations) .map(([key, value]) => [key, value === 'NO_TRANSLATION' ? key : value]) @@ -23,7 +23,7 @@ Object.entries(missingTranslations) ) fs.writeFileSync( UiTranslationPath, - safeDump(translatedKeys, { sortKeys: true }) + stringify(translatedKeys, { sortMapEntries: true }) ) } catch (e) { console.log(e) diff --git a/source/scripts/i18n/utils.js b/source/scripts/i18n/utils.js index 9e586b101..a2c1e3562 100644 --- a/source/scripts/i18n/utils.js +++ b/source/scripts/i18n/utils.js @@ -6,7 +6,7 @@ let R = require('ramda') var querystring = require('querystring') let { readRules } = require('../rules') -let { safeLoad } = require('js-yaml') +let { parse } = require('yaml') let rulesTranslationPath = path.resolve('source/locales/rules-en.yaml') let UiTranslationPath = path.resolve('source/locales/en.yaml') @@ -23,7 +23,7 @@ let attributesToTranslate = [ function getRulesMissingTranslations() { let rules = readRules() - let currentExternalization = safeLoad( + let currentExternalization = parse( fs.readFileSync(rulesTranslationPath, 'utf-8') ) @@ -119,7 +119,7 @@ const getUiMissingTranslations = () => { const staticKeys = require(path.resolve( 'source/locales/static-analysis-fr.json' )) - const translatedKeys = safeLoad(fs.readFileSync(UiTranslationPath, 'utf-8')) + const translatedKeys = parse(fs.readFileSync(UiTranslationPath, 'utf-8')) const missingTranslations = Object.keys(staticKeys).filter(key => { if (key.match(/^\{.*\}$/)) { diff --git a/source/scripts/rules.js b/source/scripts/rules.js index 15966d2e3..9101941c3 100644 --- a/source/scripts/rules.js +++ b/source/scripts/rules.js @@ -3,7 +3,7 @@ const fs = require('fs') const path = require('path') -const yaml = require('js-yaml') +const yaml = require('yaml') const publicodesDir = path.resolve(__dirname, '../rules') @@ -22,7 +22,7 @@ function concatenateFilesInDir(dirPath = publicodesDir) { } function readRules() { - return yaml.safeLoad(concatenateFilesInDir()) + return yaml.parse(concatenateFilesInDir()) } exports.readRules = readRules diff --git a/source/sites/publi.codes/Studio.tsx b/source/sites/publi.codes/Studio.tsx index eead76968..061af2e75 100644 --- a/source/sites/publi.codes/Studio.tsx +++ b/source/sites/publi.codes/Studio.tsx @@ -1,13 +1,12 @@ // import { ControlledEditor } from '@monaco-editor/react' import Engine from 'Engine' import { formatValue } from 'Engine/format' -import { safeLoad } from 'js-yaml' +import yaml from 'yaml' import { last } from 'ramda' import React, { useCallback, useEffect, useMemo, useState } from 'react' import emoji from 'react-easy-emoji' import MonacoEditor from 'react-monaco-editor' import { useLocation } from 'react-router' -import { DottedName } from 'Rules' import styled from 'styled-components' const EXAMPLE_CODE = ` @@ -58,7 +57,7 @@ export default function Studio() { const targets = useMemo(() => { try { - return Object.keys(safeLoad(debouncedEditorValue) ?? {}) + return Object.keys(yaml.parse(debouncedEditorValue) ?? {}) } catch (e) { console.error(e) return [] diff --git a/yarn.lock b/yarn.lock index ef3b1c441..5a33b7b19 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12598,6 +12598,13 @@ yaml@^1.7.2: dependencies: "@babel/runtime" "^7.8.7" +yaml@^1.9.2: + version "1.9.2" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.9.2.tgz#f0cfa865f003ab707663e4f04b3956957ea564ed" + integrity sha512-HPT7cGGI0DuRcsO51qC1j9O16Dh1mZ2bnXwsi0jrSpsLz0WxOLSLXfkABVl6bZO629py3CU+OMJtpNHDLB97kg== + dependencies: + "@babel/runtime" "^7.9.2" + yamljs@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/yamljs/-/yamljs-0.3.0.tgz#dc060bf267447b39f7304e9b2bfbe8b5a7ddb03b"