Skip to content

Commit

Permalink
use .js extension for require() as a preparation for future migration…
Browse files Browse the repository at this point in the history
… to ESM
  • Loading branch information
zadam committed Nov 22, 2023
1 parent 722299d commit cf99345
Show file tree
Hide file tree
Showing 189 changed files with 986 additions and 986 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ the "copyright" line and a pointer to where the full notice is found.
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.js.gnu.org/licenses/>.

This comment has been minimized.

Copy link
@rom1dep

rom1dep Jan 24, 2024

@zadam could this be unintended?

This comment has been minimized.

Copy link
@zadam

zadam Jan 28, 2024

Author Owner

yes, thanks for catching this.


Also add information on how to contact you by electronic and paper mail.

Expand All @@ -658,4 +658,4 @@ specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<http://www.gnu.org/licenses/>.
<http://www.js.gnu.org/licenses/>.

This comment has been minimized.

Copy link
@rom1dep

rom1dep Jan 24, 2024

@zadam could this be unintended?

2 changes: 1 addition & 1 deletion bin/create-anonymization-script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

const anonymizationService = require('../src/services/anonymization');
const anonymizationService = require('../src/services/anonymization.js');
const fs = require('fs');
const path = require('path');

Expand Down
4 changes: 2 additions & 2 deletions db/migrations/0216__move_content_into_blobs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = () => {
const sql = require("../../src/services/sql");
const utils = require("../../src/services/utils");
const sql = require('../../src/services/sql.js');
const utils = require('../../src/services/utils.js');

const existingBlobIds = new Set();

Expand Down
10 changes: 5 additions & 5 deletions db/migrations/0220__migrate_images_to_attachments.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = () => {
const beccaLoader = require("../../src/becca/becca_loader");
const becca = require("../../src/becca/becca");
const cls = require("../../src/services/cls");
const log = require("../../src/services/log");
const sql = require("../../src/services/sql");
const beccaLoader = require('../../src/becca/becca_loader.js');
const becca = require('../../src/becca/becca.js');
const cls = require('../../src/services/cls.js');
const log = require('../../src/services/log.js');
const sql = require('../../src/services/sql.js');

cls.init(() => {
// emergency disabling of image compression since it appears to make problems in migration to 0.61
Expand Down
6 changes: 3 additions & 3 deletions docker_healthcheck.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const http = require("http");
const ini = require("ini");
const fs = require("fs");
const dataDir = require("./src/services/data_dir");
const dataDir = require('./src/services/data_dir.js');
const config = ini.parse(fs.readFileSync(dataDir.CONFIG_INI_PATH, 'utf-8'));

if (config.Network.https) {
Expand All @@ -10,8 +10,8 @@ if (config.Network.https) {
process.exit(0);
}

const port = require('./src/services/port');
const host = require('./src/services/host');
const port = require('./src/services/port.js');
const host = require('./src/services/host.js');

const options = { timeout: 2000 };

Expand Down
2 changes: 1 addition & 1 deletion dump-db/dump-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const dumpService = require("./inc/dump");
const dumpService = require('./inc/dump.js');

yargs(hideBin(process.argv))
.command('$0 <path_to_document> <target_directory>', 'dump the contents of document.db into the target directory', (yargs) => {
Expand Down
4 changes: 2 additions & 2 deletions dump-db/inc/data_key.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const crypto = require("crypto");
const sql = require("./sql");
const decryptService = require("./decrypt");
const sql = require('./sql.js');
const decryptService = require('./decrypt.js');

function getDataKey(password) {
if (!password) {
Expand Down
8 changes: 4 additions & 4 deletions dump-db/inc/dump.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const fs = require("fs");
const sanitize = require("sanitize-filename");
const sql = require("./sql");
const decryptService = require("./decrypt");
const dataKeyService = require("./data_key");
const extensionService = require("./extension");
const sql = require('./sql.js');
const decryptService = require('./decrypt.js');
const dataKeyService = require('./data_key.js');
const extensionService = require('./extension.js');

function dumpDocument(documentPath, targetPath, options) {
const stats = {
Expand Down
10 changes: 5 additions & 5 deletions electron.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

const {app, globalShortcut, BrowserWindow} = require('electron');
const sqlInit = require('./src/services/sql_init');
const appIconService = require('./src/services/app_icon');
const windowService = require('./src/services/window');
const tray = require('./src/services/tray');
const sqlInit = require('./src/services/sql_init.js');
const appIconService = require('./src/services/app_icon.js');
const windowService = require('./src/services/window.js');
const tray = require('./src/services/tray.js');

// Adds debug features like hotkeys for triggering dev tools and reload
require('electron-debug')();
Expand Down Expand Up @@ -59,4 +59,4 @@ app.on('will-quit', () => {
// this is to disable electron warning spam in the dev console (local development only)
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';

require('./src/www');
require('./src/www.js');
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
"license": "AGPL-3.0-only",
"main": "electron.js",
"bin": {
"trilium": "./src/www"
"trilium": "src/www.js"
},
"repository": {
"type": "git",
"url": "https://github.com/zadam/trilium.git"
},
"scripts": {
"start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon ./src/www",
"start-server": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js",
"start-server-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js",
"qstart-server": "npm run qswitch-server && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 nodemon src/www.js",
"start-electron": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .",
"start-electron-no-dir": "cross-env TRILIUM_SAFE_MODE=1 TRILIUM_ENV=dev TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 electron --inspect=5858 .",
"qstart-electron": "npm run qswitch-electron && TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev electron --inspect=5858 .",
"start-test-server": "npm run qswitch-server; rm -rf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 node ./src/www",
"start-test-server": "npm run qswitch-server; rm -rf ./data-test; cross-env TRILIUM_SAFE_MODE=1 TRILIUM_DATA_DIR=./data-test TRILIUM_SYNC_SERVER_HOST=http://tsyncserver:4000 TRILIUM_ENV=dev TRILIUM_PORT=9999 node src/www.js",
"switch-server": "rm -rf ./node_modules/better-sqlite3 && npm install",
"switch-electron": "./node_modules/.bin/electron-rebuild",
"qswitch-server": "rm -rf ./node_modules/better-sqlite3/bin ; mkdir -p ./node_modules/better-sqlite3/build ; cp ./bin/better-sqlite3/linux-server-better_sqlite3.node ./node_modules/better-sqlite3/build/better_sqlite3.node",
Expand Down
2 changes: 1 addition & 1 deletion spec/etapi/app_info.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
describeEtapi, postEtapi,
putEtapiContent
} = require("../support/etapi");
} = require('../support/etapi.js');
const {getEtapi} = require("../support/etapi.js");

describeEtapi("app_info", () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/etapi/backup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
describeEtapi, postEtapi,
getEtapi,
} = require("../support/etapi");
} = require('../support/etapi.js');
const {putEtapiContent} = require("../support/etapi.js");

describeEtapi("backup", () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/etapi/import.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
describeEtapi, postEtapi,
postEtapiContent,
} = require("../support/etapi");
} = require('../support/etapi.js');
const fs = require("fs");
const path = require("path");
const {getEtapiContent} = require("../support/etapi.js");
Expand Down
2 changes: 1 addition & 1 deletion spec/etapi/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
getEtapiContent,
patchEtapi, putEtapi,
putEtapiContent
} = require("../support/etapi");
} = require('../support/etapi.js');

describeEtapi("notes", () => {
it("create", async () => {
Expand Down
8 changes: 4 additions & 4 deletions spec/search/becca_mocking.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const BNote = require('../../src/becca/entities/bnote');
const BBranch = require('../../src/becca/entities/bbranch');
const BAttribute = require('../../src/becca/entities/battribute');
const becca = require('../../src/becca/becca');
const BNote = require('../../src/becca/entities/bnote.js');
const BBranch = require('../../src/becca/entities/bbranch.js');
const BAttribute = require('../../src/becca/entities/battribute.js');
const becca = require('../../src/becca/becca.js');
const randtoken = require('rand-token').generator({source: 'crypto'});

/** @returns {BNote} */
Expand Down
2 changes: 1 addition & 1 deletion spec/search/lexer.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const lex = require('../../src/services/search/services/lex');
const lex = require('../../src/services/search/services/lex.js');

describe("Lexer fulltext", () => {
it("simple lexing", () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/search/parens.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const handleParens = require('../../src/services/search/services/handle_parens');
const handleParens = require('../../src/services/search/services/handle_parens.js');

describe("Parens handler", () => {
it("handles parens", () => {
Expand Down
4 changes: 2 additions & 2 deletions spec/search/parser.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const SearchContext = require("../../src/services/search/search_context");
const parse = require('../../src/services/search/services/parse');
const SearchContext = require('../../src/services/search/search_context.js');
const parse = require('../../src/services/search/services/parse.js');

function tokens(toks, cur = 0) {
return toks.map(arg => {
Expand Down
14 changes: 7 additions & 7 deletions spec/search/search.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const searchService = require('../../src/services/search/services/search');
const BNote = require('../../src/becca/entities/bnote');
const BBranch = require('../../src/becca/entities/bbranch');
const SearchContext = require('../../src/services/search/search_context');
const dateUtils = require('../../src/services/date_utils');
const becca = require('../../src/becca/becca');
const {NoteBuilder, findNoteByTitle, note} = require('./becca_mocking');
const searchService = require('../../src/services/search/services/search.js');
const BNote = require('../../src/becca/entities/bnote.js');
const BBranch = require('../../src/becca/entities/bbranch.js');
const SearchContext = require('../../src/services/search/search_context.js');
const dateUtils = require('../../src/services/date_utils.js');
const becca = require('../../src/becca/becca.js');
const {NoteBuilder, findNoteByTitle, note} = require('./becca_mocking.js');

describe("Search", () => {
let rootNote;
Expand Down
8 changes: 4 additions & 4 deletions spec/search/value_extractor.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {note} = require('./becca_mocking');
const ValueExtractor = require('../../src/services/search/value_extractor');
const becca = require('../../src/becca/becca');
const SearchContext = require("../../src/services/search/search_context");
const {note} = require('./becca_mocking.js');
const ValueExtractor = require('../../src/services/search/value_extractor.js');
const becca = require('../../src/becca/becca.js');
const SearchContext = require('../../src/services/search/search_context.js');

const dsc = new SearchContext();

Expand Down
6 changes: 3 additions & 3 deletions src/anonymize.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const anonymizationService = require('./services/anonymization');
const sqlInit = require('./services/sql_init');
require('./becca/entity_constructor');
const anonymizationService = require('./services/anonymization.js');
const sqlInit = require('./services/sql_init.js');
require('./becca/entity_constructor.js');

sqlInit.dbReady.then(async () => {
try {
Expand Down
24 changes: 12 additions & 12 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const favicon = require('serve-favicon');
const cookieParser = require('cookie-parser');
const helmet = require('helmet');
const compression = require('compression');
const sessionParser = require('./routes/session_parser');
const utils = require('./services/utils');
const sessionParser = require('./routes/session_parser.js');
const utils = require('./services/utils.js');

require('./services/handlers');
require('./becca/becca_loader');
require('./services/handlers.js');
require('./becca/becca_loader.js');

const app = express();

Expand Down Expand Up @@ -37,21 +37,21 @@ app.use(`/robots.txt`, express.static(path.join(__dirname, 'public/robots.txt'))
app.use(sessionParser);
app.use(favicon(`${__dirname}/../images/app-icons/win/icon.ico`));

require('./routes/assets').register(app);
require('./routes/routes').register(app);
require('./routes/custom').register(app);
require('./routes/error_handlers').register(app);
require('./routes/assets.js').register(app);
require('./routes/routes.js').register(app);
require('./routes/custom.js').register(app);
require('./routes/error_handlers.js').register(app);

// triggers sync timer
require('./services/sync');
require('./services/sync.js');

// triggers backup timer
require('./services/backup');
require('./services/backup.js');

// trigger consistency checks timer
require('./services/consistency_checks');
require('./services/consistency_checks.js');

require('./services/scheduler');
require('./services/scheduler.js');

if (utils.isElectron()) {
require('@electron/remote/main').initialize();
Expand Down
18 changes: 9 additions & 9 deletions src/becca/becca.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

const sql = require("../services/sql");
const NoteSet = require("../services/search/note_set");
const NotFoundError = require("../errors/not_found_error");
const sql = require('../services/sql.js');
const NoteSet = require('../services/search/note_set.js');
const NotFoundError = require('../errors/not_found_error.js');

/**
* Becca is a backend cache of all notes, branches, and attributes.
Expand Down Expand Up @@ -148,7 +148,7 @@ class Becca {
getRevision(revisionId) {
const row = sql.getRow("SELECT * FROM revisions WHERE revisionId = ?", [revisionId]);

const BRevision = require("./entities/brevision"); // avoiding circular dependency problems
const BRevision = require('./entities/brevision.js'); // avoiding circular dependency problems
return row ? new BRevision(row) : null;
}

Expand All @@ -163,7 +163,7 @@ class Becca {
WHERE attachmentId = ? AND isDeleted = 0`
: `SELECT * FROM attachments WHERE attachmentId = ? AND isDeleted = 0`;

const BAttachment = require("./entities/battachment"); // avoiding circular dependency problems
const BAttachment = require('./entities/battachment.js'); // avoiding circular dependency problems

return sql.getRows(query, [attachmentId])
.map(row => new BAttachment(row))[0];
Expand All @@ -180,7 +180,7 @@ class Becca {

/** @returns {BAttachment[]} */
getAttachments(attachmentIds) {
const BAttachment = require("./entities/battachment"); // avoiding circular dependency problems
const BAttachment = require('./entities/battachment.js'); // avoiding circular dependency problems
return sql.getManyRows("SELECT * FROM attachments WHERE attachmentId IN (???) AND isDeleted = 0", attachmentIds)
.map(row => new BAttachment(row));
}
Expand All @@ -189,7 +189,7 @@ class Becca {
getBlob(entity) {
const row = sql.getRow("SELECT *, LENGTH(content) AS contentLength FROM blobs WHERE blobId = ?", [entity.blobId]);

const BBlob = require("./entities/bblob"); // avoiding circular dependency problems
const BBlob = require('./entities/bblob.js'); // avoiding circular dependency problems
return row ? new BBlob(row) : null;
}

Expand Down Expand Up @@ -238,15 +238,15 @@ class Becca {
getRecentNotesFromQuery(query, params = []) {
const rows = sql.getRows(query, params);

const BRecentNote = require("./entities/brecent_note"); // avoiding circular dependency problems
const BRecentNote = require('./entities/brecent_note.js'); // avoiding circular dependency problems
return rows.map(row => new BRecentNote(row));
}

/** @returns {BRevision[]} */
getRevisionsFromQuery(query, params = []) {
const rows = sql.getRows(query, params);

const BRevision = require("./entities/brevision"); // avoiding circular dependency problems
const BRevision = require('./entities/brevision.js'); // avoiding circular dependency problems
return rows.map(row => new BRevision(row));
}

Expand Down
Loading

0 comments on commit cf99345

Please sign in to comment.