mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
workspace: add experimental pnpm support
This commit is contained in:
1 parent
6c4bd6c21d
commit
188a8c6ed0
12 files changed
+71
-20
No files matched your search
@@ -1,8 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
require('@hydrooj/utils/lib/register');
|
||||
|
||||
const packageBasedir = require('path').resolve(__dirname, '..');
|
||||
const { default: hook } = require('require-resolve-hook');
|
||||
const { bypass } = hook(/^(hydrooj|@hydrooj\/utils|cordis|schemastery|lodash|js-yaml)/, (id) => {
|
||||
const { bypass } = hook(/^(hydrooj|@hydrooj\/utils|cordis|lodash|js-yaml)($|\/)/, (id) => {
|
||||
if (id.startsWith('hydrooj/src')) {
|
||||
console.log('module require via %s is deprecated.', id);
|
||||
if (process.env.DEV) {
|
||||
@@ -13,7 +14,34 @@ const { bypass } = hook(/^(hydrooj|@hydrooj\/utils|cordis|schemastery|lodash|js-
|
||||
);
|
||||
}
|
||||
}
|
||||
return bypass(() => require.resolve(id));
|
||||
if (id.startsWith('hydrooj')) {
|
||||
return bypass(() => require.resolve(id, { paths: [packageBasedir] }));
|
||||
}
|
||||
return bypass(() => {
|
||||
try {
|
||||
return require.resolve(id);
|
||||
} catch (_) {
|
||||
try {
|
||||
return require.resolve(id, { paths: [`${process.cwd()}/node_modules`] });
|
||||
} catch (e) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Replace pnpm paths.
|
||||
// Vscode will try to open a local file for links, so this doesn't work for remote-ssh, etc.
|
||||
if (process.env.npm_execpath && process.env.npm_execpath.includes('pnpm') && !process.env.SSH_CONNECTION) {
|
||||
const original = Error.prepareStackTrace;
|
||||
Error.prepareStackTrace = function capture(...args) {
|
||||
const res = original.apply(this, args);
|
||||
if (!res.includes('.pnpm')) return res;
|
||||
return res.replace(
|
||||
/([( ])([^( ]+\/\.pnpm\/.+?\/node_modules\/)(.+)(:\d+:[^)\n]+)/g,
|
||||
'$1\u001B]8;;$2$3$4\u0007pnpm:$3$4\u001B]8;;\u0007',
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
require('./commands');
|
||||
@@ -1,4 +1,9 @@
|
||||
import serialize from 'serialize-javascript';
|
||||
import db from './service/db';
|
||||
|
||||
export { nanoid } from 'nanoid';
|
||||
export { serialize };
|
||||
|
||||
export * from './pipelineUtils';
|
||||
export * from './error';
|
||||
export * from './libs';
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { IncomingMessage } from 'http';
|
||||
import KoaRouter from 'koa-router';
|
||||
import parseUrl from 'parseurl';
|
||||
import { pathToRegexp } from 'path-to-regexp';
|
||||
import type WebSocket from 'ws';
|
||||
import type { KoaContext } from './server';
|
||||
@@ -20,7 +19,7 @@ export class WebSocketLayer {
|
||||
}
|
||||
|
||||
accept(socket: WebSocket, request: IncomingMessage, ctx: KoaContext) {
|
||||
if (!this.regexp.test(parseUrl(request).pathname)) return false;
|
||||
if (!this.regexp.test(new URL(request.url, `http://${request.headers.host}`).pathname)) return false;
|
||||
this.clients.add(socket);
|
||||
socket.on('close', () => {
|
||||
this.clients.delete(socket);
|
||||
|
||||
Reference in new issue
Block a user