Skip to content

Commit

Permalink
fix(watch): fix git ignore parsing
Browse files Browse the repository at this point in the history
using a more reliable module
  • Loading branch information
nfroidure committed Nov 27, 2023
1 parent 09292c7 commit 392e53f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 28 deletions.
18 changes: 4 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ DEV_MODE=1
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"jsarch": "^6.0.3",
"parse-gitignore": "^2.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"schema2dts": "^5.3.0",
Expand Down Expand Up @@ -510,7 +509,6 @@ DEV_MODE=1
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"jsarch": "^6.0.3",
"parse-gitignore": "^2.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"schema2dts": "^5.3.0",
Expand Down Expand Up @@ -882,7 +880,6 @@ DEV_MODE=1
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"jsarch": "^6.0.3",
"parse-gitignore": "^2.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"schema2dts": "^5.3.0",
Expand Down Expand Up @@ -1237,7 +1234,6 @@ DEV_MODE=1
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"jsarch": "^6.0.3",
"parse-gitignore": "^2.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"schema2dts": "^5.3.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/whook-create/src/services/createWhook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ describe('initCreateWhook', () => {
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"jsarch": "^6.0.3",
"parse-gitignore": "^2.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"schema2dts": "^5.3.0",
Expand Down Expand Up @@ -416,7 +415,6 @@ describe('initCreateWhook', () => {
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"jsarch": "^6.0.3",
"parse-gitignore": "^2.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"schema2dts": "^5.3.0",
Expand Down Expand Up @@ -623,7 +621,6 @@ describe('initCreateWhook', () => {
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"jsarch": "^6.0.3",
"parse-gitignore": "^2.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"schema2dts": "^5.3.0",
Expand Down
1 change: 0 additions & 1 deletion packages/whook-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
"jsarch": "^6.0.3",
"metapak": "^5.1.7",
"metapak-nfroidure": "15.0.4",
"parse-gitignore": "^2.0.0",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"schema2dts": "^5.3.0",
Expand Down
1 change: 1 addition & 0 deletions packages/whook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"fs-extra": "^11.1.1",
"ignore": "^5.3.0",
"inquirer": "^9.2.12",
"internal-ip": "^8.0.0",
"knifecycle": "^17.0.1",
Expand Down
14 changes: 8 additions & 6 deletions packages/whook/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import initGenerateOpenAPITypes from './commands/generateOpenAPITypes.js';
import initGetOpenAPI from './handlers/getOpenAPI.js';
import { readFile } from 'fs';
import { promisify } from 'util';
import parseGitIgnore from 'parse-gitignore';
import ignore from 'ignore';
import { createRequire } from 'module';
import { AppEnvVars } from 'application-services';
import type { Dependencies, Knifecycle } from 'knifecycle';
Expand Down Expand Up @@ -43,12 +43,14 @@ export async function watchDevServer<T extends Dependencies>(
injectedNames: [],
},
): Promise<void> {
let ignored = ['node_modules', '*.d.ts', '.git'];
let ignoreFilter;

try {
ignored = ignored.concat(
parseGitIgnore((await promisify(readFile)('.gitignore')).toString()),
);
ignoreFilter = ignore
.default()
.add(['node_modules', '*.d.ts', '.git'])
.add((await promisify(readFile)('.gitignore')).toString())
.createFilter();
} catch (err) {
// TODO: requires a deeper integration of Knifecycle to
// start with a silo containing only the environment
Expand All @@ -63,7 +65,7 @@ export async function watchDevServer<T extends Dependencies>(
await new Promise<void>((resolve, reject) => {
chokidar
.watch(['**/*.ts', 'package*.json'], {
ignored,
ignored: ignoreFilter,
ignoreInitial: true,
})
.once('ready', () => {
Expand Down

0 comments on commit 392e53f

Please sign in to comment.