Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor researcher app to use ECMAScript modules (ESM) #496

Merged
merged 17 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ['custom'],
extends: ['@colonial-collections/eslint-config'],
settings: {
next: {
rootDir: ['apps/*/'],
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ This repo uses [Turborepo](https://turbo.build/) as build system and [npm](https

### Packages

- `eslint-config-custom`: `eslint` configurations
- `@colonial-collections/eslint-config`: `eslint` configurations
- `iris`: helper functions for working with IRIs
- `tailwind-config`: Tailwind config used by both the apps and the `ui` package
- `tsconfig`: `tsconfig.json`s used throughout the monorepo
- `ui`: a React component library shared by the apps
- `@colonial-collections/tailwind-config`: Tailwind config used by both the apps and the `ui` package
- `@colonial-collections/ts-config`: `tsconfig.json`s used throughout the monorepo
- `@colonial-collections/ui`: a React component library shared by the apps

## Prerequisites

Expand Down
4 changes: 0 additions & 4 deletions apps/dataset-browser/.eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions apps/dataset-browser/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": ["@colonial-collections/eslint-config"]
}
2 changes: 1 addition & 1 deletion apps/dataset-browser/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "tsconfig/cypress.json",
"extends": "@colonial-collections/ts-config/cypress.json",
"include": ["**/*.ts", "**/*.tsx", "../src/**/*.cy.tsx"],
"exclude": []
}
27 changes: 27 additions & 0 deletions apps/dataset-browser/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const nextJest = require('next/jest');

const createJestConfig = nextJest();

/** @type {import('jest').Config} */
const customJestConfig = {
testTimeout: 60000,
testMatch: ['**/*.test.ts(x)?'],
collectCoverage: true,
setupFiles: ['<rootDir>/jest.setup.cjs'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
/**
* Don't try to transform the package `next-intl`, or else you will get the error:
* "SyntaxError: Cannot use import statement outside a module"
*
* `next-intl` uses ECMAScript Modules (ESM) and Jest provides some experimental support for it
* but "node_modules" are not transpiled by next/jest yet.
*
* @link https://github.com/vercel/next.js/issues/36077#issuecomment-1096698456
* @link https://jestjs.io/docs/ecmascript-modules
*/
transformIgnorePatterns: ['node_modules/(?!(next-intl)/)'],
};

module.exports = createJestConfig(customJestConfig);
33 changes: 0 additions & 33 deletions apps/dataset-browser/jest.config.js

This file was deleted.

File renamed without changes.
9 changes: 5 additions & 4 deletions apps/dataset-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "dataset-browser",
"version": "1.0.0",
"private": true,
"type": "module",
"files": [],
"engines": {
"node": "18.x"
Expand Down Expand Up @@ -45,15 +46,15 @@
"@types/react": "18.2.56",
"@types/react-dom": "18.2.19",
"autoprefixer": "10.4.18",
"cypress": "13.6.2",
"cypress": "13.7.0",
"encoding": "0.1.13",
"eslint-config-custom": "*",
"@colonial-collections/eslint-config": "*",
"gts": "5.2.0",
"jest": "29.7.0",
"postcss": "8.4.33",
"tailwind-config": "*",
"@colonial-collections/tailwind-config": "*",
"tailwindcss": "3.4.1",
"tsconfig": "*",
"@colonial-collections/ts-config": "*",
"typescript": "5.3.3"
}
}
6 changes: 0 additions & 6 deletions apps/dataset-browser/postcss.config.js

This file was deleted.

6 changes: 6 additions & 0 deletions apps/dataset-browser/postcss.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": {
"tailwindcss": {},
"autoprefixer": {}
}
}
4 changes: 4 additions & 0 deletions apps/dataset-browser/src/definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum LocaleEnum {
En = 'en',
Nl = 'nl',
}
20 changes: 17 additions & 3 deletions apps/dataset-browser/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import {notFound} from 'next/navigation';
import {getRequestConfig} from 'next-intl/server';
import {locales} from './navigation';
import {LocaleEnum} from '@/definitions';

export default getRequestConfig(async ({locale}) => ({
messages: (await import(`./messages/${locale}/messages.json`)).default,
}));
export default getRequestConfig(async ({locale}) => {
if (!locales.includes(locale as LocaleEnum)) {
notFound();
}

return {
messages: (
await (locale === 'en'
? // This will enable HMR for `en`
import('./messages/en/messages.json')
: import(`./messages/${locale}/messages.json`))
).default,
};
});
5 changes: 0 additions & 5 deletions apps/dataset-browser/tailwind.config.js

This file was deleted.

5 changes: 5 additions & 0 deletions apps/dataset-browser/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import config from '@colonial-collections/tailwind-config';

export default {
presets: [config],
};
2 changes: 1 addition & 1 deletion apps/dataset-browser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "tsconfig/nextjs.json",
"extends": "../../packages/ts-config/nextjs.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
Expand Down
4 changes: 0 additions & 4 deletions apps/researcher/.eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions apps/researcher/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": ["@colonial-collections/eslint-config"]
}
2 changes: 1 addition & 1 deletion apps/researcher/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "tsconfig/cypress.json",
"extends": "@colonial-collections/ts-config/cypress.json",
"include": ["**/*.ts", "**/*.tsx", "../src/**/*.cy.tsx"],
"exclude": []
}
27 changes: 27 additions & 0 deletions apps/researcher/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const nextJest = require('next/jest');

const createJestConfig = nextJest();

