Skip to content

Commit

Permalink
chore: Move to ESM package
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Dec 13, 2023
1 parent 87fc04e commit 82810aa
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 68 deletions.
24 changes: 0 additions & 24 deletions .eslintrc.js

This file was deleted.

24 changes: 24 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"globals": {
"EMOJIS": true,
"PRODUCTION": true,
"SCOPE_VERSION": true,
"TRANSLATIONS": true,
"oc_userconfig": true,
"appName": true,
"appVersion": true
},
"extends": [
"@nextcloud"
],
"plugins": [
"cypress"
],
"parserOptions": {
"babelOptions": {
"plugins": [
"@babel/plugin-syntax-import-assertions"
]
}
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion build/extract-l10n.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { GettextExtractor, JsExtractors, HtmlExtractors } = require('gettext-extractor')
import { GettextExtractor, JsExtractors, HtmlExtractors } from 'gettext-extractor'

const extractor = new GettextExtractor()

Expand Down
19 changes: 5 additions & 14 deletions build/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@
*
*/

import { basename, join } from 'path'
import { readdir, readFile } from 'fs/promises'
import gettextParser from 'gettext-parser'

// https://github.com/alexanderwallin/node-gettext#usage
// https://github.com/alexanderwallin/node-gettext#load-and-add-translations-from-mo-or-po-files
const parseFile = async (fileName) => {
// We need to import dependencies dynamically to support this module to be imported by vite and to be required by Cypress
// If we use require, vite will fail with 'Dynamic require of "path" is not supported'
// 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
const { basename } = await import('path')
const { readFile } = await import('fs/promises')
const gettextParser = await import('gettext-parser')

const locale = basename(fileName).slice(0, -'.pot'.length)
const po = await readFile(fileName)

Expand Down Expand Up @@ -59,9 +56,7 @@ const parseFile = async (fileName) => {
}
}

const loadTranslations = async (baseDir) => {
const { join } = await import('path')
const { readdir } = await import('fs/promises')
export const loadTranslations = async (baseDir) => {
const files = await readdir(baseDir)

const promises = files
Expand All @@ -71,7 +66,3 @@ const loadTranslations = async (baseDir) => {

return Promise.all(promises)
}

module.exports = {
loadTranslations,
}
7 changes: 0 additions & 7 deletions build/usernameToColor-export.js

This file was deleted.

3 changes: 2 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import webpackRules from '@nextcloud/webpack-vue-config/rules.js'

import { loadTranslations } from './build/translations.js'

const SCOPE_VERSION = Date.now();
const SCOPE_VERSION = Date.now()
const __dirname = new URL('.', import.meta.url).pathname;

(webpackRules.RULE_SCSS.use as webpack.RuleSetUse[]).push({
loader: 'sass-loader',
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"bugs": "https://github.com/nextcloud-libraries/nextcloud-vue/issues",
"author": "John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>",
"license": "AGPL-3.0",
"type": "module",
"scripts": {
"build": "vite build --mode production ",
"dev": "vite build --mode development",
Expand All @@ -24,8 +25,8 @@
"test:coverage": "TZ=UTC jest --verbose --coverage --no-cache",
"stylelint": "stylelint src/**/*.vue src/**/*.scss src/**/*.css",
"stylelint:fix": "stylelint src/**/*.vue src/**/*.scss src/**/*.css --fix",
"styleguide": "vue-styleguidist server",
"styleguide:build": "vue-styleguidist build",
"styleguide": "vue-styleguidist --config styleguide.config.cjs server",
"styleguide:build": "vue-styleguidist --config styleguide.config.cjs build",
"cypress": "TZ=UTC cypress run --component",
"cypress:gui": "TZ=UTC cypress open --component",
"cypress:update-snapshots": "TZ=UTC cypress run --component --spec \"cypress/visual/**/*.cy.{t,j}s\" --env type=base --config screenshotsFolder=cypress/snapshots/base"
Expand Down Expand Up @@ -142,10 +143,10 @@
"node-polyfill-webpack-plugin": "^3.0.0",
"resolve-url-loader": "^5.0.0",
"sanitize-filename": "^1.6.3",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"typescript": "^5.0.4",
"url-loader": "^4.1.1",
"vite": "^4.3.9",
"vite": "^4.5.0",
"vue-eslint-parser": "^9.0.3",
"vue-material-design-icons": "^5.2.0",
"vue-router": "^3.6.5",
Expand Down
2 changes: 1 addition & 1 deletion styleguide.config.js → styleguide.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const { merge } = require('webpack-merge')
const webpackConfig = require('./webpack.config.js')
const webpackConfig = require('./webpack.config.cjs')

module.exports = async () => {
const base = await webpackConfig()
Expand Down
8 changes: 4 additions & 4 deletions styleguide/global.requires.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable-next-line */
import 'core-js/stable'
/* eslint-disable-next-line */
import 'regenerator-runtime/runtime'
// eslint-disable-next-line n/no-extraneous-import
import 'core-js/stable/index.js'
// eslint-disable-next-line n/no-extraneous-import
import 'regenerator-runtime/runtime.js'
import Vue from 'vue'
import VTooltip from './../src/directives/Tooltip/index.js'

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@vue/tsconfig",
"extends": "@vue/tsconfig/tsconfig.json",
"include": ["./src/**/*.ts"],
"exclude": ["./src/**/*.cy.ts"],
"compilerOptions": {
Expand Down
4 changes: 0 additions & 4 deletions vite.config.mts → vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import { join, resolve } from 'node:path'
import { defineConfig } from 'vite'

import md5 from 'md5'
import * as url from 'url'

import { loadTranslations } from './build/translations.js'

// `__dirname` not available on ES modules by default
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))

const appVersion = JSON.stringify(process.env.npm_package_version || 'nextcloud-vue')
const SCOPE_VERSION = md5(appVersion).slice(0, 7) as string
const TRANSLATIONS = await loadTranslations(resolve(__dirname, './l10n'))
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js → webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const path = require('path')

const { DefinePlugin } = require('webpack')
const BabelLoaderExcludeNodeModulesExcept = require('babel-loader-exclude-node-modules-except')
const { loadTranslations } = require('./build/translations.js')

const buildMode = process.env.NODE_ENV
const isDev = buildMode === 'development'
Expand Down Expand Up @@ -68,6 +67,7 @@ webpackRules.RULE_NODE_MJS = {
webpackConfig.module.rules = Object.values(webpackRules)

module.exports = async () => {
const { loadTranslations } = await import('./build/translations.js')
const translations = await loadTranslations(path.resolve(__dirname, './l10n'))

webpackConfig.plugins.push(new DefinePlugin({
Expand Down

0 comments on commit 82810aa

Please sign in to comment.