Skip to content

Commit 0e61454

Browse files
authored
Merge pull request #4276 from nextcloud/feat/migrate-to-vite
2 parents 316acb3 + eafc329 commit 0e61454

File tree

15 files changed

+2738
-1664
lines changed

15 files changed

+2738
-1664
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ module.exports = {
1414
plugins: [
1515
'cypress',
1616
],
17+
parserOptions: {
18+
babelOptions: {
19+
plugins: [
20+
'@babel/plugin-syntax-import-assertions',
21+
],
22+
},
23+
},
1724
}
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
const { join, basename } = require('path')
23-
const fs = require('fs/promises')
24-
const gettextParser = require('gettext-parser')
2522

2623
// https://github.com/alexanderwallin/node-gettext#usage
2724
// https://github.com/alexanderwallin/node-gettext#load-and-add-translations-from-mo-or-po-files
2825
const parseFile = async (fileName) => {
26+
// We need to import dependencies dynamically to support this module to be imported by vite and to be required by Cypress
27+
// If we use require, vite will fail with 'Dynamic require of "path" is not supported'
28+
// If we convert it to an ES module, webpack and vite are fine but Cypress will fail because it can not handle ES imports in Typescript configs in commonjs packages
29+
const { basename } = await import('path')
30+
const { readFile } = await import('fs/promises')
31+
const gettextParser = await import('gettext-parser')
32+
2933
const locale = basename(fileName).slice(0, -'.pot'.length)
30-
const po = await fs.readFile(fileName)
34+
const po = await readFile(fileName)
3135

3236
const json = gettextParser.po.parse(po)
3337

@@ -56,7 +60,9 @@ const parseFile = async (fileName) => {
5660
}
5761

5862
const loadTranslations = async (baseDir) => {
59-
const files = await fs.readdir(baseDir)
63+
const { join } = await import('path')
64+
const { readdir } = await import('fs/promises')
65+
const files = await readdir(baseDir)
6066

6167
const promises = files
6268
.filter(name => name !== 'messages.pot' && name.endsWith('.pot'))

build/usernameToColor-export.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const snapshot = require('./../src/functions/usernameToColor/__snapshots__/usernameToColor.spec.js.snap')
22
const result = {}
33
Object.keys(snapshot).map((key) => {
4-
const uid = key.replace('usernameToColor ', '').replace(' has the proper color 1', '')
5-
result[uid] = JSON.parse(snapshot[key])
4+
const uid = key.replace('usernameToColor ', '').replace(' has the proper color 1', '')
5+
result[uid] = JSON.parse(snapshot[key])
66
})
77
console.log(JSON.stringify(result))

cypress.config.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { defineConfig } from 'cypress'
2-
import { DefinePlugin } from 'webpack'
3-
import getCompareSnapshotsPlugin from 'cypress-visual-regression/dist/plugin'
2+
import webpack from 'webpack'
3+
import getCompareSnapshotsPlugin from 'cypress-visual-regression/dist/plugin.js'
44
import path from 'path'
55
import webpackConfig from '@nextcloud/webpack-vue-config'
6-
import webpackRules from '@nextcloud/webpack-vue-config/rules'
6+
import webpackRules from '@nextcloud/webpack-vue-config/rules.js'
77

8-
import { loadTranslations } from './resources/translations'
8+
import { loadTranslations } from './build/translations.js'
99

10-
const SCOPE_VERSION = Date.now()
11-
webpackRules.RULE_SCSS.use.push({
10+
const SCOPE_VERSION = Date.now();
11+
12+
(webpackRules.RULE_SCSS.use as webpack.RuleSetUse[]).push({
1213
loader: 'sass-loader',
1314
options: {
1415
additionalData: `@use 'sass:math'; $scope_version:${SCOPE_VERSION}; @import 'variables'; @import 'material-icons';`,
@@ -72,7 +73,7 @@ export default defineConfig({
7273
bundler: 'webpack',
7374
webpackConfig: async () => {
7475
const translations = await loadTranslations(path.resolve(__dirname, './l10n'))
75-
webpackConfig.plugins.push(new DefinePlugin({
76+
webpackConfig.plugins.push(new webpack.DefinePlugin({
7677
PRODUCTION: false,
7778
SCOPE_VERSION,
7879
TRANSLATIONS: JSON.stringify(translations),

cypress/visual/NcAppSidebar/NcAppSidebar-compact.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
import BuildAppSidebarTest from './NcAppSidebarMixin'
22+
import BuildAppSidebarTest from './NcAppSidebarMixin.js'
2323

2424
BuildAppSidebarTest(true)

cypress/visual/NcAppSidebar/NcAppSidebar.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*
2121
*/
22-
import BuildAppSidebarTest from './NcAppSidebarMixin'
22+
import BuildAppSidebarTest from './NcAppSidebarMixin.js'
2323

2424
BuildAppSidebarTest(false)

0 commit comments

Comments
 (0)