@nuxt/cli-nightly 3.26.0-20250607-210256-59f83b1 → 3.26.0-20250607-215204-1943f84

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 (36) hide show
  1. package/bin/nuxi.mjs +1 -0
  2. package/dist/chunks/add.mjs +308 -290
  3. package/dist/chunks/add2.mjs +291 -307
  4. package/dist/chunks/analyze.mjs +8 -7
  5. package/dist/chunks/build.mjs +11 -11
  6. package/dist/chunks/cleanup.mjs +8 -7
  7. package/dist/chunks/dev-child.mjs +11 -71
  8. package/dist/chunks/dev.mjs +142 -117
  9. package/dist/chunks/devtools.mjs +3 -2
  10. package/dist/chunks/generate.mjs +8 -8
  11. package/dist/chunks/index.mjs +379 -12
  12. package/dist/chunks/index2.mjs +15 -0
  13. package/dist/chunks/info.mjs +8 -6
  14. package/dist/chunks/init.mjs +4 -3
  15. package/dist/chunks/prepare.mjs +7 -6
  16. package/dist/chunks/preview.mjs +6 -5
  17. package/dist/chunks/search.mjs +3 -2
  18. package/dist/chunks/test.mjs +3 -2
  19. package/dist/chunks/typecheck.mjs +6 -6
  20. package/dist/chunks/upgrade.mjs +9 -8
  21. package/dist/dev/index.d.mts +75 -0
  22. package/dist/dev/index.d.ts +75 -0
  23. package/dist/dev/index.mjs +21 -0
  24. package/dist/index.mjs +2 -1
  25. package/dist/shared/{cli-nightly.DTVmTXKJ.mjs → cli-nightly.B4U5vhqQ.mjs} +7 -6
  26. package/dist/shared/cli-nightly.B9AmABr3.mjs +5 -0
  27. package/dist/shared/{cli-nightly.CjK7ZDKA.mjs → cli-nightly.BgFMCBoq.mjs} +9 -10
  28. package/dist/shared/{cli-nightly.DlcAx0De.mjs → cli-nightly.BrKZotr9.mjs} +11 -9
  29. package/dist/shared/{cli-nightly.DDBHWicM.mjs → cli-nightly.Bu_9IHj2.mjs} +2 -2
  30. package/dist/shared/{cli-nightly.DPQxxyDx.mjs → cli-nightly.Cf9T6EbF.mjs} +1 -1
  31. package/dist/shared/{cli-nightly.BnfAj4iy.mjs → cli-nightly.DPmMxQ6h.mjs} +1 -1
  32. package/dist/shared/cli-nightly.Dc8ncNQ_.mjs +27 -0
  33. package/dist/shared/{cli-nightly.DdmGgrsK.mjs → cli-nightly.DkO5RR_e.mjs} +1 -1
  34. package/package.json +2 -1
  35. package/dist/chunks/dev2.mjs +0 -293
  36. package/dist/shared/cli-nightly.COGWopdX.mjs +0 -26
package/bin/nuxi.mjs CHANGED
@@ -6,6 +6,7 @@ import { runMain } from '../dist/index.mjs'
6
6
  globalThis.__nuxt_cli__ = {
7
7
  startTime: Date.now(),
8
8
  entry: fileURLToPath(import.meta.url),
9
+ devEntry: fileURLToPath(new URL('../dist/dev/index.mjs', import.meta.url)),
9
10
  }
10
11
 
11
12
  runMain()
@@ -1,318 +1,336 @@
1
- import { existsSync, promises } from 'node:fs';
1
+ import * as fs from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
2
4
  import process from 'node:process';
5
+ import { updateConfig } from 'c12/update';
3
6
  import { defineCommand } from 'citty';
