@vidavidorra/create-project 2.0.4 → 2.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vidavidorra/create-project",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "private": false,
5
5
  "description": "Interactively create a GitHub project.",
6
6
  "homepage": "https://github.com/vidavidorra/create-project#readme",
@@ -20,10 +20,11 @@
20
20
  },
21
21
  "files": [
22
22
  "./dist/**/!(*.test).{js,d.ts,cjs}",
23
- "./.github/",
24
23
  "./.editorconfig",
24
+ "./.github/",
25
25
  "./.gitignore",
26
26
  "./.npmrc",
27
+ "./src/scripts/postinstall.js",
27
28
  "./LICENSE.md",
28
29
  "./tsconfig.json"
29
30
  ],
@@ -0,0 +1,32 @@
1
+ import fs from 'node:fs';
2
+ import {fileURLToPath} from 'node:url';
3
+ import {argv} from 'node:process';
4
+ import {join, resolve, dirname} from 'node:path';
5
+
6
+ const rootPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../');
7
+ const gitIgnore = join(rootPath, '.gitignore');
8
+ const npmIgnore = join(rootPath, '.npmignore');
9
+
10
+ /**
11
+ * Workaround for [Rename `.gitignore` to `.npmignore` in package if no
12
+ * `.npmignore` found](https://github.com/npm/npm/issues/1862) and ['npm pack'/
13
+ * `publish` option to not rename or keep a copy of `.gitignore` files](
14
+ * https://github.com/npm/npm/issues/7252) issues. With npm v9 or newer, the
15
+ * `npm pack` includes the `.gitignore` in the tarball and `npm install` renames
16
+ * the file to `.npmignore`. This script simply reverts that rename if it has
17
+ * occurred.
18
+ */
19
+ function postinstall() {
20
+ if (fs.existsSync(npmIgnore) && !fs.existsSync(gitIgnore)) {
21
+ fs.renameSync(npmIgnore, gitIgnore);
22
+ }
23
+ }
24
+
25
+ if (
26
+ import.meta.url.startsWith('file:') &&
27
+ fileURLToPath(import.meta.url) === argv.at(1)
28
+ ) {
29
+ postinstall();
30
+ }
31
+
32
+ export {gitIgnore, npmIgnore, postinstall};