Skip to content

Commit

Permalink
fix(app-vite&app-webpack): fix types feature flags (#17429)
Browse files Browse the repository at this point in the history
* refactor: centralize types feature flags

* fix: make feature flags work when using moduleResolution: bundler
which is what's specified in the tsconfig-presets

* feat: improve feature flag comments

* refactor: make it sync and rename
it doesn't use any async APIs, it used to a long time ago

* fix: update store-flag.d.ts files in create-quasar too
  • Loading branch information
yusufkandemir authored Aug 12, 2024
1 parent 6ea52eb commit d2ec87d
Show file tree
Hide file tree
Showing 32 changed files with 164 additions and 226 deletions.
4 changes: 2 additions & 2 deletions app-vite/lib/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ await quasarConfFile.init()

const quasarConf = await quasarConfFile.read()

const { regenerateTypesFeatureFlags } = await import('../utils/types-feature-flags.js')
await regenerateTypesFeatureFlags(quasarConf)
const { ensureTypesFeatureFlags } = await import('../utils/types-feature-flags.js')
ensureTypesFeatureFlags(quasarConf)

const { QuasarModeBuilder } = await import(`../modes/${ argv.mode }/${ argv.mode }-builder.js`)
const appBuilder = new QuasarModeBuilder({ argv, quasarConf })
Expand Down
4 changes: 2 additions & 2 deletions app-vite/lib/cmd/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ await quasarConfFile.init()

const quasarConf = await quasarConfFile.read()

import { regenerateTypesFeatureFlags } from '../utils/types-feature-flags.js'
await regenerateTypesFeatureFlags(quasarConf)
import { ensureTypesFeatureFlags } from '../utils/types-feature-flags.js'
ensureTypesFeatureFlags(quasarConf)

if (quasarConf.metaConf.vueDevtools !== false) {
await startVueDevtools(ctx, quasarConf.metaConf.vueDevtools.port)
Expand Down
39 changes: 30 additions & 9 deletions app-vite/lib/utils/types-feature-flags.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import { join, dirname } from 'node:path'
import { existsSync } from 'node:fs'
import fse from 'fs-extra'
import { writeFileSync, existsSync } from 'node:fs'

import { log } from './logger.js'

export async function regenerateTypesFeatureFlags (quasarConf) {
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 */
/*
WARNING: DO NOT MODIFY OR DELETE
This file is auto-generated by Quasar CLI
It's recommended to NOT .gitignore it
You don't have to use TypeScript in your project, don't worry
*/
import "quasar/dist/types/feature-flag.d.ts";
declare module "quasar/dist/types/feature-flag.d.ts" {
interface QuasarFeatureFlags {
__FEATURE_NAME__: true;
}
}
`

// 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 All @@ -19,9 +40,9 @@ export async function regenerateTypesFeatureFlags (quasarConf) {
)

if (!existsSync(destFlagPath)) {
fse.copySync(
appPaths.resolve.cli('templates/store/store-flag.d.ts'),
destFlagPath
writeFileSync(
destFlagPath,
template.replace('__FEATURE_NAME__', 'store')
)
log('"store" feature flag was missing and has been regenerated')
}
Expand All @@ -35,9 +56,9 @@ export async function regenerateTypesFeatureFlags (quasarConf) {
const destFlagPath = appPaths.resolve[ modeName ](`${ modeName }-flag.d.ts`)

if (!existsSync(destFlagPath)) {
fse.copySync(
appPaths.resolve.cli(`templates/${ modeName }/${ modeName }-flag.d.ts`),
destFlagPath
writeFileSync(
destFlagPath,
template.replace('__FEATURE_NAME__', modeName)
)
log(`"${ modeName }" feature flag was missing and has been regenerated`)
}
Expand Down
10 changes: 0 additions & 10 deletions app-vite/templates/bex/bex-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-vite/templates/capacitor/capacitor-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-vite/templates/cordova/cordova-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-vite/templates/electron/electron-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-vite/templates/pwa/pwa-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-vite/templates/ssr/ssr-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-vite/templates/store/store-flag.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions app-webpack/lib/cmd/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ async function runBuild () {

const quasarConf = await quasarConfFile.read()

const { regenerateTypesFeatureFlags } = require('../utils/types-feature-flags.js')
await regenerateTypesFeatureFlags(quasarConf)
const { ensureTypesFeatureFlags } = require('../utils/types-feature-flags.js')
ensureTypesFeatureFlags(quasarConf)

const { QuasarModeBuilder } = require(`../modes/${ argv.mode }/${ argv.mode }-builder.js`)
const appBuilder = new QuasarModeBuilder({ argv, quasarConf })
Expand Down
4 changes: 2 additions & 2 deletions app-webpack/lib/cmd/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ async function runDev () {

const quasarConf = await quasarConfFile.read()

const { regenerateTypesFeatureFlags } = require('../utils/types-feature-flags.js')
await regenerateTypesFeatureFlags(quasarConf)
const { ensureTypesFeatureFlags } = require('../utils/types-feature-flags.js')
ensureTypesFeatureFlags(quasarConf)

if (quasarConf.metaConf.vueDevtools !== false) {
await startVueDevtools(ctx, quasarConf.metaConf.vueDevtools.port)
Expand Down
39 changes: 30 additions & 9 deletions app-webpack/lib/utils/types-feature-flags.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
const { join, dirname } = require('node:path')
const { existsSync } = require('node:fs')
const fse = require('fs-extra')
const { writeFileSync, existsSync } = require('node:fs')

const { log } = require('./logger.js')

module.exports.regenerateTypesFeatureFlags = async function regenerateTypesFeatureFlags (quasarConf) {
module.exports.ensureTypesFeatureFlags = 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 */
/*
WARNING: DO NOT MODIFY OR DELETE
This file is auto-generated by Quasar CLI
It's recommended to NOT .gitignore it
You don't have to use TypeScript in your project, don't worry
*/
import "quasar/dist/types/feature-flag.d.ts";
declare module "quasar/dist/types/feature-flag.d.ts" {
interface QuasarFeatureFlags {
__FEATURE_NAME__: true;
}
}
`

// 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 All @@ -19,9 +40,9 @@ module.exports.regenerateTypesFeatureFlags = async function regenerateTypesFeatu
)

if (!existsSync(destFlagPath)) {
fse.copySync(
appPaths.resolve.cli('templates/store/store-flag.d.ts'),
destFlagPath
writeFileSync(
destFlagPath,
template.replace('__FEATURE_NAME__', 'store')
)
log('"store" feature flag was missing and has been regenerated')
}
Expand All @@ -35,9 +56,9 @@ module.exports.regenerateTypesFeatureFlags = async function regenerateTypesFeatu
const destFlagPath = appPaths.resolve[ modeName ](`${ modeName }-flag.d.ts`)

if (!existsSync(destFlagPath)) {
fse.copySync(
appPaths.resolve.cli(`templates/${ modeName }/${ modeName }-flag.d.ts`),
destFlagPath
writeFileSync(
destFlagPath,
template.replace('__FEATURE_NAME__', modeName)
)
log(`"${ modeName }" feature flag was missing and has been regenerated`)
}
Expand Down
10 changes: 0 additions & 10 deletions app-webpack/templates/bex/bex-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-webpack/templates/capacitor/capacitor-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-webpack/templates/cordova/cordova-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-webpack/templates/electron/electron-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-webpack/templates/pwa/pwa-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-webpack/templates/ssr/ssr-flag.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions app-webpack/templates/store/store-flag.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable */
// THIS FEATURE-FLAG FILE IS AUTOGENERATED,
// REMOVAL OR CHANGES WILL CAUSE RELATED TYPES TO STOP WORKING
import "quasar/dist/types/feature-flag";
/*
WARNING: DO NOT MODIFY OR DELETE
This file is auto-generated by Quasar CLI
It's recommended to NOT .gitignore it
You don't have to use TypeScript in your project, don't worry
*/
import "quasar/dist/types/feature-flag.d.ts";

declare module "quasar/dist/types/feature-flag" {
declare module "quasar/dist/types/feature-flag.d.ts" {
interface QuasarFeatureFlags {
store: true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable */
// THIS FEATURE-FLAG FILE IS AUTOGENERATED,
// REMOVAL OR CHANGES WILL CAUSE RELATED TYPES TO STOP WORKING
import "quasar/dist/types/feature-flag";
/*
WARNING: DO NOT MODIFY OR DELETE
This file is auto-generated by Quasar CLI
It's recommended to NOT .gitignore it
You don't have to use TypeScript in your project, don't worry
*/
import "quasar/dist/types/feature-flag.d.ts";

declare module "quasar/dist/types/feature-flag" {
declare module "quasar/dist/types/feature-flag.d.ts" {
interface QuasarFeatureFlags {
store: true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable */
// THIS FEATURE-FLAG FILE IS AUTOGENERATED,
// REMOVAL OR CHANGES WILL CAUSE RELATED TYPES TO STOP WORKING
import "quasar/dist/types/feature-flag";
/*
WARNING: DO NOT MODIFY OR DELETE
This file is auto-generated by Quasar CLI
It's recommended to NOT .gitignore it
You don't have to use TypeScript in your project, don't worry
*/
import "quasar/dist/types/feature-flag.d.ts";

declare module "quasar/dist/types/feature-flag" {
declare module "quasar/dist/types/feature-flag.d.ts" {
interface QuasarFeatureFlags {
store: true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* eslint-disable */
// THIS FEATURE-FLAG FILE IS AUTOGENERATED,
// REMOVAL OR CHANGES WILL CAUSE RELATED TYPES TO STOP WORKING
import "quasar/dist/types/feature-flag";
/*
WARNING: DO NOT MODIFY OR DELETE
This file is auto-generated by Quasar CLI
It's recommended to NOT .gitignore it
You don't have to use TypeScript in your project, don't worry
*/
import "quasar/dist/types/feature-flag.d.ts";

declare module "quasar/dist/types/feature-flag" {
declare module "quasar/dist/types/feature-flag.d.ts" {
interface QuasarFeatureFlags {
store: true;
}
Expand Down
Loading

0 comments on commit d2ec87d

Please sign in to comment.