@vltpkg/init
Advanced tools
| import type { GitUser } from '@vltpkg/git'; | ||
| export declare const getAuthorFromGitUser: (user?: GitUser) => string; | ||
| //# sourceMappingURL=get-author-from-git-user.d.ts.map |
| {"version":3,"file":"get-author-from-git-user.d.ts","sourceRoot":"","sources":["../src/get-author-from-git-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,MAUrD,CAAA"} |
| export const getAuthorFromGitUser = (user) => { | ||
| if (!user) | ||
| return ''; | ||
| const { name, email } = user; | ||
| let res = ''; | ||
| if (name) | ||
| res += name; | ||
| if (email) { | ||
| if (name) | ||
| res += ' '; | ||
| res += `<${email}>`; | ||
| } | ||
| return res; | ||
| }; | ||
| //# sourceMappingURL=get-author-from-git-user.js.map |
| {"version":3,"file":"get-author-from-git-user.js","sourceRoot":"","sources":["../src/get-author-from-git-user.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAc,EAAU,EAAE;IAC7D,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IAC5B,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,IAAI,IAAI;QAAE,GAAG,IAAI,IAAI,CAAA;IACrB,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,IAAI;YAAE,GAAG,IAAI,GAAG,CAAA;QACpB,GAAG,IAAI,IAAI,KAAK,GAAG,CAAA;IACrB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import type { GitUser } from '@vltpkg/git'\n\nexport const getAuthorFromGitUser = (user?: GitUser): string => {\n if (!user) return ''\n const { name, email } = user\n let res = ''\n if (name) res += name\n if (email) {\n if (name) res += ' '\n res += `<${email}>`\n }\n return res\n}\n"]} |
| import type { JSONObj } from '@vltpkg/registry-client'; | ||
| import type { NormalizedManifest } from '@vltpkg/types'; | ||
| import { getAuthorFromGitUser } from './get-author-from-git-user.ts'; | ||
| export { getAuthorFromGitUser }; | ||
| export type InitOptions = { | ||
| cwd?: string; | ||
| author?: string; | ||
| logger?: (...a: unknown[]) => void; | ||
| }; | ||
| export type CustomizableInitOptions = { | ||
| name: string; | ||
| author: string; | ||
| }; | ||
| export type JSONFileInfo<T extends JSONObj = JSONObj> = { | ||
| path: string; | ||
| data: T; | ||
| }; | ||
| export type InitFileResults = { | ||
| manifest?: JSONFileInfo<NormalizedManifest>; | ||
| }; | ||
| export declare const init: ({ cwd, author, logger, }?: InitOptions) => Promise<InitFileResults>; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAEpE,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAK/B,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAWD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,CAAC,CAAA;CACR,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAAC,CAAA;CAK5C,CAAA;AAED,eAAO,MAAM,IAAI,8BAId,WAAW,KAAQ,OAAO,CAAC,eAAe,CA6B5C,CAAA"} |
| import { getUser } from '@vltpkg/git'; | ||
| import { PackageJson } from '@vltpkg/package-json'; | ||
| import { basename, resolve } from 'node:path'; | ||
| import { getAuthorFromGitUser } from "./get-author-from-git-user.js"; | ||
| import { asError, normalizeManifest } from '@vltpkg/types'; | ||
| export { getAuthorFromGitUser }; | ||
| // eslint-disable-next-line no-console | ||
| const stderr = console.error; | ||
| const template = ({ name, author }) => normalizeManifest({ | ||
| name, | ||
| version: '1.0.0', | ||
| description: '', | ||
| main: 'index.js', | ||
| ...(author ? { author } : undefined), | ||
| }); | ||
| export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {}) => { | ||
| const packageJson = new PackageJson(); | ||
| const path = resolve(cwd, 'package.json'); | ||
| let existingData; | ||
| try { | ||
| existingData = packageJson.read(cwd); | ||
| logger('package.json already exists'); | ||
| } | ||
| catch (err) { | ||
| if (asError(err).message !== 'Could not read package.json file') { | ||
| throw err; | ||
| } | ||
| } | ||
| const name = basename(cwd); | ||
| const templateData = template({ | ||
| name, | ||
| author: author ?? | ||
| getAuthorFromGitUser(await getUser().catch(() => undefined)), | ||
| }); | ||
| // Merge template with existing data, preserving existing properties | ||
| const data = existingData ? { ...templateData, ...existingData } : templateData; | ||
| const indent = 2; | ||
| packageJson.write(cwd, data, indent); | ||
| return { manifest: { path, data } }; | ||
| }; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGlD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAA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AC;KAC/D,CAAC,CAAA;IAEF,oEAAoE;IACpE,MAAM,IAAI,GACR,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC,YAAY,CAAA;IAEpE,MAAM,MAAM,GAAG,CAAC,CAAA;IAChB,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACpC,OAAO,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAA;AACrC,CAAC,CAAA","sourcesContent":["import { getUser } from '@vltpkg/git'\nimport { PackageJson } from '@vltpkg/package-json'\nimport type { JSONObj } from '@vltpkg/registry-client'\nimport type { NormalizedManifest } from '@vltpkg/types'\nimport { basename, resolve } from 'node:path'\nimport { getAuthorFromGitUser } from './get-author-from-git-user.ts'\nimport { asError, normalizeManifest } from '@vltpkg/types'\nexport { getAuthorFromGitUser }\n\n// eslint-disable-next-line no-console\nconst stderr: (...a: unknown[]) => void = console.error\n\nexport type InitOptions = {\n cwd?: string\n author?: string\n logger?: (...a: unknown[]) => void\n}\n\nexport type CustomizableInitOptions = {\n name: string\n author: string\n}\n\nconst template = ({ name, author }: CustomizableInitOptions) =>\n normalizeManifest({\n name,\n version: '1.0.0',\n description: '',\n main: 'index.js',\n ...(author ? { author } : undefined),\n })\n\nexport type JSONFileInfo<T extends JSONObj = JSONObj> = {\n path: string\n data: T\n}\n\nexport type InitFileResults = {\n manifest?: JSONFileInfo<NormalizedManifest>\n // TODO: enable these if/when we do more than just the manifest\n // Eg:\n // workspaces?: JSONFileInfo\n // config?: JSONFileInfo\n}\n\nexport const init = async ({\n cwd = process.cwd(),\n author,\n logger = stderr,\n}: InitOptions = {}): Promise<InitFileResults> => {\n const packageJson = new PackageJson()\n const path = resolve(cwd, 'package.json')\n let existingData: NormalizedManifest | undefined\n\n try {\n existingData = packageJson.read(cwd)\n logger('package.json already exists')\n } catch (err) {\n if (asError(err).message !== 'Could not read package.json file') {\n throw err\n }\n }\n\n const name = basename(cwd)\n const templateData = template({\n name,\n author:\n author ??\n getAuthorFromGitUser(await getUser().catch(() => undefined)),\n })\n\n // Merge template with existing data, preserving existing properties\n const data: NormalizedManifest =\n existingData ? { ...templateData, ...existingData } : templateData\n\n const indent = 2\n packageJson.write(cwd, data, indent)\n return { manifest: { path, data } }\n}\n"]} |
+7
-21
| { | ||
| "name": "@vltpkg/init", | ||
| "description": "vlt project intialization logic", | ||
| "version": "1.0.0-rc.10", | ||
| "version": "1.0.0-rc.11", | ||
| "repository": { | ||
@@ -11,18 +11,7 @@ "type": "git", | ||
| "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)", | ||
| "tshy": { | ||
| "selfLink": false, | ||
| "liveDev": true, | ||
| "dialects": [ | ||
| "esm" | ||
| ], | ||
| "exports": { | ||
| "./package.json": "./package.json", | ||
| ".": "./src/index.ts" | ||
| } | ||
| }, | ||
| "dependencies": { | ||
| "@vltpkg/git": "1.0.0-rc.10", | ||
| "@vltpkg/registry-client": "1.0.0-rc.10", | ||
| "@vltpkg/types": "1.0.0-rc.10", | ||
| "@vltpkg/package-json": "1.0.0-rc.10" | ||
| "@vltpkg/git": "1.0.0-rc.11", | ||
| "@vltpkg/types": "1.0.0-rc.11", | ||
| "@vltpkg/package-json": "1.0.0-rc.11", | ||
| "@vltpkg/registry-client": "1.0.0-rc.11" | ||
| }, | ||
@@ -35,3 +24,2 @@ "devDependencies": { | ||
| "tap": "^21.5.0", | ||
| "tshy": "^3.1.0", | ||
| "typedoc": "~0.27.9", | ||
@@ -49,3 +37,3 @@ "typescript": "5.7.3", | ||
| "prettier": "../../.prettierrc.js", | ||
| "module": "./dist/esm/index.js", | ||
| "module": "./dist/index.js", | ||
| "type": "module", | ||
@@ -56,4 +44,3 @@ "exports": { | ||
| "import": { | ||
| "types": "./dist/esm/index.d.ts", | ||
| "default": "./dist/esm/index.js" | ||
| "default": "./dist/index.js" | ||
| } | ||
@@ -73,5 +60,4 @@ } | ||
| "posttest": "tsc --noEmit", | ||
| "tshy": "tshy", | ||
| "typecheck": "tsc --noEmit" | ||
| } | ||
| } |
| import type { GitUser } from '@vltpkg/git'; | ||
| export declare const getAuthorFromGitUser: (user?: GitUser) => string; | ||
| //# sourceMappingURL=get-author-from-git-user.d.ts.map |
| {"version":3,"file":"get-author-from-git-user.d.ts","sourceRoot":"","sources":["../../src/get-author-from-git-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,eAAO,MAAM,oBAAoB,UAAW,OAAO,KAAG,MAUrD,CAAA"} |
| export const getAuthorFromGitUser = (user) => { | ||
| if (!user) | ||
| return ''; | ||
| const { name, email } = user; | ||
| let res = ''; | ||
| if (name) | ||
| res += name; | ||
| if (email) { | ||
| if (name) | ||
| res += ' '; | ||
| res += `<${email}>`; | ||
| } | ||
| return res; | ||
| }; | ||
| //# sourceMappingURL=get-author-from-git-user.js.map |
| {"version":3,"file":"get-author-from-git-user.js","sourceRoot":"","sources":["../../src/get-author-from-git-user.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAc,EAAU,EAAE;IAC7D,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IACpB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IAC5B,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,IAAI,IAAI;QAAE,GAAG,IAAI,IAAI,CAAA;IACrB,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,IAAI;YAAE,GAAG,IAAI,GAAG,CAAA;QACpB,GAAG,IAAI,IAAI,KAAK,GAAG,CAAA;IACrB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import type { GitUser } from '@vltpkg/git'\n\nexport const getAuthorFromGitUser = (user?: GitUser): string => {\n if (!user) return ''\n const { name, email } = user\n let res = ''\n if (name) res += name\n if (email) {\n if (name) res += ' '\n res += `<${email}>`\n }\n return res\n}\n"]} |
| import type { JSONObj } from '@vltpkg/registry-client'; | ||
| import type { NormalizedManifest } from '@vltpkg/types'; | ||
| import { getAuthorFromGitUser } from './get-author-from-git-user.ts'; | ||
| export { getAuthorFromGitUser }; | ||
| export type InitOptions = { | ||
| cwd?: string; | ||
| author?: string; | ||
| logger?: (...a: unknown[]) => void; | ||
| }; | ||
| export type CustomizableInitOptions = { | ||
| name: string; | ||
| author: string; | ||
| }; | ||
| export type JSONFileInfo<T extends JSONObj = JSONObj> = { | ||
| path: string; | ||
| data: T; | ||
| }; | ||
| export type InitFileResults = { | ||
| manifest?: JSONFileInfo<NormalizedManifest>; | ||
| }; | ||
| export declare const init: ({ cwd, author, logger, }?: InitOptions) => Promise<InitFileResults>; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAA;AAEpE,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAK/B,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAWD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,CAAC,CAAA;CACR,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAAC,CAAA;CAK5C,CAAA;AAED,eAAO,MAAM,IAAI,8BAId,WAAW,KAAQ,OAAO,CAAC,eAAe,CA6B5C,CAAA"} |
| import { getUser } from '@vltpkg/git'; | ||
| import { PackageJson } from '@vltpkg/package-json'; | ||
| import { basename, resolve } from 'node:path'; | ||
| import { getAuthorFromGitUser } from "./get-author-from-git-user.js"; | ||
| import { asError, normalizeManifest } from '@vltpkg/types'; | ||
| export { getAuthorFromGitUser }; | ||
| // eslint-disable-next-line no-console | ||
| const stderr = console.error; | ||
| const template = ({ name, author }) => normalizeManifest({ | ||
| name, | ||
| version: '1.0.0', | ||
| description: '', | ||
| main: 'index.js', | ||
| ...(author ? { author } : undefined), | ||
| }); | ||
| export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {}) => { | ||
| const packageJson = new PackageJson(); | ||
| const path = resolve(cwd, 'package.json'); | ||
| let existingData; | ||
| try { | ||
| existingData = packageJson.read(cwd); | ||
| logger('package.json already exists'); | ||
| } | ||
| catch (err) { | ||
| if (asError(err).message !== 'Could not read package.json file') { | ||
| throw err; | ||
| } | ||
| } | ||
| const name = basename(cwd); | ||
| const templateData = template({ | ||
| name, | ||
| author: author ?? | ||
| getAuthorFromGitUser(await getUser().catch(() => undefined)), | ||
| }); | ||
| // Merge template with existing data, preserving existing properties | ||
| const data = existingData ? { ...templateData, ...existingData } : templateData; | ||
| const indent = 2; | ||
| packageJson.write(cwd, data, indent); | ||
| return { manifest: { path, data } }; | ||
| }; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGlD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAA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,oBAAoB,CAAC,MAAM,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;KAC/D,CAAC,CAAA;IAEF,oEAAoE;IACpE,MAAM,IAAI,GACR,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC,CAAC,YAAY,CAAA;IAEpE,MAAM,MAAM,GAAG,CAAC,CAAA;IAChB,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACpC,OAAO,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAA;AACrC,CAAC,CAAA","sourcesContent":["import { getUser } from '@vltpkg/git'\nimport { PackageJson } from '@vltpkg/package-json'\nimport type { JSONObj } from '@vltpkg/registry-client'\nimport type { NormalizedManifest } from '@vltpkg/types'\nimport { basename, resolve } from 'node:path'\nimport { getAuthorFromGitUser } from './get-author-from-git-user.ts'\nimport { asError, normalizeManifest } from '@vltpkg/types'\nexport { getAuthorFromGitUser }\n\n// eslint-disable-next-line no-console\nconst stderr: (...a: unknown[]) => void = console.error\n\nexport type InitOptions = {\n cwd?: string\n author?: string\n logger?: (...a: unknown[]) => void\n}\n\nexport type CustomizableInitOptions = {\n name: string\n author: string\n}\n\nconst template = ({ name, author }: CustomizableInitOptions) =>\n normalizeManifest({\n name,\n version: '1.0.0',\n description: '',\n main: 'index.js',\n ...(author ? { author } : undefined),\n })\n\nexport type JSONFileInfo<T extends JSONObj = JSONObj> = {\n path: string\n data: T\n}\n\nexport type InitFileResults = {\n manifest?: JSONFileInfo<NormalizedManifest>\n // TODO: enable these if/when we do more than just the manifest\n // Eg:\n // workspaces?: JSONFileInfo\n // config?: JSONFileInfo\n}\n\nexport const init = async ({\n cwd = process.cwd(),\n author,\n logger = stderr,\n}: InitOptions = {}): Promise<InitFileResults> => {\n const packageJson = new PackageJson()\n const path = resolve(cwd, 'package.json')\n let existingData: NormalizedManifest | undefined\n\n try {\n existingData = packageJson.read(cwd)\n logger('package.json already exists')\n } catch (err) {\n if (asError(err).message !== 'Could not read package.json file') {\n throw err\n }\n }\n\n const name = basename(cwd)\n const templateData = template({\n name,\n author:\n author ??\n getAuthorFromGitUser(await getUser().catch(() => undefined)),\n })\n\n // Merge template with existing data, preserving existing properties\n const data: NormalizedManifest =\n existingData ? { ...templateData, ...existingData } : templateData\n\n const indent = 2\n packageJson.write(cwd, data, indent)\n return { manifest: { path, data } }\n}\n"]} |
| { | ||
| "type": "module" | ||
| } |
8
-11.11%12812
-2.42%11
-8.33%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated