@vltpkg/init 1.0.0-rc.8 → 1.0.1

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/README.md CHANGED
@@ -7,7 +7,7 @@ Project initialization logic for `vlt`.
7
7
  ## Overview
8
8
 
9
9
  This is a tool that provides the project initialization logic used by
10
- the vlt cli and gui.
10
+ the vlt cli.
11
11
 
12
12
  ## Usage
13
13
 
@@ -1,3 +1,2 @@
1
1
  import type { GitUser } from '@vltpkg/git';
2
2
  export declare const getAuthorFromGitUser: (user?: GitUser) => string;
3
- //# sourceMappingURL=get-author-from-git-user.d.ts.map
@@ -12,4 +12,3 @@ export const getAuthorFromGitUser = (user) => {
12
12
  }
13
13
  return res;
14
14
  };
15
- //# sourceMappingURL=get-author-from-git-user.js.map
@@ -0,0 +1,39 @@
1
+ import type { JSONObj } from '@vltpkg/registry-client';
2
+ import type { NormalizedManifest } from '@vltpkg/types';
3
+ import { getAuthorFromGitUser } from './get-author-from-git-user.ts';
4
+ export { getAuthorFromGitUser };
5
+ export type InitOptions = {
6
+ cwd?: string;
7
+ author?: string;
8
+ logger?: (...a: unknown[]) => void;
9
+ };
10
+ export type CustomizableInitOptions = {
11
+ name: string;
12
+ author: string;
13
+ };
14
+ export type JSONFileInfo<T extends JSONObj = JSONObj> = {
15
+ path: string;
16
+ data: T;
17
+ };
18
+ export type IgnoreFileInfo = {
19
+ path: string;
20
+ };
21
+ export type GitignoreFileInfo = IgnoreFileInfo;
22
+ export type InitFileResults = {
23
+ manifest?: JSONFileInfo<NormalizedManifest>;
24
+ gitignore?: IgnoreFileInfo;
25
+ npmignore?: IgnoreFileInfo;
26
+ };
27
+ /**
28
+ * Create or update a `.gitignore` file ensuring `node_modules` is listed.
29
+ * Returns `{ path }` of the file that was written, or `undefined` if the
30
+ * file already contained the entry and no changes were needed.
31
+ */
32
+ export declare const ensureGitignore: (cwd: string) => GitignoreFileInfo | undefined;
33
+ /**
34
+ * Create or update a `.npmignore` file ensuring `vlt.json` is listed.
35
+ * Returns `{ path }` of the file that was written, or `undefined` if the
36
+ * file already contained the entry and no changes were needed.
37
+ */
38
+ export declare const ensureNpmignore: (cwd: string) => IgnoreFileInfo | undefined;
39
+ export declare const init: ({ cwd, author, logger, }?: InitOptions) => Promise<InitFileResults>;
package/dist/index.js ADDED
@@ -0,0 +1,90 @@
1
+ import { getUser } from '@vltpkg/git';
2
+ import { PackageJson } from '@vltpkg/package-json';
3
+ import { appendFileSync, existsSync, readFileSync, writeFileSync, } from 'node:fs';
4
+ import { basename, resolve } from 'node:path';
5
+ import { getAuthorFromGitUser } from "./get-author-from-git-user.js";
6
+ import { asError, normalizeManifest } from '@vltpkg/types';
7
+ export { getAuthorFromGitUser };
8
+ // eslint-disable-next-line no-console
9
+ const stderr = console.error;
10
+ const template = ({ name, author }) => normalizeManifest({
11
+ name,
12
+ version: '1.0.0',
13
+ description: '',
14
+ main: 'index.js',
15
+ ...(author ? { author } : undefined),
16
+ });
17
+ const GITIGNORE_ENTRY = 'node_modules';
18
+ const NPMIGNORE_ENTRY = 'vlt.json';
19
+ /**
20
+ * Create or update a `.gitignore` file ensuring `node_modules` is listed.
21
+ * Returns `{ path }` of the file that was written, or `undefined` if the
22
+ * file already contained the entry and no changes were needed.
23
+ */
24
+ export const ensureGitignore = (cwd) => {
25
+ const gitignorePath = resolve(cwd, '.gitignore');
26
+ if (!existsSync(gitignorePath)) {
27
+ writeFileSync(gitignorePath, `${GITIGNORE_ENTRY}\n`, 'utf8');
28
+ return { path: gitignorePath };
29
+ }
30
+ const content = readFileSync(gitignorePath, 'utf8');
31
+ const lines = content.split('\n').map(l => l.trim());
32
+ if (!lines.includes(GITIGNORE_ENTRY)) {
33
+ // Append with a leading newline to avoid joining onto an existing last line
34
+ const prefix = content.endsWith('\n') ? '' : '\n';
35
+ appendFileSync(gitignorePath, `${prefix}${GITIGNORE_ENTRY}\n`, 'utf8');
36
+ return { path: gitignorePath };
37
+ }
38
+ return undefined;
39
+ };
40
+ /**
41
+ * Create or update a `.npmignore` file ensuring `vlt.json` is listed.
42
+ * Returns `{ path }` of the file that was written, or `undefined` if the
43
+ * file already contained the entry and no changes were needed.
44
+ */
45
+ export const ensureNpmignore = (cwd) => {
46
+ const npmignorePath = resolve(cwd, '.npmignore');
47
+ if (!existsSync(npmignorePath)) {
48
+ writeFileSync(npmignorePath, `${NPMIGNORE_ENTRY}\n`, 'utf8');
49
+ return { path: npmignorePath };
50
+ }
51
+ const content = readFileSync(npmignorePath, 'utf8');
52
+ const lines = content.split('\n').map(l => l.trim());
53
+ if (!lines.includes(NPMIGNORE_ENTRY)) {
54
+ const prefix = content.endsWith('\n') ? '' : '\n';
55
+ appendFileSync(npmignorePath, `${prefix}${NPMIGNORE_ENTRY}\n`, 'utf8');
56
+ return { path: npmignorePath };
57
+ }
58
+ return undefined;
59
+ };
60
+ export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {}) => {
61
+ const packageJson = new PackageJson();
62
+ const path = resolve(cwd, 'package.json');
63
+ let existingData;
64
+ try {
65
+ existingData = packageJson.read(cwd);
66
+ logger('package.json already exists');
67
+ }
68
+ catch (err) {
69
+ if (asError(err).message !== 'Could not read package.json file') {
70
+ throw err;
71
+ }
72
+ }
73
+ const name = basename(cwd);
74
+ const templateData = template({
75
+ name,
76
+ author: author ??
77
+ getAuthorFromGitUser(await getUser().catch(() => undefined)),
78
+ });
79
+ // Merge template with existing data, preserving existing properties
80
+ const data = existingData ? { ...templateData, ...existingData } : templateData;
81
+ const indent = 2;
82
+ packageJson.write(cwd, data, indent);
83
+ const gitignore = ensureGitignore(cwd);
84
+ const npmignore = ensureNpmignore(cwd);
85
+ return {
86
+ manifest: { path, data },
87
+ ...(gitignore ? { gitignore } : {}),
88
+ ...(npmignore ? { npmignore } : {}),
89
+ };
90
+ };
package/package.json CHANGED
@@ -1,72 +1,70 @@
1
1
  {
2
2
  "name": "@vltpkg/init",
3
3
  "description": "vlt project intialization logic",
4
- "version": "1.0.0-rc.8",
4
+ "version": "1.0.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
8
8
  "directory": "src/init"
9
9
  },
