Skip to content

Commit

Permalink
Fix ESM loading with recent versions of Node (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Oct 13, 2024
1 parent 581b630 commit 961e754
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 37 deletions.
6 changes: 1 addition & 5 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# This must be run with the Docker context set to the root folder of the repository
# (the one with the yarn.lock file)

FROM node:lts-alpine

# App directory
WORKDIR /usr/src/backend

ENV NODE_ENV production
ENV NODE_ENV=production

COPY ./yarn.lock ./
COPY ./package.json ./
Expand Down
4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"build": "rimraf dist && tsc --build && yarn copy-templates",
"start": "nodemon --exec 'yarn fix & ts-node' --esm --files ./src/index.ts",
"start": "nodemon --exec 'yarn fix & node' --import ./ts-node.register.mjs ./src/index.ts",
"create-migration": "scripty",
"create-empty-migration": "scripty",
"hardcode-licence": "scripty",
Expand All @@ -23,7 +23,7 @@
"dependencies": {
"@sendgrid/mail": "7.7.0",
"@sentry/node": "7.60.0",
"@types/bcryptjs": "2.4.2",
"@types/bcryptjs": "^2.4.6",
"@types/connect-redis": "0.0.20",
"@types/cookie-parser": "^1.4.3",
"@types/crypto-js": "^4.1.1",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { default as Actions } from './actions.js';
export * from './types.js';
export type * from './types.js';
export * from './models.js';
export * from './payloads.js';
export * from './ws.js';
4 changes: 2 additions & 2 deletions backend/src/db/entities/AiChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
CreateDateColumn,
UpdateDateColumn,
Index,
Relation,
} from 'typeorm';
import { CoachRole } from '../../common/index.js';
import type { Relation } from 'typeorm';
import type { CoachRole } from '../../common/index.js';
import AiChatEntity from './AiChat.js';

@Entity({ name: 'ai_chat_messages' })
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/entities/ColumnDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
CreateDateColumn,
UpdateDateColumn,
Index,
Relation,
} from 'typeorm';
import type { Relation } from 'typeorm';
import { ColumnDefinition, ColumnDefinitionType } from '../../common/index.js';
import SessionEntity from './Session.js';
import SessionTemplateEntity from './SessionTemplate.js';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/entities/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
CreateDateColumn,
UpdateDateColumn,
Index,
Relation,
} from 'typeorm';
import type { Relation } from 'typeorm';
import SessionEntity from './Session.js';
import { Message } from '../../common/index.js';
import { UserEntity } from './UserIdentity.js';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/entities/PostGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
UpdateDateColumn,
OneToMany,
Index,
Relation,
} from 'typeorm';
import type { Relation } from 'typeorm';
import { LexoRank } from 'lexorank';
import SessionEntity from './Session.js';
import PostEntity from './Post.js';
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/entities/SessionView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ViewEntity, ViewColumn } from 'typeorm';
import { User, SessionMetadata } from '../../common/index.js';
import type { User, SessionMetadata } from '../../common/index.js';

