@vltpkg/init 1.0.0-rc.29 → 1.0.0-rc.30

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 CHANGED
@@ -15,12 +15,14 @@ export type JSONFileInfo<T extends JSONObj = JSONObj> = {
15
15
  path: string;
16
16
  data: T;
17
17
  };
18
- export type GitignoreFileInfo = {
18
+ export type IgnoreFileInfo = {
19
19
  path: string;
20
20
  };
21
+ export type GitignoreFileInfo = IgnoreFileInfo;
21
22
  export type InitFileResults = {
22
23
  manifest?: JSONFileInfo<NormalizedManifest>;
23
- gitignore?: GitignoreFileInfo;
24
+ gitignore?: IgnoreFileInfo;
25
+ npmignore?: IgnoreFileInfo;
24
26
  };
25
27
  /**
26
28
  * Create or update a `.gitignore` file ensuring `node_modules` is listed.
@@ -28,4 +30,10 @@ export type InitFileResults = {
28
30
  * file already contained the entry and no changes were needed.
29
31
  */
30
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;
31
39
  export declare const init: ({ cwd, author, logger, }?: InitOptions) => Promise<InitFileResults>;
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ const template = ({ name, author }) => normalizeManifest({
15
15
  ...(author ? { author } : undefined),
16
16
  });
17
17
  const GITIGNORE_ENTRY = 'node_modules';
18
+ const NPMIGNORE_ENTRY = 'vlt.json';
18
19
  /**
19
20
  * Create or update a `.gitignore` file ensuring `node_modules` is listed.
20
21
  * Returns `{ path }` of the file that was written, or `undefined` if the
@@ -36,6 +37,26 @@ export const ensureGitignore = (cwd) => {
36
37
  }
37
38
  return undefined;
38
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
+ };
39
60
  export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {}) => {
40
61
  const packageJson = new PackageJson();
41
62
  const path = resolve(cwd, 'package.json');
@@ -60,8 +81,10 @@ export const init = async ({ cwd = process.cwd(), author, logger = stderr, } = {
60
81
  const indent = 2;
61
82
  packageJson.write(cwd, data, indent);
62
83
  const gitignore = ensureGitignore(cwd);
84
+ const npmignore = ensureNpmignore(cwd);
63
85
  return {
64
86
  manifest: { path, data },
65
87
  ...(gitignore ? { gitignore } : {}),
88
+ ...(npmignore ? { npmignore } : {}),
66
89
  };
67
90
  };
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.29",
4
+ "version": "1.0.0-rc.30",
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.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"
16
+ "@vltpkg/git": "1.0.0-rc.30",
17
+ "@vltpkg/package-json": "1.0.0-rc.30",
18
+ "@vltpkg/registry-client": "1.0.0-rc.30",
19
+ "@vltpkg/types": "1.0.0-rc.30"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@eslint/js": "^9.39.1",