@w5s/configurator-core 1.0.0-alpha.10 → 1.0.0-alpha.11
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ignoreFile.ts +1 -1
- package/src/json.ts +1 -1
- package/src/yaml.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -348,7 +348,7 @@ function toFileOption$1({ update, ...otherOptions }) {
|
|
|
348
348
|
const meta = Object.freeze({
|
|
349
349
|
buildNumber: 1,
|
|
350
350
|
name: "@w5s/configurator-core",
|
|
351
|
-
version: "1.0.0-alpha.
|
|
351
|
+
version: "1.0.0-alpha.11"
|
|
352
352
|
});
|
|
353
353
|
//#endregion
|
|
354
354
|
//#region src/yaml.ts
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["constants","constants","toFileOption","toFileOption","yaml","YAML"],"sources":["../src/__exists.ts","../src/__existsSync.ts","../src/__toMode.ts","../src/file.ts","../src/block.ts","../src/directory.ts","../src/ignoreFile.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: string[] | undefined) => 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 { 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 = boolean | JSONValue[] | 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: 1 as number, // (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 = boolean | null | number | string | YAMLValue[] | { [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 stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\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', String(key)]);\n await exec('yarn', ['config', 'set', String(key), String(update == null ? '' : update(stdout))]);\n } else {\n await exec('yarn', ['config', 'unset']);\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', String(key)]);\n execSync('yarn', ['config', 'set', String(key), String(update == null ? '' : update(stdout))]);\n } else {\n execSync('yarn', ['config', 'unset']);\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,GAAA,iBAAA,OAAA,CAAa,MAAMA,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,Q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O,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":["constants","constants","toFileOption","toFileOption","yaml","YAML"],"sources":["../src/__exists.ts","../src/__existsSync.ts","../src/__toMode.ts","../src/file.ts","../src/block.ts","../src/directory.ts","../src/ignoreFile.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 { 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: 1 as number, // (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 stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\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', String(key)]);\n await exec('yarn', ['config', 'set', String(key), String(update == null ? '' : update(stdout))]);\n } else {\n await exec('yarn', ['config', 'unset']);\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', String(key)]);\n execSync('yarn', ['config', 'set', String(key), String(update == null ? '' : update(stdout))]);\n } else {\n execSync('yarn', ['config', 'unset']);\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,GAAA,iBAAA,OAAA,CAAa,MAAMA,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,IAAI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,CAAC;CACjG,OACE,MAAM,KAAK,QAAQ,CAAC,UAAU,OAAO,CAAC;AAE1C;;;;;;;;;;;;AAaA,SAAgB,eAAe,SAA4B;CACzD,MAAM,EAAE,KAAK,OAAO,WAAW;CAC/B,IAAI,UAAU,WAAW;EACvB,MAAM,EAAE,WAAW,SAAS,QAAQ;GAAC;GAAU;GAAO,OAAO,GAAG;EAAC,CAAC;EAClE,SAAS,QAAQ;GAAC;GAAU;GAAO,OAAO,GAAG;GAAG,OAAO,UAAU,OAAO,KAAK,OAAO,MAAM,CAAC;EAAC,CAAC;CAC/F,OACE,SAAS,QAAQ,CAAC,UAAU,OAAO,CAAC;AAExC;;;;;;;;;;;;;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/dist/index.d.cts
CHANGED
|
@@ -199,7 +199,7 @@ interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {
|
|
|
199
199
|
* File content mapping function where content is represented as lines.
|
|
200
200
|
* When the file does not yet exist, the callback receives `undefined`.
|
|
201
201
|
*/
|
|
202
|
-
readonly update?: ((content: string
|
|
202
|
+
readonly update?: ((content: Array<string> | undefined) => Array<string> | undefined) | undefined;
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* Ensure file is present/absent asynchronously with content initialized or modified by line.
|
|
@@ -235,7 +235,7 @@ interface JSONOption<V = JSONValue> extends Omit<FileOptions, 'update'> {
|
|
|
235
235
|
*/
|
|
236
236
|
readonly update?: ((content: undefined | V) => undefined | V) | undefined;
|
|
237
237
|
}
|
|
238
|
-
type JSONValue =
|
|
238
|
+
type JSONValue = Array<JSONValue> | boolean | null | number | string | {
|
|
239
239
|
[key: string]: JSONValue;
|
|
240
240
|
};
|
|
241
241
|
/**
|
|
@@ -265,7 +265,7 @@ interface YAMLOption<V = YAMLValue> extends Omit<FileOptions, 'update'> {
|
|
|
265
265
|
*/
|
|
266
266
|
readonly update?: ((content: undefined | V) => undefined | V) | undefined;
|
|
267
267
|
}
|
|
268
|
-
type YAMLValue = boolean | null | number | string |
|
|
268
|
+
type YAMLValue = Array<YAMLValue> | boolean | null | number | string | {
|
|
269
269
|
[key: string]: YAMLValue;
|
|
270
270
|
};
|
|
271
271
|
/**
|
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/json.ts","../src/meta.ts","../src/yaml.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"mappings":";UAEiB,YAAA;EAAA;;;EAIf,KAAA;EAAA;;;EAKA,cAAA,2BAAyC,MAAA,mCAAyC,MAAM;EAOxF;;;;;EAAA,MAAA,IAAU,IAAA;EA0CI;;;EArCd,IAAA;EAqC6B;;;EAhC7B,KAAA;AAAA;AA6CF;;;;AAA+C;;;;ACzE/C;ADyEA,iBAbgB,KAAA,CAAM,OAAA,EAAS,YAAA,GAAY,OAAA;;;;;;;;;;iBAa3B,SAAA,CAAU,OAAqB,EAAZ,YAAY;;;UCzE9B,QAAA;EDEA;;;EAAA,SCEN,KAAA,GAAQ,iBAAA;EDEjB;;;EAAA,SCGS,KAAA,GAAQ,iBAAA;EDSjB;;;EAAA,SCJS,KAAA,GAAQ,iBAAA;AAAA;AAAA,UAGF,iBAAA;ED2CD;;;EAAA,SCvCL,OAAA;EDuCoB;;;EAAA,SClCpB,IAAA;EDkCgC;AAa3C;;EAb2C,SC7BhC,KAAA;AAAA;;;UCtBM,gBAAA;EFPY;;;EAAA,SEWlB,IAAA,GAAO,QAAQ;EFFxB;;;EAAA,SEOS,IAAA;EFAC;;;EAAA,SEKD,KAAA;AAAA;AFqCX;;;;;;;;AAA2C;AAa3C;;;;AAA+C;;;;ACzE/C;AD4DA,iBEhBsB,SAAA,CAAU,OAAA,EAAS,gBAAA,GAAmB,OAAO;;;;;;;;;;;;;;AD9B/B;AAGpC;;;;iBC6DgB,aAAA,CAAc,OAAyB,EAAhB,gBAAgB;;;UCrEtC,WAAA;EHPY;;;EAAA,SGWlB,QAAA,GAAW,cAAA;EHFpB;;;EAAA,SGOS,IAAA,GAAO,QAAQ;EHAd;;;EAAA,SGKD,IAAA;EHKJ;AAgCP;;EAhCO,SGAI,KAAA;EHgCgC;;;;EAAA,SG1BhC,MAAA,KAAW,OAAA;AAAA;AHuCtB;;;;AAA+C;;;;ACzE/C;;;;;;;;;;;ADyEA,iBGjBsB,IAAA,CAAK,OAAA,EAAS,WAAA,GAAc,OAAO;;;;AF1CrB;AAGpC;;;;;;;;AAcgB;;;;ACtBhB;;;iBCoFgB,QAAA,CAAS,OAAoB,EAAX,WAAW;;;UC3F5B,iBAAA,SAA0B,
|
|
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/json.ts","../src/meta.ts","../src/yaml.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"mappings":";UAEiB,YAAA;EAAA;;;EAIf,KAAA;EAAA;;;EAKA,cAAA,2BAAyC,MAAA,mCAAyC,MAAM;EAOxF;;;;;EAAA,MAAA,IAAU,IAAA;EA0CI;;;EArCd,IAAA;EAqC6B;;;EAhC7B,KAAA;AAAA;AA6CF;;;;AAA+C;;;;ACzE/C;ADyEA,iBAbgB,KAAA,CAA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/C;AAgCP;;;;;;;iBSjCsB,WAAA,CAAY,OAAA,EAAS,kBAAA,GAAqB,OAAO;ATiC5B;AAa3C;;;;AAA+C;;;;ACzE/C;AD4D2C,iBSb3B,eAAA,CAAgB,OAA2B,EAAlB,kBAAkB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -199,7 +199,7 @@ interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {
|
|
|
199
199
|
* File content mapping function where content is represented as lines.
|
|
200
200
|
* When the file does not yet exist, the callback receives `undefined`.
|
|
201
201
|
*/
|
|
202
|
-
readonly update?: ((content: string
|
|
202
|
+
readonly update?: ((content: Array<string> | undefined) => Array<string> | undefined) | undefined;
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* Ensure file is present/absent asynchronously with content initialized or modified by line.
|
|
@@ -235,7 +235,7 @@ interface JSONOption<V = JSONValue> extends Omit<FileOptions, 'update'> {
|
|
|
235
235
|
*/
|
|
236
236
|
readonly update?: ((content: undefined | V) => undefined | V) | undefined;
|
|
237
237
|
}
|
|
238
|
-
type JSONValue =
|
|
238
|
+
type JSONValue = Array<JSONValue> | boolean | null | number | string | {
|
|
239
239
|
[key: string]: JSONValue;
|
|
240
240
|
};
|
|
241
241
|
/**
|
|
@@ -265,7 +265,7 @@ interface YAMLOption<V = YAMLValue> extends Omit<FileOptions, 'update'> {
|
|
|
265
265
|
*/
|
|
266
266
|
readonly update?: ((content: undefined | V) => undefined | V) | undefined;
|
|
267
267
|
}
|
|
268
|
-
type YAMLValue = boolean | null | number | string |
|
|
268
|
+
type YAMLValue = Array<YAMLValue> | boolean | null | number | string | {
|
|
269
269
|
[key: string]: YAMLValue;
|
|
270
270
|
};
|
|
271
271
|
/**
|
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/json.ts","../src/meta.ts","../src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AAS,WAAA,GAAc,OAAO;;;;AF1CrB;AAGpC;;;;;;;;AAcgB;;;;ACtBhB;;;iBCoFgB,QAAA,CAAS,OAAoB,EAAX,WAAW;;;UC3F5B,iBAAA,SAA0B,
|
|
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/json.ts","../src/meta.ts","../src/yaml.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"mappings":";UAEiB,YAAA;EAAA;;;EAIf,KAAA;EAAA;;;EAKA,cAAA,2BAAyC,MAAA,mCAAyC,MAAM;EAOxF;;;;;EAAA,MAAA,IAAU,IAAA;EA0CI;;;EArCd,IAAA;EAqC6B;;;EAhC7B,KAAA;AAAA;AA6CF;;;;AAA+C;;;;ACzE/C;ADyEA,iBAbgB,KAAA,CAAM,OAAA,EAAS,YAAA,GAAY,OAAA;;;;;;;;;;iBAa3B,SAAA,CAAU,OAAqB,EAAZ,YAAY;;;UCzE9B,QAAA;EDEA;;;EAAA,SCEN,KAAA,GAAQ,iBAAA;EDEjB;;;EAAA,SCGS,KAAA,GAAQ,iBAAA;EDSjB;;;EAAA,SCJS,KAAA,GAAQ,iBAAA;AAAA;AAAA,UAGF,iBAAA;ED2CD;;;EAAA,SCvCL,OAAA;EDuCoB;;;EAAA,SClCpB,IAAA;EDkCgC;AAa3C;;EAb2C,SC7BhC,KAAA;AAAA;;;UCtBM,gBAAA;EFPY;;;EAAA,SEWlB,IAAA,GAAO,QAAQ;EFFxB;;;EAAA,SEOS,IAAA;EFAC;;;EAAA,SEKD,KAAA;AAAA;AFqCX;;;;;;;;AAA2C;AAa3C;;;;AAA+C;;;;ACzE/C;AD4DA,iBEhBsB,SAAA,CAAU,OAAA,EAAS,gBAAA,GAAmB,OAAO;;;;;;;;;;;;;;AD9B/B;AAGpC;;;;iBC6DgB,aAAA,CAAc,OAAyB,EAAhB,gBAAgB;;;UCrEtC,WAAA;EHPY;;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SAAA;AAAA;;;;;APiBxF;iBOVe,IAAA,QAAY,OAAA,EAAS,UAAA,CAAW,KAAA,IAAS,OAAA;;;;;;iBAS/C,QAAA,QAAgB,OAAA,EAAS,UAAU,CAAC,KAAA;;;UCzBnC,iBAAA;ERAA;;;EAAA,SQIN,GAAA;ERAT;;;EAAA,SQKS,KAAA;EROT;;;;EAAA,SQDS,MAAA,KAAW,OAAA;AAAA;AR2CtB;;;;;;;;AAA2C;AAa3C;;AAbA,iBQ7BsB,UAAA,CAAW,OAAA,EAAS,iBAAA,GAAoB,OAAO;;AR0CtB;;;;ACzE/C;;;;;;iBOoDgB,cAAA,CAAe,OAA0B,EAAjB,iBAAiB;;;KClD7C,eAAA;AAAA,UAEK,kBAAA;ETFY;;;EAAA,SSMlB,KAAA;ETGT;;;;EAAA,SSGS,MAAA,sBAA4B,eAAe;AAAA;;;ATc/C;AAgCP;;;;;;;iBSjCsB,WAAA,CAAY,OAAA,EAAS,kBAAA,GAAqB,OAAO;ATiC5B;AAa3C;;;;AAA+C;;;;ACzE/C;AD4D2C,iBSb3B,eAAA,CAAgB,OAA2B,EAAlB,kBAAkB"}
|
package/dist/index.js
CHANGED
|
@@ -324,7 +324,7 @@ function toFileOption$1({ update, ...otherOptions }) {
|
|
|
324
324
|
const meta = Object.freeze({
|
|
325
325
|
buildNumber: 1,
|
|
326
326
|
name: "@w5s/configurator-core",
|
|
327
|
-
version: "1.0.0-alpha.
|
|
327
|
+
version: "1.0.0-alpha.11"
|
|
328
328
|
});
|
|
329
329
|
//#endregion
|
|
330
330
|
//#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/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: string[] | undefined) => 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 { 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 = boolean | JSONValue[] | 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: 1 as number, // (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 = boolean | null | number | string | YAMLValue[] | { [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 stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\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', String(key)]);\n await exec('yarn', ['config', 'set', String(key), String(update == null ? '' : update(stdout))]);\n } else {\n await exec('yarn', ['config', 'unset']);\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', String(key)]);\n execSync('yarn', ['config', 'set', String(key), String(update == null ? '' : update(stdout))]);\n } else {\n execSync('yarn', ['config', 'unset']);\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"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,iBAAiB;AAErC"}
|
|
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/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 { 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: 1 as number, // (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 stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\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', String(key)]);\n await exec('yarn', ['config', 'set', String(key), String(update == null ? '' : update(stdout))]);\n } else {\n await exec('yarn', ['config', 'unset']);\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', String(key)]);\n execSync('yarn', ['config', 'set', String(key), String(update == null ? '' : update(stdout))]);\n } else {\n execSync('yarn', ['config', 'unset']);\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,I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lF,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.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.11",
|
|
4
4
|
"description": "Core library for @w5s/configurator-core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"sideEffect": false,
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "2d215d8f8c7c57653b9f0ef5674ffc2e7beeea5c"
|
|
50
50
|
}
|
package/src/ignoreFile.ts
CHANGED
|
@@ -5,7 +5,7 @@ export interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {
|
|
|
5
5
|
* File content mapping function where content is represented as lines.
|
|
6
6
|
* When the file does not yet exist, the callback receives `undefined`.
|
|
7
7
|
*/
|
|
8
|
-
readonly update?: ((content: string
|
|
8
|
+
readonly update?: ((content: Array<string> | undefined) => Array<string> | undefined) | undefined;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
package/src/json.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface JSONOption<V = JSONValue> extends Omit<FileOptions, 'update'> {
|
|
|
7
7
|
readonly update?: ((content: undefined | V) => undefined | V) | undefined;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export type JSONValue =
|
|
10
|
+
export type JSONValue = Array<JSONValue> | boolean | null | number | string | { [key: string]: JSONValue };
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Ensure file is present/absent asynchronously with content value initialized or modified with `update`
|
package/src/yaml.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface YAMLOption<V = YAMLValue> extends Omit<FileOptions, 'update'> {
|
|
|
9
9
|
readonly update?: ((content: undefined | V) => undefined | V) | undefined;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export type YAMLValue = boolean | null | number | string |
|
|
12
|
+
export type YAMLValue = Array<YAMLValue> | boolean | null | number | string | { [key: string]: YAMLValue };
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Ensure file is present/absent asynchronously with content value initialized or modified with `update`
|