fix: migrate deprecated APIs and patch vulnerable dependencies
Use current Mongoose, NATS, React, and ESLint APIs. Upgrade Vite and other affected dependencies, restrict the compatibility plugin to resolved module IDs, and keep qs unchanged.
This commit is contained in:
1 parent
5882585f69
commit
9d7c888b0a
14 files changed
+952
-900
No files matched your search
@@ -1,10 +1,11 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
import eslint from '@eslint/js';
|
import eslint from '@eslint/js';
|
||||||
|
import { defineConfig } from 'eslint/config';
|
||||||
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
||||||
import globals from 'globals';
|
import globals from 'globals';
|
||||||
import tseslint from 'typescript-eslint';
|
import tseslint from 'typescript-eslint';
|
||||||
|
|
||||||
export default tseslint.config(
|
export default defineConfig(
|
||||||
{
|
{
|
||||||
ignores: ['eslint.config.mjs'],
|
ignores: ['eslint.config.mjs'],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -35,19 +35,20 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lolympus/contracts": "workspace:*",
|
"@lolympus/contracts": "workspace:*",
|
||||||
|
"@nats-io/jetstream": "^3.4.0",
|
||||||
|
"@nats-io/transport-node": "^3.4.0",
|
||||||
"@nestjs/common": "^11.1.28",
|
"@nestjs/common": "^11.1.28",
|
||||||
"@nestjs/config": "^4.0.4",
|
"@nestjs/config": "^4.0.4",
|
||||||
"@nestjs/core": "^11.1.28",
|
"@nestjs/core": "^11.1.28",
|
||||||
"@nestjs/platform-express": "^11.1.28",
|
"@nestjs/platform-express": "^11.1.28",
|
||||||
"@nestjs/platform-socket.io": "^11.1.28",
|
"@nestjs/platform-socket.io": "^11.1.28",
|
||||||
"@nestjs/swagger": "^11.4.6",
|
"@nestjs/swagger": "^11.4.8",
|
||||||
"@nestjs/websockets": "^11.1.28",
|
"@nestjs/websockets": "^11.1.28",
|
||||||
"@socket.io/redis-adapter": "^8.3.0",
|
"@socket.io/redis-adapter": "^8.3.0",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.15.1",
|
"class-validator": "^0.15.1",
|
||||||
"jose": "^6.2.2",
|
"jose": "^6.2.2",
|
||||||
"mongoose": "9.11.4",
|
"mongoose": "9.12.1",
|
||||||
"nats": "^2.29.3",
|
|
||||||
"newrelic": "^14.3.3",
|
"newrelic": "^14.3.3",
|
||||||
"redis": "^5.12.1",
|
"redis": "^5.12.1",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.2",
|
||||||
@@ -56,8 +57,7 @@
|
|||||||
"temporal-polyfill": "^0.3.2"
|
"temporal-polyfill": "^0.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/js": "^10.0.1",
|
||||||
"@eslint/js": "^9.18.0",
|
|
||||||
"@nestjs/cli": "^11.0.0",
|
"@nestjs/cli": "^11.0.0",
|
||||||
"@nestjs/schematics": "^11.0.0",
|
"@nestjs/schematics": "^11.0.0",
|
||||||
"@nestjs/testing": "^11.0.1",
|
"@nestjs/testing": "^11.0.1",
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
"@types/jest": "^30.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/node": "^26.1.1",
|
"@types/node": "^26.1.1",
|
||||||
"@types/supertest": "^7.0.0",
|
"@types/supertest": "^7.0.0",
|
||||||
"eslint": "^9.18.0",
|
"eslint": "^10.14.0",
|
||||||
"eslint-config-prettier": "^10.0.1",
|
"eslint-config-prettier": "^10.0.1",
|
||||||
"eslint-plugin-prettier": "^5.2.2",
|
"eslint-plugin-prettier": "^5.2.2",
|
||||||
"globals": "^17.0.0",
|
"globals": "^17.0.0",
|
||||||
|
|||||||
@@ -1895,7 +1895,7 @@ describe('AuctionService', () => {
|
|||||||
expect(findOneAndUpdate).toHaveBeenCalledWith(
|
expect(findOneAndUpdate).toHaveBeenCalledWith(
|
||||||
{ matchId, 'chatMessages.id': { $ne: appended.message.id } },
|
{ matchId, 'chatMessages.id': { $ne: appended.message.id } },
|
||||||
{ $push: { chatMessages: { $each: [appended.message], $slice: -200 } } },
|
{ $push: { chatMessages: { $each: [appended.message], $slice: -200 } } },
|
||||||
{ new: true },
|
{ returnDocument: 'after' },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -706,7 +706,7 @@ export class AuctionService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ new: true },
|
{ returnDocument: 'after' },
|
||||||
);
|
);
|
||||||
if (auction) return { auction, message, created: true };
|
if (auction) return { auction, message, created: true };
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { connect } from 'nats';
|
import { connect, type NatsConnection } from '@nats-io/transport-node';
|
||||||
import type { NatsConnection } from 'nats';
|
|
||||||
import { SecretModule } from '../secret/secret.module';
|
import { SecretModule } from '../secret/secret.module';
|
||||||
import { SecretService } from '../secret/secret.service';
|
import { SecretService } from '../secret/secret.service';
|
||||||
import { NATS_CLIENT } from './nats.constants';
|
import { NATS_CLIENT } from './nats.constants';
|
||||||
|
|||||||
@@ -2,20 +2,21 @@ import { Inject, Injectable, Logger, OnModuleDestroy } from '@nestjs/common';
|
|||||||
import {
|
import {
|
||||||
AckPolicy,
|
AckPolicy,
|
||||||
DeliverPolicy,
|
DeliverPolicy,
|
||||||
nanos,
|
jetstream,
|
||||||
|
jetstreamManager,
|
||||||
ReplayPolicy,
|
ReplayPolicy,
|
||||||
RetentionPolicy,
|
RetentionPolicy,
|
||||||
StorageType,
|
StorageType,
|
||||||
StringCodec,
|
type ConsumerMessages,
|
||||||
} from 'nats';
|
type JsMsg,
|
||||||
import type {
|
type PubAck,
|
||||||
ConsumerMessages,
|
} from '@nats-io/jetstream';
|
||||||
JsMsg,
|
import {
|
||||||
Msg,
|
nanos,
|
||||||
NatsConnection,
|
type Msg,
|
||||||
PubAck,
|
type NatsConnection,
|
||||||
Subscription,
|
type Subscription,
|
||||||
} from 'nats';
|
} from '@nats-io/transport-node';
|
||||||
import { NATS_CLIENT } from './nats.constants';
|
import { NATS_CLIENT } from './nats.constants';
|
||||||
|
|
||||||
export type NatsMessageHandler<T = unknown> = (
|
export type NatsMessageHandler<T = unknown> = (
|
||||||
@@ -64,7 +65,6 @@ const JET_STREAM_CONSUMER_RESTART_DELAY_MILLISECONDS = 1_000;
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class NatsService implements OnModuleDestroy {
|
export class NatsService implements OnModuleDestroy {
|
||||||
private readonly logger = new Logger(NatsService.name);
|
private readonly logger = new Logger(NatsService.name);
|
||||||
private readonly stringCodec = StringCodec();
|
|
||||||
private readonly subscriptions = new Set<Subscription>();
|
private readonly subscriptions = new Set<Subscription>();
|
||||||
private readonly jetStreamConsumers = new Set<ConsumerMessages>();
|
private readonly jetStreamConsumers = new Set<ConsumerMessages>();
|
||||||
private isDestroying = false;
|
private isDestroying = false;
|
||||||
@@ -108,10 +108,7 @@ export class NatsService implements OnModuleDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async publish<T = unknown>(subject: string, data: T): Promise<void> {
|
public async publish<T = unknown>(subject: string, data: T): Promise<void> {
|
||||||
this.natsClient.publish(
|
this.natsClient.publish(subject, JSON.stringify(data));
|
||||||
subject,
|
|
||||||
this.stringCodec.encode(JSON.stringify(data)),
|
|
||||||
);
|
|
||||||
await this.natsClient.flush();
|
await this.natsClient.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,19 +130,16 @@ export class NatsService implements OnModuleDestroy {
|
|||||||
data: T,
|
data: T,
|
||||||
options?: { messageId?: string; timeoutMs?: number },
|
options?: { messageId?: string; timeoutMs?: number },
|
||||||
): Promise<PubAck> {
|
): Promise<PubAck> {
|
||||||
const ack = await this.natsClient
|
return jetstream(this.natsClient).publish(subject, JSON.stringify(data), {
|
||||||
.jetstream()
|
msgID: options?.messageId,
|
||||||
.publish(subject, this.stringCodec.encode(JSON.stringify(data)), {
|
timeout: options?.timeoutMs ?? 5000,
|
||||||
msgID: options?.messageId,
|
});
|
||||||
timeout: options?.timeoutMs ?? 5000,
|
|
||||||
});
|
|
||||||
return ack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ensureJetStreamStream(
|
public async ensureJetStreamStream(
|
||||||
options: JetStreamStreamOptions,
|
options: JetStreamStreamOptions,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const manager = await this.natsClient.jetstreamManager();
|
const manager = await jetstreamManager(this.natsClient);
|
||||||
const config = {
|
const config = {
|
||||||
name: options.name,
|
name: options.name,
|
||||||
subjects: options.subjects,
|
subjects: options.subjects,
|
||||||
@@ -173,7 +167,7 @@ export class NatsService implements OnModuleDestroy {
|
|||||||
public async ensureJetStreamConsumer(
|
public async ensureJetStreamConsumer(
|
||||||
options: JetStreamConsumerOptions,
|
options: JetStreamConsumerOptions,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const manager = await this.natsClient.jetstreamManager();
|
const manager = await jetstreamManager(this.natsClient);
|
||||||
const config = {
|
const config = {
|
||||||
durable_name: options.durable,
|
durable_name: options.durable,
|
||||||
name: options.durable,
|
name: options.durable,
|
||||||
@@ -206,9 +200,10 @@ export class NatsService implements OnModuleDestroy {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
while (!this.isDestroying) {
|
while (!this.isDestroying) {
|
||||||
try {
|
try {
|
||||||
const consumer = await this.natsClient
|
const consumer = await jetstream(this.natsClient).consumers.get(
|
||||||
.jetstream()
|
options.stream,
|
||||||
.consumers.get(options.stream, options.durable);
|
options.durable,
|
||||||
|
);
|
||||||
const messages = await consumer.consume({
|
const messages = await consumer.consume({
|
||||||
max_messages: options.maxMessages ?? 10,
|
max_messages: options.maxMessages ?? 10,
|
||||||
expires: options.expiresMs ?? 30000,
|
expires: options.expiresMs ?? 30000,
|
||||||
@@ -263,8 +258,7 @@ export class NatsService implements OnModuleDestroy {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let data: T;
|
let data: T;
|
||||||
try {
|
try {
|
||||||
const decoded = this.stringCodec.decode(msg.data);
|
data = msg.json<T>();
|
||||||
data = JSON.parse(decoded) as T;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
`Failed to decode NATS message on subject="${msg.subject}": ${
|
`Failed to decode NATS message on subject="${msg.subject}": ${
|
||||||
@@ -292,7 +286,7 @@ export class NatsService implements OnModuleDestroy {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
let data: T;
|
let data: T;
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(msg.string()) as T;
|
data = msg.json<T>();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.warn(
|
this.logger.warn(
|
||||||
`Terminating undecodable JetStream message subject="${msg.subject}" stream="${options.stream}": ${
|
`Terminating undecodable JetStream message subject="${msg.subject}" stream="${options.stream}": ${
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import os from 'node:os';
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import { AuctionService } from '../src/modules/auction/auction.service';
|
import { AuctionService } from '../src/modules/auction/auction.service';
|
||||||
import { AuctionDurabilityScheduler } from '../src/modules/auction/auction-durability.scheduler';
|
import { AuctionDurabilityScheduler } from '../src/modules/auction/auction-durability.scheduler';
|
||||||
@@ -16,7 +17,7 @@ import {
|
|||||||
} from '../src/modules/global/database/schema';
|
} from '../src/modules/global/database/schema';
|
||||||
|
|
||||||
let connection: mongoose.Connection;
|
let connection: mongoose.Connection;
|
||||||
let models: Record<string, mongoose.Model<any>>;
|
let models: ReturnType<typeof createModels>;
|
||||||
const redis = {
|
const redis = {
|
||||||
acquireTokenLock: async () => true,
|
acquireTokenLock: async () => true,
|
||||||
releaseTokenLock: async () => true,
|
releaseTokenLock: async () => true,
|
||||||
@@ -27,19 +28,8 @@ const redis = {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeAll(async () => {
|
function createModels(connection: mongoose.Connection) {
|
||||||
if (
|
return {
|
||||||
process.env.MONGO_TEST_ISOLATED !== '1' ||
|
|
||||||
!process.env.MONGO_TEST_URL?.startsWith('mongodb://127.0.0.1:')
|
|
||||||
)
|
|
||||||
throw new Error('Use test:mongodb with an isolated local replica set.');
|
|
||||||
connection = await mongoose
|
|
||||||
.createConnection(process.env.MONGO_TEST_URL, {
|
|
||||||
autoIndex: false,
|
|
||||||
autoCreate: false,
|
|
||||||
})
|
|
||||||
.asPromise();
|
|
||||||
models = {
|
|
||||||
match: connection.model('match', MatchSchema),
|
match: connection.model('match', MatchSchema),
|
||||||
auction: connection.model('auction', AuctionSchema),
|
auction: connection.model('auction', AuctionSchema),
|
||||||
auctionHistory: connection.model(
|
auctionHistory: connection.model(
|
||||||
@@ -56,12 +46,29 @@ beforeAll(async () => {
|
|||||||
AuctionBidRecordSchema,
|
AuctionBidRecordSchema,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
if (
|
||||||
|
process.env.MONGO_TEST_ISOLATED !== '1' ||
|
||||||
|
!process.env.MONGO_TEST_URL?.startsWith('mongodb://127.0.0.1:')
|
||||||
|
)
|
||||||
|
throw new Error('Use test:mongodb with an isolated local replica set.');
|
||||||
|
connection = await mongoose
|
||||||
|
.createConnection(process.env.MONGO_TEST_URL, {
|
||||||
|
autoIndex: false,
|
||||||
|
autoCreate: false,
|
||||||
|
// NODE-7832: the driver's default OS adapter breaks the Jest handshake.
|
||||||
|
runtimeAdapters: { os },
|
||||||
|
})
|
||||||
|
.asPromise();
|
||||||
|
models = createModels(connection);
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Object.values(models).map((model) => model.createCollection()),
|
Object.values(models).map((model) => model.createCollection()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await Promise.all(Object.values(models).map((model) => model.deleteMany({})));
|
await Promise.all(Object.values(models).map((model) => model.deleteMany()));
|
||||||
});
|
});
|
||||||
afterEach(() => jest.restoreAllMocks());
|
afterEach(() => jest.restoreAllMocks());
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
@@ -84,7 +91,6 @@ async function fixture(reserved: boolean) {
|
|||||||
participants: [],
|
participants: [],
|
||||||
tournamentCodeIds: reserved ? [codeId] : [],
|
tournamentCodeIds: reserved ? [codeId] : [],
|
||||||
gameSchedule: [],
|
gameSchedule: [],
|
||||||
__v: 0,
|
|
||||||
});
|
});
|
||||||
await models.auction.collection.insertOne({
|
await models.auction.collection.insertOne({
|
||||||
_id: auctionId,
|
_id: auctionId,
|
||||||
@@ -104,7 +110,7 @@ async function fixture(reserved: boolean) {
|
|||||||
matchId,
|
matchId,
|
||||||
});
|
});
|
||||||
const database = {
|
const database = {
|
||||||
getModel: async (name: string) => models[name],
|
getModel: async (name: keyof typeof models) => models[name],
|
||||||
createSession: () => connection.startSession(),
|
createSession: () => connection.startSession(),
|
||||||
};
|
};
|
||||||
const codes = new TournamentCodeService(database as never, redis as never);
|
const codes = new TournamentCodeService(database as never, redis as never);
|
||||||
@@ -611,10 +617,7 @@ it('reads an uncommitted Match in the provided session when cancelling polling b
|
|||||||
{ session },
|
{ session },
|
||||||
);
|
);
|
||||||
expect(await models.match.findById(created._id)).toBeNull();
|
expect(await models.match.findById(created._id)).toBeNull();
|
||||||
await f.results.cancelPolling(
|
await f.results.cancelPolling(created._id, session);
|
||||||
created._id as mongoose.Types.ObjectId,
|
|
||||||
session,
|
|
||||||
);
|
|
||||||
expect(
|
expect(
|
||||||
await models.match.findById(created._id).session(session),
|
await models.match.findById(created._id).session(session),
|
||||||
).not.toBeNull();
|
).not.toBeNull();
|
||||||
|
|||||||
@@ -324,7 +324,13 @@ describe('Community Hash response cache', () => {
|
|||||||
|
|
||||||
it('does not share an old in-flight detail request after invalidation or overwrite the fresh response', async () => {
|
it('does not share an old in-flight detail request after invalidation or overwrite the fresh response', async () => {
|
||||||
const service = new CommunityStatsService(
|
const service = new CommunityStatsService(
|
||||||
{} as never,
|
{
|
||||||
|
getModel: async () => ({
|
||||||
|
findOne: () => ({
|
||||||
|
select: () => ({ lean: () => ({ exec: async () => null }) }),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
} as never,
|
||||||
cache,
|
cache,
|
||||||
{} as never,
|
{} as never,
|
||||||
{} as never,
|
{} as never,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
"@azure/msal-browser": "^5.8.0",
|
"@azure/msal-browser": "^5.8.0",
|
||||||
"@azure/msal-react": "^5.3.1",
|
"@azure/msal-react": "^5.3.1",
|
||||||
"@lolympus/contracts": "workspace:*",
|
"@lolympus/contracts": "workspace:*",
|
||||||
"@newrelic/browser-agent": "^1.318.0",
|
"@newrelic/browser-agent": "^1.324.1",
|
||||||
"@stylexjs/stylex": "0.19.1",
|
"@stylexjs/stylex": "0.19.1",
|
||||||
"@tanstack/react-query": "^5.100.1",
|
"@tanstack/react-query": "^5.100.1",
|
||||||
"lucide-react": "^1.14.0",
|
"lucide-react": "^1.14.0",
|
||||||
@@ -35,20 +35,20 @@
|
|||||||
"socket.io-client": "^4.8.3"
|
"socket.io-client": "^4.8.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.39.4",
|
"@eslint/js": "^10.0.1",
|
||||||
"@tailwindcss/vite": "^4.2.2",
|
"@tailwindcss/vite": "^4.3.5",
|
||||||
"@types/node": "^26.1.1",
|
"@types/node": "^26.1.1",
|
||||||
"@types/react": "^19.2.14",
|
"@types/react": "^19.2.14",
|
||||||
"@types/react-dom": "^19.2.3",
|
"@types/react-dom": "^19.2.3",
|
||||||
"@vitejs/plugin-react": "^6.0.1",
|
"@vitejs/plugin-react": "^6.3.0",
|
||||||
"eslint": "^9.39.4",
|
"eslint": "^10.14.0",
|
||||||
"eslint-plugin-react-hooks": "^7.0.1",
|
"eslint-plugin-react-hooks": "^7.1.1",
|
||||||
"eslint-plugin-react-refresh": "^0.5.2",
|
"eslint-plugin-react-refresh": "^0.5.2",
|
||||||
"globals": "^17.4.0",
|
"globals": "^17.4.0",
|
||||||
"tailwindcss": "^4.2.2",
|
"tailwindcss": "^4.3.5",
|
||||||
"typescript": "~6.0.2",
|
"typescript": "~6.0.2",
|
||||||
"typescript-eslint": "^8.58.0",
|
"typescript-eslint": "^8.58.0",
|
||||||
"vite": "^8.1.5",
|
"vite": "^8.3.8",
|
||||||
"wrangler": "^4.114.0"
|
"wrangler": "^4.114.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useRef, useState } from "react";
|
import { useMemo, useRef, useState, type SubmitEvent } from "react";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import type {
|
import type {
|
||||||
CompetitionCommandResponse,
|
CompetitionCommandResponse,
|
||||||
@@ -170,7 +170,7 @@ export function CompetitionAdminControls({
|
|||||||
resetCommandFeedback();
|
resetCommandFeedback();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleAdjudicationSubmit(event: React.FormEvent) {
|
function handleAdjudicationSubmit(event: SubmitEvent<HTMLFormElement>) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (!selectedSeries || !canAdjudicate || !adjudicationReason.trim()) {
|
if (!selectedSeries || !canAdjudicate || !adjudicationReason.trim()) {
|
||||||
return;
|
return;
|
||||||
@@ -216,7 +216,7 @@ export function CompetitionAdminControls({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePreviewSubmit(event: React.FormEvent) {
|
function handlePreviewSubmit(event: SubmitEvent<HTMLFormElement>) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (!selectedSeries || !canReverse || !reversalReason.trim()) return;
|
if (!selectedSeries || !canReverse || !reversalReason.trim()) return;
|
||||||
|
|
||||||
|
|||||||
+14
-11
@@ -8,6 +8,12 @@ import path from "node:path";
|
|||||||
const ES_TOOLKIT_COMPAT_RE = /^es-toolkit\/compat\/[A-Za-z0-9_$]+$/;
|
const ES_TOOLKIT_COMPAT_RE = /^es-toolkit\/compat\/[A-Za-z0-9_$]+$/;
|
||||||
const VIRTUAL_ES_TOOLKIT_COMPAT_PREFIX = "\0es-toolkit-compat-esm:";
|
const VIRTUAL_ES_TOOLKIT_COMPAT_PREFIX = "\0es-toolkit-compat-esm:";
|
||||||
|
|
||||||
|
// Share resolved modules between the app and dependency optimizer plugins.
|
||||||
|
const resolvedCompatModules = new Map<
|
||||||
|
string,
|
||||||
|
{ exportName: string; esmPath: string }
|
||||||
|
>();
|
||||||
|
|
||||||
function esToolkitCompatEsm() {
|
function esToolkitCompatEsm() {
|
||||||
return {
|
return {
|
||||||
name: "es-toolkit-compat-esm",
|
name: "es-toolkit-compat-esm",
|
||||||
@@ -34,21 +40,18 @@ function esToolkitCompatEsm() {
|
|||||||
`${esmPathWithoutExtension}.mjs`,
|
`${esmPathWithoutExtension}.mjs`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return `${VIRTUAL_ES_TOOLKIT_COMPAT_PREFIX}${encodeURIComponent(
|
const id = `${VIRTUAL_ES_TOOLKIT_COMPAT_PREFIX}${encodeURIComponent(
|
||||||
exportName,
|
exportName,
|
||||||
)}:${encodeURIComponent(esmPath)}`;
|
)}:${encodeURIComponent(esmPath)}`;
|
||||||
|
resolvedCompatModules.set(id, { exportName, esmPath });
|
||||||
|
return id;
|
||||||
},
|
},
|
||||||
load(id: string) {
|
load(id: string) {
|
||||||
if (!id.startsWith(VIRTUAL_ES_TOOLKIT_COMPAT_PREFIX)) {
|
// A dev-server request can supply a virtual ID directly. Only load IDs
|
||||||
return null;
|
// previously produced by resolving an installed es-toolkit module.
|
||||||
}
|
const module = resolvedCompatModules.get(id);
|
||||||
|
if (!module) return null;
|
||||||
const [encodedExportName, encodedEsmPath] = id
|
const { exportName, esmPath } = module;
|
||||||
.slice(VIRTUAL_ES_TOOLKIT_COMPAT_PREFIX.length)
|
|
||||||
.split(":");
|
|
||||||
const exportName = decodeURIComponent(encodedExportName);
|
|
||||||
const esmPath = decodeURIComponent(encodedEsmPath);
|
|
||||||
|
|
||||||
return `export { ${exportName} as default, ${exportName} } from ${JSON.stringify(
|
return `export { ${exportName} as default, ${exportName} } from ${JSON.stringify(
|
||||||
esmPath,
|
esmPath,
|
||||||
)};`;
|
)};`;
|
||||||
|
|||||||
+11
-7
@@ -35,16 +35,19 @@
|
|||||||
"overrides": {
|
"overrides": {
|
||||||
"@babel/core@7.29.0": "7.29.6",
|
"@babel/core@7.29.0": "7.29.6",
|
||||||
"@grpc/grpc-js@>=1.14.0 <1.14.5": "1.14.7",
|
"@grpc/grpc-js@>=1.14.0 <1.14.5": "1.14.7",
|
||||||
|
"baseline-browser-mapping@>=2.10.0 <2.11.0": "2.11.35",
|
||||||
"body-parser@>=2.0.0 <2.4.0": "2.4.0",
|
"body-parser@>=2.0.0 <2.4.0": "2.4.0",
|
||||||
"brace-expansion@1.1.13": "1.1.16",
|
"brace-expansion@>=1.1.13 <1.1.21": "1.1.22",
|
||||||
"brace-expansion@2.0.3": "2.1.2",
|
"brace-expansion@>=2.0.3 <2.1.7": "2.1.8",
|
||||||
"brace-expansion@5.0.5": "5.0.8",
|
"brace-expansion@>=5.0.5 <5.0.12": "5.0.13",
|
||||||
|
"browserslist@>=4.28.2 <4.28.7": "4.29.5",
|
||||||
"engine.io@>=6.6.0 <6.6.10": "6.6.11",
|
"engine.io@>=6.6.0 <6.6.10": "6.6.11",
|
||||||
"fast-uri@3.1.0": "3.1.4",
|
"fast-uri@>=3.1.0 <3.1.9": "3.1.9",
|
||||||
"form-data@4.0.5": "4.0.6",
|
"form-data@4.0.5": "4.0.6",
|
||||||
"handlebars@>=3.0.0 <4.7.10": "4.7.10",
|
"handlebars@>=3.0.0 <4.7.10": "4.7.10",
|
||||||
"js-yaml@4.1.1": "4.3.0",
|
"js-yaml@>=3.0.0 <3.15.2": "3.15.2",
|
||||||
"js-yaml@5.2.1": "5.2.2",
|
"js-yaml@>=4.0.0 <4.3.2": "4.3.2",
|
||||||
|
"miniflare>sharp@0.35.2": "0.35.5",
|
||||||
"multer@>=2.0.0 <2.5.0": "2.5.0",
|
"multer@>=2.0.0 <2.5.0": "2.5.0",
|
||||||
"nanoid@3.3.16": "3.3.18",
|
"nanoid@3.3.16": "3.3.18",
|
||||||
"proxy-addr@>=2.0.0 <2.0.8": "2.0.8",
|
"proxy-addr@>=2.0.0 <2.0.8": "2.0.8",
|
||||||
@@ -52,7 +55,8 @@
|
|||||||
"socket.io-parser@4.2.6": "4.2.7",
|
"socket.io-parser@4.2.6": "4.2.7",
|
||||||
"source-map-js@>=1.0.0 <1.2.2": "1.2.2",
|
"source-map-js@>=1.0.0 <1.2.2": "1.2.2",
|
||||||
"undici@>=7.0.0 <7.30.1": "7.30.2",
|
"undici@>=7.0.0 <7.30.1": "7.30.2",
|
||||||
"ws@8.18.3": "8.21.0"
|
"ws@8.18.3": "8.21.0",
|
||||||
|
"zod@>=4.3.6 <4.6.6": "4.6.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
+817
-807
File diff suppressed because it is too large.
Load diff
@@ -3,6 +3,7 @@ import { once } from "node:events";
|
|||||||
import http from "node:http";
|
import http from "node:http";
|
||||||
import { createRequire } from "node:module";
|
import { createRequire } from "node:module";
|
||||||
import { test } from "node:test";
|
import { test } from "node:test";
|
||||||
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||||
import { gzipSync } from "node:zlib";
|
import { gzipSync } from "node:zlib";
|
||||||
|
|
||||||
const apiRequire = createRequire(
|
const apiRequire = createRequire(
|
||||||
@@ -158,3 +159,34 @@ test(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
test("Vite only loads compatibility modules resolved from real imports", async (t) => {
|
||||||
|
const { createServer } = await import(
|
||||||
|
pathToFileURL(webRequire.resolve("vite")).href
|
||||||
|
);
|
||||||
|
const server = await createServer({
|
||||||
|
root: fileURLToPath(new URL("../apps/web", import.meta.url)),
|
||||||
|
logLevel: "silent",
|
||||||
|
optimizeDeps: { noDiscovery: true },
|
||||||
|
server: { middlewareMode: true, ws: false, hmr: false, watch: null },
|
||||||
|
});
|
||||||
|
t.after(() => server.close());
|
||||||
|
|
||||||
|
const canary = fileURLToPath(
|
||||||
|
new URL("../apps/api/src/app.service.ts", import.meta.url),
|
||||||
|
).replaceAll("\\", "/");
|
||||||
|
const forgedId =
|
||||||
|
"\0es-toolkit-compat-esm:AppService:" +
|
||||||
|
encodeURIComponent(canary);
|
||||||
|
await assert.rejects(server.transformRequest(forgedId), {
|
||||||
|
code: "ERR_LOAD_URL",
|
||||||
|
});
|
||||||
|
|
||||||
|
const resolved = await server.environments.client.pluginContainer.resolveId(
|
||||||
|
"es-toolkit/compat/sortBy",
|
||||||
|
webRequire.resolve("recharts"),
|
||||||
|
);
|
||||||
|
assert.ok(resolved?.id.startsWith("\0es-toolkit-compat-esm:"));
|
||||||
|
const transformed = await server.transformRequest(resolved.id);
|
||||||
|
assert.match(transformed?.code ?? "", /sortBy/);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user