view-ignored 0.4.1 → 0.4.2

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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![github](https://img.shields.io/github/stars/Mopsgamer/view-ignored.svg?style=flat)](https://github.com/Mopsgamer/view-ignored)
6
6
  [![github issues](https://img.shields.io/github/issues/Mopsgamer/view-ignored.svg?style=flat)](https://github.com/Mopsgamer/view-ignored/issues)
7
7
 
8
- Retrieve list of files ignored/included by Git, NPM, Yarn and VSC Extension.
8
+ Retrieve list of files ignored/included by Git, NPM, Yarn, JSR, VSCE or other tools.
9
9
 
10
10
  ## Highlights
11
11
 
@@ -88,8 +88,7 @@ const fileInfoSorted = fileInfoList.sort((a, b) => sorter(String(a), String(b)))
88
88
  ### Targets
89
89
 
90
90
  - `git`
91
- - `npm` (use it for PNPM and Bun)
91
+ - `npm` (compatible with Bun, PNPM, and others)
92
92
  - `yarn`
93
93
  - `vsce`
94
- - `jsr` *planned*
95
- - `deno` *planned*
94
+ - `jsr` (compatible with Deno)
@@ -3,7 +3,7 @@ export * from './targets.js';
3
3
  /**
4
4
  * Built-in name list.
5
5
  */
6
- export declare const builtInNameList: readonly ["git", "npm", "vsce", "yarn"];
6
+ export declare const builtInNameList: readonly ["git", "npm", "vsce", "yarn", "jsr"];
7
7
  /**
8
8
  * Built-in name type.
9
9
  */
@@ -11,11 +11,12 @@ const builtInImportMap = {
11
11
  npm: './plugins/npm.js',
12
12
  vsce: './plugins/vsce.js',
13
13
  yarn: './plugins/yarn.js',
14
+ jsr: './plugins/jsr.js',
14
15
  };
15
16
  /**
16
17
  * Built-in name list.
17
18
  */
18
- export const builtInNameList = ['git', 'npm', 'vsce', 'yarn'];
19
+ export const builtInNameList = ['git', 'npm', 'vsce', 'yarn', 'jsr'];
19
20
  /**
20
21
  * Checks if the value is the {@link PluginExport}.
21
22
  */
@@ -0,0 +1,3 @@
1
+ import { type Plugins } from '../../index.js';
2
+ declare const npm: Plugins.PluginExport;
3
+ export default npm;
@@ -0,0 +1,96 @@
1
+ import { icons } from '@m234/nerd-fonts';
2
+ import { z } from 'zod';
3
+ import { Directory, InvalidPatternError, BadSourceError, } from '../../index.js';
4
+ import { ScannerGitignore } from '../scanner.js';
5
+ import * as git from './git.js';
6
+ const id = 'jsr';
7
+ const name = 'JSR';
8
+ const icon = { ...icons['nf-ple-pixelated_squares_big'], color: '#F5DD1E' };
9
+ /**
10
+ * @internal
11
+ */
12
+ export const matcherExclude = [];
13
+ /**
14
+ * @internal
15
+ */
16
+ export const matcherInclude = [];
17
+ /**
18
+ * @internal
19
+ */
20
+ export function isValidManifestJsr(value) {
21
+ return z.object({
22
+ name: z.string(),
23
+ version: z.string(),
24
+ exports: z.string(),
25
+ exclude: z.array(z.string()).optional(),
26
+ include: z.array(z.string()).optional(),
27
+ publish: z.object({
28
+ exclude: z.array(z.string()).optional(),
29
+ include: z.array(z.string()).optional(),
30
+ }).optional(),
31
+ }).safeParse(value).success;
32
+ }
33
+ /**
34
+ * @internal
35
+ */
36
+ export function useChildren(tree, map, getMap) {
37
+ for (const child of tree.children.values()) {
38
+ if (!(child instanceof Directory)) {
39
+ continue;
40
+ }
41
+ const submap = getMap(child);
42
+ for (const [key, value] of submap.entries()) {
43
+ map.set(key, value);
44
+ }
45
+ }
46
+ return map;
47
+ }
48
+ /**
49
+ * @internal
50
+ */
51
+ export const sourceSearch = (priority, scanner) => function (tree, o) {
52
+ const map = new Map();
53
+ for (const element of priority) {
54
+ const sourceFile = tree.get(element);
55
+ if (sourceFile === undefined) {
56
+ continue;
57
+ }
58
+ if (/^(deno|jsr).jsonc?$/.test(sourceFile.base)) {
59
+ const manifest = JSON.parse(o.modules.fs.readFileSync(sourceFile.absolutePath).toString());
60
+ if (!isValidManifestJsr(manifest)) {
61
+ throw new BadSourceError(sourceFile, 'Must have \'name\', \'version\'.');
62
+ }
63
+ const { exclude, include, publish } = manifest;
64
+ if (exclude === undefined && include === undefined && publish === undefined) {
65
+ continue;
66
+ }
67
+ const pattern = publish?.include ?? include;
68
+ if (!scanner.isValid(pattern)) {
69
+ throw new BadSourceError(sourceFile, `Invalid pattern, got ${JSON.stringify(pattern)}`);
70
+ }
71
+ scanner.negated = true;
72
+ scanner.pattern = pattern;
73
+ if (Array.isArray(scanner.exclude)) {
74
+ scanner.exclude.push(...(publish?.exclude ?? exclude ?? []));
75
+ }
76
+ }
77
+ else {
78
+ const content = o.modules.fs.readFileSync(sourceFile.absolutePath).toString();
79
+ const pattern = content;
80
+ if (!scanner.isValid(pattern)) {
81
+ throw new InvalidPatternError(sourceFile, pattern);
82
+ }
83
+ scanner.negated = false;
84
+ scanner.pattern = pattern;
85
+ }
86
+ return git.useSourceFile(map, sourceFile, scanner);
87
+ }
88
+ return useChildren(tree, map, child => sourceSearch(priority, scanner)(child, o));
89
+ };
90
+ const bind = {
91
+ id, icon, name, scanOptions: {
92
+ target: sourceSearch(['deno.json', 'deno.jsonc', 'jsr.json', 'jsr.jsonc'], new ScannerGitignore({ exclude: matcherExclude, include: matcherInclude })),
93
+ },
94
+ };
95
+ const npm = { viewignored: { addTargets: [bind] } };
96
+ export default npm;
@@ -1,4 +1,5 @@
1
1
  import { icons } from '@m234/nerd-fonts';
2
+ import { z } from 'zod';
2
3
  import { Directory, InvalidPatternError, BadSourceError, NoSourceError, } from '../../index.js';
3
4
  import { ScannerGitignore } from '../scanner.js';
4
5
  import * as git from './git.js';
@@ -40,14 +41,12 @@ export const matcherInclude = [
40
41
  /**
41
42
  * @internal
42
43
  */
43
- export function isValidManifest(value) {
44
- if (value?.constructor !== Object) {
45
- return false;
46
- }
47
- const value_ = value;
48
- return ('name' in value_ && typeof value_.name === 'string')
49
- && ('version' in value_ && typeof value_.version === 'string')
50
- && (value_.files === undefined || (Array.isArray(value_.files) && value_.files.every(element => typeof element === 'string')));
44
+ export function isValidManifestPackageJson(value) {
45
+ return z.object({
46
+ name: z.string(),
47
+ version: z.string(),
48
+ files: z.array(z.string()).optional(),
49
+ }).safeParse(value).success;
51
50
  }
52
51
  /**
53
52
  * @internal
@@ -76,7 +75,7 @@ export const sourceSearch = (priority, scanner) => function (tree, o) {
76
75
  }
77
76
  if (sourceFile.base === 'package.json') {
78
77
  const manifest = JSON.parse(o.modules.fs.readFileSync(sourceFile.absolutePath).toString());
79
- if (!isValidManifest(manifest)) {
78
+ if (!isValidManifestPackageJson(manifest)) {
80
79
  throw new BadSourceError(sourceFile, 'Must have \'name\', \'version\' and \'files\'.');
81
80
  }
82
81
  const { files: pattern } = manifest;
@@ -123,7 +122,7 @@ export const methodologyManifestNpmLike = (priority, scanner) => function (tree,
123
122
  }
124
123
  throw error;
125
124
  }
126
- if (!isValidManifest(manifest)) {
125
+ if (!isValidManifestPackageJson(manifest)) {
127
126
  throw new BadSourceError(packageJson, 'Must have \'name\', \'version\' and \'files\'.');
128
127
  }
129
128
  return sourceSearch(priority, scanner)(tree, o);
@@ -47,8 +47,8 @@ export class Directory {
47
47
  */
48
48
  static deepStream(directoryPath, optionsReal) {
49
49
  const controller = new EventEmitter();
50
- controller.endPromise = new Promise(resolve => {
51
- controller.once('end', data => {
50
+ controller.endPromise = new Promise((resolve) => {
51
+ controller.once('end', (data) => {
52
52
  resolve(data);
53
53
  });
54
54
  });
@@ -56,7 +56,7 @@ export declare class FileInfo extends File {
56
56
  static from(file: File, source?: SourceInfo): FileInfo;
57
57
  /**
58
58
  * Determines if ignored file is ignored or not.
59
- */
59
+ */
60
60
  readonly status: FileInfoStatus;
61
61
  constructor(
62
62
  /**
@@ -12,7 +12,7 @@ export class FileInfo extends File {
12
12
  }
13
13
  /**
14
14
  * Determines if ignored file is ignored or not.
15
- */
15
+ */
16
16
  status;
17
17
  constructor(
18
18
  /**
@@ -8,8 +8,8 @@ export type FormatFilesOptions = {
8
8
  * resolved UNC forms, eg instead of `'C:\\foo\\bar'`, it would return
9
9
  * `'//?/C:/foo/bar'`
10
10
  * @default false
11
- * @returns `/` delimited paths, even on Windows.
12
- */
11
+ * @returns `/` delimited paths, even on Windows.
12
+ */
13
13
  posix?: boolean;
14
14
  /**
15
15
  * @default false
package/out/cli.js CHANGED
@@ -232,8 +232,8 @@ export async function actionScan() {
232
232
  fileInfoList: [],
233
233
  stream,
234
234
  message: '',
235
- reading: new Promise(resolve => {
236
- stream.on('end', data => {
235
+ reading: new Promise((resolve) => {
236
+ stream.on('end', (data) => {
237
237
  resolve(data);
238
238
  });
239
239
  }),
package/out/config.js CHANGED
@@ -54,7 +54,7 @@ export const configDefault = {
54
54
  concurrency: 8,
55
55
  };
56
56
  export const configValueArray = (type) => {
57
- const validator = value => {
57
+ const validator = (value) => {
58
58
  if (Array.isArray(value)) {
59
59
  if (type === undefined) {
60
60
  return;
@@ -72,7 +72,7 @@ export const configValueArray = (type) => {
72
72
  return validator;
73
73
  };
74
74
  export const configValueLiteral = (choices) => {
75
- const validator = value => {
75
+ const validator = (value) => {
76
76
  if (choices.includes(value)) {
77
77
  return;
78
78
  }
@@ -85,7 +85,7 @@ export const switchTrueValues = ['true', 'on', 'yes', 'y', 'enable', 'enabled',
85
85
  export const switchFalseValues = ['false', 'off', 'no', 'n', 'disable', 'disabled', '0'];
86
86
  export const booleanValues = [...switchTrueValues, ...switchFalseValues];
87
87
  export const configValueSwitch = () => {
88
- const validator = value => {
88
+ const validator = (value) => {
89
89
  if (booleanValues.includes(value)) {
90
90
  return;
91
91
  }
@@ -95,7 +95,7 @@ export const configValueSwitch = () => {
95
95
  return validator;
96
96
  };
97
97
  export const configValueBoolean = () => {
98
- const validator = value => {
98
+ const validator = (value) => {
99
99
  if (typeof value === 'boolean') {
100
100
  return;
101
101
  }
@@ -105,7 +105,7 @@ export const configValueBoolean = () => {
105
105
  return validator;
106
106
  };
107
107
  export const configValueObject = () => {
108
- const validator = value => {
108
+ const validator = (value) => {
109
109
  if (value?.constructor === Object) {
110
110
  return;
111
111
  }
@@ -115,7 +115,7 @@ export const configValueObject = () => {
115
115
  return validator;
116
116
  };
117
117
  export const configValueString = () => {
118
- const validator = value => {
118
+ const validator = (value) => {
119
119
  if (typeof value === 'string') {
120
120
  return;
121
121
  }
@@ -125,7 +125,7 @@ export const configValueString = () => {
125
125
  return validator;
126
126
  };
127
127
  export const configValueNumber = () => {
128
- const validator = value => {
128
+ const validator = (value) => {
129
129
  if (typeof value === 'number') {
130
130
  return;
131
131
  }
@@ -135,7 +135,7 @@ export const configValueNumber = () => {
135
135
  return validator;
136
136
  };
137
137
  export const configValueInteger = () => {
138
- const validator = value => {
138
+ const validator = (value) => {
139
139
  if (typeof value === 'number' && (Number.isSafeInteger(value) || Math.abs(value) === Infinity)) {
140
140
  return;
141
141
  }
package/out/styling.js CHANGED
@@ -16,7 +16,7 @@ export function highlight(text, chalk) {
16
16
  const rall = new RegExp(`${[ansiRegex(), rstring, rseparator, rbracketsSquare, rnumber, rspecial]
17
17
  .map(r => `(${typeof r === 'string' ? r : r.source})`)
18
18
  .join('|')}`, 'g');
19
- const colored = text.replaceAll(rall, match => {
19
+ const colored = text.replaceAll(rall, (match) => {
20
20
  if (match.match(ansiRegex()) !== null) {
21
21
  return match;
22
22
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "view-ignored",
3
- "version": "0.4.1",
4
- "description": "Retrieve list of files ignored/included by Git, NPM, Yarn and VSC Extension.",
3
+ "version": "0.4.2",
4
+ "description": "Retrieve list of files ignored/included by Git, NPM, Yarn, JSR, VSCE or other tools.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "viewig": "./bin/viewig",
8
8
  "view-ignored": "./bin/viewig"
9
9
  },
10
10
  "scripts": {
11
- "prerelease": "bun run lint && bun run build:pub && bun run test",
11
+ "prerelease": "bun run build:pub && bun run lint",
12
12
  "test": "bun run node --test out/**/*.test.js",
13
13
  "build": "bun run build:clean && bun run tsc -p src",
14
14
  "build:pub": "bun run build:clean && bun run tsc -p src --sourceMap false && rm **/*.test.d.ts",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "dependencies": {
73
73
  "@humanwhocodes/gitignore-to-minimatch": "^1.0.2",
74
- "@m234/nerd-fonts": "^0.3.0",
74
+ "@m234/nerd-fonts": "^0.3.1",
75
75
  "ansi-regex": "^6.1.0",
76
76
  "boxen": "^8.0.1",
77
77
  "chalk": "^5.4.1",
@@ -82,12 +82,13 @@
82
82
  "minimatch": "^10.0.3",
83
83
  "p-limit": "^6.2.0",
84
84
  "treeify": "^1.1.0",
85
- "tslib": "^2.8.1",
86
- "yaml": "^2.8.0"
85
+ "yaml": "^2.8.0",
86
+ "zod": "^3.25.71"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@eslint/js": "^9.30.1",
90
90
  "@release-it/keep-a-changelog": "^7.0.0",
91
+ "@stylistic/eslint-plugin": "^5.1.0",
91
92
  "@types/node": "^24.0.10",
92
93
  "@types/treeify": "^1.0.3",
93
94
  "eslint": "^9.30.1",