From b6142f4f07bb85efe3fa4c65cea7ac45508eca77 Mon Sep 17 00:00:00 2001 From: BacLuc Date: Sat, 21 Dec 2024 16:12:49 +0100 Subject: [PATCH] frontend/pdf/print: set type to module in package.json And switch to esm syntax for the matchingTranslationKeys eslint plugin. Because there cannot be dashes in an identifier, the rule is now called 'matchingTranslationKeys'. jest-serializer-vue-tjw loads the vue config with require, and seems to expect a commonjs module. We switched to a esm module, and now the structure is not pluginOptions.jestSerializer, but default.pluginOptions.jestSerializer -> with the added export we can support vue itself and jest-serializer-vue-tjw. This might enable us to update vite-plugin-comlink - https://github.com/ecamp/ecamp3/pull/6220 And might help with - https://github.com/ecamp/ecamp3/issues/6038 Fix checked in dist files in pdf/dist/ --- .../__tests__/matchingTranslationKeys.spec.js | 8 ++--- .../__tests__/packageDirectory.spec.js | 4 +-- .../matchingTranslationKeys.js | 6 ++-- common/eslint-local-rules/packageDirectory.js | 9 +++--- frontend/babel.config.js | 11 +++---- frontend/docker-setup.sh | 6 ++-- frontend/eslint-local-rules/index.js | 12 +++---- frontend/eslint.config.mjs | 2 +- frontend/package.json | 1 + .../print/print-client/generatePdf.js | 2 +- .../print/print-client/renderPdf.js | 2 +- frontend/vue.config.js | 32 +++++++++---------- pdf/.gitignore | 3 +- pdf/babel.config.js | 11 +++---- pdf/dist/{pdf.mjs.dist => pdf.js.dist} | 0 ...d.mjs.dist => prepareInMainThread.js.dist} | 0 pdf/eslint-local-rules/index.js | 12 +++---- pdf/eslint.config.mjs | 2 +- pdf/package.json | 1 + print/eslint-local-rules/index.js | 12 +++---- print/eslint.config.mjs | 2 +- print/package.json | 1 + 22 files changed, 67 insertions(+), 72 deletions(-) rename pdf/dist/{pdf.mjs.dist => pdf.js.dist} (100%) rename pdf/dist/{prepareInMainThread.mjs.dist => prepareInMainThread.js.dist} (100%) diff --git a/common/eslint-local-rules/__tests__/matchingTranslationKeys.spec.js b/common/eslint-local-rules/__tests__/matchingTranslationKeys.spec.js index 342c3c9405..19f7c05694 100644 --- a/common/eslint-local-rules/__tests__/matchingTranslationKeys.spec.js +++ b/common/eslint-local-rules/__tests__/matchingTranslationKeys.spec.js @@ -1,11 +1,9 @@ -import rule from '../matchingTranslationKeys.js' +import createMatchingTranslationKeys from '../matchingTranslationKeys.js' import { RuleTester } from 'eslint' -import path from 'path' -import fs from 'fs' -import utils from 'eslint-plugin-vue/lib/utils/index.js' import { describe, it } from 'vitest' import localRules from 'eslint-plugin-local-rules' import globals from 'globals' +import utils from 'eslint-plugin-vue/lib/utils/index.js' import eslintParser from 'vue-eslint-parser' RuleTester.describe = describe @@ -28,7 +26,7 @@ const ruleTester = new RuleTester({ }, }, }) -const ruleInstance = rule(path, utils, fs) +const ruleInstance = createMatchingTranslationKeys(utils) const options = [ { diff --git a/common/eslint-local-rules/__tests__/packageDirectory.spec.js b/common/eslint-local-rules/__tests__/packageDirectory.spec.js index 0a3643c70e..49248cb800 100644 --- a/common/eslint-local-rules/__tests__/packageDirectory.spec.js +++ b/common/eslint-local-rules/__tests__/packageDirectory.spec.js @@ -1,10 +1,8 @@ import { describe, expect, it } from 'vitest' -import factory from '../packageDirectory.js' +import { packageDirectory } from '../packageDirectory.js' import path from 'path' import fs from 'fs' -const { packageDirectory } = factory(path, fs) - describe('packageDirectory', () => { it('resolves the location of the closest package.json', () => { const packageJsonFile = path.resolve(__dirname, '../../package.json') diff --git a/common/eslint-local-rules/matchingTranslationKeys.js b/common/eslint-local-rules/matchingTranslationKeys.js index fbfbc80edd..ec3dc95289 100644 --- a/common/eslint-local-rules/matchingTranslationKeys.js +++ b/common/eslint-local-rules/matchingTranslationKeys.js @@ -1,5 +1,7 @@ -module.exports = (path, utils, fs) => { - const { packageDirectory } = require('./packageDirectory.js')(path, fs) +import { packageDirectory } from "./packageDirectory.js" +import path from "path" + +export default function createMatchingTranslationKeys(utils) { /** * Convert a file path to our convention for translation key structures diff --git a/common/eslint-local-rules/packageDirectory.js b/common/eslint-local-rules/packageDirectory.js index ea4faf4093..01bdca5468 100644 --- a/common/eslint-local-rules/packageDirectory.js +++ b/common/eslint-local-rules/packageDirectory.js @@ -1,5 +1,7 @@ -module.exports = (path, fs) => ({ - packageDirectory: function (filename) { +import path from "path"; +import fs from "fs"; + +export function packageDirectory(filename) { const { root } = path.parse(filename) let directory = filename @@ -16,5 +18,4 @@ module.exports = (path, fs) => ({ } return '' - }, -}) +} diff --git a/frontend/babel.config.js b/frontend/babel.config.js index cbadcc09f9..2b8a72a2f4 100644 --- a/frontend/babel.config.js +++ b/frontend/babel.config.js @@ -1,8 +1,7 @@ -module.exports = { - presets: ['@vue/app'], - env: { - test: { - plugins: ['require-context-hook'], - }, +// noinspection JSUnusedGlobalSymbols +export const presets = ['@vue/app'] +export const env = { + test: { + plugins: ['require-context-hook'], }, } diff --git a/frontend/docker-setup.sh b/frontend/docker-setup.sh index 8f31586a22..91dd9c4dd9 100755 --- a/frontend/docker-setup.sh +++ b/frontend/docker-setup.sh @@ -4,10 +4,10 @@ set -euo pipefail BASEDIR=$(dirname "$0") PDF_DIST=$BASEDIR"/src/pdf" -if [ ! -f "$PDF_DIST/pdf.mjs" ] || [ ! -f "$PDF_DIST/prepareInMainThread.mjs" ]; then +if [ ! -f "$PDF_DIST/pdf.js" ] || [ ! -f "$PDF_DIST/prepareInMainThread.js" ]; then # Copy dummy versions of the pdf build outputs, to make sure there is always something to import - cp "$PDF_DIST/pdf.mjs.dist" "$PDF_DIST/pdf.mjs" - cp "$PDF_DIST/prepareInMainThread.mjs.dist" "$PDF_DIST/prepareInMainThread.mjs" + cp "$PDF_DIST/pdf.js.dist" "$PDF_DIST/pdf.js" + cp "$PDF_DIST/prepareInMainThread.js.dist" "$PDF_DIST/prepareInMainThread.js" fi if [ "$CI" = 'true' ] ; then diff --git a/frontend/eslint-local-rules/index.js b/frontend/eslint-local-rules/index.js index 7da60a12f9..0431dd1383 100644 --- a/frontend/eslint-local-rules/index.js +++ b/frontend/eslint-local-rules/index.js @@ -1,8 +1,6 @@ -const path = require('path') -const fs = require('fs') -const utils = require('eslint-plugin-vue/lib/utils/index.js') -const matchingTranslationKeys = require('../src/common/eslint-local-rules/matchingTranslationKeys.js') +import utils from 'eslint-plugin-vue/lib/utils/index.js' +// noinspection ES6UnusedImports +import createMatchingTranslationKeys from '../../common/eslint-local-rules/matchingTranslationKeys.js' -module.exports = { - 'matching-translation-keys': matchingTranslationKeys(path, utils, fs), -} +// noinspection JSUnusedGlobalSymbols +export const matchingTranslationKeys = createMatchingTranslationKeys(utils) diff --git a/frontend/eslint.config.mjs b/frontend/eslint.config.mjs index 9d959b3c5f..3296272992 100644 --- a/frontend/eslint.config.mjs +++ b/frontend/eslint.config.mjs @@ -77,7 +77,7 @@ export default [ }, ], - 'local-rules/matching-translation-keys': [ + 'local-rules/matchingTranslationKeys': [ 'error', { ignoreKeysRegex: diff --git a/frontend/package.json b/frontend/package.json index 498d7a8548..3f9f1e8605 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,7 @@ { "name": "@ecamp3/frontend", "private": true, + "type": "module", "scripts": { "serve": "vite --host 0.0.0.0", "preview": "vite preview --host 0.0.0.0 --port 3000", diff --git a/frontend/src/components/print/print-client/generatePdf.js b/frontend/src/components/print/print-client/generatePdf.js index 67a533c8c1..f1f20e9959 100644 --- a/frontend/src/components/print/print-client/generatePdf.js +++ b/frontend/src/components/print/print-client/generatePdf.js @@ -1,4 +1,4 @@ -import { prepareInMainThread } from '@/pdf/prepareInMainThread.mjs' +import { prepareInMainThread } from '@/pdf/prepareInMainThread.js' import cloneDeep from 'lodash/cloneDeep.js' export const generatePdf = async (data) => { diff --git a/frontend/src/components/print/print-client/renderPdf.js b/frontend/src/components/print/print-client/renderPdf.js index 60acd6235c..b9ee20d80a 100644 --- a/frontend/src/components/print/print-client/renderPdf.js +++ b/frontend/src/components/print/print-client/renderPdf.js @@ -1,6 +1,6 @@ import wrap from './minimalHalJsonVuex.js' import createI18n from './i18n.js' -import { render, prepare } from '@/pdf/pdf.mjs' +import { render, prepare } from '@/pdf/pdf.js' export const renderPdf = async ({ config, storeData, translationData }) => { const result = { diff --git a/frontend/vue.config.js b/frontend/vue.config.js index c6ceaf6618..2c74438f9d 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -1,25 +1,25 @@ -module.exports = { +export const pluginOptions = { + jestSerializer: { + attributesToClear: ['id', 'for'], + formatting: { + indent_char: ' ', + indent_inner_html: true, + indent_size: 5, + inline: [], + sep: '\n', + wrap_attributes: 'force-aligned', + }, + }, +} + +export default { devServer: { useLocalIp: false, allowedHosts: ['ecamp3', 'localhost', '127.0.0.1'], }, transpileDependencies: ['vuetify'], - - pluginOptions: { - jestSerializer: { - attributesToClear: ['id', 'for'], - formatting: { - indent_char: ' ', - indent_inner_html: true, - indent_size: 5, - inline: [], - sep: '\n', - wrap_attributes: 'force-aligned', - }, - }, - }, - + pluginOptions, css: { sourceMap: true, }, diff --git a/pdf/.gitignore b/pdf/.gitignore index be1616bf10..4cf9e4833b 100644 --- a/pdf/.gitignore +++ b/pdf/.gitignore @@ -9,7 +9,8 @@ lerna-debug.log* node_modules .DS_Store -dist +/dist/* +!/dist/*.dist dist-ssr coverage *.local diff --git a/pdf/babel.config.js b/pdf/babel.config.js index cbadcc09f9..2b8a72a2f4 100644 --- a/pdf/babel.config.js +++ b/pdf/babel.config.js @@ -1,8 +1,7 @@ -module.exports = { - presets: ['@vue/app'], - env: { - test: { - plugins: ['require-context-hook'], - }, +// noinspection JSUnusedGlobalSymbols +export const presets = ['@vue/app'] +export const env = { + test: { + plugins: ['require-context-hook'], }, } diff --git a/pdf/dist/pdf.mjs.dist b/pdf/dist/pdf.js.dist similarity index 100% rename from pdf/dist/pdf.mjs.dist rename to pdf/dist/pdf.js.dist diff --git a/pdf/dist/prepareInMainThread.mjs.dist b/pdf/dist/prepareInMainThread.js.dist similarity index 100% rename from pdf/dist/prepareInMainThread.mjs.dist rename to pdf/dist/prepareInMainThread.js.dist diff --git a/pdf/eslint-local-rules/index.js b/pdf/eslint-local-rules/index.js index fa20d58d4d..0431dd1383 100644 --- a/pdf/eslint-local-rules/index.js +++ b/pdf/eslint-local-rules/index.js @@ -1,8 +1,6 @@ -const path = require('path') -const fs = require('fs') -const utils = require('eslint-plugin-vue/lib/utils/index.js') -const matchingTranslationKeys = require('../common/eslint-local-rules/matchingTranslationKeys.js') +import utils from 'eslint-plugin-vue/lib/utils/index.js' +// noinspection ES6UnusedImports +import createMatchingTranslationKeys from '../../common/eslint-local-rules/matchingTranslationKeys.js' -module.exports = { - 'matching-translation-keys': matchingTranslationKeys(path, utils, fs), -} +// noinspection JSUnusedGlobalSymbols +export const matchingTranslationKeys = createMatchingTranslationKeys(utils) diff --git a/pdf/eslint.config.mjs b/pdf/eslint.config.mjs index 91fd7649ef..0fb2259799 100644 --- a/pdf/eslint.config.mjs +++ b/pdf/eslint.config.mjs @@ -73,7 +73,7 @@ export default [ }, ], - 'local-rules/matching-translation-keys': [ + 'local-rules/matchingTranslationKeys': [ 'error', { ignoreKeysRegex: diff --git a/pdf/package.json b/pdf/package.json index 4ad2a03026..4ef8601cf1 100644 --- a/pdf/package.json +++ b/pdf/package.json @@ -1,6 +1,7 @@ { "name": "@ecamp3/client-pdf", "description": "Create pdfs for eCamp, using Vue components", + "type": "module", "main": "src/index.js", "private": true, "scripts": { diff --git a/print/eslint-local-rules/index.js b/print/eslint-local-rules/index.js index 7ec246a27d..0431dd1383 100644 --- a/print/eslint-local-rules/index.js +++ b/print/eslint-local-rules/index.js @@ -1,8 +1,6 @@ -const path = require('path') -const fs = require('fs') -const utils = require('eslint-plugin-vue/lib/utils/index.js') -const matchingTranslationKeys = require('../../common/eslint-local-rules/matchingTranslationKeys.js') +import utils from 'eslint-plugin-vue/lib/utils/index.js' +// noinspection ES6UnusedImports +import createMatchingTranslationKeys from '../../common/eslint-local-rules/matchingTranslationKeys.js' -module.exports = { - 'matching-translation-keys': matchingTranslationKeys(path, utils, fs), -} +// noinspection JSUnusedGlobalSymbols +export const matchingTranslationKeys = createMatchingTranslationKeys(utils) diff --git a/print/eslint.config.mjs b/print/eslint.config.mjs index 377a195b9d..272deb64b9 100644 --- a/print/eslint.config.mjs +++ b/print/eslint.config.mjs @@ -51,7 +51,7 @@ export default [ 'prefer-const': 'error', 'vue/multi-word-component-names': 'off', - 'local-rules/matching-translation-keys': [ + 'local-rules/matchingTranslationKeys': [ 'error', { ignoreKeysRegex: diff --git a/print/package.json b/print/package.json index 2ca28f1e22..98f2aefc17 100644 --- a/print/package.json +++ b/print/package.json @@ -1,6 +1,7 @@ { "name": "@ecamp3/backend-print", "private": true, + "type": "module", "scripts": { "dev": "nuxt dev", "dev-debug": "node --inspect node_modules/.bin/nuxt",