diff --git a/app-vite/lib/modes/bex/bex-installation.js b/app-vite/lib/modes/bex/bex-installation.js index ab647c75233..a3043ba6a83 100644 --- a/app-vite/lib/modes/bex/bex-installation.js +++ b/app-vite/lib/modes/bex/bex-installation.js @@ -3,6 +3,7 @@ import fse from 'fs-extra' import inquirer from 'inquirer' import { log, warn } from '../../utils/logger.js' +import { generateTypesFeatureFlag } from '../../utils/types-feature-flags.js' const bexDeps = { events: '^3.3.0' @@ -43,7 +44,7 @@ export async function addMode ({ log('Creating Browser Extension source folder...') fse.copySync(appPaths.resolve.cli('templates/bex/common'), appPaths.bexDir) - fse.copySync(appPaths.resolve.cli('templates/bex/bex-flag.d.ts'), appPaths.resolve.bex('bex-flag.d.ts')) + generateTypesFeatureFlag('bex', appPaths) const hasTypescript = await cacheProxy.getModule('hasTypescript') const format = hasTypescript ? 'ts' : 'default' diff --git a/app-vite/lib/modes/electron/electron-installation.js b/app-vite/lib/modes/electron/electron-installation.js index 8da8e12aa92..ce967421aaa 100644 --- a/app-vite/lib/modes/electron/electron-installation.js +++ b/app-vite/lib/modes/electron/electron-installation.js @@ -2,6 +2,7 @@ import fs from 'node:fs' import fse from 'fs-extra' import { log, warn } from '../../utils/logger.js' +import { generateTypesFeatureFlag } from '../../utils/types-feature-flags.js' const electronDeps = { electron: 'latest' @@ -36,10 +37,7 @@ export async function addMode ({ appPaths.electronDir ) - fse.copySync( - appPaths.resolve.cli('templates/electron/electron-flag.d.ts'), - appPaths.resolve.electron('electron-flag.d.ts') - ) + generateTypesFeatureFlag('electron', appPaths) log('Creating Electron icons folder...') fse.copySync( diff --git a/app-vite/lib/modes/pwa/pwa-installation.js b/app-vite/lib/modes/pwa/pwa-installation.js index e398d741235..c8ff531a6dd 100644 --- a/app-vite/lib/modes/pwa/pwa-installation.js +++ b/app-vite/lib/modes/pwa/pwa-installation.js @@ -2,6 +2,7 @@ import fs from 'node:fs' import fse from 'fs-extra' import { log, warn } from '../../utils/logger.js' +import { generateTypesFeatureFlag } from '../../utils/types-feature-flags.js' const defaultVersion = '^7.0.0' @@ -57,10 +58,7 @@ export async function addMode ({ hasEslint === true ? { filter: src => !src.endsWith('/.eslintrc.cjs') } : void 0 ) - fse.copySync( - appPaths.resolve.cli('templates/pwa/pwa-flag.d.ts'), - appPaths.resolve.pwa('pwa-flag.d.ts') - ) + generateTypesFeatureFlag('pwa', appPaths) log('Copying PWA icons to /public/icons/ (if they are not already there)...') fse.copySync( diff --git a/app-vite/lib/modes/ssr/ssr-installation.js b/app-vite/lib/modes/ssr/ssr-installation.js index 6b8031f67ac..d1f893a420c 100644 --- a/app-vite/lib/modes/ssr/ssr-installation.js +++ b/app-vite/lib/modes/ssr/ssr-installation.js @@ -2,6 +2,7 @@ import fs from 'node:fs' import fse from 'fs-extra' import { log, warn } from '../../utils/logger.js' +import { generateTypesFeatureFlag } from '../../utils/types-feature-flags.js' export function isModeInstalled (appPaths) { return fs.existsSync(appPaths.ssrDir) @@ -26,10 +27,7 @@ export async function addMode ({ appPaths.ssrDir ) - fse.copySync( - appPaths.resolve.cli('templates/ssr/ssr-flag.d.ts'), - appPaths.resolve.ssr('ssr-flag.d.ts') - ) + generateTypesFeatureFlag('ssr', appPaths) log('SSR support was added') } diff --git a/app-vite/lib/utils/types-feature-flags.js b/app-vite/lib/utils/types-feature-flags.js index 88f2338cae7..344c36050fe 100644 --- a/app-vite/lib/utils/types-feature-flags.js +++ b/app-vite/lib/utils/types-feature-flags.js @@ -3,14 +3,13 @@ import { writeFileSync, existsSync } from 'node:fs' import { log } from './logger.js' -export function ensureTypesFeatureFlags (quasarConf) { - // We don't have a specific entry for the augmenting file in `package.json > exports` - // We rely on the wildcard entry, so we use a deep import, instead of let's say `quasar/feature-flags` - // When using TypeScript `moduleResolution: "bundler"`, it requires the file extension. - // This may sound unusual, but that's because it seems to treat wildcard entries differently. - - // Keep in sync with `create-quasar/templates/**/store-flag.d.ts` - const template = `/* eslint-disable */ +// We don't have a specific entry for the augmenting file in `package.json > exports` +// We rely on the wildcard entry, so we use a deep import, instead of let's say `quasar/feature-flags` +// When using TypeScript `moduleResolution: "bundler"`, it requires the file extension. +// This may sound unusual, but that's because it seems to treat wildcard entries differently. +// +// Keep in sync with `create-quasar/templates/**/store-flag.d.ts` +const template = `/* eslint-disable */ /* WARNING: DO NOT MODIFY OR DELETE This file is auto-generated by Quasar CLI @@ -26,6 +25,16 @@ declare module "quasar/dist/types/feature-flag.d.ts" { } ` +export function generateTypesFeatureFlag (modeName, appPaths) { + const destFlagPath = appPaths.resolve[ modeName ](`${ modeName }-flag.d.ts`) + + writeFileSync( + destFlagPath, + template.replace('__FEATURE_NAME__', modeName) + ) +} + +export function ensureTypesFeatureFlags (quasarConf) { // Flags must be available even in pure JS codebases, // because boot and configure wrappers functions files will // provide autocomplete based on them also to JS users