esbuild-ignore-with-comments-plugin 0.3.0 → 0.3.1
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,63 @@
|
|
|
1
|
+
[](https://badge.fury.io/js/esbuild-ignore-with-comments-plugin)
|
|
2
|
+
|
|
1
3
|
# ESBuild Ignore with Comments Plugin
|
|
2
4
|
|
|
3
|
-
Allows inserting comments into TypeScript source files. ESBuild will ignore these files during build.
|
|
5
|
+
Allows inserting comments into TypeScript source files. ESBuild will ignore these files during build.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
Add to any `.ts` or `.tsx` file the following comment:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
/* esbuild-ignore */
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This file will be replaced with a source file that has an empty object as a default export.
|
|
16
|
+
|
|
17
|
+
Configure the plugin for esbuild as follows:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import ignorePlugin from 'esbuild-ignore-with-comments-plugin';
|
|
21
|
+
import { build } from 'esbuild';
|
|
22
|
+
|
|
23
|
+
await build({
|
|
24
|
+
plugins: [ignorePlugin()],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
If you are bundling the same files multiple times (such as for server-side rendering) you can group files into sets and only ignore specific sets of files.
|
|
29
|
+
|
|
30
|
+
For instance, assume you have the following files:
|
|
31
|
+
|
|
32
|
+
`server.ts`
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
/* esbuild-ignore ui */
|
|
36
|
+
|
|
37
|
+
// some server only stuff
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`ui.ts`
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
/* esbuild-ignore server */
|
|
44
|
+
|
|
45
|
+
// some ui only stuff
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Then running the following will ignore `server.ts` during the build:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
await build({
|
|
52
|
+
plugins: [ignorePlugin(['ui'])],
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Note that files that have the comment `/* esbuild-ignore */` without specifying a group will always be ignored.
|
|
57
|
+
|
|
58
|
+
Also note that if you want to add a file to multiple groups, you need to include multiple `esbuild-ignore` comments, such as:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
/* esbuild-ignore server */
|
|
62
|
+
/* esbuild-ignore ui */
|
|
63
|
+
```
|
|
@@ -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,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esbuild-ignore-with-comments-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "esbuild Plugin for ignoring files with specific comments in them",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
7
7
|
"javascript",
|
|
8
8
|
"esbuild"
|
|
9
9
|
],
|
|
10
|
-
"homepage": "",
|
|
10
|
+
"homepage": "https://github.com/goldstack/goldstack/tree/master/workspaces/utils/packages/esbuild-ignore-with-comments-plugin",
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/goldstack/goldstack/issues"
|
|
13
13
|
},
|
|
@@ -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.2.
|
|
36
|
+
"@goldstack/utils-git": "0.2.1",
|
|
37
37
|
"@types/jest": "^28.1.8",
|
|
38
38
|
"@types/node": "^18.7.13",
|
|
39
39
|
"esbuild": "^0.15.5",
|