4
- import { resolve, extname, dirname } from 'pathe';
5
- import { l as loadKit } from '../shared/cli-nightly.DlcAx0De.mjs';
6
- import { l as logLevelArgs, c as cwdArgs, a as logger } from '../shared/cli-nightly.CjK7ZDKA.mjs';
7
- import { pascalCase, camelCase } from 'scule';
8
- import 'jiti';
9
- import 'node:path';
7
+ import { colors } from 'consola/utils';
8
+ import { addDependency } from 'nypm';
9
+ import { $fetch } from 'ofetch';
10
+ import { resolve } from 'pathe';
11
+ import { readPackageJSON } from 'pkg-types';
12
+ import { satisfies } from 'semver';
13
+ import { joinURL } from 'ufo';
14
+ import { r as runCommand } from '../shared/cli-nightly.B4U5vhqQ.mjs';
15
+ import { l as logger } from '../shared/cli-nightly.B9AmABr3.mjs';
16
+ import { a as logLevelArgs, c as cwdArgs } from '../shared/cli-nightly.BgFMCBoq.mjs';
17
+ import { f as fetchModules, g as getNuxtVersion, c as checkNuxtCompatibility } from '../shared/cli-nightly.C935N1ss.mjs';
18
+ import 'node:url';
19
+ import 'node:crypto';
10
20
  import 'std-env';
21
+ import '../shared/cli-nightly.Cf9T6EbF.mjs';
11
22
  import 'consola';
