@w5s/configurator-core 1.21.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +80 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +20 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +84 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/block.ts +62 -12
- package/src/internal/resolveCommentStyle.ts +56 -0
package/dist/index.cjs
CHANGED
|
@@ -124,9 +124,66 @@ function fileSync(options) {
|
|
|
124
124
|
} else (0, node_fs.rmSync)(path, { force: true });
|
|
125
125
|
}
|
|
126
126
|
//#endregion
|
|
127
|
+
//#region src/internal/resolveCommentStyle.ts
|
|
128
|
+
const HASH_BASENAMES = /* @__PURE__ */ new Set([
|
|
129
|
+
"containerfile",
|
|
130
|
+
"dockerfile",
|
|
131
|
+
"gemfile",
|
|
132
|
+
"makefile"
|
|
133
|
+
]);
|
|
134
|
+
const HTML_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
135
|
+
"htm",
|
|
136
|
+
"html",
|
|
137
|
+
"md",
|
|
138
|
+
"mdx",
|
|
139
|
+
"svg",
|
|
140
|
+
"xml"
|
|
141
|
+
]);
|
|
142
|
+
const LINE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
143
|
+
"c",
|
|
144
|
+
"cjs",
|
|
145
|
+
"cpp",
|
|
146
|
+
"cs",
|
|
147
|
+
"cts",
|
|
148
|
+
"go",
|
|
149
|
+
"h",
|
|
150
|
+
"java",
|
|
151
|
+
"js",
|
|
152
|
+
"jsx",
|
|
153
|
+
"kt",
|
|
154
|
+
"mjs",
|
|
155
|
+
"mts",
|
|
156
|
+
"rs",
|
|
157
|
+
"swift",
|
|
158
|
+
"ts",
|
|
159
|
+
"tsx"
|
|
160
|
+
]);
|
|
161
|
+
const BLOCK_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
162
|
+
"css",
|
|
163
|
+
"less",
|
|
164
|
+
"sass",
|
|
165
|
+
"scss"
|
|
166
|
+
]);
|
|
167
|
+
/**
|
|
168
|
+
* Resolve comment style from the file path when `commentStyle` is `'auto'`.
|
|
169
|
+
*
|
|
170
|
+
* @param path File path used to infer the comment style.
|
|
171
|
+
*/
|
|
172
|
+
function resolveCommentStyle(path) {
|
|
173
|
+
const basename = node_path.default.basename(path);
|
|
174
|
+
const basenameLower = basename.toLowerCase();
|
|
175
|
+
if (basename.startsWith(".") || HASH_BASENAMES.has(basenameLower)) return "#";
|
|
176
|
+
const extension = node_path.default.extname(basename).slice(1).toLowerCase();
|
|
177
|
+
if (HTML_EXTENSIONS.has(extension)) return "<!--";
|
|
178
|
+
if (LINE_EXTENSIONS.has(extension)) return "//";
|
|
179
|
+
if (BLOCK_EXTENSIONS.has(extension)) return "/*";
|
|
180
|
+
return "#";
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
127
183
|
//#region src/block.ts
|
|
128
184
|
const EOF = "EndOfFile";
|
|
129
185
|
const BOF = "BeginningOfFile";
|
|
186
|
+
const DEFAULT_TOPIC = "managed-block";
|
|
130
187
|
const insertAt = (str, index, toInsert) => str.slice(0, index) + toInsert + str.slice(index);
|
|
131
188
|
const matchLast = (string, regexp) => {
|
|
132
189
|
const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
|
|
@@ -168,11 +225,22 @@ function block(options) {
|
|
|
168
225
|
function blockSync(options) {
|
|
169
226
|
return fileSync(toFileOptions(options));
|
|
170
227
|
}
|
|
228
|
+
function formatMarker(style, mark, topic) {
|
|
229
|
+
const inner = `${mark.toUpperCase()}:${topic}`;
|
|
230
|
+
switch (style) {
|
|
231
|
+
case "#": return `# ${inner}`;
|
|
232
|
+
case "/*": return `/* ${inner} */`;
|
|
233
|
+
case "//": return `// ${inner}`;
|
|
234
|
+
case "<!--": return `<!-- ${inner} -->`;
|
|
235
|
+
default: throw new Error(`Unsupported comment style ${String(style)}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
171
238
|
function toFileOptions(options) {
|
|
172
|
-
const { block: blockName, insertPosition = ["after", EOF], marker
|
|
239
|
+
const { block: blockName, insertPosition = ["after", EOF], marker, path, state = "present" } = options;
|
|
173
240
|
const EOL = "\n";
|
|
174
|
-
const
|
|
175
|
-
const
|
|
241
|
+
const markerFn = toMarkerFn(marker, path);
|
|
242
|
+
const beginBlock = markerFn("Begin");
|
|
243
|
+
const endBlock = markerFn("End");
|
|
176
244
|
/**
|
|
177
245
|
* @param content
|
|
178
246
|
*/
|
|
@@ -214,6 +282,13 @@ function toFileOptions(options) {
|
|
|
214
282
|
update: (sourceContent) => apply(sourceContent, blockName)
|
|
215
283
|
};
|
|
216
284
|
}
|
|
285
|
+
function toMarkerFn(marker, path) {
|
|
286
|
+
if (typeof marker === "function") return marker;
|
|
287
|
+
const commentStyle = marker?.commentStyle ?? "auto";
|
|
288
|
+
const topic = marker?.topic ?? DEFAULT_TOPIC;
|
|
289
|
+
const resolvedStyle = commentStyle === "auto" ? resolveCommentStyle(path) : commentStyle;
|
|
290
|
+
return (mark) => formatMarker(resolvedStyle, mark, topic);
|
|
291
|
+
}
|
|
217
292
|
//#endregion
|
|
218
293
|
//#region src/directory.ts
|
|
219
294
|
/**
|
|
@@ -408,9 +483,9 @@ function toFileOption$1({ update, ...otherOptions }) {
|
|
|
408
483
|
//#endregion
|
|
409
484
|
//#region src/meta.ts
|
|
410
485
|
const meta = Object.freeze({
|
|
411
|
-
buildNumber:
|
|
486
|
+
buildNumber: 1791883988,
|
|
412
487
|
name: "@w5s/configurator-core",
|
|
413
|
-
version: "1.
|
|
488
|
+
version: "1.22.0"
|
|
414
489
|
});
|
|
415
490
|
//#endregion
|
|
416
491
|
//#region src/yaml.ts
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["access","constants","constants","readFile","writeFile","chmod","rm","readFileSync","mkdir","chmod","rm","toFileOption","readFileSync","readFile","path","toFileOption","yaml","YAML","spawn","spawnSync"],"sources":["../src/__exists.ts","../src/__existsSync.ts","../src/__toMode.ts","../src/file.ts","../src/block.ts","../src/directory.ts","../src/ignoreFile.ts","../src/isConfigPresent.ts","../src/json.ts","../src/meta.ts","../src/yaml.ts","../src/exec.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"sourcesContent":["import { constants } from 'node:fs';\nimport { access } from 'node:fs/promises';\n\nexport async function __exists(path: string) {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import { accessSync, constants } from 'node:fs';\n\nexport function __existsSync(path: string) {\n try {\n accessSync(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import type { FileMode, FilePermissionSet } from './FileMode.js';\n\nexport function __toMode(mode: FileMode | undefined): number | undefined {\n return mode == null\n ? mode\n : (\n toModeFlag(mode.owner, 0o400, 0o200, 0o100)\n | toModeFlag(mode.group, 0o040, 0o020, 0o010)\n | toModeFlag(mode.other, 0o004, 0o002, 0o001)\n );\n}\n\nfunction toModeFlag(permissionSet: FilePermissionSet | undefined, read: number, write: number, execute: number): number {\n return (\n (permissionSet?.read === true ? read : 0)\n | (permissionSet?.write === true ? write : 0)\n | (permissionSet?.execute === true ? execute : 0)\n );\n}\n","import { chmodSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { chmod, readFile, rm, writeFile } from 'node:fs/promises';\n\nimport type { FileMode } from './FileMode.js';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface FileOptions {\n /**\n * File encoding\n */\n readonly encoding?: BufferEncoding;\n\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n\n /**\n * File path\n */\n readonly path: string;\n\n /**\n * File target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * await file({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function file(options: FileOptions): Promise<void> {\n const { encoding = 'utf8', mode, path, state, update } = options;\n if (state === 'present') {\n const isPresent = await __exists(path);\n const previousContent = isPresent ? await readFile(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n await writeFile(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n await chmod(path, newMode);\n }\n } else {\n await rm(path, { force: true });\n }\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * fileSync({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function fileSync(options: FileOptions): void {\n const { encoding = 'utf8', mode, path, state, update } = options;\n if (state === 'present') {\n const isPresent = __existsSync(path);\n const previousContent = isPresent ? readFileSync(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n writeFileSync(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n chmodSync(path, newMode);\n }\n } else {\n rmSync(path, { force: true });\n }\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface BlockOptions {\n /**\n * Block content to insert\n */\n block: string;\n\n /**\n * Insert position\n */\n insertPosition?: ['after', 'EndOfFile' | RegExp] | ['before', 'BeginningOfFile' | RegExp];\n\n /**\n * The marker builder function that will take either `markerBegin` or `markerEnd`\n *\n * @default '# ${mark} MANAGED BLOCK'\n */\n marker?: (mark: 'Begin' | 'End') => string;\n\n /**\n * File path\n */\n path: string;\n\n /**\n * Block target state\n */\n state?: 'absent' | 'present';\n}\n\nconst EOF = 'EndOfFile';\nconst BOF = 'BeginningOfFile';\nconst insertAt = (str: string, index: number, toInsert: string) => str.slice(0, index) + toInsert + str.slice(index);\nconst matchLast = (string: string, regexp: RegExp) => {\n const matcher = new RegExp(regexp.source, `${regexp.flags}g`);\n let firstIndex = -1;\n let lastIndex = -1;\n let matches;\n\n while (true) {\n matches = matcher.exec(string);\n if (matches == null) {\n break;\n }\n firstIndex = matches.index;\n lastIndex = matcher.lastIndex;\n }\n return { firstIndex, lastIndex };\n};\n\n/**\n * Replace asynchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function block(options: BlockOptions) {\n return file(toFileOptions(options));\n}\n\n/**\n * Replace synchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function blockSync(options: BlockOptions) {\n return fileSync(toFileOptions(options));\n}\n\nfunction toFileOptions(options: BlockOptions): FileOptions {\n const {\n block: blockName,\n insertPosition = ['after', EOF],\n marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`,\n path,\n state = 'present',\n } = options;\n\n const EOL = '\\n';\n const beginBlock = marker('Begin');\n const endBlock = marker('End');\n\n /**\n * @param content\n */\n function findBlock(content: string) {\n const startIndex = content.indexOf(beginBlock);\n const endIndex = content.indexOf(endBlock) + endBlock.length;\n\n return {\n endIndex,\n exists: startIndex !== -1 && endIndex >= 0,\n startIndex,\n };\n }\n\n function apply(fullContent: string, blockContent: string) {\n const found = findBlock(fullContent);\n const remove = state === 'absent';\n const replaceBlock = remove ? '' : beginBlock + EOL + blockContent + EOL + endBlock;\n const [positionDirection, positionAnchor] = insertPosition;\n\n if (found.exists) {\n return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);\n }\n if (remove) {\n return fullContent;\n }\n switch (positionDirection) {\n case 'after': {\n // insert\n if (positionAnchor !== EOF) {\n const { lastIndex } = matchLast(fullContent, positionAnchor);\n if (lastIndex >= 0) {\n return insertAt(fullContent, lastIndex, EOL + replaceBlock);\n }\n }\n\n // end of file\n return fullContent + EOL + replaceBlock;\n }\n case 'before': {\n if (positionAnchor !== BOF) {\n const { firstIndex } = matchLast(fullContent, positionAnchor);\n if (firstIndex >= 0) {\n return insertAt(fullContent, firstIndex, replaceBlock + EOL);\n }\n }\n\n // Beginning of file\n return replaceBlock + EOL + fullContent;\n }\n\n default: {\n throw new Error(`Unsupported position ${String(positionDirection)}`);\n }\n }\n }\n\n return {\n path,\n state: 'present',\n update: (sourceContent) => apply(sourceContent, blockName),\n };\n}\n","import { chmodSync, mkdirSync, rmSync } from 'node:fs';\nimport { chmod, mkdir, rm } from 'node:fs/promises';\n\nimport type { FileMode } from './FileMode.js';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface DirectoryOptions {\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n\n /**\n * Directory path\n */\n readonly path: string;\n\n /**\n * Directory target state\n */\n readonly state: 'absent' | 'present';\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * await directory({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function directory(options: DirectoryOptions): Promise<void> {\n const { mode, path, state } = options;\n const isPresent = await __exists(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n await mkdir(path, { mode: newMode, recursive: true });\n }\n if (newMode != null && isPresent) {\n await chmod(path, newMode);\n }\n } else if (isPresent) {\n await rm(path, { recursive: true });\n }\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * directorySync({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function directorySync(options: DirectoryOptions): void {\n const { mode, path, state } = options;\n const isPresent = __existsSync(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n mkdirSync(path, { mode: newMode, recursive: true });\n }\n if (newMode != null && isPresent) {\n chmodSync(path, newMode);\n }\n } else if (isPresent) {\n rmSync(path, { recursive: true });\n }\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function where content is represented as lines.\n * When the file does not yet exist, the callback receives `undefined`.\n */\n readonly update?: ((content: Array<string> | undefined) => Array<string> | undefined) | undefined;\n}\n\n/**\n * Ensure file is present/absent asynchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * await ignoreFile({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport async function ignoreFile(options: IgnoreFileOptions): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * ignoreFileSync({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport function ignoreFileSync(options: IgnoreFileOptions): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption({ update, ...otherOptions }: IgnoreFileOptions): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const eol = content.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lines = content === '' ? undefined : content.split(eol);\n const updatedLines = update(lines);\n\n return updatedLines == null ? undefined : updatedLines.join(eol);\n },\n };\n}\n","import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\n\nconst defaultExtensions: Array<string> = ['.json', '.yaml', '.yml', '.js', '.cjs', '.mjs', '.ts', '.cts', '.mts'];\n\nexport interface IsConfigPresentOptions {\n /**\n * The name of the application.\n */\n app: string;\n\n /**\n * The directory to look into. Defaults to `process.cwd()`.\n */\n cwd?: string | undefined;\n\n /**\n * The list of extensions to check for.\n */\n extensions?: Array<string> | undefined;\n\n /**\n * The name of the package configuration. Defaults to `app`.\n */\n packageConfig?: string | undefined;\n}\n\n/**\n * Return whether tool configuration exists at `cwd` (cosmiconfig-style).\n *\n * Looks for `.{app}rc`, `.{app}rc.{ext}`, `{app}.config.{ext}` and a matching\n * `package.json` key.\n *\n * @param options\n */\nexport async function isConfigPresent(options: IsConfigPresentOptions): Promise<boolean> {\n const { candidatePaths, packageConfig, packageJsonPath } = toCandidates(options);\n\n const [hasConfigFile, hasPackageConfig] = await Promise.all([\n hasAnyFile(candidatePaths),\n hasPackageConfigFile(packageJsonPath, packageConfig),\n ]);\n\n return hasConfigFile || hasPackageConfig;\n}\n\nexport function isConfigPresentSync(options: IsConfigPresentOptions): boolean {\n const { candidatePaths, packageConfig, packageJsonPath } = toCandidates(options);\n\n for (const candidatePath of candidatePaths) {\n if (__existsSync(candidatePath)) {\n return true;\n }\n }\n\n if (__existsSync(packageJsonPath)) {\n try {\n return hasPackageConfigKey(readFileSync(packageJsonPath, 'utf8'), packageConfig);\n } catch {\n return false;\n }\n }\n\n return false;\n}\n\nasync function hasAnyFile(paths: Array<string>): Promise<boolean> {\n const results = await Promise.all(paths.map((candidatePath) => __exists(candidatePath)));\n\n return results.some(Boolean);\n}\n\nasync function hasPackageConfigFile(packageJsonPath: string, packageConfig: string): Promise<boolean> {\n if (!(await __exists(packageJsonPath))) {\n return false;\n }\n\n try {\n return hasPackageConfigKey(await readFile(packageJsonPath, 'utf8'), packageConfig);\n } catch {\n return false;\n }\n}\n\nfunction hasPackageConfigKey(packageJsonContent: string, packageConfig: string): boolean {\n const packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>;\n const value = packageJson[packageConfig];\n\n return value !== undefined && value !== null && value !== false;\n}\n\nfunction toCandidates({ app, cwd = process.cwd(), extensions = defaultExtensions, packageConfig = app }: IsConfigPresentOptions) {\n const candidatePaths = [path.join(cwd, `.${app}rc`)];\n for (const extension of extensions) {\n candidatePaths.push(path.join(cwd, `.${app}rc${extension}`), path.join(cwd, `${app}.config${extension}`));\n }\n\n return {\n candidatePaths,\n packageConfig,\n packageJsonPath: path.join(cwd, 'package.json'),\n };\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface JSONOption<V = JSONValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: undefined | V) => undefined | V) | undefined;\n}\n\nexport type JSONValue = Array<JSONValue> | boolean | null | number | string | { [key: string]: JSONValue };\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function json<Value>(options: JSONOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function jsonSync<Value>(options: JSONOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: JSONOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const jsonValue = content === '' ? undefined : (JSON.parse(content) as Value);\n\n return JSON.stringify(update(jsonValue));\n },\n };\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import YAML from 'yaml';\n\nimport { file, type FileOptions, fileSync } from './file.js';\n\nexport interface YAMLOption<V = YAMLValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: undefined | V) => undefined | V) | undefined;\n}\n\nexport type YAMLValue = Array<YAMLValue> | boolean | null | number | string | { [key: string]: YAMLValue };\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function yaml<Value>(options: YAMLOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function yamlSync<Value>(options: YAMLOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: YAMLOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const yamlValue = content === '' ? undefined : (YAML.parse(content) as Value);\n\n return YAML.stringify(update(yamlValue));\n },\n };\n}\n","import { spawn, spawnSync } from 'node:child_process';\n\nexport interface ExecOptions {\n /**\n * Current working directory\n */\n cwd?: string;\n\n /**\n * Stdio options\n */\n stdio?: 'ignore' | 'inherit' | 'pipe';\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n */\nexport async function exec(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): Promise<{ stderr: string; stdout: string }> {\n return new Promise((resolve, reject) => {\n const encoding = 'utf8';\n const child = spawn(command, args, { ...options });\n let stdout = '';\n let stderr = '';\n\n // Capture the stdout and stderr streams\n if (child.stdout != null) {\n child.stdout.on('data', (data) => {\n // eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access\n stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\n // eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access\n stderr += data.toString(encoding);\n });\n }\n // Handle process exit\n child.on('close', (_code) => {\n resolve({ stderr, stdout });\n });\n\n // Handle errors\n child.on('error', reject);\n });\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n * @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`\n */\nexport function execSync(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): { stderr: string; stdout: string } {\n const result = spawnSync(command, args, { ...options });\n const encoding = 'utf8';\n\n return { stderr: result.stderr.toString(encoding), stdout: result.stdout.toString(encoding) };\n}\n","import { exec, execSync } from './exec.js';\n\nexport interface YarnConfigOptions {\n /**\n * Configuration key\n */\n readonly key: string;\n\n /**\n * Option target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnConfig({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport async function yarnConfig(options: YarnConfigOptions): Promise<void> {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = await exec('yarn', ['config', 'get', key]);\n await exec('yarn', ['config', 'set', key, String(update == null ? '' : update(stdout))]);\n } else {\n await exec('yarn', ['config', 'unset', key]);\n }\n}\n\n/**\n * Synchronous version of {@link yarnConfig}\n *\n * @param options\n * @example\n * yarnConfigSync({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport function yarnConfigSync(options: YarnConfigOptions) {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = execSync('yarn', ['config', 'get', key]);\n execSync('yarn', ['config', 'set', key, String(update == null ? '' : update(stdout))]);\n } else {\n execSync('yarn', ['config', 'unset', key]);\n }\n}\n","import { exec, execSync } from './exec.js';\n\nexport type YarnVersionKind = 'berry' | 'classic';\n\nexport interface YarnVersionOptions {\n /**\n * Option target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * Version mapping function\n *\n */\n readonly update?: (() => undefined | YarnVersionKind) | undefined;\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnVersion({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport async function yarnVersion(options: YarnVersionOptions): Promise<void> {\n const { state, update } = options;\n if (state === 'present') {\n await exec('yarn', ['set', 'version', String(update == null ? 'berry' : update())]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n\n/**\n * Synchronous version of {@link yarnVersion}\n *\n * @param options\n * @example\n * yarnVersionSync({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport function yarnVersionSync(options: YarnVersionOptions) {\n const { state, update } = options;\n if (state === 'present') {\n execSync('yarn', ['set', 'version', String(update == null ? 'berry' : update())]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,eAAsB,SAAS,MAAc;CAC3C,IAAI;EACF,OAAA,GAAMA,iBAAAA,OAAAA,CAAO,MAAMC,QAAAA,UAAU,IAAI;EACjC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACRA,SAAgB,aAAa,MAAc;CACzC,IAAI;EACF,CAAA,GAAA,QAAA,WAAA,CAAW,MAAMC,QAAAA,UAAU,IAAI;EAC/B,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACPA,SAAgB,SAAS,MAAgD;CACvE,OAAO,QAAQ,OACX,OAEE,WAAW,KAAK,OAAO,KAAO,KAAO,EAAK,IACxC,WAAW,KAAK,OAAO,IAAO,I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AO,CAAC;CAAC,CAAC;MAGlF,MAAM,IAAI,MAAM,iBAAiB;AAErC;;;;;;;;;;;AAYA,SAAgB,gBAAgB,SAA6B;CAC3D,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,SAAS,QAAQ;EAAC;EAAO;EAAW,OAAO,UAAU,OAAO,UAAU,OAAO,CAAC;CAAC,CAAC;MAGhF,MAAM,IAAI,MAAM,iBAAiB;AAErC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["access","constants","constants","readFile","writeFile","chmod","rm","readFileSync","nodePath","mkdir","chmod","rm","toFileOption","readFileSync","readFile","path","toFileOption","yaml","YAML","spawn","spawnSync"],"sources":["../src/__exists.ts","../src/__existsSync.ts","../src/__toMode.ts","../src/file.ts","../src/internal/resolveCommentStyle.ts","../src/block.ts","../src/directory.ts","../src/ignoreFile.ts","../src/isConfigPresent.ts","../src/json.ts","../src/meta.ts","../src/yaml.ts","../src/exec.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"sourcesContent":["import { constants } from 'node:fs';\nimport { access } from 'node:fs/promises';\n\nexport async function __exists(path: string) {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import { accessSync, constants } from 'node:fs';\n\nexport function __existsSync(path: string) {\n try {\n accessSync(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import type { FileMode, FilePermissionSet } from './FileMode.js';\n\nexport function __toMode(mode: FileMode | undefined): number | undefined {\n return mode == null\n ? mode\n : (\n toModeFlag(mode.owner, 0o400, 0o200, 0o100)\n | toModeFlag(mode.group, 0o040, 0o020, 0o010)\n | toModeFlag(mode.other, 0o004, 0o002, 0o001)\n );\n}\n\nfunction toModeFlag(permissionSet: FilePermissionSet | undefined, read: number, write: number, execute: number): number {\n return (\n (permissionSet?.read === true ? read : 0)\n | (permissionSet?.write === true ? write : 0)\n | (permissionSet?.execute === true ? execute : 0)\n );\n}\n","import { chmodSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { chmod, readFile, rm, writeFile } from 'node:fs/promises';\n\nimport type { FileMode } from './FileMode.js';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface FileOptions {\n /**\n * File encoding\n */\n readonly encoding?: BufferEncoding;\n\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n\n /**\n * File path\n */\n readonly path: string;\n\n /**\n * File target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * await file({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function file(options: FileOptions): Promise<void> {\n const { encoding = 'utf8', mode, path, state, update } = options;\n if (state === 'present') {\n const isPresent = await __exists(path);\n const previousContent = isPresent ? await readFile(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n await writeFile(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n await chmod(path, newMode);\n }\n } else {\n await rm(path, { force: true });\n }\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * fileSync({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function fileSync(options: FileOptions): void {\n const { encoding = 'utf8', mode, path, state, update } = options;\n if (state === 'present') {\n const isPresent = __existsSync(path);\n const previousContent = isPresent ? readFileSync(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n writeFileSync(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n chmodSync(path, newMode);\n }\n } else {\n rmSync(path, { force: true });\n }\n}\n","import nodePath from 'node:path';\n\nexport type ResolvedCommentStyle = '#' | '/*' | '//' | '<!--';\n\n/* cspell:ignore containerfile */\nconst HASH_BASENAMES = new Set(['containerfile', 'dockerfile', 'gemfile', 'makefile']);\n\nconst HTML_EXTENSIONS = new Set(['htm', 'html', 'md', 'mdx', 'svg', 'xml']);\nconst LINE_EXTENSIONS = new Set([\n 'c',\n 'cjs',\n 'cpp',\n 'cs',\n 'cts',\n 'go',\n 'h',\n 'java',\n 'js',\n 'jsx',\n 'kt',\n 'mjs',\n 'mts',\n 'rs',\n 'swift',\n 'ts',\n 'tsx',\n]);\nconst BLOCK_EXTENSIONS = new Set(['css', 'less', 'sass', 'scss']);\n\n/**\n * Resolve comment style from the file path when `commentStyle` is `'auto'`.\n *\n * @param path File path used to infer the comment style.\n */\nexport function resolveCommentStyle(path: string): ResolvedCommentStyle {\n const basename = nodePath.basename(path);\n const basenameLower = basename.toLowerCase();\n\n if (basename.startsWith('.') || HASH_BASENAMES.has(basenameLower)) {\n return '#';\n }\n\n const extension = nodePath.extname(basename).slice(1).toLowerCase();\n if (HTML_EXTENSIONS.has(extension)) {\n return '<!--';\n }\n if (LINE_EXTENSIONS.has(extension)) {\n return '//';\n }\n if (BLOCK_EXTENSIONS.has(extension)) {\n return '/*';\n }\n\n // py, rb, sh, toml, yaml, yml, json, no extension, and unknown → #\n return '#';\n}\n","import { file, type FileOptions, fileSync } from './file.js';\nimport { resolveCommentStyle, type ResolvedCommentStyle } from './internal/resolveCommentStyle.js';\n\nexport type BlockCommentStyle = '#' | '/*' | '//' | '<!--' | 'auto';\n\nexport interface BlockMarkerOptions {\n /**\n * Comment opener used for the marker lines: `'auto'` (from file name),\n * `'#'`, `'//'`, slash-star, or `'<!--'`.\n *\n * @default 'auto'\n */\n commentStyle?: BlockCommentStyle;\n\n /**\n * Identity after `BEGIN:` / `END:`, so multiple blocks in one file do not collide.\n *\n * @default 'managed-block'\n */\n topic?: string;\n}\n\nexport interface BlockOptions {\n /**\n * Block content to insert\n */\n block: string;\n\n /**\n * Insert position\n */\n insertPosition?: ['after', 'EndOfFile' | RegExp] | ['before', 'BeginningOfFile' | RegExp];\n\n /**\n * Marker configuration, or a function that returns the full marker line.\n *\n * @default `{ commentStyle: 'auto', topic: 'managed-block' }`\n */\n marker?: ((mark: 'Begin' | 'End') => string) | BlockMarkerOptions;\n\n /**\n * File path\n */\n path: string;\n\n /**\n * Block target state\n */\n state?: 'absent' | 'present';\n}\n\nconst EOF = 'EndOfFile';\nconst BOF = 'BeginningOfFile';\nconst DEFAULT_TOPIC = 'managed-block';\n\nconst insertAt = (str: string, index: number, toInsert: string) => str.slice(0, index) + toInsert + str.slice(index);\nconst matchLast = (string: string, regexp: RegExp) => {\n const matcher = new RegExp(regexp.source, `${regexp.flags}g`);\n let firstIndex = -1;\n let lastIndex = -1;\n let matches;\n\n while (true) {\n matches = matcher.exec(string);\n if (matches == null) {\n break;\n }\n firstIndex = matches.index;\n lastIndex = matcher.lastIndex;\n }\n return { firstIndex, lastIndex };\n};\n\n/**\n * Replace asynchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function block(options: BlockOptions) {\n return file(toFileOptions(options));\n}\n\n/**\n * Replace synchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function blockSync(options: BlockOptions) {\n return fileSync(toFileOptions(options));\n}\n\nfunction formatMarker(style: ResolvedCommentStyle, mark: 'Begin' | 'End', topic: string): string {\n const inner = `${mark.toUpperCase()}:${topic}`;\n switch (style) {\n case '#': {\n return `# ${inner}`;\n }\n case '/*': {\n return `/* ${inner} */`;\n }\n case '//': {\n return `// ${inner}`;\n }\n case '<!--': {\n return `<!-- ${inner} -->`;\n }\n default: {\n throw new Error(`Unsupported comment style ${String(style)}`);\n }\n }\n}\n\nfunction toFileOptions(options: BlockOptions): FileOptions {\n const { block: blockName, insertPosition = ['after', EOF], marker, path, state = 'present' } = options;\n\n const EOL = '\\n';\n const markerFn = toMarkerFn(marker, path);\n const beginBlock = markerFn('Begin');\n const endBlock = markerFn('End');\n\n /**\n * @param content\n */\n function findBlock(content: string) {\n const startIndex = content.indexOf(beginBlock);\n const endIndex = content.indexOf(endBlock) + endBlock.length;\n\n return {\n endIndex,\n exists: startIndex !== -1 && endIndex >= 0,\n startIndex,\n };\n }\n\n function apply(fullContent: string, blockContent: string) {\n const found = findBlock(fullContent);\n const remove = state === 'absent';\n const replaceBlock = remove ? '' : beginBlock + EOL + blockContent + EOL + endBlock;\n const [positionDirection, positionAnchor] = insertPosition;\n\n if (found.exists) {\n return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);\n }\n if (remove) {\n return fullContent;\n }\n switch (positionDirection) {\n case 'after': {\n // insert\n if (positionAnchor !== EOF) {\n const { lastIndex } = matchLast(fullContent, positionAnchor);\n if (lastIndex >= 0) {\n return insertAt(fullContent, lastIndex, EOL + replaceBlock);\n }\n }\n\n // end of file\n return fullContent + EOL + replaceBlock;\n }\n case 'before': {\n if (positionAnchor !== BOF) {\n const { firstIndex } = matchLast(fullContent, positionAnchor);\n if (firstIndex >= 0) {\n return insertAt(fullContent, firstIndex, replaceBlock + EOL);\n }\n }\n\n // Beginning of file\n return replaceBlock + EOL + fullContent;\n }\n\n default: {\n throw new Error(`Unsupported position ${String(positionDirection)}`);\n }\n }\n }\n\n return {\n path,\n state: 'present',\n update: (sourceContent) => apply(sourceContent, blockName),\n };\n}\n\nfunction toMarkerFn(marker: BlockOptions['marker'], path: string): (mark: 'Begin' | 'End') => string {\n if (typeof marker === 'function') {\n return marker;\n }\n\n const commentStyle = marker?.commentStyle ?? 'auto';\n const topic = marker?.topic ?? DEFAULT_TOPIC;\n const resolvedStyle = commentStyle === 'auto' ? resolveCommentStyle(path) : commentStyle;\n\n return (mark) => formatMarker(resolvedStyle, mark, topic);\n}\n","import { chmodSync, mkdirSync, rmSync } from 'node:fs';\nimport { chmod, mkdir, rm } from 'node:fs/promises';\n\nimport type { FileMode } from './FileMode.js';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface DirectoryOptions {\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n\n /**\n * Directory path\n */\n readonly path: string;\n\n /**\n * Directory target state\n */\n readonly state: 'absent' | 'present';\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * await directory({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function directory(options: DirectoryOptions): Promise<void> {\n const { mode, path, state } = options;\n const isPresent = await __exists(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n await mkdir(path, { mode: newMode, recursive: true });\n }\n if (newMode != null && isPresent) {\n await chmod(path, newMode);\n }\n } else if (isPresent) {\n await rm(path, { recursive: true });\n }\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * directorySync({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function directorySync(options: DirectoryOptions): void {\n const { mode, path, state } = options;\n const isPresent = __existsSync(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n mkdirSync(path, { mode: newMode, recursive: true });\n }\n if (newMode != null && isPresent) {\n chmodSync(path, newMode);\n }\n } else if (isPresent) {\n rmSync(path, { recursive: true });\n }\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function where content is represented as lines.\n * When the file does not yet exist, the callback receives `undefined`.\n */\n readonly update?: ((content: Array<string> | undefined) => Array<string> | undefined) | undefined;\n}\n\n/**\n * Ensure file is present/absent asynchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * await ignoreFile({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport async function ignoreFile(options: IgnoreFileOptions): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * ignoreFileSync({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport function ignoreFileSync(options: IgnoreFileOptions): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption({ update, ...otherOptions }: IgnoreFileOptions): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const eol = content.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lines = content === '' ? undefined : content.split(eol);\n const updatedLines = update(lines);\n\n return updatedLines == null ? undefined : updatedLines.join(eol);\n },\n };\n}\n","import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\n\nconst defaultExtensions: Array<string> = ['.json', '.yaml', '.yml', '.js', '.cjs', '.mjs', '.ts', '.cts', '.mts'];\n\nexport interface IsConfigPresentOptions {\n /**\n * The name of the application.\n */\n app: string;\n\n /**\n * The directory to look into. Defaults to `process.cwd()`.\n */\n cwd?: string | undefined;\n\n /**\n * The list of extensions to check for.\n */\n extensions?: Array<string> | undefined;\n\n /**\n * The name of the package configuration. Defaults to `app`.\n */\n packageConfig?: string | undefined;\n}\n\n/**\n * Return whether tool configuration exists at `cwd` (cosmiconfig-style).\n *\n * Looks for `.{app}rc`, `.{app}rc.{ext}`, `{app}.config.{ext}` and a matching\n * `package.json` key.\n *\n * @param options\n */\nexport async function isConfigPresent(options: IsConfigPresentOptions): Promise<boolean> {\n const { candidatePaths, packageConfig, packageJsonPath } = toCandidates(options);\n\n const [hasConfigFile, hasPackageConfig] = await Promise.all([\n hasAnyFile(candidatePaths),\n hasPackageConfigFile(packageJsonPath, packageConfig),\n ]);\n\n return hasConfigFile || hasPackageConfig;\n}\n\nexport function isConfigPresentSync(options: IsConfigPresentOptions): boolean {\n const { candidatePaths, packageConfig, packageJsonPath } = toCandidates(options);\n\n for (const candidatePath of candidatePaths) {\n if (__existsSync(candidatePath)) {\n return true;\n }\n }\n\n if (__existsSync(packageJsonPath)) {\n try {\n return hasPackageConfigKey(readFileSync(packageJsonPath, 'utf8'), packageConfig);\n } catch {\n return false;\n }\n }\n\n return false;\n}\n\nasync function hasAnyFile(paths: Array<string>): Promise<boolean> {\n const results = await Promise.all(paths.map((candidatePath) => __exists(candidatePath)));\n\n return results.some(Boolean);\n}\n\nasync function hasPackageConfigFile(packageJsonPath: string, packageConfig: string): Promise<boolean> {\n if (!(await __exists(packageJsonPath))) {\n return false;\n }\n\n try {\n return hasPackageConfigKey(await readFile(packageJsonPath, 'utf8'), packageConfig);\n } catch {\n return false;\n }\n}\n\nfunction hasPackageConfigKey(packageJsonContent: string, packageConfig: string): boolean {\n const packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>;\n const value = packageJson[packageConfig];\n\n return value !== undefined && value !== null && value !== false;\n}\n\nfunction toCandidates({ app, cwd = process.cwd(), extensions = defaultExtensions, packageConfig = app }: IsConfigPresentOptions) {\n const candidatePaths = [path.join(cwd, `.${app}rc`)];\n for (const extension of extensions) {\n candidatePaths.push(path.join(cwd, `.${app}rc${extension}`), path.join(cwd, `${app}.config${extension}`));\n }\n\n return {\n candidatePaths,\n packageConfig,\n packageJsonPath: path.join(cwd, 'package.json'),\n };\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface JSONOption<V = JSONValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: undefined | V) => undefined | V) | undefined;\n}\n\nexport type JSONValue = Array<JSONValue> | boolean | null | number | string | { [key: string]: JSONValue };\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function json<Value>(options: JSONOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function jsonSync<Value>(options: JSONOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: JSONOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const jsonValue = content === '' ? undefined : (JSON.parse(content) as Value);\n\n return JSON.stringify(update(jsonValue));\n },\n };\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import YAML from 'yaml';\n\nimport { file, type FileOptions, fileSync } from './file.js';\n\nexport interface YAMLOption<V = YAMLValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: undefined | V) => undefined | V) | undefined;\n}\n\nexport type YAMLValue = Array<YAMLValue> | boolean | null | number | string | { [key: string]: YAMLValue };\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function yaml<Value>(options: YAMLOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function yamlSync<Value>(options: YAMLOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: YAMLOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const yamlValue = content === '' ? undefined : (YAML.parse(content) as Value);\n\n return YAML.stringify(update(yamlValue));\n },\n };\n}\n","import { spawn, spawnSync } from 'node:child_process';\n\nexport interface ExecOptions {\n /**\n * Current working directory\n */\n cwd?: string;\n\n /**\n * Stdio options\n */\n stdio?: 'ignore' | 'inherit' | 'pipe';\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n */\nexport async function exec(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): Promise<{ stderr: string; stdout: string }> {\n return new Promise((resolve, reject) => {\n const encoding = 'utf8';\n const child = spawn(command, args, { ...options });\n let stdout = '';\n let stderr = '';\n\n // Capture the stdout and stderr streams\n if (child.stdout != null) {\n child.stdout.on('data', (data) => {\n // eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access\n stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\n // eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access\n stderr += data.toString(encoding);\n });\n }\n // Handle process exit\n child.on('close', (_code) => {\n resolve({ stderr, stdout });\n });\n\n // Handle errors\n child.on('error', reject);\n });\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n * @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`\n */\nexport function execSync(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): { stderr: string; stdout: string } {\n const result = spawnSync(command, args, { ...options });\n const encoding = 'utf8';\n\n return { stderr: result.stderr.toString(encoding), stdout: result.stdout.toString(encoding) };\n}\n","import { exec, execSync } from './exec.js';\n\nexport interface YarnConfigOptions {\n /**\n * Configuration key\n */\n readonly key: string;\n\n /**\n * Option target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnConfig({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport async function yarnConfig(options: YarnConfigOptions): Promise<void> {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = await exec('yarn', ['config', 'get', key]);\n await exec('yarn', ['config', 'set', key, String(update == null ? '' : update(stdout))]);\n } else {\n await exec('yarn', ['config', 'unset', key]);\n }\n}\n\n/**\n * Synchronous version of {@link yarnConfig}\n *\n * @param options\n * @example\n * yarnConfigSync({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport function yarnConfigSync(options: YarnConfigOptions) {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = execSync('yarn', ['config', 'get', key]);\n execSync('yarn', ['config', 'set', key, String(update == null ? '' : update(stdout))]);\n } else {\n execSync('yarn', ['config', 'unset', key]);\n }\n}\n","import { exec, execSync } from './exec.js';\n\nexport type YarnVersionKind = 'berry' | 'classic';\n\nexport interface YarnVersionOptions {\n /**\n * Option target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * Version mapping function\n *\n */\n readonly update?: (() => undefined | YarnVersionKind) | undefined;\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnVersion({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport async function yarnVersion(options: YarnVersionOptions): Promise<void> {\n const { state, update } = options;\n if (state === 'present') {\n await exec('yarn', ['set', 'version', String(update == null ? 'berry' : update())]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n\n/**\n * Synchronous version of {@link yarnVersion}\n *\n * @param options\n * @example\n * yarnVersionSync({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport function yarnVersionSync(options: YarnVersionOptions) {\n const { state, update } = options;\n if (state === 'present') {\n execSync('yarn', ['set', 'version', String(update == null ? 'berry' : update())]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,eAAsB,SAAS,MAAc;CAC3C,IAAI;EACF,OAAA,GAAMA,iBAAAA,OAAAA,CAAO,MAAMC,QAAAA,UAAU,IAAI;EACjC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACRA,SAAgB,aAAa,MAAc;CACzC,IAAI;EACF,CAAA,GAAA,QAAA,WAAA,CAAW,MAAMC,QAAAA,UAAU,IAAI;EAC/B,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACPA,SAAgB,SAAS,MAAgD;CACvE,OAAO,QAAQ,OACX,OAEE,WAAW,KAAK,OAAO,KAAO,KAAO,EAAK,IACxC,WAAW,KAAK,OAAO,IAAO,IAAO,CAAK,IAC1C,WAAW,KAAK,OAAO,GAAO,GAAO,CAAK;AAEpD;AAEA,SAAS,WAAW,eAA8C,MAAc,OAAe,SAAyB;CACtH,QACG,eAAe,SAAS,OAAO,OAAO,MACpC,eAAe,UAAU,OAAO,QAAQ,MACxC,eAAe,YAAY,OAAO,UAAU;AAEnD;;;;;;;;;;;;;;;;;;;;;;ACsCA,eAAsB,KAAK,SAAqC;CAC9D,MAAM,EAAE,WAAW,QAAQ,MAAM,MAAM,OAAO,WAAW;CACzD,IAAI,UAAU,WAAW;EACvB,MAAM,YAAY,MAAM,SAAS,IAA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M,iBAAiB;AAErC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
//#region src/block.d.ts
|
|
2
|
+
export type BlockCommentStyle = '#' | '/*' | '//' | '<!--' | 'auto';
|
|
3
|
+
export interface BlockMarkerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Comment opener used for the marker lines: `'auto'` (from file name),
|
|
6
|
+
* `'#'`, `'//'`, slash-star, or `'<!--'`.
|
|
7
|
+
*
|
|
8
|
+
* @default 'auto'
|
|
9
|
+
*/
|
|
10
|
+
commentStyle?: BlockCommentStyle;
|
|
11
|
+
/**
|
|
12
|
+
* Identity after `BEGIN:` / `END:`, so multiple blocks in one file do not collide.
|
|
13
|
+
*
|
|
14
|
+
* @default 'managed-block'
|
|
15
|
+
*/
|
|
16
|
+
topic?: string;
|
|
17
|
+
}
|
|
2
18
|
export interface BlockOptions {
|
|
3
19
|
/**
|
|
4
20
|
* Block content to insert
|
|
@@ -9,11 +25,11 @@ export interface BlockOptions {
|
|
|
9
25
|
*/
|
|
10
26
|
insertPosition?: ['after', 'EndOfFile' | RegExp] | ['before', 'BeginningOfFile' | RegExp];
|
|
11
27
|
/**
|
|
12
|
-
*
|
|
28
|
+
* Marker configuration, or a function that returns the full marker line.
|
|
13
29
|
*
|
|
14
|
-
* @default '
|
|
30
|
+
* @default `{ commentStyle: 'auto', topic: 'managed-block' }`
|
|
15
31
|
*/
|
|
16
|
-
marker?: (mark: 'Begin' | 'End') => string;
|
|
32
|
+
marker?: ((mark: 'Begin' | 'End') => string) | BlockMarkerOptions;
|
|
17
33
|
/**
|
|
18
34
|
* File path
|
|
19
35
|
*/
|
|
@@ -388,4 +404,5 @@ export declare function yarnVersion(options: YarnVersionOptions): Promise<void>;
|
|
|
388
404
|
*/
|
|
389
405
|
export declare function yarnVersionSync(options: YarnVersionOptions): void;
|
|
390
406
|
//#endregion
|
|
407
|
+
export {};
|
|
391
408
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/block.ts","../src/FileMode.ts","../src/directory.ts","../src/file.ts","../src/ignoreFile.ts","../src/isConfigPresent.ts","../src/json.ts","../src/meta.ts","../src/yaml.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/block.ts","../src/FileMode.ts","../src/directory.ts","../src/file.ts","../src/ignoreFile.ts","../src/isConfigPresent.ts","../src/json.ts","../src/meta.ts","../src/yaml.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"mappings":";YAGY;iBAEK;;;;;;;EAOf,eAAe;;;;;;EAOf;;iBAGe;;;;EAIf;;;;EAKA,yCAAyC,yCAAyC;;;;;;EAOlF,WAAW,oCAAoC;;;;EAK/C;;;;EAKA;;;;;;;;;;;wBAkCc,MAAM,SAAS,eAAY;;;;;;;;;;wBAa3B,UAAU,SAAS;;;UC/FlB;;;;WAIN,QAAQ;;;;WAKR,QAAQ;;;;WAKR,QAAQ;;UAGF;;;;WAIN;;;;WAKA;;;;WAKA;;;;iBCtBM;;;;WAIN,OAAO;;;;WAKP;;;;WAKA;;;;;;;;;;;;;;;;;;;;wBAqBW,UAAU,SAAS,mBAAmB;;;;;;;;;;;;;;;;;;;wBAkC5C,cAAc,SAAS;;;iBCrEtB;;;;WAIN,WAAW;;;;WAKX,OAAO;;;;WAKP;;;;WAKA;;;;;WAMA,WAAW;;;;;;;;;;;;;;;;;;;;;wBAsBA,KAAK,SAAS,cAAc;;;;;;;;;;;;;;;;;;;;wBAqClC,SAAS,SAAS;;;iBC3FjB,0BAA0B,KAAK;;;;;WAKrC,WAAW,SAAS,8BAA8B;;;;;;;;;;;;;;wBAevC,WAAW,SAAS,oBAAoB;;;;;;;;;;;;;wBAgB9C,eAAe,SAAS;;;iBC7BvB;;;;EAIf;;;;EAKA;;;;EAKA,aAAa;;;;EAKb;;;;;;;;;;wBAWoB,gBAAgB,SAAS,yBAAyB;wBAWxD,oBAAoB,SAAS;;;iBChD5B,WAAW,IAAI,mBAAmB,KAAK;;;;WAI7C,WAAW,qBAAqB,kBAAkB;;YAGjD,YAAY,MAAM;GAAmD,cAAc;;;;;;;wBAOzE,KAAK,OAAO,SAAS,WAAW,SAAS;;;;;;wBAS/C,SAAS,OAAO,SAAS,WAAW;;;qBCzBvC,MAAI;EAEkF;EAEtB;EAES;;;;iBCFrE,WAAW,IAAI,mBAAmB,KAAK;;;;WAI7C,WAAW,qBAAqB,kBAAkB;;YAGjD,YAAY,MAAM;GAAmD,cAAc;;;;;;;wBAOzE,KAAK,OAAO,SAAS,WAAW,SAAS;;;;;;wBAS/C,SAAS,OAAO,SAAS,WAAW;;;iBCzBnC;;;;WAIN;;;;WAKA;;;;;WAMA,WAAW;;;;;;;;;;;;;wBAcA,WAAW,SAAS,oBAAoB;;;;;;;;;;;;wBAqB9C,eAAe,SAAS;;;YClD5B;iBAEK;;;;WAIN;;;;;WAMA,4BAA4B;;;;;;;;;;;;wBAajB,YAAY,SAAS,qBAAqB;;;;;;;;;;;wBAoBhD,gBAAgB,SAAS"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
//#region src/block.d.ts
|
|
2
|
+
export type BlockCommentStyle = '#' | '/*' | '//' | '<!--' | 'auto';
|
|
3
|
+
export interface BlockMarkerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Comment opener used for the marker lines: `'auto'` (from file name),
|
|
6
|
+
* `'#'`, `'//'`, slash-star, or `'<!--'`.
|
|
7
|
+
*
|
|
8
|
+
* @default 'auto'
|
|
9
|
+
*/
|
|
10
|
+
commentStyle?: BlockCommentStyle;
|
|
11
|
+
/**
|
|
12
|
+
* Identity after `BEGIN:` / `END:`, so multiple blocks in one file do not collide.
|
|
13
|
+
*
|
|
14
|
+
* @default 'managed-block'
|
|
15
|
+
*/
|
|
16
|
+
topic?: string;
|
|
17
|
+
}
|
|
2
18
|
export interface BlockOptions {
|
|
3
19
|
/**
|
|
4
20
|
* Block content to insert
|
|
@@ -9,11 +25,11 @@ export interface BlockOptions {
|
|
|
9
25
|
*/
|
|
10
26
|
insertPosition?: ['after', 'EndOfFile' | RegExp] | ['before', 'BeginningOfFile' | RegExp];
|
|
11
27
|
/**
|
|
12
|
-
*
|
|
28
|
+
* Marker configuration, or a function that returns the full marker line.
|
|
13
29
|
*
|
|
14
|
-
* @default '
|
|
30
|
+
* @default `{ commentStyle: 'auto', topic: 'managed-block' }`
|
|
15
31
|
*/
|
|
16
|
-
marker?: (mark: 'Begin' | 'End') => string;
|
|
32
|
+
marker?: ((mark: 'Begin' | 'End') => string) | BlockMarkerOptions;
|
|
17
33
|
/**
|
|
18
34
|
* File path
|
|
19
35
|
*/
|
|
@@ -388,4 +404,5 @@ export declare function yarnVersion(options: YarnVersionOptions): Promise<void>;
|
|
|
388
404
|
*/
|
|
389
405
|
export declare function yarnVersionSync(options: YarnVersionOptions): void;
|
|
390
406
|
//#endregion
|
|
407
|
+
export {};
|
|
391
408
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/block.ts","../src/FileMode.ts","../src/directory.ts","../src/file.ts","../src/ignoreFile.ts","../src/isConfigPresent.ts","../src/json.ts","../src/meta.ts","../src/yaml.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/block.ts","../src/FileMode.ts","../src/directory.ts","../src/file.ts","../src/ignoreFile.ts","../src/isConfigPresent.ts","../src/json.ts","../src/meta.ts","../src/yaml.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"mappings":";YAGY;iBAEK;;;;;;;EAOf,eAAe;;;;;;EAOf;;iBAGe;;;;EAIf;;;;EAKA,yCAAyC,yCAAyC;;;;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A;;;;;WAMA,WAAW;;;;;;;;;;;;;wBAcA,WAAW,SAAS,oBAAoB;;;;;;;;;;;;wBAqB9C,eAAe,SAAS;;;YClD5B;iBAEK;;;;WAIN;;;;;WAMA,4BAA4B;;;;;;;;;;;;wBAajB,YAAY,SAAS,qBAAqB;;;;;;;;;;;wBAoBhD,gBAAgB,SAAS"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { accessSync, chmodSync, constants, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { access, chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import
|
|
3
|
+
import nodePath from "node:path";
|
|
4
4
|
import YAML from "yaml";
|
|
5
5
|
import { spawn, spawnSync } from "node:child_process";
|
|
6
6
|
//#region src/__exists.ts
|
|
@@ -99,9 +99,66 @@ function fileSync(options) {
|
|
|
99
99
|
} else rmSync(path, { force: true });
|
|
100
100
|
}
|
|
101
101
|
//#endregion
|
|
102
|
+
//#region src/internal/resolveCommentStyle.ts
|
|
103
|
+
const HASH_BASENAMES = /* @__PURE__ */ new Set([
|
|
104
|
+
"containerfile",
|
|
105
|
+
"dockerfile",
|
|
106
|
+
"gemfile",
|
|
107
|
+
"makefile"
|
|
108
|
+
]);
|
|
109
|
+
const HTML_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
110
|
+
"htm",
|
|
111
|
+
"html",
|
|
112
|
+
"md",
|
|
113
|
+
"mdx",
|
|
114
|
+
"svg",
|
|
115
|
+
"xml"
|
|
116
|
+
]);
|
|
117
|
+
const LINE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
118
|
+
"c",
|
|
119
|
+
"cjs",
|
|
120
|
+
"cpp",
|
|
121
|
+
"cs",
|
|
122
|
+
"cts",
|
|
123
|
+
"go",
|
|
124
|
+
"h",
|
|
125
|
+
"java",
|
|
126
|
+
"js",
|
|
127
|
+
"jsx",
|
|
128
|
+
"kt",
|
|
129
|
+
"mjs",
|
|
130
|
+
"mts",
|
|
131
|
+
"rs",
|
|
132
|
+
"swift",
|
|
133
|
+
"ts",
|
|
134
|
+
"tsx"
|
|
135
|
+
]);
|
|
136
|
+
const BLOCK_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
137
|
+
"css",
|
|
138
|
+
"less",
|
|
139
|
+
"sass",
|
|
140
|
+
"scss"
|
|
141
|
+
]);
|
|
142
|
+
/**
|
|
143
|
+
* Resolve comment style from the file path when `commentStyle` is `'auto'`.
|
|
144
|
+
*
|
|
145
|
+
* @param path File path used to infer the comment style.
|
|
146
|
+
*/
|
|
147
|
+
function resolveCommentStyle(path) {
|
|
148
|
+
const basename = nodePath.basename(path);
|
|
149
|
+
const basenameLower = basename.toLowerCase();
|
|
150
|
+
if (basename.startsWith(".") || HASH_BASENAMES.has(basenameLower)) return "#";
|
|
151
|
+
const extension = nodePath.extname(basename).slice(1).toLowerCase();
|
|
152
|
+
if (HTML_EXTENSIONS.has(extension)) return "<!--";
|
|
153
|
+
if (LINE_EXTENSIONS.has(extension)) return "//";
|
|
154
|
+
if (BLOCK_EXTENSIONS.has(extension)) return "/*";
|
|
155
|
+
return "#";
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
102
158
|
//#region src/block.ts
|
|
103
159
|
const EOF = "EndOfFile";
|
|
104
160
|
const BOF = "BeginningOfFile";
|
|
161
|
+
const DEFAULT_TOPIC = "managed-block";
|
|
105
162
|
const insertAt = (str, index, toInsert) => str.slice(0, index) + toInsert + str.slice(index);
|
|
106
163
|
const matchLast = (string, regexp) => {
|
|
107
164
|
const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
|
|
@@ -143,11 +200,22 @@ function block(options) {
|
|
|
143
200
|
function blockSync(options) {
|
|
144
201
|
return fileSync(toFileOptions(options));
|
|
145
202
|
}
|
|
203
|
+
function formatMarker(style, mark, topic) {
|
|
204
|
+
const inner = `${mark.toUpperCase()}:${topic}`;
|
|
205
|
+
switch (style) {
|
|
206
|
+
case "#": return `# ${inner}`;
|
|
207
|
+
case "/*": return `/* ${inner} */`;
|
|
208
|
+
case "//": return `// ${inner}`;
|
|
209
|
+
case "<!--": return `<!-- ${inner} -->`;
|
|
210
|
+
default: throw new Error(`Unsupported comment style ${String(style)}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
146
213
|
function toFileOptions(options) {
|
|
147
|
-
const { block: blockName, insertPosition = ["after", EOF], marker
|
|
214
|
+
const { block: blockName, insertPosition = ["after", EOF], marker, path, state = "present" } = options;
|
|
148
215
|
const EOL = "\n";
|
|
149
|
-
const
|
|
150
|
-
const
|
|
216
|
+
const markerFn = toMarkerFn(marker, path);
|
|
217
|
+
const beginBlock = markerFn("Begin");
|
|
218
|
+
const endBlock = markerFn("End");
|
|
151
219
|
/**
|
|
152
220
|
* @param content
|
|
153
221
|
*/
|
|
@@ -189,6 +257,13 @@ function toFileOptions(options) {
|
|
|
189
257
|
update: (sourceContent) => apply(sourceContent, blockName)
|
|
190
258
|
};
|
|
191
259
|
}
|
|
260
|
+
function toMarkerFn(marker, path) {
|
|
261
|
+
if (typeof marker === "function") return marker;
|
|
262
|
+
const commentStyle = marker?.commentStyle ?? "auto";
|
|
263
|
+
const topic = marker?.topic ?? DEFAULT_TOPIC;
|
|
264
|
+
const resolvedStyle = commentStyle === "auto" ? resolveCommentStyle(path) : commentStyle;
|
|
265
|
+
return (mark) => formatMarker(resolvedStyle, mark, topic);
|
|
266
|
+
}
|
|
192
267
|
//#endregion
|
|
193
268
|
//#region src/directory.ts
|
|
194
269
|
/**
|
|
@@ -345,12 +420,12 @@ function hasPackageConfigKey(packageJsonContent, packageConfig) {
|
|
|
345
420
|
return value !== void 0 && value !== null && value !== false;
|
|
346
421
|
}
|
|
347
422
|
function toCandidates({ app, cwd = process.cwd(), extensions = defaultExtensions, packageConfig = app }) {
|
|
348
|
-
const candidatePaths = [
|
|
349
|
-
for (const extension of extensions) candidatePaths.push(
|
|
423
|
+
const candidatePaths = [nodePath.join(cwd, `.${app}rc`)];
|
|
424
|
+
for (const extension of extensions) candidatePaths.push(nodePath.join(cwd, `.${app}rc${extension}`), nodePath.join(cwd, `${app}.config${extension}`));
|
|
350
425
|
return {
|
|
351
426
|
candidatePaths,
|
|
352
427
|
packageConfig,
|
|
353
|
-
packageJsonPath:
|
|
428
|
+
packageJsonPath: nodePath.join(cwd, "package.json")
|
|
354
429
|
};
|
|
355
430
|
}
|
|
356
431
|
//#endregion
|
|
@@ -383,9 +458,9 @@ function toFileOption$1({ update, ...otherOptions }) {
|
|
|
383
458
|
//#endregion
|
|
384
459
|
//#region src/meta.ts
|
|
385
460
|
const meta = Object.freeze({
|
|
386
|
-
buildNumber:
|
|
461
|
+
buildNumber: 1791883988,
|
|
387
462
|
name: "@w5s/configurator-core",
|
|
388
|
-
version: "1.
|
|
463
|
+
version: "1.22.0"
|
|
389
464
|
});
|
|
390
465
|
//#endregion
|
|
391
466
|
//#region src/yaml.ts
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["toFileOption","toFileOption"],"sources":["../src/__exists.ts","../src/__existsSync.ts","../src/__toMode.ts","../src/file.ts","../src/block.ts","../src/directory.ts","../src/ignoreFile.ts","../src/isConfigPresent.ts","../src/json.ts","../src/meta.ts","../src/yaml.ts","../src/exec.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"sourcesContent":["import { constants } from 'node:fs';\nimport { access } from 'node:fs/promises';\n\nexport async function __exists(path: string) {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import { accessSync, constants } from 'node:fs';\n\nexport function __existsSync(path: string) {\n try {\n accessSync(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import type { FileMode, FilePermissionSet } from './FileMode.js';\n\nexport function __toMode(mode: FileMode | undefined): number | undefined {\n return mode == null\n ? mode\n : (\n toModeFlag(mode.owner, 0o400, 0o200, 0o100)\n | toModeFlag(mode.group, 0o040, 0o020, 0o010)\n | toModeFlag(mode.other, 0o004, 0o002, 0o001)\n );\n}\n\nfunction toModeFlag(permissionSet: FilePermissionSet | undefined, read: number, write: number, execute: number): number {\n return (\n (permissionSet?.read === true ? read : 0)\n | (permissionSet?.write === true ? write : 0)\n | (permissionSet?.execute === true ? execute : 0)\n );\n}\n","import { chmodSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { chmod, readFile, rm, writeFile } from 'node:fs/promises';\n\nimport type { FileMode } from './FileMode.js';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface FileOptions {\n /**\n * File encoding\n */\n readonly encoding?: BufferEncoding;\n\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n\n /**\n * File path\n */\n readonly path: string;\n\n /**\n * File target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * await file({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function file(options: FileOptions): Promise<void> {\n const { encoding = 'utf8', mode, path, state, update } = options;\n if (state === 'present') {\n const isPresent = await __exists(path);\n const previousContent = isPresent ? await readFile(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n await writeFile(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n await chmod(path, newMode);\n }\n } else {\n await rm(path, { force: true });\n }\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * fileSync({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function fileSync(options: FileOptions): void {\n const { encoding = 'utf8', mode, path, state, update } = options;\n if (state === 'present') {\n const isPresent = __existsSync(path);\n const previousContent = isPresent ? readFileSync(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n writeFileSync(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n chmodSync(path, newMode);\n }\n } else {\n rmSync(path, { force: true });\n }\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface BlockOptions {\n /**\n * Block content to insert\n */\n block: string;\n\n /**\n * Insert position\n */\n insertPosition?: ['after', 'EndOfFile' | RegExp] | ['before', 'BeginningOfFile' | RegExp];\n\n /**\n * The marker builder function that will take either `markerBegin` or `markerEnd`\n *\n * @default '# ${mark} MANAGED BLOCK'\n */\n marker?: (mark: 'Begin' | 'End') => string;\n\n /**\n * File path\n */\n path: string;\n\n /**\n * Block target state\n */\n state?: 'absent' | 'present';\n}\n\nconst EOF = 'EndOfFile';\nconst BOF = 'BeginningOfFile';\nconst insertAt = (str: string, index: number, toInsert: string) => str.slice(0, index) + toInsert + str.slice(index);\nconst matchLast = (string: string, regexp: RegExp) => {\n const matcher = new RegExp(regexp.source, `${regexp.flags}g`);\n let firstIndex = -1;\n let lastIndex = -1;\n let matches;\n\n while (true) {\n matches = matcher.exec(string);\n if (matches == null) {\n break;\n }\n firstIndex = matches.index;\n lastIndex = matcher.lastIndex;\n }\n return { firstIndex, lastIndex };\n};\n\n/**\n * Replace asynchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function block(options: BlockOptions) {\n return file(toFileOptions(options));\n}\n\n/**\n * Replace synchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function blockSync(options: BlockOptions) {\n return fileSync(toFileOptions(options));\n}\n\nfunction toFileOptions(options: BlockOptions): FileOptions {\n const {\n block: blockName,\n insertPosition = ['after', EOF],\n marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`,\n path,\n state = 'present',\n } = options;\n\n const EOL = '\\n';\n const beginBlock = marker('Begin');\n const endBlock = marker('End');\n\n /**\n * @param content\n */\n function findBlock(content: string) {\n const startIndex = content.indexOf(beginBlock);\n const endIndex = content.indexOf(endBlock) + endBlock.length;\n\n return {\n endIndex,\n exists: startIndex !== -1 && endIndex >= 0,\n startIndex,\n };\n }\n\n function apply(fullContent: string, blockContent: string) {\n const found = findBlock(fullContent);\n const remove = state === 'absent';\n const replaceBlock = remove ? '' : beginBlock + EOL + blockContent + EOL + endBlock;\n const [positionDirection, positionAnchor] = insertPosition;\n\n if (found.exists) {\n return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);\n }\n if (remove) {\n return fullContent;\n }\n switch (positionDirection) {\n case 'after': {\n // insert\n if (positionAnchor !== EOF) {\n const { lastIndex } = matchLast(fullContent, positionAnchor);\n if (lastIndex >= 0) {\n return insertAt(fullContent, lastIndex, EOL + replaceBlock);\n }\n }\n\n // end of file\n return fullContent + EOL + replaceBlock;\n }\n case 'before': {\n if (positionAnchor !== BOF) {\n const { firstIndex } = matchLast(fullContent, positionAnchor);\n if (firstIndex >= 0) {\n return insertAt(fullContent, firstIndex, replaceBlock + EOL);\n }\n }\n\n // Beginning of file\n return replaceBlock + EOL + fullContent;\n }\n\n default: {\n throw new Error(`Unsupported position ${String(positionDirection)}`);\n }\n }\n }\n\n return {\n path,\n state: 'present',\n update: (sourceContent) => apply(sourceContent, blockName),\n };\n}\n","import { chmodSync, mkdirSync, rmSync } from 'node:fs';\nimport { chmod, mkdir, rm } from 'node:fs/promises';\n\nimport type { FileMode } from './FileMode.js';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface DirectoryOptions {\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n\n /**\n * Directory path\n */\n readonly path: string;\n\n /**\n * Directory target state\n */\n readonly state: 'absent' | 'present';\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * await directory({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function directory(options: DirectoryOptions): Promise<void> {\n const { mode, path, state } = options;\n const isPresent = await __exists(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n await mkdir(path, { mode: newMode, recursive: true });\n }\n if (newMode != null && isPresent) {\n await chmod(path, newMode);\n }\n } else if (isPresent) {\n await rm(path, { recursive: true });\n }\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * directorySync({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function directorySync(options: DirectoryOptions): void {\n const { mode, path, state } = options;\n const isPresent = __existsSync(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n mkdirSync(path, { mode: newMode, recursive: true });\n }\n if (newMode != null && isPresent) {\n chmodSync(path, newMode);\n }\n } else if (isPresent) {\n rmSync(path, { recursive: true });\n }\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function where content is represented as lines.\n * When the file does not yet exist, the callback receives `undefined`.\n */\n readonly update?: ((content: Array<string> | undefined) => Array<string> | undefined) | undefined;\n}\n\n/**\n * Ensure file is present/absent asynchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * await ignoreFile({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport async function ignoreFile(options: IgnoreFileOptions): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * ignoreFileSync({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport function ignoreFileSync(options: IgnoreFileOptions): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption({ update, ...otherOptions }: IgnoreFileOptions): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const eol = content.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lines = content === '' ? undefined : content.split(eol);\n const updatedLines = update(lines);\n\n return updatedLines == null ? undefined : updatedLines.join(eol);\n },\n };\n}\n","import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\n\nconst defaultExtensions: Array<string> = ['.json', '.yaml', '.yml', '.js', '.cjs', '.mjs', '.ts', '.cts', '.mts'];\n\nexport interface IsConfigPresentOptions {\n /**\n * The name of the application.\n */\n app: string;\n\n /**\n * The directory to look into. Defaults to `process.cwd()`.\n */\n cwd?: string | undefined;\n\n /**\n * The list of extensions to check for.\n */\n extensions?: Array<string> | undefined;\n\n /**\n * The name of the package configuration. Defaults to `app`.\n */\n packageConfig?: string | undefined;\n}\n\n/**\n * Return whether tool configuration exists at `cwd` (cosmiconfig-style).\n *\n * Looks for `.{app}rc`, `.{app}rc.{ext}`, `{app}.config.{ext}` and a matching\n * `package.json` key.\n *\n * @param options\n */\nexport async function isConfigPresent(options: IsConfigPresentOptions): Promise<boolean> {\n const { candidatePaths, packageConfig, packageJsonPath } = toCandidates(options);\n\n const [hasConfigFile, hasPackageConfig] = await Promise.all([\n hasAnyFile(candidatePaths),\n hasPackageConfigFile(packageJsonPath, packageConfig),\n ]);\n\n return hasConfigFile || hasPackageConfig;\n}\n\nexport function isConfigPresentSync(options: IsConfigPresentOptions): boolean {\n const { candidatePaths, packageConfig, packageJsonPath } = toCandidates(options);\n\n for (const candidatePath of candidatePaths) {\n if (__existsSync(candidatePath)) {\n return true;\n }\n }\n\n if (__existsSync(packageJsonPath)) {\n try {\n return hasPackageConfigKey(readFileSync(packageJsonPath, 'utf8'), packageConfig);\n } catch {\n return false;\n }\n }\n\n return false;\n}\n\nasync function hasAnyFile(paths: Array<string>): Promise<boolean> {\n const results = await Promise.all(paths.map((candidatePath) => __exists(candidatePath)));\n\n return results.some(Boolean);\n}\n\nasync function hasPackageConfigFile(packageJsonPath: string, packageConfig: string): Promise<boolean> {\n if (!(await __exists(packageJsonPath))) {\n return false;\n }\n\n try {\n return hasPackageConfigKey(await readFile(packageJsonPath, 'utf8'), packageConfig);\n } catch {\n return false;\n }\n}\n\nfunction hasPackageConfigKey(packageJsonContent: string, packageConfig: string): boolean {\n const packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>;\n const value = packageJson[packageConfig];\n\n return value !== undefined && value !== null && value !== false;\n}\n\nfunction toCandidates({ app, cwd = process.cwd(), extensions = defaultExtensions, packageConfig = app }: IsConfigPresentOptions) {\n const candidatePaths = [path.join(cwd, `.${app}rc`)];\n for (const extension of extensions) {\n candidatePaths.push(path.join(cwd, `.${app}rc${extension}`), path.join(cwd, `${app}.config${extension}`));\n }\n\n return {\n candidatePaths,\n packageConfig,\n packageJsonPath: path.join(cwd, 'package.json'),\n };\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface JSONOption<V = JSONValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: undefined | V) => undefined | V) | undefined;\n}\n\nexport type JSONValue = Array<JSONValue> | boolean | null | number | string | { [key: string]: JSONValue };\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function json<Value>(options: JSONOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function jsonSync<Value>(options: JSONOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: JSONOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const jsonValue = content === '' ? undefined : (JSON.parse(content) as Value);\n\n return JSON.stringify(update(jsonValue));\n },\n };\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import YAML from 'yaml';\n\nimport { file, type FileOptions, fileSync } from './file.js';\n\nexport interface YAMLOption<V = YAMLValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: undefined | V) => undefined | V) | undefined;\n}\n\nexport type YAMLValue = Array<YAMLValue> | boolean | null | number | string | { [key: string]: YAMLValue };\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function yaml<Value>(options: YAMLOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function yamlSync<Value>(options: YAMLOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: YAMLOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const yamlValue = content === '' ? undefined : (YAML.parse(content) as Value);\n\n return YAML.stringify(update(yamlValue));\n },\n };\n}\n","import { spawn, spawnSync } from 'node:child_process';\n\nexport interface ExecOptions {\n /**\n * Current working directory\n */\n cwd?: string;\n\n /**\n * Stdio options\n */\n stdio?: 'ignore' | 'inherit' | 'pipe';\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n */\nexport async function exec(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): Promise<{ stderr: string; stdout: string }> {\n return new Promise((resolve, reject) => {\n const encoding = 'utf8';\n const child = spawn(command, args, { ...options });\n let stdout = '';\n let stderr = '';\n\n // Capture the stdout and stderr streams\n if (child.stdout != null) {\n child.stdout.on('data', (data) => {\n // eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access\n stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\n // eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access\n stderr += data.toString(encoding);\n });\n }\n // Handle process exit\n child.on('close', (_code) => {\n resolve({ stderr, stdout });\n });\n\n // Handle errors\n child.on('error', reject);\n });\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n * @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`\n */\nexport function execSync(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): { stderr: string; stdout: string } {\n const result = spawnSync(command, args, { ...options });\n const encoding = 'utf8';\n\n return { stderr: result.stderr.toString(encoding), stdout: result.stdout.toString(encoding) };\n}\n","import { exec, execSync } from './exec.js';\n\nexport interface YarnConfigOptions {\n /**\n * Configuration key\n */\n readonly key: string;\n\n /**\n * Option target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnConfig({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport async function yarnConfig(options: YarnConfigOptions): Promise<void> {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = await exec('yarn', ['config', 'get', key]);\n await exec('yarn', ['config', 'set', key, String(update == null ? '' : update(stdout))]);\n } else {\n await exec('yarn', ['config', 'unset', key]);\n }\n}\n\n/**\n * Synchronous version of {@link yarnConfig}\n *\n * @param options\n * @example\n * yarnConfigSync({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport function yarnConfigSync(options: YarnConfigOptions) {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = execSync('yarn', ['config', 'get', key]);\n execSync('yarn', ['config', 'set', key, String(update == null ? '' : update(stdout))]);\n } else {\n execSync('yarn', ['config', 'unset', key]);\n }\n}\n","import { exec, execSync } from './exec.js';\n\nexport type YarnVersionKind = 'berry' | 'classic';\n\nexport interface YarnVersionOptions {\n /**\n * Option target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * Version mapping function\n *\n */\n readonly update?: (() => undefined | YarnVersionKind) | undefined;\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnVersion({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport async function yarnVersion(options: YarnVersionOptions): Promise<void> {\n const { state, update } = options;\n if (state === 'present') {\n await exec('yarn', ['set', 'version', String(update == null ? 'berry' : update())]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n\n/**\n * Synchronous version of {@link yarnVersion}\n *\n * @param options\n * @example\n * yarnVersionSync({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport function yarnVersionSync(options: YarnVersionOptions) {\n const { state, update } = options;\n if (state === 'present') {\n execSync('yarn', ['set', 'version', String(update == null ? 'berry' : update())]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n"],"mappings":";;;;;;AAGA,eAAsB,SAAS,MAAc;CAC3C,IAAI;EACF,MAAM,OAAO,MAAM,UAAU,IAAI;EACjC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACRA,SAAgB,aAAa,MAAc;CACzC,IAAI;EACF,WAAW,MAAM,UAAU,IAAI;EAC/B,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACPA,SAAgB,SAAS,MAAgD;CACvE,OAAO,QAAQ,OACX,OAEE,WAAW,KAAK,OAAO,KAAO,KAAO,EAAK,IACxC,WAAW,KAAK,OAAO,IAAO,IAAO,CAAK,IAC1C,WAAW,KAAK,OAAO,GAAO,GAAO,CAAK;AAEpD;AAEA,SAAS,WAAW,eAA8C,MAAc,OAAe,SAAyB;CACtH,QACG,eAAe,SAAS,OAAO,OAAO,MACpC,eAAe,UAAU,OAAO,QAAQ,MACxC,eAAe,YAAY,OAAO,UAAU;AAEnD;;;;;;;;;;;;;;;;;;;;;;ACsCA,eAAsB,KAAK,SAAqC;CAC9D,MAAM,EAAE,WAAW,QAAQ,MAAM,MAAM,OAAO,WAAW;CACzD,IAAI,UAAU,WAAW;EACvB,MAAM,YAAY,MAAM,SAAS,IAAI;EACrC,MAAM,kBAAkB,YAAY,MAAM,SAAS,MAAM,QAAQ,IAAI;EACrE,MAAM,aAAa,UAAU,OAAQ,YAAY,KAAA,IAAY,KAAM,OAAO,eAAe;EACzF,MAAM,UAAU,SAAS,IAAI;EAC7B,IAAI,cAAc,MAChB,MAAM,UAAU,MAAM,YAAY;GAAE;GAAU,MAAM;EAAQ,CAAC;EAE/D,IAAI,WAAW,SAAS,aAAa,cAAc,OACjD,MAAM,MAAM,MAAM,OAAO;CAE7B,OACE,MAAM,GAAG,MAAM,EAAE,OAAO,KAA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;EAAO;EAAW,OAAO,UAAU,OAAO,UAAU,OAAO,CAAC;CAAC,CAAC;MAGlF,MAAM,IAAI,MAAM,iBAAiB;AAErC;;;;;;;;;;;AAYA,SAAgB,gBAAgB,SAA6B;CAC3D,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,SAAS,QAAQ;EAAC;EAAO;EAAW,OAAO,UAAU,OAAO,UAAU,OAAO,CAAC;CAAC,CAAC;MAGhF,MAAM,IAAI,MAAM,iBAAiB;AAErC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["toFileOption","path","toFileOption"],"sources":["../src/__exists.ts","../src/__existsSync.ts","../src/__toMode.ts","../src/file.ts","../src/internal/resolveCommentStyle.ts","../src/block.ts","../src/directory.ts","../src/ignoreFile.ts","../src/isConfigPresent.ts","../src/json.ts","../src/meta.ts","../src/yaml.ts","../src/exec.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"sourcesContent":["import { constants } from 'node:fs';\nimport { access } from 'node:fs/promises';\n\nexport async function __exists(path: string) {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import { accessSync, constants } from 'node:fs';\n\nexport function __existsSync(path: string) {\n try {\n accessSync(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import type { FileMode, FilePermissionSet } from './FileMode.js';\n\nexport function __toMode(mode: FileMode | undefined): number | undefined {\n return mode == null\n ? mode\n : (\n toModeFlag(mode.owner, 0o400, 0o200, 0o100)\n | toModeFlag(mode.group, 0o040, 0o020, 0o010)\n | toModeFlag(mode.other, 0o004, 0o002, 0o001)\n );\n}\n\nfunction toModeFlag(permissionSet: FilePermissionSet | undefined, read: number, write: number, execute: number): number {\n return (\n (permissionSet?.read === true ? read : 0)\n | (permissionSet?.write === true ? write : 0)\n | (permissionSet?.execute === true ? execute : 0)\n );\n}\n","import { chmodSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { chmod, readFile, rm, writeFile } from 'node:fs/promises';\n\nimport type { FileMode } from './FileMode.js';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface FileOptions {\n /**\n * File encoding\n */\n readonly encoding?: BufferEncoding;\n\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n\n /**\n * File path\n */\n readonly path: string;\n\n /**\n * File target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * await file({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function file(options: FileOptions): Promise<void> {\n const { encoding = 'utf8', mode, path, state, update } = options;\n if (state === 'present') {\n const isPresent = await __exists(path);\n const previousContent = isPresent ? await readFile(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n await writeFile(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n await chmod(path, newMode);\n }\n } else {\n await rm(path, { force: true });\n }\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * fileSync({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function fileSync(options: FileOptions): void {\n const { encoding = 'utf8', mode, path, state, update } = options;\n if (state === 'present') {\n const isPresent = __existsSync(path);\n const previousContent = isPresent ? readFileSync(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n writeFileSync(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n chmodSync(path, newMode);\n }\n } else {\n rmSync(path, { force: true });\n }\n}\n","import nodePath from 'node:path';\n\nexport type ResolvedCommentStyle = '#' | '/*' | '//' | '<!--';\n\n/* cspell:ignore containerfile */\nconst HASH_BASENAMES = new Set(['containerfile', 'dockerfile', 'gemfile', 'makefile']);\n\nconst HTML_EXTENSIONS = new Set(['htm', 'html', 'md', 'mdx', 'svg', 'xml']);\nconst LINE_EXTENSIONS = new Set([\n 'c',\n 'cjs',\n 'cpp',\n 'cs',\n 'cts',\n 'go',\n 'h',\n 'java',\n 'js',\n 'jsx',\n 'kt',\n 'mjs',\n 'mts',\n 'rs',\n 'swift',\n 'ts',\n 'tsx',\n]);\nconst BLOCK_EXTENSIONS = new Set(['css', 'less', 'sass', 'scss']);\n\n/**\n * Resolve comment style from the file path when `commentStyle` is `'auto'`.\n *\n * @param path File path used to infer the comment style.\n */\nexport function resolveCommentStyle(path: string): ResolvedCommentStyle {\n const basename = nodePath.basename(path);\n const basenameLower = basename.toLowerCase();\n\n if (basename.startsWith('.') || HASH_BASENAMES.has(basenameLower)) {\n return '#';\n }\n\n const extension = nodePath.extname(basename).slice(1).toLowerCase();\n if (HTML_EXTENSIONS.has(extension)) {\n return '<!--';\n }\n if (LINE_EXTENSIONS.has(extension)) {\n return '//';\n }\n if (BLOCK_EXTENSIONS.has(extension)) {\n return '/*';\n }\n\n // py, rb, sh, toml, yaml, yml, json, no extension, and unknown → #\n return '#';\n}\n","import { file, type FileOptions, fileSync } from './file.js';\nimport { resolveCommentStyle, type ResolvedCommentStyle } from './internal/resolveCommentStyle.js';\n\nexport type BlockCommentStyle = '#' | '/*' | '//' | '<!--' | 'auto';\n\nexport interface BlockMarkerOptions {\n /**\n * Comment opener used for the marker lines: `'auto'` (from file name),\n * `'#'`, `'//'`, slash-star, or `'<!--'`.\n *\n * @default 'auto'\n */\n commentStyle?: BlockCommentStyle;\n\n /**\n * Identity after `BEGIN:` / `END:`, so multiple blocks in one file do not collide.\n *\n * @default 'managed-block'\n */\n topic?: string;\n}\n\nexport interface BlockOptions {\n /**\n * Block content to insert\n */\n block: string;\n\n /**\n * Insert position\n */\n insertPosition?: ['after', 'EndOfFile' | RegExp] | ['before', 'BeginningOfFile' | RegExp];\n\n /**\n * Marker configuration, or a function that returns the full marker line.\n *\n * @default `{ commentStyle: 'auto', topic: 'managed-block' }`\n */\n marker?: ((mark: 'Begin' | 'End') => string) | BlockMarkerOptions;\n\n /**\n * File path\n */\n path: string;\n\n /**\n * Block target state\n */\n state?: 'absent' | 'present';\n}\n\nconst EOF = 'EndOfFile';\nconst BOF = 'BeginningOfFile';\nconst DEFAULT_TOPIC = 'managed-block';\n\nconst insertAt = (str: string, index: number, toInsert: string) => str.slice(0, index) + toInsert + str.slice(index);\nconst matchLast = (string: string, regexp: RegExp) => {\n const matcher = new RegExp(regexp.source, `${regexp.flags}g`);\n let firstIndex = -1;\n let lastIndex = -1;\n let matches;\n\n while (true) {\n matches = matcher.exec(string);\n if (matches == null) {\n break;\n }\n firstIndex = matches.index;\n lastIndex = matcher.lastIndex;\n }\n return { firstIndex, lastIndex };\n};\n\n/**\n * Replace asynchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function block(options: BlockOptions) {\n return file(toFileOptions(options));\n}\n\n/**\n * Replace synchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function blockSync(options: BlockOptions) {\n return fileSync(toFileOptions(options));\n}\n\nfunction formatMarker(style: ResolvedCommentStyle, mark: 'Begin' | 'End', topic: string): string {\n const inner = `${mark.toUpperCase()}:${topic}`;\n switch (style) {\n case '#': {\n return `# ${inner}`;\n }\n case '/*': {\n return `/* ${inner} */`;\n }\n case '//': {\n return `// ${inner}`;\n }\n case '<!--': {\n return `<!-- ${inner} -->`;\n }\n default: {\n throw new Error(`Unsupported comment style ${String(style)}`);\n }\n }\n}\n\nfunction toFileOptions(options: BlockOptions): FileOptions {\n const { block: blockName, insertPosition = ['after', EOF], marker, path, state = 'present' } = options;\n\n const EOL = '\\n';\n const markerFn = toMarkerFn(marker, path);\n const beginBlock = markerFn('Begin');\n const endBlock = markerFn('End');\n\n /**\n * @param content\n */\n function findBlock(content: string) {\n const startIndex = content.indexOf(beginBlock);\n const endIndex = content.indexOf(endBlock) + endBlock.length;\n\n return {\n endIndex,\n exists: startIndex !== -1 && endIndex >= 0,\n startIndex,\n };\n }\n\n function apply(fullContent: string, blockContent: string) {\n const found = findBlock(fullContent);\n const remove = state === 'absent';\n const replaceBlock = remove ? '' : beginBlock + EOL + blockContent + EOL + endBlock;\n const [positionDirection, positionAnchor] = insertPosition;\n\n if (found.exists) {\n return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);\n }\n if (remove) {\n return fullContent;\n }\n switch (positionDirection) {\n case 'after': {\n // insert\n if (positionAnchor !== EOF) {\n const { lastIndex } = matchLast(fullContent, positionAnchor);\n if (lastIndex >= 0) {\n return insertAt(fullContent, lastIndex, EOL + replaceBlock);\n }\n }\n\n // end of file\n return fullContent + EOL + replaceBlock;\n }\n case 'before': {\n if (positionAnchor !== BOF) {\n const { firstIndex } = matchLast(fullContent, positionAnchor);\n if (firstIndex >= 0) {\n return insertAt(fullContent, firstIndex, replaceBlock + EOL);\n }\n }\n\n // Beginning of file\n return replaceBlock + EOL + fullContent;\n }\n\n default: {\n throw new Error(`Unsupported position ${String(positionDirection)}`);\n }\n }\n }\n\n return {\n path,\n state: 'present',\n update: (sourceContent) => apply(sourceContent, blockName),\n };\n}\n\nfunction toMarkerFn(marker: BlockOptions['marker'], path: string): (mark: 'Begin' | 'End') => string {\n if (typeof marker === 'function') {\n return marker;\n }\n\n const commentStyle = marker?.commentStyle ?? 'auto';\n const topic = marker?.topic ?? DEFAULT_TOPIC;\n const resolvedStyle = commentStyle === 'auto' ? resolveCommentStyle(path) : commentStyle;\n\n return (mark) => formatMarker(resolvedStyle, mark, topic);\n}\n","import { chmodSync, mkdirSync, rmSync } from 'node:fs';\nimport { chmod, mkdir, rm } from 'node:fs/promises';\n\nimport type { FileMode } from './FileMode.js';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface DirectoryOptions {\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n\n /**\n * Directory path\n */\n readonly path: string;\n\n /**\n * Directory target state\n */\n readonly state: 'absent' | 'present';\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * await directory({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function directory(options: DirectoryOptions): Promise<void> {\n const { mode, path, state } = options;\n const isPresent = await __exists(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n await mkdir(path, { mode: newMode, recursive: true });\n }\n if (newMode != null && isPresent) {\n await chmod(path, newMode);\n }\n } else if (isPresent) {\n await rm(path, { recursive: true });\n }\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * directorySync({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function directorySync(options: DirectoryOptions): void {\n const { mode, path, state } = options;\n const isPresent = __existsSync(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n mkdirSync(path, { mode: newMode, recursive: true });\n }\n if (newMode != null && isPresent) {\n chmodSync(path, newMode);\n }\n } else if (isPresent) {\n rmSync(path, { recursive: true });\n }\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function where content is represented as lines.\n * When the file does not yet exist, the callback receives `undefined`.\n */\n readonly update?: ((content: Array<string> | undefined) => Array<string> | undefined) | undefined;\n}\n\n/**\n * Ensure file is present/absent asynchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * await ignoreFile({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport async function ignoreFile(options: IgnoreFileOptions): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * ignoreFileSync({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport function ignoreFileSync(options: IgnoreFileOptions): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption({ update, ...otherOptions }: IgnoreFileOptions): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const eol = content.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lines = content === '' ? undefined : content.split(eol);\n const updatedLines = update(lines);\n\n return updatedLines == null ? undefined : updatedLines.join(eol);\n },\n };\n}\n","import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\n\nconst defaultExtensions: Array<string> = ['.json', '.yaml', '.yml', '.js', '.cjs', '.mjs', '.ts', '.cts', '.mts'];\n\nexport interface IsConfigPresentOptions {\n /**\n * The name of the application.\n */\n app: string;\n\n /**\n * The directory to look into. Defaults to `process.cwd()`.\n */\n cwd?: string | undefined;\n\n /**\n * The list of extensions to check for.\n */\n extensions?: Array<string> | undefined;\n\n /**\n * The name of the package configuration. Defaults to `app`.\n */\n packageConfig?: string | undefined;\n}\n\n/**\n * Return whether tool configuration exists at `cwd` (cosmiconfig-style).\n *\n * Looks for `.{app}rc`, `.{app}rc.{ext}`, `{app}.config.{ext}` and a matching\n * `package.json` key.\n *\n * @param options\n */\nexport async function isConfigPresent(options: IsConfigPresentOptions): Promise<boolean> {\n const { candidatePaths, packageConfig, packageJsonPath } = toCandidates(options);\n\n const [hasConfigFile, hasPackageConfig] = await Promise.all([\n hasAnyFile(candidatePaths),\n hasPackageConfigFile(packageJsonPath, packageConfig),\n ]);\n\n return hasConfigFile || hasPackageConfig;\n}\n\nexport function isConfigPresentSync(options: IsConfigPresentOptions): boolean {\n const { candidatePaths, packageConfig, packageJsonPath } = toCandidates(options);\n\n for (const candidatePath of candidatePaths) {\n if (__existsSync(candidatePath)) {\n return true;\n }\n }\n\n if (__existsSync(packageJsonPath)) {\n try {\n return hasPackageConfigKey(readFileSync(packageJsonPath, 'utf8'), packageConfig);\n } catch {\n return false;\n }\n }\n\n return false;\n}\n\nasync function hasAnyFile(paths: Array<string>): Promise<boolean> {\n const results = await Promise.all(paths.map((candidatePath) => __exists(candidatePath)));\n\n return results.some(Boolean);\n}\n\nasync function hasPackageConfigFile(packageJsonPath: string, packageConfig: string): Promise<boolean> {\n if (!(await __exists(packageJsonPath))) {\n return false;\n }\n\n try {\n return hasPackageConfigKey(await readFile(packageJsonPath, 'utf8'), packageConfig);\n } catch {\n return false;\n }\n}\n\nfunction hasPackageConfigKey(packageJsonContent: string, packageConfig: string): boolean {\n const packageJson = JSON.parse(packageJsonContent) as Record<string, unknown>;\n const value = packageJson[packageConfig];\n\n return value !== undefined && value !== null && value !== false;\n}\n\nfunction toCandidates({ app, cwd = process.cwd(), extensions = defaultExtensions, packageConfig = app }: IsConfigPresentOptions) {\n const candidatePaths = [path.join(cwd, `.${app}rc`)];\n for (const extension of extensions) {\n candidatePaths.push(path.join(cwd, `.${app}rc${extension}`), path.join(cwd, `${app}.config${extension}`));\n }\n\n return {\n candidatePaths,\n packageConfig,\n packageJsonPath: path.join(cwd, 'package.json'),\n };\n}\n","import { file, type FileOptions, fileSync } from './file.js';\n\nexport interface JSONOption<V = JSONValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: undefined | V) => undefined | V) | undefined;\n}\n\nexport type JSONValue = Array<JSONValue> | boolean | null | number | string | { [key: string]: JSONValue };\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function json<Value>(options: JSONOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function jsonSync<Value>(options: JSONOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: JSONOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const jsonValue = content === '' ? undefined : (JSON.parse(content) as Value);\n\n return JSON.stringify(update(jsonValue));\n },\n };\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n buildNumber: (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n});\n","import YAML from 'yaml';\n\nimport { file, type FileOptions, fileSync } from './file.js';\n\nexport interface YAMLOption<V = YAMLValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: undefined | V) => undefined | V) | undefined;\n}\n\nexport type YAMLValue = Array<YAMLValue> | boolean | null | number | string | { [key: string]: YAMLValue };\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function yaml<Value>(options: YAMLOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function yamlSync<Value>(options: YAMLOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: YAMLOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const yamlValue = content === '' ? undefined : (YAML.parse(content) as Value);\n\n return YAML.stringify(update(yamlValue));\n },\n };\n}\n","import { spawn, spawnSync } from 'node:child_process';\n\nexport interface ExecOptions {\n /**\n * Current working directory\n */\n cwd?: string;\n\n /**\n * Stdio options\n */\n stdio?: 'ignore' | 'inherit' | 'pipe';\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n */\nexport async function exec(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): Promise<{ stderr: string; stdout: string }> {\n return new Promise((resolve, reject) => {\n const encoding = 'utf8';\n const child = spawn(command, args, { ...options });\n let stdout = '';\n let stderr = '';\n\n // Capture the stdout and stderr streams\n if (child.stdout != null) {\n child.stdout.on('data', (data) => {\n // eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access\n stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\n // eslint-disable-next-line ts/no-unsafe-call, ts/no-unsafe-member-access\n stderr += data.toString(encoding);\n });\n }\n // Handle process exit\n child.on('close', (_code) => {\n resolve({ stderr, stdout });\n });\n\n // Handle errors\n child.on('error', reject);\n });\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n * @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`\n */\nexport function execSync(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): { stderr: string; stdout: string } {\n const result = spawnSync(command, args, { ...options });\n const encoding = 'utf8';\n\n return { stderr: result.stderr.toString(encoding), stdout: result.stdout.toString(encoding) };\n}\n","import { exec, execSync } from './exec.js';\n\nexport interface YarnConfigOptions {\n /**\n * Configuration key\n */\n readonly key: string;\n\n /**\n * Option target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnConfig({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport async function yarnConfig(options: YarnConfigOptions): Promise<void> {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = await exec('yarn', ['config', 'get', key]);\n await exec('yarn', ['config', 'set', key, String(update == null ? '' : update(stdout))]);\n } else {\n await exec('yarn', ['config', 'unset', key]);\n }\n}\n\n/**\n * Synchronous version of {@link yarnConfig}\n *\n * @param options\n * @example\n * yarnConfigSync({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport function yarnConfigSync(options: YarnConfigOptions) {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = execSync('yarn', ['config', 'get', key]);\n execSync('yarn', ['config', 'set', key, String(update == null ? '' : update(stdout))]);\n } else {\n execSync('yarn', ['config', 'unset', key]);\n }\n}\n","import { exec, execSync } from './exec.js';\n\nexport type YarnVersionKind = 'berry' | 'classic';\n\nexport interface YarnVersionOptions {\n /**\n * Option target state\n */\n readonly state: 'absent' | 'present';\n\n /**\n * Version mapping function\n *\n */\n readonly update?: (() => undefined | YarnVersionKind) | undefined;\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnVersion({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport async function yarnVersion(options: YarnVersionOptions): Promise<void> {\n const { state, update } = options;\n if (state === 'present') {\n await exec('yarn', ['set', 'version', String(update == null ? 'berry' : update())]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n\n/**\n * Synchronous version of {@link yarnVersion}\n *\n * @param options\n * @example\n * yarnVersionSync({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport function yarnVersionSync(options: YarnVersionOptions) {\n const { state, update } = options;\n if (state === 'present') {\n execSync('yarn', ['set', 'version', String(update == null ? 'berry' : update())]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n"],"mappings":";;;;;;AAGA,eAAsB,SAAS,MAAc;CAC3C,IAAI;EACF,MAAM,OAAO,MAAM,UAAU,IAAI;EACjC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACRA,SAAgB,aAAa,MAAc;CACzC,IAAI;EACF,WAAW,MAAM,UAAU,IAAI;EAC/B,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACPA,SAAgB,SAAS,MAAgD;CACvE,OAAO,QAAQ,OACX,OAEE,WAAW,KAAK,OAAO,KAAO,KAAO,EAAK,IACxC,WAAW,KAAK,OAAO,IAAO,IAAO,CAAK,IAC1C,WAAW,KAAK,OAAO,GAAO,GAAO,CAAK;AAEpD;AAEA,SAAS,WAAW,eAA8C,MAAc,OAAe,SAAyB;CACtH,QACG,eAAe,SAAS,OAAO,OAAO,MACpC,eAAe,UAAU,OAAO,QAAQ,MACxC,eAAe,YAAY,OAAO,UAAU;AAEnD;;;;;;;;;;;;;;;;;;;;;;ACsCA,eAAsB,KAAK,SAAqC;CAC9D,MAAM,EAAE,WAAW,QAAQ,MAAM,MAAM,OAAO,WAAW;CACzD,IAAI,UAAU,WAAW;EACvB,MAAM,YAAY,MAAM,SAAS,IAAI;EACrC,MAAM,kBAAkB,YAAY,MAAM,SAAS,MAAM,QAAQ,IAAI;EACrE,MAAM,aAAa,UAAU,OAAQ,YAAY,KAAA,IAAY,KAAM,OAAO,eAAe;EACzF,MAAM,UAAU,S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GAAU;GAAO;EAAG,CAAC;EAC1D,SAAS,QAAQ;GAAC;GAAU;GAAO;GAAK,OAAO,UAAU,OAAO,KAAK,OAAO,MAAM,CAAC;EAAC,CAAC;CACvF,OACE,SAAS,QAAQ;EAAC;EAAU;EAAS;CAAG,CAAC;AAE7C;;;;;;;;;;;;;ACjCA,eAAsB,YAAY,SAA4C;CAC5E,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,MAAM,KAAK,QAAQ;EAAC;EAAO;EAAW,OAAO,UAAU,OAAO,UAAU,OAAO,CAAC;CAAC,CAAC;MAGlF,MAAM,IAAI,MAAM,iBAAiB;AAErC;;;;;;;;;;;AAYA,SAAgB,gBAAgB,SAA6B;CAC3D,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,SAAS,QAAQ;EAAC;EAAO;EAAW,OAAO,UAAU,OAAO,UAAU,OAAO,CAAC;CAAC,CAAC;MAGhF,MAAM,IAAI,MAAM,iBAAiB;AAErC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/configurator-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Core library for @w5s/configurator-core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "d39c8e42e2e9cb34d05ea9e23c757383dd30795a"
|
|
50
50
|
}
|
package/src/block.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { file, type FileOptions, fileSync } from './file.js';
|
|
2
|
+
import { resolveCommentStyle, type ResolvedCommentStyle } from './internal/resolveCommentStyle.js';
|
|
3
|
+
|
|
4
|
+
export type BlockCommentStyle = '#' | '/*' | '//' | '<!--' | 'auto';
|
|
5
|
+
|
|
6
|
+
export interface BlockMarkerOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Comment opener used for the marker lines: `'auto'` (from file name),
|
|
9
|
+
* `'#'`, `'//'`, slash-star, or `'<!--'`.
|
|
10
|
+
*
|
|
11
|
+
* @default 'auto'
|
|
12
|
+
*/
|
|
13
|
+
commentStyle?: BlockCommentStyle;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Identity after `BEGIN:` / `END:`, so multiple blocks in one file do not collide.
|
|
17
|
+
*
|
|
18
|
+
* @default 'managed-block'
|
|
19
|
+
*/
|
|
20
|
+
topic?: string;
|
|
21
|
+
}
|
|
2
22
|
|
|
3
23
|
export interface BlockOptions {
|
|
4
24
|
/**
|
|
@@ -12,11 +32,11 @@ export interface BlockOptions {
|
|
|
12
32
|
insertPosition?: ['after', 'EndOfFile' | RegExp] | ['before', 'BeginningOfFile' | RegExp];
|
|
13
33
|
|
|
14
34
|
/**
|
|
15
|
-
*
|
|
35
|
+
* Marker configuration, or a function that returns the full marker line.
|
|
16
36
|
*
|
|
17
|
-
* @default '
|
|
37
|
+
* @default `{ commentStyle: 'auto', topic: 'managed-block' }`
|
|
18
38
|
*/
|
|
19
|
-
marker?: (mark: 'Begin' | 'End') => string;
|
|
39
|
+
marker?: ((mark: 'Begin' | 'End') => string) | BlockMarkerOptions;
|
|
20
40
|
|
|
21
41
|
/**
|
|
22
42
|
* File path
|
|
@@ -31,6 +51,8 @@ export interface BlockOptions {
|
|
|
31
51
|
|
|
32
52
|
const EOF = 'EndOfFile';
|
|
33
53
|
const BOF = 'BeginningOfFile';
|
|
54
|
+
const DEFAULT_TOPIC = 'managed-block';
|
|
55
|
+
|
|
34
56
|
const insertAt = (str: string, index: number, toInsert: string) => str.slice(0, index) + toInsert + str.slice(index);
|
|
35
57
|
const matchLast = (string: string, regexp: RegExp) => {
|
|
36
58
|
const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
|
|
@@ -75,18 +97,34 @@ export function blockSync(options: BlockOptions) {
|
|
|
75
97
|
return fileSync(toFileOptions(options));
|
|
76
98
|
}
|
|
77
99
|
|
|
100
|
+
function formatMarker(style: ResolvedCommentStyle, mark: 'Begin' | 'End', topic: string): string {
|
|
101
|
+
const inner = `${mark.toUpperCase()}:${topic}`;
|
|
102
|
+
switch (style) {
|
|
103
|
+
case '#': {
|
|
104
|
+
return `# ${inner}`;
|
|
105
|
+
}
|
|
106
|
+
case '/*': {
|
|
107
|
+
return `/* ${inner} */`;
|
|
108
|
+
}
|
|
109
|
+
case '//': {
|
|
110
|
+
return `// ${inner}`;
|
|
111
|
+
}
|
|
112
|
+
case '<!--': {
|
|
113
|
+
return `<!-- ${inner} -->`;
|
|
114
|
+
}
|
|
115
|
+
default: {
|
|
116
|
+
throw new Error(`Unsupported comment style ${String(style)}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
78
121
|
function toFileOptions(options: BlockOptions): FileOptions {
|
|
79
|
-
const {
|
|
80
|
-
block: blockName,
|
|
81
|
-
insertPosition = ['after', EOF],
|
|
82
|
-
marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`,
|
|
83
|
-
path,
|
|
84
|
-
state = 'present',
|
|
85
|
-
} = options;
|
|
122
|
+
const { block: blockName, insertPosition = ['after', EOF], marker, path, state = 'present' } = options;
|
|
86
123
|
|
|
87
124
|
const EOL = '\n';
|
|
88
|
-
const
|
|
89
|
-
const
|
|
125
|
+
const markerFn = toMarkerFn(marker, path);
|
|
126
|
+
const beginBlock = markerFn('Begin');
|
|
127
|
+
const endBlock = markerFn('End');
|
|
90
128
|
|
|
91
129
|
/**
|
|
92
130
|
* @param content
|
|
@@ -151,3 +189,15 @@ function toFileOptions(options: BlockOptions): FileOptions {
|
|
|
151
189
|
update: (sourceContent) => apply(sourceContent, blockName),
|
|
152
190
|
};
|
|
153
191
|
}
|
|
192
|
+
|
|
193
|
+
function toMarkerFn(marker: BlockOptions['marker'], path: string): (mark: 'Begin' | 'End') => string {
|
|
194
|
+
if (typeof marker === 'function') {
|
|
195
|
+
return marker;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const commentStyle = marker?.commentStyle ?? 'auto';
|
|
199
|
+
const topic = marker?.topic ?? DEFAULT_TOPIC;
|
|
200
|
+
const resolvedStyle = commentStyle === 'auto' ? resolveCommentStyle(path) : commentStyle;
|
|
201
|
+
|
|
202
|
+
return (mark) => formatMarker(resolvedStyle, mark, topic);
|
|
203
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import nodePath from 'node:path';
|
|
2
|
+
|
|
3
|
+
export type ResolvedCommentStyle = '#' | '/*' | '//' | '<!--';
|
|
4
|
+
|
|
5
|
+
/* cspell:ignore containerfile */
|
|
6
|
+
const HASH_BASENAMES = new Set(['containerfile', 'dockerfile', 'gemfile', 'makefile']);
|
|
7
|
+
|
|
8
|
+
const HTML_EXTENSIONS = new Set(['htm', 'html', 'md', 'mdx', 'svg', 'xml']);
|
|
9
|
+
const LINE_EXTENSIONS = new Set([
|
|
10
|
+
'c',
|
|
11
|
+
'cjs',
|
|
12
|
+
'cpp',
|
|
13
|
+
'cs',
|
|
14
|
+
'cts',
|
|
15
|
+
'go',
|
|
16
|
+
'h',
|
|
17
|
+
'java',
|
|
18
|
+
'js',
|
|
19
|
+
'jsx',
|
|
20
|
+
'kt',
|
|
21
|
+
'mjs',
|
|
22
|
+
'mts',
|
|
23
|
+
'rs',
|
|
24
|
+
'swift',
|
|
25
|
+
'ts',
|
|
26
|
+
'tsx',
|
|
27
|
+
]);
|
|
28
|
+
const BLOCK_EXTENSIONS = new Set(['css', 'less', 'sass', 'scss']);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolve comment style from the file path when `commentStyle` is `'auto'`.
|
|
32
|
+
*
|
|
33
|
+
* @param path File path used to infer the comment style.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveCommentStyle(path: string): ResolvedCommentStyle {
|
|
36
|
+
const basename = nodePath.basename(path);
|
|
37
|
+
const basenameLower = basename.toLowerCase();
|
|
38
|
+
|
|
39
|
+
if (basename.startsWith('.') || HASH_BASENAMES.has(basenameLower)) {
|
|
40
|
+
return '#';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const extension = nodePath.extname(basename).slice(1).toLowerCase();
|
|
44
|
+
if (HTML_EXTENSIONS.has(extension)) {
|
|
45
|
+
return '<!--';
|
|
46
|
+
}
|
|
47
|
+
if (LINE_EXTENSIONS.has(extension)) {
|
|
48
|
+
return '//';
|
|
49
|
+
}
|
|
50
|
+
if (BLOCK_EXTENSIONS.has(extension)) {
|
|
51
|
+
return '/*';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// py, rb, sh, toml, yaml, yml, json, no extension, and unknown → #
|
|
55
|
+
return '#';
|
|
56
|
+
}
|