Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(patchers): fix patching modules resolving by require.resolve #240

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* @copyright Copyright (c) 2022 Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
* @copyright Copyright (c) 2023 Grigorii Shartsev <me@shgk.me>
*
* @author Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
* @author Grigorii Shartsev <me@shgk.me>
*
* @license GNU AGPL version 3 or any later version
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -19,12 +19,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { appData } from '../app/AppData.js'
import { appData } from '../../app/AppData.js'

export {
getRequestToken,
onRequestTokenUpdate,
} from '@talk/node_modules/@nextcloud/auth/dist/index.esm.js'
} from '@talk-modules--@nextcloud/auth'

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* @copyright Copyright (c) 2022 Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
* @copyright Copyright (c) 2023 Grigorii Shartsev <me@shgk.me>
*
* @author Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
* @author Grigorii Shartsev <me@shgk.me>
*
* @license GNU AGPL version 3 or any later version
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import axios from '../../node_modules/@nextcloud/axios/dist/index.esm.js'
import axios from '@desktop-modules--@nextcloud/axios'

axios.interceptors.request.use((config) => {
config.withCredentials = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* @copyright Copyright (c) 2022 Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
* @copyright Copyright (c) 2023 Grigorii Shartsev <me@shgk.me>
*
* @author Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
* @author Grigorii Shartsev <me@shgk.me>
*
* @license GNU AGPL version 3 or any later version
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { appData } from '../app/AppData.js'
import { appData } from '../../app/AppData.js'

/**
* Generates Initial State-like object based on capablilities and user metadata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* @copyright Copyright (c) 2022 Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
* @copyright Copyright (c) 2023 Grigorii Shartsev <me@shgk.me>
*
* @author Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
* @author Grigorii Shartsev <me@shgk.me>
*
* @license GNU AGPL version 3 or any later version
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -21,9 +21,9 @@

/* eslint-disable jsdoc/require-jsdoc */

import { getRootUrl, generateFilePath as _generateFilePath } from '../../node_modules/@nextcloud/router/dist/index.js'
import { getRootUrl, generateFilePath as _generateFilePath } from '@desktop-modules--@nextcloud/router'

export { linkTo, getRootUrl, generateUrl } from '../../node_modules/@nextcloud/router/dist/index.js'
export { linkTo, getRootUrl, generateUrl } from '@desktop-modules--@nextcloud/router'

/**
* @param {string} s - String with "{token}" blocks
Expand Down Expand Up @@ -73,7 +73,7 @@ export function generateFilePath(app, type, file) {
}
} else if (app === 'notifications' && ext === '.ogg') {
// For now notifications sounds are just a copy of the notifications app sounds
return require(`../../sounds/${filename}.ogg`)
return require(`../../../sounds/${filename}.ogg`)
}

return _generateFilePath(app, type, file)
Expand Down
2 changes: 1 addition & 1 deletion src/patchers/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { loadState } from './nextcloud-initial-state.js'
import { loadState } from '@nextcloud/initial-state'
import { appData } from '../app/AppData.js'

export const OC = {
Expand Down
39 changes: 34 additions & 5 deletions webpack.renderer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ process.env.npm_package_version = talkPackage.version
const nextcloudWebpackConfig = require('@nextcloud/webpack-vue-config')
const commonTalkWebpackConfig = require(`${TALK_PATH}/webpack.common.config`)

/**
* Create webpack aliases config to patch a package
*
* @param {string} packageName - name of the package to patch, for example, @nextcloud/axios
* @return {Object<string, string>} webpack.resolve.alice config object with at most 3 aliases:
* - Alias from package to the patcher (e.g. @nextcloud/axios)
* - Alias to the original module in spreed (e.g. @talk-modules--@nextcloud/axios)
* - Alias to the original module in talk-desktop (e.g. @desktop-modules--@nextcloud/axios)
*/
function createPatcherAliases(packageName) {
// Try to resolve a package. If it throws then there is no such package, do not create an alias
let talkModulePath = false
try {
talkModulePath = require.resolve(packageName, { paths: [TALK_PATH] })
} catch {}

let desktopModulePath = false
try {
desktopModulePath = require.resolve(packageName)
} catch {}

// webpack.resolve.aliases
return {
[`${packageName}$`]: path.resolve(__dirname, `src/patchers/${packageName}.js`),
[`@talk-modules--${packageName}$`]: talkModulePath,
[`@desktop-modules--${packageName}$`]: desktopModulePath,
}
}

const merge = mergeWithRules({
module: {
rules: {
Expand Down Expand Up @@ -85,11 +114,11 @@ module.exports = merge(commonTalkWebpackConfig, {
resolve: {
alias: {
'@talk': TALK_PATH,
'@nextcloud/initial-state$': path.resolve(__dirname, 'src/patchers/nextcloud-initial-state.js'),
'@nextcloud/axios$': path.resolve(__dirname, 'src/patchers/nextcloud-axios.js'),
'@nextcloud/router$': path.resolve(__dirname, 'src/patchers/nextcloud-router.js'),
'@nextcloud/auth$': path.resolve(__dirname, 'src/patchers/nextcloud-auth.js'),
'@nextcloud/notify_push$': path.resolve(__dirname, 'src/patchers/nextcloud-notify_push.js'),
...createPatcherAliases('@nextcloud/initial-state'),
...createPatcherAliases('@nextcloud/axios'),
...createPatcherAliases('@nextcloud/router'),
...createPatcherAliases('@nextcloud/auth'),
...createPatcherAliases('@nextcloud/notify_push'),
},
},

Expand Down