view-ignored 0.8.0 → 0.9.0

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
@@ -138,37 +138,39 @@ vign.scan({ target, cwd, fs })
138
138
 
139
139
  ## Targets
140
140
 
141
- > [!NOTE]
142
- > Each scanner expects minimal configurations, but the actual tool can have
143
- > more/less complex rules. Refer to the documentation of each tool for details.
144
-
145
141
  The following built-in scanners are available:
146
142
 
147
- - Git
143
+ - Git ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts))
148
144
  - Reads `.gitignore` and `.git/info/exclude` but does not consider global settings.
149
145
  - Starts searching from `/`.
150
146
  - Check this scanner by running `git ls-files --others --exclude-standard --cached`.
151
- - See the implementation of [Git target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/git.ts) for details.
152
- - NPM (expecting to be compatible with Bun, PNPM, and others)
153
- - Reads `.npmignore` and `package.json` `files` field.
147
+ - NPM ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts))
148
+ - Expecting to be compatible with PNPM, and others.
149
+ - Validates `package.json`.
150
+ - Reads `package.json` `files` field, `.npmignore` and `.gitignore`.
154
151
  - Starts searching from `.` (current working directory).
155
- - No additional checks for `name`, `version` or `publishConfig`.
156
152
  - Check this scanner by running `npm pack --dry-run`.
157
- - See the implementation of [NPM target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/npm.ts) for details.
158
- - Yarn
159
- - Modern Berry behavior, but does not include paths from `package.json` `main`, `module`, `browser` and `bin`.
160
- - `YarnClassic` is available.
153
+ - Bun ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/bun.ts))
154
+ - Bun tries to mimic NPM, but that does not mean it behaves the same way.
155
+ - Check this scanner by running `bun pm pack --dry-run`.
156
+ - Yarn ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts))
157
+ - Modern Berry behavior.
158
+ - Validates `package.json`.
159
+ - Reads `package.json` `files` field, `.npmignore` and `.gitignore`.
160
+ - Requires `package.json`: includes paths from `main`, `module`, `browser` and `bin`.
161
161
  - Starts searching from `.` (current working directory).
162
- - See the implementation of [Yarn target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarn.ts) for details.
163
- - VSCE
162
+ - `YarnClassic` is available. ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/yarnClassic.ts))
163
+ - VSCE ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts))
164
+ - Validates `package.json`.
164
165
  - Reads `package.json` `files` field, `.vscodeignore` and `.gitignore`.
165
166
  - Starts searching from `.` (current working directory).
166
167
  - Check this scanner by running `vsce ls`.
167
- - See the implementation of [VSCE target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/vsce.ts) for details.
168
- - JSR (compatible with Deno)
169
- - Reads `jsr.json(c)` and `deno.json(c)` `include` and `exclude` fields.
168
+ - JSR ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts))
169
+ - Validates and reads `jsr.json(c)` `include` and `exclude` fields.
170
+ - Starts searching from `.` (current working directory).
171
+ - Deno ([implementation](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/deno.ts))
172
+ - Validates and reads `jsr.json(c)` and `deno.json(c)` `include` and `exclude` fields.
170
173
  - Starts searching from `.` (current working directory).