12
- import 'node:url';
13
-
14
- const httpMethods = [
15
- "connect",
16
- "delete",
17
- "get",
18
- "head",
19
- "options",
20
- "post",
21
- "put",
22
- "trace",
23
- "patch"
24
- ];
25
- const api = ({ name, args, nuxtOptions }) => {
26
- return {
27
- path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, `api/${name}${applySuffix(args, httpMethods, "method")}.ts`),
28
- contents: `
29
- export default defineEventHandler(event => {
30
- return 'Hello ${name}'
31
- })
32
- `
33
- };
34
- };
35
-
36
- const app = ({ args, nuxtOptions }) => ({
37
- path: resolve(nuxtOptions.srcDir, "app.vue"),
38
- contents: args.pages ? `
39
- <script setup lang="ts"><\/script>
40
-
41
- <template>
42
- <div>
43
- <NuxtLayout>
44
- <NuxtPage/>
45
- </NuxtLayout>
46
- </div>
47
- </template>
48
-
49
- <style scoped></style>
50
- ` : `
51
- <script setup lang="ts"><\/script>
52
-
53
- <template>
54
- <div>
55
- <h1>Hello World!</h1>
56
- </div>
57
- </template>
58
-
59
- <style scoped></style>
60
- `
61
- });
62
-
63
- const appConfig = ({ nuxtOptions }) => ({
64
- path: resolve(nuxtOptions.srcDir, "app.config.ts"),
65
- contents: `
66
- export default defineAppConfig({})
67
- `
68
- });
69
-
70
- const component = ({ name, args, nuxtOptions }) => ({
71
- path: resolve(nuxtOptions.srcDir, `components/${name}${applySuffix(
72
- args,
73
- ["client", "server"],
74
- "mode"
75
- )}.vue`),
76
- contents: `
77
- <script setup lang="ts"><\/script>
78
-
79
- <template>
80
- <div>
81
- Component: ${name}
82
- </div>
83
- </template>
84
-
85
- <style scoped></style>
86
- `
87
- });
88
-
89
- const composable = ({ name, nuxtOptions }) => {
90
- const nameWithoutUsePrefix = name.replace(/^use-?/, "");
91
- const nameWithUsePrefix = `use${pascalCase(nameWithoutUsePrefix)}`;
92
- return {
93
- path: resolve(nuxtOptions.srcDir, `composables/${name}.ts`),
94
- contents: `
95
- export const ${nameWithUsePrefix} = () => {
96
- return ref()
97
- }
98
- `
99
- };
100
- };
101
-
102
- const error = ({ nuxtOptions }) => ({
103
- path: resolve(nuxtOptions.srcDir, "error.vue"),
104
- contents: `
105
- <script setup lang="ts">
106
- import type { NuxtError } from '#app'
107
-
108
- const props = defineProps({
109
- error: Object as () => NuxtError
110
- })
111
- <\/script>
112
-
113
- <template>
114
- <div>
115
- <h1>{{ error.statusCode }}</h1>
116
- <NuxtLink to="/">Go back home</NuxtLink>
117
- </div>
118
- </template>
119
-
120
- <style scoped></style>
121
- `
122
- });
123
-
124
- const layer = ({ name, nuxtOptions }) => {
125
- return {
126
- path: resolve(nuxtOptions.srcDir, `layers/${name}/nuxt.config.ts`),
127
- contents: `
128
- export default defineNuxtConfig({})
129
- `
130
- };
131
- };
132
-
133
- const layout = ({ name, nuxtOptions }) => ({
134
- path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.layouts, `${name}.vue`),
135
- contents: `
136
- <script setup lang="ts"><\/script>
137
-
138
- <template>
139
- <div>
140
- Layout: ${name}
141
- <slot />
142
- </div>
143
- </template>
144
-
145
- <style scoped></style>
146
- `
147
- });
148
-
149
- const middleware = ({ name, args, nuxtOptions }) => ({
150
- path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.middleware, `${name}${applySuffix(args, ["global"])}.ts`),
151
- contents: `
152
- export default defineNuxtRouteMiddleware((to, from) => {})
153
- `
154
- });
155
-
156
- const module = ({ name, nuxtOptions }) => ({
157
- path: resolve(nuxtOptions.rootDir, "modules", `${name}.ts`),
158
- contents: `
159
- import { defineNuxtModule } from 'nuxt/kit'
160
-
161
- export default defineNuxtModule({
162
- meta: {
163
- name: '${name}'
164
- },
165
- setup () {}
166
- })
167
- `
168
- });
169
-
170
- const page = ({ name, nuxtOptions }) => ({
171
- path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.pages, `${name}.vue`),
172
- contents: `
173
- <script setup lang="ts"><\/script>
174
-
175
- <template>
176
- <div>
177
- Page: ${name}
178
- </div>
179
- </template>
180
-
181
- <style scoped></style>
182
- `
183
- });
184
-
185
- const plugin = ({ name, args, nuxtOptions }) => ({
186
- path: resolve(nuxtOptions.srcDir, nuxtOptions.dir.plugins, `${name}${applySuffix(args, ["client", "server"], "mode")}.ts`),
187
- contents: `
188
- export default defineNuxtPlugin(nuxtApp => {})
189
- `
190
- });
191
-
192
- const serverMiddleware = ({ name, nuxtOptions }) => ({
193
- path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "middleware", `${name}.ts`),
194
- contents: `
195
- export default defineEventHandler(event => {})
196
- `
197
- });
198
-
199
- const serverPlugin = ({ name, nuxtOptions }) => ({
200
- path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "plugins", `${name}.ts`),
201
- contents: `
202
- export default defineNitroPlugin(nitroApp => {})
203
- `
204
- });
205
-
206
- const serverRoute = ({ name, args, nuxtOptions }) => ({
207
- path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, args.api ? "api" : "routes", `${name}.ts`),
208
- contents: `
209
- export default defineEventHandler(event => {})
210
- `
211
- });
212
-
213
- const serverUtil = ({ name, nuxtOptions }) => ({
214
- path: resolve(nuxtOptions.srcDir, nuxtOptions.serverDir, "utils", `${name}.ts`),
215
- contents: `
216
- export function ${camelCase(name)}() {}
217
- `
218
- });
219
23
 
