c12 1.0.1 → 1.1.0

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.
package/dist/index.cjs CHANGED
@@ -3,7 +3,8 @@
3
3
  const node_fs = require('node:fs');
4
4
  const pathe = require('pathe');
5
5
  const dotenv = require('dotenv');
6
- const os = require('node:os');
6
+ const promises = require('node:fs/promises');
7
+ const node_os = require('node:os');
7
8
  const createJiti = require('jiti');
8
9
  const rc9 = require('rc9');
9
10
  const defu = require('defu');
@@ -204,16 +205,16 @@ async function resolveConfig(source, options) {
204
205
  }
205
206
  }
206
207
  if (GIT_PREFIXES.some((prefix) => source.startsWith(prefix))) {
208
+ const { downloadTemplate } = await import('giget');
207
209
  const url = new URL(source);
208
- const subPath = url.pathname.split("/").slice(2).join("/");
209
210
  const gitRepo = url.protocol + url.pathname.split("/").slice(0, 2).join("/");
210
- const tmpdir = pathe.resolve(os.tmpdir(), "c12/", gitRepo.replace(/[#/:@\\]/g, "_"));
211
- await node_fs.promises.rm(tmpdir, { recursive: true }).catch(() => {
212
- });
213
- const gittar = await import('gittar').then((r) => r.default || r);
214
- const tarFile = await gittar.fetch(gitRepo);
215
- await gittar.extract(tarFile, tmpdir);
216
- source = pathe.resolve(tmpdir, subPath);
211
+ const name = gitRepo.replace(/[#/:@\\]/g, "_");
212
+ const tmpDir = process.env.XDG_CACHE_HOME ? pathe.resolve(process.env.XDG_CACHE_HOME, "c12", name) : pathe.resolve(node_os.homedir(), ".cache/c12", name);
213
+ if (node_fs.existsSync(tmpDir)) {
214
+ await promises.rmdir(tmpDir, { recursive: true });
215
+ }
216
+ const clonned = await downloadTemplate(source, { dir: tmpDir });
217
+ source = clonned.dir;
217
218
  }
218
219
  if (NPM_PACKAGE_RE.test(source)) {
219
220
  try {
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { existsSync, promises } from 'node:fs';
2
2
  import { resolve, extname, dirname } from 'pathe';
3
3
  import * as dotenv from 'dotenv';
4
- import os from 'node:os';
4
+ import { rmdir } from 'node:fs/promises';
5
+ import { homedir } from 'node:os';
5
6
  import createJiti from 'jiti';
6
7
  import * as rc9 from 'rc9';
7
8
  import { defu } from 'defu';
@@ -188,16 +189,16 @@ async function resolveConfig(source, options) {
188
189
  }
189
190
  }
190
191
  if (GIT_PREFIXES.some((prefix) => source.startsWith(prefix))) {
192
+ const { downloadTemplate } = await import('giget');
191
193
  const url = new URL(source);
192
- const subPath = url.pathname.split("/").slice(2).join("/");
193
194
  const gitRepo = url.protocol + url.pathname.split("/").slice(0, 2).join("/");
194
- const tmpdir = resolve(os.tmpdir(), "c12/", gitRepo.replace(/[#/:@\\]/g, "_"));
195
- await promises.rm(tmpdir, { recursive: true }).catch(() => {
196
- });
197
- const gittar = await import('gittar').then((r) => r.default || r);
198
- const tarFile = await gittar.fetch(gitRepo);
199
- await gittar.extract(tarFile, tmpdir);
200
- source = resolve(tmpdir, subPath);
195
+ const name = gitRepo.replace(/[#/:@\\]/g, "_");
196
+ const tmpDir = process.env.XDG_CACHE_HOME ? resolve(process.env.XDG_CACHE_HOME, "c12", name) : resolve(homedir(), ".cache/c12", name);
197
+ if (existsSync(tmpDir)) {
198
+ await rmdir(tmpDir, { recursive: true });
199
+ }
200
+ const clonned = await downloadTemplate(source, { dir: tmpDir });
201
+ source = clonned.dir;
201
202
  }
202
203
  if (NPM_PACKAGE_RE.test(source)) {
203
204
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "c12",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Smart Config Loader",
5
5
  "repository": "unjs/c12",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "defu": "^6.1.1",
24
24
  "dotenv": "^16.0.3",
25
- "gittar": "^0.1.1",
25
+ "giget": "^1.0.0",
26
26
  "jiti": "^1.16.0",
27
27
  "mlly": "^1.0.0",
28
28
  "pathe": "^1.0.0",