Skip to content

Commit

Permalink
fix(app-vite): fix feature flags generation when adding modes
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufkandemir committed Aug 19, 2024
1 parent a0b7171 commit b27711e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
3 changes: 2 additions & 1 deletion app-vite/lib/modes/bex/bex-installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
6 changes: 2 additions & 4 deletions app-vite/lib/modes/electron/electron-installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions app-vite/lib/modes/pwa/pwa-installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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(
Expand Down
6 changes: 2 additions & 4 deletions app-vite/lib/modes/ssr/ssr-installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')
}
Expand Down
25 changes: 17 additions & 8 deletions app-vite/lib/utils/types-feature-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b27711e

Please sign in to comment.