Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0914cb4
Rebased from latest
SamAxe Jun 3, 2025
897e862
Convert server to ESM
SamAxe Jun 4, 2025
ddb2beb
Formatting
SamAxe Jun 4, 2025
b8360cf
anticipate version code and test
SamAxe Jun 4, 2025
88e8f1f
Update default exports
SamAxe Jun 4, 2025
7638ba6
Merge commit '88e8f1fe234009545c57a584d0b4abe1d904a9eb' into decaffei…
paul90 Jul 16, 2025
2473b1a
A few extra ESM bits
paul90 Jul 17, 2025
6d64b1c
Replace require calls with ESM package.json imports
paul90 Jul 29, 2025
5943d9d
Add version test and test package version info
paul90 Aug 7, 2025
42ac7bd
add test watch
paul90 Aug 7, 2025
a5b6ecb
Refactor version endpoint to use dynamic imports
paul90 Aug 7, 2025
6a287f6
Move factory loading from startup back to request time
paul90 Aug 7, 2025
e85c819
Update import statements to modern ESM syntax
paul90 Sep 25, 2025
8a37261
Merge branch 'ESM' into next
paul90 Sep 25, 2025
1c7237a
0.26.0-rc.5
paul90 Sep 25, 2025
65b68b4
Add index.js as main entry point
paul90 Sep 27, 2025
89be7cc
0.26.0-rc.6
paul90 Sep 27, 2025
d71b24f
Corrent plugin loading for ESM
paul90 Oct 2, 2025
f1f1cca
improved import of plugin factory.json
paul90 Oct 25, 2025
5b9e59d
update dependencies
paul90 Nov 22, 2025
aeb5b65
0.26.0-rc.7
paul90 Nov 22, 2025
8e7c18e
Refactor package import with async fallback
paul90 Nov 29, 2025
b07f14c
update dependencies
paul90 Dec 1, 2025
4c9a50a
0.26.0-rc.8
paul90 Dec 1, 2025
1fc8468
import alt only if not already done
paul90 Dec 1, 2025
a27ab9f
requested package, not just wiki
paul90 Dec 2, 2025
a6f7485
0.26.0-rc.9
paul90 Dec 2, 2025
97baca7
remove extra trailing blank line
paul90 Dec 4, 2025
2a71704
fix for fedwiki/wiki-server#203
paul90 Dec 4, 2025
ecf9007
0.26.0-rc.10
paul90 Dec 4, 2025
ecf9adf
also dotfiles for default favicon
paul90 Dec 6, 2025
4646d8c
0.26.0-rc.11
paul90 Dec 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default [
{ ignores: ['client/*'] },
{
languageOptions: {
sourceType: 'commonjs',
sourceType: 'module',
globals: {
wiki: 'readonly',
...globals.node,
Expand Down
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// Simple file so that if you require this directory
// in node it instead requires ./lib/server.coffee
// with coffee-script already loaded.
require('coffeescript')
require('coffeescript/register')
// import('coffeescript')
// import('coffeescript/register.js')

module.exports = require('./lib/server')
// const { default: server } = await import('./lib/server.js')
// export default server

import { default as server } from './lib/server.js'
export default server
20 changes: 13 additions & 7 deletions lib/defaultargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
// **defaultargs.coffee** when called on the argv object this
// module will create reasonable defaults for options not supplied,
// based on what information is provided.
const path = require('node:path')
import path from 'node:path'
import { randomBytes } from 'node:crypto'
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const getUserHome = () => {
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
}

module.exports = argv => {
export default argv => {
argv = argv || {}
argv.root ||= __dirname
// the directory that contains all the packages that makeup the wiki
Expand All @@ -32,7 +38,7 @@ module.exports = argv => {
argv.url ||= `http://localhost${argv.port === 80 ? '' : ':' + argv.port}`
argv.id ||= path.join(argv.status, 'owner.json')
argv.uploadLimit ||= '5mb'
argv.cookieSecret ||= require('crypto').randomBytes(64).toString('hex')
argv.cookieSecret ||= randomBytes(64).toString('hex')
argv.secure_cookie ||= false
argv.session_duration ||= 7
argv.neighbors ||= ''
Expand All @@ -43,18 +49,18 @@ module.exports = argv => {
argv.database = JSON.parse(argv.database)
}
argv.database ||= {}
argv.database.type ||= './page'
argv.database.type ||= './page.js'
if (argv.database.type.charAt(0) === '.') {
if (argv.database.type != './page') {
if (argv.database.type != './page.js') {
console.log('\n\nWARNING: This storage option is depeciated.')
console.log(' See ReadMe for details of the changes required.\n\n')
}
} else {
argv.database.type = 'wiki-storage-' + argv.database.type
}

argv.security_type ||= './security'
if (argv.security_type === './security') {
argv.security_type ||= './security.js'
if (argv.security_type === './security.js') {
console.log('\n\nINFORMATION: Using default security module.')
} else {
argv.security_type = 'wiki-security-' + argv.security_type
Expand Down
3 changes: 1 addition & 2 deletions lib/forward.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const init = (app, emitter) => {
export const init = (app, emitter) => {
let sockets = []
app.io.on('connection', socket => {
let listeners = []
Expand Down Expand Up @@ -35,4 +35,3 @@ const init = (app, emitter) => {
})
})
}
module.exports = { init }
61 changes: 50 additions & 11 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,53 @@
// Everything is stored using json flat files.

// #### Requires ####
const fs = require('fs')
const path = require('path')
const events = require('events')
// const fs = require('fs')
// const path = require('path')
// const events = require('events')
// const glob = require('glob')
//
// const async = require('async')
//
// // const random_id = require('./random_id.cjs')
// const synopsis = require('wiki-client/lib/synopsis')

import fs from 'node:fs'
import path from 'node:path'
import url from 'node:url'
import events from 'node:events'

import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)

// Use dynamic import to load package.json from the main application's working directory
const wikiPackageImport = async () => {
let done = false
return new Promise(resolve => {
import('wiki/package.json', { with: { type: 'json' } })
.then(imported => {
done = true
resolve(imported.default)
})
.catch(e => {
return e
})
.then(async () => {
if (done) return
const packageJsonPath = path.join(process.cwd(), 'package.json')
const packageJsonUrl = url.pathToFileURL(packageJsonPath).href
import(packageJsonUrl, { with: { type: 'json' } })
.then(imported => {
resolve(imported.default)
})
.catch(e => console.error('problems importing package', e))
})
})
}

const random_id = require('./random_id')
const synopsis = require('wiki-client/lib/synopsis')
const packageJson = await wikiPackageImport()

// import random_id from './random_id.cjs'; // Uncomment if needed
import synopsis from 'wiki-client/lib/synopsis.js' // Add correct extension if necessary

const asSlug = name =>
name
Expand All @@ -25,7 +66,7 @@ const asSlug = name =>

// Export a function that generates a page handler
// when called with options object.
module.exports = exports = argv => {
export default argv => {
const wikiName = new URL(argv.url).hostname

fs.mkdir(argv.db, { recursive: true }, e => {
Expand All @@ -34,13 +75,11 @@ module.exports = exports = argv => {

// create a list of plugin pages.
const pluginPages = new Map()
Object.keys(require.main.require('./package').dependencies)

Object.keys(packageJson.dependencies)
.filter(depend => depend.startsWith('wiki-plugin'))
.forEach(plugin => {
const pagesPath = path.join(
path.dirname(require.resolve(`${plugin}/package`, { paths: require.main.paths })),
'pages',
)
const pagesPath = path.join(path.dirname(require.resolve(`${plugin}/package`)), 'pages')
fs.readdir(pagesPath, { withFileTypes: true }, (err, entries) => {
if (err) return
entries.forEach(entry => {
Expand Down
15 changes: 6 additions & 9 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

// support server-side plugins

const fs = require('node:fs')
const { pathToFileURL } = require('node:url')
// forward = require './forward'
import fs from 'node:fs'
import { pathToFileURL } from 'node:url'
// import forward from './forward.cjs'; // Uncomment if needed and adjust import style if it's not a default export

module.exports = exports = argv => {
export default argv => {
// NOTE: plugins are now in their own package directories alongside this one...
// Plugins are in directories of the form wiki-package-*
// those with a server component will have a server directory
Expand All @@ -39,11 +39,8 @@ module.exports = exports = argv => {
}

const startServers = params => {
// emitter = new events.EventEmitter()
// forward.init params.app, emitter
// params.emitter = emitter

Object.keys(require.main.require('./package').dependencies)
const dependencies = params.packageJson.dependencies
Object.keys(dependencies)
.filter(depend => depend.startsWith('wiki-plugin'))
.forEach(plugin => {
startServer(params, plugin)
Expand Down
4 changes: 1 addition & 3 deletions lib/random_id.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@
// Simple random hex generator, takes an optional number of
// chars that defaults to 16 and returns a random id.

const random_id = (chars = 16) => [...Array(chars)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')

module.exports = random_id.random_id = random_id
export default (chars = 16) => [...Array(chars)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')
14 changes: 7 additions & 7 deletions lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

// **search.js**

const fs = require('node:fs')
const path = require('node:path')
const events = require('node:events')
const url = require('node:url')
const writeFileAtomic = require('write-file-atomic')
import fs from 'node:fs'
import path from 'node:path'
import events from 'node:events'
import url from 'node:url'
import writeFileAtomic from 'write-file-atomic'

const miniSearch = require('minisearch')
import miniSearch from 'minisearch'

module.exports = exports = argv => {
export default argv => {
const wikiName = new URL(argv.url).hostname
let siteIndex = []
const queue = []
Expand Down
15 changes: 12 additions & 3 deletions lib/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// allow the server to run read-only.

// #### Requires ####
const fs = require('node:fs')
import fs from 'node:fs'

// Export a function that generates security handler
// when called with options object.
module.exports = exports = (log, loga, argv) => {
export default (log, loga, argv) => {
const security = {}

// #### Private utility methods. ####
Expand Down Expand Up @@ -84,7 +84,16 @@ module.exports = exports = (log, loga, argv) => {
}
// Wiki server admin
security.isAdmin = () => {
return false
// nobody is admin - unless legacy support, and test
if (argv.security_legacy) {
if (argv.test) {
return true
} else {
return false
}
} else {
return false
}
}
security.defineRoutes = (app, cors, updateOwner) => {
// default security does not have any routes
Expand Down
Loading