Skip to content

Commit

Permalink
frontend/pdf/print: set type to module in package.json
Browse files Browse the repository at this point in the history
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
- ecamp#6220
And might help with
- ecamp#6038

Fix checked in dist files in pdf/dist/
  • Loading branch information
BacLuc committed Dec 22, 2024
1 parent e5d850d commit 30f8c7d
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import rule from '../matchingTranslationKeys.js'
import { matchingTranslationKeys } 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
Expand All @@ -28,7 +26,7 @@ const ruleTester = new RuleTester({
},
},
})
const ruleInstance = rule(path, utils, fs)
const ruleInstance = matchingTranslationKeys(utils)

const options = [
{
Expand Down
6 changes: 4 additions & 2 deletions common/eslint-local-rules/matchingTranslationKeys.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 5 additions & 4 deletions common/eslint-local-rules/packageDirectory.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,5 +18,4 @@ module.exports = (path, fs) => ({
}

return ''
},
})
}
11 changes: 5 additions & 6 deletions frontend/babel.config.js
Original file line number Diff line number Diff line change
@@ -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'],
},
}
6 changes: 3 additions & 3 deletions frontend/docker-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions frontend/eslint-local-rules/index.js
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default [
},
],

'local-rules/matching-translation-keys': [
'local-rules/matchingTranslationKeys': [
'error',
{
ignoreKeysRegex:
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/print/print-client/generatePdf.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/print/print-client/renderPdf.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
32 changes: 16 additions & 16 deletions frontend/vue.config.js
Original file line number Diff line number Diff line change
@@ -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,
},
Expand Down
3 changes: 2 additions & 1 deletion pdf/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ lerna-debug.log*

node_modules
.DS_Store
dist
/dist/*
!/dist/*.dist
dist-ssr
coverage
*.local
Expand Down
11 changes: 5 additions & 6 deletions pdf/babel.config.js
Original file line number Diff line number Diff line change
@@ -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'],
},
}
File renamed without changes.
File renamed without changes.
12 changes: 5 additions & 7 deletions pdf/eslint-local-rules/index.js
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion pdf/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default [
},
],

'local-rules/matching-translation-keys': [
'local-rules/matchingTranslationKeys': [
'error',
{
ignoreKeysRegex:
Expand Down
1 change: 1 addition & 0 deletions pdf/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
12 changes: 5 additions & 7 deletions print/eslint-local-rules/index.js
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion print/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions print/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@ecamp3/backend-print",
"private": true,
"type": "module",
"scripts": {
"dev": "nuxt dev",
"dev-debug": "node --inspect node_modules/.bin/nuxt",
Expand Down

0 comments on commit 30f8c7d

Please sign in to comment.