Skip to content

Commit 7afef98

Browse files
author
CI Fix
committed
update to esm only
1 parent 32e473c commit 7afef98

File tree

19 files changed

+1159
-904
lines changed

19 files changed

+1159
-904
lines changed

bin/lib/updateIndex.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { initConfigDir, initTemplateDirs } from '../../lib/server-config.mjs';
1212

1313
export default function (program) {
1414
program
15-
.command('updateindex')
15+
.command('updateindex.mjs')
1616
.description('Update index.html in root of all PODs that haven\'t been marked otherwise')
1717
.action(async (options) => {
1818
const config = loadConfig(program, options);

index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import ldnode from './lib/create-app.mjs'
21
import createServer from './lib/create-server.mjs'
2+
import ldnode from './lib/create-app.mjs'
33
import startCli from './bin/lib/cli.mjs'
44

55
// Preserve the CommonJS-style shape where the default export has

lib/create-app.mjs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
// import { createRequire } from 'module'
2+
// const require = createRequire(import.meta.url)
13
import express from 'express'
24
import session from 'express-session'
35
import handlebars from 'express-handlebars'
46
import { v4 as uuid } from 'uuid'
57
import cors from 'cors'
68
import vhost from 'vhost'
7-
import aclCheck from '@solid/acl-check'
89
import path from 'path'
9-
import { createRequire } from 'module'
10+
import aclCheck from '@solid/acl-check'
11+
import fs from 'fs'
1012
import { fileURLToPath } from 'url'
1113
import { dirname } from 'path'
1214
import acceptEventsModule from 'express-accept-events'
@@ -18,29 +20,28 @@ import prepModule from 'express-prep'
1820
const __filename = fileURLToPath(import.meta.url)
1921
const __dirname = dirname(__filename)
2022

21-
// Create require for accessing CommonJS modules and package.json
22-
const require = createRequire(import.meta.url)
23-
const { version } = require('../package.json')
23+
// Read package.json synchronously to avoid using require() for JSON
24+
const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'))
2425

2526
// Complex internal modules - keep as CommonJS for now except where ESM available
26-
const LDP = require('./ldp.js')
27+
import LDP from './ldp.mjs'
2728
import LdpMiddleware from './ldp-middleware.mjs'
28-
const corsProxy = require('./handlers/cors-proxy.js')
29-
const authProxy = require('./handlers/auth-proxy.js')
30-
const SolidHost = require('./models/solid-host.js')
31-
const AccountManager = require('./models/account-manager.js')
32-
const EmailService = require('./services/email-service.js')
33-
const TokenService = require('./services/token-service.js')
34-
const capabilityDiscovery = require('./capability-discovery.js')
35-
const paymentPointerDiscovery = require('./payment-pointer-discovery.js')
36-
const API = require('./api/index.js')
37-
const errorPages = require('./handlers/error-pages.js')
38-
const config = require('./server-config.js')
29+
import corsProxy from './handlers/cors-proxy.mjs'
30+
import authProxy from './handlers/auth-proxy.mjs'
31+
import SolidHost from'./models/solid-host.mjs'
32+
import AccountManager from './models/account-manager.mjs'
33+
import EmailService from './services/email-service.mjs'
34+
import TokenService from './services/token-service.mjs'
35+
import capabilityDiscovery from './capability-discovery.mjs'
36+
import paymentPointerDiscovery from './payment-pointer-discovery.mjs'
37+
import * as API from './api/index.mjs'
38+
import errorPages from './handlers/error-pages.mjs'
39+
import * as config from './server-config.mjs'
3940
import defaults from '../config/defaults.mjs'
40-
const options = require('./handlers/options.js')
41+
import options from './handlers/options.mjs'
4142
import { handlers as debug } from './debug.mjs'
4243
import { routeResolvedFile } from './utils.mjs'
43-
const ResourceMapper = require('./resource-mapper.js')
44+
import ResourceMapper from './resource-mapper.mjs'
4445

4546
// Extract default exports from ESM modules
4647
const acceptEvents = acceptEventsModule.default
@@ -94,7 +95,7 @@ function createApp (argv = {}) {
9495

9596
// Serve the public 'common' directory (for shared CSS files, etc)
9697
app.use('/common', express.static(path.join(__dirname, '../common')))
97-
app.use('/', express.static(path.dirname(require.resolve('mashlib/dist/databrowser.html')), { index: false }))
98+
app.use('/', express.static(path.dirname(import.meta.resolve('mashlib/dist/databrowser.html')), { index: false }))
9899
routeResolvedFile(app, '/common/js/', 'solid-auth-client/dist-lib/solid-auth-client.bundle.js')
99100
routeResolvedFile(app, '/common/js/', 'solid-auth-client/dist-lib/solid-auth-client.bundle.js.map')
100101
app.use('/.well-known', express.static(path.join(__dirname, '../common/well-known')))

lib/create-server.mjs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import fs from 'fs'
33
import https from 'https'
44
import http from 'http'
55
import SolidWs from 'solid-ws'
6-
import createApp from './create-app.mjs'
76
import globalTunnel from 'global-tunnel-ng'
8-
import { settings as debugSettings } from './debug.mjs'
9-
import { createRequire } from 'module'
7+
import debug from './debug.mjs'
8+
import createApp from './create-app.mjs'
109

1110
function createServer (argv, app) {
11+
console.log('Creating server with options:', argv)
1212
argv = argv || {}
1313
app = app || express()
1414
const ldpApp = createApp(argv)
@@ -20,8 +20,7 @@ function createServer (argv, app) {
2020
mount = mount.slice(0, -1)
2121
}
2222
app.use(mount, ldpApp)
23-
debugSettings('Base URL (--mount): ' + mount)
24-
23+
debug.settings('Base URL (--mount): ' + mount)
2524
if (argv.idp) {
2625
console.warn('The idp configuration option has been renamed to multiuser.')
2726
argv.multiuser = argv.idp
@@ -37,8 +36,8 @@ function createServer (argv, app) {
3736
if (!needsTLS) {
3837
server = http.createServer(app)
3938
} else {
40-
debugSettings('SSL Private Key path: ' + argv.sslKey)
41-
debugSettings('SSL Certificate path: ' + argv.sslCert)
39+
debug.settings('SSL Private Key path: ' + argv.sslKey)
40+
debug.settings('SSL Certificate path: ' + argv.sslCert)
4241

4342
if (!argv.sslCert && !argv.sslKey) {
4443
throw new Error('Missing SSL cert and SSL key to enable WebIDs')

lib/handlers/allow.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// TODO: This is a CommonJS wrapper. Use allow.mjs directly once ESM migration is complete.
22
module.exports = allow
33

4-
// const path = require('path')
54
const ACL = require('../acl-checker')
6-
// const debug = require('../debug.js').ACL
7-
// const error = require('../http-error')
5+
// const debug = require('../debug.js').server
86

97
function allow (mode) {
108
return async function allowHandler (req, res, next) {
@@ -78,7 +76,6 @@ function allow (mode) {
7876
if (resourceUrl.endsWith('.acl') && (await ldp.isOwner(userId, req.hostname))) return next()
7977
} catch (err) {}
8078
const error = req.authError || await req.acl.getError(userId, mode)
81-
// debug(`${mode} access denied to ${userId || '(none)'}: ${error.status} - ${error.message}`)
8279
next(error)
8380
}
8481
}

lib/handlers/allow.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ACL from '../acl-checker.mjs'
2+
// import { handlers as debug} from '../debug.mjs'
23

34
export default function allow (mode) {
45
return async function allowHandler (req, res, next) {
@@ -15,7 +16,7 @@ export default function allow (mode) {
1516
let resourcePath = res && res.locals && res.locals.path
1617
? res.locals.path
1718
: req.path
18-
19+
1920
// Check whether the resource exists
2021
let stat
2122
try {
@@ -72,7 +73,7 @@ export default function allow (mode) {
7273
if (resourceUrl.endsWith('.acl') && (await ldp.isOwner(userId, req.hostname))) return next()
7374
} catch (err) {}
7475
const error = req.authError || await req.acl.getError(userId, mode)
75-
// debug(`${mode} access denied to ${userId || '(none)'}: ${error.status} - ${error.message}`)
76+
// debug(`ALLOW -- ${mode} access denied to ${userId || '(none)'}: ${error.status} - ${error.message}`)
7677
next(error)
7778
}
7879
}

0 commit comments

Comments
 (0)