feat: init
This commit is contained in:
188
node_modules/@nuxt/telemetry/dist/cli.cjs
generated
vendored
Normal file
188
node_modules/@nuxt/telemetry/dist/cli.cjs
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const node_path = require('node:path');
|
||||
const rc = require('rc9');
|
||||
const utils = require('consola/utils');
|
||||
const consola = require('consola');
|
||||
const kit = require('@nuxt/kit');
|
||||
const stdEnv = require('std-env');
|
||||
const citty = require('citty');
|
||||
const consent = require('./shared/telemetry.BikY0E3b.cjs');
|
||||
|
||||
function _interopNamespaceCompat(e) {
|
||||
if (e && typeof e === 'object' && 'default' in e) return e;
|
||||
const n = Object.create(null);
|
||||
if (e) {
|
||||
for (const k in e) {
|
||||
n[k] = e[k];
|
||||
}
|
||||
}
|
||||
n.default = e;
|
||||
return n;
|
||||
}
|
||||
|
||||
const rc__namespace = /*#__PURE__*/_interopNamespaceCompat(rc);
|
||||
|
||||
function isTruthy(val) {
|
||||
return val === true || val === "true" || val === "1" || val === 1;
|
||||
}
|
||||
function parseDotenv(src) {
|
||||
const result = {};
|
||||
for (const line of src.split("\n")) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith("#")) continue;
|
||||
const eqIndex = trimmed.indexOf("=");
|
||||
if (eqIndex === -1) continue;
|
||||
const key = trimmed.slice(0, eqIndex).trim();
|
||||
let value = trimmed.slice(eqIndex + 1).trim();
|
||||
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
result[key] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
const RC_FILENAME = ".nuxtrc";
|
||||
const sharedArgs = {
|
||||
global: {
|
||||
type: "boolean",
|
||||
alias: "g",
|
||||
default: false,
|
||||
description: "Apply globally"
|
||||
},
|
||||
dir: {
|
||||
type: "positional",
|
||||
default: "."
|
||||
}
|
||||
};
|
||||
const main = citty.createMain({
|
||||
meta: {
|
||||
name: "nuxt-telemetry",
|
||||
description: "Manage consent for Nuxt collecting anonymous telemetry data about general usage.",
|
||||
version: consent.version
|
||||
},
|
||||
subCommands: {
|
||||
status: citty.defineCommand({
|
||||
meta: {
|
||||
name: "status",
|
||||
description: "Show telemetry status"
|
||||
},
|
||||
args: sharedArgs,
|
||||
async run({ args }) {
|
||||
ensureNuxtProject(args);
|
||||
const dir = node_path.resolve(args.dir);
|
||||
await showStatus(dir, args.global);
|
||||
}
|
||||
}),
|
||||
enable: citty.defineCommand({
|
||||
meta: {
|
||||
name: "enable",
|
||||
description: "Enable telemetry"
|
||||
},
|
||||
args: sharedArgs,
|
||||
async run({ args }) {
|
||||
ensureNuxtProject(args);
|
||||
const dir = node_path.resolve(args.dir);
|
||||
setRC(dir, "telemetry.enabled", true, args.global);
|
||||
setRC(dir, "telemetry.consent", consent.consentVersion, args.global);
|
||||
await showStatus(dir, args.global);
|
||||
consola.consola.info("You can disable telemetry with `npx nuxt-telemetry disable" + (args.global ? " --global" : args.dir ? " " + args.dir : "") + "`");
|
||||
}
|
||||
}),
|
||||
disable: citty.defineCommand({
|
||||
meta: {
|
||||
name: "disable",
|
||||
description: "Disable telemetry"
|
||||
},
|
||||
args: sharedArgs,
|
||||
async run({ args }) {
|
||||
ensureNuxtProject(args);
|
||||
const dir = node_path.resolve(args.dir);
|
||||
setRC(dir, "telemetry.enabled", false, args.global);
|
||||
setRC(dir, "telemetry.consent", 0, args.global);
|
||||
await showStatus(dir, args.global);
|
||||
consola.consola.info("You can enable telemetry with `npx nuxt-telemetry enable" + (args.global ? " --global" : args.dir ? " " + args.dir : "") + "`");
|
||||
}
|
||||
}),
|
||||
consent: citty.defineCommand({
|
||||
meta: {
|
||||
name: "consent",
|
||||
description: "Prompt for user consent"
|
||||
},
|
||||
args: sharedArgs,
|
||||
async run({ args }) {
|
||||
ensureNuxtProject(args);
|
||||
const dir = node_path.resolve(args.dir);
|
||||
const accepted = await consent.ensureUserconsent({});
|
||||
if (accepted && !args.global) {
|
||||
setRC(dir, "telemetry.enabled", true, args.global);
|
||||
setRC(dir, "telemetry.consent", consent.consentVersion, args.global);
|
||||
}
|
||||
await showStatus(dir, args.global);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
async function _checkDisabled(dir) {
|
||||
if (stdEnv.isTest) {
|
||||
return "because you are running in a test environment";
|
||||
}
|
||||
if (isTruthy(process.env.NUXT_TELEMETRY_DISABLED)) {
|
||||
return "by the `NUXT_TELEMETRY_DISABLED` environment variable";
|
||||
}
|
||||
const dotenvFile = node_path.resolve(dir, ".env");
|
||||
if (fs.existsSync(dotenvFile)) {
|
||||
const _env = parseDotenv(fs.readFileSync(dotenvFile, "utf8"));
|
||||
if (isTruthy(_env.NUXT_TELEMETRY_DISABLED)) {
|
||||
return "by the `NUXT_TELEMETRY_DISABLED` environment variable set in " + dotenvFile;
|
||||
}
|
||||
}
|
||||
const disabledByConf = (conf) => conf.telemetry === false || conf.telemetry && conf.telemetry.enabled === false;
|
||||
try {
|
||||
const config = await kit.loadNuxtConfig({ cwd: dir });
|
||||
for (const layer of config._layers) {
|
||||
if (disabledByConf(layer.config)) {
|
||||
return "by " + config._layers[0].configFile;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
if (disabledByConf(rc__namespace.read({ name: RC_FILENAME, dir }))) {
|
||||
return "by " + node_path.resolve(dir, RC_FILENAME);
|
||||
}
|
||||
if (disabledByConf(rc__namespace.readUser({ name: RC_FILENAME }))) {
|
||||
return "by " + node_path.resolve(os.homedir(), RC_FILENAME);
|
||||
}
|
||||
}
|
||||
async function showStatus(dir, global) {
|
||||
const disabled = await _checkDisabled(dir);
|
||||
if (disabled) {
|
||||
consola.consola.info(`Nuxt telemetry is ${utils.colors.yellow("disabled")} ${disabled}.`);
|
||||
} else {
|
||||
consola.consola.info(`Nuxt telemetry is ${utils.colors.green("enabled")}`, global ? "on your machine." : "in the current project.");
|
||||
}
|
||||
}
|
||||
function setRC(dir, key, val, global) {
|
||||
const update = { [key]: val };
|
||||
if (global) {
|
||||
rc__namespace.updateUser(update, RC_FILENAME);
|
||||
} else {
|
||||
rc__namespace.update(update, { name: RC_FILENAME, dir });
|
||||
}
|
||||
}
|
||||
async function ensureNuxtProject(args) {
|
||||
if (args.global) {
|
||||
return;
|
||||
}
|
||||
const dir = node_path.resolve(args.dir);
|
||||
const nuxtConfig = await kit.loadNuxtConfig({ cwd: dir });
|
||||
if (!nuxtConfig || !nuxtConfig._layers[0]?.configFile) {
|
||||
consola.consola.error("You are not in a Nuxt project.");
|
||||
consola.consola.info("You can try specifying a directory or by using the `--global` flag to configure telemetry for your machine.");
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
exports.main = main;
|
||||
5
node_modules/@nuxt/telemetry/dist/cli.d.cts
generated
vendored
Normal file
5
node_modules/@nuxt/telemetry/dist/cli.d.cts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as citty from 'citty';
|
||||
|
||||
declare const main: (opts?: citty.RunMainOptions) => Promise<void>;
|
||||
|
||||
export { main };
|
||||
5
node_modules/@nuxt/telemetry/dist/cli.d.mts
generated
vendored
Normal file
5
node_modules/@nuxt/telemetry/dist/cli.d.mts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as citty from 'citty';
|
||||
|
||||
declare const main: (opts?: citty.RunMainOptions) => Promise<void>;
|
||||
|
||||
export { main };
|
||||
172
node_modules/@nuxt/telemetry/dist/cli.mjs
generated
vendored
Normal file
172
node_modules/@nuxt/telemetry/dist/cli.mjs
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { homedir } from 'node:os';
|
||||
import { resolve } from 'node:path';
|
||||
import * as rc from 'rc9';
|
||||
import { colors } from 'consola/utils';
|
||||
import { consola } from 'consola';
|
||||
import { loadNuxtConfig } from '@nuxt/kit';
|
||||
import { isTest } from 'std-env';
|
||||
import { createMain, defineCommand } from 'citty';
|
||||
import { v as version, e as ensureUserconsent, c as consentVersion } from './shared/telemetry.Dgzu-axG.mjs';
|
||||
|
||||
function isTruthy(val) {
|
||||
return val === true || val === "true" || val === "1" || val === 1;
|
||||
}
|
||||
function parseDotenv(src) {
|
||||
const result = {};
|
||||
for (const line of src.split("\n")) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith("#")) continue;
|
||||
const eqIndex = trimmed.indexOf("=");
|
||||
if (eqIndex === -1) continue;
|
||||
const key = trimmed.slice(0, eqIndex).trim();
|
||||
let value = trimmed.slice(eqIndex + 1).trim();
|
||||
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
result[key] = value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
const RC_FILENAME = ".nuxtrc";
|
||||
const sharedArgs = {
|
||||
global: {
|
||||
type: "boolean",
|
||||
alias: "g",
|
||||
default: false,
|
||||
description: "Apply globally"
|
||||
},
|
||||
dir: {
|
||||
type: "positional",
|
||||
default: "."
|
||||
}
|
||||
};
|
||||
const main = createMain({
|
||||
meta: {
|
||||
name: "nuxt-telemetry",
|
||||
description: "Manage consent for Nuxt collecting anonymous telemetry data about general usage.",
|
||||
version
|
||||
},
|
||||
subCommands: {
|
||||
status: defineCommand({
|
||||
meta: {
|
||||
name: "status",
|
||||
description: "Show telemetry status"
|
||||
},
|
||||
args: sharedArgs,
|
||||
async run({ args }) {
|
||||
ensureNuxtProject(args);
|
||||
const dir = resolve(args.dir);
|
||||
await showStatus(dir, args.global);
|
||||
}
|
||||
}),
|
||||
enable: defineCommand({
|
||||
meta: {
|
||||
name: "enable",
|
||||
description: "Enable telemetry"
|
||||
},
|
||||
args: sharedArgs,
|
||||
async run({ args }) {
|
||||
ensureNuxtProject(args);
|
||||
const dir = resolve(args.dir);
|
||||
setRC(dir, "telemetry.enabled", true, args.global);
|
||||
setRC(dir, "telemetry.consent", consentVersion, args.global);
|
||||
await showStatus(dir, args.global);
|
||||
consola.info("You can disable telemetry with `npx nuxt-telemetry disable" + (args.global ? " --global" : args.dir ? " " + args.dir : "") + "`");
|
||||
}
|
||||
}),
|
||||
disable: defineCommand({
|
||||
meta: {
|
||||
name: "disable",
|
||||
description: "Disable telemetry"
|
||||
},
|
||||
args: sharedArgs,
|
||||
async run({ args }) {
|
||||
ensureNuxtProject(args);
|
||||
const dir = resolve(args.dir);
|
||||
setRC(dir, "telemetry.enabled", false, args.global);
|
||||
setRC(dir, "telemetry.consent", 0, args.global);
|
||||
await showStatus(dir, args.global);
|
||||
consola.info("You can enable telemetry with `npx nuxt-telemetry enable" + (args.global ? " --global" : args.dir ? " " + args.dir : "") + "`");
|
||||
}
|
||||
}),
|
||||
consent: defineCommand({
|
||||
meta: {
|
||||
name: "consent",
|
||||
description: "Prompt for user consent"
|
||||
},
|
||||
args: sharedArgs,
|
||||
async run({ args }) {
|
||||
ensureNuxtProject(args);
|
||||
const dir = resolve(args.dir);
|
||||
const accepted = await ensureUserconsent({});
|
||||
if (accepted && !args.global) {
|
||||
setRC(dir, "telemetry.enabled", true, args.global);
|
||||
setRC(dir, "telemetry.consent", consentVersion, args.global);
|
||||
}
|
||||
await showStatus(dir, args.global);
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
async function _checkDisabled(dir) {
|
||||
if (isTest) {
|
||||
return "because you are running in a test environment";
|
||||
}
|
||||
if (isTruthy(process.env.NUXT_TELEMETRY_DISABLED)) {
|
||||
return "by the `NUXT_TELEMETRY_DISABLED` environment variable";
|
||||
}
|
||||
const dotenvFile = resolve(dir, ".env");
|
||||
if (existsSync(dotenvFile)) {
|
||||
const _env = parseDotenv(readFileSync(dotenvFile, "utf8"));
|
||||
if (isTruthy(_env.NUXT_TELEMETRY_DISABLED)) {
|
||||
return "by the `NUXT_TELEMETRY_DISABLED` environment variable set in " + dotenvFile;
|
||||
}
|
||||
}
|
||||
const disabledByConf = (conf) => conf.telemetry === false || conf.telemetry && conf.telemetry.enabled === false;
|
||||
try {
|
||||
const config = await loadNuxtConfig({ cwd: dir });
|
||||
for (const layer of config._layers) {
|
||||
if (disabledByConf(layer.config)) {
|
||||
return "by " + config._layers[0].configFile;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
if (disabledByConf(rc.read({ name: RC_FILENAME, dir }))) {
|
||||
return "by " + resolve(dir, RC_FILENAME);
|
||||
}
|
||||
if (disabledByConf(rc.readUser({ name: RC_FILENAME }))) {
|
||||
return "by " + resolve(homedir(), RC_FILENAME);
|
||||
}
|
||||
}
|
||||
async function showStatus(dir, global) {
|
||||
const disabled = await _checkDisabled(dir);
|
||||
if (disabled) {
|
||||
consola.info(`Nuxt telemetry is ${colors.yellow("disabled")} ${disabled}.`);
|
||||
} else {
|
||||
consola.info(`Nuxt telemetry is ${colors.green("enabled")}`, global ? "on your machine." : "in the current project.");
|
||||
}
|
||||
}
|
||||
function setRC(dir, key, val, global) {
|
||||
const update = { [key]: val };
|
||||
if (global) {
|
||||
rc.updateUser(update, RC_FILENAME);
|
||||
} else {
|
||||
rc.update(update, { name: RC_FILENAME, dir });
|
||||
}
|
||||
}
|
||||
async function ensureNuxtProject(args) {
|
||||
if (args.global) {
|
||||
return;
|
||||
}
|
||||
const dir = resolve(args.dir);
|
||||
const nuxtConfig = await loadNuxtConfig({ cwd: dir });
|
||||
if (!nuxtConfig || !nuxtConfig._layers[0]?.configFile) {
|
||||
consola.error("You are not in a Nuxt project.");
|
||||
consola.info("You can try specifying a directory or by using the `--global` flag to configure telemetry for your machine.");
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
export { main };
|
||||
429
node_modules/@nuxt/telemetry/dist/module.cjs
generated
vendored
Normal file
429
node_modules/@nuxt/telemetry/dist/module.cjs
generated
vendored
Normal file
@@ -0,0 +1,429 @@
|
||||
'use strict';
|
||||
|
||||
const kit = require('@nuxt/kit');
|
||||
const consent = require('./shared/telemetry.BikY0E3b.cjs');
|
||||
const ofetch = require('ofetch');
|
||||
const os = require('node:os');
|
||||
const fs = require('node:fs');
|
||||
const node_child_process = require('node:child_process');
|
||||
const stdEnv = require('std-env');
|
||||
const node_crypto = require('node:crypto');
|
||||
const node_path = require('node:path');
|
||||
require('consola/utils');
|
||||
require('consola');
|
||||
require('rc9');
|
||||
|
||||
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
||||
|
||||
const os__default = /*#__PURE__*/_interopDefaultCompat(os);
|
||||
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
||||
|
||||
async function postEvent(endpoint, body) {
|
||||
const res = await ofetch.fetch(endpoint, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"user-agent": "Nuxt Telemetry " + consent.version
|
||||
}
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(res.statusText);
|
||||
}
|
||||
}
|
||||
|
||||
function hash(str) {
|
||||
return node_crypto.createHash("sha256").update(str).digest("hex").substr(0, 16);
|
||||
}
|
||||
function randomSeed() {
|
||||
return hash(node_crypto.randomUUID());
|
||||
}
|
||||
|
||||
function getNuxtMajorVersion(nuxt) {
|
||||
for (let i = 2; i < 10; i++) {
|
||||
if (kit.isNuxtMajorVersion(i, nuxt)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
async function createContext(nuxt, options) {
|
||||
const rootDir = nuxt.options.workspaceDir || nuxt.options.rootDir || process.cwd();
|
||||
const git = await getGit(rootDir);
|
||||
const packageManager = detectPackageManager(rootDir);
|
||||
const { seed } = options;
|
||||
const projectHash = getProjectHash(rootDir, git, seed);
|
||||
const projectSession = getProjectSession(projectHash, seed);
|
||||
const nuxtVersion = kit.getNuxtVersion(nuxt);
|
||||
const nuxtMajorVersion = getNuxtMajorVersion(nuxt);
|
||||
const nodeVersion = process.version.replace("v", "");
|
||||
const isEdge = nuxtVersion.includes("edge");
|
||||
return {
|
||||
nuxt,
|
||||
seed,
|
||||
git,
|
||||
projectHash,
|
||||
projectSession,
|
||||
nuxtVersion,
|
||||
nuxtMajorVersion,
|
||||
isEdge,
|
||||
cli: getCLI(),
|
||||
nodeVersion,
|
||||
os: os__default.type().toLocaleLowerCase(),
|
||||
environment: getEnv(),
|
||||
packageManager: packageManager || "unknown",
|
||||
concent: options.consent
|
||||
};
|
||||
}
|
||||
function getEnv() {
|
||||
if (stdEnv.provider) {
|
||||
return stdEnv.provider;
|
||||
}
|
||||
if (consent.isDocker()) {
|
||||
return "Docker";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
function getCLI() {
|
||||
const entry = process.argv[1] ?? "";
|
||||
const knownCLIs = {
|
||||
"nuxt-ts.js": "nuxt-ts",
|
||||
"nuxt-start.js": "nuxt-start",
|
||||
"nuxt.js": "nuxt",
|
||||
"nuxi": "nuxi"
|
||||
};
|
||||
for (const _key in knownCLIs) {
|
||||
const key = _key;
|
||||
if (entry.includes(key)) {
|
||||
const edge = entry.includes("-edge") ? "-edge" : entry.includes("-nightly") ? "-nightly" : "";
|
||||
return knownCLIs[key] + edge;
|
||||
}
|
||||
}
|
||||
return "programmatic";
|
||||
}
|
||||
function getProjectSession(projectHash, sessionId) {
|
||||
return hash(`${projectHash}#${sessionId}`);
|
||||
}
|
||||
function getProjectHash(rootDir, git, seed) {
|
||||
let id;
|
||||
if (git && git.url) {
|
||||
id = `${git.source}#${git.owner}#${git.name}`;
|
||||
} else {
|
||||
id = `${rootDir}#${seed}`;
|
||||
}
|
||||
return hash(id);
|
||||
}
|
||||
async function getGitRemote(cwd) {
|
||||
let gitRemoteUrl = null;
|
||||
try {
|
||||
gitRemoteUrl = node_child_process.execSync("git config --get remote.origin.url ", { encoding: "utf8", cwd }).trim() || null;
|
||||
} catch {
|
||||
}
|
||||
return gitRemoteUrl;
|
||||
}
|
||||
function detectPackageManager(rootDir) {
|
||||
const lockFiles = {
|
||||
"bun.lockb": "bun",
|
||||
"bun.lock": "bun",
|
||||
"deno.lock": "deno",
|
||||
"pnpm-lock.yaml": "pnpm",
|
||||
"pnpm-workspace.yaml": "pnpm",
|
||||
"yarn.lock": "yarn",
|
||||
"package-lock.json": "npm",
|
||||
"npm-shrinkwrap.json": "npm"
|
||||
};
|
||||
for (const [file, manager] of Object.entries(lockFiles)) {
|
||||
if (fs.existsSync(`${rootDir}/${file}`)) {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
try {
|
||||
const pkgJson = JSON.parse(fs.readFileSync(`${rootDir}/package.json`, "utf8"));
|
||||
if (typeof pkgJson.packageManager === "string") {
|
||||
const name = pkgJson.packageManager.split("@")[0];
|
||||
if (name) return name;
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
function parseGitUrl(gitUrl) {
|
||||
const normalized = gitUrl.trim();
|
||||
const sshMatch = normalized.match(/^[\w-]+@([^:]+):(.+?)(?:\.git)?$/);
|
||||
if (sshMatch) {
|
||||
const source = sshMatch[1];
|
||||
const path = sshMatch[2];
|
||||
const parts = path.split("/");
|
||||
if (parts.length >= 2) {
|
||||
return { source, owner: parts.slice(0, -1).join("/"), name: parts.at(-1) };
|
||||
}
|
||||
}
|
||||
try {
|
||||
const url = new URL(normalized);
|
||||
const pathname = url.pathname.replace(/\.git$/, "").replace(/^\//, "");
|
||||
const parts = pathname.split("/");
|
||||
if (parts.length >= 2) {
|
||||
return { source: url.hostname, owner: parts.slice(0, -1).join("/"), name: parts.at(-1) };
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
async function getGit(rootDir) {
|
||||
const gitRemote = await getGitRemote(rootDir);
|
||||
if (!gitRemote) {
|
||||
return;
|
||||
}
|
||||
const meta = parseGitUrl(gitRemote);
|
||||
if (!meta) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
url: `https://${meta.source}/${meta.owner}/${meta.name}`,
|
||||
gitRemote,
|
||||
source: meta.source,
|
||||
owner: meta.owner,
|
||||
name: meta.name
|
||||
};
|
||||
}
|
||||
|
||||
const logger = kit.useLogger("@nuxt/telemetry");
|
||||
|
||||
const build = function({ nuxt }, payload) {
|
||||
const duration = { build: payload.duration.build };
|
||||
let isSuccess = true;
|
||||
for (const [name, stat] of Object.entries(payload.stats)) {
|
||||
duration[name] = stat.duration;
|
||||
if (!stat.success) {
|
||||
isSuccess = false;
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: "build",
|
||||
isSuccess,
|
||||
isDev: nuxt.options.dev || false,
|
||||
duration
|
||||
// size
|
||||
};
|
||||
};
|
||||
|
||||
const command = function({ nuxt }) {
|
||||
let command2 = process.argv[2] || "unknown";
|
||||
const flagMap = {
|
||||
dev: "dev",
|
||||
_generate: "generate",
|
||||
_export: "export",
|
||||
_build: "build",
|
||||
_serve: "serve",
|
||||
_start: "start"
|
||||
};
|
||||
for (const _flag in flagMap) {
|
||||
const flag = _flag;
|
||||
if (nuxt.options[flag]) {
|
||||
command2 = flagMap[flag];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: "command",
|
||||
command: command2
|
||||
};
|
||||
};
|
||||
|
||||
const generate = function generate2({ nuxt }, payload) {
|
||||
return {
|
||||
name: "generate",
|
||||
// @ts-expect-error Legacy type from Nuxt 2
|
||||
isExport: !!nuxt.options._export,
|
||||
routesCount: payload.routesCount,
|
||||
duration: {
|
||||
generate: payload.duration.generate
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const module$2 = function({ nuxt: { options } }) {
|
||||
const events = [];
|
||||
const modules = (options._installedModules || []).filter((m) => m.meta?.version).map((m) => ({
|
||||
name: m.meta.name,
|
||||
version: m.meta.version,
|
||||
timing: m.timings?.setup || 0
|
||||
}));
|
||||
for (const m of modules) {
|
||||
events.push({
|
||||
name: "module",
|
||||
moduleName: m.name,
|
||||
version: m.version,
|
||||
timing: m.timing
|
||||
});
|
||||
}
|
||||
return events;
|
||||
};
|
||||
|
||||
const project = function(context) {
|
||||
const { options } = context.nuxt;
|
||||
return {
|
||||
name: "project",
|
||||
type: context.git && context.git.url ? "git" : "local",
|
||||
isSSR: options.ssr !== false,
|
||||
target: options.server ? "server" : "static",
|
||||
packageManager: context.packageManager
|
||||
};
|
||||
};
|
||||
|
||||
const session = function({ seed }) {
|
||||
return {
|
||||
name: "session",
|
||||
id: seed
|
||||
};
|
||||
};
|
||||
|
||||
const files = async function(context) {
|
||||
const { options } = context.nuxt;
|
||||
const nuxtIgnore = fs__default.existsSync(node_path.resolve(options.rootDir, ".nuxtignore"));
|
||||
const nuxtRc = fs__default.existsSync(node_path.resolve(options.rootDir, ".nuxtrc"));
|
||||
const appConfig = fs__default.existsSync(await kit.resolvePath("~/app.config"));
|
||||
return {
|
||||
name: "files",
|
||||
nuxtIgnore,
|
||||
nuxtRc,
|
||||
appConfig
|
||||
};
|
||||
};
|
||||
|
||||
class Telemetry {
|
||||
nuxt;
|
||||
options;
|
||||
storage;
|
||||
// TODO
|
||||
_contextPromise;
|
||||
events = [];
|
||||
eventFactories = {
|
||||
build,
|
||||
command,
|
||||
generate,
|
||||
module: module$2,
|
||||
project,
|
||||
session,
|
||||
files
|
||||
};
|
||||
constructor(nuxt, options) {
|
||||
this.nuxt = nuxt;
|
||||
this.options = options;
|
||||
}
|
||||
getContext() {
|
||||
if (!this._contextPromise) {
|
||||
this._contextPromise = createContext(this.nuxt, this.options);
|
||||
}
|
||||
return this._contextPromise;
|
||||
}
|
||||
createEvent(name, payload) {
|
||||
const eventFactory = this.eventFactories[name];
|
||||
if (typeof eventFactory !== "function") {
|
||||
logger.warn("Unknown event:", name);
|
||||
return;
|
||||
}
|
||||
const eventPromise = this._invokeEvent(name, eventFactory, payload);
|
||||
this.events.push(eventPromise);
|
||||
}
|
||||
async _invokeEvent(name, eventFactory, payload) {
|
||||
try {
|
||||
const context = await this.getContext();
|
||||
const event = await eventFactory(context, payload);
|
||||
event.name = name;
|
||||
return event;
|
||||
} catch (err) {
|
||||
logger.error("Error while running event:", err);
|
||||
}
|
||||
}
|
||||
async getPublicContext() {
|
||||
const context = await this.getContext();
|
||||
const eventContext = {};
|
||||
for (const key of [
|
||||
"nuxtVersion",
|
||||
"nuxtMajorVersion",
|
||||
"isEdge",
|
||||
"nodeVersion",
|
||||
"cli",
|
||||
"os",
|
||||
"environment",
|
||||
"projectHash",
|
||||
"projectSession"
|
||||
]) {
|
||||
eventContext[key] = context[key];
|
||||
}
|
||||
return eventContext;
|
||||
}
|
||||
async sendEvents(debug) {
|
||||
const events = [].concat(...(await Promise.all(this.events)).filter(Boolean));
|
||||
this.events = [];
|
||||
const context = await this.getPublicContext();
|
||||
const body = {
|
||||
timestamp: Date.now(),
|
||||
context,
|
||||
events
|
||||
};
|
||||
if (this.options.endpoint) {
|
||||
const start = Date.now();
|
||||
try {
|
||||
if (debug) {
|
||||
logger.info("Sending events:", JSON.stringify(body, null, 2));
|
||||
}
|
||||
await postEvent(this.options.endpoint, body);
|
||||
if (debug) {
|
||||
logger.success(`Events sent to \`${this.options.endpoint}\` (${Date.now() - start} ms)`);
|
||||
}
|
||||
} catch (err) {
|
||||
if (debug) {
|
||||
logger.error(`Error sending sent to \`${this.options.endpoint}\` (${Date.now() - start} ms)
|
||||
`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const module$1 = kit.defineNuxtModule({
|
||||
meta: {
|
||||
name: "@nuxt/telemetry",
|
||||
configKey: "telemetry"
|
||||
},
|
||||
defaults: {
|
||||
endpoint: process.env.NUXT_TELEMETRY_ENDPOINT || "https://telemetry.nuxt.com",
|
||||
debug: process.env.NUXT_TELEMETRY_DEBUG === "1" || process.env.NUXT_TELEMETRY_DEBUG === "true",
|
||||
enabled: void 0,
|
||||
seed: void 0
|
||||
},
|
||||
async setup(toptions, nuxt) {
|
||||
if (!toptions.debug) {
|
||||
logger.level = 0;
|
||||
}
|
||||
const _topLevelTelemetry = nuxt.options.telemetry;
|
||||
if (_topLevelTelemetry !== true) {
|
||||
if (toptions.enabled === false || _topLevelTelemetry === false || !await consent.ensureUserconsent(toptions)) {
|
||||
logger.info("Telemetry disabled");
|
||||
return;
|
||||
}
|
||||
}
|
||||
logger.info("Telemetry enabled");
|
||||
if (!toptions.seed || typeof toptions.seed !== "string") {
|
||||
toptions.seed = randomSeed();
|
||||
consent.updateUserNuxtRc("telemetry.seed", toptions.seed);
|
||||
logger.info("Seed generated:", toptions.seed);
|
||||
}
|
||||
const t = new Telemetry(nuxt, toptions);
|
||||
nuxt.hook("modules:done", async () => {
|
||||
t.createEvent("project");
|
||||
if (nuxt.options.dev) {
|
||||
t.createEvent("session");
|
||||
t.createEvent("files");
|
||||
}
|
||||
t.createEvent("command");
|
||||
t.createEvent("module");
|
||||
await nuxt.callHook("telemetry:setup", t);
|
||||
t.sendEvents(toptions.debug);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = module$1;
|
||||
58
node_modules/@nuxt/telemetry/dist/module.d.cts
generated
vendored
Normal file
58
node_modules/@nuxt/telemetry/dist/module.d.cts
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
import * as _nuxt_schema from '@nuxt/schema';
|
||||
import { Nuxt } from '@nuxt/schema';
|
||||
|
||||
interface TelemetryOptions {
|
||||
debug: boolean;
|
||||
endpoint: string;
|
||||
seed: string;
|
||||
consent?: number;
|
||||
enabled: boolean;
|
||||
}
|
||||
interface Context {
|
||||
nuxt: Nuxt;
|
||||
cli: string;
|
||||
seed: string;
|
||||
projectHash: string;
|
||||
projectSession: string;
|
||||
nuxtVersion: string;
|
||||
nuxtMajorVersion: number;
|
||||
isEdge: boolean;
|
||||
nodeVersion: string;
|
||||
os: string;
|
||||
git?: {
|
||||
url: string;
|
||||
};
|
||||
environment: string | null;
|
||||
packageManager: string;
|
||||
concent: number;
|
||||
}
|
||||
interface Event {
|
||||
name: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
type EventFactoryResult<T> = Promise<T> | T | Promise<T>[] | T[];
|
||||
type EventFactory<T extends Event> = (context: Context, payload: any) => EventFactoryResult<T>;
|
||||
|
||||
declare class Telemetry {
|
||||
nuxt: Nuxt;
|
||||
options: Required<TelemetryOptions>;
|
||||
storage: any;
|
||||
_contextPromise?: Promise<Context>;
|
||||
events: Promise<EventFactoryResult<any>>[];
|
||||
eventFactories: Record<string, EventFactory<any>>;
|
||||
constructor(nuxt: Nuxt, options: Required<TelemetryOptions>);
|
||||
getContext(): Promise<Context>;
|
||||
createEvent(name: string, payload?: object): undefined | Promise<any>;
|
||||
_invokeEvent(name: string, eventFactory: EventFactory<any>, payload?: object): Promise<any>;
|
||||
getPublicContext(): Promise<Record<string, any>>;
|
||||
sendEvents(debug?: boolean): Promise<void>;
|
||||
}
|
||||
|
||||
type ModuleOptions = TelemetryOptions;
|
||||
interface ModuleHooks {
|
||||
'telemetry:setup': (telemetry: Telemetry) => void;
|
||||
}
|
||||
declare const _default: _nuxt_schema.NuxtModule<TelemetryOptions, TelemetryOptions, false>;
|
||||
|
||||
export = _default;
|
||||
export type { ModuleHooks, ModuleOptions };
|
||||
58
node_modules/@nuxt/telemetry/dist/module.d.mts
generated
vendored
Normal file
58
node_modules/@nuxt/telemetry/dist/module.d.mts
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
import * as _nuxt_schema from '@nuxt/schema';
|
||||
import { Nuxt } from '@nuxt/schema';
|
||||
|
||||
interface TelemetryOptions {
|
||||
debug: boolean;
|
||||
endpoint: string;
|
||||
seed: string;
|
||||
consent?: number;
|
||||
enabled: boolean;
|
||||
}
|
||||
interface Context {
|
||||
nuxt: Nuxt;
|
||||
cli: string;
|
||||
seed: string;
|
||||
projectHash: string;
|
||||
projectSession: string;
|
||||
nuxtVersion: string;
|
||||
nuxtMajorVersion: number;
|
||||
isEdge: boolean;
|
||||
nodeVersion: string;
|
||||
os: string;
|
||||
git?: {
|
||||
url: string;
|
||||
};
|
||||
environment: string | null;
|
||||
packageManager: string;
|
||||
concent: number;
|
||||
}
|
||||
interface Event {
|
||||
name: string;
|
||||
[key: string]: any;
|
||||
}
|
||||
type EventFactoryResult<T> = Promise<T> | T | Promise<T>[] | T[];
|
||||
type EventFactory<T extends Event> = (context: Context, payload: any) => EventFactoryResult<T>;
|
||||
|
||||
declare class Telemetry {
|
||||
nuxt: Nuxt;
|
||||
options: Required<TelemetryOptions>;
|
||||
storage: any;
|
||||
_contextPromise?: Promise<Context>;
|
||||
events: Promise<EventFactoryResult<any>>[];
|
||||
eventFactories: Record<string, EventFactory<any>>;
|
||||
constructor(nuxt: Nuxt, options: Required<TelemetryOptions>);
|
||||
getContext(): Promise<Context>;
|
||||
createEvent(name: string, payload?: object): undefined | Promise<any>;
|
||||
_invokeEvent(name: string, eventFactory: EventFactory<any>, payload?: object): Promise<any>;
|
||||
getPublicContext(): Promise<Record<string, any>>;
|
||||
sendEvents(debug?: boolean): Promise<void>;
|
||||
}
|
||||
|
||||
type ModuleOptions = TelemetryOptions;
|
||||
interface ModuleHooks {
|
||||
'telemetry:setup': (telemetry: Telemetry) => void;
|
||||
}
|
||||
declare const _default: _nuxt_schema.NuxtModule<TelemetryOptions, TelemetryOptions, false>;
|
||||
|
||||
export { _default as default };
|
||||
export type { ModuleHooks, ModuleOptions };
|
||||
9
node_modules/@nuxt/telemetry/dist/module.json
generated
vendored
Normal file
9
node_modules/@nuxt/telemetry/dist/module.json
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "@nuxt/telemetry",
|
||||
"configKey": "telemetry",
|
||||
"version": "2.7.0",
|
||||
"builder": {
|
||||
"@nuxt/module-builder": "1.0.2",
|
||||
"unbuild": "3.6.1"
|
||||
}
|
||||
}
|
||||
422
node_modules/@nuxt/telemetry/dist/module.mjs
generated
vendored
Normal file
422
node_modules/@nuxt/telemetry/dist/module.mjs
generated
vendored
Normal file
@@ -0,0 +1,422 @@
|
||||
import { getNuxtVersion, isNuxtMajorVersion, useLogger, resolvePath, defineNuxtModule } from '@nuxt/kit';
|
||||
import { v as version, i as isDocker, e as ensureUserconsent, u as updateUserNuxtRc } from './shared/telemetry.Dgzu-axG.mjs';
|
||||
import { fetch } from 'ofetch';
|
||||
import os from 'node:os';
|
||||
import fs, { existsSync, readFileSync } from 'node:fs';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { provider } from 'std-env';
|
||||
import { randomUUID, createHash } from 'node:crypto';
|
||||
import { resolve } from 'node:path';
|
||||
import 'consola/utils';
|
||||
import 'consola';
|
||||
import 'rc9';
|
||||
|
||||
async function postEvent(endpoint, body) {
|
||||
const res = await fetch(endpoint, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"user-agent": "Nuxt Telemetry " + version
|
||||
}
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(res.statusText);
|
||||
}
|
||||
}
|
||||
|
||||
function hash(str) {
|
||||
return createHash("sha256").update(str).digest("hex").substr(0, 16);
|
||||
}
|
||||
function randomSeed() {
|
||||
return hash(randomUUID());
|
||||
}
|
||||
|
||||
function getNuxtMajorVersion(nuxt) {
|
||||
for (let i = 2; i < 10; i++) {
|
||||
if (isNuxtMajorVersion(i, nuxt)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
async function createContext(nuxt, options) {
|
||||
const rootDir = nuxt.options.workspaceDir || nuxt.options.rootDir || process.cwd();
|
||||
const git = await getGit(rootDir);
|
||||
const packageManager = detectPackageManager(rootDir);
|
||||
const { seed } = options;
|
||||
const projectHash = getProjectHash(rootDir, git, seed);
|
||||
const projectSession = getProjectSession(projectHash, seed);
|
||||
const nuxtVersion = getNuxtVersion(nuxt);
|
||||
const nuxtMajorVersion = getNuxtMajorVersion(nuxt);
|
||||
const nodeVersion = process.version.replace("v", "");
|
||||
const isEdge = nuxtVersion.includes("edge");
|
||||
return {
|
||||
nuxt,
|
||||
seed,
|
||||
git,
|
||||
projectHash,
|
||||
projectSession,
|
||||
nuxtVersion,
|
||||
nuxtMajorVersion,
|
||||
isEdge,
|
||||
cli: getCLI(),
|
||||
nodeVersion,
|
||||
os: os.type().toLocaleLowerCase(),
|
||||
environment: getEnv(),
|
||||
packageManager: packageManager || "unknown",
|
||||
concent: options.consent
|
||||
};
|
||||
}
|
||||
function getEnv() {
|
||||
if (provider) {
|
||||
return provider;
|
||||
}
|
||||
if (isDocker()) {
|
||||
return "Docker";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
function getCLI() {
|
||||
const entry = process.argv[1] ?? "";
|
||||
const knownCLIs = {
|
||||
"nuxt-ts.js": "nuxt-ts",
|
||||
"nuxt-start.js": "nuxt-start",
|
||||
"nuxt.js": "nuxt",
|
||||
"nuxi": "nuxi"
|
||||
};
|
||||
for (const _key in knownCLIs) {
|
||||
const key = _key;
|
||||
if (entry.includes(key)) {
|
||||
const edge = entry.includes("-edge") ? "-edge" : entry.includes("-nightly") ? "-nightly" : "";
|
||||
return knownCLIs[key] + edge;
|
||||
}
|
||||
}
|
||||
return "programmatic";
|
||||
}
|
||||
function getProjectSession(projectHash, sessionId) {
|
||||
return hash(`${projectHash}#${sessionId}`);
|
||||
}
|
||||
function getProjectHash(rootDir, git, seed) {
|
||||
let id;
|
||||
if (git && git.url) {
|
||||
id = `${git.source}#${git.owner}#${git.name}`;
|
||||
} else {
|
||||
id = `${rootDir}#${seed}`;
|
||||
}
|
||||
return hash(id);
|
||||
}
|
||||
async function getGitRemote(cwd) {
|
||||
let gitRemoteUrl = null;
|
||||
try {
|
||||
gitRemoteUrl = execSync("git config --get remote.origin.url ", { encoding: "utf8", cwd }).trim() || null;
|
||||
} catch {
|
||||
}
|
||||
return gitRemoteUrl;
|
||||
}
|
||||
function detectPackageManager(rootDir) {
|
||||
const lockFiles = {
|
||||
"bun.lockb": "bun",
|
||||
"bun.lock": "bun",
|
||||
"deno.lock": "deno",
|
||||
"pnpm-lock.yaml": "pnpm",
|
||||
"pnpm-workspace.yaml": "pnpm",
|
||||
"yarn.lock": "yarn",
|
||||
"package-lock.json": "npm",
|
||||
"npm-shrinkwrap.json": "npm"
|
||||
};
|
||||
for (const [file, manager] of Object.entries(lockFiles)) {
|
||||
if (existsSync(`${rootDir}/${file}`)) {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
try {
|
||||
const pkgJson = JSON.parse(readFileSync(`${rootDir}/package.json`, "utf8"));
|
||||
if (typeof pkgJson.packageManager === "string") {
|
||||
const name = pkgJson.packageManager.split("@")[0];
|
||||
if (name) return name;
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
function parseGitUrl(gitUrl) {
|
||||
const normalized = gitUrl.trim();
|
||||
const sshMatch = normalized.match(/^[\w-]+@([^:]+):(.+?)(?:\.git)?$/);
|
||||
if (sshMatch) {
|
||||
const source = sshMatch[1];
|
||||
const path = sshMatch[2];
|
||||
const parts = path.split("/");
|
||||
if (parts.length >= 2) {
|
||||
return { source, owner: parts.slice(0, -1).join("/"), name: parts.at(-1) };
|
||||
}
|
||||
}
|
||||
try {
|
||||
const url = new URL(normalized);
|
||||
const pathname = url.pathname.replace(/\.git$/, "").replace(/^\//, "");
|
||||
const parts = pathname.split("/");
|
||||
if (parts.length >= 2) {
|
||||
return { source: url.hostname, owner: parts.slice(0, -1).join("/"), name: parts.at(-1) };
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
async function getGit(rootDir) {
|
||||
const gitRemote = await getGitRemote(rootDir);
|
||||
if (!gitRemote) {
|
||||
return;
|
||||
}
|
||||
const meta = parseGitUrl(gitRemote);
|
||||
if (!meta) {
|
||||
return;
|
||||
}
|
||||
return {
|
||||
url: `https://${meta.source}/${meta.owner}/${meta.name}`,
|
||||
gitRemote,
|
||||
source: meta.source,
|
||||
owner: meta.owner,
|
||||
name: meta.name
|
||||
};
|
||||
}
|
||||
|
||||
const logger = useLogger("@nuxt/telemetry");
|
||||
|
||||
const build = function({ nuxt }, payload) {
|
||||
const duration = { build: payload.duration.build };
|
||||
let isSuccess = true;
|
||||
for (const [name, stat] of Object.entries(payload.stats)) {
|
||||
duration[name] = stat.duration;
|
||||
if (!stat.success) {
|
||||
isSuccess = false;
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: "build",
|
||||
isSuccess,
|
||||
isDev: nuxt.options.dev || false,
|
||||
duration
|
||||
// size
|
||||
};
|
||||
};
|
||||
|
||||
const command = function({ nuxt }) {
|
||||
let command2 = process.argv[2] || "unknown";
|
||||
const flagMap = {
|
||||
dev: "dev",
|
||||
_generate: "generate",
|
||||
_export: "export",
|
||||
_build: "build",
|
||||
_serve: "serve",
|
||||
_start: "start"
|
||||
};
|
||||
for (const _flag in flagMap) {
|
||||
const flag = _flag;
|
||||
if (nuxt.options[flag]) {
|
||||
command2 = flagMap[flag];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: "command",
|
||||
command: command2
|
||||
};
|
||||
};
|
||||
|
||||
const generate = function generate2({ nuxt }, payload) {
|
||||
return {
|
||||
name: "generate",
|
||||
// @ts-expect-error Legacy type from Nuxt 2
|
||||
isExport: !!nuxt.options._export,
|
||||
routesCount: payload.routesCount,
|
||||
duration: {
|
||||
generate: payload.duration.generate
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const module$2 = function({ nuxt: { options } }) {
|
||||
const events = [];
|
||||
const modules = (options._installedModules || []).filter((m) => m.meta?.version).map((m) => ({
|
||||
name: m.meta.name,
|
||||
version: m.meta.version,
|
||||
timing: m.timings?.setup || 0
|
||||
}));
|
||||
for (const m of modules) {
|
||||
events.push({
|
||||
name: "module",
|
||||
moduleName: m.name,
|
||||
version: m.version,
|
||||
timing: m.timing
|
||||
});
|
||||
}
|
||||
return events;
|
||||
};
|
||||
|
||||
const project = function(context) {
|
||||
const { options } = context.nuxt;
|
||||
return {
|
||||
name: "project",
|
||||
type: context.git && context.git.url ? "git" : "local",
|
||||
isSSR: options.ssr !== false,
|
||||
target: options.server ? "server" : "static",
|
||||
packageManager: context.packageManager
|
||||
};
|
||||
};
|
||||
|
||||
const session = function({ seed }) {
|
||||
return {
|
||||
name: "session",
|
||||
id: seed
|
||||
};
|
||||
};
|
||||
|
||||
const files = async function(context) {
|
||||
const { options } = context.nuxt;
|
||||
const nuxtIgnore = fs.existsSync(resolve(options.rootDir, ".nuxtignore"));
|
||||
const nuxtRc = fs.existsSync(resolve(options.rootDir, ".nuxtrc"));
|
||||
const appConfig = fs.existsSync(await resolvePath("~/app.config"));
|
||||
return {
|
||||
name: "files",
|
||||
nuxtIgnore,
|
||||
nuxtRc,
|
||||
appConfig
|
||||
};
|
||||
};
|
||||
|
||||
class Telemetry {
|
||||
nuxt;
|
||||
options;
|
||||
storage;
|
||||
// TODO
|
||||
_contextPromise;
|
||||
events = [];
|
||||
eventFactories = {
|
||||
build,
|
||||
command,
|
||||
generate,
|
||||
module: module$2,
|
||||
project,
|
||||
session,
|
||||
files
|
||||
};
|
||||
constructor(nuxt, options) {
|
||||
this.nuxt = nuxt;
|
||||
this.options = options;
|
||||
}
|
||||
getContext() {
|
||||
if (!this._contextPromise) {
|
||||
this._contextPromise = createContext(this.nuxt, this.options);
|
||||
}
|
||||
return this._contextPromise;
|
||||
}
|
||||
createEvent(name, payload) {
|
||||
const eventFactory = this.eventFactories[name];
|
||||
if (typeof eventFactory !== "function") {
|
||||
logger.warn("Unknown event:", name);
|
||||
return;
|
||||
}
|
||||
const eventPromise = this._invokeEvent(name, eventFactory, payload);
|
||||
this.events.push(eventPromise);
|
||||
}
|
||||
async _invokeEvent(name, eventFactory, payload) {
|
||||
try {
|
||||
const context = await this.getContext();
|
||||
const event = await eventFactory(context, payload);
|
||||
event.name = name;
|
||||
return event;
|
||||
} catch (err) {
|
||||
logger.error("Error while running event:", err);
|
||||
}
|
||||
}
|
||||
async getPublicContext() {
|
||||
const context = await this.getContext();
|
||||
const eventContext = {};
|
||||
for (const key of [
|
||||
"nuxtVersion",
|
||||
"nuxtMajorVersion",
|
||||
"isEdge",
|
||||
"nodeVersion",
|
||||
"cli",
|
||||
"os",
|
||||
"environment",
|
||||
"projectHash",
|
||||
"projectSession"
|
||||
]) {
|
||||
eventContext[key] = context[key];
|
||||
}
|
||||
return eventContext;
|
||||
}
|
||||
async sendEvents(debug) {
|
||||
const events = [].concat(...(await Promise.all(this.events)).filter(Boolean));
|
||||
this.events = [];
|
||||
const context = await this.getPublicContext();
|
||||
const body = {
|
||||
timestamp: Date.now(),
|
||||
context,
|
||||
events
|
||||
};
|
||||
if (this.options.endpoint) {
|
||||
const start = Date.now();
|
||||
try {
|
||||
if (debug) {
|
||||
logger.info("Sending events:", JSON.stringify(body, null, 2));
|
||||
}
|
||||
await postEvent(this.options.endpoint, body);
|
||||
if (debug) {
|
||||
logger.success(`Events sent to \`${this.options.endpoint}\` (${Date.now() - start} ms)`);
|
||||
}
|
||||
} catch (err) {
|
||||
if (debug) {
|
||||
logger.error(`Error sending sent to \`${this.options.endpoint}\` (${Date.now() - start} ms)
|
||||
`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const module$1 = defineNuxtModule({
|
||||
meta: {
|
||||
name: "@nuxt/telemetry",
|
||||
configKey: "telemetry"
|
||||
},
|
||||
defaults: {
|
||||
endpoint: process.env.NUXT_TELEMETRY_ENDPOINT || "https://telemetry.nuxt.com",
|
||||
debug: process.env.NUXT_TELEMETRY_DEBUG === "1" || process.env.NUXT_TELEMETRY_DEBUG === "true",
|
||||
enabled: void 0,
|
||||
seed: void 0
|
||||
},
|
||||
async setup(toptions, nuxt) {
|
||||
if (!toptions.debug) {
|
||||
logger.level = 0;
|
||||
}
|
||||
const _topLevelTelemetry = nuxt.options.telemetry;
|
||||
if (_topLevelTelemetry !== true) {
|
||||
if (toptions.enabled === false || _topLevelTelemetry === false || !await ensureUserconsent(toptions)) {
|
||||
logger.info("Telemetry disabled");
|
||||
return;
|
||||
}
|
||||
}
|
||||
logger.info("Telemetry enabled");
|
||||
if (!toptions.seed || typeof toptions.seed !== "string") {
|
||||
toptions.seed = randomSeed();
|
||||
updateUserNuxtRc("telemetry.seed", toptions.seed);
|
||||
logger.info("Seed generated:", toptions.seed);
|
||||
}
|
||||
const t = new Telemetry(nuxt, toptions);
|
||||
nuxt.hook("modules:done", async () => {
|
||||
t.createEvent("project");
|
||||
if (nuxt.options.dev) {
|
||||
t.createEvent("session");
|
||||
t.createEvent("files");
|
||||
}
|
||||
t.createEvent("command");
|
||||
t.createEvent("module");
|
||||
await nuxt.callHook("telemetry:setup", t);
|
||||
t.sendEvents(toptions.debug);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export { module$1 as default };
|
||||
76
node_modules/@nuxt/telemetry/dist/shared/telemetry.BikY0E3b.cjs
generated
vendored
Normal file
76
node_modules/@nuxt/telemetry/dist/shared/telemetry.BikY0E3b.cjs
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
'use strict';
|
||||
|
||||
const utils = require('consola/utils');
|
||||
const consola = require('consola');
|
||||
const stdEnv = require('std-env');
|
||||
const rc = require('rc9');
|
||||
const fs = require('node:fs');
|
||||
|
||||
const version = "2.7.0";
|
||||
|
||||
const consentVersion = 1;
|
||||
|
||||
function updateUserNuxtRc(key, val) {
|
||||
rc.updateUser({ [key]: val }, ".nuxtrc");
|
||||
}
|
||||
|
||||
let isDockerCached;
|
||||
function hasDockerEnv() {
|
||||
try {
|
||||
fs.statSync("/.dockerenv");
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function hasDockerCGroup() {
|
||||
try {
|
||||
return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function hasDockerMountInfo() {
|
||||
try {
|
||||
return fs.readFileSync("/proc/self/mountinfo", "utf8").includes("/docker/containers/");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isDocker() {
|
||||
isDockerCached ??= hasDockerEnv() || hasDockerCGroup() || hasDockerMountInfo();
|
||||
return isDockerCached;
|
||||
}
|
||||
|
||||
async function ensureUserconsent(options) {
|
||||
if (options.consent && options.consent >= consentVersion) {
|
||||
return true;
|
||||
}
|
||||
if (stdEnv.isMinimal || process.env.CODESANDBOX_SSE || process.env.NEXT_TELEMETRY_DISABLED || isDocker()) {
|
||||
return false;
|
||||
}
|
||||
consola.consola.restoreAll();
|
||||
process.stdout.write("\n");
|
||||
consola.consola.info(`${utils.colors.green("Nuxt")} collects completely anonymous data about usage.
|
||||
This will help us improve Nuxt developer experience over time.
|
||||
Read more on ${utils.colors.underline(utils.colors.cyan("https://github.com/nuxt/telemetry"))}
|
||||
`);
|
||||
const accepted = await consola.consola.prompt("Are you interested in participating?", {
|
||||
type: "confirm"
|
||||
});
|
||||
process.stdout.write("\n");
|
||||
consola.consola.wrapAll();
|
||||
if (accepted) {
|
||||
updateUserNuxtRc("telemetry.consent", consentVersion);
|
||||
updateUserNuxtRc("telemetry.enabled", true);
|
||||
return true;
|
||||
}
|
||||
updateUserNuxtRc("telemetry.enabled", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
exports.consentVersion = consentVersion;
|
||||
exports.ensureUserconsent = ensureUserconsent;
|
||||
exports.isDocker = isDocker;
|
||||
exports.updateUserNuxtRc = updateUserNuxtRc;
|
||||
exports.version = version;
|
||||
70
node_modules/@nuxt/telemetry/dist/shared/telemetry.Dgzu-axG.mjs
generated
vendored
Normal file
70
node_modules/@nuxt/telemetry/dist/shared/telemetry.Dgzu-axG.mjs
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import { colors } from 'consola/utils';
|
||||
import { consola } from 'consola';
|
||||
import { isMinimal } from 'std-env';
|
||||
import { updateUser } from 'rc9';
|
||||
import { statSync, readFileSync } from 'node:fs';
|
||||
|
||||
const version = "2.7.0";
|
||||
|
||||
const consentVersion = 1;
|
||||
|
||||
function updateUserNuxtRc(key, val) {
|
||||
updateUser({ [key]: val }, ".nuxtrc");
|
||||
}
|
||||
|
||||
let isDockerCached;
|
||||
function hasDockerEnv() {
|
||||
try {
|
||||
statSync("/.dockerenv");
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function hasDockerCGroup() {
|
||||
try {
|
||||
return readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function hasDockerMountInfo() {
|
||||
try {
|
||||
return readFileSync("/proc/self/mountinfo", "utf8").includes("/docker/containers/");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function isDocker() {
|
||||
isDockerCached ??= hasDockerEnv() || hasDockerCGroup() || hasDockerMountInfo();
|
||||
return isDockerCached;
|
||||
}
|
||||
|
||||
async function ensureUserconsent(options) {
|
||||
if (options.consent && options.consent >= consentVersion) {
|
||||
return true;
|
||||
}
|
||||
if (isMinimal || process.env.CODESANDBOX_SSE || process.env.NEXT_TELEMETRY_DISABLED || isDocker()) {
|
||||
return false;
|
||||
}
|
||||
consola.restoreAll();
|
||||
process.stdout.write("\n");
|
||||
consola.info(`${colors.green("Nuxt")} collects completely anonymous data about usage.
|
||||
This will help us improve Nuxt developer experience over time.
|
||||
Read more on ${colors.underline(colors.cyan("https://github.com/nuxt/telemetry"))}
|
||||
`);
|
||||
const accepted = await consola.prompt("Are you interested in participating?", {
|
||||
type: "confirm"
|
||||
});
|
||||
process.stdout.write("\n");
|
||||
consola.wrapAll();
|
||||
if (accepted) {
|
||||
updateUserNuxtRc("telemetry.consent", consentVersion);
|
||||
updateUserNuxtRc("telemetry.enabled", true);
|
||||
return true;
|
||||
}
|
||||
updateUserNuxtRc("telemetry.enabled", false);
|
||||
return false;
|
||||
}
|
||||
|
||||
export { consentVersion as c, ensureUserconsent as e, isDocker as i, updateUserNuxtRc as u, version as v };
|
||||
3
node_modules/@nuxt/telemetry/dist/types.d.cts
generated
vendored
Normal file
3
node_modules/@nuxt/telemetry/dist/types.d.cts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
import { default as telemetryModule } from './module.mjs'
|
||||
export = telemetryModule
|
||||
9
node_modules/@nuxt/telemetry/dist/types.d.mts
generated
vendored
Normal file
9
node_modules/@nuxt/telemetry/dist/types.d.mts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { ModuleHooks } from './module.mjs'
|
||||
|
||||
declare module '@nuxt/schema' {
|
||||
interface NuxtHooks extends ModuleHooks {}
|
||||
}
|
||||
|
||||
export { default } from './module.mjs'
|
||||
|
||||
export { type ModuleHooks, type ModuleOptions } from './module.mjs'
|
||||
Reference in New Issue
Block a user