esbuild-ignore-with-comments-plugin 0.1.1 → 0.3.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
@@ -1,3 +1,3 @@
1
1
  # ESBuild Ignore with Comments Plugin
2
2
 
3
- Allows inserting comments into TypeScript source files. ESBuild will ignore these files during build.
3
+ Allows inserting comments into TypeScript source files. ESBuild will ignore these files during build.
@@ -1,9 +1,9 @@
1
- import { Plugin } from 'esbuild';
2
- export interface IgnoreWithCommentsPluginOptions {
3
- ignore: string[];
4
- }
5
- export declare function mustIgnore(comments: string[], ignore: string[] | undefined): boolean;
6
- export declare function findComments(text: string): string[];
7
- declare const pluginFactory: (opts?: IgnoreWithCommentsPluginOptions) => Plugin;
8
- export default pluginFactory;
1
+ import { Plugin } from 'esbuild';
2
+ export interface IgnoreWithCommentsPluginOptions {
3
+ ignore: string[];
4
+ }
5
+ export declare function mustIgnore(comments: string[], ignore: string[] | undefined): boolean;
6
+ export declare function findComments(text: string): string[];
7
+ declare const pluginFactory: (opts?: IgnoreWithCommentsPluginOptions) => Plugin;
8
+ export default pluginFactory;
9
9
  //# sourceMappingURL=esbuildIgnoreWithCommentsPlugin.d.ts.map
@@ -1,68 +1,68 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.findComments = exports.mustIgnore = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const ignorePlugin = (opts) => {
9
- return {
10
- name: 'ignore-with-comments-plugin',
11
- setup: (build) => {
12
- // build.onResolve({ filter: /.*/, namespace: 'ignore' }, (args) => {
13
- // return {
14
- // path: args.path,
15
- // namespace: 'ignore',
16
- // };
17
- // });
18
- build.onLoad({
19
- filter: /\.(ts|tsx)$/,
20
- }, async (args) => {
21
- const text = await fs_1.default.promises.readFile(args.path, 'utf8');
22
- const res = findComments(text);
23
- if (mustIgnore(res, opts === null || opts === void 0 ? void 0 : opts.ignore)) {
24
- return {
25
- contents: 'const dummy = {}; export default dummy;',
26
- loader: 'ts',
27
- };
28
- }
29
- const type = args.path.endsWith('.ts') ? 'ts' : 'tsx';
30
- return {
31
- contents: text,
32
- loader: type,
33
- };
34
- });
35
- },
36
- };
37
- };
38
- function mustIgnore(comments, ignore) {
39
- if (comments.length === 0) {
40
- return false;
41
- }
42
- if (!ignore) {
43
- return true;
44
- }
45
- const reducer = (prev, curr) => {
46
- return (prev && comments.find((el) => el === curr || el === '') !== undefined);
47
- };
48
- return ignore.reduce(reducer, true);
49
- }
50
- exports.mustIgnore = mustIgnore;
51
- function findComments(text) {
52
- const commentRegex = /^\s*\/\* esbuild-ignore ([^\s\*]*)/gm;
53
- const res = [];
54
- let matches;
55
- do {
56
- matches = commentRegex.exec(text);
57
- if (matches && matches.length > 1) {
58
- res.push(matches[1]);
59
- }
60
- } while (matches !== null);
61
- return res;
62
- }
63
- exports.findComments = findComments;
64
- const pluginFactory = (opts) => {
65
- return ignorePlugin(opts);
66
- };
67
- exports.default = pluginFactory;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.findComments = exports.mustIgnore = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const ignorePlugin = (opts) => {
9
+ return {
10
+ name: 'ignore-with-comments-plugin',
11
+ setup: (build) => {
12
+ // build.onResolve({ filter: /.*/, namespace: 'ignore' }, (args) => {
13
+ // return {
14
+ // path: args.path,
15
+ // namespace: 'ignore',
16
+ // };
17
+ // });
18
+ build.onLoad({
19
+ filter: /\.(ts|tsx)$/,
20
+ }, async (args) => {
21
+ const text = await fs_1.default.promises.readFile(args.path, 'utf8');
22
+ const res = findComments(text);
23
+ if (mustIgnore(res, opts === null || opts === void 0 ? void 0 : opts.ignore)) {
24
+ return {
25
+ contents: 'const dummy = {}; export default dummy;',
26
+ loader: 'ts',
27
+ };
28
+ }
29
+ const type = args.path.endsWith('.ts') ? 'ts' : 'tsx';
30
+ return {
31
+ contents: text,
32
+ loader: type,
33
+ };
34
+ });
35
+ },
36
+ };
37
+ };
38
+ function mustIgnore(comments, ignore) {
39
+ if (comments.length === 0) {
40
+ return false;
41
+ }
42
+ if (!ignore) {
43
+ return true;
44
+ }
45
+ const reducer = (prev, curr) => {
46
+ return (prev && comments.find((el) => el === curr || el === '') !== undefined);
47
+ };
48
+ return ignore.reduce(reducer, true);
49
+ }
50
+ exports.mustIgnore = mustIgnore;
51
+ function findComments(text) {
52
+ const commentRegex = /^\s*\/\* esbuild-ignore ([^\s\*]*)/gm;
53
+ const res = [];
54
+ let matches;
55
+ do {
56
+ matches = commentRegex.exec(text);
57
+ if (matches && matches.length > 1) {
58
+ res.push(matches[1]);
59
+ }
60
+ } while (matches !== null);
61
+ return res;
62
+ }
63
+ exports.findComments = findComments;
64
+ const pluginFactory = (opts) => {
65
+ return ignorePlugin(opts);
66
+ };
67
+ exports.default = pluginFactory;
68
68
  //# sourceMappingURL=esbuildIgnoreWithCommentsPlugin.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esbuild-ignore-with-comments-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "esbuild Plugin for ignoring files with specific comments in them",
5
5
  "keywords": [
6
6
  "node",
@@ -33,7 +33,7 @@
33
33
  "version:apply": "utils-git changed --exec \"yarn version $@ && yarn version apply\""
34
34
  },
35
35
  "devDependencies": {
36
- "@goldstack/utils-git": "0.1.37",
36
+ "@goldstack/utils-git": "0.2.0",
37
37
  "@types/jest": "^28.1.8",
38
38
  "@types/node": "^18.7.13",
39
39
  "esbuild": "^0.15.5",