220
- const templates = {
221
- "api": api,
222
- "app": app,
223
- "app-config": appConfig,
224
- "component": component,
225
- "composable": composable,
226
- "error": error,
227
- "layer": layer,
228
- "layout": layout,
229
- "middleware": middleware,
230
- "module": module,
231
- "page": page,
232
- "plugin": plugin,
233
- "server-middleware": serverMiddleware,
234
- "server-plugin": serverPlugin,
235
- "server-route": serverRoute,
236
- "server-util": serverUtil
237
- };
238
- function applySuffix(args, suffixes, unwrapFrom) {
239
- let suffix = "";
240
- for (const s of suffixes) {
241
- if (args[s]) {
242
- suffix += `.${s}`;
243
- }
244
- }
245
- if (unwrapFrom && args[unwrapFrom] && suffixes.includes(args[unwrapFrom])) {
246
- suffix += `.${args[unwrapFrom]}`;
247
- }
248
- return suffix;
249
- }
250
-
251
- const templateNames = Object.keys(templates);
252
24
  const add = defineCommand({
253
25
  meta: {
254
26
  name: "add",
255
- description: "Create a new template file."
27
+ description: "Add Nuxt modules"
256
28
  },
257
29
  args: {
258
30
  ...cwdArgs,
259
31
  ...logLevelArgs,
260
- force: {
32
+ moduleName: {
33
+ type: "positional",
34
+ description: "Specify one or more modules to install by name, separated by spaces"
35
+ },
36
+ skipInstall: {
261
37
  type: "boolean",
262
- description: "Force override file if it already exists",
263
- default: false
38
+ description: "Skip npm install"
264
39
  },
265
- template: {
266
- type: "positional",
267
- required: true,
268
- valueHint: templateNames.join("|"),
269
- description: `Specify which template to generate`
40
+ skipConfig: {
41
+ type: "boolean",
42
+ description: "Skip nuxt.config.ts update"
270
43
  },
271
- name: {
272
- type: "positional",
273
- required: true,
274
- description: "Specify name of the generated file"
44
+ dev: {
45
+ type: "boolean",
46
+ description: "Install modules as dev dependencies"
275
47
  }
276
48
  },
277
- async run(ctx) {
49
+ async setup(ctx) {
278
50
  const cwd = resolve(ctx.args.cwd);
279
- const templateName = ctx.args.template;
280
- if (!templateNames.includes(templateName)) {
281
- logger.error(
282
- `Template ${templateName} is not supported. Possible values: ${Object.keys(
283
- templates
284
- ).join(", ")}`
51
+ const modules = ctx.args._.map((e) => e.trim()).filter(Boolean);
52
+ const projectPkg = await readPackageJSON(cwd).catch(() => ({}));
53
+ if (!projectPkg.dependencies?.nuxt && !projectPkg.devDependencies?.nuxt) {
54
+ logger.warn(`No \`nuxt\` dependency detected in \`${cwd}\`.`);
55
+ const shouldContinue = await logger.prompt(
56
+ `Do you want to continue anyway?`,
57
+ {
58
+ type: "confirm",
59
+ initial: false,
60
+ cancel: "default"
61
+ }
285
62
  );
286
- process.exit(1);
63
+ if (shouldContinue !== true) {
64
+ process.exit(1);
65
+ }
287
66
  }
288
- const ext = extname(ctx.args.name);
289
- const name = ext === ".vue" || ext === ".ts" ? ctx.args.name.replace(ext, "") : ctx.args.name;
290
- if (!name) {
291
- logger.error("name argument is missing!");
292
- process.exit(1);
67
+ const maybeResolvedModules = await Promise.all(modules.map((moduleName) => resolveModule(moduleName, cwd)));
68
+ const resolvedModules = maybeResolvedModules.filter((x) => x != null);
69
+ logger.info(`Resolved \`${resolvedModules.map((x) => x.pkgName).join("`, `")}\`, adding module${resolvedModules.length > 1 ? "s" : ""}...`);
70
+ await addModules(resolvedModules, { ...ctx.args, cwd }, projectPkg);
71
+ if (!ctx.args.skipInstall) {
72
+ const args = Object.entries(ctx.args).filter(([k]) => k in cwdArgs || k in logLevelArgs).map(([k, v]) => `--${k}=${v}`);
73
+ await runCommand("prepare", args);
293
74
  }
294
- const kit = await loadKit(cwd);
295
- const config = await kit.loadNuxtConfig({ cwd });
296
- const template = templates[templateName];
297
- const res = template({ name, args: ctx.args, nuxtOptions: config });
298
- if (!ctx.args.force && existsSync(res.path)) {
299
- logger.error(
300
- `File exists: ${res.path} . Use --force to override or use a different name.`
75
+ }
76
+ });
77
+ async function addModules(modules, { skipInstall, skipConfig, cwd, dev }, projectPkg) {
78
+ if (!skipInstall) {
79
+ const installedModules = [];
80
+ const notInstalledModules = [];
81
+ const dependencies = /* @__PURE__ */ new Set([
82
+ ...Object.keys(projectPkg.dependencies || {}),
83
+ ...Object.keys(projectPkg.devDependencies || {})
84
+ ]);
85
+ for (const module of modules) {
86
+ if (dependencies.has(module.pkgName)) {
87
+ installedModules.push(module);
88
+ } else {
89
+ notInstalledModules.push(module);
90
+ }
91
+ }
92
+ if (installedModules.length > 0) {
93
+ const installedModulesList = installedModules.map((module) => module.pkgName).join("`, `");
94
+ const are = installedModules.length > 1 ? "are" : "is";
95
+ logger.info(`\`${installedModulesList}\` ${are} already installed`);
96
+ }
97
+ if (notInstalledModules.length > 0) {
98
+ const isDev = Boolean(projectPkg.devDependencies?.nuxt) || dev;
99
+ const notInstalledModulesList = notInstalledModules.map((module) => module.pkg).join("`, `");
100
+ const dependency = notInstalledModules.length > 1 ? "dependencies" : "dependency";
101
+ const a = notInstalledModules.length > 1 ? "" : " a";
102
+ logger.info(`Installing \`${notInstalledModulesList}\` as${a}${isDev ? " development" : ""} ${dependency}`);
103
+ const res = await addDependency(notInstalledModules.map((module) => module.pkg), {
104
+ cwd,
105
+ dev: isDev,
106
+ installPeerDependencies: true
107
+ }).then(() => true).catch(
108
+ (error) => {
109
+ logger.error(error);
110
+ const failedModulesList = notInstalledModules.map((module) => colors.cyan(module.pkg)).join("`, `");
111
+ const s = notInstalledModules.length > 1 ? "s" : "";
112
+ return logger.prompt(`Install failed for \`${failedModulesList}\`. Do you want to continue adding the module${s} to ${colors.cyan("nuxt.config")}?`, {
113
+ type: "confirm",
114
+ initial: false,
115
+ cancel: "default"
116
+ });
117
+ }
301
118
  );
302
- process.exit(1);
119
+ if (res !== true) {
120
+ return;
121
+ }
303
122
  }
304
- const parentDir = dirname(res.path);
305
- if (!existsSync(parentDir)) {
306
- logger.info("Creating directory", parentDir);
307
- if (templateName === "page") {
308
- logger.info("This enables vue-router functionality!");
123
+ }
124
+ if (!skipConfig) {
125
+ await updateConfig({
126
+ cwd,
127
+ configFile: "nuxt.config",
128
+ async onCreate() {
129
+ logger.info(`Creating \`nuxt.config.ts\``);
130
+ return getDefaultNuxtConfig();
131
+ },
132
+ async onUpdate(config) {
133
+ if (!config.modules) {
134
+ config.modules = [];
135
+ }
136
+ for (const resolved of modules) {
137
+ if (config.modules.includes(resolved.pkgName)) {
138
+ logger.info(`\`${resolved.pkgName}\` is already in the \`modules\``);
139
+ continue;
140
+ }
141
+ logger.info(`Adding \`${resolved.pkgName}\` to the \`modules\``);
142
+ config.modules.push(resolved.pkgName);
143
+ }
309
144
  }
310
- await promises.mkdir(parentDir, { recursive: true });
145
+ }).catch((error) => {
146
+ logger.error(`Failed to update \`nuxt.config\`: ${error.message}`);
147
+ logger.error(`Please manually add \`${modules.map((module) => module.pkgName).join("`, `")}\` to the \`modules\` in \`nuxt.config.ts\``);
148
+ return null;
149
+ });
150
+ }
151
+ }
152
+ function getDefaultNuxtConfig() {
153
+ return `
154
+ // https://nuxt.com/docs/api/configuration/nuxt-config
155
+ export default defineNuxtConfig({
156
+ modules: []
157
+ })`;
158
+ }
159
+ const packageRegex = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?([a-z0-9-~][a-z0-9-._~]*)(@[^@]+)?$/;
160
+ async function resolveModule(moduleName, cwd) {
161
+ let pkgName = moduleName;
162
+ let pkgVersion;
163
+ const reMatch = moduleName.match(packageRegex);
164
+ if (reMatch) {
165
+ if (reMatch[3]) {
166
+ pkgName = `${reMatch[1] || ""}${reMatch[2] || ""}`;
167
+ pkgVersion = reMatch[3].slice(1);
311
168
  }
312
- await promises.writeFile(res.path, `${res.contents.trim()}
313
- `);
314
- logger.info(`\u{1FA84} Generated a new ${templateName} in ${res.path}`);
169
+ } else {
170
+ logger.error(`Invalid package name \`${pkgName}\`.`);
171
+ return false;
315
172
  }
316
- });
173
+ const modulesDB = await fetchModules().catch((err) => {
174
+ logger.warn(`Cannot search in the Nuxt Modules database: ${err}`);
175
+ return [];
176
+ });
177
+ const matchedModule = modulesDB.find(
178
+ (module) => module.name === moduleName || pkgVersion && module.name === pkgName || module.npm === pkgName || module.aliases?.includes(pkgName)
179
+ );
180
+ if (matchedModule?.npm) {
181
+ pkgName = matchedModule.npm;
182
+ }
183
+ if (matchedModule && matchedModule.compatibility.nuxt) {
184
+ const nuxtVersion = await getNuxtVersion(cwd);
185
+ if (!checkNuxtCompatibility(matchedModule, nuxtVersion)) {
186
+ logger.warn(
187
+ `The module \`${pkgName}\` is not compatible with Nuxt \`${nuxtVersion}\` (requires \`${matchedModule.compatibility.nuxt}\`)`
188
+ );
189
+ const shouldContinue = await logger.prompt(
190
+ "Do you want to continue installing incompatible version?",
191
+ {
192
+ type: "confirm",
193
+ initial: false,
194
+ cancel: "default"
195
+ }
196
+ );
197
+ if (!shouldContinue) {
198
+ return false;
199
+ }
200
+ }
201
+ const versionMap = matchedModule.compatibility.versionMap;
202
+ if (versionMap) {
203
+ for (const [_nuxtVersion, _moduleVersion] of Object.entries(versionMap)) {
204
+ if (satisfies(nuxtVersion, _nuxtVersion)) {
205
+ if (!pkgVersion) {
206
+ pkgVersion = _moduleVersion;
207
+ } else {
208
+ logger.warn(
209
+ `Recommended version of \`${pkgName}\` for Nuxt \`${nuxtVersion}\` is \`${_moduleVersion}\` but you have requested \`${pkgVersion}\``
210
+ );
211
+ pkgVersion = await logger.prompt("Choose a version:", {
212
+ type: "select",
213
+ options: [_moduleVersion, pkgVersion],
214
+ cancel: "undefined"
215
+ });
216
+ if (!pkgVersion) {
217
+ return false;
218
+ }
219
+ }
220
+ break;
221
+ }
222
+ }
223
+ }
224
+ }
225
+ let version = pkgVersion || "latest";
226
+ const pkgScope = pkgName.startsWith("@") ? pkgName.split("/")[0] : null;
227
+ const meta = await detectNpmRegistry(pkgScope);
228
+ const headers = {};
229
+ if (meta.authToken) {
230
+ headers.Authorization = `Bearer ${meta.authToken}`;
231
+ }
232
+ const pkgDetails = await $fetch(joinURL(meta.registry, `${pkgName}`), { headers });
233
+ if (pkgDetails["dist-tags"]?.[version]) {
234
+ version = pkgDetails["dist-tags"][version];
235
+ } else {
236
+ version = Object.keys(pkgDetails.versions)?.findLast((v) => satisfies(v, version)) || version;
237
+ }
238
+ const pkg = pkgDetails.versions[version];
239
+ const pkgDependencies = Object.assign(
240
+ pkg.dependencies || {},
241
+ pkg.devDependencies || {}
242
+ );
243
+ if (!pkgDependencies.nuxt && !pkgDependencies["nuxt-edge"] && !pkgDependencies["@nuxt/kit"]) {
244
+ logger.warn(`It seems that \`${pkgName}\` is not a Nuxt module.`);
245
+ const shouldContinue = await logger.prompt(
246
+ `Do you want to continue installing ${colors.cyan(pkgName)} anyway?`,
247
+ {
248
+ type: "confirm",
249
+ initial: false,
250
+ cancel: "default"
251
+ }
252
+ );
253
+ if (!shouldContinue) {
254
+ return false;
255
+ }
256
+ }
257
+ return {
258
+ nuxtModule: matchedModule,
259
+ pkg: `${pkgName}@${version}`,
260
+ pkgName,
261
+ pkgVersion: version
262
+ };
263
+ }
264
+ function getNpmrcPaths() {
265
+ const userNpmrcPath = join(homedir(), ".npmrc");
266
+ const cwdNpmrcPath = join(process.cwd(), ".npmrc");
267
+ return [cwdNpmrcPath, userNpmrcPath];
268
+ }
269
+ async function getAuthToken(registry) {
270
+ const paths = getNpmrcPaths();
271
+ const authTokenRegex = new RegExp(`^//${registry.replace(/^https?:\/\//, "").replace(/\/$/, "")}/:_authToken=(.+)$`, "m");
272
+ for (const npmrcPath of paths) {
273
+ let fd;
274
+ try {
275
+ fd = await fs.promises.open(npmrcPath, "r");
276
+ if (await fd.stat().then((r) => r.isFile())) {
277
+ const npmrcContent = await fd.readFile("utf-8");
278
+ const authTokenMatch = npmrcContent.match(authTokenRegex)?.[1];
279
+ if (authTokenMatch) {
280
+ return authTokenMatch.trim();
281
+ }
282
+ }
283
+ } catch {
284
+ } finally {
285
+ await fd?.close();
286
+ }
287
+ }
288
+ return null;
289
+ }
290
+ async function detectNpmRegistry(scope) {
291
+ const registry = await getRegistry(scope);
292
+ const authToken = await getAuthToken(registry);
293
+ return {
294
+ registry,
295
+ authToken
296
+ };
297
+ }
298
+ async function getRegistry(scope) {
299
+ if (process.env.COREPACK_NPM_REGISTRY) {
300
+ return process.env.COREPACK_NPM_REGISTRY;
301
+ }
302
+ const registry = await getRegistryFromFile(getNpmrcPaths(), scope);
303
+ if (registry) {
304
+ process.env.COREPACK_NPM_REGISTRY = registry;
305
+ }
306
+ return registry || "https://registry.npmjs.org";
307
+ }
308
+ async function getRegistryFromFile(paths, scope) {
309
+ for (const npmrcPath of paths) {
310
+ let fd;
311
+ try {
312
+ fd = await fs.promises.open(npmrcPath, "r");
313
+ if (await fd.stat().then((r) => r.isFile())) {
314
+ const npmrcContent = await fd.readFile("utf-8");
315
+ if (scope) {
316
+ const scopedRegex = new RegExp(`^${scope}:registry=(.+)$`, "m");
317
+ const scopedMatch = npmrcContent.match(scopedRegex)?.[1];
318
+ if (scopedMatch) {
319
+ return scopedMatch.trim();
320
+ }
321
+ }
322
+ const defaultRegex = /^\s*registry=(.+)$/m;
323
+ const defaultMatch = npmrcContent.match(defaultRegex)?.[1];
324
+ if (defaultMatch) {
325
+ return defaultMatch.trim();
326
+ }
327
+ }
328
+ } catch {
329
+ } finally {
330
+ await fd?.close();
331
+ }
332
+ }
333
+ return null;
334
+ }
317
335
 
318
336
  export { add as default };