@ViewEntity({
expression: `
Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/entities/Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ManyToOne,
Index,
} from 'typeorm';
import { Plan } from '../../common/index.js';
import type { Plan } from '../../common/index.js';
import { UserEntity } from './UserIdentity.js';

@Entity({ name: 'subscriptions' })
Expand Down
10 changes: 3 additions & 7 deletions backend/src/db/entities/UserIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ import {
ManyToOne,
ManyToMany,
} from 'typeorm';
import {
AccountType,
Currency,
User,
UserIdentity,
} from '../../common/index.js';
import { Currency, User, UserIdentity } from '../../common/index.js';
import type { AccountType } from '../../common/types.js';

import { UserIds } from '../../utils.js';
import SessionEntity from './Session.js';
Expand Down Expand Up @@ -122,7 +118,7 @@ export class UserIdentityEntity {
})
@Index()
public user: UserEntity;
@Column({ default: 'anonymous' })
@Column({ default: 'anonymous', type: 'character varying' })
public accountType: AccountType;
@Column({ nullable: true, type: 'character varying' })
public username: string | null;
Expand Down
7 changes: 6 additions & 1 deletion backend/src/db/entities/UserView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ViewEntity, ViewColumn } from 'typeorm';
import { AccountType, FullUser, Currency, Plan } from '../../common/index.js';
import type {
AccountType,
FullUser,
Currency,
Plan,
} from '../../common/index.js';

@ViewEntity({
expression: `
Expand Down
4 changes: 2 additions & 2 deletions backend/src/db/entities/Vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
CreateDateColumn,
UpdateDateColumn,
Index,
Relation,
} from 'typeorm';
import { VoteType, Vote, VoteExtract } from '../../common/index.js';
import type { Relation } from 'typeorm';
import type { VoteType, Vote, VoteExtract } from '../../common/index.js';
import PostEntity from './Post.js';
import { UserEntity } from './UserIdentity.js';

Expand Down
4 changes: 4 additions & 0 deletions backend/ts-node.register.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { pathToFileURL } from 'node:url';
import { register } from 'node:module';

register('ts-node/esm', pathToFileURL('./'));
9 changes: 7 additions & 2 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"outDir": "./dist",
"target": "es6",
"module": "ESNext",
"module": "NodeNext",
"incremental": true,
"moduleResolution": "NodeNext",
"allowJs": false,
Expand All @@ -21,7 +21,12 @@
"inlineSources": true,
"sourceRoot": "/",
"lib": ["es2015", "es2017", "dom", "ESNext"],
"baseUrl": "src"
"baseUrl": "src"
},
"ts-node": {
"experimentalSpecifierResolution": "node",
"transpileOnly": true,
"esm": true,
},
"include": ["src", "./package.json"],
"exclude": ["src/**/*.test.ts"]
Expand Down
8 changes: 4 additions & 4 deletions backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -929,10 +929,10 @@
dependencies:
"@babel/types" "^7.20.7"

"@types/[email protected].2":
version "2.4.2"
resolved "https://registry.yarnpkg.com/@types/bcryptjs/-/bcryptjs-2.4.2.tgz#e3530eac9dd136bfdfb0e43df2c4c5ce1f77dfae"
integrity sha512-LiMQ6EOPob/4yUL66SZzu6Yh77cbzJFYll+ZfaPiPPFswtIlA/Fs1MzdKYA7JApHU49zQTbJGX3PDmCpIdDBRQ==
"@types/bcryptjs@^2.4.6":
version "2.4.6"
resolved "https://registry.yarnpkg.com/@types/bcryptjs/-/bcryptjs-2.4.6.tgz#2b92e3c2121c66eba3901e64faf8bb922ec291fa"
integrity sha512-9xlo6R2qDs5uixm0bcIqCeMCE6HiQsIyel9KQySStiyqNl2tnj2mP3DX1Nf56MD6KMenNNlBBsy3LJ7gUEQPXQ==

"@types/body-parser@*":
version "1.19.5"
Expand Down
8 changes: 2 additions & 6 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# This must be run with the Docker context set to the root folder of the repository
# (the one with the yarn.lock file)

FROM --platform=$BUILDPLATFORM node:lts-alpine as Node
#FROM node:16-alpine as Node
FROM --platform=$BUILDPLATFORM node:lts-alpine AS node

ENV NODE_ENV=production

Expand Down Expand Up @@ -33,7 +29,7 @@ RUN apt update
RUN apt -y remove libfreetype6
RUN apt -y install jq

COPY --from=Node /home/node/app/dist /usr/share/nginx/html
COPY --from=node /home/node/app/dist /usr/share/nginx/html
COPY ./docker/nginx.conf.template /etc/nginx/conf.d/default.conf.template
COPY ./docker/frontend-entrypoint.sh /
COPY ./docker/wpcc.html /
Expand Down

0 comments on commit 961e754

Please sign in to comment.