Skip to content

Commit 2c564b0

Browse files
Fix type checking for global variables such as __DEV__ (#5)
1 parent b9501cc commit 2c564b0

File tree

9 files changed

+42
-22
lines changed

9 files changed

+42
-22
lines changed

Diff for: packages/create-vue-lib/src/template/base/config/packages/@projectName@/env.d.ts

-1
This file was deleted.

Diff for: packages/create-vue-lib/src/template/base/config/packages/@projectName@/src/global.d.ts.ejs renamed to packages/create-vue-lib/src/template/base/config/packages/@projectName@/env.d.ts.ejs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference types="vite/client" />
2+
13
declare const __DEV__: boolean
24
<%_ if (config.includeTestVariable) { _%>
35
declare const __TEST__: boolean

Diff for: packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/ExampleComponent.vue.ejs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import { ref } from 'vue'
33
44
if (__DEV__) {
5-
console.log('dev: creating ExampleComponent')
6-
<%_ if (config.includeTestVariable) { _%>
7-
console.log(`__TEST__: ${__TEST__}`)
8-
<%_ } _%>
5+
console.log('[<%- config.scopedPackageName %>] creating ExampleComponent')
96
}
107
118
const msg = ref('Hello world!')

Diff for: packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanel.vue

+5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<script setup lang="ts">
2+
import { provide } from 'vue'
23
import MyPanelSection from './MyPanelSection.vue'
34
45
defineProps<{
56
title?: string
67
footer?: string
78
}>()
9+
10+
if (__DEV__) {
11+
provide('MyPanel', true)
12+
}
813
</script>
914

1015
<template>

Diff for: packages/create-vue-lib/src/template/base/examples/packages/@projectName@/src/components/MyPanelSection.vue

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script setup lang="ts">
2+
import { inject, provide } from 'vue'
3+
4+
if (__DEV__) {
5+
const insideMyPanel = inject('MyPanel', false)
6+
7+
if (!insideMyPanel) {
8+
console.warn('[<%- config.scopedPackageName %>] MyPanelSection can only be used inside MyPanel')
9+
}
10+
11+
provide('MyPanel', false)
12+
}
13+
</script>
14+
15+
<template>
16+
<div class="panel-section">
17+
<slot />
18+
</div>
19+
</template>
20+
21+
<style scoped>
22+
.panel-section {
23+
padding: 10px;
24+
}
25+
</style>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
export { default as ExampleComponent } from './components/ExampleComponent.vue'
22
export { default as MyPanel } from './components/MyPanel.vue'
33
export { default as MyPanelSection } from './components/MyPanelSection.vue'
4+
5+
if (__DEV__) {
6+
console.log('[<%- config.scopedPackageName %>] dev mode')
7+
<%_ if (config.includeTestVariable) { _%>
8+
console.log(`[<%- config.scopedPackageName %>] __TEST__: ${__TEST__}`)
9+
<%_ } _%>
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/// <reference types="vite/client" />
22

3-
import '../@projectName@/src/global.d.ts'
3+
import '../@projectName@/env.d.ts'
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/// <reference types="vite/client" />
22

3-
import '../@projectName@/src/global.d.ts'
3+
import '../@projectName@/env.d.ts'

0 commit comments

Comments
 (0)