171
- - See the implementation of [JSR target](https://github.com/Mopsgamer/view-ignored/tree/main/src/targets/jsr.ts) for details.
172
174
 
173
175
  ## See also
174
176
 
@@ -1,5 +1,5 @@
1
- import { MatcherStream } from "./patterns/matcherStream.js";
2
1
  import type { ScanOptions, FsAdapter } from "./types.js";
2
+ import { MatcherStream } from "./patterns/matcherStream.js";
3
3
  export type * from "./types.js";
4
4
  /**
5
5
  * @see {@link browserScan}
@@ -9,7 +9,9 @@ import { sourcePushNegatable } from "./source.js";
9
9
  */
10
10
  export function extractGitignore(source, content) {
11
11
  extract(source, content);
12
- signedPatternCompile(source.pattern);
12
+ for (const element of source.pattern) {
13
+ signedPatternCompile(element);
14
+ }
13
15
  }
14
16
  /**
15
17
  * Extracts and compiles patterns from the file.
@@ -20,10 +22,14 @@ export function extractGitignore(source, content) {
20
22
  */
21
23
  export function extractGitignoreNocase(source, content) {
22
24
  extract(source, content);
23
- signedPatternCompile(source.pattern, { nocase: true });
25
+ for (const element of source.pattern) {
26
+ signedPatternCompile(element, { nocase: true });
27
+ }
24
28
  }
25
29
  extractGitignore;
26
30
  function extract(source, content) {
31
+ const include = { compiled: null, excludes: false, pattern: [] };
32
+ const exclude = { compiled: null, excludes: true, pattern: [] };
27
33
  for (let line of content.toString().split("\n")) {
28
34
  line = line.trim();
29
35
  if (line === "" || line.startsWith("#")) {
@@ -33,6 +39,7 @@ function extract(source, content) {
33
39
  if (cdx >= 0) {
34
40
  line = line.substring(-cdx);
35
41
  }
36
- sourcePushNegatable(source, line);
42
+ sourcePushNegatable(line, false, include, exclude);
37
43
  }
44
+ source.pattern.push(include, exclude);
38
45
  }
@@ -19,6 +19,8 @@ const parse = type("string")
19
19
  */
20
20
  export function extractJsrJson(source, content, ctx) {
21
21
  const dist = parse(content.toString());
22
+ const include = { compiled: null, excludes: false, pattern: [] };
23
+ const exclude = { compiled: null, excludes: true, pattern: [] };
22
24
  if (dist instanceof type.errors) {
23
25
  source.error = new Error("Invalid '" + source.path + "': " + dist.summary, { cause: dist });
24
26
  ctx.failed.push(source);
@@ -26,21 +28,23 @@ export function extractJsrJson(source, content, ctx) {
26
28
  }
27
29
  if (!dist.publish) {
28
30
  if (dist.exclude) {
29
- source.pattern.exclude.push(...dist.exclude);
31
+ exclude.pattern.push(...dist.exclude);
30
32
  }
31
33
  }
32
34
  else if (dist.publish.exclude) {
33
- source.pattern.exclude.push(...dist.publish.exclude);
35
+ exclude.pattern.push(...dist.publish.exclude);
34
36
  }
35
37
  if (!dist.publish) {
36
38
  if (dist.include) {
37
- source.pattern.include.push(...dist.include);
39
+ include.pattern.push(...dist.include);
38
40
  }
39
41
  }
40
42
  else if (dist.publish.include) {
41
- source.pattern.include.push(...dist.publish.include);
43
+ include.pattern.push(...dist.publish.include);
44
+ }
45
+ for (const element of source.pattern) {
46
+ signedPatternCompile(element);
42
47
  }
43
- signedPatternCompile(source.pattern);
44
48
  }
45
49
  extractJsrJson;
46
50
  /**
@@ -1,5 +1,5 @@
1
- import { EventEmitter } from "node:events";
2
1
  import type { Dirent } from "node:fs";
2
+ import { EventEmitter } from "node:events";
3
3
  import type { MatcherContext } from "../patterns/matcherContext.js";
4
4
  import type { ScanOptions, FsAdapter } from "../types.js";
5
5
  import type { SignedPatternMatch } from "./signedPattern.js";
@@ -1,12 +1,7 @@
1
1
  import { type } from "arktype";
2
+ import { npmManifestParse } from "../targets/npmManifest.js";
2
3
  import { signedPatternCompile } from "./resolveSources.js";
3
4
  import { sourcePushNegatable } from "./source.js";
4
- const npmManifest = type({
5
- "files?": "string[]",
6
- });
7
- const parse = type("string")
8
- .pipe((s) => JSON.parse(s))
9
- .pipe(npmManifest);
10
5
  /**
11
6
  * Extracts and compiles patterns from the file.
12
7
  *
@@ -16,8 +11,11 @@ const parse = type("string")
16
11
  */
17
12
  export function extractPackageJson(source, content) {
18
13
  const result = extract(source, content);
19
- if (result === undefined)
20
- signedPatternCompile(source.pattern);
14
+ if (result === undefined) {
15
+ for (const element of source.pattern) {
16
+ signedPatternCompile(element);
17
+ }
18
+ }
21
19
  if (result === "error")
22
20
  return;
23
21
  return result;
@@ -31,15 +29,20 @@ export function extractPackageJson(source, content) {
31
29
  */
32
30
  export function extractPackageJsonNocase(source, content) {
33
31
  const result = extract(source, content);
34
- if (result === undefined)
35
- signedPatternCompile(source.pattern, { nocase: true });
32
+ if (result === undefined) {
33
+ for (const element of source.pattern) {
34
+ signedPatternCompile(element, { nocase: true });
35
+ }
36
+ }
36
37
  if (result === "error")
37
38
  return;
38
39
  return result;
39
40
  }
40
41
  function extract(source, content) {
41
42
  source.inverted = true;
42
- const dist = parse(content.toString());
43
+ const include = { compiled: null, excludes: false, pattern: [] };
44
+ const exclude = { compiled: null, excludes: true, pattern: [] };
45
+ const dist = npmManifestParse(content.toString());
43
46
  if (dist instanceof type.errors) {
44
47
  source.error = new Error("Invalid '" + source.path + "': " + dist.summary, { cause: dist });
45
48
  return "error";
@@ -48,7 +51,8 @@ function extract(source, content) {
48
51
  return "none";
49
52
  }
50
53
  for (const pattern of dist.files) {
51
- sourcePushNegatable(source, pattern);
54
+ sourcePushNegatable(pattern, true, include, exclude);
52
55
  }
56
+ source.pattern.push(include, exclude);
53
57
  }
54
58
  extractPackageJson;
@@ -8,6 +8,11 @@ import { type StringCompileOptions } from "./stringCompile.js";
8
8
  * @since 0.6.0
9
9
  */
10
10
  export type PatternMinimatch = {
11
+ /**
12
+ * The regular expression instance.
13
+ *
14
+ * @since 0.6.0
15
+ */
11
16
  re: RegExp;
12
17
  /**
13
18
  * The original pattern string this minimatch was compiled from.
@@ -13,11 +13,11 @@ export type PatternMatcher = {
13
13
  *
14
14
  * @since 0.6.0
15
15
  */
16
- internal: SignedPattern;
16
+ internal: SignedPattern[];
17
17
  /**
18
18
  * External patterns are sourced from existing project files at runtime.
19
19
  *
20
20
  * @since 0.6.0
21
21
  */
22
- external: SignedPattern;
22
+ external: SignedPattern[];
23
23
  };
@@ -11,10 +11,7 @@ import { patternCompile } from "./pattern.js";
11
11
  * @since 0.6.0
12
12
  */
13
13
  export function signedPatternCompile(signedPattern, options) {
14
- signedPattern.compiled = {
15
- include: patternCompile(signedPattern.include, options),
16
- exclude: patternCompile(signedPattern.exclude, options),
17
- };
14
+ signedPattern.compiled = patternCompile(signedPattern.pattern, options);
18
15
  return signedPattern;
19
16
  }
20
17
  /**
@@ -110,10 +107,10 @@ async function tryExtractor(cwd, fs, ctx, extractor) {
110
107
  const path = relative(cwd, abs);
111
108
  const name = path.substring(path.lastIndexOf("/") + 1);
112
109
  const newSource = {
113
- inverted: false,
114
110
  name,
115
111
  path,
116
- pattern: { exclude: [], include: [], compiled: null },
112
+ inverted: false,
113
+ pattern: [],
117
114
  };
118
115
  let buff;
119
116
  try {
@@ -1,6 +1,6 @@
1
1
  import type { PatternFinderOptions } from "./extractor.js";
2
- import { type Pattern, type PatternMinimatch } from "./pattern.js";
3
2
  import type { Source } from "./source.js";
3
+ import { type Pattern, type PatternMinimatch } from "./pattern.js";
4
4
  /**
5
5
  * Represents a set of include and exclude patterns.
6
6
  * These patterns are positive minimatch patterns.
@@ -18,17 +18,17 @@ export type SignedPattern = {
18
18
  *
19
19
  * @see {@link signedPatternIgnores} provides the ignoring algorithm.
20
20
  *
21
- * @since 0.6.0
21
+ * @since 0.9.0
22
22
  */
23
- include: Pattern;
23
+ pattern: Pattern;
24
24
  /**
25
- * Provides ignored or included file and directory patterns.
25
+ * If `true`, pattern "test" will exclude file named "test".
26
26
  *
27
27
  * @see {@link signedPatternIgnores} provides the ignoring algorithm.
28
28
  *
29
- * @since 0.6.0
29
+ * @since 0.9.0
30
30
  */
31
- exclude: Pattern;
31
+ excludes: boolean;
32
32
  /**
33
33
  * Provides compiled ignored or included file and directory patterns.
34
34
  *
@@ -36,24 +36,7 @@ export type SignedPattern = {
36
36
  *
37
37
  * @since 0.6.0
38
38
  */
39
- compiled: null | {
40
- /**
41
- * Provides compiled ignored or included file and directory patterns.
42
- *
43
- * @see {@link signedPatternIgnores} provides the ignoring algorithm.
44
- *
45
- * @since 0.6.0
46
- */
47
- include: PatternMinimatch[];
48
- /**
49
- * Provides compiled ignored or included file and directory patterns.
50
- *
51
- * @see {@link signedPatternIgnores} provides the ignoring algorithm.
52
- *
53
- * @since 0.6.0
54
- */
55
- exclude: PatternMinimatch[];
56
- };
39
+ compiled: null | PatternMinimatch[];
57
40
  };
58
41
  /**
59
42
  * @see {@link signedPatternIgnores}
@@ -103,24 +86,12 @@ export interface SignedPatternIgnoresOptions extends PatternFinderOptions {
103
86
  *
104
87
  * @since 0.6.0
105
88
  */
106
- internal: SignedPattern;
89
+ internal: SignedPattern[];
107
90
  }
108
91
  /**
109
92
  * Checks whether a given entry should be ignored based on internal and external patterns.
110
93
  * Populates unknown sources using {@link resolveSources}.
111
94
  *
112
- * Algorithm:
113
- * 1. Check internal exclude patterns. If matched, return true.
114
- * 2. Check internal include patterns. If matched, return false.
115
- * 3. Check external patterns:
116
- * - If not inverted:
117
- * a. Check external include patterns. If matched, return false.
118
- * b. Check external exclude patterns. If matched, return true.
119
- * - If inverted:
120
- * a. Check external exclude patterns. If matched, return true.
121
- * b. Check external include patterns. If matched, return false.
122
- * 4. If no patterns matched, return the inverted state.
123
- *
124
95
  * @since 0.6.0
125
96
  */
126
97
  export declare function signedPatternIgnores(options: SignedPatternIgnoresOptions): Promise<SignedPatternMatch>;
@@ -19,25 +19,21 @@ function signedPatternCompiledMatchInternal(options, path) {
19
19
  let err;
20
20
  const kind = "internal";
21
21
  const signedPattern = options.internal;
22
- const compiled = signedPattern.compiled; // no null
23
22
  try {
24
- ;
25
- [patternMatch, err] = patternRegExpTest(path, compiled.exclude);
26
- if (err) {
27
- throw err;
28
- }
29
- if (patternMatch) {
30
- // return true
31
- return { kind, pattern: patternMatch, ignored: true };
32
- }
33
- ;
34
- [patternMatch, err] = patternRegExpTest(path, compiled.include);
35
- if (err) {
36
- throw err;
37
- }
38
- if (patternMatch) {
39
- // return false
40
- return { kind, pattern: patternMatch, ignored: false };
23
+ for (const si of signedPattern) {
24
+ const compiled = si.compiled;
25
+ if (compiled === null) {
26
+ continue;
27
+ }
28
+ ;
29
+ [patternMatch, err] = patternRegExpTest(path, compiled);
30
+ if (err) {
31
+ throw err;
32
+ }
33
+ if (patternMatch) {
34
+ // return true
35
+ return { kind, pattern: patternMatch, ignored: si.excludes };
36
+ }
41
37
  }
42
38
  }
43
39
  catch (error) {
@@ -54,47 +50,20 @@ function signedPatternCompiledMatchExternal(options, path, source) {
54
50
  let patternMatch = "";
55
51
  let err;
56
52
  const kind = "external";
57
- const signedPattern = source.pattern;
58
- const compiled = signedPattern.compiled; // no null
59
53
  try {
60
- if (source.inverted) {
61
- ;
62
- [patternMatch, err] = patternRegExpTest(path, compiled.exclude);
63
- if (err) {
64
- throw err;
54
+ for (const si of source.pattern) {
55
+ const compiled = si.compiled;
56
+ if (compiled === null) {
57
+ continue;
65
58
  }
66
- if (patternMatch) {
67
- // return true
68
- return { kind, source, pattern: patternMatch, ignored: true };
69
- }
70
- ;
71
- [patternMatch, err] = patternRegExpTest(path, compiled.include);
72
- if (err) {
73
- throw err;
74
- }
75
- if (patternMatch) {
76
- // return false
77
- return { kind, source, pattern: patternMatch, ignored: false };
78
- }
79
- }
80
- else {
81
59
  ;
82
- [patternMatch, err] = patternRegExpTest(path, compiled.include);
83
- if (err) {
84
- throw err;
85
- }
86
- if (patternMatch) {
87
- // return false
88
- return { kind, source, pattern: patternMatch, ignored: false };
89
- }
90
- ;
91
- [patternMatch, err] = patternRegExpTest(path, compiled.exclude);
60
+ [patternMatch, err] = patternRegExpTest(path, compiled);
92
61
  if (err) {
93
62
  throw err;
94
63
  }
95
64
  if (patternMatch) {
96
65
  // return true
97
- return { kind, source, pattern: patternMatch, ignored: true };
66
+ return { kind, pattern: patternMatch, ignored: si.excludes, source };
98
67
  }
99
68
  }
100
69
  }
@@ -109,18 +78,6 @@ function signedPatternCompiledMatchExternal(options, path, source) {
109
78
  * Checks whether a given entry should be ignored based on internal and external patterns.
110
79
  * Populates unknown sources using {@link resolveSources}.
111
80
  *
112
- * Algorithm:
113
- * 1. Check internal exclude patterns. If matched, return true.
114
- * 2. Check internal include patterns. If matched, return false.
115
- * 3. Check external patterns:
116
- * - If not inverted:
117
- * a. Check external include patterns. If matched, return false.
118
- * b. Check external exclude patterns. If matched, return true.
119
- * - If inverted:
120
- * a. Check external exclude patterns. If matched, return true.
121
- * b. Check external include patterns. If matched, return false.
122
- * 4. If no patterns matched, return the inverted state.
123
- *
124
81
  * @since 0.6.0
125
82
  */
126
83
  export async function signedPatternIgnores(options) {
@@ -131,7 +88,7 @@ export async function signedPatternIgnores(options) {
131
88
  source = options.ctx.external.get(parent);
132
89
  }
133
90
  if (source === undefined || source === "none") {
134
- return { kind: "missing-source", ignored: true };
91
+ return { kind: "missing-source", ignored: false };
135
92
  }
136
93
  if (typeof source === "object" && source.error) {
137
94
  return { kind: "broken-source", ignored: true, source };
@@ -14,7 +14,7 @@ export type Source = {
14
14
  *
15
15
  * @since 0.6.0
16
16
  */
17
- pattern: SignedPattern;
17
+ pattern: SignedPattern[];
18
18
  /**
19
19
  * Name of the source file.
20
20
  *
@@ -54,4 +54,4 @@ export type Source = {
54
54
  *
55
55
  * @since 0.6.0
56
56
  */
57
- export declare function sourcePushNegatable(source: Source, pattern: string): void;
57
+ export declare function sourcePushNegatable(pattern: string, invert: boolean, include: SignedPattern, exclude: SignedPattern): void;
@@ -5,9 +5,8 @@
5
5
  *
6
6
  * @since 0.6.0
7
7
  */
8
- export function sourcePushNegatable(source, pattern) {
9
- let exclude = source.pattern.exclude, include = source.pattern.include;
10
- if (source.inverted) {
8
+ export function sourcePushNegatable(pattern, invert, include, exclude) {
9
+ if (invert) {
11
10
  ;
12
11
  [exclude, include] = [include, exclude];
13
12
  }
@@ -16,5 +15,5 @@ export function sourcePushNegatable(source, pattern) {
16
15
  dist = include;
17
16
  pattern = pattern.substring(1);
18
17
  }
19
- dist.push(pattern);
18
+ dist.pattern.push(pattern);
20
19
  }
@@ -17,7 +17,9 @@ export function stringCompile(pattern, context = [], options) {
17
17
  else if (!pattern.startsWith("**/")) {
18
18
  pattern = "**/" + pattern;
19
19
  }
20
- pattern += "/**";
20
+ if (!pattern.endsWith("/**")) {
21
+ pattern += "/**";
22
+ }
21
23
  const re = makeRe(pattern, {
22
24
  dot: true,
23
25
  nonegate: true,
@@ -0,0 +1,5 @@
1
+ import type { Target } from "./target.js";
2
+ /**
3
+ * @since 0.8.1
4
+ */
5
+ export declare const Bun: Target;
@@ -0,0 +1,123 @@
1
+ import { type } from "arktype";
2
+ import { signedPatternIgnores, signedPatternCompile, extractPackageJson, extractGitignore, } from "../patterns/index.js";
3
+ import { join, unixify } from "../unixify.js";
4
+ import { npmManifestParse } from "./npmManifest.js";
5
+ const extractors = [
6
+ {
7
+ extract: extractPackageJson,
8
+ path: "package.json",
9
+ },
10
+ {
11
+ extract: extractGitignore,
12
+ path: ".npmignore",
13
+ },
14
+ {
15
+ extract: extractGitignore,
16
+ path: ".gitignore",
17
+ },
18
+ ];
19
+ const internalInclude = {
20
+ excludes: false,
21
+ pattern: [], // filled within init
22
+ compiled: [],
23
+ };
24
+ const internal = [
25
+ internalInclude,
26
+ signedPatternCompile({
27
+ excludes: true,
28
+ pattern: [
29
+ // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L180
30
+ "package-lock.json",
31
+ "yarn.lock",
32
+ "pnpm-lock.yaml",
33
+ "bun.lockb",
34
+ "bun.lock", // npm includes it
35
+ // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L189
36
+ ".*.swp",
37
+ "._*",
38
+ ".DS_Store",
39
+ ".git",
40
+ ".gitignore",
41
+ ".hg",
42
+ ".npmignore",
43
+ ".npmrc",
44
+ ".lock-wscript",
45
+ ".svn",
46
+ "wafpickle-*",
47
+ "CVS",
48
+ "npm-debug.log",
49
+ // bun says it is "mentioned in the docs but does not appear to be ignored by default"
50
+ // but we know it should be /build/config.gypi, not just config.gypi, haha
51
+ // "config.gypi",
52
+ ".env.production", // npm includes it
53
+ "bunfig.toml", // npm includes it
54
+ // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L284
55
+ // manifest should be included, but bun ignores it on this line
56
+ // bun forces it later: https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L2586
57
+ // "package.json",
58
+ // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L285
59
+ "node_modules",
60
+ ],
61
+ compiled: null,
62
+ }), // nocase should be false here
63
+ signedPatternCompile({
64
+ excludes: true,
65
+ pattern: [
66
+ // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L2586
67
+ "package.json",
68
+ // the special?.* check works this way: https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L2599
69
+ "LICENSE",
70
+ "LICENSE.*",
71
+ "LICENCE",
72
+ "LICENCE.*",
73
+ "README",
74
+ "README.*",
75
+ ],
76
+ compiled: null,
77
+ }, { nocase: true }),
78
+ ];
79
+ /**
80
+ * @since 0.8.1
81
+ */
82
+ export const Bun = {
83
+ async init({ fs, cwd }) {
84
+ let content;
85
+ const normalCwd = unixify(cwd);
86
+ try {
87
+ content = await fs.promises.readFile(normalCwd + "/" + "package.json");
88
+ }
89
+ catch (error) {
90
+ throw new Error("Error while initializing Bun", { cause: error });
91
+ }
92
+ const dist = npmManifestParse(content.toString());
93
+ if (dist instanceof type.errors) {
94
+ throw new Error("Invalid 'package.json': " + dist.summary, { cause: dist });
95
+ }
96
+ const set = new Set();
97
+ function normal(path) {
98
+ const result = unixify(join(normalCwd, path)).substring(normalCwd.length);
99
+ return result;
100
+ }
101
+ // https://github.com/oven-sh/bun/blob/main/src/cli/pack_command.zig#L1440
102
+ if (typeof dist.bin === "string") {
103
+ set.add(normal(dist.bin));
104
+ }
105
+ else if (typeof dist.bin === "object" && dist.bin !== null) {
106
+ Object.values(dist.bin).forEach((binPath) => set.add(normal(binPath)));
107
+ }
108
+ // TODO: Bun should include bundled deps
109
+ // nothing else
110
+ // link zig code
111
+ internalInclude.pattern = Array.from(set);
112
+ signedPatternCompile(internalInclude, { nocase: true });
113
+ },
114
+ extractors,
115
+ ignores(o) {
116
+ return signedPatternIgnores({
117
+ ...o,
118
+ internal,
119
+ root: ".",
120
+ target: Bun,
121
+ });
122
+ },
123
+ };
@@ -0,0 +1,5 @@
1
+ import type { Target } from "./target.js";
2
+ /**
3
+ * @since 0.8.1
4
+ */
5
+ export declare const Deno: Target;