@vltpkg/init 1.0.0-rc.26 → 1.0.0-rc.29
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.d.ts +10 -0
- package/dist/index.js +28 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,17 @@ export type JSONFileInfo<T extends JSONObj = JSONObj> = {
|
|
|
15
15
|
path: string;
|
|
16
16
|
data: T;
|
|
17
17
|
};
|
|
18
|
+
export type GitignoreFileInfo = {
|
|
19
|
+
path: string;
|
|
20
|
+
};
|
|
18
21
|
export type InitFileResults = {
|
|
19
22
|
manifest?: JSONFileInfo<NormalizedManifest>;
|
|
23
|
+
gitignore?: GitignoreFileInfo;
|
|
20
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Create or update a `.gitignore` file ensuring `node_modules` is listed.
|
|
27
|
+
* Returns `{ path }` of the file that was written, or `undefined` if the
|
|
28
|
+
* file already contained the entry and no changes were needed.
|
|
29
|
+
*/
|
|
30
|
+
export declare const ensureGitignore: (cwd: string) => GitignoreFileInfo | undefined;
|
|
21
31
|
export declare const init: ({ cwd, author, logger, }?: InitOptions) => Promise<InitFileResults>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getUser } from '@vltpkg/git';
|
|
2
2
|
import { PackageJson } from '@vltpkg/package-json';
|
|
3
|
+
import { appendFileSync, existsSync, readFileSync, writeFileSync, } from 'node:fs';
|
|
3
4
|
import { basename, resolve } from 'node:path';
|
|
4
5
|
import { getAuthorFromGitUser } from "./get-author-from-git-user.js";
|
|
5
6
|
import { asError, normalizeManifest } from '@vltpkg/types';
|
|
@@ -13,6 +14,28 @@ const template = ({ name, author }) => normalizeManifest({
|
|
|
13
14
|
main: 'index.js',
|
|
14
15
|
...(author ? { author } : undefined),
|
|
15
16
|
});
|
|
17
|
+
const GITIGNORE_ENTRY = 'node_modules';
|
|
18
|
+
/**
|
|
19
|
+
* Create or update a `.gitignore` file ensuring `node_modules` is listed.
|
|
20
|
+
* Returns `{ path }` of the file that was written, or `undefined` if the
|
|
21
|
+
* file already contained the entry and no changes were needed.
|
|
22
|
+
*/
|
|
23
|
+
export const ensureGitignore = (cwd) => {
|
|
24
|
+
const gitignorePath = resolve(cwd, '.gitignore');
|
|
25
|
+
if (!existsSync(gitignorePath)) {
|
|
26
|
+
writeFileSync(gitignorePath, `${GITIGNORE_ENTRY}\n`, 'utf8');
|
|
27
|
+
return { path: gitignorePath };
|
|
28
|
+
}
|
|
29
|
+
const content = readFileSync(gitignorePath, 'utf8');
|
|
30
|
+
const lines = content.split('\n').map(l => l.trim());
|
|
31
|
+
if (!lines.includes(GITIGNORE_ENTRY)) {
|
|
32
|
+
// Append with a leading newline to avoid joining onto an existing last line
|
|
33
|
+
const prefix = content.endsWith('\n') ? '' : '\n';
|
|
34
|
+
appendFileSync(gitignorePath, `${prefix}${GITIGNORE_ENTRY}\n`, 'utf8');
|
|
35
|
+
return { path: gitignorePath };
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
16
39
|
export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {}) => {
|
|
17
40
|
const packageJson = new PackageJson();
|
|
18
41
|
const path = resolve(cwd, 'package.json');
|
|
@@ -36,5 +59,9 @@ export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {
|
|
|
36
59
|
const data = existingData ? { ...templateData, ...existingData } : templateData;
|
|
37
60
|
const indent = 2;
|
|
38
61
|
packageJson.write(cwd, data, indent);
|
|
39
|
-
|
|
62
|
+
const gitignore = ensureGitignore(cwd);
|
|
63
|
+
return {
|
|
64
|
+
manifest: { path, data },
|
|
65
|
+
...(gitignore ? { gitignore } : {}),
|
|
66
|
+
};
|
|
40
67
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/init",
|
|
3
3
|
"description": "vlt project intialization logic",
|
|
4
|
-
"version": "1.0.0-rc.
|
|
4
|
+
"version": "1.0.0-rc.29",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"url": "http://vlt.sh"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@vltpkg/git": "1.0.0-rc.
|
|
17
|
-
"@vltpkg/package-json": "1.0.0-rc.
|
|
18
|
-
"@vltpkg/registry-client": "1.0.0-rc.
|
|
19
|
-
"@vltpkg/types": "1.0.0-rc.
|
|
16
|
+
"@vltpkg/git": "1.0.0-rc.29",
|
|
17
|
+
"@vltpkg/package-json": "1.0.0-rc.29",
|
|
18
|
+
"@vltpkg/registry-client": "1.0.0-rc.29",
|
|
19
|
+
"@vltpkg/types": "1.0.0-rc.29"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@eslint/js": "^9.39.1",
|