Skip to content

Commit

Permalink
feat(ui/app-vite/app-webpack): convert UI pkg to ESM
Browse files Browse the repository at this point in the history
* add ui/package.json > exports
* drop dist/transforms/import-transformation.js (should be handled by CLIs through dist/transforms/import-map.json)
* convert UI build system to ESM
* drop ui/lang/*.mjs + *.js and replace with ESM *.js
* drop ui/wrappers/*.mjs + *.js and replace with *.js + *.cjs
* update q/app-vite + q/app-webpack + vite-plugin to the newer specs
  • Loading branch information
rstoenescu committed Apr 30, 2024
1 parent ab0c9bf commit a7f5fc0
Show file tree
Hide file tree
Showing 257 changed files with 827 additions and 14,549 deletions.
3 changes: 1 addition & 2 deletions app-vite/lib/config-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ export function createNodeEsbuildConfig (quasarConf, { format }) {
sourcemap: quasarConf.metaConf.debugging === true ? 'inline' : false,
minify: quasarConf.build.minify !== false,
alias: {
...quasarConf.build.alias,
'quasar/wrappers': format === 'esm' ? 'quasar/wrappers/index.mjs' : 'quasar/wrappers/index.js'
...quasarConf.build.alias
},
resolveExtensions: [ format === 'esm' ? '.mjs' : '.cjs', '.js', '.mts', '.ts', '.json' ],
// we use a fresh list since this can be tampered with by the user:
Expand Down
3 changes: 2 additions & 1 deletion app-vite/lib/modes/ssr/ssr-devserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createServer } from 'vite'
import chokidar from 'chokidar'
import debounce from 'lodash/debounce.js'
import serialize from 'serialize-javascript'
import { green } from 'kolorist'

import { AppDevserver } from '../../app-devserver.js'
import { getPackage } from '../../utils/get-package.js'
Expand All @@ -20,7 +21,7 @@ const autoRemove = 'document.currentScript.remove()'

function logServerMessage (title, msg, additional) {
log()
info(`${ msg }${ additional !== void 0 ? ` ${ dot } ${ additional }` : '' }`, title)
info(`${ msg }${ additional !== void 0 ? ` ${ green(dot) } ${ additional }` : '' }`, title)
}

let renderSSRError
Expand Down
17 changes: 14 additions & 3 deletions app-vite/lib/quasar-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ export class QuasarConfigFile {
format: appPaths.quasarConfigOutputFormat,
bundle: true,
packages: 'external',
alias: {
'quasar/wrappers': appPaths.quasarConfigOutputFormat === 'esm' ? 'quasar/wrappers/index.mjs' : 'quasar/wrappers/index.js'
},
banner: {
js: quasarConfigBanner
},
Expand Down Expand Up @@ -670,6 +667,20 @@ export class QuasarConfigFile {
cfg.framework.directives = getUniqueArray(cfg.framework.directives)
cfg.framework.plugins = getUniqueArray(cfg.framework.plugins)

const { lang, iconSet } = cfg.framework

if (lang !== void 0) {
cfg.framework.lang = lang.indexOf('/') === true
? lang
: `quasar/lang/${ lang }.js`
}

if (iconSet !== void 0) {
cfg.framework.iconSet = iconSet.indexOf('/') === true
? iconSet
: `quasar/icon-set/${ iconSet }.js`
}

Object.assign(cfg.metaConf, {
packageTypeBasedExtension: this.#ctx.pkg.appPkg.type === 'module' ? 'js' : 'mjs',
hasLoadingBarPlugin: cfg.framework.plugins.includes('LoadingBar'),
Expand Down
2 changes: 1 addition & 1 deletion app-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"electron-builder": ">= 22",
"electron-packager": ">= 15",
"pinia": "^2.0.0",
"quasar": "^2.14.0",
"quasar": "^2.16.0",
"vue": "^3.2.29",
"vue-router": "^4.0.12",
"vuex": "^4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions app-vite/templates/entry/quasar-user-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
const useStatement = [ `config: ${JSON.stringify(framework.config)}` ]

if (framework.lang) { %>
import lang from '<%= framework.lang.includes('/') ? '' : 'quasar/lang/' %><%= framework.lang %>'
import lang from '<%= framework.lang %>'
<%
useStatement.push('lang')
}

if (framework.iconSet) { %>
import iconSet from '<%= framework.iconSet.includes('/') ? '' : 'quasar/icon-set/' %><%= framework.iconSet %>'
import iconSet from '<%= framework.iconSet %>'
<%
useStatement.push('iconSet')
}
Expand Down
10 changes: 8 additions & 2 deletions app-webpack/lib/cache/module.quasarMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ const { getPackage } = require('../utils/get-package.js')

module.exports.createInstance = function createInstance ({ appPaths }) {
const autoImportData = getPackage('quasar/dist/transforms/auto-import.json', appPaths.appDir)
const importTransformation = getPackage('quasar/dist/transforms/import-transformation.js', appPaths.appDir)
const importMap = getPackage('quasar/dist/transforms/import-map.json', appPaths.appDir)

return {
transformAssetUrls: getPackage('quasar/dist/transforms/loader-asset-urls.json', appPaths.appDir),
autoImport: {
autoImportData,
importTransformation,
importTransformation (importName) {
const file = importMap[ importName ]
if (file === void 0) {
throw new Error('Unknown import from Quasar: ' + importName)
}
return 'quasar/' + file
},

compRegex: {
kebab: new RegExp(autoImportData.regex.kebabComponents || autoImportData.regex.components, 'g'),
Expand Down
3 changes: 1 addition & 2 deletions app-webpack/lib/config-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ module.exports.createNodeEsbuildConfig = async function createNodeEsbuildConfig
sourcemap: quasarConf.metaConf.debugging === true ? 'inline' : false,
minify: quasarConf.build.minify !== false,
alias: {
...quasarConf.build.alias,
'quasar/wrappers': format === 'esm' ? 'quasar/wrappers/index.mjs' : 'quasar/wrappers/index.js'
...quasarConf.build.alias
},
resolveExtensions: [ format === 'esm' ? '.mjs' : '.cjs', '.js', '.mts', '.ts', '.json' ],
// we use a fresh list since this can be tampered with by the user:
Expand Down
3 changes: 0 additions & 3 deletions app-webpack/lib/modes/ssr/ssr-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ const quasarSsrConfig = {
appPaths.resolve.entry('server-entry.js')
)

webpackChain.resolve.alias
.set('quasar$', 'quasar/dist/quasar.cjs.prod.js')

webpackChain.target('node')

if (quasarConf.metaConf.debugging) {
Expand Down
3 changes: 2 additions & 1 deletion app-webpack/lib/modes/ssr/ssr-devserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const { createDevRenderer } = require('@quasar/ssr-helpers/create-renderer.js')
const { green } = require('kolorist')

const { getSsrHtmlTemplateFn } = require('../../utils/html-template.js')
const { getClientManifest } = require('./plugin.webpack.client-side.js')
Expand All @@ -21,7 +22,7 @@ const doubleSlashRE = /\/\//g

function logServerMessage (title, msg, additional) {
log()
info(`${ msg }${ additional !== void 0 ? ` ${ dot } ${ additional }` : '' }`, title)
info(`${ msg }${ additional !== void 0 ? ` ${ green(dot) } ${ additional }` : '' }`, title)
}

let renderSSRError
Expand Down
17 changes: 14 additions & 3 deletions app-webpack/lib/quasar-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ module.exports.QuasarConfigFile = class QuasarConfigFile {
format: appPaths.quasarConfigOutputFormat,
bundle: true,
packages: 'external',
alias: {
'quasar/wrappers': appPaths.quasarConfigOutputFormat === 'esm' ? 'quasar/wrappers/index.mjs' : 'quasar/wrappers/index.js'
},
banner: {
js: quasarConfigBanner
},
Expand Down Expand Up @@ -698,6 +695,20 @@ module.exports.QuasarConfigFile = class QuasarConfigFile {
cfg.framework.directives = getUniqueArray(cfg.framework.directives)
cfg.framework.plugins = getUniqueArray(cfg.framework.plugins)

const { lang, iconSet } = cfg.framework

if (lang !== void 0) {
cfg.framework.lang = lang.indexOf('/') === true
? lang
: `quasar/lang/${ lang }.js`
}

if (iconSet !== void 0) {
cfg.framework.iconSet = iconSet.indexOf('/') === true
? iconSet
: `quasar/icon-set/${ iconSet }.js`
}

Object.assign(cfg.metaConf, {
hasLoadingBarPlugin: cfg.framework.plugins.includes('LoadingBar'),
hasMetaPlugin: cfg.framework.plugins.includes('Meta')
Expand Down
4 changes: 2 additions & 2 deletions app-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@
"@electron/packager": ">= 18",
"electron-builder": ">= 22",
"electron-packager": ">= 15",
"eslint": "^8.11.0",
"eslint": "^8.57.0",
"pinia": "^2.0.0",
"quasar": "^2.14.0",
"quasar": "^2.16.0",
"vue": "^3.2.29",
"vue-router": "^4.0.12",
"vuex": "^4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions app-webpack/templates/entry/quasar-user-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
const useStatement = [ `config: ${JSON.stringify(framework.config)}` ]

if (framework.lang) { %>
import lang from '<%= framework.lang.includes('/') ? '' : 'quasar/lang/' %><%= framework.lang %>'
import lang from '<%= framework.lang %>'
<%
useStatement.push('lang')
}

if (framework.iconSet) { %>
import iconSet from '<%= framework.iconSet.includes('/') ? '' : 'quasar/icon-set/' %><%= framework.iconSet %>'
import iconSet from '<%= framework.iconSet %>'
<%
useStatement.push('iconSet')
}
Expand Down
Loading

0 comments on commit a7f5fc0

Please sign in to comment.