@prismicio/manager 0.0.1 → 0.0.2-alpha.xru-fix-npx-install-warnings.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/lib/installDependencies.d.ts +6 -2
- package/dist/lib/installDependencies.js +33 -6
- package/dist/lib/installDependencies.js.map +1 -1
- package/dist/managers/project/ProjectManager.d.ts +4 -1
- package/dist/managers/project/ProjectManager.js +3 -1
- package/dist/managers/project/ProjectManager.js.map +1 -1
- package/package.json +4 -4
- package/src/lib/installDependencies.ts +46 -7
- package/src/managers/project/ProjectManager.ts +7 -1
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { type ResultPromise, type Options } from "execa";
|
|
2
1
|
import { PackageManager } from "../types.js";
|
|
3
2
|
type InstallDependenciesArgs = {
|
|
4
3
|
packageManager: PackageManager;
|
|
5
4
|
dependencies: Record<string, string>;
|
|
6
5
|
dev?: boolean;
|
|
7
|
-
|
|
6
|
+
cwd?: string;
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
};
|
|
9
|
+
type ResultPromise = Promise<void> & {
|
|
10
|
+
stdout: NodeJS.ReadableStream | null;
|
|
11
|
+
stderr: NodeJS.ReadableStream | null;
|
|
8
12
|
};
|
|
9
13
|
type InstallDependenciesReturnType = {
|
|
10
14
|
execaProcess: ResultPromise;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
1
2
|
import { parseNi } from "@antfu/ni";
|
|
2
|
-
import { execaCommand } from "execa";
|
|
3
3
|
const EXTRA_INSTALL_FLAGS = {
|
|
4
4
|
npm: ["--color=always", "--loglevel=info"],
|
|
5
5
|
pnpm: [],
|
|
@@ -30,13 +30,40 @@ const installDependencies = async (args) => {
|
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
...args.
|
|
33
|
+
const parsed = resolveCommand(parsedCommand);
|
|
34
|
+
let command;
|
|
35
|
+
if (typeof parsedCommand === "object" && parsedCommand !== null) {
|
|
36
|
+
command = [parsedCommand.command, ...parsedCommand.args].join(" ");
|
|
37
|
+
} else {
|
|
38
|
+
command = parsed;
|
|
39
|
+
}
|
|
40
|
+
const childProcess = spawn(command, {
|
|
41
|
+
cwd: args.cwd || process.cwd(),
|
|
42
|
+
env: { ...process.env, ...args.env },
|
|
43
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
44
|
+
shell: true
|
|
45
|
+
});
|
|
46
|
+
const promise = new Promise((resolve, reject) => {
|
|
47
|
+
childProcess.on("error", (error) => {
|
|
48
|
+
reject(error);
|
|
49
|
+
});
|
|
50
|
+
childProcess.on("exit", (code) => {
|
|
51
|
+
if (code === 0) {
|
|
52
|
+
resolve();
|
|
53
|
+
} else {
|
|
54
|
+
const error = new Error(`Command failed with exit code ${code}`);
|
|
55
|
+
Object.assign(error, {
|
|
56
|
+
shortMessage: `Command failed: ${parsed}`,
|
|
57
|
+
stderr: ""
|
|
58
|
+
});
|
|
59
|
+
reject(error);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
37
62
|
});
|
|
63
|
+
promise.stdout = childProcess.stdout;
|
|
64
|
+
promise.stderr = childProcess.stderr;
|
|
38
65
|
return {
|
|
39
|
-
execaProcess
|
|
66
|
+
execaProcess: promise
|
|
40
67
|
};
|
|
41
68
|
};
|
|
42
69
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installDependencies.js","sources":["../../../src/lib/installDependencies.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"installDependencies.js","sources":["../../../src/lib/installDependencies.ts"],"sourcesContent":["import { spawn } from \"node:child_process\";\n\nimport { parseNi } from \"@antfu/ni\";\n\nimport { PackageManager } from \"../types\";\n\nconst EXTRA_INSTALL_FLAGS: Record<PackageManager, string[]> = {\n\tnpm: [\"--color=always\", \"--loglevel=info\"],\n\tpnpm: [],\n\tyarn: [],\n\t\"yarn@berry\": [],\n\t\"pnpm@6\": [],\n\tbun: [],\n\tdeno: [],\n};\n\ntype InstallDependenciesArgs = {\n\tpackageManager: PackageManager;\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\tcwd?: string;\n\tenv?: NodeJS.ProcessEnv;\n};\n\ntype ResultPromise = Promise<void> & {\n\tstdout: NodeJS.ReadableStream | null;\n\tstderr: NodeJS.ReadableStream | null;\n};\n\ntype InstallDependenciesReturnType = {\n\texecaProcess: ResultPromise;\n};\n\nconst resolveCommand = (\n\tcommand: string | { command: string; args: string[] },\n): string => {\n\tif (typeof command === \"string\") {\n\t\treturn command;\n\t}\n\n\treturn [command.command, ...command.args].join(\" \");\n};\n\nexport const installDependencies = async (\n\targs: InstallDependenciesArgs,\n): Promise<InstallDependenciesReturnType> => {\n\tconst commandArgs = Object.entries(args.dependencies).map(\n\t\t([pkg, range]) => `${pkg}@${range}`,\n\t);\n\n\tif (commandArgs.length && args.dev) {\n\t\tcommandArgs.unshift(\"-D\");\n\t}\n\n\tcommandArgs.push(...EXTRA_INSTALL_FLAGS[args.packageManager]);\n\n\tconst parsedCommand = await parseNi(args.packageManager, commandArgs);\n\n\tif (!parsedCommand) {\n\t\tthrow new Error(\n\t\t\t\"Failed to begin dependency installation (could not parse command)\",\n\t\t\t{\n\t\t\t\tcause: {\n\t\t\t\t\tpackageManager: args.packageManager,\n\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t}\n\n\tconst parsed = resolveCommand(parsedCommand);\n\n\tlet command: string;\n\n\tif (typeof parsedCommand === \"object\" && parsedCommand !== null) {\n\t\tcommand = [parsedCommand.command, ...parsedCommand.args].join(\" \");\n\t} else {\n\t\tcommand = parsed;\n\t}\n\n\tconst childProcess = spawn(command, {\n\t\tcwd: args.cwd || process.cwd(),\n\t\tenv: { ...process.env, ...args.env },\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\tshell: true,\n\t});\n\n\tconst promise = new Promise<void>((resolve, reject) => {\n\t\tchildProcess.on(\"error\", (error) => {\n\t\t\treject(error);\n\t\t});\n\n\t\tchildProcess.on(\"exit\", (code) => {\n\t\t\tif (code === 0) {\n\t\t\t\tresolve();\n\t\t\t} else {\n\t\t\t\tconst error = new Error(`Command failed with exit code ${code}`);\n\t\t\t\tObject.assign(error, {\n\t\t\t\t\tshortMessage: `Command failed: ${parsed}`,\n\t\t\t\t\tstderr: \"\",\n\t\t\t\t});\n\t\t\t\treject(error);\n\t\t\t}\n\t\t});\n\t}) as ResultPromise;\n\n\tpromise.stdout = childProcess.stdout;\n\tpromise.stderr = childProcess.stderr;\n\n\treturn {\n\t\texecaProcess: promise,\n\t};\n};\n"],"names":[],"mappings":";;AAMA,MAAM,sBAAwD;AAAA,EAC7D,KAAK,CAAC,kBAAkB,iBAAiB;AAAA,EACzC,MAAM,CAAA;AAAA,EACN,MAAM,CAAA;AAAA,EACN,cAAc,CAAA;AAAA,EACd,UAAU,CAAA;AAAA,EACV,KAAK,CAAA;AAAA,EACL,MAAM,CAAA;;AAoBP,MAAM,iBAAiB,CACtB,YACW;AACX,MAAI,OAAO,YAAY,UAAU;AAChC,WAAO;AAAA,EACR;AAEA,SAAO,CAAC,QAAQ,SAAS,GAAG,QAAQ,IAAI,EAAE,KAAK,GAAG;AACnD;AAEO,MAAM,sBAAsB,OAClC,SAC2C;AAC3C,QAAM,cAAc,OAAO,QAAQ,KAAK,YAAY,EAAE,IACrD,CAAC,CAAC,KAAK,KAAK,MAAM,GAAG,GAAG,IAAI,KAAK,EAAE;AAGpC,MAAI,YAAY,UAAU,KAAK,KAAK;AACnC,gBAAY,QAAQ,IAAI;AAAA,EACzB;AAEA,cAAY,KAAK,GAAG,oBAAoB,KAAK,cAAc,CAAC;AAE5D,QAAM,gBAAgB,MAAM,QAAQ,KAAK,gBAAgB,WAAW;AAEpE,MAAI,CAAC,eAAe;AACnB,UAAM,IAAI,MACT,qEACA;AAAA,MACC,OAAO;AAAA,QACN,gBAAgB,KAAK;AAAA,QACrB,cAAc,KAAK;AAAA,MAAA;AAAA,IACnB,CACD;AAAA,EAEH;AAEA,QAAM,SAAS,eAAe,aAAa;AAE3C,MAAI;AAEJ,MAAI,OAAO,kBAAkB,YAAY,kBAAkB,MAAM;AAChE,cAAU,CAAC,cAAc,SAAS,GAAG,cAAc,IAAI,EAAE,KAAK,GAAG;AAAA,EAClE,OAAO;AACN,cAAU;AAAA,EACX;AAEA,QAAM,eAAe,MAAM,SAAS;AAAA,IACnC,KAAK,KAAK,OAAO,QAAQ,IAAA;AAAA,IACzB,KAAK,EAAE,GAAG,QAAQ,KAAK,GAAG,KAAK,IAAA;AAAA,IAC/B,OAAO,CAAC,UAAU,QAAQ,MAAM;AAAA,IAChC,OAAO;AAAA,EAAA,CACP;AAED,QAAM,UAAU,IAAI,QAAc,CAAC,SAAS,WAAU;AACrD,iBAAa,GAAG,SAAS,CAAC,UAAS;AAClC,aAAO,KAAK;AAAA,IACb,CAAC;AAED,iBAAa,GAAG,QAAQ,CAAC,SAAQ;AAChC,UAAI,SAAS,GAAG;AACf,gBAAA;AAAA,MACD,OAAO;AACN,cAAM,QAAQ,IAAI,MAAM,iCAAiC,IAAI,EAAE;AAC/D,eAAO,OAAO,OAAO;AAAA,UACpB,cAAc,mBAAmB,MAAM;AAAA,UACvC,QAAQ;AAAA,QAAA,CACR;AACD,eAAO,KAAK;AAAA,MACb;AAAA,IACD,CAAC;AAAA,EACF,CAAC;AAED,UAAQ,SAAS,aAAa;AAC9B,UAAQ,SAAS,aAAa;AAE9B,SAAO;AAAA,IACN,cAAc;AAAA,EAAA;AAEhB;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type ResultPromise } from "execa";
|
|
2
1
|
import { PackageManager, PrismicConfig } from "../../types.js";
|
|
3
2
|
import { BaseManager } from "../BaseManager.js";
|
|
4
3
|
type ProjectManagerGetPrismicConfigPathArgs = {
|
|
@@ -26,6 +25,10 @@ type ProjectManagerInstallDependenciesArgs = {
|
|
|
26
25
|
packageManager?: PackageManager;
|
|
27
26
|
log?: (message: string) => void;
|
|
28
27
|
};
|
|
28
|
+
type ResultPromise = Promise<void> & {
|
|
29
|
+
stdout: NodeJS.ReadableStream | null;
|
|
30
|
+
stderr: NodeJS.ReadableStream | null;
|
|
31
|
+
};
|
|
29
32
|
type ProjectManagerInstallDependenciesReturnType = {
|
|
30
33
|
execaProcess: ResultPromise;
|
|
31
34
|
};
|
|
@@ -180,10 +180,12 @@ Error Message: ${error2.message}`);
|
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
try {
|
|
183
|
+
const projectRoot = await this.getRoot();
|
|
183
184
|
const { execaProcess } = await installDependencies({
|
|
184
185
|
packageManager,
|
|
185
186
|
dependencies: args.dependencies,
|
|
186
|
-
dev: args.dev
|
|
187
|
+
dev: args.dev,
|
|
188
|
+
cwd: projectRoot
|
|
187
189
|
});
|
|
188
190
|
if (process.stdout.isTTY || process.env.NODE_ENV === "test") {
|
|
189
191
|
execaProcess.stdout?.on("data", wrappedLogger);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectManager.js","sources":["../../../../src/managers/project/ProjectManager.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { detect as niDetect } from \"@antfu/ni\";\nimport { type ResultPromise } from \"execa\";\n\nimport { PRISMIC_CONFIG_FILENAME } from \"../../constants/PRISMIC_CONFIG_FILENAME\";\nimport { SLICEMACHINE_CONFIG_FILENAME } from \"../../constants/SLICEMACHINE_CONFIG_FILENAME\";\nimport { TS_CONFIG_FILENAME } from \"../../constants/TS_CONFIG_FILENAME\";\nimport { PrismicError, InternalError } from \"../../errors\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodePrismicConfig } from \"../../lib/decodePrismicConfig\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\nimport { PackageManager, PrismicConfig } from \"../../types\";\nimport { BaseManager } from \"../BaseManager\";\n\ntype ProjectManagerGetPrismicConfigPathArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerGetRootArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerCheckIsTypeScriptArgs = {\n\trootOverride?: string;\n};\n\ntype ProjectManagerWritePrismicConfigArgs = {\n\tconfig: PrismicConfig;\n\tpath?: string;\n};\n\ntype ProjectManagerInitProjectArgs = {\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerDetectPackageManager = {\n\troot?: string;\n};\n\ntype ProjectManagerInstallDependenciesArgs = {\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\tpackageManager?: PackageManager;\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerInstallDependenciesReturnType = {\n\texecaProcess: ResultPromise;\n};\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedPrismicConfigPath: string | undefined;\n\tprivate _cachedPrismicConfig: PrismicConfig | undefined;\n\n\tasync getPrismicConfigPath(\n\t\targs?: ProjectManagerGetPrismicConfigPathArgs,\n\t): Promise<string> {\n\t\tif (this._cachedPrismicConfigPath && !args?.ignoreCache) {\n\t\t\treturn this._cachedPrismicConfigPath;\n\t\t}\n\n\t\ttry {\n\t\t\tthis._cachedPrismicConfigPath = await locateFileUpward(\n\t\t\t\tPRISMIC_CONFIG_FILENAME,\n\t\t\t\t{ startDir: this.cwd },\n\t\t\t);\n\t\t} catch {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find a ${PRISMIC_CONFIG_FILENAME} file. Please create a config file at the root of your project.`,\n\t\t\t);\n\t\t}\n\n\t\treturn this._cachedPrismicConfigPath;\n\t}\n\n\tasync getRoot(args?: ProjectManagerGetRootArgs): Promise<string> {\n\t\tif (this._cachedRoot && !args?.ignoreCache) {\n\t\t\treturn this._cachedRoot;\n\t\t}\n\n\t\tconst prismicConfigFilePath = await this.getPrismicConfigPath({\n\t\t\tignoreCache: args?.ignoreCache,\n\t\t});\n\n\t\tthis._cachedRoot = path.dirname(prismicConfigFilePath);\n\n\t\treturn this._cachedRoot;\n\t}\n\n\tasync suggestRoot(): Promise<string> {\n\t\tconst suggestedRootPackageJSON = await locateFileUpward(\"package.json\", {\n\t\t\tstartDir: this.cwd,\n\t\t});\n\n\t\treturn path.dirname(suggestedRootPackageJSON);\n\t}\n\n\tasync suggestPrismicConfigPath(): Promise<string> {\n\t\tconst suggestedRoot = await this.suggestRoot();\n\n\t\treturn path.resolve(suggestedRoot, PRISMIC_CONFIG_FILENAME);\n\t}\n\n\tasync checkIsTypeScript(\n\t\targs?: ProjectManagerCheckIsTypeScriptArgs,\n\t): Promise<boolean> {\n\t\tconst root = args?.rootOverride || (await this.getRoot());\n\t\tconst rootTSConfigPath = path.resolve(root, TS_CONFIG_FILENAME);\n\n\t\t// We just care if the file exists, we don't need access to it\n\t\treturn existsSync(rootTSConfigPath);\n\t}\n\n\tasync getPrismicConfig(): Promise<PrismicConfig> {\n\t\tif (this._cachedPrismicConfig) {\n\t\t\treturn this._cachedPrismicConfig;\n\t\t} else {\n\t\t\treturn await this.loadPrismicConfig();\n\t\t}\n\t}\n\n\tasync writePrismicConfig(\n\t\targs: ProjectManagerWritePrismicConfigArgs,\n\t): Promise<void> {\n\t\tconst configFilePath = args.path || (await this.getPrismicConfigPath());\n\n\t\tconst config = await format(\n\t\t\tJSON.stringify(args.config, null, 2),\n\t\t\tconfigFilePath,\n\t\t);\n\n\t\tawait fs.writeFile(configFilePath, config, \"utf-8\");\n\n\t\t// Clear config cache\n\t\tdelete this._cachedPrismicConfig;\n\t}\n\n\tasync loadPrismicConfig(): Promise<PrismicConfig> {\n\t\tconst configFilePath = await this.getPrismicConfigPath();\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\tthrow new PrismicError(\n\t\t\t\t\t`Could not parse config file at ${configFilePath}.\\n\\nError Message: ${error.message}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Noop, more specific error is thrown after\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t\"No Prismic config found, please initialize your project with Prismic first.\",\n\t\t\t);\n\t\t}\n\n\t\tconst { value: prismicConfig, error } = decodePrismicConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\tthrow new Error(`Invalid Prismic config. ${error.errors.join(\", \")}`, {\n\t\t\t\tcause: { rawConfig },\n\t\t\t});\n\t\t}\n\n\t\tthis._cachedPrismicConfig = prismicConfig;\n\n\t\treturn prismicConfig;\n\t}\n\n\tasync getRepositoryName(): Promise<string> {\n\t\tconst prismicConfig = await this.getPrismicConfig();\n\n\t\treturn prismicConfig.repositoryName;\n\t}\n\n\tasync checkLegacyConfigExists(): Promise<boolean> {\n\t\ttry {\n\t\t\tawait locateFileUpward(SLICEMACHINE_CONFIG_FILENAME, {\n\t\t\t\tstartDir: this.cwd,\n\t\t\t});\n\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync migrateLegacyConfig(): Promise<void> {\n\t\tconst suggestedRoot = await this.suggestRoot();\n\t\tconst legacyConfigPath = path.resolve(\n\t\t\tsuggestedRoot,\n\t\t\tSLICEMACHINE_CONFIG_FILENAME,\n\t\t);\n\t\tconst newConfigPath = path.resolve(suggestedRoot, PRISMIC_CONFIG_FILENAME);\n\n\t\t// Check if legacy config exists\n\t\ttry {\n\t\t\tawait fs.access(legacyConfigPath);\n\t\t} catch {\n\t\t\tthrow new Error(\n\t\t\t\t`Legacy config file ${SLICEMACHINE_CONFIG_FILENAME} not found.`,\n\t\t\t);\n\t\t}\n\n\t\t// Check if new config already exists\n\t\ttry {\n\t\t\tawait fs.access(newConfigPath);\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot migrate: ${PRISMIC_CONFIG_FILENAME} already exists.`,\n\t\t\t);\n\t\t} catch {\n\t\t\t// File doesn't exist, which is what we want\n\t\t}\n\n\t\tconst legacyConfigContent = await fs.readFile(legacyConfigPath, \"utf8\");\n\n\t\t// Parse and validate the config\n\t\tlet rawConfig: unknown;\n\t\ttry {\n\t\t\trawConfig = JSON.parse(legacyConfigContent);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\tthrow new PrismicError(\n\t\t\t\t\t`Could not parse legacy config file at ${legacyConfigPath}.\\n\\nError Message: ${error.message}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst { value: prismicConfig, error } = decodePrismicConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid legacy Prismic config. ${error.errors.join(\", \")}`,\n\t\t\t\t{\n\t\t\t\t\tcause: { rawConfig },\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Format and write the new config\n\t\tconst formattedConfig = await format(\n\t\t\tJSON.stringify(prismicConfig, null, 2),\n\t\t\tnewConfigPath,\n\t\t);\n\n\t\tawait fs.writeFile(newConfigPath, formattedConfig, \"utf-8\");\n\n\t\t// Remove legacy config file\n\t\tawait fs.unlink(legacyConfigPath);\n\n\t\t// Clear caches\n\t\tdelete this._cachedPrismicConfig;\n\t\tdelete this._cachedPrismicConfigPath;\n\t\tdelete this._cachedRoot;\n\t}\n\n\tasync initProject(args?: ProjectManagerInitProjectArgs): Promise<void> {\n\t\tassertPluginsInitialized(this.pluginSystemRunner);\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args?.log || console.log.bind(this);\n\n\t\tconst { errors } = await this.pluginSystemRunner.callHook(\"project:init\", {\n\t\t\tlog,\n\t\t\tinstallDependencies: async (args) => {\n\t\t\t\tconst { execaProcess } = await this.installDependencies({\n\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t\tdev: args.dev,\n\t\t\t\t\tlog,\n\t\t\t\t});\n\n\t\t\t\tawait execaProcess;\n\t\t\t},\n\t\t});\n\n\t\tif (errors.length > 0) {\n\t\t\tthrow new PrismicError(\n\t\t\t\t`Failed to initialize project: ${errors.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync detectPackageManager(\n\t\targs?: ProjectManagerDetectPackageManager,\n\t): Promise<PackageManager> {\n\t\tconst projectRoot = args?.root || (await this.getRoot());\n\n\t\tconst packageManager = await niDetect({\n\t\t\tautoInstall: true,\n\t\t\tcwd: projectRoot,\n\t\t});\n\n\t\treturn packageManager || \"npm\";\n\t}\n\n\tasync installDependencies(\n\t\targs: ProjectManagerInstallDependenciesArgs,\n\t): Promise<ProjectManagerInstallDependenciesReturnType> {\n\t\tconst packageManager =\n\t\t\targs.packageManager || (await this.detectPackageManager());\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args.log || console.log.bind(this);\n\n\t\tconst wrappedLogger = (data: Buffer | string | null) => {\n\t\t\tif (data instanceof Buffer) {\n\t\t\t\tlog(data.toString());\n\t\t\t} else if (typeof data === \"string\") {\n\t\t\t\tlog(data);\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tconst { execaProcess } = await installDependencies({\n\t\t\t\tpackageManager,\n\t\t\t\tdependencies: args.dependencies,\n\t\t\t\tdev: args.dev,\n\t\t\t});\n\n\t\t\t// Don't clutter console with logs when process is non TTY (CI, etc.)\n\t\t\tif (process.stdout.isTTY || process.env.NODE_ENV === \"test\") {\n\t\t\t\texecaProcess.stdout?.on(\"data\", wrappedLogger);\n\t\t\t}\n\t\t\texecaProcess.stderr?.on(\"data\", wrappedLogger);\n\n\t\t\treturn {\n\t\t\t\texecaProcess,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t\"shortMessage\" in error &&\n\t\t\t\t\"stderr\" in error\n\t\t\t) {\n\t\t\t\tthrow new InternalError(\"Package installation failed\", {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"],"names":["error","args","niDetect"],"mappings":";;;;;;;;;;;;;;AAuDM,MAAO,uBAAuB,YAAW;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EAER,MAAM,qBACL,MAA6C;AAE7C,QAAI,KAAK,4BAA4B,CAAC,MAAM,aAAa;AACxD,aAAO,KAAK;AAAA,IACb;AAEA,QAAI;AACH,WAAK,2BAA2B,MAAM,iBACrC,yBACA,EAAE,UAAU,KAAK,KAAK;AAAA,IAExB,QAAQ;AACP,YAAM,IAAI,MACT,oBAAoB,uBAAuB,iEAAiE;AAAA,IAE9G;AAEA,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,MAAM,QAAQ,MAAgC;AAC7C,QAAI,KAAK,eAAe,CAAC,MAAM,aAAa;AAC3C,aAAO,KAAK;AAAA,IACb;AAEA,UAAM,wBAAwB,MAAM,KAAK,qBAAqB;AAAA,MAC7D,aAAa,MAAM;AAAA,IAAA,CACnB;AAED,SAAK,cAAc,KAAK,QAAQ,qBAAqB;AAErD,WAAO,KAAK;AAAA,EACb;AAAA,EAEA,MAAM,cAAW;AAChB,UAAM,2BAA2B,MAAM,iBAAiB,gBAAgB;AAAA,MACvE,UAAU,KAAK;AAAA,IAAA,CACf;AAED,WAAO,KAAK,QAAQ,wBAAwB;AAAA,EAC7C;AAAA,EAEA,MAAM,2BAAwB;AAC7B,UAAM,gBAAgB,MAAM,KAAK,YAAA;AAEjC,WAAO,KAAK,QAAQ,eAAe,uBAAuB;AAAA,EAC3D;AAAA,EAEA,MAAM,kBACL,MAA0C;AAE1C,UAAM,OAAO,MAAM,gBAAiB,MAAM,KAAK,QAAA;AAC/C,UAAM,mBAAmB,KAAK,QAAQ,MAAM,kBAAkB;AAG9D,WAAO,WAAW,gBAAgB;AAAA,EACnC;A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AAA,QACN;AAAA,MAAA;AAAA,IAEF,SAAS,OAAO;AACf,UACC,iBAAiB,SACjB,kBAAkB,SAClB,YAAY,OACX;AACD,cAAM,IAAI,cAAc,+BAA+B;AAAA,UACtD,OAAO;AAAA,QAAA,CACP;AAAA,MACF;AAEA,YAAM;AAAA,IACP;AAAA,EACD;AACA;"}
|
|
1
|
+
{"version":3,"file":"ProjectManager.js","sources":["../../../../src/managers/project/ProjectManager.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { detect as niDetect } from \"@antfu/ni\";\n\nimport { PRISMIC_CONFIG_FILENAME } from \"../../constants/PRISMIC_CONFIG_FILENAME\";\nimport { SLICEMACHINE_CONFIG_FILENAME } from \"../../constants/SLICEMACHINE_CONFIG_FILENAME\";\nimport { TS_CONFIG_FILENAME } from \"../../constants/TS_CONFIG_FILENAME\";\nimport { PrismicError, InternalError } from \"../../errors\";\nimport { assertPluginsInitialized } from \"../../lib/assertPluginsInitialized\";\nimport { decodePrismicConfig } from \"../../lib/decodePrismicConfig\";\nimport { format } from \"../../lib/format\";\nimport { installDependencies } from \"../../lib/installDependencies\";\nimport { locateFileUpward } from \"../../lib/locateFileUpward\";\nimport { PackageManager, PrismicConfig } from \"../../types\";\nimport { BaseManager } from \"../BaseManager\";\n\ntype ProjectManagerGetPrismicConfigPathArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerGetRootArgs = {\n\tignoreCache?: boolean;\n};\n\ntype ProjectManagerCheckIsTypeScriptArgs = {\n\trootOverride?: string;\n};\n\ntype ProjectManagerWritePrismicConfigArgs = {\n\tconfig: PrismicConfig;\n\tpath?: string;\n};\n\ntype ProjectManagerInitProjectArgs = {\n\tlog?: (message: string) => void;\n};\n\ntype ProjectManagerDetectPackageManager = {\n\troot?: string;\n};\n\ntype ProjectManagerInstallDependenciesArgs = {\n\tdependencies: Record<string, string>;\n\tdev?: boolean;\n\tpackageManager?: PackageManager;\n\tlog?: (message: string) => void;\n};\n\ntype ResultPromise = Promise<void> & {\n\tstdout: NodeJS.ReadableStream | null;\n\tstderr: NodeJS.ReadableStream | null;\n};\n\ntype ProjectManagerInstallDependenciesReturnType = {\n\texecaProcess: ResultPromise;\n};\n\nexport class ProjectManager extends BaseManager {\n\tprivate _cachedRoot: string | undefined;\n\tprivate _cachedPrismicConfigPath: string | undefined;\n\tprivate _cachedPrismicConfig: PrismicConfig | undefined;\n\n\tasync getPrismicConfigPath(\n\t\targs?: ProjectManagerGetPrismicConfigPathArgs,\n\t): Promise<string> {\n\t\tif (this._cachedPrismicConfigPath && !args?.ignoreCache) {\n\t\t\treturn this._cachedPrismicConfigPath;\n\t\t}\n\n\t\ttry {\n\t\t\tthis._cachedPrismicConfigPath = await locateFileUpward(\n\t\t\t\tPRISMIC_CONFIG_FILENAME,\n\t\t\t\t{ startDir: this.cwd },\n\t\t\t);\n\t\t} catch {\n\t\t\tthrow new Error(\n\t\t\t\t`Could not find a ${PRISMIC_CONFIG_FILENAME} file. Please create a config file at the root of your project.`,\n\t\t\t);\n\t\t}\n\n\t\treturn this._cachedPrismicConfigPath;\n\t}\n\n\tasync getRoot(args?: ProjectManagerGetRootArgs): Promise<string> {\n\t\tif (this._cachedRoot && !args?.ignoreCache) {\n\t\t\treturn this._cachedRoot;\n\t\t}\n\n\t\tconst prismicConfigFilePath = await this.getPrismicConfigPath({\n\t\t\tignoreCache: args?.ignoreCache,\n\t\t});\n\n\t\tthis._cachedRoot = path.dirname(prismicConfigFilePath);\n\n\t\treturn this._cachedRoot;\n\t}\n\n\tasync suggestRoot(): Promise<string> {\n\t\tconst suggestedRootPackageJSON = await locateFileUpward(\"package.json\", {\n\t\t\tstartDir: this.cwd,\n\t\t});\n\n\t\treturn path.dirname(suggestedRootPackageJSON);\n\t}\n\n\tasync suggestPrismicConfigPath(): Promise<string> {\n\t\tconst suggestedRoot = await this.suggestRoot();\n\n\t\treturn path.resolve(suggestedRoot, PRISMIC_CONFIG_FILENAME);\n\t}\n\n\tasync checkIsTypeScript(\n\t\targs?: ProjectManagerCheckIsTypeScriptArgs,\n\t): Promise<boolean> {\n\t\tconst root = args?.rootOverride || (await this.getRoot());\n\t\tconst rootTSConfigPath = path.resolve(root, TS_CONFIG_FILENAME);\n\n\t\t// We just care if the file exists, we don't need access to it\n\t\treturn existsSync(rootTSConfigPath);\n\t}\n\n\tasync getPrismicConfig(): Promise<PrismicConfig> {\n\t\tif (this._cachedPrismicConfig) {\n\t\t\treturn this._cachedPrismicConfig;\n\t\t} else {\n\t\t\treturn await this.loadPrismicConfig();\n\t\t}\n\t}\n\n\tasync writePrismicConfig(\n\t\targs: ProjectManagerWritePrismicConfigArgs,\n\t): Promise<void> {\n\t\tconst configFilePath = args.path || (await this.getPrismicConfigPath());\n\n\t\tconst config = await format(\n\t\t\tJSON.stringify(args.config, null, 2),\n\t\t\tconfigFilePath,\n\t\t);\n\n\t\tawait fs.writeFile(configFilePath, config, \"utf-8\");\n\n\t\t// Clear config cache\n\t\tdelete this._cachedPrismicConfig;\n\t}\n\n\tasync loadPrismicConfig(): Promise<PrismicConfig> {\n\t\tconst configFilePath = await this.getPrismicConfigPath();\n\n\t\tlet rawConfig: unknown | undefined;\n\t\ttry {\n\t\t\tconst contents = await fs.readFile(configFilePath, \"utf8\");\n\t\t\trawConfig = JSON.parse(contents);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\tthrow new PrismicError(\n\t\t\t\t\t`Could not parse config file at ${configFilePath}.\\n\\nError Message: ${error.message}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Noop, more specific error is thrown after\n\t\t}\n\n\t\tif (!rawConfig) {\n\t\t\tthrow new Error(\n\t\t\t\t\"No Prismic config found, please initialize your project with Prismic first.\",\n\t\t\t);\n\t\t}\n\n\t\tconst { value: prismicConfig, error } = decodePrismicConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\tthrow new Error(`Invalid Prismic config. ${error.errors.join(\", \")}`, {\n\t\t\t\tcause: { rawConfig },\n\t\t\t});\n\t\t}\n\n\t\tthis._cachedPrismicConfig = prismicConfig;\n\n\t\treturn prismicConfig;\n\t}\n\n\tasync getRepositoryName(): Promise<string> {\n\t\tconst prismicConfig = await this.getPrismicConfig();\n\n\t\treturn prismicConfig.repositoryName;\n\t}\n\n\tasync checkLegacyConfigExists(): Promise<boolean> {\n\t\ttry {\n\t\t\tawait locateFileUpward(SLICEMACHINE_CONFIG_FILENAME, {\n\t\t\t\tstartDir: this.cwd,\n\t\t\t});\n\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tasync migrateLegacyConfig(): Promise<void> {\n\t\tconst suggestedRoot = await this.suggestRoot();\n\t\tconst legacyConfigPath = path.resolve(\n\t\t\tsuggestedRoot,\n\t\t\tSLICEMACHINE_CONFIG_FILENAME,\n\t\t);\n\t\tconst newConfigPath = path.resolve(suggestedRoot, PRISMIC_CONFIG_FILENAME);\n\n\t\t// Check if legacy config exists\n\t\ttry {\n\t\t\tawait fs.access(legacyConfigPath);\n\t\t} catch {\n\t\t\tthrow new Error(\n\t\t\t\t`Legacy config file ${SLICEMACHINE_CONFIG_FILENAME} not found.`,\n\t\t\t);\n\t\t}\n\n\t\t// Check if new config already exists\n\t\ttry {\n\t\t\tawait fs.access(newConfigPath);\n\t\t\tthrow new Error(\n\t\t\t\t`Cannot migrate: ${PRISMIC_CONFIG_FILENAME} already exists.`,\n\t\t\t);\n\t\t} catch {\n\t\t\t// File doesn't exist, which is what we want\n\t\t}\n\n\t\tconst legacyConfigContent = await fs.readFile(legacyConfigPath, \"utf8\");\n\n\t\t// Parse and validate the config\n\t\tlet rawConfig: unknown;\n\t\ttry {\n\t\t\trawConfig = JSON.parse(legacyConfigContent);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SyntaxError) {\n\t\t\t\tthrow new PrismicError(\n\t\t\t\t\t`Could not parse legacy config file at ${legacyConfigPath}.\\n\\nError Message: ${error.message}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst { value: prismicConfig, error } = decodePrismicConfig(rawConfig);\n\n\t\tif (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid legacy Prismic config. ${error.errors.join(\", \")}`,\n\t\t\t\t{\n\t\t\t\t\tcause: { rawConfig },\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Format and write the new config\n\t\tconst formattedConfig = await format(\n\t\t\tJSON.stringify(prismicConfig, null, 2),\n\t\t\tnewConfigPath,\n\t\t);\n\n\t\tawait fs.writeFile(newConfigPath, formattedConfig, \"utf-8\");\n\n\t\t// Remove legacy config file\n\t\tawait fs.unlink(legacyConfigPath);\n\n\t\t// Clear caches\n\t\tdelete this._cachedPrismicConfig;\n\t\tdelete this._cachedPrismicConfigPath;\n\t\tdelete this._cachedRoot;\n\t}\n\n\tasync initProject(args?: ProjectManagerInitProjectArgs): Promise<void> {\n\t\tassertPluginsInitialized(this.pluginSystemRunner);\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args?.log || console.log.bind(this);\n\n\t\tconst { errors } = await this.pluginSystemRunner.callHook(\"project:init\", {\n\t\t\tlog,\n\t\t\tinstallDependencies: async (args) => {\n\t\t\t\tconst { execaProcess } = await this.installDependencies({\n\t\t\t\t\tdependencies: args.dependencies,\n\t\t\t\t\tdev: args.dev,\n\t\t\t\t\tlog,\n\t\t\t\t});\n\n\t\t\t\tawait execaProcess;\n\t\t\t},\n\t\t});\n\n\t\tif (errors.length > 0) {\n\t\t\tthrow new PrismicError(\n\t\t\t\t`Failed to initialize project: ${errors.join(\", \")}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync detectPackageManager(\n\t\targs?: ProjectManagerDetectPackageManager,\n\t): Promise<PackageManager> {\n\t\tconst projectRoot = args?.root || (await this.getRoot());\n\n\t\tconst packageManager = await niDetect({\n\t\t\tautoInstall: true,\n\t\t\tcwd: projectRoot,\n\t\t});\n\n\t\treturn packageManager || \"npm\";\n\t}\n\n\tasync installDependencies(\n\t\targs: ProjectManagerInstallDependenciesArgs,\n\t): Promise<ProjectManagerInstallDependenciesReturnType> {\n\t\tconst packageManager =\n\t\t\targs.packageManager || (await this.detectPackageManager());\n\n\t\t// eslint-disable-next-line no-console\n\t\tconst log = args.log || console.log.bind(this);\n\n\t\tconst wrappedLogger = (data: Buffer | string | null) => {\n\t\t\tif (data instanceof Buffer) {\n\t\t\t\tlog(data.toString());\n\t\t\t} else if (typeof data === \"string\") {\n\t\t\t\tlog(data);\n\t\t\t}\n\t\t};\n\n\t\ttry {\n\t\t\tconst projectRoot = await this.getRoot();\n\t\t\tconst { execaProcess } = await installDependencies({\n\t\t\t\tpackageManager,\n\t\t\t\tdependencies: args.dependencies,\n\t\t\t\tdev: args.dev,\n\t\t\t\tcwd: projectRoot,\n\t\t\t});\n\n\t\t\t// Don't clutter console with logs when process is non TTY (CI, etc.)\n\t\t\tif (process.stdout.isTTY || process.env.NODE_ENV === \"test\") {\n\t\t\t\texecaProcess.stdout?.on(\"data\", wrappedLogger);\n\t\t\t}\n\t\t\texecaProcess.stderr?.on(\"data\", wrappedLogger);\n\n\t\t\treturn {\n\t\t\t\texecaProcess,\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t\"shortMessage\" in error &&\n\t\t\t\t\"stderr\" in error\n\t\t\t) {\n\t\t\t\tthrow new InternalError(\"Package installation failed\", {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t}\n}\n"],"names":["error","args","niDetect"],"mappings":";;;;;;;;;;;;;;AA2DM,MAAO,uBAAuB,YAAW;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EAER,MAAM,qBACL,MAA6C;AAE7C,QAAI,KAAK,4BAA4B,CAAC,MAAM,aAAa;AACxD,aAAO,KAAK;AAAA,IACb;AAEA,QAAI;A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3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-alpha.xru-fix-npx-install-warnings.2",
|
|
4
4
|
"description": "Manage all aspects of a Prismic project.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -63,12 +63,11 @@
|
|
|
63
63
|
"@antfu/ni": "27.0.1",
|
|
64
64
|
"@prismicio/client": "7.21.0",
|
|
65
65
|
"@prismicio/custom-types-client": "2.1.0",
|
|
66
|
-
"@prismicio/plugin-kit": "0.0.
|
|
66
|
+
"@prismicio/plugin-kit": "0.0.2-alpha.xru-fix-npx-install-warnings.3",
|
|
67
67
|
"@prismicio/types-internal": "3.16.1",
|
|
68
68
|
"@segment/analytics-node": "2.3.0",
|
|
69
69
|
"cookie": "1.1.1",
|
|
70
70
|
"cors": "2.8.5",
|
|
71
|
-
"execa": "9.6.0",
|
|
72
71
|
"fp-ts": "2.16.11",
|
|
73
72
|
"get-port": "7.1.0",
|
|
74
73
|
"h3": "1.15.4",
|
|
@@ -96,5 +95,6 @@
|
|
|
96
95
|
"typescript-eslint": "8.33.0",
|
|
97
96
|
"vite": "7.2.4",
|
|
98
97
|
"vite-plugin-sdk": "0.1.5"
|
|
99
|
-
}
|
|
98
|
+
},
|
|
99
|
+
"stableVersion": "0.0.1"
|
|
100
100
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
|
|
1
3
|
import { parseNi } from "@antfu/ni";
|
|
2
|
-
import { execaCommand, type ResultPromise, type Options } from "execa";
|
|
3
4
|
|
|
4
5
|
import { PackageManager } from "../types";
|
|
5
6
|
|
|
@@ -17,7 +18,13 @@ type InstallDependenciesArgs = {
|
|
|
17
18
|
packageManager: PackageManager;
|
|
18
19
|
dependencies: Record<string, string>;
|
|
19
20
|
dev?: boolean;
|
|
20
|
-
|
|
21
|
+
cwd?: string;
|
|
22
|
+
env?: NodeJS.ProcessEnv;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type ResultPromise = Promise<void> & {
|
|
26
|
+
stdout: NodeJS.ReadableStream | null;
|
|
27
|
+
stderr: NodeJS.ReadableStream | null;
|
|
21
28
|
};
|
|
22
29
|
|
|
23
30
|
type InstallDependenciesReturnType = {
|
|
@@ -61,14 +68,46 @@ export const installDependencies = async (
|
|
|
61
68
|
);
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
const
|
|
71
|
+
const parsed = resolveCommand(parsedCommand);
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
let command: string;
|
|
74
|
+
|
|
75
|
+
if (typeof parsedCommand === "object" && parsedCommand !== null) {
|
|
76
|
+
command = [parsedCommand.command, ...parsedCommand.args].join(" ");
|
|
77
|
+
} else {
|
|
78
|
+
command = parsed;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const childProcess = spawn(command, {
|
|
82
|
+
cwd: args.cwd || process.cwd(),
|
|
83
|
+
env: { ...process.env, ...args.env },
|
|
84
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
85
|
+
shell: true,
|
|
69
86
|
});
|
|
70
87
|
|
|
88
|
+
const promise = new Promise<void>((resolve, reject) => {
|
|
89
|
+
childProcess.on("error", (error) => {
|
|
90
|
+
reject(error);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
childProcess.on("exit", (code) => {
|
|
94
|
+
if (code === 0) {
|
|
95
|
+
resolve();
|
|
96
|
+
} else {
|
|
97
|
+
const error = new Error(`Command failed with exit code ${code}`);
|
|
98
|
+
Object.assign(error, {
|
|
99
|
+
shortMessage: `Command failed: ${parsed}`,
|
|
100
|
+
stderr: "",
|
|
101
|
+
});
|
|
102
|
+
reject(error);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}) as ResultPromise;
|
|
106
|
+
|
|
107
|
+
promise.stdout = childProcess.stdout;
|
|
108
|
+
promise.stderr = childProcess.stderr;
|
|
109
|
+
|
|
71
110
|
return {
|
|
72
|
-
execaProcess,
|
|
111
|
+
execaProcess: promise,
|
|
73
112
|
};
|
|
74
113
|
};
|
|
@@ -3,7 +3,6 @@ import * as fs from "node:fs/promises";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
|
|
5
5
|
import { detect as niDetect } from "@antfu/ni";
|
|
6
|
-
import { type ResultPromise } from "execa";
|
|
7
6
|
|
|
8
7
|
import { PRISMIC_CONFIG_FILENAME } from "../../constants/PRISMIC_CONFIG_FILENAME";
|
|
9
8
|
import { SLICEMACHINE_CONFIG_FILENAME } from "../../constants/SLICEMACHINE_CONFIG_FILENAME";
|
|
@@ -49,6 +48,11 @@ type ProjectManagerInstallDependenciesArgs = {
|
|
|
49
48
|
log?: (message: string) => void;
|
|
50
49
|
};
|
|
51
50
|
|
|
51
|
+
type ResultPromise = Promise<void> & {
|
|
52
|
+
stdout: NodeJS.ReadableStream | null;
|
|
53
|
+
stderr: NodeJS.ReadableStream | null;
|
|
54
|
+
};
|
|
55
|
+
|
|
52
56
|
type ProjectManagerInstallDependenciesReturnType = {
|
|
53
57
|
execaProcess: ResultPromise;
|
|
54
58
|
};
|
|
@@ -322,10 +326,12 @@ export class ProjectManager extends BaseManager {
|
|
|
322
326
|
};
|
|
323
327
|
|
|
324
328
|
try {
|
|
329
|
+
const projectRoot = await this.getRoot();
|
|
325
330
|
const { execaProcess } = await installDependencies({
|
|
326
331
|
packageManager,
|
|
327
332
|
dependencies: args.dependencies,
|
|
328
333
|
dev: args.dev,
|
|
334
|
+
cwd: projectRoot,
|
|
329
335
|
});
|
|
330
336
|
|
|
331
337
|
// Don't clutter console with logs when process is non TTY (CI, etc.)
|