Skip to content

Commit

Permalink
fix: Filter local files using global ignores and .gitignore (#53)
Browse files Browse the repository at this point in the history
This cleans up the amount of files that are sent to the editor to not include things such as `node_modules`, `build`, and other ignored files.

fixes #49
  • Loading branch information
Zoramite authored Aug 4, 2021
1 parent 855a373 commit 91e1bfb
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"typescript": "^4.3.5"
},
"dependencies": {
"@blinkk/editor.dev-ui": "^3.7.0",
"@blinkk/editor.dev-ui": "^3.8.0",
"@blinkk/selective-edit": "^2.2.1",
"@google-cloud/datastore": "^6.4.7",
"@google-cloud/error-reporting": "^2.0.2",
Expand Down
51 changes: 48 additions & 3 deletions src/ts/api/localApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import {
FileNotFoundError,
ProjectTypeStorageComponent,
} from '../storage/storage';
import {
GitignoreFilter,
GlobFilter,
} from '@blinkk/editor.dev-ui/dist/utility/filter';

import {AmagakiApi} from './projectType/amagakiApi';
import {AmagakiProjectType} from '../projectType/amagakiProjectType';
import {FeatureFlags} from '@blinkk/editor.dev-ui/dist/editor/features';
Expand Down Expand Up @@ -273,12 +278,52 @@ export class LocalApi implements ApiComponent {
const projectType = await this.getProjectType(storage);
const files = await storage.readDir('/');
let filteredFiles = files;

// Globally ignored files.
const ignoreFilter = new GlobFilter({
negate: true,
patterns: ['/.git/**', '**/.*', '**/_*'],
});
filteredFiles = filteredFiles.filter(file =>
ignoreFilter.matches(file.path)
);

// Check for project type specific filtering.
if (projectType.fileFilter) {
filteredFiles = files.filter(file =>
filteredFiles = filteredFiles.filter(file =>
projectType.fileFilter?.matches(file.path)
);
} else {
// TODO: Default file filter for api.
}

// Ignore files that are in .gitignore.
try {
const gitIgnoreFile = await storage.readFile('.gitignore');
const ignorePatterns = gitIgnoreFile
.split(/\r?\n/)
.filter((value: string) => {
value = value.trim();
if (value.startsWith('#')) {
return false;
}
if (value.length === 0) {
return false;
}
return true;
});

const gitIgnoreFilter = new GitignoreFilter({
patterns: ignorePatterns,
});

filteredFiles = filteredFiles.filter(file =>
gitIgnoreFilter.matches(file.path)
);
} catch (error) {
if (error instanceof FileNotFoundError) {
// pass.
} else {
throw error;
}
}

// Convert to the correct FileDate interface.
Expand Down
139 changes: 106 additions & 33 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,24 @@
"@babel/helper-validator-identifier" "^7.14.9"
to-fast-properties "^2.0.0"

"@blinkk/editor.dev-ui@^3.7.0":
version "3.7.0"
resolved "https://registry.yarnpkg.com/@blinkk/editor.dev-ui/-/editor.dev-ui-3.7.0.tgz#2340785281f565b0c2a158b84a6093cf69e339d6"
integrity sha512-DHp6PUZEHhc1tJ/3CTYG6AVcgKOs+wn4mP3P0r+PgG619WQxV6aJfSIKhdor706LT9nWWIlHHS/XnIGFwJrAQw==
"@blinkk/editor.dev-ui@^3.8.0":
version "3.8.0"
resolved "https://registry.yarnpkg.com/@blinkk/editor.dev-ui/-/editor.dev-ui-3.8.0.tgz#fb70566cee85e27a361dcade503c2cf9881fe17a"
integrity sha512-Yz/q3eeFenwzJ73ou5D6GkNNclKTEAWZ6NRfrI2TdxdsLbOgNMi8wzjTAcKTHg2T+thTSNL8mPnFq8X2tjBdNw==
dependencies:
"@blinkk/selective-edit" "^2.2.1"
"@toast-ui/editor" "^2.5.3"
"@toast-ui/editor" "^3.0.2"
bent "^7.3.12"
codemirror "^5.62.2"
javascript-time-ago "^2.3.8"
js-yaml "^4.1.0"
lodash.clonedeep "^4.5.0"
lodash.merge "^4.6.2"
marked "^2.1.3"
minimatch "^3.0.4"
path-browserify "^1.0.1"
quill "^1.3.7"
sass "^1.37.0"
sass "^1.37.5"
stackdriver-errors-js "^0.8.0"

"@blinkk/selective-edit@^2.2.1":
Expand Down Expand Up @@ -510,13 +512,18 @@
dependencies:
defer-to-connect "^1.0.1"

"@toast-ui/editor@^2.5.3":
version "2.5.3"
resolved "https://registry.yarnpkg.com/@toast-ui/editor/-/editor-2.5.3.tgz#c1a4094be7fa8516628c214de7d7e9c78dd1ebea"
integrity sha512-KKDBaB3fOylox1GZsfw0pDUOPFfpz9hqHmJvSwassWKeRUDkijJvpNdSwUn9jMxXSIvKqKoOxlv6say1JXxgAA==
"@toast-ui/editor@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@toast-ui/editor/-/editor-3.0.2.tgz#a4caef695f65fe59f0aa1010b1ed23b649ffadbb"
integrity sha512-auyfN5OzXZoR76FeR9kVKuZctEPj15i9PQOM4ebE1VOWyJ9VPXPwFYDZ1KQNWkxkMWWqw7qI28VDIUQhTvK3mg==
dependencies:
"@types/codemirror" "0.0.71"
codemirror "^5.48.4"
prosemirror-commands "^1.1.9"
prosemirror-history "^1.1.3"
prosemirror-inputrules "^1.1.3"
prosemirror-keymap "^1.1.4"
prosemirror-model "^1.14.1"
prosemirror-state "^1.3.4"
prosemirror-view "^1.18.7"

"@tootallnate/once@1":
version "1.1.2"
Expand Down Expand Up @@ -558,13 +565,6 @@
"@types/connect" "*"
"@types/node" "*"

"@types/[email protected]":
version "0.0.71"
resolved "https://registry.yarnpkg.com/@types/codemirror/-/codemirror-0.0.71.tgz#861f1bcb3100c0a064567c5400f2981cf4ae8ca7"
integrity sha512-b2oEEnno1LIGKMR7uBEsr40al1UijF1HEpRn0+Yf1xOLl24iQgB7DBpZVMM7y54G5wCNoclDrRO65E6KHPNO2w==
dependencies:
"@types/tern" "*"

"@types/connect@*":
version "3.4.35"
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.35.tgz#5fcf6ae445e4021d1fc2219a4873cc73a3bb2ad1"
Expand All @@ -577,11 +577,6 @@
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080"
integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==

"@types/estree@*":
version "0.0.50"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.50.tgz#1e0caa9364d3fccd2931c3ed96fdbeaa5d4cca83"
integrity sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw==

"@types/express-serve-static-core@^4.17.18":
version "4.17.24"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.24.tgz#ea41f93bf7e0d59cd5a76665068ed6aab6815c07"
Expand Down Expand Up @@ -659,13 +654,6 @@
"@types/mime" "^1"
"@types/node" "*"

"@types/tern@*":
version "0.23.4"
resolved "https://registry.yarnpkg.com/@types/tern/-/tern-0.23.4.tgz#03926eb13dbeaf3ae0d390caf706b2643a0127fb"
integrity sha512-JAUw1iXGO1qaWwEOzxTKJZ/5JxVeON9kvGZ/osgZaJImBnyjyn0cjovPsf6FNLmyGY8Vw9DoXZCMlfMkMwHRWg==
dependencies:
"@types/estree" "*"

"@typescript-eslint/eslint-plugin@^4.2.0", "@typescript-eslint/eslint-plugin@^4.29.0":
version "4.29.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.29.0.tgz#b866c9cd193bfaba5e89bade0015629ebeb27996"
Expand Down Expand Up @@ -1371,7 +1359,7 @@ codecov@^3.8.3:
teeny-request "7.1.1"
urlgrey "1.0.0"

codemirror@^5.48.4, codemirror@^5.62.2:
codemirror@^5.62.2:
version "5.62.2"
resolved "https://registry.yarnpkg.com/codemirror/-/codemirror-5.62.2.tgz#bce6d19c9829e6e788f83886d48ecf5c1e106e65"
integrity sha512-tVFMUa4J3Q8JUd1KL9yQzQB0/BJt7ZYZujZmTPgo/54Lpuq3ez4C8x/ATUY/wv7b7X3AUq8o3Xd+2C5ZrCGWHw==
Expand Down Expand Up @@ -3646,6 +3634,11 @@ ora@^5.2.0:
strip-ansi "^6.0.0"
wcwidth "^1.0.1"

orderedmap@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/orderedmap/-/orderedmap-1.1.1.tgz#c618e77611b3b21d0fe3edc92586265e0059c789"
integrity sha512-3Ux8um0zXbVacKUkcytc0u3HgC0b0bBLT+I60r2J/En72cI0nZffqrA7Xtf2Hqs27j1g82llR5Mhbd0Z1XW4AQ==

os-tmpdir@~1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
Expand Down Expand Up @@ -3785,6 +3778,11 @@ parseurl@~1.3.3:
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4"
integrity sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==

path-browserify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd"
integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==

path-exists@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515"
Expand Down Expand Up @@ -3898,6 +3896,71 @@ progress@^2.0.0, progress@^2.0.3:
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==

prosemirror-commands@^1.1.9:
version "1.1.10"
resolved "https://registry.yarnpkg.com/prosemirror-commands/-/prosemirror-commands-1.1.10.tgz#406a6589966e6cd80809cea2d801fb998639b37d"
integrity sha512-IWyBBXNAd44RM6NnBPljwq+/CM2oYCQJkF+YhKEAZNwzW0uFdGf4qComhjbKZzqFdu6Iub2ZhNsXgwPibA0lCQ==
dependencies:
prosemirror-model "^1.0.0"
prosemirror-state "^1.0.0"
prosemirror-transform "^1.0.0"

prosemirror-history@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/prosemirror-history/-/prosemirror-history-1.1.3.tgz#4f76a1e71db4ef7cdf0e13dec6d8da2aeaecd489"
integrity sha512-zGDotijea+vnfnyyUGyiy1wfOQhf0B/b6zYcCouBV8yo6JmrE9X23M5q7Nf/nATywEZbgRLG70R4DmfSTC+gfg==
dependencies:
prosemirror-state "^1.2.2"
prosemirror-transform "^1.0.0"
rope-sequence "^1.3.0"

prosemirror-inputrules@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/prosemirror-inputrules/-/prosemirror-inputrules-1.1.3.tgz#93f9199ca02473259c30d7e352e4c14022d54638"
integrity sha512-ZaHCLyBtvbyIHv0f5p6boQTIJjlD6o2NPZiEaZWT2DA+j591zS29QQEMT4lBqwcLW3qRSf7ZvoKNbf05YrsStw==
dependencies:
prosemirror-state "^1.0.0"
prosemirror-transform "^1.0.0"

prosemirror-keymap@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/prosemirror-keymap/-/prosemirror-keymap-1.1.4.tgz#8b481bf8389a5ac40d38dbd67ec3da2c7eac6a6d"
integrity sha512-Al8cVUOnDFL4gcI5IDlG6xbZ0aOD/i3B17VT+1JbHWDguCgt/lBHVTHUBcKvvbSg6+q/W4Nj1Fu6bwZSca3xjg==
dependencies:
prosemirror-state "^1.0.0"
w3c-keyname "^2.2.0"

prosemirror-model@^1.0.0, prosemirror-model@^1.14.1, prosemirror-model@^1.14.3:
version "1.14.3"
resolved "https://registry.yarnpkg.com/prosemirror-model/-/prosemirror-model-1.14.3.tgz#a9c250d3c4023ddf10ecb41a0a7a130e9741d37e"
integrity sha512-yzZlBaSxfUPIIP6U5Edh5zKxJPZ5f7bwZRhiCuH3UYkWhj+P3d8swHsbuAMOu/iDatDc5J/Qs5Mb3++mZf+CvQ==
dependencies:
orderedmap "^1.1.0"

prosemirror-state@^1.0.0, prosemirror-state@^1.2.2, prosemirror-state@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/prosemirror-state/-/prosemirror-state-1.3.4.tgz#4c6b52628216e753fc901c6d2bfd84ce109e8952"
integrity sha512-Xkkrpd1y/TQ6HKzN3agsQIGRcLckUMA9u3j207L04mt8ToRgpGeyhbVv0HI7omDORIBHjR29b7AwlATFFf2GLA==
dependencies:
prosemirror-model "^1.0.0"
prosemirror-transform "^1.0.0"

prosemirror-transform@^1.0.0, prosemirror-transform@^1.1.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/prosemirror-transform/-/prosemirror-transform-1.3.2.tgz#5620ebe7379e6fae4f34ecc881886cb22ce96579"
integrity sha512-/G6d/u9Mf6Bv3H1XR8VxhpjmUO75LYmnvj+s3ZfZpakU1hnQbsvCEybml1B3f2IWUAAQRFkbO1PnsbFhLZsYsw==
dependencies:
prosemirror-model "^1.0.0"

prosemirror-view@^1.18.7:
version "1.18.11"
resolved "https://registry.yarnpkg.com/prosemirror-view/-/prosemirror-view-1.18.11.tgz#1a839508e7cb6d500a95512af8079661f9e36034"
integrity sha512-KXUM8UEV+IK4JYWHNyxkPGDGbxeTEUHQv3POApfyTRN5eMcPFbY4cB0mDJr0LPelVvYPghmZDOCqfCIm9mYHtQ==
dependencies:
prosemirror-model "^1.14.3"
prosemirror-state "^1.0.0"
prosemirror-transform "^1.1.0"

[email protected], protobufjs@^6.10.0:
version "6.11.2"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.11.2.tgz#de39fabd4ed32beaa08e9bb1e30d08544c1edf8b"
Expand Down Expand Up @@ -4173,6 +4236,11 @@ rimraf@^3.0.0, rimraf@^3.0.2:
dependencies:
glob "^7.1.3"

rope-sequence@^1.3.0:
version "1.3.2"
resolved "https://registry.yarnpkg.com/rope-sequence/-/rope-sequence-1.3.2.tgz#a19e02d72991ca71feb6b5f8a91154e48e3c098b"
integrity sha512-ku6MFrwEVSVmXLvy3dYph3LAMNS0890K7fabn+0YIRQ2T96T9F4gkFf0vf0WW0JUraNWwGRtInEpH7yO4tbQZg==

run-async@^2.4.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"
Expand Down Expand Up @@ -4207,7 +4275,7 @@ safe-buffer@^5.0.1, safe-buffer@~5.2.0:
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==

sass@^1.37.0:
sass@^1.37.5:
version "1.37.5"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.37.5.tgz#f6838351f7cc814c4fcfe1d9a20e0cabbd1e7b3c"
integrity sha512-Cx3ewxz9QB/ErnVIiWg2cH0kiYZ0FPvheDTVC6BsiEGBTZKKZJ1Gq5Kq6jy3PKtL6+EJ8NIoaBW/RSd2R6cZOA==
Expand Down Expand Up @@ -4956,6 +5024,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-5.2.0.tgz#01f01760a391e8222fe4f33fbccbd1ad71aed74e"
integrity sha512-Uw5ooOQxRASHgu6C7GVvUxisKXfSgW4oFlO+aa+PAkgmH89O3CXxEEzNRNtHSqtXFTl0nAC1uYj0GMSH27uwtQ==

w3c-keyname@^2.2.0:
version "2.2.4"
resolved "https://registry.yarnpkg.com/w3c-keyname/-/w3c-keyname-2.2.4.tgz#4ade6916f6290224cdbd1db8ac49eab03d0eef6b"
integrity sha512-tOhfEwEzFLJzf6d1ZPkYfGj+FWhIpBux9ppoP3rlclw3Z0BZv3N7b7030Z1kYth+6rDuAsXUFr+d0VE6Ed1ikw==

wcwidth@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8"
Expand Down

0 comments on commit 91e1bfb

Please sign in to comment.