mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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
+19
-3
@@ -1,9 +1,11 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const child = require('child_process');
|
const child = require('child_process');
|
||||||
|
|
||||||
if (fs.existsSync('plugins/patch-package/package.json') && fs.existsSync('node_modules/patch-package/package.json')) {
|
if (process.env.npm_execpath.includes('yarn')) {
|
||||||
child.execSync('npx patch-package --patch-dir=plugins/patch-package/patches', { stdio: 'inherit' });
|
if (fs.existsSync('plugins/patch-package/package.json') && fs.existsSync('node_modules/patch-package/package.json')) {
|
||||||
|
child.execSync('npx patch-package --patch-dir=plugins/patch-package/patches', { stdio: 'inherit' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dir = path.dirname(path.dirname(require.resolve('@types/node/package.json')));
|
const dir = path.dirname(path.dirname(require.resolve('@types/node/package.json')));
|
||||||
@@ -96,9 +98,23 @@ const UIConfig = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const nm = path.resolve(__dirname, '../node_modules');
|
||||||
|
fs.ensureDirSync(path.join(nm, '@hydrooj'));
|
||||||
|
try {
|
||||||
|
fs.symlinkSync(
|
||||||
|
path.join(process.cwd(), 'packages/ui-default'),
|
||||||
|
path.join(nm, '@hydrooj/ui-default'),
|
||||||
|
'dir',
|
||||||
|
);
|
||||||
|
} catch (e) { }
|
||||||
for (const package of modules) {
|
for (const package of modules) {
|
||||||
const basedir = path.resolve(process.cwd(), package);
|
const basedir = path.resolve(process.cwd(), package);
|
||||||
const files = fs.readdirSync(basedir);
|
const files = fs.readdirSync(basedir);
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line import/no-dynamic-require
|
||||||
|
const name = require(path.join(basedir, 'package.json')).name;
|
||||||
|
fs.symlinkSync(basedir, path.join(nm, name), 'dir');
|
||||||
|
} catch (e) { }
|
||||||
if (!files.includes('src') && !files.filter((i) => i.endsWith('.ts')).length && package !== 'packages/utils') continue;
|
if (!files.includes('src') && !files.filter((i) => i.endsWith('.ts')).length && package !== 'packages/utils') continue;
|
||||||
config.references.push({ path: package });
|
config.references.push({ path: package });
|
||||||
const expectedConfig = JSON.stringify((files.includes('src') ? configSrc : configFlat)(package));
|
const expectedConfig = JSON.stringify((files.includes('src') ? configSrc : configFlat)(package));
|
||||||
|
|||||||
+3
-3
@@ -10,10 +10,10 @@
|
|||||||
"build": "node build/prepare.js && tsc -b --verbose",
|
"build": "node build/prepare.js && tsc -b --verbose",
|
||||||
"build:installer": "esbuild ./install/install.js --minify --format=cjs | base64",
|
"build:installer": "esbuild ./install/install.js --minify --format=cjs | base64",
|
||||||
"build:watch": "node build/prepare.js && tsc -b --watch",
|
"build:watch": "node build/prepare.js && tsc -b --watch",
|
||||||
"build:ui": "yarn build:ui:gulp && node packages/ui-default/build",
|
"build:ui": "node packages/ui-default/build --gulp && node packages/ui-default/build",
|
||||||
"build:ui:gulp": "node packages/ui-default/build --gulp",
|
"build:ui:gulp": "node packages/ui-default/build --gulp",
|
||||||
"build:ui:dev": "yarn build:ui:gulp && node --trace-deprecation packages/ui-default/build --dev",
|
"build:ui:dev": "node packages/ui-default/build --gulp && node --trace-deprecation packages/ui-default/build --dev",
|
||||||
"build:ui:production": "cross-env NODE_OPTIONS=--max_old_space_size=8192 yarn build:ui:gulp && node packages/ui-default/build --production",
|
"build:ui:production": "cross-env NODE_OPTIONS=--max_old_space_size=8192 node packages/ui-default/build --gulp && node packages/ui-default/build --production",
|
||||||
"build:ui:production:webpack": "cross-env NODE_OPTIONS=--max_old_space_size=8192 node packages/ui-default/build --production",
|
"build:ui:production:webpack": "cross-env NODE_OPTIONS=--max_old_space_size=8192 node packages/ui-default/build --production",
|
||||||
"test": "mocha",
|
"test": "mocha",
|
||||||
"benchmark": "cross-env BENCHMARK=true mocha",
|
"benchmark": "cross-env BENCHMARK=true mocha",
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
require('@hydrooj/utils/lib/register');
|
require('@hydrooj/utils/lib/register');
|
||||||
|
|
||||||
|
const packageBasedir = require('path').resolve(__dirname, '..');
|
||||||
const { default: hook } = require('require-resolve-hook');
|
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')) {
|
if (id.startsWith('hydrooj/src')) {
|
||||||
console.log('module require via %s is deprecated.', id);
|
console.log('module require via %s is deprecated.', id);
|
||||||
if (process.env.DEV) {
|
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');
|
require('./commands');
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
|
import serialize from 'serialize-javascript';
|
||||||
import db from './service/db';
|
import db from './service/db';
|
||||||
|
|
||||||
|
export { nanoid } from 'nanoid';
|
||||||
|
export { serialize };
|
||||||
|
|
||||||
export * from './pipelineUtils';
|
export * from './pipelineUtils';
|
||||||
export * from './error';
|
export * from './error';
|
||||||
export * from './libs';
|
export * from './libs';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { IncomingMessage } from 'http';
|
import { IncomingMessage } from 'http';
|
||||||
import KoaRouter from 'koa-router';
|
import KoaRouter from 'koa-router';
|
||||||
import parseUrl from 'parseurl';
|
|
||||||
import { pathToRegexp } from 'path-to-regexp';
|
import { pathToRegexp } from 'path-to-regexp';
|
||||||
import type WebSocket from 'ws';
|
import type WebSocket from 'ws';
|
||||||
import type { KoaContext } from './server';
|
import type { KoaContext } from './server';
|
||||||
@@ -20,7 +19,7 @@ export class WebSocketLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
accept(socket: WebSocket, request: IncomingMessage, ctx: KoaContext) {
|
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);
|
this.clients.add(socket);
|
||||||
socket.on('close', () => {
|
socket.on('close', () => {
|
||||||
this.clients.delete(socket);
|
this.clients.delete(socket);
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import AnsiUp from 'ansi_up';
|
import AnsiUp from 'ansi_up';
|
||||||
import moment from 'moment-timezone';
|
import { moment, ObjectID } from 'hydrooj';
|
||||||
import { ObjectID } from 'mongodb';
|
|
||||||
|
|
||||||
export { size, formatSeconds } from '@hydrooj/utils/lib/utils';
|
export { size, formatSeconds } from 'hydrooj';
|
||||||
|
|
||||||
const AU = new AnsiUp();
|
const AU = new AnsiUp();
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const yaml = require('js-yaml');
|
const { serialize, fs, yaml } = require('hydrooj');
|
||||||
const serialize = require('serialize-javascript');
|
|
||||||
const nunjucks = require('nunjucks');
|
const nunjucks = require('nunjucks');
|
||||||
const jsesc = require('jsesc');
|
const jsesc = require('jsesc');
|
||||||
const argv = require('cac')().parse();
|
const argv = require('cac')().parse();
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ export default function (env: { watch?: boolean, production?: boolean, measure?:
|
|||||||
const p = pathData.module.resource.replace(/\\/g, '/');
|
const p = pathData.module.resource.replace(/\\/g, '/');
|
||||||
const filename = p.split('/').pop();
|
const filename = p.split('/').pop();
|
||||||
if (p.includes('node_modules')) {
|
if (p.includes('node_modules')) {
|
||||||
const extra = p.split('node_modules')[1];
|
const extra = p.split('node_modules/').pop();
|
||||||
const moduleName = extra.split('/')[0];
|
const moduleName = extra.split('/')[0];
|
||||||
if (extra.includes('@fontsource')) {
|
if (extra.includes('@fontsource')) {
|
||||||
return `fonts/${filename}?[hash:6]`;
|
return `fonts/${filename}?[hash:6]`;
|
||||||
@@ -198,7 +198,7 @@ export default function (env: { watch?: boolean, production?: boolean, measure?:
|
|||||||
test: /[\\/]node_modules[\\/].+\.([jt]sx?|json|yaml)$/,
|
test: /[\\/]node_modules[\\/].+\.([jt]sx?|json|yaml)$/,
|
||||||
priority: -10,
|
priority: -10,
|
||||||
name(module) {
|
name(module) {
|
||||||
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
|
const packageName = module.context.replace(/\\/g, '/').split('node_modules/').pop().split('/')[0];
|
||||||
if (packageName === 'monaco-editor-nls') {
|
if (packageName === 'monaco-editor-nls') {
|
||||||
return `i.monaco.${module.userRequest.split('/').pop().split('.')[0]}`;
|
return `i.monaco.${module.userRequest.split('/').pop().split('.')[0]}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,6 +90,7 @@
|
|||||||
"redux-promise-middleware": "^6.1.3",
|
"redux-promise-middleware": "^6.1.3",
|
||||||
"redux-thunk": "^2.4.2",
|
"redux-thunk": "^2.4.2",
|
||||||
"rupture": "^0.7.1",
|
"rupture": "^0.7.1",
|
||||||
|
"schemastery": "^3.6.1",
|
||||||
"slideout": "^1.0.1",
|
"slideout": "^1.0.1",
|
||||||
"sticky-kit": "^1.1.3",
|
"sticky-kit": "^1.1.3",
|
||||||
"tether": "1.4.7",
|
"tether": "1.4.7",
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const vm = require('vm');
|
|||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const esbuild = require('esbuild');
|
const esbuild = require('esbuild');
|
||||||
|
|
||||||
if (!process.env.NODE_APP_INSTANCE) process.env.NODE_APP_INSTANCE = '0';
|
process.env.NODE_APP_INSTANCE ||= '0';
|
||||||
const major = +process.version.split('.')[0].split('v')[1];
|
const major = +process.version.split('.')[0].split('v')[1];
|
||||||
const minor = +process.version.split('.')[1];
|
const minor = +process.version.split('.')[1];
|
||||||
|
|
||||||
@@ -86,4 +86,4 @@ if (argv.options.debug) {
|
|||||||
console.log('Debug mode enabled');
|
console.log('Debug mode enabled');
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
process.env.DEV = 'on';
|
process.env.DEV = 'on';
|
||||||
} else process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
} else process.env.NODE_ENV ||= 'production';
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
packages:
|
||||||
|
- packages/*
|
||||||
|
- plugins/*
|
||||||
Reference in new issue
Block a user