/** @type {import('jest').Config} */
const customJestConfig = {
testTimeout: 60000,
testMatch: ['**/*.test.ts(x)?'],
collectCoverage: true,
setupFiles: ['<rootDir>/jest.setup.cjs'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
/**
* Don't try to transform the package `next-intl`, or else you will get the error:
* "SyntaxError: Cannot use import statement outside a module"
*
* `next-intl` uses ECMAScript Modules (ESM) and Jest provides some experimental support for it
* but "node_modules" are not transpiled by next/jest yet.
*
* @link https://github.com/vercel/next.js/issues/36077#issuecomment-1096698456
* @link https://jestjs.io/docs/ecmascript-modules
*/
transformIgnorePatterns: ['node_modules/(?!(next-intl)/)'],
};

module.exports = createJestConfig(customJestConfig);
34 changes: 0 additions & 34 deletions apps/researcher/jest.config.js

This file was deleted.

File renamed without changes.
9 changes: 4 additions & 5 deletions apps/researcher/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/**
* @type {import('next').NextConfig}
*/
// @ts-check

import NextIntlPlugin from 'next-intl/plugin';
import createNextIntlPlugin from 'next-intl/plugin';
import MDXPlugin from '@next/mdx';

const withNextIntl = NextIntlPlugin('./src/i18n.ts');
const withNextIntl = createNextIntlPlugin('./src/i18n.ts');
const withMDX = MDXPlugin();

/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ['@colonial-collections/ui'],
experimental: {
Expand Down
11 changes: 6 additions & 5 deletions apps/researcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "researcher",
"version": "1.0.0",
"private": true,
"type": "module",
"files": [],
"engines": {
"node": "18.x"
Expand Down Expand Up @@ -35,7 +36,7 @@
"@hookform/resolvers": "3.3.4",
"@next/mdx": "14.1.0",
"classnames": "2.3.2",
"iso-639-1-dir": "3.0.5",
"iso-639-1": "3.1.2",
"jwt-decode": "4.0.0",
"leaflet": "1.9.4",
"leaflet-defaulticon-compatibility": "0.1.2",
Expand All @@ -62,14 +63,14 @@
"@types/react": "18.2.56",
"@types/react-dom": "18.2.19",
"autoprefixer": "10.4.18",
"cypress": "13.6.2",
"eslint-config-custom": "*",
"cypress": "13.7.0",
"@colonial-collections/eslint-config": "*",
"gts": "5.2.0",
"jest": "29.7.0",
"postcss": "8.4.33",
"tailwind-config": "*",
"@colonial-collections/tailwind-config": "*",
"tailwindcss": "3.4.1",
"tsconfig": "*",
"@colonial-collections/ts-config": "*",
"typescript": "5.3.3"
}
}
6 changes: 0 additions & 6 deletions apps/researcher/postcss.config.js

This file was deleted.

6 changes: 6 additions & 0 deletions apps/researcher/postcss.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"plugins": {
"tailwindcss": {},
"autoprefixer": {}
}
}
3 changes: 1 addition & 2 deletions apps/researcher/src/app/[locale]/objects/[id]/metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {getFormatter} from 'next-intl/server';
import classNames from 'classnames';
import {InformationCircleIcon} from '@heroicons/react/24/outline';
import type {AdditionalType} from '@colonial-collections/enricher';
import ISO6391 from 'iso-639-1-dir';
import {LanguageCode} from 'iso-639-1-dir/dist/data';
import ISO6391, {LanguageCode} from 'iso-639-1';

interface Props {
translationKey: string;
Expand Down
3 changes: 1 addition & 2 deletions apps/researcher/src/app/[locale]/objects/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import ObjectListsMenu from './object-lists-menu';
import SignedIn from '@/lib/community/signed-in';
import {fetcher} from '@/lib/enricher-instances';
import {AdditionalType} from '@colonial-collections/enricher';
import ISO6391 from 'iso-639-1-dir';
import {LanguageCode} from 'iso-639-1-dir/dist/data';
import ISO6391, {LanguageCode} from 'iso-639-1';
import Provenance from './(provenance)/overview';
import {getDateFormatter} from '@/lib/date-formatter/actions';
import {LocaleEnum} from '@/definitions';
Expand Down
19 changes: 9 additions & 10 deletions apps/researcher/src/components/language-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {CheckIcon, ChevronUpDownIcon} from '@heroicons/react/20/solid';
import {Combobox} from '@headlessui/react';
import {useState} from 'react';
import classNames from 'classnames';
import ISO6391 from 'iso-639-1-dir';
import {LanguageCode} from 'iso-639-1-dir/dist/data';
import ISO6391 from 'iso-639-1';

interface Props {
value: string;
Expand All @@ -14,14 +13,14 @@ export default function LanguageSelector({value, setValue}: Props) {
const [query, setQuery] = useState('');

const filteredLanguageCodes = query
? ISO6391.getLanguages()
.filter(languageCode => {
// Search in both the name and the native name
return `${languageCode.name.toLowerCase()} ${languageCode.nativeName.toLowerCase()}`.includes(
query.toLowerCase()
);
})
.map(languageCode => languageCode.code as LanguageCode)
? ISO6391.getAllCodes().filter(code => {
const englishName = ISO6391.getName(code);
const localName = ISO6391.getNativeName(code);
// Search in both the name and the native name
return `${englishName.toLowerCase()} ${localName.toLowerCase()}`.includes(
query.toLowerCase()
);
})
: ISO6391.getAllCodes();

return (
Expand Down