Skip to content

Commit

Permalink
Node: Migrate to ES Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Cohee1207 committed Oct 10, 2024
1 parent 5a52196 commit d52b4fb
Show file tree
Hide file tree
Showing 74 changed files with 1,301 additions and 1,150 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module.exports = {
env: {
node: true,
},
parserOptions: {
sourceType: 'module',
},
},
{
files: ['src/**/*.mjs'],
Expand Down
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "node",
"moduleResolution": "Node",
"strictNullChecks": true,
"strictFunctionTypes": true,
"checkJs": true,
Expand Down
438 changes: 413 additions & 25 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 22 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
"express": "^4.21.0",
"form-data": "^4.0.0",
"google-translate-api-browser": "^3.0.1",
"he": "^1.2.0",
"helmet": "^7.1.0",
"html-entities": "^2.5.2",
"iconv-lite": "^0.6.3",
"ip-matching": "^2.1.2",
"ipaddr.js": "^2.0.1",
"jimp": "^0.22.10",
"lodash": "^4.17.21",
"mime-types": "^2.1.35",
"multer": "^1.4.5-lts.1",
"node-fetch": "^2.6.11",
"node-fetch": "^3.3.2",
"node-persist": "^4.0.1",
"open": "^8.4.2",
"png-chunk-text": "^1.0.0",
Expand Down Expand Up @@ -60,7 +60,7 @@
}
},
"name": "sillytavern",
"type": "commonjs",
"type": "module",
"license": "AGPL-3.0",
"repository": {
"type": "git",
Expand All @@ -85,9 +85,28 @@
},
"main": "server.js",
"devDependencies": {
"@types/archiver": "^6.0.2",
"@types/command-exists": "^1.2.3",
"@types/compression": "^1.7.5",
"@types/cookie-parser": "^1.4.7",
"@types/cookie-session": "^2.0.49",
"@types/cors": "^2.8.17",
"@types/dompurify": "^3.0.5",
"@types/express": "^5.0.0",
"@types/jquery": "^3.5.29",
"@types/lodash": "^4.17.10",
"@types/mime-types": "^2.1.4",
"@types/multer": "^1.4.12",
"@types/node-fetch": "^2.6.11",
"@types/node-persist": "^3.1.8",
"@types/png-chunk-text": "^1.0.3",
"@types/png-chunks-encode": "^1.0.2",
"@types/png-chunks-extract": "^1.0.2",
"@types/response-time": "^2.3.8",
"@types/toastr": "^2.1.43",
"@types/write-file-atomic": "^4.0.3",
"@types/yargs": "^17.0.33",
"@types/yauzl": "^2.10.3",
"eslint": "^8.57.0"
}
}
9 changes: 5 additions & 4 deletions plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// 1. node plugins.js update
// 2. node plugins.js install <plugin-git-url>
// More operations coming soon.
const { default: git } = require('simple-git');
const fs = require('fs');
const path = require('path');
const { color } = require('./src/util');
import { default as git } from 'simple-git';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { color } from './src/util.js';

const __dirname = import.meta.dirname;
process.chdir(__dirname);
const pluginsPath = './plugins';

Expand Down
14 changes: 8 additions & 6 deletions post-install.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* Scripts to be done before starting the server for the first time.
*/
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const yaml = require('yaml');
const _ = require('lodash');
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as crypto from 'node:crypto';
import * as yaml from 'yaml';
import _ from 'lodash';
import { createRequire } from 'node:module';

/**
* Colorizes console output.
Expand Down Expand Up @@ -59,6 +60,7 @@ function convertConfig() {

try {
console.log(color.blue('Converting config.conf to config.yaml. Your old config.conf will be renamed to config.conf.bak'));
const require = createRequire(import.meta.url);
const config = require(path.join(process.cwd(), './config.conf'));
fs.copyFileSync('./config.conf', './config.conf.bak');
fs.rmSync('./config.conf');
Expand All @@ -75,7 +77,7 @@ function convertConfig() {
* Compares the current config.yaml with the default config.yaml and adds any missing values.
*/
function addMissingConfigValues() {
try {
try {
const defaultConfig = yaml.parse(fs.readFileSync(path.join(process.cwd(), './default/config.yaml'), 'utf8'));
let config = yaml.parse(fs.readFileSync(path.join(process.cwd(), './config.yaml'), 'utf8'));

Expand Down
8 changes: 4 additions & 4 deletions recover.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const yaml = require('yaml');
const fs = require('fs');
const storage = require('node-persist');
const users = require('./src/users');
import * as fs from 'node:fs';
import yaml from 'yaml';
import storage from 'node-persist';
import * as users from './src/users';

const userAccount = process.argv[2];
const userPassword = process.argv[3];
Expand Down
Loading

0 comments on commit d52b4fb

Please sign in to comment.