10
- "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
11
- "tshy": {
12
- "selfLink": false,
13
- "liveDev": true,
14
- "dialects": [
15
- "esm"
16
- ],
17
- "exports": {
18
- "./package.json": "./package.json",
19
- ".": "./src/index.ts"
20
- }
10
+ "author": {
11
+ "name": "vlt technology inc.",
12
+ "email": "support@vlt.sh",
13
+ "url": "http://vlt.sh"
21
14
  },
22
15
  "dependencies": {
23
- "@vltpkg/git": "1.0.0-rc.8",
24
- "@vltpkg/registry-client": "1.0.0-rc.8",
25
- "@vltpkg/types": "1.0.0-rc.8",
26
- "@vltpkg/package-json": "1.0.0-rc.8"
16
+ "@vltpkg/git": "1.0.1",
17
+ "@vltpkg/package-json": "1.0.1",
18
+ "@vltpkg/registry-client": "1.0.1",
19
+ "@vltpkg/types": "1.0.1"
27
20
  },
28
21
  "devDependencies": {
29
- "@eslint/js": "^9.34.0",
30
- "@types/node": "^22.17.2",
31
- "eslint": "^9.34.0",
32
- "prettier": "^3.6.2",
33
- "tap": "^21.1.0",
34
- "tshy": "^3.0.2",
22
+ "@eslint/js": "^9.39.1",
23
+ "@types/node": "^22.19.2",
24
+ "eslint": "^9.39.1",
25
+ "prettier": "^3.7.4",
26
+ "tap": "^21.5.0",
35
27
  "typedoc": "~0.27.9",
36
28
  "typescript": "5.7.3",
37
- "typescript-eslint": "^8.40.0"
29
+ "typescript-eslint": "^8.49.0"
38
30
  },
39
31
  "license": "BSD-2-Clause-Patent",
40
32
  "engines": {
41
- "node": ">=22"
33
+ "node": ">=22.22.0"
34
+ },
35
+ "scripts": {
36
+ "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
37
+ "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
38
+ "lint": "eslint . --fix",
39
+ "lint:check": "eslint .",
40
+ "prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
41
+ "snap": "tap",
42
+ "test": "tap",
43
+ "posttest": "tsc --noEmit",
44
+ "typecheck": "tsc --noEmit"
42
45
  },
43
46
  "tap": {
44
47
  "extends": "../../tap-config.yaml"
45
48
  },
46
49
  "prettier": "../../.prettierrc.js",
47
- "module": "./dist/esm/index.js",
50
+ "module": "./dist/index.js",
48
51
  "type": "module",
49
52
  "exports": {
50
53
  "./package.json": "./package.json",
51
54
  ".": {
52
55
  "import": {
53
- "types": "./dist/esm/index.d.ts",
54
- "default": "./dist/esm/index.js"
56
+ "default": "./dist/index.js"
55
57
  }
56
58
  }
57
59
  },
58
60
  "files": [
59
61
  "dist"
60
62
  ],
61
- "scripts": {
62
- "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
63
- "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
64
- "lint": "eslint . --fix",
65
- "lint:check": "eslint .",
66
- "snap": "tap",
67
- "test": "tap",
68
- "posttest": "tsc --noEmit",
69
- "tshy": "tshy",
70
- "typecheck": "tsc --noEmit"
71
- }
72
- }
63
+ "bugs": [
64
+ {
65
+ "type": "link",
66
+ "url": "https://github.com/vltpkg/vltpkg/issues"
67
+ }
68
+ ],
69
+ "homepage": "https://github.com/vltpkg/vltpkg/tree/main/src/init#readme"
70
+ }
@@ -1 +0,0 @@
1
- {"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"}
@@ -1 +0,0 @@
1
- {"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"]}
@@ -1,22 +0,0 @@
1
- import type { JSONObj } from '@vltpkg/registry-client';
2
- import type { NormalizedManifest } from '@vltpkg/types';
3
- import { getAuthorFromGitUser } from './get-author-from-git-user.ts';
4
- export { getAuthorFromGitUser };
5
- export type InitOptions = {
6
- cwd?: string;
7
- author?: string;
8
- logger?: (...a: unknown[]) => void;
9
- };
10
- export type CustomizableInitOptions = {
11
- name: string;
12
- author: string;
13
- };
14
- export type JSONFileInfo<T extends JSONObj = JSONObj> = {
15
- path: string;
16
- data: T;
17
- };
18
- export type InitFileResults = {
19
- manifest?: JSONFileInfo<NormalizedManifest>;
20
- };
21
- export declare const init: ({ cwd, author, logger, }?: InitOptions) => Promise<InitFileResults>;
22
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"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"}
package/dist/esm/index.js DELETED
@@ -1,41 +0,0 @@
1
- import { getUser } from '@vltpkg/git';
2
- import { PackageJson } from '@vltpkg/package-json';
3
- import { basename, resolve } from 'node:path';
4
- import { getAuthorFromGitUser } from "./get-author-from-git-user.js";
5
- import { asError, normalizeManifest } from '@vltpkg/types';
6
- export { getAuthorFromGitUser };
7
- // eslint-disable-next-line no-console
8
- const stderr = console.error;
9
- const template = ({ name, author }) => normalizeManifest({
10
- name,
11
- version: '1.0.0',
12
- description: '',
13
- main: 'index.js',
14
- ...(author ? { author } : undefined),
15
- });
16
- export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {}) => {
17
- const packageJson = new PackageJson();
18
- const path = resolve(cwd, 'package.json');
19
- let existingData;
20
- try {
21
- existingData = packageJson.read(cwd);
22
- logger('package.json already exists');
23
- }
24
- catch (err) {
25
- if (asError(err).message !== 'Could not read package.json file') {
26
- throw err;
27
- }
28
- }
29
- const name = basename(cwd);
30
- const templateData = template({
31
- name,
32
- author: author ??
33
- getAuthorFromGitUser(await getUser().catch(() => undefined)),
34
- });
35
- // Merge template with existing data, preserving existing properties
36
- const data = existingData ? { ...templateData, ...existingData } : templateData;
37
- const indent = 2;
38
- packageJson.write(cwd, data, indent);
39
- return { manifest: { path, data } };
40
- };
41
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"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,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,oBAAoB,EAAE,CAAA;AAE/B,sCAAsC;AACtC,MAAM,MAAM,GAA8B,OAAO,CAAC,KAAK,CAAA;AAavD,MAAM,QAAQ,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAA2B,EAAE,EAAE,CAC7D,iBAAiB,CAAC;IAChB,IAAI;IACJ,OAAO,EAAE,OAAO;IAChB,WAAW,EAAE,EAAE;IACf,IAAI,EAAE,UAAU;IAChB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;CACrC,CAAC,CAAA;AAeJ,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EAAE,EACzB,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EACnB,MAAM,EACN,MAAM,GAAG,MAAM,MACA,EAAE,EAA4B,EAAE;IAC/C,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;IACrC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IACzC,IAAI,YAA4C,CAAA;IAEhD,IAAI,CAAC;QACH,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACpC,MAAM,CAAC,6BAA6B,CAAC,CAAA;IACvC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,kCAAkC,EAAE,CAAC;YAChE,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC1B,MAAM,YAAY,GAAG,QAAQ,CAAC;QAC5B,IAAI;QACJ,MAAM,EACJ,MAAM;YACN,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"]}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }