@vixt/core 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +39 -29
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -202,49 +202,46 @@ const config = defineVixtModule({
202
202
  }
203
203
  });
204
204
 
205
- function generateDts(options, vixt, config) {
206
- const { root } = config;
207
- const { buildDir } = vixt.options;
208
- const vixtDts = options.references?.map((reference) => {
205
+ function generateVixtDts(options, vixt) {
206
+ const { buildDir, rootDir } = vixt.options;
207
+ const codePath = path.resolve(rootDir, buildDir, "vixt.d.ts");
208
+ const code = options.references?.map((reference) => {
209
209
  if (typeof reference === "string") {
210
210
  return `/// <reference path="${reference}" />`;
211
211
  } else if (typeof reference === "object" && reference.path && reference.content) {
212
- fs.outputFileSync(path.resolve(root, buildDir), reference.content ?? "");
212
+ fs.outputFileSync(path.resolve(rootDir, buildDir), reference.content ?? "");
213
213
  return `/// <reference path="${reference.path}" />`;
214
214
  } else {
215
215
  return "";
216
216
  }
217
217
  }).concat("export {}").join("\n");
218
- const vixtDtsPath = path.resolve(root, buildDir, "vixt.d.ts");
219
- fs.outputFileSync(vixtDtsPath, vixtDts);
218
+ code && fs.outputFileSync(codePath, code);
220
219
  }
221
- function generateTsConfig(options, vixt, config) {
222
- const { root } = config;
223
- const { buildDir } = vixt.options;
224
- const tsConfigPath = path.resolve(root, buildDir, "tsconfig.json");
220
+ function generateTsConfig(options, vixt) {
221
+ const { buildDir, rootDir } = vixt.options;
222
+ const codePath = path.resolve(rootDir, buildDir, "tsconfig.json");
225
223
  const layersDirs = vixt._layers.map((e) => e.cwd);
226
224
  const tsConfig = defu(options.tsConfig, { include: layersDirs });
227
- fs.outputFileSync(tsConfigPath, JSON.stringify(tsConfig, null, 2));
225
+ const code = JSON.stringify(tsConfig, null, 2);
226
+ fs.outputFileSync(codePath, code);
228
227
  }
229
- function generateEnvDts(options, vixt, config) {
230
- const { env, root } = config;
231
- const { buildDir } = vixt.options;
228
+ function generateEnvDts(options, vixt, env) {
229
+ const { buildTypesDir, rootDir } = vixt.options;
230
+ const codePath = path.resolve(rootDir, buildTypesDir, "vite-env.d.ts");
232
231
  const values = Object.entries(env).map(([key, value]) => `/** ${key}=${value} */
233
232
  ${key}: ${typeof value}`).join("\n ");
234
- const envDts = `interface ImportMeta {
233
+ const code = `interface ImportMeta {
235
234
  readonly env: ImportMetaEnv
236
235
  }
237
236
  interface ImportMetaEnv {
238
237
  ${values}
239
238
  }
240
239
  `;
241
- const envDtsPath = path.resolve(root, buildDir, "types", "vite-env.d.ts");
242
- fs.outputFileSync(envDtsPath, envDts);
240
+ fs.outputFileSync(codePath, code);
243
241
  }
244
- function genarateShims(options, vixt, config) {
245
- const { root } = config;
246
- const { buildDir } = vixt.options;
247
- const shimsDts = `
242
+ function genarateShims(options, vixt) {
243
+ const { buildTypesDir, rootDir } = vixt.options;
244
+ const code = `
248
245
  declare module '*.vue' {
249
246
  import type { DefineComponent } from 'vue'
250
247
 
@@ -252,12 +249,24 @@ declare module '*.vue' {
252
249
  export default component
253
250
  }
254
251
  `;
255
- const shimsDtsPath = path.resolve(root, buildDir, "types", "shims.d.ts");
256
- fs.outputFileSync(shimsDtsPath, shimsDts);
252
+ const codePath = path.resolve(rootDir, buildTypesDir, "shims.d.ts");
253
+ fs.outputFileSync(codePath, code);
254
+ }
255
+ function genarateGlobalComponents(options, vixt) {
256
+ const { buildTypesDir, rootDir } = vixt.options;
257
+ const codePath = path.resolve(rootDir, buildTypesDir, "global-components.d.ts");
258
+ const code = `
259
+ import type { GlobalComponents as _GlobalComponents } from '@vue/runtime-core'
260
+
261
+ declare module 'vue'{
262
+ interface GlobalComponents extends _GlobalComponents {}
263
+ }
264
+ `;
265
+ fs.outputFileSync(codePath, code);
257
266
  }
258
267
  const name = "vixt:typescript";
259
268
  const defaults = {
260
- references: ["./types/vite-env.d.ts", "./types/shims.d.ts"],
269
+ // references: ['types/vite-env.d.ts', 'types/shims.d.ts', 'types/global-components.d.ts'],
261
270
  tsConfig: {
262
271
  extends: "@vue/tsconfig/tsconfig.dom.json",
263
272
  compilerOptions: {
@@ -283,10 +292,11 @@ const typescript = defineVixtModule({
283
292
  {
284
293
  name,
285
294
  configResolved(config) {
286
- generateDts(options, vixt, config);
287
- generateTsConfig(options, vixt, config);
288
- generateEnvDts(options, vixt, config);
289
- genarateShims(options, vixt, config);
295
+ generateVixtDts(options, vixt);
296
+ generateTsConfig(options, vixt);
297
+ generateEnvDts(options, vixt, config.env);
298
+ genarateShims(options, vixt);
299
+ genarateGlobalComponents(options, vixt);
290
300
  }
291
301
  },
292
302
  Checker(options.typeCheck ?? {})
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vixt/core",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.9",
5
5
  "author": "SoulLyoko<https://github.com/SoulLyoko>",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/SoulLyoko/vixt#readme",
@@ -25,7 +25,7 @@
25
25
  "fs-extra": "^11.2.0",
26
26
  "mlly": "1.7.1",
27
27
  "pathe": "^1.1.2",
28
- "pkg-types": "^1.1.2",
28
+ "pkg-types": "^1.1.3",
29
29
  "tsx": "^4.16.0",
30
30
  "vite": "^5.3.2",
31
31
  "vite-plugin-checker": "^0.7.0",