sv 0.11.0 → 0.11.2
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/bin.mjs +7 -7
- package/dist/{core-D6dTS6c8.mjs → core-D715tamU.mjs} +2561 -2561
- package/dist/lib/core/index.mjs +1 -1
- package/dist/lib/index.mjs +3 -3
- package/dist/lib/testing.mjs +2 -2
- package/dist/{official-A2Qnog8q.mjs → official-P5OKi7QM.mjs} +11 -11
- package/dist/{package-manager-BaBHlsHz.mjs → package-manager-CySZrSUa.mjs} +190 -173
- package/package.json +1 -1
package/dist/lib/core/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { V as dedent_default, at as parseSvelte, d as defineAddonOptions, f as js_exports, i as svelte_exports, l as utils_exports, o as isVersionUnsupportedBelow, q as T, s as splitVersion, t as import_picocolors, u as defineAddon, ut as walk_exports } from "../../core-D715tamU.mjs";
|
|
2
2
|
|
|
3
3
|
var colors = import_picocolors.default;
|
|
4
4
|
export { walk_exports as Walker, colors, dedent_default as dedent, defineAddon, defineAddonOptions, isVersionUnsupportedBelow, js_exports as js, T as log, parseSvelte, splitVersion, svelte_exports as svelte, utils_exports as utils };
|
package/dist/lib/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../core-
|
|
3
|
-
import { i as installAddon, n as officialAddons } from "../official-
|
|
1
|
+
import { p as create } from "../package-manager-CySZrSUa.mjs";
|
|
2
|
+
import "../core-D715tamU.mjs";
|
|
3
|
+
import { i as installAddon, n as officialAddons } from "../official-P5OKi7QM.mjs";
|
|
4
4
|
|
|
5
5
|
export { create, installAddon, officialAddons };
|
package/dist/lib/testing.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "../chunk-BjMGrMj9.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import "../core-
|
|
2
|
+
import { D as q, E as K, n as addPnpmBuildDependencies, p as create } from "../package-manager-CySZrSUa.mjs";
|
|
3
|
+
import "../core-D715tamU.mjs";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import process$1 from "node:process";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as __toESM } from "./chunk-BjMGrMj9.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { A as
|
|
2
|
+
import { C as writeFile, D as q, S as readFile, T as resolveCommand, _ as fileExists, b as getPackageJson, g as commonFilePaths, h as sanitizeName, k as getSharedFiles, r as getUserAgent, u as any, w as detect, x as installPackages, y as getHighlighter } from "./package-manager-CySZrSUa.mjs";
|
|
3
|
+
import { A as property, B as parseStatement, C as addNamed, D as createCall, E as remove, F as contains, I as createLiteral, L as createSpread, M as create$1, N as addJsDocTypeComment, O as create, P as appendStatement, R as hasTypeProperty, S as addEmpty, T as find, V as dedent_default, _ as createDefault, a as toFragment, at as parseSvelte, b as declaration, c as createPrinter, ct as MagicString, d as defineAddonOptions, dt as require_picocolors, g as addHooksHandle, h as addGlobalAppInterface, it as parseScript, j as append, k as overrideProperties, lt as walk, m as getConfig, n as addSlot, nt as parseHtml, ot as parseToml, p as addPlugin, q as T, r as ensureScript, rt as parseJson, t as import_picocolors$1, tt as parseCss, u as defineAddon, v as createNamed, w as addNamespace, x as addDefault, y as createIdentifier, z as parseExpression } from "./core-D715tamU.mjs";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import process from "node:process";
|
|
@@ -12,7 +12,7 @@ const TESTING = process.env.NODE_ENV?.toLowerCase() === "test";
|
|
|
12
12
|
//#region lib/cli/add/workspace.ts
|
|
13
13
|
async function createWorkspace({ cwd: cwd$1, packageManager, override }) {
|
|
14
14
|
const resolvedCwd = path.resolve(cwd$1);
|
|
15
|
-
const
|
|
15
|
+
const typescript = any([commonFilePaths.jsconfig, commonFilePaths.tsconfig], { cwd: cwd$1 })?.endsWith(commonFilePaths.tsconfig) ?? false;
|
|
16
16
|
const viteConfigPath = path.join(resolvedCwd, commonFilePaths.viteConfigTS);
|
|
17
17
|
const viteConfig = fs.existsSync(viteConfigPath) ? commonFilePaths.viteConfigTS : commonFilePaths.viteConfig;
|
|
18
18
|
const svelteConfigPath = path.join(resolvedCwd, commonFilePaths.svelteConfigTS);
|
|
@@ -42,7 +42,7 @@ async function createWorkspace({ cwd: cwd$1, packageManager, override }) {
|
|
|
42
42
|
return {
|
|
43
43
|
cwd: resolvedCwd,
|
|
44
44
|
packageManager: packageManager ?? (await detect({ cwd: cwd$1 }))?.name ?? getUserAgent() ?? "npm",
|
|
45
|
-
typescript
|
|
45
|
+
typescript,
|
|
46
46
|
files: {
|
|
47
47
|
viteConfig,
|
|
48
48
|
svelteConfig,
|
|
@@ -80,7 +80,7 @@ function findWorkspaceRoot(cwd$1) {
|
|
|
80
80
|
function parseKitOptions(cwd$1) {
|
|
81
81
|
const { ast } = parseScript(readFile(cwd$1, commonFilePaths.svelteConfig));
|
|
82
82
|
const defaultExport = ast.body.find((s) => s.type === "ExportDefaultDeclaration");
|
|
83
|
-
if (!defaultExport) throw Error(
|
|
83
|
+
if (!defaultExport) throw Error(`Missing default export in \`${commonFilePaths.svelteConfig}\``);
|
|
84
84
|
let objectExpression;
|
|
85
85
|
if (defaultExport.declaration.type === "Identifier") {
|
|
86
86
|
const identifier = defaultExport.declaration;
|
|
@@ -90,9 +90,9 @@ function parseKitOptions(cwd$1) {
|
|
|
90
90
|
if (declarator?.init?.type !== "ObjectExpression") continue;
|
|
91
91
|
objectExpression = declarator.init;
|
|
92
92
|
}
|
|
93
|
-
if (!objectExpression) throw Error(
|
|
93
|
+
if (!objectExpression) throw Error(`Unable to find svelte config object expression from \`${commonFilePaths.svelteConfig}\``);
|
|
94
94
|
} else if (defaultExport.declaration.type === "ObjectExpression") objectExpression = defaultExport.declaration;
|
|
95
|
-
if (!objectExpression) throw new Error(
|
|
95
|
+
if (!objectExpression) throw new Error(`Unexpected svelte config shape from \`${commonFilePaths.svelteConfig}\``);
|
|
96
96
|
const kit = property(objectExpression, {
|
|
97
97
|
name: "kit",
|
|
98
98
|
fallback: create({})
|
|
@@ -2159,8 +2159,8 @@ var sveltekit_adapter_default = defineAddon({
|
|
|
2159
2159
|
const devDeps = data["devDependencies"];
|
|
2160
2160
|
for (const pkg of Object.keys(devDeps)) if (pkg.startsWith("@sveltejs/adapter-")) delete devDeps[pkg];
|
|
2161
2161
|
if (options$7.adapter === "cloudflare") {
|
|
2162
|
-
if (options$7.cfTarget === "workers") data.scripts.preview = "wrangler dev .svelte-kit/cloudflare/_worker.js";
|
|
2163
|
-
else if (options$7.cfTarget === "pages") data.scripts.preview = "wrangler pages dev .svelte-kit/cloudflare";
|
|
2162
|
+
if (options$7.cfTarget === "workers") data.scripts.preview = "wrangler dev .svelte-kit/cloudflare/_worker.js --port 4173";
|
|
2163
|
+
else if (options$7.cfTarget === "pages") data.scripts.preview = "wrangler pages dev .svelte-kit/cloudflare --port 4173";
|
|
2164
2164
|
}
|
|
2165
2165
|
return generateCode();
|
|
2166
2166
|
});
|
|
@@ -2199,7 +2199,7 @@ var sveltekit_adapter_default = defineAddon({
|
|
|
2199
2199
|
sv.file(`wrangler.${configFormat}`, (content) => {
|
|
2200
2200
|
const { data, generateCode } = configFormat === "jsonc" ? parseJson(content) : parseToml(content);
|
|
2201
2201
|
if (configFormat === "jsonc") data.$schema ??= "./node_modules/wrangler/config-schema.json";
|
|
2202
|
-
if (!data.name) data.name = parseJson(readFile(cwd$1, files.package)).data.name;
|
|
2202
|
+
if (!data.name) data.name = sanitizeName(parseJson(readFile(cwd$1, files.package)).data.name, "wrangler");
|
|
2203
2203
|
data.compatibility_date ??= (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
2204
2204
|
data.compatibility_flags ??= [];
|
|
2205
2205
|
if (!data.compatibility_flags.includes("nodejs_compat") && !data.compatibility_flags.includes("nodejs_als")) data.compatibility_flags.push("nodejs_als");
|
|
@@ -2235,7 +2235,7 @@ var sveltekit_adapter_default = defineAddon({
|
|
|
2235
2235
|
const { data, generateCode } = parseJson(content);
|
|
2236
2236
|
data.compilerOptions ??= {};
|
|
2237
2237
|
data.compilerOptions.types ??= [];
|
|
2238
|
-
data.compilerOptions.types.push("worker-configuration.d.ts");
|
|
2238
|
+
data.compilerOptions.types.push("./worker-configuration.d.ts");
|
|
2239
2239
|
return generateCode();
|
|
2240
2240
|
});
|
|
2241
2241
|
sv.file("src/app.d.ts", (content) => {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-BjMGrMj9.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as ze, G as J, H as De, X as Ze, dt as require_picocolors, et as Vu, o as isVersionUnsupportedBelow, q as T$1, rt as parseJson, st as parseYaml } from "./core-D715tamU.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import fs, { existsSync } from "node:fs";
|
|
5
5
|
import path, { delimiter, dirname, isAbsolute, join, normalize, resolve } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import process$1, { cwd } from "node:process";
|
|
8
|
-
import c from "node:readline";
|
|
9
7
|
import { createRequire as createRequire$1 } from "module";
|
|
10
8
|
import { spawn } from "node:child_process";
|
|
9
|
+
import process$1, { cwd } from "node:process";
|
|
11
10
|
import { PassThrough } from "node:stream";
|
|
11
|
+
import c from "node:readline";
|
|
12
12
|
import fs$1 from "node:fs/promises";
|
|
13
13
|
|
|
14
14
|
//#region lib/create/utils.ts
|
|
@@ -44,99 +44,6 @@ function getSharedFiles() {
|
|
|
44
44
|
return files;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region lib/create/index.ts
|
|
49
|
-
const templateTypes = [
|
|
50
|
-
"minimal",
|
|
51
|
-
"demo",
|
|
52
|
-
"library"
|
|
53
|
-
];
|
|
54
|
-
const languageTypes = [
|
|
55
|
-
"typescript",
|
|
56
|
-
"checkjs",
|
|
57
|
-
"none"
|
|
58
|
-
];
|
|
59
|
-
function create(cwd$1, options) {
|
|
60
|
-
mkdirp(cwd$1);
|
|
61
|
-
write_template_files(options.template, options.types, options.name, cwd$1);
|
|
62
|
-
write_common_files(cwd$1, options, options.name);
|
|
63
|
-
}
|
|
64
|
-
const templates = templateTypes.map((dir) => {
|
|
65
|
-
const meta_file = dist(`templates/${dir}/meta.json`);
|
|
66
|
-
const { title, description } = JSON.parse(fs.readFileSync(meta_file, "utf8"));
|
|
67
|
-
return {
|
|
68
|
-
name: dir,
|
|
69
|
-
title,
|
|
70
|
-
description
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
function write_template_files(template, types, name, cwd$1) {
|
|
74
|
-
const dir = dist(`templates/${template}`);
|
|
75
|
-
copy(`${dir}/assets`, cwd$1, (name$1) => name$1.replace("DOT-", "."));
|
|
76
|
-
copy(`${dir}/package.json`, `${cwd$1}/package.json`);
|
|
77
|
-
const manifest = `${dir}/files.types=${types}.json`;
|
|
78
|
-
JSON.parse(fs.readFileSync(manifest, "utf-8")).forEach((file) => {
|
|
79
|
-
const dest = path.join(cwd$1, file.name);
|
|
80
|
-
mkdirp(path.dirname(dest));
|
|
81
|
-
fs.writeFileSync(dest, file.contents.replace(/~TODO~/g, name));
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function write_common_files(cwd$1, options, name) {
|
|
85
|
-
const files = getSharedFiles();
|
|
86
|
-
const pkg_file = path.join(cwd$1, "package.json");
|
|
87
|
-
const pkg = JSON.parse(fs.readFileSync(pkg_file, "utf-8"));
|
|
88
|
-
sort_files(files).forEach((file) => {
|
|
89
|
-
const include = file.include.every((condition) => matches_condition(condition, options));
|
|
90
|
-
if (file.exclude.some((condition) => matches_condition(condition, options)) || !include) return;
|
|
91
|
-
if (file.name === "package.json") merge(pkg, JSON.parse(file.contents));
|
|
92
|
-
else {
|
|
93
|
-
const dest = path.join(cwd$1, file.name);
|
|
94
|
-
mkdirp(path.dirname(dest));
|
|
95
|
-
fs.writeFileSync(dest, file.contents);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
pkg.dependencies = sort_keys(pkg.dependencies);
|
|
99
|
-
pkg.devDependencies = sort_keys(pkg.devDependencies);
|
|
100
|
-
pkg.name = to_valid_package_name(name);
|
|
101
|
-
fs.writeFileSync(pkg_file, JSON.stringify(pkg, null, " ") + "\n");
|
|
102
|
-
}
|
|
103
|
-
function matches_condition(condition, options) {
|
|
104
|
-
if (templateTypes.includes(condition)) return options.template === condition;
|
|
105
|
-
if (languageTypes.includes(condition)) return options.types === condition;
|
|
106
|
-
return Boolean(options[condition]);
|
|
107
|
-
}
|
|
108
|
-
function merge(target, source) {
|
|
109
|
-
for (const key in source) if (key in target) {
|
|
110
|
-
const target_value = target[key];
|
|
111
|
-
const source_value = source[key];
|
|
112
|
-
if (typeof source_value !== typeof target_value || Array.isArray(source_value) !== Array.isArray(target_value)) throw new Error("Mismatched values");
|
|
113
|
-
if (typeof source_value === "object") merge(target_value, source_value);
|
|
114
|
-
else target[key] = source_value;
|
|
115
|
-
} else target[key] = source[key];
|
|
116
|
-
}
|
|
117
|
-
function sort_keys(obj) {
|
|
118
|
-
if (!obj) return;
|
|
119
|
-
const sorted = {};
|
|
120
|
-
Object.keys(obj).sort().forEach((key) => {
|
|
121
|
-
sorted[key] = obj[key];
|
|
122
|
-
});
|
|
123
|
-
return sorted;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Sort files so that those which apply more generically come first so they
|
|
127
|
-
* can be overwritten by files for more precise cases later.
|
|
128
|
-
*/
|
|
129
|
-
function sort_files(files) {
|
|
130
|
-
return files.sort((f1, f2) => {
|
|
131
|
-
const f1_more_generic = f1.include.every((include) => f2.include.includes(include)) && f1.exclude.every((exclude) => f2.exclude.includes(exclude));
|
|
132
|
-
const f2_more_generic = f2.include.every((include) => f1.include.includes(include)) && f2.exclude.every((exclude) => f1.exclude.includes(exclude));
|
|
133
|
-
return f1_more_generic && f2_more_generic || !f1_more_generic && !f2_more_generic ? 0 : f1_more_generic ? -1 : 1;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
function to_valid_package_name(name) {
|
|
137
|
-
return name.trim().toLowerCase().replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9~.-]+/g, "-");
|
|
138
|
-
}
|
|
139
|
-
|
|
140
47
|
//#endregion
|
|
141
48
|
//#region ../../node_modules/.pnpm/tinyexec@1.0.2/node_modules/tinyexec/dist/main.js
|
|
142
49
|
var l = Object.create;
|
|
@@ -1310,82 +1217,6 @@ function isMetadataYarnClassic(metadataPath) {
|
|
|
1310
1217
|
return metadataPath.endsWith(".yarn_integrity");
|
|
1311
1218
|
}
|
|
1312
1219
|
|
|
1313
|
-
//#endregion
|
|
1314
|
-
//#region ../../node_modules/.pnpm/empathic@2.0.0/node_modules/empathic/resolve.mjs
|
|
1315
|
-
/**
|
|
1316
|
-
* Resolve an absolute path from {@link root}, but only
|
|
1317
|
-
* if {@link input} isn't already absolute.
|
|
1318
|
-
*
|
|
1319
|
-
* @param input The path to resolve.
|
|
1320
|
-
* @param root The base path; default = process.cwd()
|
|
1321
|
-
* @returns The resolved absolute path.
|
|
1322
|
-
*/
|
|
1323
|
-
function absolute(input, root) {
|
|
1324
|
-
return isAbsolute(input) ? input : resolve(root || ".", input);
|
|
1325
|
-
}
|
|
1326
|
-
function from(root, ident, silent) {
|
|
1327
|
-
try {
|
|
1328
|
-
return createRequire(root instanceof URL || root.startsWith("file://") ? join(fileURLToPath(root), "noop.js") : join(absolute(root), "noop.js")).resolve(ident);
|
|
1329
|
-
} catch (err) {
|
|
1330
|
-
if (!silent) throw err;
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
//#endregion
|
|
1335
|
-
//#region ../../node_modules/.pnpm/empathic@2.0.0/node_modules/empathic/walk.mjs
|
|
1336
|
-
/**
|
|
1337
|
-
* Get all parent directories of {@link base}.
|
|
1338
|
-
* Stops after {@link Options['last']} is processed.
|
|
1339
|
-
*
|
|
1340
|
-
* @returns An array of absolute paths of all parent directories.
|
|
1341
|
-
*/
|
|
1342
|
-
function up$1(base, options) {
|
|
1343
|
-
let { last, cwd: cwd$1 } = options || {};
|
|
1344
|
-
let tmp = absolute(base, cwd$1);
|
|
1345
|
-
let root = absolute(last || "/", cwd$1);
|
|
1346
|
-
let prev, arr = [];
|
|
1347
|
-
while (prev !== root) {
|
|
1348
|
-
arr.push(tmp);
|
|
1349
|
-
tmp = dirname(prev = tmp);
|
|
1350
|
-
if (tmp === prev) break;
|
|
1351
|
-
}
|
|
1352
|
-
return arr;
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
//#endregion
|
|
1356
|
-
//#region ../../node_modules/.pnpm/empathic@2.0.0/node_modules/empathic/find.mjs
|
|
1357
|
-
/**
|
|
1358
|
-
* Find an item by name, walking parent directories until found.
|
|
1359
|
-
*
|
|
1360
|
-
* @param name The item name to find.
|
|
1361
|
-
* @returns The absolute path to the item, if found.
|
|
1362
|
-
*/
|
|
1363
|
-
function up(name, options) {
|
|
1364
|
-
let dir, tmp;
|
|
1365
|
-
let start = options && options.cwd || "";
|
|
1366
|
-
for (dir of up$1(start, options)) {
|
|
1367
|
-
tmp = join(dir, name);
|
|
1368
|
-
if (existsSync(tmp)) return tmp;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
/**
|
|
1372
|
-
* Get the first path that matches any of the names provided.
|
|
1373
|
-
*
|
|
1374
|
-
* > [NOTE]
|
|
1375
|
-
* > The order of {@link names} is respected.
|
|
1376
|
-
*
|
|
1377
|
-
* @param names The item names to find.
|
|
1378
|
-
* @returns The absolute path of the first item found, if any.
|
|
1379
|
-
*/
|
|
1380
|
-
function any(names, options) {
|
|
1381
|
-
let dir, start = options && options.cwd || "";
|
|
1382
|
-
let j$1 = 0, len = names.length, tmp;
|
|
1383
|
-
for (dir of up$1(start, options)) for (j$1 = 0; j$1 < len; j$1++) {
|
|
1384
|
-
tmp = join(dir, names[j$1]);
|
|
1385
|
-
if (existsSync(tmp)) return tmp;
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
1220
|
//#endregion
|
|
1390
1221
|
//#region lib/cli/add/utils.ts
|
|
1391
1222
|
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
@@ -1490,6 +1321,192 @@ function getHighlighter() {
|
|
|
1490
1321
|
};
|
|
1491
1322
|
}
|
|
1492
1323
|
|
|
1324
|
+
//#endregion
|
|
1325
|
+
//#region lib/core/sanitize.ts
|
|
1326
|
+
/**
|
|
1327
|
+
* @param name - The name to sanitize.
|
|
1328
|
+
* @param style - The sanitization style.
|
|
1329
|
+
* - `package` for package.json
|
|
1330
|
+
* - `wrangler` for Cloudflare Wrangler compatibility
|
|
1331
|
+
* @returns The sanitized name.
|
|
1332
|
+
*/
|
|
1333
|
+
function sanitizeName(name, style) {
|
|
1334
|
+
let sanitized = name.trim().toLowerCase().replace(/\s+/g, "-");
|
|
1335
|
+
if (style === "package") {
|
|
1336
|
+
const hasLeadingAt = sanitized.startsWith("@");
|
|
1337
|
+
sanitized = sanitized.replace(/\s+/g, "-").replace(/^[._]/, "").replace(/[^a-z0-9~./-]+/g, "-");
|
|
1338
|
+
if (hasLeadingAt) sanitized = "@" + sanitized.slice(1);
|
|
1339
|
+
} else if (style === "wrangler") sanitized = sanitized.replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").slice(0, 63).replace(/^-|-$/g, "");
|
|
1340
|
+
else throw new Error(`Invalid kind: ${style}`);
|
|
1341
|
+
return sanitized || "undefined-sv-name";
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
//#endregion
|
|
1345
|
+
//#region lib/create/index.ts
|
|
1346
|
+
const templateTypes = [
|
|
1347
|
+
"minimal",
|
|
1348
|
+
"demo",
|
|
1349
|
+
"library"
|
|
1350
|
+
];
|
|
1351
|
+
const languageTypes = [
|
|
1352
|
+
"typescript",
|
|
1353
|
+
"checkjs",
|
|
1354
|
+
"none"
|
|
1355
|
+
];
|
|
1356
|
+
function create(cwd$1, options) {
|
|
1357
|
+
mkdirp(cwd$1);
|
|
1358
|
+
write_template_files(options.template, options.types, options.name, cwd$1);
|
|
1359
|
+
write_common_files(cwd$1, options, options.name);
|
|
1360
|
+
}
|
|
1361
|
+
const templates = templateTypes.map((dir) => {
|
|
1362
|
+
const meta_file = dist(`templates/${dir}/meta.json`);
|
|
1363
|
+
const { title, description } = JSON.parse(fs.readFileSync(meta_file, "utf8"));
|
|
1364
|
+
return {
|
|
1365
|
+
name: dir,
|
|
1366
|
+
title,
|
|
1367
|
+
description
|
|
1368
|
+
};
|
|
1369
|
+
});
|
|
1370
|
+
function write_template_files(template, types, name, cwd$1) {
|
|
1371
|
+
const dir = dist(`templates/${template}`);
|
|
1372
|
+
copy(`${dir}/assets`, cwd$1, (name$1) => name$1.replace("DOT-", "."));
|
|
1373
|
+
copy(`${dir}/package.json`, `${cwd$1}/package.json`);
|
|
1374
|
+
const manifest = `${dir}/files.types=${types}.json`;
|
|
1375
|
+
JSON.parse(fs.readFileSync(manifest, "utf-8")).forEach((file) => {
|
|
1376
|
+
const dest = path.join(cwd$1, file.name);
|
|
1377
|
+
mkdirp(path.dirname(dest));
|
|
1378
|
+
fs.writeFileSync(dest, file.contents.replace(/~TODO~/g, name));
|
|
1379
|
+
});
|
|
1380
|
+
}
|
|
1381
|
+
function write_common_files(cwd$1, options, name) {
|
|
1382
|
+
const files = getSharedFiles();
|
|
1383
|
+
const pkg_file = path.join(cwd$1, commonFilePaths.packageJson);
|
|
1384
|
+
const pkg = JSON.parse(fs.readFileSync(pkg_file, "utf-8"));
|
|
1385
|
+
sort_files(files).forEach((file) => {
|
|
1386
|
+
const include = file.include.every((condition) => matches_condition(condition, options));
|
|
1387
|
+
if (file.exclude.some((condition) => matches_condition(condition, options)) || !include) return;
|
|
1388
|
+
if (file.name === commonFilePaths.packageJson) merge(pkg, JSON.parse(file.contents));
|
|
1389
|
+
else {
|
|
1390
|
+
const dest = path.join(cwd$1, file.name);
|
|
1391
|
+
mkdirp(path.dirname(dest));
|
|
1392
|
+
fs.writeFileSync(dest, file.contents);
|
|
1393
|
+
}
|
|
1394
|
+
});
|
|
1395
|
+
pkg.dependencies = sort_keys(pkg.dependencies);
|
|
1396
|
+
pkg.devDependencies = sort_keys(pkg.devDependencies);
|
|
1397
|
+
pkg.name = sanitizeName(name, "package");
|
|
1398
|
+
fs.writeFileSync(pkg_file, JSON.stringify(pkg, null, " ") + "\n");
|
|
1399
|
+
}
|
|
1400
|
+
function matches_condition(condition, options) {
|
|
1401
|
+
if (templateTypes.includes(condition)) return options.template === condition;
|
|
1402
|
+
if (languageTypes.includes(condition)) return options.types === condition;
|
|
1403
|
+
return Boolean(options[condition]);
|
|
1404
|
+
}
|
|
1405
|
+
function merge(target, source) {
|
|
1406
|
+
for (const key in source) if (key in target) {
|
|
1407
|
+
const target_value = target[key];
|
|
1408
|
+
const source_value = source[key];
|
|
1409
|
+
if (typeof source_value !== typeof target_value || Array.isArray(source_value) !== Array.isArray(target_value)) throw new Error("Mismatched values");
|
|
1410
|
+
if (typeof source_value === "object") merge(target_value, source_value);
|
|
1411
|
+
else target[key] = source_value;
|
|
1412
|
+
} else target[key] = source[key];
|
|
1413
|
+
}
|
|
1414
|
+
function sort_keys(obj) {
|
|
1415
|
+
if (!obj) return;
|
|
1416
|
+
const sorted = {};
|
|
1417
|
+
Object.keys(obj).sort().forEach((key) => {
|
|
1418
|
+
sorted[key] = obj[key];
|
|
1419
|
+
});
|
|
1420
|
+
return sorted;
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* Sort files so that those which apply more generically come first so they
|
|
1424
|
+
* can be overwritten by files for more precise cases later.
|
|
1425
|
+
*/
|
|
1426
|
+
function sort_files(files) {
|
|
1427
|
+
return files.sort((f1, f2) => {
|
|
1428
|
+
const f1_more_generic = f1.include.every((include) => f2.include.includes(include)) && f1.exclude.every((exclude) => f2.exclude.includes(exclude));
|
|
1429
|
+
const f2_more_generic = f2.include.every((include) => f1.include.includes(include)) && f2.exclude.every((exclude) => f1.exclude.includes(exclude));
|
|
1430
|
+
return f1_more_generic && f2_more_generic || !f1_more_generic && !f2_more_generic ? 0 : f1_more_generic ? -1 : 1;
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
//#endregion
|
|
1435
|
+
//#region ../../node_modules/.pnpm/empathic@2.0.0/node_modules/empathic/resolve.mjs
|
|
1436
|
+
/**
|
|
1437
|
+
* Resolve an absolute path from {@link root}, but only
|
|
1438
|
+
* if {@link input} isn't already absolute.
|
|
1439
|
+
*
|
|
1440
|
+
* @param input The path to resolve.
|
|
1441
|
+
* @param root The base path; default = process.cwd()
|
|
1442
|
+
* @returns The resolved absolute path.
|
|
1443
|
+
*/
|
|
1444
|
+
function absolute(input, root) {
|
|
1445
|
+
return isAbsolute(input) ? input : resolve(root || ".", input);
|
|
1446
|
+
}
|
|
1447
|
+
function from(root, ident, silent) {
|
|
1448
|
+
try {
|
|
1449
|
+
return createRequire(root instanceof URL || root.startsWith("file://") ? join(fileURLToPath(root), "noop.js") : join(absolute(root), "noop.js")).resolve(ident);
|
|
1450
|
+
} catch (err) {
|
|
1451
|
+
if (!silent) throw err;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
//#endregion
|
|
1456
|
+
//#region ../../node_modules/.pnpm/empathic@2.0.0/node_modules/empathic/walk.mjs
|
|
1457
|
+
/**
|
|
1458
|
+
* Get all parent directories of {@link base}.
|
|
1459
|
+
* Stops after {@link Options['last']} is processed.
|
|
1460
|
+
*
|
|
1461
|
+
* @returns An array of absolute paths of all parent directories.
|
|
1462
|
+
*/
|
|
1463
|
+
function up$1(base, options) {
|
|
1464
|
+
let { last, cwd: cwd$1 } = options || {};
|
|
1465
|
+
let tmp = absolute(base, cwd$1);
|
|
1466
|
+
let root = absolute(last || "/", cwd$1);
|
|
1467
|
+
let prev, arr = [];
|
|
1468
|
+
while (prev !== root) {
|
|
1469
|
+
arr.push(tmp);
|
|
1470
|
+
tmp = dirname(prev = tmp);
|
|
1471
|
+
if (tmp === prev) break;
|
|
1472
|
+
}
|
|
1473
|
+
return arr;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
//#endregion
|
|
1477
|
+
//#region ../../node_modules/.pnpm/empathic@2.0.0/node_modules/empathic/find.mjs
|
|
1478
|
+
/**
|
|
1479
|
+
* Find an item by name, walking parent directories until found.
|
|
1480
|
+
*
|
|
1481
|
+
* @param name The item name to find.
|
|
1482
|
+
* @returns The absolute path to the item, if found.
|
|
1483
|
+
*/
|
|
1484
|
+
function up(name, options) {
|
|
1485
|
+
let dir, tmp;
|
|
1486
|
+
let start = options && options.cwd || "";
|
|
1487
|
+
for (dir of up$1(start, options)) {
|
|
1488
|
+
tmp = join(dir, name);
|
|
1489
|
+
if (existsSync(tmp)) return tmp;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Get the first path that matches any of the names provided.
|
|
1494
|
+
*
|
|
1495
|
+
* > [NOTE]
|
|
1496
|
+
* > The order of {@link names} is respected.
|
|
1497
|
+
*
|
|
1498
|
+
* @param names The item names to find.
|
|
1499
|
+
* @returns The absolute path of the first item found, if any.
|
|
1500
|
+
*/
|
|
1501
|
+
function any(names, options) {
|
|
1502
|
+
let dir, start = options && options.cwd || "";
|
|
1503
|
+
let j$1 = 0, len = names.length, tmp;
|
|
1504
|
+
for (dir of up$1(start, options)) for (j$1 = 0; j$1 < len; j$1++) {
|
|
1505
|
+
tmp = join(dir, names[j$1]);
|
|
1506
|
+
if (existsSync(tmp)) return tmp;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1493
1510
|
//#endregion
|
|
1494
1511
|
//#region ../../node_modules/.pnpm/commander@14.0.2/node_modules/commander/lib/error.js
|
|
1495
1512
|
var require_error = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
@@ -4617,4 +4634,4 @@ async function getPnpmVersion() {
|
|
|
4617
4634
|
}
|
|
4618
4635
|
|
|
4619
4636
|
//#endregion
|
|
4620
|
-
export {
|
|
4637
|
+
export { writeFile as C, q as D, K as E, dist as O, readFile as S, resolveCommand as T, fileExists as _, installOption as a, getPackageJson as b, Option as c, up as d, from as f, commonFilePaths as g, sanitizeName as h, installDependencies as i, getSharedFiles as k, program as l, templates as m, addPnpmBuildDependencies as n, packageManagerPrompt as o, create as p, getUserAgent as r, Command as s, AGENT_NAMES as t, any as u, formatFiles as v, detect as w, installPackages as x, getHighlighter as y };
|